46#include "config_components.h"
60 ff_dlog(
NULL,
"k-overflow bias:%d error:%d drift:%d count:%d k:%d",
66 ff_dlog(
NULL,
"v:%d bias:%d error:%d drift:%d count:%d k:%d",
69 v ^= ((2 *
state->drift +
state->count) >> 31);
91#define RENAME(name) name
97#define RENAME(name) name ## 32
102 uint8_t *
src,
int w,
int h,
int stride,
int plane_index,
103 int remap_index,
int pixel_stride,
int ac)
116 bits =
f->avctx->bits_per_raw_sample;
126 for (y = 0; y <
h; y++) {
135 if (
f->avctx->bits_per_raw_sample <= 8) {
136 int ret = decode_line(
f, sc, gb,
w,
sample, plane_index, 8, ac);
140 for (x = 0; x <
w; x++)
142 for (x = 0; x <
w; x++)
145 int ret = decode_line(
f, sc, gb,
w,
sample, plane_index,
bits, ac);
150 if (
f->packed_at_lsb ||
f->avctx->bits_per_raw_sample == 16) {
151 for (x = 0; x <
w; x++) {
155 for (x = 0; x <
w; x++) {
157 ((uint16_t*)(
src +
stride*y))[x*pixel_stride] = v << (16 -
f->avctx->bits_per_raw_sample) | v >> (2 *
f->avctx->bits_per_raw_sample - 16);
161 if (
f->packed_at_lsb ||
f->avctx->bits_per_raw_sample == 16) {
162 for (x = 0; x <
w; x++) {
166 for (x = 0; x <
w; x++) {
167 ((uint16_t*)(
src +
stride*y))[x*pixel_stride] =
sample[1][x] << (16 -
f->avctx->bits_per_raw_sample) | ((uint16_t **)
sample)[1][x] >> (2 *
f->avctx->bits_per_raw_sample - 16);
181 unsigned ps, context_count;
193 if (sx < 0 || sy < 0 || sw <= 0 || sh <= 0)
195 if (sx >
f->num_h_slices - sw || sy >
f->num_v_slices - sh)
211 for (
unsigned i = 0;
i <
f->plane_count;
i++) {
214 if (idx >= (
unsigned)
f->quant_table_count) {
218 p->quant_table_index = idx;
219 context_count =
f->context_count[idx];
221 if (p->context_count < context_count) {
225 p->context_count = context_count;
232 }
else if (ps == 2) {
235 }
else if (ps == 3) {
242 frame->sample_aspect_ratio) < 0) {
244 frame->sample_aspect_ratio.num,
245 frame->sample_aspect_ratio.den);
249 if (
f->version > 3) {
260 if (
f->combined_version >= 0x40004) {
262 if (sc->
remap > 2U ||
269 if (
f->avctx->bits_per_raw_sample == 32) {
286 f->frame_damaged = 1;
291 int ndx = (
i * mul_count) >> 32;
302 unsigned int end = (1LL<<
f->avctx->bits_per_raw_sample) - 1;
303 int flip = sc->
remap == 2 ? (end>>1) : 0;
305 for (
int p = 0; p < 1 + 2*
f->chroma_planes +
f->transparency; p++) {
308 uint8_t
state[2][3][32];
313 const int is_chroma = (p == 1 || p == 2) &&
f->chroma_planes;
316 const int pixel_num =
FFMIN(plane_width * plane_height, end + 1LL);
317 const size_t fltmap_ceil = 1ULL <<
av_ceil_log2(pixel_num);
319 if (
f->avctx->bits_per_raw_sample == 32) {
332 if (mul_count > 4096U)
334 for (
int i = 0;
i<mul_count;
i++) {
342 for (
i=0;
i <= end ;) {
344 unsigned run0 = lu ? 0 :
run;
345 unsigned run1 = lu ?
run : 1;
347 i += run0 * current_mul;
350 if (current_mul > 1) {
354 i += current_mul - 1 +
delta;
396 for (x = 0; x < 4; x++) {
405 for (y = 0; y <
h; y += 2) {
406 for (p = 0; p < 4; p++) {
416 p == 1 ? 2 : (p > 1),
bits[p], ac);
421 for (x = 0; x <
w; x++) {
422 int g_r =
sample[0][1][x];
423 int g_b =
sample[1][1][x];
436 g_b = g_r - (gd >> 1);
440 *((uint16_t*)(
src + (x*2 + 0)*2 +
stride*(y + 0))) =
r;
441 *((uint16_t*)(
src + (x*2 + 1)*2 +
stride*(y + 0))) = g_r;
442 *((uint16_t*)(
src + (x*2 + 0)*2 +
stride*(y + 1))) = g_b;
443 *((uint16_t*)(
src + (x*2 + 1)*2 +
stride*(y + 1))) =
b;
456 const int si = sc -
f->slices;
463 if (
f->slice_damaged[si])
469 if (
f->version > 2) {
500 if (
f->combined_version >= 0x30002)
501 get_rac(&sc->
c, (uint8_t[]) { 129 });
509 if (
f->colorspace == 0 && (
f->chroma_planes || !
f->transparency)) {
512 const int cx = x >>
f->chroma_h_shift;
513 const int cy = y >>
f->chroma_v_shift;
514 decode_plane(
f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0],
width,
height, p->linesize[0], 0, 0, 1, ac);
516 if (
f->chroma_planes) {
517 decode_plane(
f, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1, 1, ac);
518 decode_plane(
f, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 2, 1, ac);
521 decode_plane(
f, sc, &gb, p->data[3] + ps*x + y*p->linesize[3],
width,
height, p->linesize[3], (
f->version >= 4 && !
f->chroma_planes) ? 1 : 2,
522 (
f->version >= 4 && !
f->chroma_planes) ? 1 : 3, 1, ac);
523 }
else if (
f->colorspace == 0) {
524 decode_plane(
f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] ,
width,
height, p->linesize[0], 0, 0, 2, ac);
525 decode_plane(
f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + (ps>>1),
width,
height, p->linesize[0], 1, 1, 2, ac);
526 }
else if (
f->bayer) {
529 }
else if (
f->use32bit) {
530 uint8_t *
planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
531 p->data[1] + ps * x + y * p->linesize[1],
532 p->data[2] + ps * x + y * p->linesize[2] };
534 planes[3] = p->data[3] + ps * x + y * p->linesize[3];
537 uint8_t *
planes[4] = { p->data[0] + ps * x + y * p->linesize[0] };
538 if (
f->avctx->bits_per_raw_sample > 8) {
539 planes[1] = p->data[1] + ps * x + y * p->linesize[1];
540 planes[2] = p->data[2] + ps * x + y * p->linesize[2];
542 planes[3] = p->data[3] + ps * x + y * p->linesize[3];
548 get_rac(&sc->
c, (uint8_t[]) { 129 });
568#if CONFIG_FFV1_VULKAN_HWACCEL
581 int context_count = -1;
590 if (
f->bayer &&
f->combined_version <= 0x40002) {
592 "Bayer requires aligned slice coordinates (combined_version > 0x40002)\n");
596 if (
f->configured_pix_fmt !=
f->pix_fmt ||
597 f->configured_width !=
f->width ||
598 f->configured_height !=
f->height ||
599 f->configured_ac !=
f->ac) {
601 if (
f->avctx->pix_fmt < 0)
603 f->configured_pix_fmt =
f->pix_fmt;
604 f->configured_width =
f->width;
605 f->configured_height =
f->height;
606 f->configured_ac =
f->ac;
610 f->chroma_h_shift,
f->chroma_v_shift,
f->pix_fmt);
611 if (
f->version < 2) {
613 if (context_count < 0) {
617 f->slice_count =
f->max_slice_count;
618 }
else if (
f->version < 3) {
621 const uint8_t *p =
c->bytestream_end;
622 for (
f->slice_count = 0;
623 f->slice_count <
MAX_SLICES && 3 + 5*!!
f->ec < p -
c->bytestream_start;
625 int trailer = 3 + 5*!!
f->ec;
627 if (
size + trailer > p -
c->bytestream_start)
632 if (
f->slice_count > (
unsigned)
MAX_SLICES ||
f->slice_count <= 0 ||
f->slice_count >
f->max_slice_count) {
633 av_log(
f->avctx,
AV_LOG_ERROR,
"slice count %d is invalid (max=%d)\n",
f->slice_count,
f->max_slice_count);
639 if (!
f->slice_damaged)
642 for (
int j = 0; j <
f->slice_count; j++) {
645 if (
f->version == 2) {
651 if (sx < 0 || sy < 0 || sw <= 0 || sh <= 0)
653 if (sx >
f->num_h_slices - sw || sy >
f->num_v_slices - sh)
672 for (
int i = 0;
i <
f->plane_count;
i++) {
675 if (
f->version == 2) {
677 if (idx >= (
unsigned)
f->quant_table_count) {
679 "quant_table_index out of range\n");
682 p->quant_table_index = idx;
683 context_count =
f->context_count[idx];
686 if (
f->version <= 2) {
688 p->context_count = context_count;
716 uint8_t *buf, uint8_t *buf_end,
int idx,
717 uint8_t **
pos, uint32_t *
len)
722 uint32_t v = buf_end - buf;
723 if (idx ||
f->version > 2) {
725 uint32_t trailer = 3 + 5*!!
f->ec;
726 if (trailer > buf_end - buf)
729 v =
AV_RB24(buf_end - trailer) + trailer;
732 if (buf_end - buf < v) {
748 uint8_t *buf,
size_t buf_size)
753 uint8_t keystate = 128;
764 if (!
f->key_frame_ok) {
766 "Cannot decode non-keyframe without valid keyframe\n");
773 if (buf_size < avctx->
width * avctx->
height / (128*8))
777 int s = 1 +
w / (1<<23);
784 if (buf_size < (avctx->
height +
i + 6) / 8 *
s)
797 uint8_t *buf = avpkt->
data;
798 size_t buf_size = avpkt->
size;
799 uint8_t *buf_end = buf + buf_size;
801 for (
int i =
f->slice_count - 1;
i >= 0;
i--) {
817 if (crc !=
f->crcref) {
850 for (
int i =
f->slice_count - 1;
i >= 0;
i--) {
854 const uint8_t *
src[4];
857 for (
int j = 0; j <
desc->nb_components; j++) {
858 int pixshift =
desc->comp[j].depth > 8;
859 int sh = (j == 1 || j == 2) ?
f->chroma_h_shift : 0;
860 int sv = (j == 1 || j == 2) ?
f->chroma_v_shift : 0;
861 dst[j] = p->data[j] + p->linesize[j] *
863 src[j] =
f->last_picture.f->data[j] +
f->last_picture.f->linesize[j] *
869 f->last_picture.f->linesize,
874 f->slice_damaged[
i] = 1;
896 FFSWAP(
void *,
f->hwaccel_picture_private,
f->hwaccel_last_picture_private);
899 f->frame_damaged = 0;
907 f->version, !!
f->key_frame,
f->ac,
f->ec,
f->slice_count,
f->avctx->bits_per_raw_sample);
947 uint8_t *buf_end = avpkt->
data + avpkt->
size;
952 for (
int i =
f->slice_count - 1;
i >= 0;
i--) {
974 ret =
hwaccel->end_frame(avctx);
1008 fdst->
ac = fsrc->
ac;
1016 fdst->
ec = fsrc->
ec;
1088#if CONFIG_FFV1_VULKAN_HWACCEL
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_ffv1_decoder
static av_cold void close(AVCodecParserContext *s)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_THREAD_FRAME
Decode more than one frame at once.
#define FF_DEBUG_PICT_INFO
#define i(width, name, range_min, range_max)
#define UPDATE_THREAD_CONTEXT(func)
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
#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)
Public header for CRC hash function implementation.
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is ...
void ff_progress_frame_await(const ProgressFrame *f, int n)
Wait for earlier decoding threads to finish reference frames.
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
Wrapper around ff_progress_frame_alloc() and ff_thread_get_buffer().
void ff_progress_frame_unref(ProgressFrame *f)
Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame,...
#define AV_EF_EXPLODE
abort decoding on minor error detection
@ AV_FIELD_TT
Top coded_first, top displayed first.
@ AV_FIELD_TB
Top coded first, bottom displayed first.
int(* init)(AVBSFContext *ctx)
static struct @346255127015250356166251341105367306144006377143 state
static const uint8_t bits[8]
static const char * hwaccel
av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1SliceContext *sc)
av_cold int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s)
PlaneContext * ff_ffv1_planes_alloc(void)
int ff_slice_coord(const FFV1Context *f, int width, int sx, int num_h_slices, int chroma_shift)
This is intended for both width and height.
av_cold void ff_ffv1_close(FFV1Context *s)
void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc)
void ff_ffv1_compute_bits_per_plane(const FFV1Context *f, FFV1SliceContext *sc, int bits[4], int *offset, int mask[4], int bits_per_raw_sample)
av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
int ff_ffv1_get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
FF Video Codec 1 (a lossless codec)
int ff_ffv1_read_extra_header(FFV1Context *f)
static void update_vlc_state(VlcState *const state, const int v)
int ff_ffv1_parse_header(FFV1Context *f, RangeCoder *c, uint8_t *state)
int ff_ffv1_read_quant_tables(RangeCoder *c, int16_t quant_table[MAX_CONTEXT_INPUTS][256])
static av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, int is_signed)
static av_always_inline int fold(int diff, int bits)
static int decode_slice_header(const FFV1Context *f, FFV1SliceContext *sc, AVFrame *frame)
static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
static int get_vlc_symbol(GetBitContext *gb, VlcState *const state, int bits)
static av_cold int ffv1_decode_close(AVCodecContext *avctx)
static int is_input_end(RangeCoder *c, GetBitContext *gb, int ac)
static int decode_slices(AVCodecContext *avctx, RangeCoder c, AVPacket *avpkt)
static int decode_plane(FFV1Context *f, FFV1SliceContext *sc, GetBitContext *gb, uint8_t *src, int w, int h, int stride, int plane_index, int remap_index, int pixel_stride, int ac)
static av_cold int decode_init(AVCodecContext *avctx)
static int decode_slice(AVCodecContext *c, void *arg)
static void slice_set_damaged(FFV1Context *f, FFV1SliceContext *sc)
static int decode_remap(FFV1Context *f, FFV1SliceContext *sc)
static int decode_header(AVCodecContext *avctx, RangeCoder *c, uint8_t *buf, size_t buf_size)
static int find_next_slice(AVCodecContext *avctx, uint8_t *buf, uint8_t *buf_end, int idx, uint8_t **pos, uint32_t *len)
static int decode_bayer_frame(FFV1Context *f, FFV1SliceContext *sc, GetBitContext *gb, uint8_t *src, int w, int h, int stride)
static enum AVPixelFormat get_pixel_format(FFV1Context *f)
static int decode_current_mul(RangeCoder *rc, uint8_t state[32], int *mul, int mul_count, int64_t i)
static int read_header(FFV1Context *f, RangeCoder *c)
bitstream reader API header.
static int get_bits_left(GetBitContext *gb)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len)
read signed golomb rice code (ffv1).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
@ AVDISCARD_ALL
discard all
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
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_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
void av_image_copy(uint8_t *const dst_data[4], const int dst_linesizes[4], const uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar)
Check if the given sample aspect ratio of an image is valid.
@ AV_PICTURE_TYPE_I
Intra.
#define AV_NOPTS_VALUE
Undefined timestamp value.
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
#define HWACCEL_VULKAN(codec)
static av_cold int decode_init(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
static void flip(AVCodecContext *avctx, AVFrame *frame)
Multithreading API for decoders.
static enum AVPixelFormat pix_fmts[]
static const struct @257111027162314367033347246032313251342043035002 planes[]
static const uint16_t mask[17]
#define FFSWAP(type, a, b)
const uint8_t ff_log2_run[41]
Memory handling functions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
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_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size)
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
static int get_rac(RangeCoder *c, uint8_t *const state)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
main external API structure.
int width
picture width / height.
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
enum AVFieldOrder field_order
Field order.
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
enum AVDiscard skip_frame
Skip decoding for selected frames.
int step
Number of elements between 2 horizontally consecutive pixels.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Rational number (pair of numerator and denominator).
int ac
1=range coder <-> 0=golomb rice
enum AVPixelFormat configured_pix_fmt
void * hwaccel_picture_private
FFV1SliceContext * slices
uint8_t state_transition[256]
int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE]
enum AVPixelFormat pix_fmt
unsigned int fltmap32_size[4]
int ac_byte_count
number of bytes used for AC coding
unsigned int fltmap_size[4]
The ProgressFrame structure.
uint8_t * bytestream_start