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.

286 lines
9.7KB

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