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