51 #if CONFIG_ZLIB_DECODER 66 #if CONFIG_ZLIB_DECODER 76 static unsigned int mszh_decomp(
const unsigned char * srcptr,
int srclen,
unsigned char * destptr,
unsigned int destsize)
78 unsigned char *destptr_bak = destptr;
79 unsigned char *destptr_end = destptr + destsize;
80 const unsigned char *srcptr_end = srcptr + srclen;
81 unsigned mask = *srcptr++;
82 unsigned maskbit = 0x80;
84 while (srcptr < srcptr_end && destptr < destptr_end) {
85 if (!(mask & maskbit)) {
86 memcpy(destptr, srcptr, 4);
90 unsigned ofs = bytestream_get_le16(&srcptr);
91 unsigned cnt = (ofs >> 11) + 1;
93 ofs =
FFMIN(ofs, destptr - destptr_bak);
95 cnt =
FFMIN(cnt, destptr_end - destptr);
101 memset(destptr, 0, cnt);
109 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32)
break;
110 memcpy(destptr, srcptr, 32);
119 return destptr - destptr_bak;
123 #if CONFIG_ZLIB_DECODER 134 int zret = inflateReset(&c->zstream);
139 c->zstream.next_in =
src;
140 c->zstream.avail_in = src_len;
143 zret =
inflate(&c->zstream, Z_FINISH);
144 if (zret != Z_OK && zret != Z_STREAM_END) {
148 if (expected != (
unsigned int)c->zstream.total_out) {
150 expected, c->zstream.total_out);
153 return c->zstream.total_out;
163 int buf_size = avpkt->
size;
165 unsigned int pixel_ptr;
167 unsigned char *encoded = avpkt->
data, *outptr;
168 uint8_t *y_out, *u_out, *v_out;
171 unsigned int mszh_dlen;
172 unsigned char yq, y1q, uq, vq;
174 unsigned int mthread_inlen, mthread_outlen;
175 unsigned int len = buf_size;
181 outptr = frame->
data[0];
193 if (len < 8 || len - 8 < mthread_inlen) {
197 mthread_outlen =
AV_RL32(buf + 4);
200 if (mthread_outlen != mszh_dlen) {
202 mthread_outlen, mszh_dlen);
205 mszh_dlen =
mszh_decomp(buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
207 if (mthread_outlen != mszh_dlen) {
209 mthread_outlen, mszh_dlen);
244 if (len < ((width * height * bppx2) >> 1))
253 #if CONFIG_ZLIB_DECODER 259 len == width * height * 3) {
268 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
269 mthread_outlen =
AV_RL32(buf + 4);
271 ret = zlib_decomp(avctx, buf + 8, mthread_inlen, 0, mthread_outlen);
272 if (ret < 0)
return ret;
273 ret = zlib_decomp(avctx, buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
274 mthread_outlen, mthread_outlen);
275 if (ret < 0)
return ret;
277 int ret = zlib_decomp(avctx, buf, len, 0, c->
decomp_size);
278 if (ret < 0)
return ret;
285 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
295 for (row = 0; row <
height; row++) {
296 pixel_ptr = row * width * 3;
297 yq = encoded[pixel_ptr++];
298 uqvq =
AV_RL16(encoded+pixel_ptr);
300 for (col = 1; col <
width; col++) {
301 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
302 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
303 AV_WL16(encoded+pixel_ptr+1, uqvq);
309 for (row = 0; row <
height; row++) {
310 pixel_ptr = row * width * 2;
312 for (col = 0; col < width/4; col++) {
313 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
314 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
315 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
316 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
317 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
318 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
319 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
320 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
326 for (row = 0; row <
height; row++) {
327 pixel_ptr = row * width / 2 * 3;
329 for (col = 0; col < width/4; col++) {
330 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
331 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
332 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
333 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
334 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
335 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
341 for (row = 0; row <
height; row++) {
342 pixel_ptr = row * width * 2;
344 for (col = 0; col < width/2; col++) {
345 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
346 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
347 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
348 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
354 for (row = 0; row < height/2; row++) {
355 pixel_ptr = row * width * 3;
356 yq = y1q = uq = vq =0;
357 for (col = 0; col < width/2; col++) {
358 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
359 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
360 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
361 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
362 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
363 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
375 y_out = frame->
data[0] + (height - 1) * frame->
linesize[0];
376 offset = (height - 1) * frame->
linesize[1];
378 offset = (height - 1) * frame->
linesize[2];
382 for (row = 0; row <
height; row++) {
383 for (col = 0; col <
width; col++) {
384 y_out[col] = *encoded++;
385 u_out[col] = *encoded++ + 128;
386 v_out[col] = *encoded++ + 128;
394 for (row = 0; row <
height; row++) {
395 for (col = 0; col < width - 3; col += 4) {
396 memcpy(y_out + col, encoded, 4);
398 u_out[ col >> 1 ] = *encoded++ + 128;
399 u_out[(col >> 1) + 1] = *encoded++ + 128;
400 v_out[ col >> 1 ] = *encoded++ + 128;
401 v_out[(col >> 1) + 1] = *encoded++ + 128;
409 linesize = len <
FFALIGN(3 * width, 4) * height ? 3 * width :
FFALIGN(3 * width, 4);
410 for (row = height - 1; row >= 0; row--) {
411 pixel_ptr = row * frame->
linesize[0];
412 memcpy(outptr + pixel_ptr, encoded, 3 * width);
417 for (row = 0; row <
height; row++) {
418 for (col = 0; col < width - 3; col += 4) {
419 memcpy(y_out + col, encoded, 4);
421 u_out[col >> 2] = *encoded++ + 128;
422 v_out[col >> 2] = *encoded++ + 128;
430 for (row = 0; row <
height; row++) {
431 for (col = 0; col < width - 1; col += 2) {
432 memcpy(y_out + col, encoded, 2);
434 u_out[col >> 1] = *encoded++ + 128;
435 v_out[col >> 1] = *encoded++ + 128;
443 u_out = frame->
data[1] + ((height >> 1) - 1) * frame->
linesize[1];
444 v_out = frame->
data[2] + ((height >> 1) - 1) * frame->
linesize[2];
445 for (row = 0; row < height - 1; row += 2) {
446 for (col = 0; col < width - 1; col += 2) {
447 memcpy(y_out + col, encoded, 2);
449 memcpy(y_out + col - frame->
linesize[0], encoded, 2);
451 u_out[col >> 1] = *encoded++ + 128;
452 v_out[col >> 1] = *encoded++ + 128;
476 unsigned int basesize = avctx->
width * avctx->
height;
479 unsigned int max_decomp_size;
480 int subsample_h, subsample_v;
490 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
497 max_decomp_size = max_basesize * 3;
503 max_decomp_size = max_basesize * 2;
506 if (avctx->
width % 4) {
513 max_decomp_size = max_basesize * 3;
519 max_decomp_size = max_basesize / 2 * 3;
525 max_decomp_size = max_basesize * 2;
531 max_decomp_size = max_basesize / 2 * 3;
541 if (avctx->
width % (1<<subsample_h) || avctx->
height % (1<<subsample_v)) {
563 #if CONFIG_ZLIB_DECODER 609 #if CONFIG_ZLIB_DECODER 612 c->zstream.zalloc = Z_NULL;
613 c->zstream.zfree = Z_NULL;
614 c->zstream.opaque = Z_NULL;
615 zret = inflateInit(&c->zstream);
632 #if CONFIG_ZLIB_DECODER 634 inflateEnd(&c->zstream);
640 #if CONFIG_MSZH_DECODER 655 #if CONFIG_ZLIB_DECODER #define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
#define avpriv_request_sample(...)
#define COMP_ZLIB_HISPEED
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
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
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Multithreading support functions.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
#define FF_PTR_ADD(ptr, off)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static const uint16_t mask[17]
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#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.
const char * name
Name of the codec implementation.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
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
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
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
packed RGB 8:8:8, 24bpp, BGRBGR...
unsigned char * decomp_buf
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
static av_cold int decode_end(AVCodecContext *avctx)
static unsigned int mszh_decomp(const unsigned char *srcptr, int srclen, unsigned char *destptr, unsigned int destsize)
static av_cold int decode_init(AVCodecContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int key_frame
1 -> keyframe, 0-> not
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators...