28 #define UNCHECKED_BITSTREAM_READER 1
80 s->quant_precision = 5;
83 s->unrestricted_mv = 1;
89 s->unrestricted_mv = 0;
96 s->msmpeg4_version = 1;
100 s->msmpeg4_version = 2;
104 s->msmpeg4_version = 3;
108 s->msmpeg4_version = 4;
112 s->msmpeg4_version = 5;
120 s->msmpeg4_version = 6;
171 if (
s->divx_packed ||
s->avctx->hwaccel) {
176 pos -=
s->parse_context.last_index;
186 if (
pos + 10 > buf_size)
195 const int part_mask =
s->partitioned_frame
197 const int mb_size = 16 >>
s->avctx->lowres;
200 s->last_resync_gb =
s->gb;
201 s->first_slice_line = 1;
202 s->resync_mb_x =
s->mb_x;
203 s->resync_mb_y =
s->mb_y;
207 if (
s->studio_profile) {
212 if (
s->avctx->hwaccel) {
214 ret =
s->avctx->hwaccel->decode_slice(
s->avctx, start,
s->gb.buffer_end - start);
216 s->mb_y =
s->mb_height;
220 if (
s->partitioned_frame) {
221 const int qscale =
s->qscale;
228 s->first_slice_line = 1;
229 s->mb_x =
s->resync_mb_x;
230 s->mb_y =
s->resync_mb_y;
234 for (;
s->mb_y <
s->mb_height;
s->mb_y++) {
236 if (
s->msmpeg4_version) {
237 if (
s->resync_mb_y +
s->slice_height ==
s->mb_y) {
245 if (
s->msmpeg4_version == 1) {
252 for (;
s->mb_x <
s->mb_width;
s->mb_x++) {
257 if (
s->resync_mb_x ==
s->mb_x &&
s->resync_mb_y + 1 ==
s->mb_y)
258 s->first_slice_line = 0;
268 ret =
s->decode_mb(
s,
s->block);
274 const int xy =
s->mb_x +
s->mb_y *
s->mb_stride;
283 s->padding_bug_score--;
285 if (++
s->mb_x >=
s->mb_width) {
294 "Slice mismatch at MB: %d\n", xy);
296 s->mb_x + 1,
s->mb_y,
327 !
s->data_partitioning)
328 s->padding_bug_score += 32;
335 !
s->data_partitioning) {
337 const int bits_left =
s->gb.size_in_bits - bits_count;
339 if (bits_left == 0) {
340 s->padding_bug_score += 16;
341 }
else if (bits_left != 1) {
343 v |= 0x7F >> (7 - (bits_count & 7));
345 if (v == 0x7F && bits_left <= 8)
346 s->padding_bug_score--;
349 s->padding_bug_score += 4;
351 s->padding_bug_score++;
361 !
s->data_partitioning) {
363 s->padding_bug_score += 32;
369 AV_RB64(
s->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
371 s->padding_bug_score += 32;
376 (
s->padding_bug_score > -2 && !
s->data_partitioning))
397 max_extra += 256 * 256 * 256 * 64;
399 if (left > max_extra)
401 "discarding %d junk bits at end, next would be %X\n",
413 "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
426 int buf_size = avpkt->
size;
435 if (
s->low_delay == 0 &&
s->next_picture_ptr) {
438 s->next_picture_ptr =
NULL;
457 "this codec does not support truncated bitstreams\n");
467 if (
s->divx_packed &&
s->bitstream_buffer_size) {
469 for(
i=0;
i < buf_size-3;
i++) {
470 if (buf[
i]==0 && buf[
i+1]==0 && buf[
i+2]==1) {
471 if (buf[
i+3]==0xB0) {
473 s->bitstream_buffer_size = 0;
480 if (
s->bitstream_buffer_size && (
s->divx_packed || buf_size <=
MAX_NVOP_SIZE))
482 s->bitstream_buffer_size);
486 s->bitstream_buffer_size = 0;
490 if (!
s->context_initialized)
500 if (
s->avctx->extradata_size &&
s->picture_number == 0) {
503 if (
init_get_bits8(&gb,
s->avctx->extradata,
s->avctx->extradata_size) >= 0 )
518 av_log(
s->avctx,
AV_LOG_WARNING,
"Reverting picture dimensions change due to header decoding failure\n");
532 if (!
s->context_initialized) {
538 if (!
s->current_picture_ptr ||
s->current_picture_ptr->f->data[0]) {
542 s->current_picture_ptr = &
s->picture[
i];
550 if (
s->studio_profile != (
s->idsp.idct ==
NULL))
562 s->context_reinit = 0;
586 s->current_picture.f->pict_type =
s->pict_type;
590 if (!
s->last_picture_ptr &&
600 if (
s->next_p_frame_damaged) {
604 s->next_p_frame_damaged = 0;
608 s->me.qpel_put =
s->qdsp.put_qpel_pixels_tab;
609 s->me.qpel_avg =
s->qdsp.avg_qpel_pixels_tab;
611 s->me.qpel_put =
s->qdsp.put_no_rnd_qpel_pixels_tab;
612 s->me.qpel_avg =
s->qdsp.avg_qpel_pixels_tab;
618 if (!
s->divx_packed && !avctx->
hwaccel)
623 s->gb.buffer_end -
s->gb.buffer);
646 while (
s->mb_y <
s->mb_height) {
647 if (
s->msmpeg4_version) {
648 if (
s->slice_height == 0 ||
s->mb_x != 0 || slice_ret < 0 ||
652 int prev_x =
s->mb_x, prev_y =
s->mb_y;
655 if (prev_y *
s->mb_width + prev_x < s->mb_y *
s->mb_width +
s->mb_x)
656 s->er.error_occurred = 1;
659 if (
s->msmpeg4_version < 4 &&
s->h263_pred)
666 if (
s->msmpeg4_version &&
s->msmpeg4_version < 4 &&
674 if (!
s->studio_profile)
688 if (!
s->divx_packed && avctx->
hwaccel)
691 av_assert1(
s->current_picture.f->pict_type ==
s->current_picture_ptr->f->pict_type);
692 av_assert1(
s->current_picture.f->pict_type ==
s->pict_type);
694 if ((ret =
av_frame_ref(pict,
s->current_picture_ptr->f)) < 0)
698 }
else if (
s->last_picture_ptr) {
705 if (
s->last_picture_ptr ||
s->low_delay) {
710 for (p=0; p<3; p++) {
714 for (y=0; y<(
h>>1); y++)
717 pict->
data[p][x + y*linesize],
718 pict->
data[p][x + (
h-1-y)*linesize]);
731 #if CONFIG_H263_VAAPI_HWACCEL || CONFIG_MPEG4_VAAPI_HWACCEL
734 #if CONFIG_MPEG4_NVDEC_HWACCEL
737 #if CONFIG_MPEG4_VDPAU_HWACCEL
740 #if CONFIG_H263_VIDEOTOOLBOX_HWACCEL || CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
748 #if CONFIG_H263_VAAPI_HWACCEL
751 #if CONFIG_MPEG4_NVDEC_HWACCEL
754 #if CONFIG_MPEG4_VDPAU_HWACCEL
757 #if CONFIG_H263_VIDEOTOOLBOX_HWACCEL
static void flush(AVCodecContext *avctx)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Libavcodec external API header.
#define AV_EF_IGNORE_ERR
ignore errors and continue
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define AV_EF_BUFFER
detect improper bitstream length
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
#define FF_BUG_AUTODETECT
autodetection
#define FF_BUG_NO_PADDING
static av_cold int init(AVCodecContext *avctx)
#define FFSWAP(type, a, b)
#define AV_CEIL_RSHIFT(a, b)
#define CONFIG_H263_DECODER
#define CONFIG_MPEG4_DECODER
#define CONFIG_WMV2_DECODER
#define CONFIG_FLV_DECODER
#define CONFIG_H263P_DECODER
#define CONFIG_H263I_DECODER
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
void ff_er_frame_end(ERContext *s)
static int get_bits_left(GetBitContext *gb)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
#define AV_CODEC_CAP_TRUNCATED
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_TRUNCATED
Input bitstream might be truncated at a random location instead of only at frame boundaries.
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
@ AVDISCARD_ALL
discard all
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AVDISCARD_NONREF
discard all non reference
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
void ff_h263_update_motion_val(MpegEncContext *s)
void ff_h263_loop_filter(MpegEncContext *s)
int ff_intel_h263_decode_picture_header(MpegEncContext *s)
int ff_h263_resync(MpegEncContext *s)
Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
void ff_h263_decode_init_vlc(void)
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64])
#define H263_GOB_HEIGHT(h)
int ff_h263_decode_picture_header(MpegEncContext *s)
int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
#define HWACCEL_VDPAU(codec)
#define HWACCEL_NVDEC(codec)
#define HWACCEL_VAAPI(codec)
int ff_flv_decode_picture_header(MpegEncContext *s)
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
static enum AVPixelFormat h263_get_format(AVCodecContext *avctx)
const AVCodecHWConfigInternal *const ff_h263_hw_config_list[]
static int get_consumed_bytes(MpegEncContext *s, int buf_size)
Return the number of bytes consumed for building the current frame.
enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[]
av_cold int ff_h263_decode_end(AVCodecContext *avctx)
static int decode_slice(MpegEncContext *s)
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
#define FF_QSCALE_TYPE_MPEG1
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
void ff_mpeg4_clean_buffers(MpegEncContext *s)
int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx)
Decode the next video packet.
int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx)
Decode the first and second partition.
int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header)
Decode MPEG-4 headers.
int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
Find the end of the current frame in the bitstream.
void ff_mpeg_er_frame_start(MpegEncContext *s)
int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
#define FRAME_SKIPPED
Return value for header parsers if frame is not coded.
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
void ff_mpv_common_end(MpegEncContext *s)
void ff_mpv_frame_end(MpegEncContext *s)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
void ff_mpeg_flush(AVCodecContext *avctx)
int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
av_cold void ff_mpv_idct_init(MpegEncContext *s)
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
void ff_init_block_index(MpegEncContext *s)
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
int ff_mpv_common_frame_size_change(MpegEncContext *s)
void ff_mpv_report_decode_progress(MpegEncContext *s)
#define SLICE_END
end marker found
#define SLICE_NOEND
no end marker or error found but mb count exceeded
#define MV_TYPE_16X16
1 vector for the whole mb
static void ff_update_block_index(MpegEncContext *s)
static void frame_end(MpegEncContext *s)
#define CONFIG_MSMPEG4_DECODER
int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size)
int ff_msmpeg4_decode_picture_header(MpegEncContext *s)
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
av_cold void ff_qpeldsp_init(QpelDSPContext *c)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
int has_b_frames
Size of the frame reordering buffer in the decoder.
const struct AVCodec * codec
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int coded_width
Bitstream width / height, may be different from width/height e.g.
enum AVDiscard skip_frame
Skip decoding for selected frames.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
This structure stores compressed data.
int ff_wmv2_decode_picture_header(MpegEncContext *s)
int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)