static void vc1_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t *buf, int buf_size) { VC1ParseContext *vpc = (VC1ParseContext *)s->priv_data; GetBitContext gb; const uint8_t *start, *end, *next; uint8_t *buf2 = (uint8_t *)av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); vpc->v.s.avctx = avctx; vpc->v.parse_only = 1; next = buf; s->repeat_pict = 0; for(start = buf, end = buf + buf_size; next < end; start = next){ int buf2_size, size; next = find_next_marker(start + 4, end); size = next - start - 4; buf2_size = vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&gb, buf2, buf2_size * 8); if(size <= 0) continue; switch(AV_RB32(start)){ case VC1_CODE_SEQHDR: vc1_decode_sequence_header(avctx, &vpc->v, &gb); break; case VC1_CODE_ENTRYPOINT: vc1_decode_entry_point(avctx, &vpc->v, &gb); break; case VC1_CODE_FRAME: if(vpc->v.profile < PROFILE_ADVANCED) vc1_parse_frame_header (&vpc->v, &gb); else vc1_parse_frame_header_adv(&vpc->v, &gb); /* keep AV_PICTURE_TYPE_BI internal to VC1 */ if (vpc->v.s.pict_type == AV_PICTURE_TYPE_BI) s->pict_type = AV_PICTURE_TYPE_B; else s->pict_type = vpc->v.s.pict_type; if (avctx->ticks_per_frame > 1){ // process pulldown flags s->repeat_pict = 1; // Pulldown flags are only valid when 'broadcast' has been set. // So ticks_per_frame will be 2 if (vpc->v.rff){ // repeat field s->repeat_pict = 2; }else if (vpc->v.rptfrm){ // repeat frames s->repeat_pict = vpc->v.rptfrm * 2 + 1; } } break; } } av_free(buf2); }
static void vc1_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t *buf, int buf_size) { VC1ParseContext *vpc = s->priv_data; GetBitContext gb; const uint8_t *start, *end, *next; uint8_t *buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); vpc->v.s.avctx = avctx; vpc->v.parse_only = 1; next = buf; for(start = buf, end = buf + buf_size; next < end; start = next) { int buf2_size, size; next = find_next_marker(start + 4, end); size = next - start - 4; buf2_size = vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&gb, buf2, buf2_size * 8); if(size <= 0) continue; switch(AV_RB32(start)) { case VC1_CODE_SEQHDR: vc1_decode_sequence_header(avctx, &vpc->v, &gb); break; case VC1_CODE_ENTRYPOINT: vc1_decode_entry_point(avctx, &vpc->v, &gb); break; case VC1_CODE_FRAME: if(vpc->v.profile < PROFILE_ADVANCED) vc1_parse_frame_header (&vpc->v, &gb); else vc1_parse_frame_header_adv(&vpc->v, &gb); /* keep FF_BI_TYPE internal to VC1 */ if (vpc->v.s.pict_type == FF_BI_TYPE) s->pict_type = FF_B_TYPE; else s->pict_type = vpc->v.s.pict_type; break; } } av_free(buf2); }
void CVC1HeaderParser::ParseVC1Header(const BYTE *pData, size_t length, AVCodecID codec) { GetBitContext gb; if (codec == AV_CODEC_ID_VC1) { if (length < 16) return; const uint8_t *start = pData; const uint8_t *end = start + length; const uint8_t *next = nullptr; int size, buf2_size; uint8_t *buf2; buf2 = (uint8_t *)av_mallocz(length + FF_INPUT_BUFFER_PADDING_SIZE); start = find_next_marker(start, end); next = start; for(; next < end; start = next) { next = find_next_marker(start + 4, end); size = (int)(next - start - 4); if(size <= 0) continue; buf2_size = vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&gb, buf2, buf2_size * 8); switch(AV_RB32(start)) { case VC1_CODE_SEQHDR: VC1ParseSequenceHeader(&gb); break; } } av_freep(&buf2); } else if (codec == AV_CODEC_ID_WMV3) { if (length < 4) return; init_get_bits(&gb, pData, length * 8); VC1ParseSequenceHeader(&gb); } }
int av_vc1_decode_frame(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int *nFrameSize) { int n_slices = 0, i; VC1Context *v = avctx->priv_data; MpegEncContext *s = &v->s; uint8_t *buf2 = NULL; const uint8_t *buf_start = buf, *buf_start_second_field = NULL; struct { uint8_t *buf; GetBitContext gb; int mby_start; } *slices = NULL, *tmp; v->second_field = 0; *nFrameSize = 0; /* for advanced profile we may need to parse and unescape data */ if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { int buf_size2 = 0; buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */ const uint8_t *start, *end, *next; int size; next = buf; for (start = buf, end = buf + buf_size; next < end; start = next) { next = find_next_marker(start + 4, end); size = next - start - 4; if (size <= 0) continue; switch (AV_RB32(start)) { case VC1_CODE_FRAME: buf_start = start; buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); break; case VC1_CODE_FIELD: { int buf_size3; buf_start_second_field = start; slices = av_realloc(slices, sizeof(*slices) * (n_slices + 1)); if (!slices) goto err; slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!slices[n_slices].buf) goto err; buf_size3 = vc1_unescape_buffer(start + 4, size, slices[n_slices].buf); init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); /* assuming that the field marker is at the exact middle, hope it's correct */ slices[n_slices].mby_start = s->mb_height >> 1; n_slices++; break; } case VC1_CODE_ENTRYPOINT: /* it should be before frame data */ buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); init_get_bits(&s->gb, buf2, buf_size2 * 8); ff_vc1_decode_entry_point(avctx, v, &s->gb); break; case VC1_CODE_SLICE: { int buf_size3; slices = av_realloc(slices, sizeof(*slices) * (n_slices + 1)); if (!slices) goto err; slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!slices[n_slices].buf) goto err; buf_size3 = vc1_unescape_buffer(start + 4, size, slices[n_slices].buf); init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, buf_size3 << 3); slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9); n_slices++; break; } } } } else if (v->interlace && ((buf[0] & 0xC0) == 0xC0)) { /* WVC1 interlaced stores both fields divided by marker */