28 #define UNCHECKED_BITSTREAM_READER 1 69 int mb_x,
int mb_y,
int mb_intra,
int mb_skipped)
127 offset[2] = (y >> vshift) * src->
linesize[1];
185 const int st_size = big_mb_num + h->
mb_stride;
209 const int b_xy = 4 * x + 4 * y * h->
b_stride;
228 int yc_size = y_size + 2 * c_size;
239 memset(er, 0,
sizeof(*er));
240 }
else if (CONFIG_ERROR_RESILIENCE) {
271 for (i = 0; i < yc_size; i++)
395 "Error decoding the extradata\n");
416 "Error resilience with slice threads is enabled. It is unsafe and unsupported and may crash. " 417 "Use it at your own risk\n");
517 first_slice != nal->
type)
520 first_slice = nal->
type;
574 if (buf_size > 8 &&
AV_RB32(buf) == 1 &&
AV_RB32(buf+5) > (
unsigned)buf_size) {
576 }
else if(buf_size > 3 &&
AV_RB32(buf) > 1 &&
AV_RB32(buf) <= (
unsigned)buf_size)
584 "Error splitting the input into NAL units.\n");
595 int max_slice_ctx, err;
608 if ((nal->
data[1] & 0xFC) == 0x98) {
677 "SPS decoding failure, trying again with the complete NAL\n");
720 if ((ret < 0 || h->slice_ctx->er.error_occurred) && h->
cur_pic_ptr) {
727 #if CONFIG_ERROR_RESILIENCE 774 return (ret < 0) ? ret : buf_size;
784 if (pos + 10 > buf_size)
809 const unsigned int block_idx = y * p->
mb_width + x;
810 const unsigned int mb_xy = y * p->
mb_stride + x;
852 int cnt= buf[5]&0x1f;
858 if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 7)
867 if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 8)
895 for (p = 0; p<4; p++) {
911 if (CONFIG_MPEGVIDEO) {
925 int *got_frame,
int buf_index)
961 int buf_size = avpkt->
size;
984 if (h->
is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC) {
1002 buf_size >= 4 && !memcmp(
"Q264", buf, 4))
1028 #define OFFSET(x) offsetof(H264Context, x) 1029 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM 1032 {
"nal_length_size",
"nal_length_size",
OFFSET(nal_length_size),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, 0 },
1033 {
"enable_er",
"Enable error resilience on damaged frames (unsafe)",
OFFSET(enable_er),
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
VD },
1034 {
"x264_build",
"Assume this x264 version if no x264 version found in any SEI",
OFFSET(x264_build),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VD },
1058 #if CONFIG_H264_DXVA2_HWACCEL 1061 #if CONFIG_H264_D3D11VA_HWACCEL 1064 #if CONFIG_H264_D3D11VA2_HWACCEL 1067 #if CONFIG_H264_NVDEC_HWACCEL 1070 #if CONFIG_H264_VAAPI_HWACCEL 1073 #if CONFIG_H264_VDPAU_HWACCEL 1076 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL #define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int bit_length)
Decode PPS.
struct H264Context * h264
static int h264_export_enc_params(AVFrame *f, H264Picture *p)
#define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS
Decoding only.
#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)
This structure describes decoded (raw) audio or video data.
int recovery_frame_cnt
recovery_frame_cnt
static av_always_inline AVVideoBlockParams * av_video_enc_params_block(AVVideoEncParams *par, unsigned int idx)
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
ptrdiff_t const GLvoid * data
int edge_emu_buffer_allocated
static void debug_green_metadata(const H264SEIGreenMetaData *gm, void *logctx)
int32_t qp
Base quantisation parameter for the frame.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
int chroma_qp_index_offset[2]
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static av_cold int init(AVCodecContext *avctx)
#define avpriv_request_sample(...)
void ff_er_frame_end(ERContext *s)
int32_t delta_qp
Difference between this block's final quantization parameter and the corresponding per-frame value...
int bitstream_restriction_flag
int bipred_scratchpad_allocated
#define HWACCEL_NVDEC(codec)
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output...
const char * av_default_item_name(void *ptr)
Return the context name.
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
int src_x
Distance in luma pixels from the top-left corner of the visible frame to the top-left corner of the b...
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
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
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...
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
int32_t delta_qp[4][2]
Quantisation parameter offset from the base (per-frame) qp for a given plane (first index) and AC/DC ...
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.
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.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define HWACCEL_VDPAU(codec)
int(* decode_params)(AVCodecContext *avctx, int type, const uint8_t *buf, uint32_t buf_size)
Callback for parameter data (SPS/PPS/VPS etc).
void ff_h264_set_erpic(ERPicture *dst, H264Picture *src)
void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Data structure for storing block-level encoding information.
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.
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, int use_ref)
Split an input packet into NAL units.
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
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)
int recovered
picture at IDR or recovery point + recovery count
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
int last_pocs[MAX_DELAYED_PIC_COUNT]
#define HWACCEL_D3D11VA(codec)
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.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
#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.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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
uint8_t * list_counts
Array of list_count per MB specifying the slice type.
#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
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)
Video encoding parameters for a given frame.
int w
Width and height of the block in luma pixels.
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call ff_thread_finish_setup() afterwards.If some code can't be moved
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.
int init_qp
pic_init_qp_minus26 + 26
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.
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.
#define HWACCEL_DXVA2(codec)
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...
static int is_avcc_extradata(const uint8_t *buf, int buf_size)
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
AVVideoEncParams * av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type, unsigned int nb_blocks)
Allocates memory for AVEncodeInfoFrame plus an array of.
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.
static AVOnce h264_vlc_init
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.
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)
#define HWACCEL_D3D11VA2(codec)
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
#define FF_DECODE_ERROR_DECODE_SLICES
int decode_error_flags
decode error flags of the frame, set to a combination of FF_DECODE_ERROR_xxx flags if the decoder pro...
H264SEIRecoveryPoint recovery_point
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
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.
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
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
common internal api header.
static int ref[MAX_W *MAX_W]
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 HWACCEL_VAAPI(codec)
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]
static void h264_decode_flush(AVCodecContext *avctx)
int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb, const H264ParamSets *ps, void *logctx)
int prev_frame_num_offset
for POC type 2
int8_t * intra4x4_pred_mode
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl)
Init context Allocate buffers which are not shared amongst multiple threads.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int mb_field_decoding_flag
uint8_t(* non_zero_count)[48]
uint8_t * bipred_scratchpad
void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int arrangement_cancel_flag
is previous arrangement canceled, -1 if never received
const uint16_t ff_h264_mb_sizes[4]
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)
Context Adaptive Binary Arithmetic Coder.
#define H264_MAX_PICTURE_COUNT
void * av_mallocz_array(size_t nmemb, size_t size)