28 #include "libavutil/avassert.h"
29 #include "libavutil/crc.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/pixdesc.h"
54 for (i = e - 1; i >= 0; i--)
57 e = -(is_signed &&
get_rac(c, state + 11 +
FFMIN(e, 10)));
74 while (i < state->error_sum) {
80 av_dlog(NULL,
"v:%d bias:%d error:%d drift:%d count:%d k:%d",
84 if (k == 0 && 2 * state->
drift <= -state->
count)
87 v ^= ((2 * state->
drift + state->
count) >> 31);
99 int plane_index,
int bits)
110 for (x = 0; x < w; x++) {
112 for (i=0; i<
bits; i++) {
121 for (x = 0; x < w; x++) {
122 int diff, context, sign;
124 context =
get_context(p, sample[1] + x, sample[0] + x, sample[1] + x);
136 if (context == 0 && run_mode == 0)
140 if (run_count == 0 && run_mode == 1) {
143 if (x + run_count <= w)
168 av_dlog(s->
avctx,
"count:%d index:%d, mode:%d, x:%d pos:%d\n",
175 sample[1][x] = (
predict(sample[1] + x, sample[0] + x) + diff) &
182 int w,
int h,
int stride,
int plane_index)
193 for (y = 0; y < h; y++) {
194 int16_t *
temp = sample[0];
196 sample[0] = sample[1];
199 sample[1][-1] = sample[0][0];
200 sample[0][w] = sample[0][w - 1];
205 for (x = 0; x < w; x++)
206 src[x + stride * y] = sample[1][x];
210 for (x = 0; x < w; x++) {
211 ((uint16_t*)(src + stride*y))[x] = sample[1][x];
214 for (x = 0; x < w; x++) {
231 for (x = 0; x < 4; x++) {
240 for (y = 0; y < h; y++) {
242 int16_t *
temp = sample[p][0];
244 sample[p][0] = sample[p][1];
247 sample[p][1][-1]= sample[p][0][0 ];
248 sample[p][0][ w]= sample[p][0][w-1];
254 for (x = 0; x < w; x++) {
255 int g = sample[0][1][x];
256 int b = sample[1][1][x];
257 int r = sample[2][1][x];
258 int a = sample[3][1][x];
269 *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + (g<<8) + (r<<16) + (a<<24);
271 *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b;
272 *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g;
273 *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
284 memset(state, 128,
sizeof(state));
325 }
else if (ps == 2) {
328 }
else if (ps == 3) {
370 memcpy(pdst, psrc,
sizeof(*pdst));
412 if (f->colorspace == 0) {
415 const int cx = x >> f->chroma_h_shift;
416 const int cy =
y >> f->chroma_v_shift;
419 if (f->chroma_planes) {
420 decode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);
421 decode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1);
423 if (fs->transparency)
426 uint8_t *planes[3] = { p->data[0] + ps * x +
y * p->linesize[0],
427 p->data[1] + ps * x +
y * p->linesize[1],
428 p->data[2] + ps * x +
y * p->linesize[2] };
431 if (fs->ac && f->version > 2) {
434 v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec;
437 fs->slice_damaged = 1;
454 memset(state, 128,
sizeof(state));
456 for (v = 0; i < 128; v++) {
463 quant_table[i] = scale *
v;
468 for (i = 1; i < 128; i++)
469 quant_table[256 - i] = -quant_table[i];
470 quant_table[128] = -quant_table[127];
481 for (i = 0; i < 5; i++) {
483 if (context_count > 32768
U) {
487 return (context_count + 1) / 2;
497 memset(state2, 128,
sizeof(state2));
498 memset(state, 128,
sizeof(state));
514 for (i = 1; i < 256; i++)
577 "global: ver:%d.%d, coder:%d, colorspace: %d bpr:%d chroma:%d(%d:%d), alpha:%d slices:%dx%d qtabs:%d ec:%d intra:%d\n",
598 memset(state, 128,
sizeof(state));
610 for (i = 1; i < 256; i++)
616 chroma_planes =
get_rac(c, state);
619 transparency =
get_rac(c, state);
709 "chroma subsampling not supported in this colorspace\n");
736 if (context_count < 0) {
747 int trailer = 3 + 5*!!f->
ec;
791 "quant_table_index out of range\n");
837 int buf_size = avpkt->
size;
872 "Cannot decode non-keyframe without valid keyframe\n");
887 buf_p = buf + buf_size;
890 int trailer = 3 + 5*!!f->
ec;
940 for (j = 0; j < 4; j++) {
1004 fsdst->
ac = fsrc->
ac;
1007 fsdst->
ec = fsrc->
ec;
1034 memcpy(fdst, fsrc,
sizeof(*fdst));
static av_always_inline int fold(int diff, int bits)
void * av_memdup(const void *p, size_t size)
Duplicate the buffer p.
#define AV_PIX_FMT_YUV422P16
int ffv1_allocate_initial_states(FFV1Context *f)
const uint8_t ff_log2_run[41]
This structure describes decoded (raw) audio or video data.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
av_cold int ffv1_common_init(AVCodecContext *avctx)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int16_t quant_table[MAX_CONTEXT_INPUTS][256]
static av_cold int init(AVCodecContext *avctx)
static int decode_slice(AVCodecContext *c, void *arg)
#define MAX_CONTEXT_INPUTS
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define AV_PIX_FMT_GBRP10
static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, int is_signed)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
FF Video Codec 1 (a lossless codec)
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
#define AV_PIX_FMT_YUVA420P16
static int read_quant_tables(RangeCoder *c, int16_t quant_table[MAX_CONTEXT_INPUTS][256])
#define AV_PIX_FMT_YUVA444P10
static int get_rac(RangeCoder *c, uint8_t *const state)
static const uint8_t offset[511][2]
#define AV_PIX_FMT_YUVA420P10
const char * name
Name of the codec implementation.
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
uint8_t(*[MAX_QUANT_TABLES] initial_states)[32]
#define FF_CEIL_RSHIFT(a, b)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static double av_q2d(AVRational a)
Convert rational to double.
static int get_bits_count(const GetBitContext *s)
struct AVCodecInternal * internal
Private context used for internal data.
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
bitstream reader API header.
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
static void decode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, int stride[3])
int interlaced_frame
The content of the picture is interlaced.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define FFSWAP(type, a, b)
av_cold int ffv1_init_slice_state(FFV1Context *f, FFV1Context *fs)
high precision timer, useful to profile code
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
#define AV_PIX_FMT_GRAY16
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
static int init_thread_copy(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int decode_slice_header(FFV1Context *f, FFV1Context *fs)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256]
#define AV_PIX_FMT_YUVA422P9
int skip_alpha
Skip processing alpha if supported by codec.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Libavcodec external API header.
#define AV_PIX_FMT_YUVA422P10
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.
static int get_vlc_symbol(GetBitContext *gb, VlcState *const state, int bits)
#define AV_PIX_FMT_YUVA444P9
static void decode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index)
#define AV_PIX_FMT_GBRP12
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
int ac
1=range coder <-> 0=golomb rice
static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
int16_t quant_table[MAX_CONTEXT_INPUTS][256]
#define AV_PIX_FMT_YUV444P16
static av_noinline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
uint8_t state_transition[256]
static void copy_fields(FFV1Context *fsdst, FFV1Context *fssrc, FFV1Context *fsrc)
enum AVPictureType pict_type
Picture type of the frame.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static float quant_table[96]
static int get_context(PlaneContext *p, int16_t *src, int16_t *last, int16_t *last2)
static void update_vlc_state(VlcState *const state, const int v)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length) av_pure
Calculate the CRC of a block.
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
int ac_byte_count
number of bytes used for AC coding
static av_always_inline void decode_line(FFV1Context *s, int w, int16_t *sample[2], int plane_index, int bits)
av_cold int ffv1_init_slice_contexts(FFV1Context *f)
static int read_header(FFV1Context *f)
static const float pred[4]
#define AV_PIX_FMT_YUVA444P16
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
int context_count[MAX_QUANT_TABLES]
#define AV_PIX_FMT_0RGB32
main external API structure.
static void close(AVCodecParserContext *s)
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
#define AV_PIX_FMT_YUV444P9
void ffv1_clear_slice_state(FFV1Context *f, FFV1Context *fs)
static unsigned int get_bits1(GetBitContext *s)
BYTE int const BYTE int int int height
av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size)
#define AV_PIX_FMT_GBRP14
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_PIX_FMT_YUV420P9
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int allocate_progress
Whether to allocate progress for frame threading.
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define FF_DEBUG_PICT_INFO
static const uint16_t scale[4]
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV422P9
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
common internal api header.
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AV_PIX_FMT_YUV444P10
uint8_t(* state)[CONTEXT_SIZE]
#define AV_PIX_FMT_YUVA422P16
uint8_t * bytestream_start
static av_cold int decode_init(AVCodecContext *avctx)
PlaneContext plane[MAX_PLANES]
#define AVERROR_INVALIDDATA
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.
struct FFV1Context * fsrc
int top_field_first
If the content is interlaced, is top field displayed first.
av_cold int ffv1_close(AVCodecContext *avctx)
int key_frame
1 -> keyframe, 0-> not
#define AV_PIX_FMT_YUV420P10
struct FFV1Context * slice_context[MAX_SLICES]
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define AV_PIX_FMT_YUV422P10
enum AVFieldOrder field_order
Field order.
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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...
enum AVColorSpace colorspace
static int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len)
read signed golomb rice code (ffv1).
#define AV_PIX_FMT_YUVA420P9
This structure stores compressed data.
static int read_extra_header(FFV1Context *f)
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.