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.

323 lines
11KB

  1. /*
  2. * Constants for DV codec
  3. * Copyright (c) 2002 Fabrice Bellard
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Constants for DV codec.
  24. */
  25. #include "libavutil/rational.h"
  26. #include "avcodec.h"
  27. #include "dvdata.h"
  28. static DVwork_chunk work_chunks_dv25pal [1*12*27];
  29. static DVwork_chunk work_chunks_dv25pal411[1*12*27];
  30. static DVwork_chunk work_chunks_dv25ntsc [1*10*27];
  31. static DVwork_chunk work_chunks_dv50pal [2*12*27];
  32. static DVwork_chunk work_chunks_dv50ntsc [2*10*27];
  33. static DVwork_chunk work_chunks_dv100palp [2*12*27];
  34. static DVwork_chunk work_chunks_dv100ntscp[2*10*27];
  35. static DVwork_chunk work_chunks_dv100pali [4*12*27];
  36. static DVwork_chunk work_chunks_dv100ntsci[4*10*27];
  37. static uint32_t dv_idct_factor_sd [2*2*22*64];
  38. static uint32_t dv_idct_factor_hd1080[2*4*16*64];
  39. static uint32_t dv_idct_factor_hd720 [2*4*16*64];
  40. static const uint8_t dv_audio_shuffle525[10][9] = {
  41. { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
  42. { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
  43. { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
  44. { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
  45. { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
  46. { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
  47. { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
  48. { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
  49. { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
  50. { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
  51. };
  52. static const uint8_t dv_audio_shuffle625[12][9] = {
  53. { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
  54. { 6, 42, 78, 32, 68, 104, 22, 58, 94},
  55. { 12, 48, 84, 2, 38, 74, 28, 64, 100},
  56. { 18, 54, 90, 8, 44, 80, 34, 70, 106},
  57. { 24, 60, 96, 14, 50, 86, 4, 40, 76},
  58. { 30, 66, 102, 20, 56, 92, 10, 46, 82},
  59. { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
  60. { 7, 43, 79, 33, 69, 105, 23, 59, 95},
  61. { 13, 49, 85, 3, 39, 75, 29, 65, 101},
  62. { 19, 55, 91, 9, 45, 81, 35, 71, 107},
  63. { 25, 61, 97, 15, 51, 87, 5, 41, 77},
  64. { 31, 67, 103, 21, 57, 93, 11, 47, 83},
  65. };
  66. /* macroblock bit budgets */
  67. static const uint8_t block_sizes_dv2550[8] = {
  68. 112, 112, 112, 112, 80, 80, 0, 0,
  69. };
  70. static const uint8_t block_sizes_dv100[8] = {
  71. 80, 80, 80, 80, 80, 80, 64, 64,
  72. };
  73. static const DVprofile dv_profiles[] = {
  74. { .dsf = 0,
  75. .video_stype = 0x0,
  76. .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
  77. .difseg_size = 10,
  78. .n_difchan = 1,
  79. .time_base = { 1001, 30000 },
  80. .ltc_divisor = 30,
  81. .height = 480,
  82. .width = 720,
  83. .sar = {{8, 9}, {32, 27}},
  84. .work_chunks = &work_chunks_dv25ntsc[0],
  85. .idct_factor = &dv_idct_factor_sd[0],
  86. .pix_fmt = PIX_FMT_YUV411P,
  87. .bpm = 6,
  88. .block_sizes = block_sizes_dv2550,
  89. .audio_stride = 90,
  90. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  91. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  92. .audio_shuffle = dv_audio_shuffle525,
  93. },
  94. { .dsf = 1,
  95. .video_stype = 0x0,
  96. .frame_size = 144000, /* IEC 61834 - 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. .work_chunks = &work_chunks_dv25pal[0],
  105. .idct_factor = &dv_idct_factor_sd[0],
  106. .pix_fmt = PIX_FMT_YUV420P,
  107. .bpm = 6,
  108. .block_sizes = block_sizes_dv2550,
  109. .audio_stride = 108,
  110. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  111. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  112. .audio_shuffle = dv_audio_shuffle625,
  113. },
  114. { .dsf = 1,
  115. .video_stype = 0x0,
  116. .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
  117. .difseg_size = 12,
  118. .n_difchan = 1,
  119. .time_base = { 1, 25 },
  120. .ltc_divisor = 25,
  121. .height = 576,
  122. .width = 720,
  123. .sar = {{16, 15}, {64, 45}},
  124. .work_chunks = &work_chunks_dv25pal411[0],
  125. .idct_factor = &dv_idct_factor_sd[0],
  126. .pix_fmt = PIX_FMT_YUV411P,
  127. .bpm = 6,
  128. .block_sizes = block_sizes_dv2550,
  129. .audio_stride = 108,
  130. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  131. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  132. .audio_shuffle = dv_audio_shuffle625,
  133. },
  134. { .dsf = 0,
  135. .video_stype = 0x4,
  136. .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
  137. .difseg_size = 10, /* also known as "DVCPRO50" */
  138. .n_difchan = 2,
  139. .time_base = { 1001, 30000 },
  140. .ltc_divisor = 30,
  141. .height = 480,
  142. .width = 720,
  143. .sar = {{8, 9}, {32, 27}},
  144. .work_chunks = &work_chunks_dv50ntsc[0],
  145. .idct_factor = &dv_idct_factor_sd[0],
  146. .pix_fmt = PIX_FMT_YUV422P,
  147. .bpm = 6,
  148. .block_sizes = block_sizes_dv2550,
  149. .audio_stride = 90,
  150. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  151. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  152. .audio_shuffle = dv_audio_shuffle525,
  153. },
  154. { .dsf = 1,
  155. .video_stype = 0x4,
  156. .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
  157. .difseg_size = 12, /* also known as "DVCPRO50" */
  158. .n_difchan = 2,
  159. .time_base = { 1, 25 },
  160. .ltc_divisor = 25,
  161. .height = 576,
  162. .width = 720,
  163. .sar = {{16, 15}, {64, 45}},
  164. .work_chunks = &work_chunks_dv50pal[0],
  165. .idct_factor = &dv_idct_factor_sd[0],
  166. .pix_fmt = PIX_FMT_YUV422P,
  167. .bpm = 6,
  168. .block_sizes = block_sizes_dv2550,
  169. .audio_stride = 108,
  170. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  171. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  172. .audio_shuffle = dv_audio_shuffle625,
  173. },
  174. { .dsf = 0,
  175. .video_stype = 0x14,
  176. .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
  177. .difseg_size = 10, /* also known as "DVCPRO HD" */
  178. .n_difchan = 4,
  179. .time_base = { 1001, 30000 },
  180. .ltc_divisor = 30,
  181. .height = 1080,
  182. .width = 1280,
  183. .sar = {{1, 1}, {3, 2}},
  184. .work_chunks = &work_chunks_dv100ntsci[0],
  185. .idct_factor = &dv_idct_factor_hd1080[0],
  186. .pix_fmt = PIX_FMT_YUV422P,
  187. .bpm = 8,
  188. .block_sizes = block_sizes_dv100,
  189. .audio_stride = 90,
  190. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  191. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  192. .audio_shuffle = dv_audio_shuffle525,
  193. },
  194. { .dsf = 1,
  195. .video_stype = 0x14,
  196. .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
  197. .difseg_size = 12, /* also known as "DVCPRO HD" */
  198. .n_difchan = 4,
  199. .time_base = { 1, 25 },
  200. .ltc_divisor = 25,
  201. .height = 1080,
  202. .width = 1440,
  203. .sar = {{1, 1}, {4, 3}},
  204. .work_chunks = &work_chunks_dv100pali[0],
  205. .idct_factor = &dv_idct_factor_hd1080[0],
  206. .pix_fmt = PIX_FMT_YUV422P,
  207. .bpm = 8,
  208. .block_sizes = block_sizes_dv100,
  209. .audio_stride = 108,
  210. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  211. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  212. .audio_shuffle = dv_audio_shuffle625,
  213. },
  214. { .dsf = 0,
  215. .video_stype = 0x18,
  216. .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
  217. .difseg_size = 10, /* also known as "DVCPRO HD" */
  218. .n_difchan = 2,
  219. .time_base = { 1001, 60000 },
  220. .ltc_divisor = 60,
  221. .height = 720,
  222. .width = 960,
  223. .sar = {{1, 1}, {4, 3}},
  224. .work_chunks = &work_chunks_dv100ntscp[0],
  225. .idct_factor = &dv_idct_factor_hd720[0],
  226. .pix_fmt = PIX_FMT_YUV422P,
  227. .bpm = 8,
  228. .block_sizes = block_sizes_dv100,
  229. .audio_stride = 90,
  230. .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
  231. .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
  232. .audio_shuffle = dv_audio_shuffle525,
  233. },
  234. { .dsf = 1,
  235. .video_stype = 0x18,
  236. .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
  237. .difseg_size = 12, /* also known as "DVCPRO HD" */
  238. .n_difchan = 2,
  239. .time_base = { 1, 50 },
  240. .ltc_divisor = 50,
  241. .height = 720,
  242. .width = 960,
  243. .sar = {{1, 1}, {4, 3}},
  244. .work_chunks = &work_chunks_dv100palp[0],
  245. .idct_factor = &dv_idct_factor_hd720[0],
  246. .pix_fmt = PIX_FMT_YUV422P,
  247. .bpm = 8,
  248. .block_sizes = block_sizes_dv100,
  249. .audio_stride = 90,
  250. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  251. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  252. .audio_shuffle = dv_audio_shuffle625,
  253. },
  254. { .dsf = 1,
  255. .video_stype = 0x1,
  256. .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
  257. .difseg_size = 12,
  258. .n_difchan = 1,
  259. .time_base = { 1, 25 },
  260. .ltc_divisor = 25,
  261. .height = 576,
  262. .width = 720,
  263. .sar = {{16, 15}, {64, 45}},
  264. .work_chunks = &work_chunks_dv25pal[0],
  265. .idct_factor = &dv_idct_factor_sd[0],
  266. .pix_fmt = PIX_FMT_YUV420P,
  267. .bpm = 6,
  268. .block_sizes = block_sizes_dv2550,
  269. .audio_stride = 108,
  270. .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
  271. .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
  272. .audio_shuffle = dv_audio_shuffle625,
  273. }
  274. };
  275. const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
  276. const uint8_t* frame, unsigned buf_size)
  277. {
  278. int i;
  279. int dsf = (frame[3] & 0x80) >> 7;
  280. int stype = frame[80*5 + 48 + 3] & 0x1f;
  281. /* 576i50 25Mbps 4:1:1 is a special case */
  282. if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
  283. return &dv_profiles[2];
  284. }
  285. for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
  286. if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
  287. return &dv_profiles[i];
  288. /* check if old sys matches and assumes corrupted input */
  289. if (sys && buf_size == sys->frame_size)
  290. return sys;
  291. return NULL;
  292. }
  293. const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec)
  294. {
  295. int i;
  296. for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
  297. if (codec->height == dv_profiles[i].height &&
  298. codec->pix_fmt == dv_profiles[i].pix_fmt &&
  299. codec->width == dv_profiles[i].width)
  300. return &dv_profiles[i];
  301. return NULL;
  302. }