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.

298 lines
10KB

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