67 #define TEX_VLC_BITS 9
85 static const uint8_t
off[] = { 2, 6, 8, 0, 4 };
86 static const uint8_t shuf1[] = { 36, 18, 54, 0, 72 };
87 static const uint8_t shuf2[] = { 24, 12, 36, 0, 48 };
88 static const uint8_t shuf3[] = { 18, 9, 27, 0, 36 };
90 static const uint8_t l_start[] = {0, 4, 9, 13, 18, 22, 27, 31, 36, 40};
91 static const uint8_t l_start_shuffled[] = { 9, 4, 13, 0, 18 };
93 static const uint8_t serpent1[] = {0, 1, 2, 2, 1, 0,
98 static const uint8_t serpent2[] = {0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0,
99 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0,
102 static const uint8_t remap[][2] = {{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0},
103 { 0, 0}, { 0, 1}, { 0, 2}, { 0, 3}, {10, 0},
104 {10, 1}, {10, 2}, {10, 3}, {20, 0}, {20, 1},
105 {20, 2}, {20, 3}, {30, 0}, {30, 1}, {30, 2},
106 {30, 3}, {40, 0}, {40, 1}, {40, 2}, {40, 3},
107 {50, 0}, {50, 1}, {50, 2}, {50, 3}, {60, 0},
108 {60, 1}, {60, 2}, {60, 3}, {70, 0}, {70, 1},
109 {70, 2}, {70, 3}, { 0,64}, { 0,65}, { 0,66},
110 {10,64}, {10,65}, {10,66}, {20,64}, {20,65},
111 {20,66}, {30,64}, {30,65}, {30,66}, {40,64},
112 {40,65}, {40,66}, {50,64}, {50,65}, {50,66},
113 {60,64}, {60,65}, {60,66}, {70,64}, {70,65},
114 {70,66}, { 0,67}, {20,67}, {40,67}, {60,67}};
119 for (m=0; m<5; m++) {
122 blk = (chan*11+seq)*27+slot;
124 if (chan == 0 && seq == 11) {
133 i = (4*chan + blk + off[m])%11;
136 x = shuf1[m] + (chan&1)*9 + k%9;
137 y = (i*3+k/9)*2 + (chan>>1) + 1;
139 tbl[m] = (x<<1)|(y<<9);
142 blk = (chan*10+seq)*27+slot;
144 i = (4*chan + (seq/5) + 2*blk + off[m])%10;
147 x = shuf1[m]+(chan&1)*9 + k%9;
148 y = (i*3+k/9)*2 + (chan>>1) + 4;
151 x = remap[y][0]+((x-80)<<(y>59));
154 tbl[m] = (x<<1)|(y<<9);
157 blk = (chan*10+seq)*27+slot;
159 i = (4*chan + (seq/5) + 2*blk + off[m])%10;
160 k = (blk/5)%27 + (i&1)*3;
162 x = shuf2[m] + k%6 + 6*(chan&1);
163 y = l_start[i] + k/6 + 45*(chan>>1);
164 tbl[m] = (x<<1)|(y<<9);
169 x = shuf3[m] + slot/3;
172 tbl[m] = (x<<1)|(y<<8);
175 x = shuf3[m] + slot/3;
178 tbl[m] = (x<<1)|(y<<9);
182 k = slot + ((m==1||m==2)?3:0);
184 x = l_start_shuffled[m] + k/6;
185 y = serpent2[k] + i*6;
188 tbl[m] = (x<<2)|(y<<8);
200 uint32_t *factor1, *factor2;
201 const int *iweight1, *iweight2;
208 for (j=0; j<27; j++) {
232 for (c = 0; c < 4; c++) {
233 for (s = 0; s < 16; s++) {
234 for (i = 0; i < 64; i++) {
235 *factor1++ = (
dv100_qstep[s] << (c + 9)) * iweight1[i];
236 *factor2++ = (
dv100_qstep[s] << (c + 9)) * iweight2[i];
243 for (s = 0; s < 22; s++) {
244 for (i = c = 0; c < 4; c++) {
247 *factor2++ = (*factor1++) << 1;
275 for (i = 0, j = 0; i <
NB_DV_VLC; i++, j++) {
282 new_dv_vlc_bits[j] <<= 1;
296 new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2, 0);
300 int code = dv_vlc.
table[i][0];
308 run = new_dv_vlc_run [code] + 1;
309 level = new_dv_vlc_level[code];
329 for (i = 0; i < 64; i++)
336 for (i = 0; i < 64; i++){
389 if (partial_bit_count > 0) {
391 re_index -= partial_bit_count;
410 if (re_index + vlc_len > last_index) {
414 re_index = last_index;
425 block[scan_table[pos]] =
level;
452 *mb_y -= (*mb_y>17)?18:-72;
461 int quant, dc, dct_mode, class1, j;
462 int mb_index, mb_x, mb_y, last_index;
463 int y_stride, linesize;
467 const uint8_t *buf_ptr;
475 int is_field_mode[5];
477 assert((((
int)mb_bit_buffer) & 7) == 0);
478 assert((((
int)vs_bit_buffer) & 7) == 0);
480 memset(sblock, 0, 5*
DV_MAX_BPM*
sizeof(*sblock));
484 block1 = &sblock[0][0];
487 for (mb_index = 0; mb_index < 5; mb_index++, mb1 += s->
sys->
bpm, block1 += s->
sys->
bpm * 64) {
489 quant = buf_ptr[3] & 0x0f;
494 is_field_mode[mb_index] = 0;
495 for (j = 0; j < s->
sys->
bpm; j++) {
507 is_field_mode[mb_index] |= !j && dct_mode;
519 buf_ptr += last_index >> 3;
523 av_dlog(avctx,
"MB block: %d, %d ", mb_index, j);
542 for (j = 0; j < s->
sys->
bpm; j++, block += 64, mb++) {
558 block = &sblock[0][0];
563 for (mb_index = 0; mb_index < 5; mb_index++) {
564 for (j = 0; j < s->
sys->
bpm; j++) {
566 av_dlog(avctx,
"start %d:%d\n", mb_index, j);
569 if (mb->
pos >= 64 && mb->
pos < 127)
577 block = &sblock[0][0];
579 for (mb_index = 0; mb_index < 5; mb_index++) {
585 (s->
sys->
height >= 720 && mb_y != 134)) {
586 y_stride = (s->
picture.
linesize[0] << ((!is_field_mode[mb_index]) * log2_blocksize));
588 y_stride = (2 << log2_blocksize);
592 mb[0] .
idct_put(y_ptr , linesize, block + 0*64);
594 mb[2].
idct_put(y_ptr + (1 << log2_blocksize) , linesize, block + 2*64);
596 mb[1].
idct_put(y_ptr + (1 << log2_blocksize) , linesize, block + 1*64);
597 mb[2].
idct_put(y_ptr + y_stride, linesize, block + 2*64);
598 mb[3].
idct_put(y_ptr + (1 << log2_blocksize) + y_stride, linesize, block + 3*64);
606 for (j = 2; j; j--) {
609 uint64_t aligned_pixels[64/8];
610 uint8_t *pixels = (uint8_t*)aligned_pixels;
611 uint8_t *c_ptr1, *ptr1;
614 for (y = 0; y < (1 << log2_blocksize); y++, c_ptr += s->
picture.
linesize[j], pixels += 8) {
615 ptr1 = pixels + (1 << (log2_blocksize - 1));
617 for (x = 0; x < (1 << (log2_blocksize - 1)); x++) {
618 c_ptr[x] = pixels[x];
624 y_stride = (mb_y == 134) ? (1 << log2_blocksize) :
625 s->
picture.
linesize[j] << ((!is_field_mode[mb_index]) * log2_blocksize);
627 (mb++)->
idct_put(c_ptr , linesize, block); block += 64;
629 (mb++)->
idct_put(c_ptr + y_stride, linesize, block); block += 64;
651 *vlc = 0xfe00 | (level << 1) | sign;
655 *vlc |= ((run < 16) ?
dv_vlc_map[run-1][0].vlc :
656 (0x1f80 | (run - 1))) <<
size;
657 size += (run < 16) ?
dv_vlc_map[run-1][0].size : 13;
674 size += (run < 16) ?
dv_vlc_map[run-1][0].size : 13;
721 put_bits(pb, bits_left, vlc >> size);
722 vlc = vlc & ((1 <<
size) - 1);
724 if (pb + 1 >= pb_end) {
779 static const int classes[] = {12, 24, 36, 0xffff};
781 static const int classes[] = {-1, -1, 255, 0xffff};
783 int max = classes[0];
786 assert((((
int)
blk) & 15) == 0);
799 memset(blk, 0, 64*
sizeof(*blk));
807 for (area = 0; area < 4; area++) {
808 bi->
prev[area] = prev;
811 int level = blk[zigzag_scan[i]];
813 if (level + 15 > 30
U) {
814 bi->
sign[i] = (level >> 31) & 1;
829 for (bi->
cno = 0; max > classes[bi->
cno]; bi->
cno++);
837 for (area = 0; area < 4; area++) {
838 bi->
prev[area] = prev;
859 int i, j, k,
a, prev,
a2;
862 size[0] = size[1] = size[2] = size[3] = size[4] = 1 << 24;
865 for (i = 0; i < 5; i++) {
871 for (j = 0; j < 6; j++, b++) {
872 for (a = 0; a < 4; a++) {
888 assert(b->
mb[b->
next[k]]);
891 assert(b->
prev[a2] == k && (a2 + 1 >= 4 || b->
prev[a2+1] != k));
905 }
while (qnos[0]|qnos[1]|qnos[2]|qnos[3]|qnos[4]);
911 for (j = 0; j < 6 *5; j++, b++) {
913 for (k = b->
next[prev]; k < 64; k = b->next[k]) {
914 if (b->
mb[k] < a && b->
mb[k] > -a){
930 int mb_x, mb_y, c_offset, linesize, y_stride;
939 int qnos[5] = {15, 15, 15, 15, 15};
940 int* qnosp = &qnos[0];
943 enc_blk = &enc_blks[0];
944 for (mb_index = 0; mb_index < 5; mb_index++) {
950 (s->
sys->
height >= 720 && mb_y != 134)) {
976 for (j = 2; j; j--) {
982 uint8_t*
b = scratch;
983 for (i = 0; i < 8; i++) {
984 d = c_ptr + (linesize << 3);
985 b[0] = c_ptr[0]; b[1] = c_ptr[1]; b[2] = c_ptr[2]; b[3] = c_ptr[3];
986 b[4] = d[0]; b[5] = d[1]; b[6] = d[2]; b[7] = d[3];
1005 for (j=0; j<5*s->
sys->
bpm;) {
1012 for (i=0; i<s->
sys->
bpm; i++, j++) {
1016 put_sbits(&pbs[j], 9, ((enc_blks[j].mb[0] >> 3) - 1024 + 2) >> 2);
1017 put_bits(&pbs[j], 1, enc_blks[j].dct_mode);
1018 put_bits(&pbs[j], 2, enc_blks[j].cno);
1025 pb = &pbs[start_mb];
1026 for (i=0; i<s->
sys->
bpm; i++) {
1027 if (enc_blks[start_mb+i].partial_bit_count)
1034 for (j=0; j<5*s->
sys->
bpm; j++) {
1035 if (enc_blks[j].partial_bit_count)
1037 if (enc_blks[j].partial_bit_count)
1041 for (j=0; j<5*s->
sys->
bpm; j++) {
1050 memset(pbs[j].buf + pos, 0xff, size - pos);
1056 #if CONFIG_DVVIDEO_DECODER
1060 void *
data,
int *data_size,
1063 const uint8_t *buf = avpkt->
data;
1064 int buf_size = avpkt->
size;
1066 const uint8_t* vsc_pack;
1102 vsc_pack = buf + 80*5 + 48 + 5;
1104 apt = buf[4] & 0x07;
1105 is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07)));
1141 buf[0] = (uint8_t)pack_id;
1181 buf[1] = buf[2] = buf[3] = buf[4] = 0xff;
1186 #if CONFIG_DVVIDEO_ENCODER
1193 memset(buf, 0xff, 80 * 6);
1201 for (j = 0; j < 2; j++) {
1203 for (k = 0; k < 6; k++)
1209 for (j = 0; j < 3; j++) {
1220 for (j = 0; j < 135; j++) {
1222 memset(buf, 0xff, 80);
1237 static int dvvideo_encode_frame(
AVCodecContext *c, uint8_t *buf,
int buf_size,
1257 dv_format_frame(s, buf);
1274 #if CONFIG_DVVIDEO_ENCODER
1275 AVCodec ff_dvvideo_encoder = {
1281 .encode = dvvideo_encode_frame,
1286 #endif // CONFIG_DVVIDEO_ENCODER
1288 #if CONFIG_DVVIDEO_DECODER
1289 AVCodec ff_dvvideo_decoder = {
1296 .
decode = dvvideo_decode_frame,
static const uint8_t dv_vlc_run[409]
struct DVVideoContext DVVideoContext
#define LOCAL_ALIGNED_8(t, v,...)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
const uint8_t ff_zigzag_direct[64]
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static void put_sbits(PutBitContext *pb, int n, int32_t value)
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVFrame * coded_frame
the picture in the bitstream
const uint8_t ff_zigzag248_direct[64]
int(* me_cmp_func)(void *s, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
static const int dv_iweight_bits
static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t *vlc)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
static int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c, uint8_t *buf)
const DVprofile * avpriv_dv_frame_profile(const DVprofile *sys, const uint8_t *frame, unsigned buf_size)
static av_always_inline int dv_guess_dct_mode(DVVideoContext *s, uint8_t *data, int linesize)
int ildct_cmp
interlaced DCT comparison function
static const int dv_iweight_248[64]
static RL_VLC_ELEM dv_rl_vlc[1184]
static const int dv_iweight_720_y[64]
static int get_sbits(GetBitContext *s, int n)
struct BlockInfo BlockInfo
static const uint8_t zigzag_scan[16]
static const uint8_t dv_quant_offset[4]
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define DV_PROFILE_IS_720p50(p)
static const int mb_area_start[5]
static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static void dv_guess_qnos(EncBlockInfo *blks, int *qnos)
void(* get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size)
static av_always_inline int dv_rl2vlc_size(int run, int l)
void(* get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size)
static const int dv_weight_88[64]
static double av_q2d(AVRational a)
Convert rational to double.
void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type)
bitstream reader API header.
uint8_t idct_permutation[64]
idct input permutation.
int interlaced_frame
The content of the picture is interlaced.
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
#define LOCAL_ALIGNED_16(t, v,...)
const uint8_t * block_sizes
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
av_cold void dsputil_init(DSPContext *c, AVCodecContext *avctx)
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
static int init(AVCodecParserContext *s)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static const uint8_t dv_quant_areas[4]
static int dv_work_pool_size(const DVprofile *d)
static int get_bits_left(GetBitContext *gb)
static const uint8_t dv_quant_shifts[22][4]
#define UPDATE_CACHE(name, gb)
#define DV_PROFILE_IS_1080i50(p)
static void bit_copy(PutBitContext *pb, GetBitContext *gb)
uint8_t partial_bit_count
static const int vs_total_ac_bits
static int put_bits_left(PutBitContext *s)
uint16_t mb_coordinates[5]
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
void(* idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block)
static const int dv_iweight_1080_y[64]
The "inverse" DV100 weights are actually just the spec weights (zig-zagged).
void(* idct_put)(uint8_t *dest, int line_size, DCTELEM *block)
block -> idct -> clip to unsigned 8 bit -> dest.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define DV_PROFILE_IS_HD(p)
uint32_t partial_bit_buffer
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
#define CLOSE_READER(name, gb)
void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block)
static int put_bits_count(PutBitContext *s)
static void dv_calculate_mb_xy(DVVideoContext *s, DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y)
static av_always_inline void emms_c(void)
Empty mmx state.
static const int dv_iweight_1080_c[64]
static const uint16_t dv_vlc_bits[409]
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
struct EncBlockInfo EncBlockInfo
#define DV_VLC_MAP_RUN_SIZE
void(* fdct248)(DCTELEM *block)
int width
picture width / height.
struct AVFrame AVFrame
Audio Video Frame.
static DCTELEM block1[64]
const char * av_get_pix_fmt_name(enum PixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
uint32_t partial_bit_buffer
static const int dv_iweight_88[64]
static int dvvideo_close(AVCodecContext *c)
const DVprofile * avpriv_dv_codec_profile(AVCodecContext *codec)
const uint8_t * scan_table
static const int dv_weight_bits
#define av_dlog(pctx,...)
av_dlog macros Useful to print debug messages that shouldn't get compiled in normally.
#define SHOW_UBITS(name, gb, num)
static void dv_vlc_map_tableinit(void)
static void idct_put(FourXContext *f, int x, int y)
const uint32_t * factor_table
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
static void close(AVCodecParserContext *s)
static const int dv_weight_248[64]
void(* fdct[2])(DCTELEM *block)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define OPEN_READER(name, gb)
#define DV_VLC_MAP_LEV_SIZE
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
static unsigned int get_bits1(GetBitContext *s)
static const uint8_t dv100_qstep[16]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static const uint8_t dv_vlc_level[409]
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
uint8_t partial_bit_count
static int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t *buf)
#define DV_MAX_BPM
maximum number of blocks per macroblock in any DV format
static int dv_init_dynamic_tables(const DVprofile *d)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
void(* fdct)(DCTELEM *block)
static const uint8_t dv_vlc_len[409]
static av_always_inline int dv_init_enc_block(EncBlockInfo *bi, uint8_t *data, int linesize, DVVideoContext *s, int bias)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static av_cold int dvvideo_init_encoder(AVCodecContext *avctx)
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
int top_field_first
If the content is interlaced, is top field displayed first.
static void dv_calc_mb_coordinates(const DVprofile *d, int chan, int seq, int slot, uint16_t *tbl)
VLC_TYPE(* table)[2]
code, bits
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
int key_frame
1 -> keyframe, 0-> not
static av_cold int dvvideo_init(AVCodecContext *avctx)
static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
static int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num, uint8_t seq_num, uint8_t dif_num, uint8_t *buf)
static struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]
DVwork_chunk * work_chunks
void ff_free_vlc(VLC *vlc)
void(* idct_put)(uint8_t *dest, int line_size, DCTELEM *block)
static av_always_inline PutBitContext * dv_encode_ac(EncBlockInfo *bi, PutBitContext *pb_pool, PutBitContext *pb_end)
static const int dv_iweight_720_c[64]