28 #define UNCHECKED_BITSTREAM_READER 1
68 int mb_x,
int mb_y,
int mb_intra,
int mb_skipped)
126 offset[2] = (y >> vshift) * src->
linesize[1];
195 big_mb_num *
sizeof(uint16_t),
fail)
215 big_mb_num *
sizeof(uint32_t),
fail);
217 big_mb_num *
sizeof(uint32_t),
fail);
221 const int b_xy = 4 * x + 4 * y * h->
b_stride;
244 int yc_size = y_size + 2 * c_size;
255 memset(er, 0,
sizeof(*er));
257 if (CONFIG_ERROR_RESILIENCE) {
289 yc_size *
sizeof(int16_t),
fail);
293 for (i = 0; i < yc_size; i++)
439 "Error resilience with slice threads is enabled. It is unsafe and unsupported and may crash. "
440 "Use it at your own risk\n");
455 memset(h, 0,
sizeof(*h));
566 first_slice != nal->
type)
569 first_slice = nal->
type;
622 if (buf_size > 8 &&
AV_RB32(buf) == 1 &&
AV_RB32(buf+5) > (
unsigned)buf_size) {
624 }
else if(buf_size > 3 &&
AV_RB32(buf) > 1 &&
AV_RB32(buf) <= (
unsigned)buf_size)
632 "Error splitting the input into NAL units.\n");
643 int max_slice_ctx, err;
656 if ((nal->
data[1] & 0xFC) == 0x98) {
664 av_log(h,
AV_LOG_ERROR,
"invalid mixed IDR / non IDR frames cannot be decoded in slice multithreading mode\n");
692 if (CONFIG_H264_VDPAU_DECODER &&
705 if (CONFIG_H264_VDPAU_DECODER &&
744 "SPS decoding failure, trying again with the complete NAL\n");
781 #if CONFIG_ERROR_RESILIENCE
830 return (ret < 0) ? ret : buf_size;
840 if (pos + 10 > buf_size)
868 int cnt= buf[5]&0x1f;
872 if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 7)
881 if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 8)
902 int field = out->
field_poc[0] == INT_MAX;
909 for (p = 0; p<4; p++) {
925 if (CONFIG_MPEGVIDEO) {
939 int *got_frame,
int buf_index)
975 int buf_size = avpkt->
size;
999 if(h->
is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
1017 buf_size >= 4 && !memcmp(
"Q264", buf, 4))
1043 #define OFFSET(x) offsetof(H264Context, x)
1044 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1047 {
"nal_length_size",
"nal_length_size",
OFFSET(nal_length_size),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, 0 },
1048 {
"enable_er",
"Enable error resilience on damaged frames (unsafe)",
OFFSET(enable_er),
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
VD },
1079 #if CONFIG_H264_VDPAU_DECODER && FF_API_VDPAU
1080 static const AVClass h264_vdpau_class = {
1087 AVCodec ff_h264_vdpau_decoder = {
1088 .
name =
"h264_vdpau",
1089 .long_name =
NULL_IF_CONFIG_SMALL(
"H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
1101 .priv_class = &h264_vdpau_class,
int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int bit_length)
Decode PPS.
struct H264Context * h264
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int is_nalff, int nal_length_size, enum AVCodecID codec_id, int small_padding)
Split an input packet into NAL units.
const struct AVCodec * codec
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int sei_recovery_frame_cnt
#define AV_NUM_DATA_POINTERS
#define SLICE_FLAG_ALLOW_FIELD
allow draw_horiz_band() with field slices (MPEG-2 field pics)
int ff_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal)
Submit a slice for decoding.
static int send_next_delayed_frame(H264Context *h, AVFrame *dst_frame, int *got_frame, int buf_index)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
This structure describes decoded (raw) audio or video data.
#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)
int recovery_frame_cnt
recovery_frame_cnt
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
ptrdiff_t const GLvoid * data
static void flush(AVCodecContext *avctx)
int edge_emu_buffer_allocated
static void debug_green_metadata(const H264SEIGreenMetaData *gm, void *logctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
static int init_thread_copy(AVCodecContext *avctx)
#define LIBAVUTIL_VERSION_INT
AVBufferRef * sps_list[MAX_SPS_COUNT]
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
hardware decoding through Videotoolbox
static av_cold int init(AVCodecContext *avctx)
int frame_packing_arrangement_cancel_flag
is previous arrangement canceled, -1 if never received
void ff_er_frame_end(ERContext *s)
int bitstream_restriction_flag
int bipred_scratchpad_allocated
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output...
AVBufferPool * mb_type_pool
static void idr(H264Context *h)
instantaneous decoder refresh.
int16_t(*[2] motion_val)[2]
void ff_h264_flush_change(H264Context *h)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
H264Picture * delayed_pic[MAX_DELAYED_PIC_COUNT+2]
int is_avc
Used to parse AVC variant of H.264.
AVBufferPool * ref_index_pool
void ff_h264_sei_uninit(H264SEIContext *h)
Reset SEI values at the beginning of the frame.
#define AV_CODEC_FLAG2_CHUNKS
Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries...
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static void flush_dpb(AVCodecContext *avctx)
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
int size_bits
Size, in bits, of just the data, excluding the stop bit and any trailing padding. ...
H264SEIGreenMetaData green_metadata
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
int ff_h264_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
uint8_t * chroma_pred_mode_table
void ff_h264_remove_all_refs(H264Context *h)
enum AVDiscard skip_frame
Skip decoding for selected frames.
int ff_h264_execute_decode_slices(H264Context *h)
Call decode_slice() for each context.
int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx)
const char * ff_h264_sei_stereo_mode(const H264SEIFramePacking *h)
Get stereo_mode string from the h264 frame_packing_arrangement.
BYTE int const BYTE * srcp
struct AVHWAccel * hwaccel
Hardware accelerator in use.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#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_assert0(cond)
assert() equivalent, that is always enabled.
static int get_consumed_bytes(int pos, int buf_size)
Return the number of bytes consumed for building the current frame.
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void ff_h264_set_erpic(ERPicture *dst, H264Picture *src)
void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl)
static av_cold int end(AVCodecContext *avctx)
Multithreading support functions.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static int get_last_needed_nal(H264Context *h)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
uint8_t(*[2] top_borders)[(16 *3)*2]
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
int frame_recovered
Initial frame has been completely recovered.
int ff_h264_decode_extradata(const uint8_t *data, int size, H264ParamSets *ps, int *is_avc, int *nal_length_size, int err_recognition, void *logctx)
#define PICT_BOTTOM_FIELD
#define AV_CODEC_CAP_HWACCEL_VDPAU
Codec can export data for HW decoding (VDPAU).
static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
AVDictionary * metadata
metadata.
int has_slice
slice NAL is found in the packet, set by decode_nal_units, its state does not need to be preserved ou...
static int h264_init_context(AVCodecContext *avctx, H264Context *h)
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...
high precision timer, useful to profile code
int recovered
picture at IDR or recovery point + recovery count
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int last_pocs[MAX_DELAYED_PIC_COUNT]
H.264 common definitions.
void ff_h264_draw_horiz_band(const H264Context *h, H264SliceContext *sl, int y, int height)
H.264 parameter set handling.
H264Picture DPB[H264_MAX_PICTURE_COUNT]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static const AVClass h264_class
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it...
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const AVOption h264_options[]
int active_thread_type
Which multithreading methods are in use by the codec.
int capabilities
Codec capabilities.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void(* decode_mb)(void *opaque, int ref, int mv_dir, int mv_type, int(*mv)[2][4][2], int mb_x, int mb_y, int mb_intra, int mb_skipped)
uint8_t(*[2] mvd_table)[2]
static av_cold int h264_decode_end(AVCodecContext *avctx)
int prev_interlaced_frame
Complement sei_pic_struct SEI_PIC_STRUCT_TOP_BOTTOM and SEI_PIC_STRUCT_BOTTOM_TOP indicate interlaced...
int flags
AV_CODEC_FLAG_*.
static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *got_frame)
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
H264SEIUnregistered unregistered
static const uint8_t offset[127][2]
uint8_t * list_counts
Array of list_count per MB specifying the slice type.
static void * av_mallocz_array(size_t nmemb, size_t size)
uint8_t active_format_description
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
uint8_t * error_status_table
int nal_length_size
Number of bytes used for nal length (1, 2 or 4)
useful rectangle filling function
int prev_poc_msb
poc_msb of the last reference pic for POC type 0
void ff_vdpau_h264_picture_start(H264Context *h)
void(* draw_horiz_band)(struct AVCodecContext *s, const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, int height)
If non NULL, 'draw_horiz_band' is called by the libavcodec decoder to draw a horizontal band...
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define FF_THREAD_FRAME
Decode more than one frame at once.
uint16_t * slice_table
slice_table_base + 2*mb_stride + 1
static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, int(*mv)[2][4][2], int mb_x, int mb_y, int mb_intra, int mb_skipped)
static int is_extra(const uint8_t *buf, int buf_size)
static const uint8_t start_code[]
int width
picture width / height.
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Context Adaptive Binary Arithmetic Coder inline functions.
H.264 / AVC / MPEG-4 part10 codec.
H264SliceContext * slice_ctx
#define AV_EF_EXPLODE
abort decoding on minor error detection
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
int top_borders_allocated[2]
static void fill_rectangle(int x, int y, int w, int h)
int ref_idc
H.264 only, nal_ref_idc.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
uint8_t * edge_emu_buffer
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static const int8_t mv[256][2]
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Libavcodec external API header.
#define MAX_DELAYED_PIC_COUNT
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
int field_poc[2]
top/bottom POC
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int recovery_frame
recovery_frame is the frame_num at which the next frame should be fully constructed.
main external API structure.
uint8_t * data
The data buffer.
static AVOnce h264_vlc_init
void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table, uint32_t *mbtype_table, int8_t *qscale_table, int16_t(*motion_val[2])[2], int *low_delay, int mb_width, int mb_height, int mb_stride, int quarter_sample)
Print debugging info for the given picture.
static const uint8_t scan8[16 *3+3]
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
H.264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstre...
int slice_flags
slice flags
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
Describe the class of an AVClass context structure.
int prev_frame_num
frame_num of the last pic for POC type 1/2
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
av_cold void ff_h264_decode_init_vlc(void)
int mmco_reset
MMCO_RESET set this 1.
H264Picture * cur_pic_ptr
int mb_mbaff
mb_aff_frame && mb_field_decoding_flag
#define FF_DEBUG_GREEN_MD
attribute_deprecated int dtg_active_format
DTG active format information (additional aspect ratio information only used in DVB MPEG-2 transport ...
int allocate_progress
Whether to allocate progress for frame threading.
H264SEIRecoveryPoint recovery_point
static enum AVPixelFormat pix_fmts[]
int size
Size of data in bytes.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
int ff_h264_alloc_tables(H264Context *h)
Allocate tables.
discard all non reference
int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
AVBufferPool * qscale_table_pool
H264Picture * next_output_pic
AVBufferPool * motion_val_pool
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
static int ref[MAX_W *MAX_W]
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)
uint16_t * slice_table_base
H264SEIFramePacking frame_packing
H.264 / AVC / MPEG-4 part10 motion vector prediction.
int workaround_bugs
Work around bugs in encoders which sometimes cannot be detected automatically.
const AVProfile ff_h264_profiles[]
int cur_chroma_format_idc
int8_t * intra4x4_pred_mode
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static int h264_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
void ff_h264_free_tables(H264Context *h)
int8_t ref_cache[2][5 *8]
#define AV_CODEC_FLAG_OUTPUT_CORRUPT
Output even those frames that might be corrupted.
#define FF_ENABLE_DEPRECATION_WARNINGS
int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int ignore_truncation)
Decode SPS.
struct AVCodecInternal * internal
Private context used for internal data.
static int ff_thread_once(char *control, void(*routine)(void))
#define PART_NOT_AVAILABLE
int key_frame
1 -> keyframe, 0-> not
int current_slice
current slice number, used to initialize slice_num of each thread/context
int flags2
AV_CODEC_FLAG2_*.
H264Ref ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
static av_cold int h264_decode_init(AVCodecContext *avctx)
H264Picture last_pic_for_ec
#define AV_CODEC_FLAG2_SHOW_ALL
Show all frames before the first keyframe.
uint8_t(*[2] mvd_table)[2]
int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb, const H264ParamSets *ps, void *logctx)
int prev_frame_num_offset
for POC type 2
void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf, int buf_size)
int8_t * intra4x4_pred_mode
int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl)
Init context Allocate buffers which are not shared amongst multiple threads.
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
int mb_field_decoding_flag
uint8_t(* non_zero_count)[48]
uint8_t * bipred_scratchpad
void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
const uint16_t ff_h264_mb_sizes[4]
Context Adaptive Binary Arithmetic Coder.
#define H264_MAX_PICTURE_COUNT