/** * Fill the gain array for the timedomain quantization. * * @param gb pointer to the GetBitContext * @param gaininfo array[9] of gain indexes */ static void decode_gain_info(GetBitContext *gb, int *gaininfo) { int i, n; n = get_unary(gb, 0, get_bits_left(gb)); // amount of elements*2 to update i = 0; while (n--) { int index = get_bits(gb, 3); int gain = get_bits1(gb) ? get_bits(gb, 4) - 7 : -1; while (i <= index) gaininfo[i++] = gain; } while (i <= 8) gaininfo[i++] = 0; }
static inline int decode_subframe(FLACContext *s, int channel) { int32_t *decoded = s->decoded[channel]; int type, wasted = 0; int bps = s->bps; int i, tmp, ret; if (channel == 0) { if (s->ch_mode == FLAC_CHMODE_RIGHT_SIDE) bps++; } else { if (s->ch_mode == FLAC_CHMODE_LEFT_SIDE || s->ch_mode == FLAC_CHMODE_MID_SIDE) bps++; } if (get_bits1(&s->gb)) { av_log(s->avctx, AV_LOG_ERROR, "invalid subframe padding\n"); return AVERROR_INVALIDDATA; } type = get_bits(&s->gb, 6); if (get_bits1(&s->gb)) { int left = get_bits_left(&s->gb); if ( left <= 0 || (left < bps && !show_bits_long(&s->gb, left)) || !show_bits_long(&s->gb, bps)) { av_log(s->avctx, AV_LOG_ERROR, "Invalid number of wasted bits > available bits (%d) - left=%d\n", bps, left); return AVERROR_INVALIDDATA; } wasted = 1 + get_unary(&s->gb, 1, get_bits_left(&s->gb)); bps -= wasted; } if (bps > 32) { avpriv_report_missing_feature(s->avctx, "Decorrelated bit depth > 32"); return AVERROR_PATCHWELCOME; } //FIXME use av_log2 for types if (type == 0) { tmp = get_sbits_long(&s->gb, bps); for (i = 0; i < s->blocksize; i++) decoded[i] = tmp; } else if (type == 1) { for (i = 0; i < s->blocksize; i++) decoded[i] = get_sbits_long(&s->gb, bps); } else if ((type >= 8) && (type <= 12)) { if ((ret = decode_subframe_fixed(s, decoded, type & ~0x8, bps)) < 0) return ret; } else if (type >= 32) { if ((ret = decode_subframe_lpc(s, decoded, (type & ~0x20)+1, bps)) < 0) return ret; } else { av_log(s->avctx, AV_LOG_ERROR, "invalid coding type\n"); return AVERROR_INVALIDDATA; } if (wasted) { int i; for (i = 0; i < s->blocksize; i++) decoded[i] <<= wasted; } return 0; }
static AVPictureType parse_picture_type(const uint8_t *buf, int buflen, CVC1HeaderParser *vc1Header) { AVPictureType pictype = AV_PICTURE_TYPE_NONE; int skipped = 0; const BYTE *framestart = buf; if (IS_MARKER(AV_RB32(buf))) { framestart = NULL; const BYTE *start, *end, *next; next = buf; for (start = buf, end = buf + buflen; next < end; start = next) { if (AV_RB32(start) == VC1_CODE_FRAME) { framestart = start + 4; break; } next = find_next_marker(start + 4, end); } } if (framestart) { GetBitContext gb; init_get_bits(&gb, framestart, (buflen - (framestart-buf))*8); if (vc1Header->hdr.profile == PROFILE_ADVANCED) { int fcm = PROGRESSIVE; if (vc1Header->hdr.interlaced) fcm = decode012(&gb); if (fcm == ILACE_FIELD) { int fptype = get_bits(&gb, 3); pictype = (fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; if (fptype & 4) // B-picture pictype = (fptype & 2) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B; } else { switch (get_unary(&gb, 0, 4)) { case 0: pictype = AV_PICTURE_TYPE_P; break; case 1: pictype = AV_PICTURE_TYPE_B; break; case 2: pictype = AV_PICTURE_TYPE_I; break; case 3: pictype = AV_PICTURE_TYPE_BI; break; case 4: pictype = AV_PICTURE_TYPE_P; // skipped pic skipped = 1; break; } } } else { if (vc1Header->hdr.finterp) skip_bits1(&gb); skip_bits(&gb, 2); // framecnt if (vc1Header->hdr.rangered) skip_bits1(&gb); int pic = get_bits1(&gb); if (vc1Header->hdr.bframes) { if (!pic) { if (get_bits1(&gb)) { pictype = AV_PICTURE_TYPE_I; } else { pictype = AV_PICTURE_TYPE_B; } } else { pictype = AV_PICTURE_TYPE_P; } } else { pictype = pic ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; } } } return pictype; }
/** * Picture layer bitstream encoder for Simple and Main Profile * @param s Mpeg encoder context * @param picture_number number of the frame to encode */ void ff_vc1_encode_picture_header(MpegEncContext * s, int picture_number) { VC1Context * const t= s->avctx->priv_data; ff_find_best_tables(s); if( t->finterpflag ) { t->interpfrm = 0;//INTERPFRM put_bits(&s->pb,1,t->interpfrm); } put_bits(&s->pb,2,picture_number);//FRMCNT if( t->rangered ){ t->rangeredfrm = 0;//RANGEREDFRM put_bits(&s->pb,1,t->rangeredfrm); } if (s->pict_type == I_TYPE) put_bits(&s->pb,1,0);//PTYPE else if (s->pict_type == P_TYPE) put_bits(&s->pb,1,1);//PTYPE if (s->pict_type == I_TYPE) put_bits(&s->pb,7,50);//BF if(s->qscale > 8 ) { t->halfpq = 0; } else { t->halfpq = 1; } t->pqindex = s->qscale; put_bits(&s->pb,5,t->pqindex);//PQINDEX if( t->quantizer_mode == QUANT_FRAME_IMPLICIT){ //TODO create table } if( t->pqindex <= 8 ) put_bits(&s->pb,1,t->halfpq);//HALFQP t->pquantizer = 1; if (t->quantizer_mode == QUANT_FRAME_IMPLICIT) t->pquantizer = t->pqindex < 9; if (t->quantizer_mode == QUANT_NON_UNIFORM) t->pquantizer = 0; if( t->quantizer_mode == QUANT_FRAME_EXPLICIT ) put_bits(&s->pb,1,t->pquantizer);//PQUANTIZER : NON_UNIFOMR 0 / UNIFORM 1 if( t->extended_mv ) { t->mvrange = 0; put_bits(&s->pb,1,t->mvrange);//TODO fix this: num bits is not fixed } if( t->multires ) { t->respic = 0; put_bits(&s->pb,2,t->respic); } if (s->pict_type == P_TYPE) { /* TODO : Write P_TYPE header info */ /* is read like this : */ #if 0 if (v->pq < 5) v->tt_index = 0; else if(v->pq < 13) v->tt_index = 1; else v->tt_index = 2; lowquant = (v->pq > 12) ? 0 : 1; v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)]; if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { int scale, shift, i; v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)]; v->lumscale = get_bits(gb, 6); v->lumshift = get_bits(gb, 6); v->use_ic = 1; /* fill lookup tables for intensity compensation */ if(!v->lumscale) { scale = -64; shift = (255 - v->lumshift * 2) << 6; if(v->lumshift > 31) shift += 128 << 6; } else { scale = v->lumscale + 32; if(v->lumshift > 31) shift = (v->lumshift - 64) << 6; else shift = v->lumshift << 6; } for(i = 0; i < 256; i++) { v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6); v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6); } } if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) v->s.quarter_sample = 0; else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) { if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN) v->s.quarter_sample = 0; else v->s.quarter_sample = 1; } else v->s.quarter_sample = 1; v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)); if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) { status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v); if (status < 0) return -1; av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " "Imode: %i, Invert: %i\n", status>>1, status&1); } else {
static GstFlowReturn gst_tta_dec_chain (GstPad * pad, GstBuffer * in) { GstTtaDec *ttadec; GstBuffer *outbuf, *buf = GST_BUFFER (in); guchar *data, *p; decoder *dec; unsigned long outsize; unsigned long size; guint32 frame_samples; long res; long *prev; ttadec = GST_TTA_DEC (GST_OBJECT_PARENT (pad)); data = GST_BUFFER_DATA (buf); size = GST_BUFFER_SIZE (buf); ttadec->tta_buf.bit_count = 0; ttadec->tta_buf.bit_cache = 0; ttadec->tta_buf.bitpos = ttadec->tta_buf.buffer_end; ttadec->tta_buf.offset = 0; decoder_init (ttadec->tta, ttadec->channels, ttadec->bytes); if (GST_BUFFER_DURATION_IS_VALID (buf)) { frame_samples = ceil ((gdouble) (GST_BUFFER_DURATION (buf) * ttadec->samplerate) / (gdouble) GST_SECOND); } else { frame_samples = ttadec->samplerate * FRAME_TIME; } outsize = ttadec->channels * frame_samples * ttadec->bytes; dec = ttadec->tta; p = ttadec->decdata; prev = ttadec->cache; for (res = 0; p < ttadec->decdata + frame_samples * ttadec->channels * ttadec->bytes;) { unsigned long unary, binary, depth, k; long value, temp_value; fltst *fst = &dec->fst; adapt *rice = &dec->rice; long *last = &dec->last; // decode Rice unsigned get_unary (&ttadec->tta_buf, data, size, &unary); switch (unary) { case 0: depth = 0; k = rice->k0; break; default: depth = 1; k = rice->k1; unary--; } if (k) { get_binary (&ttadec->tta_buf, data, size, &binary, k); value = (unary << k) + binary; } else value = unary; switch (depth) { case 1: rice->sum1 += value - (rice->sum1 >> 4); if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1]) rice->k1--; else if (rice->sum1 > shift_16[rice->k1 + 1]) rice->k1++; value += bit_shift[rice->k0]; default: rice->sum0 += value - (rice->sum0 >> 4); if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0]) rice->k0--; else if (rice->sum0 > shift_16[rice->k0 + 1]) rice->k0++; } /* this only uses a temporary variable to silence a gcc warning */ temp_value = DEC (value); value = temp_value; // decompress stage 1: adaptive hybrid filter hybrid_filter (fst, &value); // decompress stage 2: fixed order 1 prediction switch (ttadec->bytes) { case 1: value += PREDICTOR1 (*last, 4); break; // bps 8 case 2: value += PREDICTOR1 (*last, 5); break; // bps 16 case 3: value += PREDICTOR1 (*last, 5); break; // bps 24 case 4: value += *last; break; // bps 32 } *last = value; if (dec < ttadec->tta + ttadec->channels - 1) { *prev++ = value; dec++; } else { *prev = value; if (ttadec->channels > 1) { long *r = prev - 1; for (*prev += *r / 2; r >= ttadec->cache; r--) *r = *(r + 1) - *r; for (r = ttadec->cache; r < prev; r++) WRITE_BUFFER (r, ttadec->bytes, p); } WRITE_BUFFER (prev, ttadec->bytes, p); prev = ttadec->cache; res++; dec = ttadec->tta; } } outbuf = gst_buffer_new_and_alloc (outsize); memcpy (GST_BUFFER_DATA (outbuf), ttadec->decdata, outsize); GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (ttadec->srcpad)); return gst_pad_push (ttadec->srcpad, outbuf); }