28#define UNCHECKED_BITSTREAM_READER 1
30#include "config_components.h"
53#if CONFIG_H263_VAAPI_HWACCEL || CONFIG_MPEG4_VAAPI_HWACCEL
56#if CONFIG_MPEG4_NVDEC_HWACCEL
59#if CONFIG_MPEG4_NVDEC_CUARRAY_HWACCEL
62#if CONFIG_MPEG4_VDPAU_HWACCEL
65#if CONFIG_H263_VIDEOTOOLBOX_HWACCEL || CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
97 MPVContext *
const s = &
h->c;
111 s->y_dc_scale_table =
115 s->idsp.idct_permutation);
117 s->idsp.idct_permutation);
138 s->msmpeg4_version = MSMP4_V1;
142 s->msmpeg4_version = MSMP4_V2;
146 s->msmpeg4_version = MSMP4_V3;
150 s->msmpeg4_version = MSMP4_WMV1;
154 s->msmpeg4_version = MSMP4_WMV2;
159#if CONFIG_H263I_DECODER
164#if CONFIG_FLV_DECODER
170 av_unreachable(
"Switch contains a case for every codec using ff_h263_decode_init()");
200 const int part_mask =
h->partitioned_frame
202 const int mb_size = 16 >>
h->c.avctx->lowres;
205 h->last_resync_gb =
h->gb;
206 h->c.first_slice_line = 1;
207 h->c.resync_mb_x =
h->c.mb_x;
208 h->c.resync_mb_y =
h->c.mb_y;
212#if CONFIG_MPEG4_DECODER
213 if (
h->c.studio_profile) {
219 if (
h->c.avctx->hwaccel) {
224 h->c.mb_y =
h->c.mb_height;
228#if CONFIG_MPEG4_DECODER
229 if (
h->partitioned_frame) {
230 const int qscale =
h->c.qscale;
239 h->c.first_slice_line = 1;
240 h->c.mb_x =
h->c.resync_mb_x;
241 h->c.mb_y =
h->c.resync_mb_y;
246 for (;
h->c.mb_y <
h->c.mb_height;
h->c.mb_y++) {
248 if (
h->c.msmpeg4_version != MSMP4_UNUSED) {
249 if (
h->c.resync_mb_y +
h->slice_height ==
h->c.mb_y) {
257 if (
h->c.msmpeg4_version == MSMP4_V1) {
264 for (;
h->c.mb_x <
h->c.mb_width;
h->c.mb_x++) {
268 h->c.avctx->lowres,
h->c.chroma_x_shift);
270 if (
h->c.resync_mb_x ==
h->c.mb_x &&
h->c.resync_mb_y + 1 ==
h->c.mb_y)
271 h->c.first_slice_line = 0;
280 ff_tlog(
NULL,
"Decoding MB at %dx%d\n",
h->c.mb_x,
h->c.mb_y);
281 ret =
h->decode_mb(
h);
283 if (
h->c.h263_pred ||
h->c.h263_aic) {
284 int mb_xy =
h->c.mb_y *
h->c.mb_stride +
h->c.mb_x;
285 if (!
h->c.mb_intra) {
288 h->c.mbintra_table[mb_xy] = 1;
295 const int xy =
h->c.mb_x +
h->c.mb_y *
h->c.mb_stride;
304 h->padding_bug_score--;
306 if (++
h->c.mb_x >=
h->c.mb_width) {
315 "Slice mismatch at MB: %d\n", xy);
317 h->c.mb_x + 1,
h->c.mb_y,
348 !
h->data_partitioning)
349 h->padding_bug_score += 32;
356 !
h->data_partitioning) {
358 const int bits_left =
h->gb.size_in_bits - bits_count;
361 h->padding_bug_score += 16;
364 v |= 0x7F >> (7 - (bits_count & 7));
367 h->padding_bug_score--;
370 h->padding_bug_score += 4;
372 h->padding_bug_score++;
382 !
h->data_partitioning) {
384 h->padding_bug_score += 32;
392 h->padding_bug_score += 32;
397 (
h->padding_bug_score > -2 && !
h->data_partitioning))
418 max_extra += 256 * 256 * 256 * 64;
420 if (
left > max_extra)
422 "discarding %d junk bits at end, next would be %X\n",
434 "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
447 MPVContext *
const s = &
h->c;
448 const uint8_t *buf = avpkt->
data;
449 int buf_size = avpkt->
size;
452 int bak_width, bak_height;
457 if ((!
h->c.low_delay ||
h->skipped_last_frame) &&
h->c.next_pic.ptr) {
460 if (
h->skipped_last_frame) {
482 bak_width =
h->c.width;
483 bak_height =
h->c.height;
486 ret =
h->decode_header(
h);
488 if (
h->c.width != bak_width
489 ||
h->c.height != bak_height) {
490 av_log(
h->c.avctx,
AV_LOG_WARNING,
"Reverting picture dimensions change due to header decoding failure\n");
491 h->c.width = bak_width;
492 h->c.height= bak_height;
505 if (!
h->c.context_initialized) {
513#if CONFIG_MPEG4_DECODER
518 if (
h->c.studio_profile != (
h->c.idsp.idct ==
NULL))
527 h->c.context_reinit) {
529 h->c.context_reinit = 0;
548 if (!
h->c.last_pic.ptr &&
572 s->pp_time,
s->pb_time);
577#if CONFIG_WMV2_DECODER
578 if (
h->c.msmpeg4_version == MSMP4_WMV2) {
592 while (
h->c.mb_y <
h->c.mb_height) {
593 if (
h->c.msmpeg4_version != MSMP4_UNUSED) {
594 if (
h->slice_height == 0 ||
h->c.mb_x != 0 || slice_ret < 0 ||
598 int prev_x =
h->c.mb_x, prev_y =
h->c.mb_y;
601 if (prev_y *
h->c.mb_width + prev_x < h->
c.mb_y *
h->c.mb_width +
h->c.mb_x)
602 h->c.er.error_occurred = 1;
605 if (
h->c.msmpeg4_version < MSMP4_WMV1 &&
h->c.h263_pred)
612 if (
h->c.msmpeg4_version != MSMP4_UNUSED &&
h->c.msmpeg4_version < MSMP4_WMV1 &&
614 if (!CONFIG_MSMPEG4DEC ||
619 if (!
h->c.studio_profile)
630#if CONFIG_MPEG4_DECODER
635 av_assert1(
h->c.pict_type ==
h->c.cur_pic.ptr->f->pict_type);
641 }
else if (
h->c.last_pic.ptr) {
648 if (
h->c.last_pic.ptr ||
h->c.low_delay) {
650 && (
h->c.codec_tag ==
AV_RL32(
"GEOV") ||
h->c.codec_tag ==
AV_RL32(
"GEOX"))) {
651 for (
int p = 0; p < 3; p++) {
668#if CONFIG_H263_VAAPI_HWACCEL
671#if CONFIG_MPEG4_NVDEC_HWACCEL
674#if CONFIG_MPEG4_NVDEC_CUARRAY_HWACCEL
677#if CONFIG_MPEG4_VDPAU_HWACCEL
680#if CONFIG_H263_VIDEOTOOLBOX_HWACCEL
688 CODEC_LONG_NAME(
"H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
706 CODEC_LONG_NAME(
"H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
const FFCodec ff_h263p_decoder
const FFCodec ff_h263_decoder
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Libavcodec external API header.
#define FF_BUG_AUTODETECT
autodetection
#define FF_BUG_NO_PADDING
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#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...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AV_CEIL_RSHIFT(a, b)
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
#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/muxer should not do as an error
int(* init)(AVBSFContext *ctx)
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, int *decode_error_flags)
Indicate that a frame has finished decoding and perform error concealment in case it has been enabled...
static int decode_slice(AVCodecContext *c, void *arg)
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.
static int get_bits_bytesize(const GetBitContext *s, int round_up)
Get the size of the GetBitContext's buffer in bytes.
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#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_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.
#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)
static void ff_h263_clean_intra_table_entries(MpegEncContext *s, int xy)
void ff_h263_decode_init_vlc(void)
int ff_h263_decode_picture_header(H263DecContext *const h)
int ff_intel_h263_decode_picture_header(H263DecContext *const h)
#define SLICE_NOEND
no end marker or error found but mb count exceeded
int ff_h263_decode_mb(H263DecContext *const h)
#define FRAME_SKIPPED
Frame is not coded.
int ff_h263_resync(H263DecContext *const h)
Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
#define FF_HW_SIMPLE_CALL(avctx, function)
#define FF_HW_CALL(avctx, function,...)
#define HWACCEL_NVDEC_CUARRAY(codec)
#define HWACCEL_VDPAU(codec)
#define HWACCEL_NVDEC(codec)
#define HWACCEL_VAAPI(codec)
#define HWACCEL_VIDEOTOOLBOX(codec)
int ff_flv_decode_picture_header(H263DecContext *const h)
#define SLICE_END
end marker found
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
static int decode_slice(H263DecContext *const h)
static enum AVPixelFormat h263_get_format(AVCodecContext *avctx)
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
static enum AVPixelFormat h263_hwaccel_pixfmt_list_420[]
static void report_decode_progress(H263DecContext *const h)
static const AVCodecHWConfigInternal *const h263_hw_config_list[]
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
Multithreading API for decoders.
void ff_mpeg4_clean_buffers(MpegEncContext *s)
int ff_mpeg4_decode_partitions(H263DecContext *const h)
Decode the first and second partition.
int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
Decode the next video packet.
int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
static void ff_mpv_er_frame_start_ext(MPVContext *const s, int partitioned_frame, uint16_t pp_time, uint16_t pb_time)
void ff_mpv_unref_picture(MPVWorkPicture *pic)
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
av_cold void ff_mpv_idct_init(MpegEncContext *s)
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
void ff_init_block_index(MpegEncContext *s)
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
#define MV_TYPE_16X16
1 vector for the whole mb
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
av_cold void ff_mpeg_flush(AVCodecContext *avctx)
void ff_mpv_frame_end(MpegEncContext *s)
int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, const MPVPicture *p, int qp_type)
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[][64])
av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
av_cold int ff_mpv_common_frame_size_change(MpegEncContext *s)
#define ff_mpv_unquantize_init(s, bitexact, q_scale_type)
const uint8_t ff_alternate_horizontal_scan[64]
const uint8_t ff_alternate_vertical_scan[64]
static const uint8_t *const ff_mpeg1_dc_scale_table
mpegvideo decoder header.
#define FF_MPV_QSCALE_TYPE_MPEG1
int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size)
@ 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_CUARRAY
hardware decoding through openharmony
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
@ 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...
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
Out-of-band global headers that may be used by some codecs.
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.
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, a positive or negative value, which is typically indicating the size in bytes of each pict...
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This structure stores compressed data.
void(* dct_unquantize_h263_inter)(const MPVContext *s, int16_t *block, int n, int qscale)
void(* dct_unquantize_h263_intra)(const MPVContext *s, int16_t *block, int n, int qscale)
static int64_t frame_end(const SyncQueue *sq, SyncQueueFrame frame, int nb_samples)
Compute the end timestamp of a frame.
void ff_thread_progress_report(ThreadProgress *pro, int n)
This function is a no-op in no-op mode; otherwise it notifies other threads that a certain level of p...
int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h)