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 DVprofile dv_profiles[] = {
49 .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
52 .time_base = { 1001, 30000 },
56 .sar = {{8, 9}, {32, 27}},
57 .work_chunks = &work_chunks_dv25ntsc[0],
58 .idct_factor = &dv_idct_factor_sd[0],
59 .pix_fmt = PIX_FMT_YUV411P,
61 .block_sizes = block_sizes_dv2550,
63 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
64 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
65 .audio_shuffle = dv_audio_shuffle525,
69 .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
72 .time_base = { 1, 25 },
76 .sar = {{16, 15}, {64, 45}},
77 .work_chunks = &work_chunks_dv25pal[0],
78 .idct_factor = &dv_idct_factor_sd[0],
79 .pix_fmt = PIX_FMT_YUV420P,
81 .block_sizes = block_sizes_dv2550,
83 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
84 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
85 .audio_shuffle = dv_audio_shuffle625,
89 .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
92 .time_base = { 1, 25 },
96 .sar = {{16, 15}, {64, 45}},
97 .work_chunks = &work_chunks_dv25pal411[0],
98 .idct_factor = &dv_idct_factor_sd[0],
99 .pix_fmt = PIX_FMT_YUV411P,
101 .block_sizes = block_sizes_dv2550,
103 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
104 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
105 .audio_shuffle = dv_audio_shuffle625,
109 .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
110 .difseg_size = 10, /* also known as "DVCPRO50" */
112 .time_base = { 1001, 30000 },
116 .sar = {{8, 9}, {32, 27}},
117 .work_chunks = &work_chunks_dv50ntsc[0],
118 .idct_factor = &dv_idct_factor_sd[0],
119 .pix_fmt = PIX_FMT_YUV422P,
121 .block_sizes = block_sizes_dv2550,
123 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
124 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
125 .audio_shuffle = dv_audio_shuffle525,
129 .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
130 .difseg_size = 12, /* also known as "DVCPRO50" */
132 .time_base = { 1, 25 },
136 .sar = {{16, 15}, {64, 45}},
137 .work_chunks = &work_chunks_dv50pal[0],
138 .idct_factor = &dv_idct_factor_sd[0],
139 .pix_fmt = PIX_FMT_YUV422P,
141 .block_sizes = block_sizes_dv2550,
143 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
144 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
145 .audio_shuffle = dv_audio_shuffle625,
149 .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
150 .difseg_size = 10, /* also known as "DVCPRO HD" */
152 .time_base = { 1001, 30000 },
156 .sar = {{1, 1}, {3, 2}},
157 .work_chunks = &work_chunks_dv100ntsci[0],
158 .idct_factor = &dv_idct_factor_hd1080[0],
159 .pix_fmt = PIX_FMT_YUV422P,
161 .block_sizes = block_sizes_dv100,
163 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
164 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
165 .audio_shuffle = dv_audio_shuffle525,
169 .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
170 .difseg_size = 12, /* also known as "DVCPRO HD" */
172 .time_base = { 1, 25 },
176 .sar = {{1, 1}, {4, 3}},
177 .work_chunks = &work_chunks_dv100pali[0],
178 .idct_factor = &dv_idct_factor_hd1080[0],
179 .pix_fmt = PIX_FMT_YUV422P,
181 .block_sizes = block_sizes_dv100,
183 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
184 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
185 .audio_shuffle = dv_audio_shuffle625,
189 .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
190 .difseg_size = 10, /* also known as "DVCPRO HD" */
192 .time_base = { 1001, 60000 },
196 .sar = {{1, 1}, {4, 3}},
197 .work_chunks = &work_chunks_dv100ntscp[0],
198 .idct_factor = &dv_idct_factor_hd720[0],
199 .pix_fmt = PIX_FMT_YUV422P,
201 .block_sizes = block_sizes_dv100,
203 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
204 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
205 .audio_shuffle = dv_audio_shuffle525,
209 .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
210 .difseg_size = 12, /* also known as "DVCPRO HD" */
212 .time_base = { 1, 50 },
216 .sar = {{1, 1}, {4, 3}},
217 .work_chunks = &work_chunks_dv100palp[0],
218 .idct_factor = &dv_idct_factor_hd720[0],
219 .pix_fmt = PIX_FMT_YUV422P,
221 .block_sizes = block_sizes_dv100,
223 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
224 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
225 .audio_shuffle = dv_audio_shuffle625,
229 .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
232 .time_base = { 1, 25 },
236 .sar = {{16, 15}, {64, 45}},
237 .work_chunks = &work_chunks_dv25pal[0],
238 .idct_factor = &dv_idct_factor_sd[0],
239 .pix_fmt = PIX_FMT_YUV420P,
241 .block_sizes = block_sizes_dv2550,
243 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
244 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
245 .audio_shuffle = dv_audio_shuffle625,
249 const DVprofile* ff_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys,
250 const uint8_t* frame, unsigned buf_size)
254 int dsf = (frame[3] & 0x80) >> 7;
256 int stype = frame[80*5 + 48 + 3] & 0x1f;
258 /* 576i50 25Mbps 4:1:1 is a special case */
259 if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
260 return &dv_profiles[2];
263 if(codec && codec->codec_tag==AV_RL32("dvsd") && codec->width==720 && codec->height==576)
264 return &dv_profiles[1];
266 for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
267 if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
268 return &dv_profiles[i];
270 /* check if old sys matches and assumes corrupted input */
271 if (sys && buf_size == sys->frame_size)
277 const DVprofile* ff_dv_frame_profile(const DVprofile *sys,
278 const uint8_t* frame, unsigned buf_size)
280 return ff_dv_frame_profile2(NULL, sys, frame, buf_size);
283 const DVprofile* ff_dv_codec_profile(AVCodecContext* codec)
287 for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
288 if (codec->height == dv_profiles[i].height &&
289 codec->pix_fmt == dv_profiles[i].pix_fmt &&
290 codec->width == dv_profiles[i].width)
291 return &dv_profiles[i];