]> git.sesse.net Git - ffmpeg/blob - libavcodec/dvdata.c
Merge remote-tracking branch 'mans/ac3'
[ffmpeg] / libavcodec / dvdata.c
1 /*
2  * Constants for DV codec
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21
22 /**
23  * @file
24  * Constants for DV codec.
25  */
26
27 #include "libavutil/rational.h"
28 #include "libavutil/intreadwrite.h"
29 #include "avcodec.h"
30 #include "dvdata.h"
31
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];
41
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];
45
46 static const DVprofile dv_profiles[] = {
47     { .dsf = 0,
48       .video_stype = 0x0,
49       .frame_size = 120000,        /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
50       .difseg_size = 10,
51       .n_difchan = 1,
52       .time_base = { 1001, 30000 },
53       .ltc_divisor = 30,
54       .height = 480,
55       .width = 720,
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,
60       .bpm = 6,
61       .block_sizes = block_sizes_dv2550,
62       .audio_stride = 90,
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,
66     },
67     { .dsf = 1,
68       .video_stype = 0x0,
69       .frame_size = 144000,        /* IEC 61834 - 625/50 (PAL) */
70       .difseg_size = 12,
71       .n_difchan = 1,
72       .time_base = { 1, 25 },
73       .ltc_divisor = 25,
74       .height = 576,
75       .width = 720,
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,
80       .bpm = 6,
81       .block_sizes = block_sizes_dv2550,
82       .audio_stride = 108,
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,
86     },
87     { .dsf = 1,
88       .video_stype = 0x0,
89       .frame_size = 144000,        /* SMPTE-314M - 625/50 (PAL) */
90       .difseg_size = 12,
91       .n_difchan = 1,
92       .time_base = { 1, 25 },
93       .ltc_divisor = 25,
94       .height = 576,
95       .width = 720,
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,
100       .bpm = 6,
101       .block_sizes = block_sizes_dv2550,
102       .audio_stride = 108,
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,
106     },
107     { .dsf = 0,
108       .video_stype = 0x4,
109       .frame_size = 240000,        /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
110       .difseg_size = 10,           /* also known as "DVCPRO50" */
111       .n_difchan = 2,
112       .time_base = { 1001, 30000 },
113       .ltc_divisor = 30,
114       .height = 480,
115       .width = 720,
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,
120       .bpm = 6,
121       .block_sizes = block_sizes_dv2550,
122       .audio_stride = 90,
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,
126     },
127     { .dsf = 1,
128       .video_stype = 0x4,
129       .frame_size = 288000,        /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
130       .difseg_size = 12,           /* also known as "DVCPRO50" */
131       .n_difchan = 2,
132       .time_base = { 1, 25 },
133       .ltc_divisor = 25,
134       .height = 576,
135       .width = 720,
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,
140       .bpm = 6,
141       .block_sizes = block_sizes_dv2550,
142       .audio_stride = 108,
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,
146     },
147     { .dsf = 0,
148       .video_stype = 0x14,
149       .frame_size = 480000,        /* SMPTE-370M - 1080i60 100 Mbps */
150       .difseg_size = 10,           /* also known as "DVCPRO HD" */
151       .n_difchan = 4,
152       .time_base = { 1001, 30000 },
153       .ltc_divisor = 30,
154       .height = 1080,
155       .width = 1280,
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,
160       .bpm = 8,
161       .block_sizes = block_sizes_dv100,
162       .audio_stride = 90,
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,
166     },
167     { .dsf = 1,
168       .video_stype = 0x14,
169       .frame_size = 576000,        /* SMPTE-370M - 1080i50 100 Mbps */
170       .difseg_size = 12,           /* also known as "DVCPRO HD" */
171       .n_difchan = 4,
172       .time_base = { 1, 25 },
173       .ltc_divisor = 25,
174       .height = 1080,
175       .width = 1440,
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,
180       .bpm = 8,
181       .block_sizes = block_sizes_dv100,
182       .audio_stride = 108,
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,
186     },
187     { .dsf = 0,
188       .video_stype = 0x18,
189       .frame_size = 240000,        /* SMPTE-370M - 720p60 100 Mbps */
190       .difseg_size = 10,           /* also known as "DVCPRO HD" */
191       .n_difchan = 2,
192       .time_base = { 1001, 60000 },
193       .ltc_divisor = 60,
194       .height = 720,
195       .width = 960,
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,
200       .bpm = 8,
201       .block_sizes = block_sizes_dv100,
202       .audio_stride = 90,
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,
206     },
207     { .dsf = 1,
208       .video_stype = 0x18,
209       .frame_size = 288000,        /* SMPTE-370M - 720p50 100 Mbps */
210       .difseg_size = 12,           /* also known as "DVCPRO HD" */
211       .n_difchan = 2,
212       .time_base = { 1, 50 },
213       .ltc_divisor = 50,
214       .height = 720,
215       .width = 960,
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,
220       .bpm = 8,
221       .block_sizes = block_sizes_dv100,
222       .audio_stride = 90,
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,
226     },
227     { .dsf = 1,
228       .video_stype = 0x1,
229       .frame_size = 144000,        /* IEC 61883-5 - 625/50 (PAL) */
230       .difseg_size = 12,
231       .n_difchan = 1,
232       .time_base = { 1, 25 },
233       .ltc_divisor = 25,
234       .height = 576,
235       .width = 720,
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,
240       .bpm = 6,
241       .block_sizes = block_sizes_dv2550,
242       .audio_stride = 108,
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,
246     }
247 };
248
249 const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys,
250                                   const uint8_t* frame, unsigned buf_size)
251 {
252    int i, dsf, stype;
253
254    if(buf_size < DV_PROFILE_BYTES)
255        return NULL;
256
257    dsf = (frame[3] & 0x80) >> 7;
258    stype = frame[80*5 + 48 + 3] & 0x1f;
259
260    /* 576i50 25Mbps 4:1:1 is a special case */
261    if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
262        return &dv_profiles[2];
263    }
264
265    if(codec && codec->codec_tag==AV_RL32("dvsd") &&  codec->width==720 && codec->height==576)
266        return &dv_profiles[1];
267
268    for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
269        if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
270            return &dv_profiles[i];
271
272    /* check if old sys matches and assumes corrupted input */
273    if (sys && buf_size == sys->frame_size)
274        return sys;
275
276    return NULL;
277 }
278
279 const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
280                                   const uint8_t* frame, unsigned buf_size)
281 {
282     return avpriv_dv_frame_profile2(NULL, sys, frame, buf_size);
283 }
284
285 const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec)
286 {
287     int i;
288
289     for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
290        if (codec->height  == dv_profiles[i].height  &&
291            codec->pix_fmt == dv_profiles[i].pix_fmt &&
292            codec->width   == dv_profiles[i].width)
293                return &dv_profiles[i];
294
295     return NULL;
296 }
297