2 * Constants for DV codec
3 * Copyright (c) 2002 Fabrice Bellard
5 * This file is part of Libav.
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.
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.
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
24 * Constants for DV codec.
27 #include "libavutil/rational.h"
31 static DVwork_chunk work_chunks_dv25pal [1*12*27];
32 static DVwork_chunk work_chunks_dv25pal411[1*12*27];
33 static DVwork_chunk work_chunks_dv25ntsc [1*10*27];
34 static DVwork_chunk work_chunks_dv50pal [2*12*27];
35 static DVwork_chunk work_chunks_dv50ntsc [2*10*27];
36 static DVwork_chunk work_chunks_dv100palp [2*12*27];
37 static DVwork_chunk work_chunks_dv100ntscp[2*10*27];
38 static DVwork_chunk work_chunks_dv100pali [4*12*27];
39 static DVwork_chunk work_chunks_dv100ntsci[4*10*27];
41 static uint32_t dv_idct_factor_sd [2*2*22*64];
42 static uint32_t dv_idct_factor_hd1080[2*4*16*64];
43 static uint32_t dv_idct_factor_hd720 [2*4*16*64];
45 static const uint8_t dv_audio_shuffle525[10][9] = {
46 { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
47 { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
48 { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
49 { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
50 { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
52 { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
53 { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
54 { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
55 { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
56 { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
59 static const uint8_t dv_audio_shuffle625[12][9] = {
60 { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
61 { 6, 42, 78, 32, 68, 104, 22, 58, 94},
62 { 12, 48, 84, 2, 38, 74, 28, 64, 100},
63 { 18, 54, 90, 8, 44, 80, 34, 70, 106},
64 { 24, 60, 96, 14, 50, 86, 4, 40, 76},
65 { 30, 66, 102, 20, 56, 92, 10, 46, 82},
67 { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
68 { 7, 43, 79, 33, 69, 105, 23, 59, 95},
69 { 13, 49, 85, 3, 39, 75, 29, 65, 101},
70 { 19, 55, 91, 9, 45, 81, 35, 71, 107},
71 { 25, 61, 97, 15, 51, 87, 5, 41, 77},
72 { 31, 67, 103, 21, 57, 93, 11, 47, 83},
75 /* macroblock bit budgets */
76 static const uint8_t block_sizes_dv2550[8] = {
77 112, 112, 112, 112, 80, 80, 0, 0,
80 static const uint8_t block_sizes_dv100[8] = {
81 80, 80, 80, 80, 80, 80, 64, 64,
83 static const DVprofile dv_profiles[] = {
86 .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
89 .time_base = { 1001, 30000 },
93 .sar = {{8, 9}, {32, 27}},
94 .work_chunks = &work_chunks_dv25ntsc[0],
95 .idct_factor = &dv_idct_factor_sd[0],
96 .pix_fmt = PIX_FMT_YUV411P,
98 .block_sizes = block_sizes_dv2550,
100 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
101 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
102 .audio_shuffle = dv_audio_shuffle525,
106 .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
109 .time_base = { 1, 25 },
113 .sar = {{16, 15}, {64, 45}},
114 .work_chunks = &work_chunks_dv25pal[0],
115 .idct_factor = &dv_idct_factor_sd[0],
116 .pix_fmt = PIX_FMT_YUV420P,
118 .block_sizes = block_sizes_dv2550,
120 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
121 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
122 .audio_shuffle = dv_audio_shuffle625,
126 .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
129 .time_base = { 1, 25 },
133 .sar = {{16, 15}, {64, 45}},
134 .work_chunks = &work_chunks_dv25pal411[0],
135 .idct_factor = &dv_idct_factor_sd[0],
136 .pix_fmt = PIX_FMT_YUV411P,
138 .block_sizes = block_sizes_dv2550,
140 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
141 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
142 .audio_shuffle = dv_audio_shuffle625,
146 .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
147 .difseg_size = 10, /* also known as "DVCPRO50" */
149 .time_base = { 1001, 30000 },
153 .sar = {{8, 9}, {32, 27}},
154 .work_chunks = &work_chunks_dv50ntsc[0],
155 .idct_factor = &dv_idct_factor_sd[0],
156 .pix_fmt = PIX_FMT_YUV422P,
158 .block_sizes = block_sizes_dv2550,
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,
166 .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
167 .difseg_size = 12, /* also known as "DVCPRO50" */
169 .time_base = { 1, 25 },
173 .sar = {{16, 15}, {64, 45}},
174 .work_chunks = &work_chunks_dv50pal[0],
175 .idct_factor = &dv_idct_factor_sd[0],
176 .pix_fmt = PIX_FMT_YUV422P,
178 .block_sizes = block_sizes_dv2550,
180 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
181 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
182 .audio_shuffle = dv_audio_shuffle625,
186 .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
187 .difseg_size = 10, /* also known as "DVCPRO HD" */
189 .time_base = { 1001, 30000 },
193 .sar = {{1, 1}, {3, 2}},
194 .work_chunks = &work_chunks_dv100ntsci[0],
195 .idct_factor = &dv_idct_factor_hd1080[0],
196 .pix_fmt = PIX_FMT_YUV422P,
198 .block_sizes = block_sizes_dv100,
200 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
201 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
202 .audio_shuffle = dv_audio_shuffle525,
206 .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
207 .difseg_size = 12, /* also known as "DVCPRO HD" */
209 .time_base = { 1, 25 },
213 .sar = {{1, 1}, {4, 3}},
214 .work_chunks = &work_chunks_dv100pali[0],
215 .idct_factor = &dv_idct_factor_hd1080[0],
216 .pix_fmt = PIX_FMT_YUV422P,
218 .block_sizes = block_sizes_dv100,
220 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
221 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
222 .audio_shuffle = dv_audio_shuffle625,
226 .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
227 .difseg_size = 10, /* also known as "DVCPRO HD" */
229 .time_base = { 1001, 60000 },
233 .sar = {{1, 1}, {4, 3}},
234 .work_chunks = &work_chunks_dv100ntscp[0],
235 .idct_factor = &dv_idct_factor_hd720[0],
236 .pix_fmt = PIX_FMT_YUV422P,
238 .block_sizes = block_sizes_dv100,
240 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
241 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
242 .audio_shuffle = dv_audio_shuffle525,
246 .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
247 .difseg_size = 12, /* also known as "DVCPRO HD" */
249 .time_base = { 1, 50 },
253 .sar = {{1, 1}, {4, 3}},
254 .work_chunks = &work_chunks_dv100palp[0],
255 .idct_factor = &dv_idct_factor_hd720[0],
256 .pix_fmt = PIX_FMT_YUV422P,
258 .block_sizes = block_sizes_dv100,
260 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
261 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
262 .audio_shuffle = dv_audio_shuffle625,
266 .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
269 .time_base = { 1, 25 },
273 .sar = {{16, 15}, {64, 45}},
274 .work_chunks = &work_chunks_dv25pal[0],
275 .idct_factor = &dv_idct_factor_sd[0],
276 .pix_fmt = PIX_FMT_YUV420P,
278 .block_sizes = block_sizes_dv2550,
280 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
281 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
282 .audio_shuffle = dv_audio_shuffle625,
286 const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
287 const uint8_t* frame, unsigned buf_size)
291 if (buf_size < 80 * 5 + 48 + 4)
294 dsf = (frame[3] & 0x80) >> 7;
295 stype = frame[80 * 5 + 48 + 3] & 0x1f;
297 /* 576i50 25Mbps 4:1:1 is a special case */
298 if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
299 return &dv_profiles[2];
302 for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
303 if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
304 return &dv_profiles[i];
306 /* check if old sys matches and assumes corrupted input */
307 if (sys && buf_size == sys->frame_size)
313 const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec)
317 for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
318 if (codec->height == dv_profiles[i].height &&
319 codec->pix_fmt == dv_profiles[i].pix_fmt &&
320 codec->width == dv_profiles[i].width)
321 return &dv_profiles[i];