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"
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 DVprofile dv_profiles[] = {
48 .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
51 .time_base = { 1001, 30000 },
55 .sar = {{8, 9}, {32, 27}},
56 .work_chunks = &work_chunks_dv25ntsc[0],
57 .idct_factor = &dv_idct_factor_sd[0],
58 .pix_fmt = PIX_FMT_YUV411P,
60 .block_sizes = block_sizes_dv2550,
62 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
63 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
64 .audio_shuffle = dv_audio_shuffle525,
68 .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
71 .time_base = { 1, 25 },
75 .sar = {{16, 15}, {64, 45}},
76 .work_chunks = &work_chunks_dv25pal[0],
77 .idct_factor = &dv_idct_factor_sd[0],
78 .pix_fmt = PIX_FMT_YUV420P,
80 .block_sizes = block_sizes_dv2550,
82 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
83 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
84 .audio_shuffle = dv_audio_shuffle625,
88 .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
91 .time_base = { 1, 25 },
95 .sar = {{16, 15}, {64, 45}},
96 .work_chunks = &work_chunks_dv25pal411[0],
97 .idct_factor = &dv_idct_factor_sd[0],
98 .pix_fmt = PIX_FMT_YUV411P,
100 .block_sizes = block_sizes_dv2550,
102 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
103 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
104 .audio_shuffle = dv_audio_shuffle625,
108 .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
109 .difseg_size = 10, /* also known as "DVCPRO50" */
111 .time_base = { 1001, 30000 },
115 .sar = {{8, 9}, {32, 27}},
116 .work_chunks = &work_chunks_dv50ntsc[0],
117 .idct_factor = &dv_idct_factor_sd[0],
118 .pix_fmt = PIX_FMT_YUV422P,
120 .block_sizes = block_sizes_dv2550,
122 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
123 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
124 .audio_shuffle = dv_audio_shuffle525,
128 .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
129 .difseg_size = 12, /* also known as "DVCPRO50" */
131 .time_base = { 1, 25 },
135 .sar = {{16, 15}, {64, 45}},
136 .work_chunks = &work_chunks_dv50pal[0],
137 .idct_factor = &dv_idct_factor_sd[0],
138 .pix_fmt = PIX_FMT_YUV422P,
140 .block_sizes = block_sizes_dv2550,
142 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
143 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
144 .audio_shuffle = dv_audio_shuffle625,
148 .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
149 .difseg_size = 10, /* also known as "DVCPRO HD" */
151 .time_base = { 1001, 30000 },
155 .sar = {{1, 1}, {3, 2}},
156 .work_chunks = &work_chunks_dv100ntsci[0],
157 .idct_factor = &dv_idct_factor_hd1080[0],
158 .pix_fmt = PIX_FMT_YUV422P,
160 .block_sizes = block_sizes_dv100,
162 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
163 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
164 .audio_shuffle = dv_audio_shuffle525,
168 .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
169 .difseg_size = 12, /* also known as "DVCPRO HD" */
171 .time_base = { 1, 25 },
175 .sar = {{1, 1}, {4, 3}},
176 .work_chunks = &work_chunks_dv100pali[0],
177 .idct_factor = &dv_idct_factor_hd1080[0],
178 .pix_fmt = PIX_FMT_YUV422P,
180 .block_sizes = block_sizes_dv100,
182 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
183 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
184 .audio_shuffle = dv_audio_shuffle625,
188 .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
189 .difseg_size = 10, /* also known as "DVCPRO HD" */
191 .time_base = { 1001, 60000 },
195 .sar = {{1, 1}, {4, 3}},
196 .work_chunks = &work_chunks_dv100ntscp[0],
197 .idct_factor = &dv_idct_factor_hd720[0],
198 .pix_fmt = PIX_FMT_YUV422P,
200 .block_sizes = block_sizes_dv100,
202 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
203 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
204 .audio_shuffle = dv_audio_shuffle525,
208 .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
209 .difseg_size = 12, /* also known as "DVCPRO HD" */
211 .time_base = { 1, 50 },
215 .sar = {{1, 1}, {4, 3}},
216 .work_chunks = &work_chunks_dv100palp[0],
217 .idct_factor = &dv_idct_factor_hd720[0],
218 .pix_fmt = PIX_FMT_YUV422P,
220 .block_sizes = block_sizes_dv100,
222 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
223 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
224 .audio_shuffle = dv_audio_shuffle625,
228 .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
231 .time_base = { 1, 25 },
235 .sar = {{16, 15}, {64, 45}},
236 .work_chunks = &work_chunks_dv25pal[0],
237 .idct_factor = &dv_idct_factor_sd[0],
238 .pix_fmt = PIX_FMT_YUV420P,
240 .block_sizes = block_sizes_dv2550,
242 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
243 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
244 .audio_shuffle = dv_audio_shuffle625,
248 const DVprofile* ff_dv_frame_profile(const DVprofile *sys,
249 const uint8_t* frame, unsigned buf_size)
253 int dsf = (frame[3] & 0x80) >> 7;
255 int stype = frame[80*5 + 48 + 3] & 0x1f;
257 /* 576i50 25Mbps 4:1:1 is a special case */
258 if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
259 return &dv_profiles[2];
262 for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
263 if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
264 return &dv_profiles[i];
266 /* check if old sys matches and assumes corrupted input */
267 if (sys && buf_size == sys->frame_size)
273 const DVprofile* ff_dv_codec_profile(AVCodecContext* codec)
277 for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
278 if (codec->height == dv_profiles[i].height &&
279 codec->pix_fmt == dv_profiles[i].pix_fmt &&
280 codec->width == dv_profiles[i].width)
281 return &dv_profiles[i];