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.

299 lines
10KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdint.h>
  19. #include "libavutil/common.h"
  20. #include "libavutil/log.h"
  21. #include "libavutil/pixdesc.h"
  22. #include "avcodec.h"
  23. #include "dv_profile.h"
  24. static const uint8_t dv_audio_shuffle525[10][9] = {
  25. { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
  26. { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
  27. { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
  28. { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
  29. { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
  30. { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
  31. { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
  32. { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
  33. { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
  34. { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
  35. };
  36. static const uint8_t dv_audio_shuffle625[12][9] = {
  37. { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
  38. { 6, 42, 78, 32, 68, 104, 22, 58, 94},
  39. { 12, 48, 84, 2, 38, 74, 28, 64, 100},
  40. { 18, 54, 90, 8, 44, 80, 34, 70, 106},
  41. { 24, 60, 96, 14, 50, 86, 4, 40, 76},
  42. { 30, 66, 102, 20, 56, 92, 10, 46, 82},
  43. { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
  44. { 7, 43, 79, 33, 69, 105, 23, 59, 95},
  45. { 13, 49, 85, 3, 39, 75, 29, 65, 101},
  46. { 19, 55, 91, 9, 45, 81, 35, 71, 107},
  47. { 25, 61, 97, 15, 51, 87, 5, 41, 77},
  48. { 31, 67, 103, 21, 57, 93, 11, 47, 83},
  49. };
  50. /* macroblock bit budgets */
  51. static const uint8_t block_sizes_dv2550[8] = {
  52. 112, 112, 112, 112, 80, 80, 0, 0,
  53. };
  54. static const uint8_t block_sizes_dv100[8] = {
  55. 80, 80, 80, 80, 80, 80, 64, 64,
  56. };
  57. static const DVprofile dv_profiles[] = {
  58. { .dsf = 0,
  59. .video_stype = 0x0,
  60. .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
  61. .difseg_size = 10,
  62. .n_difchan = 1,
  63. .time_base = { 1001, 30000 },
  64. .ltc_divisor = 30,
  65. .height = 480,
  66. .width = 720,
  67. .sar = {{8, 9}, {32, 27}},
  68. .pix_fmt = AV_PIX_FMT_YUV411P,
  69. .bpm = 6,
  70. .block_sizes = block_sizes_dv2550,
  71. .audio_stride = 90,
  72. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  73. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  74. .audio_shuffle = dv_audio_shuffle525,
  75. },
  76. { .dsf = 1,
  77. .video_stype = 0x0,
  78. .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
  79. .difseg_size = 12,
  80. .n_difchan = 1,
  81. .time_base = { 1, 25 },
  82. .ltc_divisor = 25,
  83. .height = 576,
  84. .width = 720,
  85. .sar = {{16, 15}, {64, 45}},
  86. .pix_fmt = AV_PIX_FMT_YUV420P,
  87. .bpm = 6,
  88. .block_sizes = block_sizes_dv2550,
  89. .audio_stride = 108,
  90. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  91. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  92. .audio_shuffle = dv_audio_shuffle625,
  93. },
  94. { .dsf = 1,
  95. .video_stype = 0x0,
  96. .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
  97. .difseg_size = 12,
  98. .n_difchan = 1,
  99. .time_base = { 1, 25 },
  100. .ltc_divisor = 25,
  101. .height = 576,
  102. .width = 720,
  103. .sar = {{16, 15}, {64, 45}},
  104. .pix_fmt = AV_PIX_FMT_YUV411P,
  105. .bpm = 6,
  106. .block_sizes = block_sizes_dv2550,
  107. .audio_stride = 108,
  108. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  109. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  110. .audio_shuffle = dv_audio_shuffle625,
  111. },
  112. { .dsf = 0,
  113. .video_stype = 0x4,
  114. .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
  115. .difseg_size = 10, /* also known as "DVCPRO50" */
  116. .n_difchan = 2,
  117. .time_base = { 1001, 30000 },
  118. .ltc_divisor = 30,
  119. .height = 480,
  120. .width = 720,
  121. .sar = {{8, 9}, {32, 27}},
  122. .pix_fmt = AV_PIX_FMT_YUV422P,
  123. .bpm = 6,
  124. .block_sizes = block_sizes_dv2550,
  125. .audio_stride = 90,
  126. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  127. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  128. .audio_shuffle = dv_audio_shuffle525,
  129. },
  130. { .dsf = 1,
  131. .video_stype = 0x4,
  132. .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
  133. .difseg_size = 12, /* also known as "DVCPRO50" */
  134. .n_difchan = 2,
  135. .time_base = { 1, 25 },
  136. .ltc_divisor = 25,
  137. .height = 576,
  138. .width = 720,
  139. .sar = {{16, 15}, {64, 45}},
  140. .pix_fmt = AV_PIX_FMT_YUV422P,
  141. .bpm = 6,
  142. .block_sizes = block_sizes_dv2550,
  143. .audio_stride = 108,
  144. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  145. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  146. .audio_shuffle = dv_audio_shuffle625,
  147. },
  148. { .dsf = 0,
  149. .video_stype = 0x14,
  150. .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
  151. .difseg_size = 10, /* also known as "DVCPRO HD" */
  152. .n_difchan = 4,
  153. .time_base = { 1001, 30000 },
  154. .ltc_divisor = 30,
  155. .height = 1080,
  156. .width = 1280,
  157. .sar = {{1, 1}, {3, 2}},
  158. .pix_fmt = AV_PIX_FMT_YUV422P,
  159. .bpm = 8,
  160. .block_sizes = block_sizes_dv100,
  161. .audio_stride = 90,
  162. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  163. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  164. .audio_shuffle = dv_audio_shuffle525,
  165. },
  166. { .dsf = 1,
  167. .video_stype = 0x14,
  168. .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
  169. .difseg_size = 12, /* also known as "DVCPRO HD" */
  170. .n_difchan = 4,
  171. .time_base = { 1, 25 },
  172. .ltc_divisor = 25,
  173. .height = 1080,
  174. .width = 1440,
  175. .sar = {{1, 1}, {4, 3}},
  176. .pix_fmt = AV_PIX_FMT_YUV422P,
  177. .bpm = 8,
  178. .block_sizes = block_sizes_dv100,
  179. .audio_stride = 108,
  180. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  181. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  182. .audio_shuffle = dv_audio_shuffle625,
  183. },
  184. { .dsf = 0,
  185. .video_stype = 0x18,
  186. .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
  187. .difseg_size = 10, /* also known as "DVCPRO HD" */
  188. .n_difchan = 2,
  189. .time_base = { 1001, 60000 },
  190. .ltc_divisor = 60,
  191. .height = 720,
  192. .width = 960,
  193. .sar = {{1, 1}, {4, 3}},
  194. .pix_fmt = AV_PIX_FMT_YUV422P,
  195. .bpm = 8,
  196. .block_sizes = block_sizes_dv100,
  197. .audio_stride = 90,
  198. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  199. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  200. .audio_shuffle = dv_audio_shuffle525,
  201. },
  202. { .dsf = 1,
  203. .video_stype = 0x18,
  204. .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
  205. .difseg_size = 12, /* also known as "DVCPRO HD" */
  206. .n_difchan = 2,
  207. .time_base = { 1, 50 },
  208. .ltc_divisor = 50,
  209. .height = 720,
  210. .width = 960,
  211. .sar = {{1, 1}, {4, 3}},
  212. .pix_fmt = AV_PIX_FMT_YUV422P,
  213. .bpm = 8,
  214. .block_sizes = block_sizes_dv100,
  215. .audio_stride = 90,
  216. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  217. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  218. .audio_shuffle = dv_audio_shuffle625,
  219. },
  220. { .dsf = 1,
  221. .video_stype = 0x1,
  222. .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
  223. .difseg_size = 12,
  224. .n_difchan = 1,
  225. .time_base = { 1, 25 },
  226. .ltc_divisor = 25,
  227. .height = 576,
  228. .width = 720,
  229. .sar = {{16, 15}, {64, 45}},
  230. .pix_fmt = AV_PIX_FMT_YUV420P,
  231. .bpm = 6,
  232. .block_sizes = block_sizes_dv2550,
  233. .audio_stride = 108,
  234. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  235. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  236. .audio_shuffle = dv_audio_shuffle625,
  237. }
  238. };
  239. const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
  240. const uint8_t* frame, unsigned buf_size)
  241. {
  242. int i, dsf, stype;
  243. if (buf_size < 80 * 5 + 48 + 4)
  244. return NULL;
  245. dsf = (frame[3] & 0x80) >> 7;
  246. stype = frame[80 * 5 + 48 + 3] & 0x1f;
  247. /* 576i50 25Mbps 4:1:1 is a special case */
  248. if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
  249. return &dv_profiles[2];
  250. }
  251. for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
  252. if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
  253. return &dv_profiles[i];
  254. /* check if old sys matches and assumes corrupted input */
  255. if (sys && buf_size == sys->frame_size)
  256. return sys;
  257. return NULL;
  258. }
  259. const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec)
  260. {
  261. int i;
  262. for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
  263. if (codec->height == dv_profiles[i].height &&
  264. codec->pix_fmt == dv_profiles[i].pix_fmt &&
  265. codec->width == dv_profiles[i].width)
  266. return &dv_profiles[i];
  267. return NULL;
  268. }
  269. void ff_dv_print_profiles(void *logctx, int loglevel)
  270. {
  271. int i;
  272. for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++) {
  273. const DVprofile *p = &dv_profiles[i];
  274. av_log(logctx, loglevel, "Frame size: %dx%d; pixel format: %s, "
  275. "framerate: %d/%d\n", p->width, p->height, av_get_pix_fmt_name(p->pix_fmt),
  276. p->time_base.den, p->time_base.num);
  277. }
  278. }