2 * This file is part of Libav.
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/common.h"
22 #include "libavutil/log.h"
23 #include "libavutil/pixdesc.h"
25 #include "dv_profile.h"
27 static DVwork_chunk work_chunks_dv25pal [1*12*27];
28 static DVwork_chunk work_chunks_dv25pal411[1*12*27];
29 static DVwork_chunk work_chunks_dv25ntsc [1*10*27];
30 static DVwork_chunk work_chunks_dv50pal [2*12*27];
31 static DVwork_chunk work_chunks_dv50ntsc [2*10*27];
32 static DVwork_chunk work_chunks_dv100palp [2*12*27];
33 static DVwork_chunk work_chunks_dv100ntscp[2*10*27];
34 static DVwork_chunk work_chunks_dv100pali [4*12*27];
35 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];
41 static const uint8_t dv_audio_shuffle525[10][9] = {
42 { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
43 { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
44 { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
45 { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
46 { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
48 { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
49 { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
50 { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
51 { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
52 { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
55 static const uint8_t dv_audio_shuffle625[12][9] = {
56 { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
57 { 6, 42, 78, 32, 68, 104, 22, 58, 94},
58 { 12, 48, 84, 2, 38, 74, 28, 64, 100},
59 { 18, 54, 90, 8, 44, 80, 34, 70, 106},
60 { 24, 60, 96, 14, 50, 86, 4, 40, 76},
61 { 30, 66, 102, 20, 56, 92, 10, 46, 82},
63 { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
64 { 7, 43, 79, 33, 69, 105, 23, 59, 95},
65 { 13, 49, 85, 3, 39, 75, 29, 65, 101},
66 { 19, 55, 91, 9, 45, 81, 35, 71, 107},
67 { 25, 61, 97, 15, 51, 87, 5, 41, 77},
68 { 31, 67, 103, 21, 57, 93, 11, 47, 83},
71 /* macroblock bit budgets */
72 static const uint8_t block_sizes_dv2550[8] = {
73 112, 112, 112, 112, 80, 80, 0, 0,
76 static const uint8_t block_sizes_dv100[8] = {
77 80, 80, 80, 80, 80, 80, 64, 64,
80 static const DVprofile dv_profiles[] = {
83 .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
86 .time_base = { 1001, 30000 },
90 .sar = {{8, 9}, {32, 27}},
91 .work_chunks = &work_chunks_dv25ntsc[0],
92 .idct_factor = &dv_idct_factor_sd[0],
93 .pix_fmt = AV_PIX_FMT_YUV411P,
95 .block_sizes = block_sizes_dv2550,
97 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
98 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
99 .audio_shuffle = dv_audio_shuffle525,
103 .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
106 .time_base = { 1, 25 },
110 .sar = {{16, 15}, {64, 45}},
111 .work_chunks = &work_chunks_dv25pal[0],
112 .idct_factor = &dv_idct_factor_sd[0],
113 .pix_fmt = AV_PIX_FMT_YUV420P,
115 .block_sizes = block_sizes_dv2550,
117 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
118 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
119 .audio_shuffle = dv_audio_shuffle625,
123 .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
126 .time_base = { 1, 25 },
130 .sar = {{16, 15}, {64, 45}},
131 .work_chunks = &work_chunks_dv25pal411[0],
132 .idct_factor = &dv_idct_factor_sd[0],
133 .pix_fmt = AV_PIX_FMT_YUV411P,
135 .block_sizes = block_sizes_dv2550,
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,
143 .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
144 .difseg_size = 10, /* also known as "DVCPRO50" */
146 .time_base = { 1001, 30000 },
150 .sar = {{8, 9}, {32, 27}},
151 .work_chunks = &work_chunks_dv50ntsc[0],
152 .idct_factor = &dv_idct_factor_sd[0],
153 .pix_fmt = AV_PIX_FMT_YUV422P,
155 .block_sizes = block_sizes_dv2550,
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,
163 .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
164 .difseg_size = 12, /* also known as "DVCPRO50" */
166 .time_base = { 1, 25 },
170 .sar = {{16, 15}, {64, 45}},
171 .work_chunks = &work_chunks_dv50pal[0],
172 .idct_factor = &dv_idct_factor_sd[0],
173 .pix_fmt = AV_PIX_FMT_YUV422P,
175 .block_sizes = block_sizes_dv2550,
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,
183 .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
184 .difseg_size = 10, /* also known as "DVCPRO HD" */
186 .time_base = { 1001, 30000 },
190 .sar = {{1, 1}, {3, 2}},
191 .work_chunks = &work_chunks_dv100ntsci[0],
192 .idct_factor = &dv_idct_factor_hd1080[0],
193 .pix_fmt = AV_PIX_FMT_YUV422P,
195 .block_sizes = block_sizes_dv100,
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,
203 .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
204 .difseg_size = 12, /* also known as "DVCPRO HD" */
206 .time_base = { 1, 25 },
210 .sar = {{1, 1}, {4, 3}},
211 .work_chunks = &work_chunks_dv100pali[0],
212 .idct_factor = &dv_idct_factor_hd1080[0],
213 .pix_fmt = AV_PIX_FMT_YUV422P,
215 .block_sizes = block_sizes_dv100,
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,
223 .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
224 .difseg_size = 10, /* also known as "DVCPRO HD" */
226 .time_base = { 1001, 60000 },
230 .sar = {{1, 1}, {4, 3}},
231 .work_chunks = &work_chunks_dv100ntscp[0],
232 .idct_factor = &dv_idct_factor_hd720[0],
233 .pix_fmt = AV_PIX_FMT_YUV422P,
235 .block_sizes = block_sizes_dv100,
237 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
238 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
239 .audio_shuffle = dv_audio_shuffle525,
243 .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
244 .difseg_size = 12, /* also known as "DVCPRO HD" */
246 .time_base = { 1, 50 },
250 .sar = {{1, 1}, {4, 3}},
251 .work_chunks = &work_chunks_dv100palp[0],
252 .idct_factor = &dv_idct_factor_hd720[0],
253 .pix_fmt = AV_PIX_FMT_YUV422P,
255 .block_sizes = block_sizes_dv100,
257 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
258 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
259 .audio_shuffle = dv_audio_shuffle625,
263 .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
266 .time_base = { 1, 25 },
270 .sar = {{16, 15}, {64, 45}},
271 .work_chunks = &work_chunks_dv25pal[0],
272 .idct_factor = &dv_idct_factor_sd[0],
273 .pix_fmt = AV_PIX_FMT_YUV420P,
275 .block_sizes = block_sizes_dv2550,
277 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
278 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
279 .audio_shuffle = dv_audio_shuffle625,
283 const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
284 const uint8_t* frame, unsigned buf_size)
288 if (buf_size < 80 * 5 + 48 + 4)
291 dsf = (frame[3] & 0x80) >> 7;
292 stype = frame[80 * 5 + 48 + 3] & 0x1f;
294 /* 576i50 25Mbps 4:1:1 is a special case */
295 if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
296 return &dv_profiles[2];
299 for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
300 if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
301 return &dv_profiles[i];
303 /* check if old sys matches and assumes corrupted input */
304 if (sys && buf_size == sys->frame_size)
310 const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec)
314 for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
315 if (codec->height == dv_profiles[i].height &&
316 codec->pix_fmt == dv_profiles[i].pix_fmt &&
317 codec->width == dv_profiles[i].width)
318 return &dv_profiles[i];
323 void ff_dv_print_profiles(void *logctx, int loglevel)
326 for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++) {
327 const DVprofile *p = &dv_profiles[i];
328 av_log(logctx, loglevel, "Frame size: %dx%d; pixel format: %s, "
329 "framerate: %d/%d\n", p->width, p->height, av_get_pix_fmt_name(p->pix_fmt),
330 p->time_base.den, p->time_base.num);