dvdata.c
Go to the documentation of this file.
1 /*
2  * Constants for DV codec
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
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.
11  *
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.
16  *
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
20  */
21 
27 #include "libavutil/rational.h"
28 #include "avcodec.h"
29 #include "dvdata.h"
30 
40 
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];
44 
45 static const DVprofile dv_profiles[] = {
46  { .dsf = 0,
47  .video_stype = 0x0,
48  .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
49  .difseg_size = 10,
50  .n_difchan = 1,
51  .time_base = { 1001, 30000 },
52  .ltc_divisor = 30,
53  .height = 480,
54  .width = 720,
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,
59  .bpm = 6,
60  .block_sizes = block_sizes_dv2550,
61  .audio_stride = 90,
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,
65  },
66  { .dsf = 1,
67  .video_stype = 0x0,
68  .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
69  .difseg_size = 12,
70  .n_difchan = 1,
71  .time_base = { 1, 25 },
72  .ltc_divisor = 25,
73  .height = 576,
74  .width = 720,
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,
79  .bpm = 6,
80  .block_sizes = block_sizes_dv2550,
81  .audio_stride = 108,
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,
85  },
86  { .dsf = 1,
87  .video_stype = 0x0,
88  .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
89  .difseg_size = 12,
90  .n_difchan = 1,
91  .time_base = { 1, 25 },
92  .ltc_divisor = 25,
93  .height = 576,
94  .width = 720,
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,
99  .bpm = 6,
100  .block_sizes = block_sizes_dv2550,
101  .audio_stride = 108,
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,
105  },
106  { .dsf = 0,
107  .video_stype = 0x4,
108  .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
109  .difseg_size = 10, /* also known as "DVCPRO50" */
110  .n_difchan = 2,
111  .time_base = { 1001, 30000 },
112  .ltc_divisor = 30,
113  .height = 480,
114  .width = 720,
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,
119  .bpm = 6,
120  .block_sizes = block_sizes_dv2550,
121  .audio_stride = 90,
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,
125  },
126  { .dsf = 1,
127  .video_stype = 0x4,
128  .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
129  .difseg_size = 12, /* also known as "DVCPRO50" */
130  .n_difchan = 2,
131  .time_base = { 1, 25 },
132  .ltc_divisor = 25,
133  .height = 576,
134  .width = 720,
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,
139  .bpm = 6,
140  .block_sizes = block_sizes_dv2550,
141  .audio_stride = 108,
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,
145  },
146  { .dsf = 0,
147  .video_stype = 0x14,
148  .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
149  .difseg_size = 10, /* also known as "DVCPRO HD" */
150  .n_difchan = 4,
151  .time_base = { 1001, 30000 },
152  .ltc_divisor = 30,
153  .height = 1080,
154  .width = 1280,
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,
159  .bpm = 8,
160  .block_sizes = block_sizes_dv100,
161  .audio_stride = 90,
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,
165  },
166  { .dsf = 1,
167  .video_stype = 0x14,
168  .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
169  .difseg_size = 12, /* also known as "DVCPRO HD" */
170  .n_difchan = 4,
171  .time_base = { 1, 25 },
172  .ltc_divisor = 25,
173  .height = 1080,
174  .width = 1440,
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,
179  .bpm = 8,
180  .block_sizes = block_sizes_dv100,
181  .audio_stride = 108,
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,
185  },
186  { .dsf = 0,
187  .video_stype = 0x18,
188  .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
189  .difseg_size = 10, /* also known as "DVCPRO HD" */
190  .n_difchan = 2,
191  .time_base = { 1001, 60000 },
192  .ltc_divisor = 60,
193  .height = 720,
194  .width = 960,
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,
199  .bpm = 8,
200  .block_sizes = block_sizes_dv100,
201  .audio_stride = 90,
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,
205  },
206  { .dsf = 1,
207  .video_stype = 0x18,
208  .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
209  .difseg_size = 12, /* also known as "DVCPRO HD" */
210  .n_difchan = 2,
211  .time_base = { 1, 50 },
212  .ltc_divisor = 50,
213  .height = 720,
214  .width = 960,
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,
219  .bpm = 8,
220  .block_sizes = block_sizes_dv100,
221  .audio_stride = 90,
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,
225  },
226  { .dsf = 1,
227  .video_stype = 0x1,
228  .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
229  .difseg_size = 12,
230  .n_difchan = 1,
231  .time_base = { 1, 25 },
232  .ltc_divisor = 25,
233  .height = 576,
234  .width = 720,
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,
239  .bpm = 6,
240  .block_sizes = block_sizes_dv2550,
241  .audio_stride = 108,
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,
245  }
246 };
247 
249  const uint8_t* frame, unsigned buf_size)
250 {
251  int i, dsf, stype;
252 
253  if (buf_size < 80*5 + 48 + 4)
254  return NULL;
255 
256  dsf = (frame[3] & 0x80) >> 7;
257  stype = frame[80*5 + 48 + 3] & 0x1f;
258 
259  /* 576i50 25Mbps 4:1:1 is a special case */
260  if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
261  return &dv_profiles[2];
262  }
263 
264  for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
265  if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
266  return &dv_profiles[i];
267 
268  /* check if old sys matches and assumes corrupted input */
269  if (sys && buf_size == sys->frame_size)
270  return sys;
271 
272  return NULL;
273 }
274 
276 {
277  int i;
278 
279  for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
280  if (codec->height == dv_profiles[i].height &&
281  codec->pix_fmt == dv_profiles[i].pix_fmt &&
282  codec->width == dv_profiles[i].width)
283  return &dv_profiles[i];
284 
285  return NULL;
286 }
287