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.

302 lines
12KB

  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 "config.h"
  19. #include <stdint.h>
  20. #include "libavutil/common.h"
  21. #include "libavutil/log.h"
  22. #include "libavutil/pixdesc.h"
  23. #include "avcodec.h"
  24. #include "dv_profile.h"
  25. #include "dv_profile_internal.h"
  26. #if CONFIG_DVPROFILE
  27. static const uint8_t dv_audio_shuffle525[10][9] = {
  28. { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
  29. { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
  30. { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
  31. { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
  32. { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
  33. { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
  34. { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
  35. { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
  36. { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
  37. { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
  38. };
  39. static const uint8_t dv_audio_shuffle625[12][9] = {
  40. { 0, 36, 72, 26, 62, 98, 16, 52, 88 }, /* 1st channel */
  41. { 6, 42, 78, 32, 68, 104, 22, 58, 94 },
  42. { 12, 48, 84, 2, 38, 74, 28, 64, 100 },
  43. { 18, 54, 90, 8, 44, 80, 34, 70, 106 },
  44. { 24, 60, 96, 14, 50, 86, 4, 40, 76 },
  45. { 30, 66, 102, 20, 56, 92, 10, 46, 82 },
  46. { 1, 37, 73, 27, 63, 99, 17, 53, 89 }, /* 2nd channel */
  47. { 7, 43, 79, 33, 69, 105, 23, 59, 95 },
  48. { 13, 49, 85, 3, 39, 75, 29, 65, 101 },
  49. { 19, 55, 91, 9, 45, 81, 35, 71, 107 },
  50. { 25, 61, 97, 15, 51, 87, 5, 41, 77 },
  51. { 31, 67, 103, 21, 57, 93, 11, 47, 83 },
  52. };
  53. /* macroblock bit budgets */
  54. static const uint8_t block_sizes_dv2550[8] = {
  55. 112, 112, 112, 112, 80, 80, 0, 0,
  56. };
  57. static const uint8_t block_sizes_dv100[8] = {
  58. 80, 80, 80, 80, 80, 80, 64, 64,
  59. };
  60. static const AVDVProfile dv_profiles[] = {
  61. { .dsf = 0,
  62. .video_stype = 0x0,
  63. .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
  64. .difseg_size = 10,
  65. .n_difchan = 1,
  66. .time_base = { 1001, 30000 },
  67. .ltc_divisor = 30,
  68. .height = 480,
  69. .width = 720,
  70. .sar = { { 8, 9 }, { 32, 27 } },
  71. .pix_fmt = AV_PIX_FMT_YUV411P,
  72. .bpm = 6,
  73. .block_sizes = block_sizes_dv2550,
  74. .audio_stride = 90,
  75. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  76. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  77. .audio_shuffle = dv_audio_shuffle525, },
  78. { .dsf = 1,
  79. .video_stype = 0x0,
  80. .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
  81. .difseg_size = 12,
  82. .n_difchan = 1,
  83. .time_base = { 1, 25 },
  84. .ltc_divisor = 25,
  85. .height = 576,
  86. .width = 720,
  87. .sar = { { 16, 15 }, { 64, 45 } },
  88. .pix_fmt = AV_PIX_FMT_YUV420P,
  89. .bpm = 6,
  90. .block_sizes = block_sizes_dv2550,
  91. .audio_stride = 108,
  92. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  93. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  94. .audio_shuffle = dv_audio_shuffle625, },
  95. { .dsf = 1,
  96. .video_stype = 0x0,
  97. .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
  98. .difseg_size = 12,
  99. .n_difchan = 1,
  100. .time_base = { 1, 25 },
  101. .ltc_divisor = 25,
  102. .height = 576,
  103. .width = 720,
  104. .sar = { { 16, 15 }, { 64, 45 } },
  105. .pix_fmt = AV_PIX_FMT_YUV411P,
  106. .bpm = 6,
  107. .block_sizes = block_sizes_dv2550,
  108. .audio_stride = 108,
  109. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  110. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  111. .audio_shuffle = dv_audio_shuffle625, },
  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. { .dsf = 1,
  130. .video_stype = 0x4,
  131. .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
  132. .difseg_size = 12, /* also known as "DVCPRO50" */
  133. .n_difchan = 2,
  134. .time_base = { 1, 25 },
  135. .ltc_divisor = 25,
  136. .height = 576,
  137. .width = 720,
  138. .sar = { { 16, 15 }, { 64, 45 } },
  139. .pix_fmt = AV_PIX_FMT_YUV422P,
  140. .bpm = 6,
  141. .block_sizes = block_sizes_dv2550,
  142. .audio_stride = 108,
  143. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  144. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  145. .audio_shuffle = dv_audio_shuffle625, },
  146. { .dsf = 0,
  147. .video_stype = 0x14,
  148. .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
  149. .difseg_size = 10, /* also known as "DVCPRO HD" */
  150. .n_difchan = 4,
  151. .time_base = { 1001, 30000 },
  152. .ltc_divisor = 30,
  153. .height = 1080,
  154. .width = 1280,
  155. .sar = { { 1, 1 }, { 3, 2 } },
  156. .pix_fmt = AV_PIX_FMT_YUV422P,
  157. .bpm = 8,
  158. .block_sizes = block_sizes_dv100,
  159. .audio_stride = 90,
  160. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  161. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  162. .audio_shuffle = dv_audio_shuffle525, },
  163. { .dsf = 1,
  164. .video_stype = 0x14,
  165. .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
  166. .difseg_size = 12, /* also known as "DVCPRO HD" */
  167. .n_difchan = 4,
  168. .time_base = { 1, 25 },
  169. .ltc_divisor = 25,
  170. .height = 1080,
  171. .width = 1440,
  172. .sar = { { 1, 1 }, { 4, 3 } },
  173. .pix_fmt = AV_PIX_FMT_YUV422P,
  174. .bpm = 8,
  175. .block_sizes = block_sizes_dv100,
  176. .audio_stride = 108,
  177. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  178. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  179. .audio_shuffle = dv_audio_shuffle625, },
  180. { .dsf = 0,
  181. .video_stype = 0x18,
  182. .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
  183. .difseg_size = 10, /* also known as "DVCPRO HD" */
  184. .n_difchan = 2,
  185. .time_base = { 1001, 60000 },
  186. .ltc_divisor = 60,
  187. .height = 720,
  188. .width = 960,
  189. .sar = { { 1, 1 }, { 4, 3 } },
  190. .pix_fmt = AV_PIX_FMT_YUV422P,
  191. .bpm = 8,
  192. .block_sizes = block_sizes_dv100,
  193. .audio_stride = 90,
  194. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  195. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  196. .audio_shuffle = dv_audio_shuffle525, },
  197. { .dsf = 1,
  198. .video_stype = 0x18,
  199. .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
  200. .difseg_size = 12, /* also known as "DVCPRO HD" */
  201. .n_difchan = 2,
  202. .time_base = { 1, 50 },
  203. .ltc_divisor = 50,
  204. .height = 720,
  205. .width = 960,
  206. .sar = { { 1, 1 }, { 4, 3 } },
  207. .pix_fmt = AV_PIX_FMT_YUV422P,
  208. .bpm = 8,
  209. .block_sizes = block_sizes_dv100,
  210. .audio_stride = 90,
  211. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  212. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  213. .audio_shuffle = dv_audio_shuffle625, },
  214. { .dsf = 1,
  215. .video_stype = 0x1,
  216. .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
  217. .difseg_size = 12,
  218. .n_difchan = 1,
  219. .time_base = { 1, 25 },
  220. .ltc_divisor = 25,
  221. .height = 576,
  222. .width = 720,
  223. .sar = { { 16, 15 }, { 64, 45 } },
  224. .pix_fmt = AV_PIX_FMT_YUV420P,
  225. .bpm = 6,
  226. .block_sizes = block_sizes_dv2550,
  227. .audio_stride = 108,
  228. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  229. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  230. .audio_shuffle = dv_audio_shuffle625, }
  231. };
  232. void ff_dv_print_profiles(void *logctx, int loglevel)
  233. {
  234. int i;
  235. for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++) {
  236. const AVDVProfile *p = &dv_profiles[i];
  237. av_log(logctx, loglevel,
  238. "Frame size: %dx%d; pixel format: %s, framerate: %d/%d\n",
  239. p->width, p->height, av_get_pix_fmt_name(p->pix_fmt),
  240. p->time_base.den, p->time_base.num);
  241. }
  242. }
  243. #endif /* CONFIG_DVPROFILE */
  244. const AVDVProfile *av_dv_frame_profile(const AVDVProfile *sys,
  245. const uint8_t *frame, unsigned buf_size)
  246. {
  247. #if CONFIG_DVPROFILE
  248. int i, dsf, stype;
  249. if (buf_size < 80 * 5 + 48 + 4)
  250. return NULL;
  251. dsf = (frame[3] & 0x80) >> 7;
  252. stype = frame[80 * 5 + 48 + 3] & 0x1f;
  253. /* 576i50 25Mbps 4:1:1 is a special case */
  254. if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */)
  255. return &dv_profiles[2];
  256. for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
  257. if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
  258. return &dv_profiles[i];
  259. /* check if old sys matches and assumes corrupted input */
  260. if (sys && buf_size == sys->frame_size)
  261. return sys;
  262. #endif
  263. return NULL;
  264. }
  265. const AVDVProfile *av_dv_codec_profile(int width, int height,
  266. enum AVPixelFormat pix_fmt)
  267. {
  268. #if CONFIG_DVPROFILE
  269. int i;
  270. for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
  271. if (height == dv_profiles[i].height &&
  272. pix_fmt == dv_profiles[i].pix_fmt &&
  273. width == dv_profiles[i].width)
  274. return &dv_profiles[i];
  275. #endif
  276. return NULL;
  277. }