36 return r - ((v + 1) >> 1);
60 uint8_t primary_frame, prev_frame;
61 uint32_t abs_bits, prec_bits,
round, prec_diff,
sub, mx;
91 sub = (idx % 3) == 2 ? (1 << prec_bits) : 0;
93 r = (prev_gm_param >> prec_diff) - sub;
97 -mx, mx + 1, r) << prec_diff) + round;
111 for (
int i = 0;
i < 6;
i++)
151 unsigned int a,
unsigned int b)
153 unsigned int diff = a -
b;
155 return (diff & (m - 1)) - (diff & m);
163 int forward_idx, backward_idx;
164 int forward_hint, backward_hint;
165 int second_forward_idx, second_forward_hint;
166 int ref_hint, dist,
i;
177 if (forward_idx < 0 ||
180 forward_hint = ref_hint;
182 }
else if (dist > 0) {
183 if (backward_idx < 0 ||
186 backward_hint = ref_hint;
191 if (forward_idx < 0) {
193 }
else if (backward_idx >= 0) {
201 second_forward_idx = -1;
205 if (second_forward_idx < 0 ||
207 second_forward_idx =
i;
208 second_forward_hint = ref_hint;
213 if (second_forward_idx < 0)
262 memcpy(dst, film_grain,
sizeof(*dst));
268 memcpy(dst,
src,
sizeof(*dst));
294 uint16_t tile_num, tile_row, tile_col;
295 uint32_t
size = 0, size_bytes = 0;
302 for (tile_num = tile_group->
tg_start; tile_num <= tile_group->tg_end; tile_num++) {
306 if (tile_num == tile_group->
tg_end) {
317 for (
int i = 0;
i < size_bytes;
i++)
318 size |= bytestream2_get_byteu(&gb) << 8 *
i;
342 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \ 343 CONFIG_AV1_D3D11VA_HWACCEL * 2 + \ 344 CONFIG_AV1_NVDEC_HWACCEL + \ 345 CONFIG_AV1_VAAPI_HWACCEL) 364 else if (bit_depth == 10)
366 else if (bit_depth == 12)
374 else if (bit_depth == 10)
376 else if (bit_depth == 12)
384 else if (bit_depth == 10)
386 else if (bit_depth == 12)
394 else if (bit_depth == 10)
396 else if (bit_depth == 12)
411 #if CONFIG_AV1_DXVA2_HWACCEL 414 #if CONFIG_AV1_D3D11VA_HWACCEL 418 #if CONFIG_AV1_NVDEC_HWACCEL 421 #if CONFIG_AV1_VAAPI_HWACCEL 426 #if CONFIG_AV1_DXVA2_HWACCEL 429 #if CONFIG_AV1_D3D11VA_HWACCEL 433 #if CONFIG_AV1_NVDEC_HWACCEL 436 #if CONFIG_AV1_VAAPI_HWACCEL 441 #if CONFIG_AV1_NVDEC_HWACCEL 446 #if CONFIG_AV1_NVDEC_HWACCEL 466 " hardware accelerated AV1 decoding.\n");
578 if (avctx->
width != width || avctx->
height != height) {
608 if (avctx->
width != width || avctx->
height != height) {
615 (int64_t)height * r_width,
616 (int64_t)width * r_height,
641 "Failed to allocate reference frame buffer %d.\n",
i);
649 "Failed to allocate current frame buffer.\n");
786 for (
int i = 0;
i < 24;
i++) {
789 for (
int i = 0;
i < 25;
i++) {
849 "Failed to update frame %d in reference list\n",
i);
868 "Failed to allocate space for current frame.\n");
912 switch (unit->
type) {
936 "Failed to get pixel format.\n");
1044 "HW accel decode slice fail.\n");
1060 if (raw_tile_group && (s->
tile_num == raw_tile_group->
tg_end + 1)) {
1082 raw_tile_group =
NULL;
1109 #define OFFSET(x) offsetof(AV1DecContext, x) 1110 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM 1112 {
"operating_point",
"Select an operating point of the scalable bitstream",
1141 #if CONFIG_AV1_DXVA2_HWACCEL 1144 #if CONFIG_AV1_D3D11VA_HWACCEL 1147 #if CONFIG_AV1_D3D11VA2_HWACCEL 1150 #if CONFIG_AV1_NVDEC_HWACCEL 1153 #if CONFIG_AV1_VAAPI_HWACCEL
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
uint8_t clip_to_restricted_range
static uint32_t decode_unsigned_subexp_with_ref(uint32_t sub_exp, int mx, int r)
The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
int nb_units
Number of units in this fragment.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static enum AVPixelFormat pix_fmt
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
static int update_context_with_frame_header(AVCodecContext *avctx, const AV1RawFrameHeader *header)
This structure describes decoded (raw) audio or video data.
static void skip_mode_params(AV1DecContext *s)
AV1RawFrameHeader * raw_frame_header
int ar_coeff_lag
Specifies the auto-regression lag.
static void flush(AVCodecContext *avctx)
int num_uv_points[2]
If chroma_scaling_from_luma is set to 0, signals the chroma scaling function parameters.
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
This structure describes how to handle film grain synthesis in video for specific codecs...
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
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.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static av_cold int init(AVCodecContext *avctx)
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
CodedBitstreamUnitType type
Codec-specific type of this unit.
uint8_t ar_coeffs_cb_plus_128[25]
enum AVColorRange color_range
MPEG vs JPEG YUV range.
static void av1_decode_flush(AVCodecContext *avctx)
#define HWACCEL_NVDEC(codec)
const char * av_default_item_name(void *ptr)
Return the context name.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int export_film_grain(AVCodecContext *avctx, AVFrame *frame)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AV_PIX_FMT_YUV420P12
uint32_t num_units_in_display_tick
#define FF_ARRAY_ELEMS(a)
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
This structure describes how to handle film grain synthesis for AOM codecs.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int grain_scale_shift
Signals the down shift applied to the generated gaussian numbers during synthesis.
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY12
uint8_t point_cr_scaling[10]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
TileGroupInfo * tile_group_info
int limit_output_range
Signals to clip to limited color levels after film grain application.
#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...
uint8_t chroma_scaling_from_luma
static void read_global_param(AV1DecContext *s, int type, int ref, int idx)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int(* decode_params)(AVCodecContext *avctx, int type, const uint8_t *buf, uint32_t buf_size)
Callback for parameter data (SPS/PPS/VPS etc).
int scaling_shift
Specifies the shift applied to the chroma components.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int ff_cbs_read_packet(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
Read the data bitstream from a packet into a fragment, then split into units and decompose.
uint8_t grain_scale_shift
static const AVClass av1_class
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Coded bitstream unit structure.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
void * content
Pointer to the decomposed form of this unit.
static const uint8_t header[24]
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
#define AV_PIX_FMT_YUV422P12
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
int num_y_points
Number of points, and the scale and value for each point of the piecewise linear scaling function for...
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
#define HWACCEL_D3D11VA(codec)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
int ar_coeff_shift
Specifies the range of the auto-regressive coefficients.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
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. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int32_t decode_signed_subexp_with_ref(uint32_t sub_exp, int low, int high, int r)
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
uint8_t point_cr_value[10]
int chroma_scaling_from_luma
Signals whether to derive the chroma scaling function from the luma.
const char * name
Name of the codec implementation.
static av_always_inline av_const double round(double x)
#define AV_PIX_FMT_YUV444P10
static int get_pixel_format(AVCodecContext *avctx)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
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 have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in AVCodec caps_internal and use ff_thread_get_buffer() to allocate frames.The frames must then be freed with ff_thread_release_buffer().Otherwise decode directly into the user-supplied frames.Call ff_thread_report_progress() after some part of the current picture has decoded.A good place to put this is where draw_horiz_band() is called-add this if it isn't called anywhere
static av_cold int av1_decode_init(AVCodecContext *avctx)
CodedBitstreamFragment current_obu
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
uint8_t film_grain_params_ref_idx
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static int get_current_frame(AVCodecContext *avctx)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int uv_mult[2]
Specifies the luma/chroma multipliers for the index to the component scaling function.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static int set_context_with_sequence(AVCodecContext *avctx, const AV1RawSequenceHeader *seq)
uint8_t ar_coeffs_cr_plus_128[25]
AV1RawFilmGrainParams film_grain
int overlap_flag
Signals whether to overlap film grain blocks.
uint8_t grain_scaling_minus_8
HW acceleration through CUDA.
#define HWACCEL_DXVA2(codec)
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Read the extradata bitstream found in a codec context into a fragment, then split into units and deco...
static void coded_lossless_param(AV1DecContext *s)
uint8_t point_cb_scaling[10]
static av_always_inline int bytestream2_tell(GetByteContext *g)
uint8_t skip_mode_frame_idx[2]
static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
int8_t ar_coeffs_uv[2][25]
Chroma auto-regression coefficients.
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
static int FUNC() sequence_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceHeader *current)
Libavcodec external API header.
uint8_t ar_coeff_shift_minus_6
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
static int get_relative_dist(const AV1RawSequenceHeader *seq, unsigned int a, unsigned int b)
const AVProfile ff_av1_profiles[]
main external API structure.
uint8_t * data
The data buffer.
AVBufferRef * av_buffer_allocz(buffer_size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
static const AVOption av1_options[]
#define AV_PIX_FMT_YUV420P10
Describe the class of an AVClass context structure.
static const AVProfile profiles[]
enum AVColorSpace colorspace
YUV colorspace type.
Rational number (pair of numerator and denominator).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVBufferRef * content_ref
If content is reference counted, a reference to the buffer containing content.
static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
#define HWACCEL_D3D11VA2(codec)
static uint32_t inverse_recenter(int r, uint32_t v)
AV1RawTileGroup tile_group
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
uint8_t point_cb_value[10]
uint8_t point_y_scaling[14]
union AVFilmGrainParams::@294 codec
Additional fields may be added both here and in any structure included.
uint32_t num_ticks_per_picture_minus_1
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
AV1RawSequenceHeader sequence_header
static enum AVPixelFormat pix_fmts[]
uint8_t equal_picture_interval
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
int32_t gm_params[AV1_NUM_REF_FRAMES][6]
CodedBitstreamContext * cbc
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define AV_PIX_FMT_YUV422P10
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
#define AV_PIX_FMT_YUV444P12
static void global_motion_params(AV1DecContext *s)
update gm type/params, since cbs already implemented part of this funcation, so we don't need to full...
Hardware surfaces for Direct3D11.
Narrow or limited range content.
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
void * priv_data
Internal codec-specific data.
enum AVPixelFormat pix_fmt
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
AV1Frame ref[AV1_NUM_REF_FRAMES]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
static int ref[MAX_W *MAX_W]
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f)
static int av1_decode_frame(AVCodecContext *avctx, void *frame, int *got_frame, AVPacket *pkt)
static int update_reference_list(AVCodecContext *avctx)
AV1RawSequenceHeader * raw_seq
uint8_t point_y_value[14]
static void load_grain_params(AV1DecContext *s)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
int uv_offset[2]
Offset used for component scaling function.
static int set_output_frame(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt, int *got_frame)
#define HWACCEL_VAAPI(codec)
int frame_priv_data_size
Size of per-frame hardware accelerator private data.
int8_t ar_coeffs_y[24]
Luma auto-regression coefficients.
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
int key_frame
1 -> keyframe, 0-> not
uint8_t chroma_sample_position
void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
AV1RawTileGroup tile_group
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
AV1RawFrameHeader frame_header
AV1RawFrameHeader * raw_frame_header
static int init_tile_data(AV1DecContext *s)
static av_cold int av1_decode_free(AVCodecContext *avctx)
static float sub(float src0, float src1)
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
void ff_cbs_flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
uint8_t gm_type[AV1_NUM_REF_FRAMES]
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
uint8_t uv_points[2][10][2]
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
void * hwaccel_picture_private
int pkt_size
size of the corresponding packet containing the compressed frame.
uint8_t ar_coeffs_y_plus_128[24]
AVPixelFormat
Pixel format.
This structure stores compressed data.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint8_t transfer_characteristics
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
FF_DISABLE_DEPRECATION_WARNINGS enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
AVBufferRef * hwaccel_priv_buf