00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdint.h>
00020
00021 #include "libavutil/common.h"
00022 #include "libavutil/intreadwrite.h"
00023 #include "libavutil/log.h"
00024 #include "libavutil/pixdesc.h"
00025 #include "avcodec.h"
00026 #include "dv_profile.h"
00027
00028 static DVwork_chunk work_chunks_dv25pal [1*12*27];
00029 static DVwork_chunk work_chunks_dv25pal411[1*12*27];
00030 static DVwork_chunk work_chunks_dv25ntsc [1*10*27];
00031 static DVwork_chunk work_chunks_dv50pal [2*12*27];
00032 static DVwork_chunk work_chunks_dv50ntsc [2*10*27];
00033 static DVwork_chunk work_chunks_dv100palp [2*12*27];
00034 static DVwork_chunk work_chunks_dv100ntscp[2*10*27];
00035 static DVwork_chunk work_chunks_dv100pali [4*12*27];
00036 static DVwork_chunk work_chunks_dv100ntsci[4*10*27];
00037
00038 static uint32_t dv_idct_factor_sd [2*2*22*64];
00039 static uint32_t dv_idct_factor_hd1080[2*4*16*64];
00040 static uint32_t dv_idct_factor_hd720 [2*4*16*64];
00041
00042 static const uint8_t dv_audio_shuffle525[10][9] = {
00043 { 0, 30, 60, 20, 50, 80, 10, 40, 70 },
00044 { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
00045 { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
00046 { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
00047 { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
00048
00049 { 1, 31, 61, 21, 51, 81, 11, 41, 71 },
00050 { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
00051 { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
00052 { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
00053 { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
00054 };
00055
00056 static const uint8_t dv_audio_shuffle625[12][9] = {
00057 { 0, 36, 72, 26, 62, 98, 16, 52, 88},
00058 { 6, 42, 78, 32, 68, 104, 22, 58, 94},
00059 { 12, 48, 84, 2, 38, 74, 28, 64, 100},
00060 { 18, 54, 90, 8, 44, 80, 34, 70, 106},
00061 { 24, 60, 96, 14, 50, 86, 4, 40, 76},
00062 { 30, 66, 102, 20, 56, 92, 10, 46, 82},
00063
00064 { 1, 37, 73, 27, 63, 99, 17, 53, 89},
00065 { 7, 43, 79, 33, 69, 105, 23, 59, 95},
00066 { 13, 49, 85, 3, 39, 75, 29, 65, 101},
00067 { 19, 55, 91, 9, 45, 81, 35, 71, 107},
00068 { 25, 61, 97, 15, 51, 87, 5, 41, 77},
00069 { 31, 67, 103, 21, 57, 93, 11, 47, 83},
00070 };
00071
00072
00073 static const uint8_t block_sizes_dv2550[8] = {
00074 112, 112, 112, 112, 80, 80, 0, 0,
00075 };
00076
00077 static const uint8_t block_sizes_dv100[8] = {
00078 80, 80, 80, 80, 80, 80, 64, 64,
00079 };
00080
00081 static const DVprofile dv_profiles[] = {
00082 { .dsf = 0,
00083 .video_stype = 0x0,
00084 .frame_size = 120000,
00085 .difseg_size = 10,
00086 .n_difchan = 1,
00087 .time_base = { 1001, 30000 },
00088 .ltc_divisor = 30,
00089 .height = 480,
00090 .width = 720,
00091 .sar = {{8, 9}, {32, 27}},
00092 .work_chunks = &work_chunks_dv25ntsc[0],
00093 .idct_factor = &dv_idct_factor_sd[0],
00094 .pix_fmt = PIX_FMT_YUV411P,
00095 .bpm = 6,
00096 .block_sizes = block_sizes_dv2550,
00097 .audio_stride = 90,
00098 .audio_min_samples = { 1580, 1452, 1053 },
00099 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 },
00100 .audio_shuffle = dv_audio_shuffle525,
00101 },
00102 { .dsf = 1,
00103 .video_stype = 0x0,
00104 .frame_size = 144000,
00105 .difseg_size = 12,
00106 .n_difchan = 1,
00107 .time_base = { 1, 25 },
00108 .ltc_divisor = 25,
00109 .height = 576,
00110 .width = 720,
00111 .sar = {{16, 15}, {64, 45}},
00112 .work_chunks = &work_chunks_dv25pal[0],
00113 .idct_factor = &dv_idct_factor_sd[0],
00114 .pix_fmt = PIX_FMT_YUV420P,
00115 .bpm = 6,
00116 .block_sizes = block_sizes_dv2550,
00117 .audio_stride = 108,
00118 .audio_min_samples = { 1896, 1742, 1264 },
00119 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00120 .audio_shuffle = dv_audio_shuffle625,
00121 },
00122 { .dsf = 1,
00123 .video_stype = 0x0,
00124 .frame_size = 144000,
00125 .difseg_size = 12,
00126 .n_difchan = 1,
00127 .time_base = { 1, 25 },
00128 .ltc_divisor = 25,
00129 .height = 576,
00130 .width = 720,
00131 .sar = {{16, 15}, {64, 45}},
00132 .work_chunks = &work_chunks_dv25pal411[0],
00133 .idct_factor = &dv_idct_factor_sd[0],
00134 .pix_fmt = PIX_FMT_YUV411P,
00135 .bpm = 6,
00136 .block_sizes = block_sizes_dv2550,
00137 .audio_stride = 108,
00138 .audio_min_samples = { 1896, 1742, 1264 },
00139 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00140 .audio_shuffle = dv_audio_shuffle625,
00141 },
00142 { .dsf = 0,
00143 .video_stype = 0x4,
00144 .frame_size = 240000,
00145 .difseg_size = 10,
00146 .n_difchan = 2,
00147 .time_base = { 1001, 30000 },
00148 .ltc_divisor = 30,
00149 .height = 480,
00150 .width = 720,
00151 .sar = {{8, 9}, {32, 27}},
00152 .work_chunks = &work_chunks_dv50ntsc[0],
00153 .idct_factor = &dv_idct_factor_sd[0],
00154 .pix_fmt = PIX_FMT_YUV422P,
00155 .bpm = 6,
00156 .block_sizes = block_sizes_dv2550,
00157 .audio_stride = 90,
00158 .audio_min_samples = { 1580, 1452, 1053 },
00159 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 },
00160 .audio_shuffle = dv_audio_shuffle525,
00161 },
00162 { .dsf = 1,
00163 .video_stype = 0x4,
00164 .frame_size = 288000,
00165 .difseg_size = 12,
00166 .n_difchan = 2,
00167 .time_base = { 1, 25 },
00168 .ltc_divisor = 25,
00169 .height = 576,
00170 .width = 720,
00171 .sar = {{16, 15}, {64, 45}},
00172 .work_chunks = &work_chunks_dv50pal[0],
00173 .idct_factor = &dv_idct_factor_sd[0],
00174 .pix_fmt = PIX_FMT_YUV422P,
00175 .bpm = 6,
00176 .block_sizes = block_sizes_dv2550,
00177 .audio_stride = 108,
00178 .audio_min_samples = { 1896, 1742, 1264 },
00179 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00180 .audio_shuffle = dv_audio_shuffle625,
00181 },
00182 { .dsf = 0,
00183 .video_stype = 0x14,
00184 .frame_size = 480000,
00185 .difseg_size = 10,
00186 .n_difchan = 4,
00187 .time_base = { 1001, 30000 },
00188 .ltc_divisor = 30,
00189 .height = 1080,
00190 .width = 1280,
00191 .sar = {{1, 1}, {3, 2}},
00192 .work_chunks = &work_chunks_dv100ntsci[0],
00193 .idct_factor = &dv_idct_factor_hd1080[0],
00194 .pix_fmt = PIX_FMT_YUV422P,
00195 .bpm = 8,
00196 .block_sizes = block_sizes_dv100,
00197 .audio_stride = 90,
00198 .audio_min_samples = { 1580, 1452, 1053 },
00199 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 },
00200 .audio_shuffle = dv_audio_shuffle525,
00201 },
00202 { .dsf = 1,
00203 .video_stype = 0x14,
00204 .frame_size = 576000,
00205 .difseg_size = 12,
00206 .n_difchan = 4,
00207 .time_base = { 1, 25 },
00208 .ltc_divisor = 25,
00209 .height = 1080,
00210 .width = 1440,
00211 .sar = {{1, 1}, {4, 3}},
00212 .work_chunks = &work_chunks_dv100pali[0],
00213 .idct_factor = &dv_idct_factor_hd1080[0],
00214 .pix_fmt = PIX_FMT_YUV422P,
00215 .bpm = 8,
00216 .block_sizes = block_sizes_dv100,
00217 .audio_stride = 108,
00218 .audio_min_samples = { 1896, 1742, 1264 },
00219 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00220 .audio_shuffle = dv_audio_shuffle625,
00221 },
00222 { .dsf = 0,
00223 .video_stype = 0x18,
00224 .frame_size = 240000,
00225 .difseg_size = 10,
00226 .n_difchan = 2,
00227 .time_base = { 1001, 60000 },
00228 .ltc_divisor = 60,
00229 .height = 720,
00230 .width = 960,
00231 .sar = {{1, 1}, {4, 3}},
00232 .work_chunks = &work_chunks_dv100ntscp[0],
00233 .idct_factor = &dv_idct_factor_hd720[0],
00234 .pix_fmt = PIX_FMT_YUV422P,
00235 .bpm = 8,
00236 .block_sizes = block_sizes_dv100,
00237 .audio_stride = 90,
00238 .audio_min_samples = { 1580, 1452, 1053 },
00239 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 },
00240 .audio_shuffle = dv_audio_shuffle525,
00241 },
00242 { .dsf = 1,
00243 .video_stype = 0x18,
00244 .frame_size = 288000,
00245 .difseg_size = 12,
00246 .n_difchan = 2,
00247 .time_base = { 1, 50 },
00248 .ltc_divisor = 50,
00249 .height = 720,
00250 .width = 960,
00251 .sar = {{1, 1}, {4, 3}},
00252 .work_chunks = &work_chunks_dv100palp[0],
00253 .idct_factor = &dv_idct_factor_hd720[0],
00254 .pix_fmt = PIX_FMT_YUV422P,
00255 .bpm = 8,
00256 .block_sizes = block_sizes_dv100,
00257 .audio_stride = 90,
00258 .audio_min_samples = { 1896, 1742, 1264 },
00259 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00260 .audio_shuffle = dv_audio_shuffle625,
00261 },
00262 { .dsf = 1,
00263 .video_stype = 0x1,
00264 .frame_size = 144000,
00265 .difseg_size = 12,
00266 .n_difchan = 1,
00267 .time_base = { 1, 25 },
00268 .ltc_divisor = 25,
00269 .height = 576,
00270 .width = 720,
00271 .sar = {{16, 15}, {64, 45}},
00272 .work_chunks = &work_chunks_dv25pal[0],
00273 .idct_factor = &dv_idct_factor_sd[0],
00274 .pix_fmt = PIX_FMT_YUV420P,
00275 .bpm = 6,
00276 .block_sizes = block_sizes_dv2550,
00277 .audio_stride = 108,
00278 .audio_min_samples = { 1896, 1742, 1264 },
00279 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
00280 .audio_shuffle = dv_audio_shuffle625,
00281 }
00282 };
00283
00284 const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys,
00285 const uint8_t* frame, unsigned buf_size)
00286 {
00287 int i, dsf, stype;
00288
00289 if(buf_size < DV_PROFILE_BYTES)
00290 return NULL;
00291
00292 dsf = (frame[3] & 0x80) >> 7;
00293 stype = frame[80 * 5 + 48 + 3] & 0x1f;
00294
00295
00296 if ((dsf == 1 && stype == 0 && frame[4] & 0x07 ) ||
00297 (stype == 31 && codec && codec->codec_tag==AV_RL32("SL25") && codec->coded_width==720 && codec->coded_height==576)) {
00298 return &dv_profiles[2];
00299 }
00300
00301 if(stype == 0 && codec && codec->codec_tag==AV_RL32("dvsd") && codec->coded_width==720 && codec->coded_height==576)
00302 return &dv_profiles[1];
00303
00304 for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
00305 if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
00306 return &dv_profiles[i];
00307
00308
00309 if (sys && buf_size == sys->frame_size)
00310 return sys;
00311
00312
00313 if ((frame[3] & 0x7f) == 0x3f && frame[80 * 5 + 48 + 3] == 0xff)
00314 return &dv_profiles[dsf];
00315
00316 return NULL;
00317 }
00318
00319 const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
00320 const uint8_t* frame, unsigned buf_size)
00321 {
00322 return avpriv_dv_frame_profile2(NULL, sys, frame, buf_size);
00323 }
00324
00325 const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec)
00326 {
00327 int i;
00328 int w, h;
00329
00330 if (codec->coded_width || codec->coded_height) {
00331 w = codec->coded_width;
00332 h = codec->coded_height;
00333 } else {
00334 w = codec->width;
00335 h = codec->height;
00336 }
00337
00338 for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
00339 if (h == dv_profiles[i].height &&
00340 codec->pix_fmt == dv_profiles[i].pix_fmt &&
00341 w == dv_profiles[i].width)
00342 return &dv_profiles[i];
00343
00344 return NULL;
00345 }
00346
00347 void ff_dv_print_profiles(void *logctx, int loglevel)
00348 {
00349 int i;
00350 for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++) {
00351 const DVprofile *p = &dv_profiles[i];
00352 av_log(logctx, loglevel, "Frame size: %dx%d; pixel format: %s, "
00353 "framerate: %d/%d\n", p->width, p->height, av_get_pix_fmt_name(p->pix_fmt),
00354 p->time_base.den, p->time_base.num);
00355 }
00356 }