You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
7.7KB

  1. /*
  2. * nut
  3. * Copyright (c) 2004-2007 Michael Niedermayer
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/mathematics.h"
  22. #include "libavutil/tree.h"
  23. #include "nut.h"
  24. #include "internal.h"
  25. const AVCodecTag ff_nut_subtitle_tags[] = {
  26. { AV_CODEC_ID_TEXT , MKTAG('U', 'T', 'F', '8') },
  27. { AV_CODEC_ID_SSA , MKTAG('S', 'S', 'A', 0 ) },
  28. { AV_CODEC_ID_DVD_SUBTITLE, MKTAG('D', 'V', 'D', 'S') },
  29. { AV_CODEC_ID_DVB_SUBTITLE, MKTAG('D', 'V', 'B', 'S') },
  30. { AV_CODEC_ID_NONE , 0 }
  31. };
  32. const AVCodecTag ff_nut_video_tags[] = {
  33. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 15 ) },
  34. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 15 ) },
  35. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 16 ) },
  36. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 16 ) },
  37. { AV_CODEC_ID_RAWVIDEO, MKTAG(15 , 'B', 'G', 'R') },
  38. { AV_CODEC_ID_RAWVIDEO, MKTAG(15 , 'R', 'G', 'B') },
  39. { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 'B', 'G', 'R') },
  40. { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 'R', 'G', 'B') },
  41. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 12 ) },
  42. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 12 ) },
  43. { AV_CODEC_ID_RAWVIDEO, MKTAG(12 , 'B', 'G', 'R') },
  44. { AV_CODEC_ID_RAWVIDEO, MKTAG(12 , 'R', 'G', 'B') },
  45. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 'A') },
  46. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 0 ) },
  47. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 'A') },
  48. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 0 ) },
  49. { AV_CODEC_ID_RAWVIDEO, MKTAG('A', 'B', 'G', 'R') },
  50. { AV_CODEC_ID_RAWVIDEO, MKTAG( 0 , 'B', 'G', 'R') },
  51. { AV_CODEC_ID_RAWVIDEO, MKTAG('A', 'R', 'G', 'B') },
  52. { AV_CODEC_ID_RAWVIDEO, MKTAG( 0 , 'R', 'G', 'B') },
  53. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 24 ) },
  54. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 24 ) },
  55. { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '1', '1', 'P') },
  56. { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '2', '2', 'P') },
  57. { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '2', '2', 'P') },
  58. { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '0', 'P') },
  59. { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '0', 'P') },
  60. { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '4', 'P') },
  61. { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '4', 'P') },
  62. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '1', 'W', '0') },
  63. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '0', 'W', '1') },
  64. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 8 ) },
  65. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 8 ) },
  66. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 4 ) },
  67. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 4 ) },
  68. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '4', 'B', 'Y') },
  69. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', '4', 'B', 'Y') },
  70. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 48 ) },
  71. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 48 ) },
  72. { AV_CODEC_ID_RAWVIDEO, MKTAG(48 , 'B', 'G', 'R') },
  73. { AV_CODEC_ID_RAWVIDEO, MKTAG(48 , 'R', 'G', 'B') },
  74. { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'R', 'A', 64 ) },
  75. { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'B', 'A', 64 ) },
  76. { AV_CODEC_ID_RAWVIDEO, MKTAG(64 , 'B', 'R', 'A') },
  77. { AV_CODEC_ID_RAWVIDEO, MKTAG(64 , 'R', 'B', 'A') },
  78. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 10 ) },
  79. { AV_CODEC_ID_RAWVIDEO, MKTAG(10 , 11 , '3', 'Y') },
  80. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 10 ) },
  81. { AV_CODEC_ID_RAWVIDEO, MKTAG(10 , 10 , '3', 'Y') },
  82. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 0 , 10 ) },
  83. { AV_CODEC_ID_RAWVIDEO, MKTAG(10 , 0 , '3', 'Y') },
  84. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 12 ) },
  85. { AV_CODEC_ID_RAWVIDEO, MKTAG(12 , 11 , '3', 'Y') },
  86. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 12 ) },
  87. { AV_CODEC_ID_RAWVIDEO, MKTAG(12 , 10 , '3', 'Y') },
  88. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 0 , 12 ) },
  89. { AV_CODEC_ID_RAWVIDEO, MKTAG(12 , 0 , '3', 'Y') },
  90. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 14 ) },
  91. { AV_CODEC_ID_RAWVIDEO, MKTAG(14 , 11 , '3', 'Y') },
  92. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 14 ) },
  93. { AV_CODEC_ID_RAWVIDEO, MKTAG(14 , 10 , '3', 'Y') },
  94. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 0 , 14 ) },
  95. { AV_CODEC_ID_RAWVIDEO, MKTAG(14 , 0 , '3', 'Y') },
  96. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '1', 0 , 16 ) },
  97. { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 0 , '1', 'Y') },
  98. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 16 ) },
  99. { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 11 , '3', 'Y') },
  100. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 16 ) },
  101. { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 10 , '3', 'Y') },
  102. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 0 , 16 ) },
  103. { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 0 , '3', 'Y') },
  104. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 11 , 8 ) },
  105. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 10 , 8 ) },
  106. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 0 , 8 ) },
  107. { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '2', 0 , 8 ) },
  108. { AV_CODEC_ID_NONE , 0 }
  109. };
  110. void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val){
  111. int i;
  112. for(i=0; i<nut->avf->nb_streams; i++){
  113. nut->stream[i].last_pts= av_rescale_rnd(
  114. val,
  115. time_base.num * (int64_t)nut->stream[i].time_base->den,
  116. time_base.den * (int64_t)nut->stream[i].time_base->num,
  117. AV_ROUND_DOWN);
  118. }
  119. }
  120. int64_t ff_lsb2full(StreamContext *stream, int64_t lsb){
  121. int64_t mask = (1<<stream->msb_pts_shift)-1;
  122. int64_t delta= stream->last_pts - mask/2;
  123. return ((lsb - delta)&mask) + delta;
  124. }
  125. int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b){
  126. return ((a->pos - b->pos) >> 32) - ((b->pos - a->pos) >> 32);
  127. }
  128. int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b){
  129. return ((a->ts - b->ts) >> 32) - ((b->ts - a->ts) >> 32);
  130. }
  131. void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){
  132. Syncpoint *sp= av_mallocz(sizeof(Syncpoint));
  133. struct AVTreeNode *node= av_mallocz(av_tree_node_size);
  134. sp->pos= pos;
  135. sp->back_ptr= back_ptr;
  136. sp->ts= ts;
  137. av_tree_insert(&nut->syncpoints, sp, (void *) ff_nut_sp_pos_cmp, &node);
  138. if(node){
  139. av_free(sp);
  140. av_free(node);
  141. }
  142. }
  143. static int enu_free(void *opaque, void *elem)
  144. {
  145. av_free(elem);
  146. return 0;
  147. }
  148. void ff_nut_free_sp(NUTContext *nut)
  149. {
  150. av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free);
  151. av_tree_destroy(nut->syncpoints);
  152. }
  153. const Dispositions ff_nut_dispositions[] = {
  154. {"default" , AV_DISPOSITION_DEFAULT},
  155. {"dub" , AV_DISPOSITION_DUB},
  156. {"original" , AV_DISPOSITION_ORIGINAL},
  157. {"comment" , AV_DISPOSITION_COMMENT},
  158. {"lyrics" , AV_DISPOSITION_LYRICS},
  159. {"karaoke" , AV_DISPOSITION_KARAOKE},
  160. {"" , 0}
  161. };
  162. const AVMetadataConv ff_nut_metadata_conv[] = {
  163. { "Author", "artist" },
  164. { "X-CreationTime", "date" },
  165. { "CreationTime", "date" },
  166. { "SourceFilename", "filename" },
  167. { "X-Language", "language" },
  168. { "X-Disposition", "disposition" },
  169. { "X-Replaces", "replaces" },
  170. { "X-Depends", "depends" },
  171. { "X-Uses", "uses" },
  172. { "X-UsesFont", "usesfont" },
  173. { 0 },
  174. };