2 * Constants for DV codec
3 * Copyright (c) 2002 Fabrice Bellard
5 * This file is part of FFmpeg.
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.
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.
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
24 * Constants for DV codec.
27 #include "libavutil/rational.h"
28 #include "libavutil/intreadwrite.h"
32 static DVwork_chunk work_chunks_dv25pal [1*12*27];
33 static DVwork_chunk work_chunks_dv25pal411[1*12*27];
34 static DVwork_chunk work_chunks_dv25ntsc [1*10*27];
35 static DVwork_chunk work_chunks_dv50pal [2*12*27];
36 static DVwork_chunk work_chunks_dv50ntsc [2*10*27];
37 static DVwork_chunk work_chunks_dv100palp [2*12*27];
38 static DVwork_chunk work_chunks_dv100ntscp[2*10*27];
39 static DVwork_chunk work_chunks_dv100pali [4*12*27];
40 static DVwork_chunk work_chunks_dv100ntsci[4*10*27];
42 static uint32_t dv_idct_factor_sd [2*2*22*64];
43 static uint32_t dv_idct_factor_hd1080[2*4*16*64];
44 static uint32_t dv_idct_factor_hd720 [2*4*16*64];
46 static const uint8_t dv_audio_shuffle525[10][9] = {
47 { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
48 { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
49 { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
50 { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
51 { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
53 { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
54 { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
55 { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
56 { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
57 { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
60 static const uint8_t dv_audio_shuffle625[12][9] = {
61 { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
62 { 6, 42, 78, 32, 68, 104, 22, 58, 94},
63 { 12, 48, 84, 2, 38, 74, 28, 64, 100},
64 { 18, 54, 90, 8, 44, 80, 34, 70, 106},
65 { 24, 60, 96, 14, 50, 86, 4, 40, 76},
66 { 30, 66, 102, 20, 56, 92, 10, 46, 82},
68 { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
69 { 7, 43, 79, 33, 69, 105, 23, 59, 95},
70 { 13, 49, 85, 3, 39, 75, 29, 65, 101},
71 { 19, 55, 91, 9, 45, 81, 35, 71, 107},
72 { 25, 61, 97, 15, 51, 87, 5, 41, 77},
73 { 31, 67, 103, 21, 57, 93, 11, 47, 83},
76 /* macroblock bit budgets */
77 static const uint8_t block_sizes_dv2550[8] = {
78 112, 112, 112, 112, 80, 80, 0, 0,
81 static const uint8_t block_sizes_dv100[8] = {
82 80, 80, 80, 80, 80, 80, 64, 64,
84 static const DVprofile dv_profiles[] = {
87 .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
90 .time_base = { 1001, 30000 },
94 .sar = {{8, 9}, {32, 27}},
95 .work_chunks = &work_chunks_dv25ntsc[0],
96 .idct_factor = &dv_idct_factor_sd[0],
97 .pix_fmt = PIX_FMT_YUV411P,
99 .block_sizes = block_sizes_dv2550,
101 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
102 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
103 .audio_shuffle = dv_audio_shuffle525,
107 .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
110 .time_base = { 1, 25 },
114 .sar = {{16, 15}, {64, 45}},
115 .work_chunks = &work_chunks_dv25pal[0],
116 .idct_factor = &dv_idct_factor_sd[0],
117 .pix_fmt = PIX_FMT_YUV420P,
119 .block_sizes = block_sizes_dv2550,
121 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
122 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
123 .audio_shuffle = dv_audio_shuffle625,
127 .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
130 .time_base = { 1, 25 },
134 .sar = {{16, 15}, {64, 45}},
135 .work_chunks = &work_chunks_dv25pal411[0],
136 .idct_factor = &dv_idct_factor_sd[0],
137 .pix_fmt = PIX_FMT_YUV411P,
139 .block_sizes = block_sizes_dv2550,
141 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
142 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
143 .audio_shuffle = dv_audio_shuffle625,
147 .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
148 .difseg_size = 10, /* also known as "DVCPRO50" */
150 .time_base = { 1001, 30000 },
154 .sar = {{8, 9}, {32, 27}},
155 .work_chunks = &work_chunks_dv50ntsc[0],
156 .idct_factor = &dv_idct_factor_sd[0],
157 .pix_fmt = PIX_FMT_YUV422P,
159 .block_sizes = block_sizes_dv2550,
161 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
162 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
163 .audio_shuffle = dv_audio_shuffle525,
167 .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
168 .difseg_size = 12, /* also known as "DVCPRO50" */
170 .time_base = { 1, 25 },
174 .sar = {{16, 15}, {64, 45}},
175 .work_chunks = &work_chunks_dv50pal[0],
176 .idct_factor = &dv_idct_factor_sd[0],
177 .pix_fmt = PIX_FMT_YUV422P,
179 .block_sizes = block_sizes_dv2550,
181 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
182 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
183 .audio_shuffle = dv_audio_shuffle625,
187 .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
188 .difseg_size = 10, /* also known as "DVCPRO HD" */
190 .time_base = { 1001, 30000 },
194 .sar = {{1, 1}, {3, 2}},
195 .work_chunks = &work_chunks_dv100ntsci[0],
196 .idct_factor = &dv_idct_factor_hd1080[0],
197 .pix_fmt = PIX_FMT_YUV422P,
199 .block_sizes = block_sizes_dv100,
201 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
202 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
203 .audio_shuffle = dv_audio_shuffle525,
207 .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
208 .difseg_size = 12, /* also known as "DVCPRO HD" */
210 .time_base = { 1, 25 },
214 .sar = {{1, 1}, {4, 3}},
215 .work_chunks = &work_chunks_dv100pali[0],
216 .idct_factor = &dv_idct_factor_hd1080[0],
217 .pix_fmt = PIX_FMT_YUV422P,
219 .block_sizes = block_sizes_dv100,
221 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
222 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
223 .audio_shuffle = dv_audio_shuffle625,
227 .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
228 .difseg_size = 10, /* also known as "DVCPRO HD" */
230 .time_base = { 1001, 60000 },
234 .sar = {{1, 1}, {4, 3}},
235 .work_chunks = &work_chunks_dv100ntscp[0],
236 .idct_factor = &dv_idct_factor_hd720[0],
237 .pix_fmt = PIX_FMT_YUV422P,
239 .block_sizes = block_sizes_dv100,
241 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
242 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
243 .audio_shuffle = dv_audio_shuffle525,
247 .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
248 .difseg_size = 12, /* also known as "DVCPRO HD" */
250 .time_base = { 1, 50 },
254 .sar = {{1, 1}, {4, 3}},
255 .work_chunks = &work_chunks_dv100palp[0],
256 .idct_factor = &dv_idct_factor_hd720[0],
257 .pix_fmt = PIX_FMT_YUV422P,
259 .block_sizes = block_sizes_dv100,
261 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
262 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
263 .audio_shuffle = dv_audio_shuffle625,
267 .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
270 .time_base = { 1, 25 },
274 .sar = {{16, 15}, {64, 45}},
275 .work_chunks = &work_chunks_dv25pal[0],
276 .idct_factor = &dv_idct_factor_sd[0],
277 .pix_fmt = PIX_FMT_YUV420P,
279 .block_sizes = block_sizes_dv2550,
281 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
282 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
283 .audio_shuffle = dv_audio_shuffle625,
287 const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys,
288 const uint8_t* frame, unsigned buf_size)
292 if(buf_size < DV_PROFILE_BYTES)
295 dsf = (frame[3] & 0x80) >> 7;
296 stype = frame[80 * 5 + 48 + 3] & 0x1f;
298 /* 576i50 25Mbps 4:1:1 is a special case */
299 if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
300 return &dv_profiles[2];
303 if(stype == 0 && codec && codec->codec_tag==AV_RL32("dvsd") && codec->width==720 && codec->height==576)
304 return &dv_profiles[1];
306 for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
307 if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
308 return &dv_profiles[i];
310 /* check if old sys matches and assumes corrupted input */
311 if (sys && buf_size == sys->frame_size)
317 const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
318 const uint8_t* frame, unsigned buf_size)
320 return avpriv_dv_frame_profile2(NULL, sys, frame, buf_size);
323 const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec)
327 for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
328 if (codec->coded_height == dv_profiles[i].height &&
329 codec->pix_fmt == dv_profiles[i].pix_fmt &&
330 codec->coded_width == dv_profiles[i].width)
331 return &dv_profiles[i];