00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #ifndef AVCODEC_DVDATA_H
00028 #define AVCODEC_DVDATA_H
00029
00030 #include "libavutil/rational.h"
00031 #include "avcodec.h"
00032
00033 typedef struct DVwork_chunk {
00034 uint16_t buf_offset;
00035 uint16_t mb_coordinates[5];
00036 } DVwork_chunk;
00037
00038
00039
00040
00041
00042
00043
00044 typedef struct DVprofile {
00045 int dsf;
00046 int video_stype;
00047 int frame_size;
00048 int difseg_size;
00049 int n_difchan;
00050 AVRational time_base;
00051 int ltc_divisor;
00052 int height;
00053 int width;
00054 AVRational sar[2];
00055 DVwork_chunk *work_chunks;
00056 uint32_t *idct_factor;
00057 enum PixelFormat pix_fmt;
00058 int bpm;
00059 const uint8_t *block_sizes;
00060 int audio_stride;
00061 int audio_min_samples[3];
00062
00063 int audio_samples_dist[5];
00064
00065 const uint8_t (*audio_shuffle)[9];
00066 } DVprofile;
00067
00068
00069 static const uint8_t dv_quant_shifts[22][4] = {
00070 { 3,3,4,4 },
00071 { 3,3,4,4 },
00072 { 2,3,3,4 },
00073 { 2,3,3,4 },
00074 { 2,2,3,3 },
00075 { 2,2,3,3 },
00076 { 1,2,2,3 },
00077 { 1,2,2,3 },
00078 { 1,1,2,2 },
00079 { 1,1,2,2 },
00080 { 0,1,1,2 },
00081 { 0,1,1,2 },
00082 { 0,0,1,1 },
00083 { 0,0,1,1 },
00084 { 0,0,0,1 },
00085 { 0,0,0,0 },
00086 { 0,0,0,0 },
00087 { 0,0,0,0 },
00088 { 0,0,0,0 },
00089 { 0,0,0,0 },
00090 { 0,0,0,0 },
00091 { 0,0,0,0 },
00092 };
00093
00094 static const uint8_t dv_quant_offset[4] = { 6, 3, 0, 1 };
00095 static const uint8_t dv_quant_areas[4] = { 6, 21, 43, 64 };
00096
00097
00098 static const uint8_t dv100_qstep[16] = {
00099 1,
00100 1,
00101 2, 3, 4, 5, 6, 7, 8, 16, 18, 20, 22, 24, 28, 52
00102 };
00103
00104
00105
00106 static const int dv_weight_bits = 18;
00107 static const int dv_weight_88[64] = {
00108 131072, 257107, 257107, 242189, 252167, 242189, 235923, 237536,
00109 237536, 235923, 229376, 231390, 223754, 231390, 229376, 222935,
00110 224969, 217965, 217965, 224969, 222935, 200636, 218652, 211916,
00111 212325, 211916, 218652, 200636, 188995, 196781, 205965, 206433,
00112 206433, 205965, 196781, 188995, 185364, 185364, 200636, 200704,
00113 200636, 185364, 185364, 174609, 180568, 195068, 195068, 180568,
00114 174609, 170091, 175557, 189591, 175557, 170091, 165371, 170627,
00115 170627, 165371, 160727, 153560, 160727, 144651, 144651, 136258,
00116 };
00117 static const int dv_weight_248[64] = {
00118 131072, 242189, 257107, 237536, 229376, 200636, 242189, 223754,
00119 224969, 196781, 262144, 242189, 229376, 200636, 257107, 237536,
00120 211916, 185364, 235923, 217965, 229376, 211916, 206433, 180568,
00121 242189, 223754, 224969, 196781, 211916, 185364, 235923, 217965,
00122 200704, 175557, 222935, 205965, 200636, 185364, 195068, 170627,
00123 229376, 211916, 206433, 180568, 200704, 175557, 222935, 205965,
00124 175557, 153560, 188995, 174609, 165371, 144651, 200636, 185364,
00125 195068, 170627, 175557, 153560, 188995, 174609, 165371, 144651,
00126 };
00127 static const int dv_iweight_bits = 14;
00128 static const int dv_iweight_88[64] = {
00129 32768, 16710, 16710, 17735, 17015, 17735, 18197, 18079,
00130 18079, 18197, 18725, 18559, 19196, 18559, 18725, 19284,
00131 19108, 19692, 19692, 19108, 19284, 21400, 19645, 20262,
00132 20214, 20262, 19645, 21400, 22733, 21845, 20867, 20815,
00133 20815, 20867, 21845, 22733, 23173, 23173, 21400, 21400,
00134 21400, 23173, 23173, 24600, 23764, 22017, 22017, 23764,
00135 24600, 25267, 24457, 22672, 24457, 25267, 25971, 25191,
00136 25191, 25971, 26715, 27962, 26715, 29642, 29642, 31536,
00137 };
00138 static const int dv_iweight_248[64] = {
00139 32768, 17735, 16710, 18079, 18725, 21400, 17735, 19196,
00140 19108, 21845, 16384, 17735, 18725, 21400, 16710, 18079,
00141 20262, 23173, 18197, 19692, 18725, 20262, 20815, 23764,
00142 17735, 19196, 19108, 21845, 20262, 23173, 18197, 19692,
00143 21400, 24457, 19284, 20867, 21400, 23173, 22017, 25191,
00144 18725, 20262, 20815, 23764, 21400, 24457, 19284, 20867,
00145 24457, 27962, 22733, 24600, 25971, 29642, 21400, 23173,
00146 22017, 25191, 24457, 27962, 22733, 24600, 25971, 29642,
00147 };
00148
00152 static const int dv_iweight_1080_y[64] = {
00153 128, 16, 16, 17, 17, 17, 18, 18,
00154 18, 18, 18, 18, 19, 18, 18, 19,
00155 19, 19, 19, 19, 19, 42, 38, 40,
00156 40, 40, 38, 42, 44, 43, 41, 41,
00157 41, 41, 43, 44, 45, 45, 42, 42,
00158 42, 45, 45, 48, 46, 43, 43, 46,
00159 48, 49, 48, 44, 48, 49, 101, 98,
00160 98, 101, 104, 109, 104, 116, 116, 123,
00161 };
00162 static const int dv_iweight_1080_c[64] = {
00163 128, 16, 16, 17, 17, 17, 25, 25,
00164 25, 25, 26, 25, 26, 25, 26, 26,
00165 26, 27, 27, 26, 26, 42, 38, 40,
00166 40, 40, 38, 42, 44, 43, 41, 41,
00167 41, 41, 43, 44, 91, 91, 84, 84,
00168 84, 91, 91, 96, 93, 86, 86, 93,
00169 96, 197, 191, 177, 191, 197, 203, 197,
00170 197, 203, 209, 219, 209, 232, 232, 246,
00171 };
00172 static const int dv_iweight_720_y[64] = {
00173 128, 16, 16, 17, 17, 17, 18, 18,
00174 18, 18, 18, 18, 19, 18, 18, 19,
00175 19, 19, 19, 19, 19, 42, 38, 40,
00176 40, 40, 38, 42, 44, 43, 41, 41,
00177 41, 41, 43, 44, 68, 68, 63, 63,
00178 63, 68, 68, 96, 92, 86, 86, 92,
00179 96, 98, 96, 88, 96, 98, 202, 196,
00180 196, 202, 208, 218, 208, 232, 232, 246,
00181 };
00182 static const int dv_iweight_720_c[64] = {
00183 128, 24, 24, 26, 26, 26, 36, 36,
00184 36, 36, 36, 36, 38, 36, 36, 38,
00185 38, 38, 38, 38, 38, 84, 76, 80,
00186 80, 80, 76, 84, 88, 86, 82, 82,
00187 82, 82, 86, 88, 182, 182, 168, 168,
00188 168, 182, 182, 192, 186, 192, 172, 186,
00189 192, 394, 382, 354, 382, 394, 406, 394,
00190 394, 406, 418, 438, 418, 464, 464, 492,
00191 };
00192
00193 static const uint8_t dv_audio_shuffle525[10][9] = {
00194 { 0, 30, 60, 20, 50, 80, 10, 40, 70 },
00195 { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
00196 { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
00197 { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
00198 { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
00199
00200 { 1, 31, 61, 21, 51, 81, 11, 41, 71 },
00201 { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
00202 { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
00203 { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
00204 { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
00205 };
00206
00207 static const uint8_t dv_audio_shuffle625[12][9] = {
00208 { 0, 36, 72, 26, 62, 98, 16, 52, 88},
00209 { 6, 42, 78, 32, 68, 104, 22, 58, 94},
00210 { 12, 48, 84, 2, 38, 74, 28, 64, 100},
00211 { 18, 54, 90, 8, 44, 80, 34, 70, 106},
00212 { 24, 60, 96, 14, 50, 86, 4, 40, 76},
00213 { 30, 66, 102, 20, 56, 92, 10, 46, 82},
00214
00215 { 1, 37, 73, 27, 63, 99, 17, 53, 89},
00216 { 7, 43, 79, 33, 69, 105, 23, 59, 95},
00217 { 13, 49, 85, 3, 39, 75, 29, 65, 101},
00218 { 19, 55, 91, 9, 45, 81, 35, 71, 107},
00219 { 25, 61, 97, 15, 51, 87, 5, 41, 77},
00220 { 31, 67, 103, 21, 57, 93, 11, 47, 83},
00221 };
00222
00223 static const av_unused int dv_audio_frequency[3] = {
00224 48000, 44100, 32000,
00225 };
00226
00227
00228 static const uint8_t block_sizes_dv2550[8] = {
00229 112, 112, 112, 112, 80, 80, 0, 0,
00230 };
00231
00232 static const uint8_t block_sizes_dv100[8] = {
00233 80, 80, 80, 80, 80, 80, 64, 64,
00234 };
00235
00236 enum dv_section_type {
00237 dv_sect_header = 0x1f,
00238 dv_sect_subcode = 0x3f,
00239 dv_sect_vaux = 0x56,
00240 dv_sect_audio = 0x76,
00241 dv_sect_video = 0x96,
00242 };
00243
00244 enum dv_pack_type {
00245 dv_header525 = 0x3f,
00246 dv_header625 = 0xbf,
00247 dv_timecode = 0x13,
00248 dv_audio_source = 0x50,
00249 dv_audio_control = 0x51,
00250 dv_audio_recdate = 0x52,
00251 dv_audio_rectime = 0x53,
00252 dv_video_source = 0x60,
00253 dv_video_control = 0x61,
00254 dv_video_recdate = 0x62,
00255 dv_video_rectime = 0x63,
00256 dv_unknown_pack = 0xff,
00257 };
00258
00259 #define DV_PROFILE_IS_HD(p) ((p)->video_stype & 0x10)
00260 #define DV_PROFILE_IS_1080i50(p) (((p)->video_stype == 0x14) && ((p)->dsf == 1))
00261 #define DV_PROFILE_IS_720p50(p) (((p)->video_stype == 0x18) && ((p)->dsf == 1))
00262
00263
00264
00265 #define DV_PROFILE_BYTES (6*80)
00266
00270 #define DV_MAX_FRAME_SIZE 576000
00271
00275 #define DV_MAX_BPM 8
00276
00277 const DVprofile* ff_dv_frame_profile(const DVprofile *sys,
00278 const uint8_t* frame, unsigned buf_size);
00279 const DVprofile* ff_dv_codec_profile(AVCodecContext* codec);
00280
00281 static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num,
00282 uint8_t seq_num, uint8_t dif_num,
00283 uint8_t* buf)
00284 {
00285 buf[0] = (uint8_t)t;
00286 buf[1] = (seq_num << 4) |
00287 (chan_num << 3) |
00288 7;
00289 buf[2] = dif_num;
00290 return 3;
00291 }
00292
00293
00294 static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t* buf)
00295 {
00296 if (syb_num == 0 || syb_num == 6) {
00297 buf[0] = (fr << 7) |
00298 (0 << 4) |
00299 0x0f;
00300 }
00301 else if (syb_num == 11) {
00302 buf[0] = (fr << 7) |
00303 0x7f;
00304 }
00305 else {
00306 buf[0] = (fr << 7) |
00307 (0 << 4) |
00308 0x0f;
00309 }
00310 buf[1] = 0xf0 |
00311 (syb_num & 0x0f);
00312 buf[2] = 0xff;
00313 return 3;
00314 }
00315
00316 #endif