34 #include "libavutil/channel_layout.h"
39 #define BITSTREAM_READER_LE
43 #define SMKTREE_BITS 9
44 #define SMK_NODE 0x80000000
80 1, 2, 3, 4, 5, 6, 7, 8,
81 9, 10, 11, 12, 13, 14, 15, 16,
82 17, 18, 19, 20, 21, 22, 23, 24,
83 25, 26, 27, 28, 29, 30, 31, 32,
84 33, 34, 35, 36, 37, 38, 39, 40,
85 41, 42, 43, 44, 45, 46, 47, 48,
86 49, 50, 51, 52, 53, 54, 55, 56,
87 57, 58, 59, 128, 256, 512, 1024, 2048 };
140 if (i1 < 0 || i2 < 0)
146 }
else if(val == ctx->
escapes[1]) {
149 }
else if(val == ctx->
escapes[2]) {
180 VLC vlc[2] = { { 0 } };
185 if(size >= UINT_MAX>>4){
213 tmp1.
lengths,
sizeof(
int),
sizeof(
int),
227 tmp2.
lengths,
sizeof(
int),
sizeof(
int),
245 last[0] = last[1] = last[2] = -1;
256 huff.
length = ((size + 3) >> 2) + 4;
297 int mmap_size, mclr_size, full_size, type_size;
355 recode[last[0]] = recode[last[1]] = recode[last[2]] = 0;
360 register int *table = recode;
365 table += (*table) & (~SMK_NODE);
370 if(v != recode[last[0]]) {
371 recode[last[2]] = recode[last[1]];
372 recode[last[1]] = recode[last[0]];
386 int blocks,
blk, bw, bh;
391 if (avpkt->
size <= 769)
400 pal = (uint32_t*)smk->
pic->
data[1];
402 flags = bytestream2_get_byteu(&gb2);
410 for(i = 0; i < 256; i++)
411 *pal++ = bytestream2_get_be24u(&gb2);
420 bw = avctx->
width >> 2;
425 while(blk < blocks) {
433 while(run-- && blk < blocks){
438 out = smk->
pic->
data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
441 for(i = 0; i < 4; i++) {
442 if(map & 1) out[0] = hi;
else out[0] = lo;
443 if(map & 2) out[1] = hi;
else out[1] = lo;
444 if(map & 4) out[2] = hi;
else out[2] = lo;
445 if(map & 8) out[3] = hi;
else out[3] = lo;
458 while(run-- && blk < blocks){
459 out = smk->
pic->
data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
462 for(i = 0; i < 4; i++) {
472 out[0] = out[1] = pix & 0xFF;
473 out[2] = out[3] = pix >> 8;
475 out[0] = out[1] = pix & 0xFF;
476 out[2] = out[3] = pix >> 8;
479 out[0] = out[1] = pix & 0xFF;
480 out[2] = out[3] = pix >> 8;
482 out[0] = out[1] = pix & 0xFF;
483 out[2] = out[3] = pix >> 8;
487 for(i = 0; i < 2; i++) {
504 while(run-- && blk < blocks)
509 while(run-- && blk < blocks){
511 out = smk->
pic->
data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
512 col = mode * 0x01010101;
513 for(i = 0; i < 4; i++) {
514 *((uint32_t*)out) = col;
604 int *got_frame_ptr,
AVPacket *avpkt)
608 int buf_size = avpkt->
size;
611 VLC vlc[4] = { { 0 } };
618 int pred[2] = {0, 0};
636 if (stereo ^ (avctx->
channels != 1)) {
651 samples = (int16_t *)frame->
data[0];
652 samples8 = frame->
data[0];
655 for(i = 0; i < (1 << (bits + stereo)); i++) {
662 if (!h[i].bits || !h[i].lengths || !h[i].values) {
672 if(h[i].current > 1) {
674 h[i].lengths,
sizeof(
int),
sizeof(
int),
675 h[i].bits,
sizeof(uint32_t),
sizeof(uint32_t),
INIT_VLC_LE);
685 for(i = stereo; i >= 0; i--)
687 for(i = 0; i <= stereo; i++)
688 *samples++ = pred[i];
689 for(; i < unp_size / 2; i++) {
700 val |= h[3].
values[res] << 8;
702 *samples++ = pred[1];
713 val |= h[1].
values[res] << 8;
715 *samples++ = pred[0];
719 for(i = stereo; i >= 0; i--)
721 for(i = 0; i <= stereo; i++)
722 *samples8++ = pred[i];
723 for(; i < unp_size; i++) {
730 *samples8++ = pred[1];
737 *samples8++ = pred[0];
746 for(i = 0; i < 4; i++) {
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
static const int block_runs[64]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
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.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AV_CH_LAYOUT_STEREO
static av_cold int decode_init(AVCodecContext *avctx)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
enum AVSampleFormat sample_fmt
audio sample format
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
const char * name
Name of the codec implementation.
static av_cold int smka_decode_init(AVCodecContext *avctx)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
bitstream reader API header.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVCodec ff_smacker_decoder
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t prefix, int length)
Decode local frame tree.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Libavcodec external API header.
uint64_t channel_layout
Audio channel layout.
static int smka_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Decode Smacker audio data.
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
Context used for code reconstructing.
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 av_cold int decode_end(AVCodecContext *avctx)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int **recodes, int *last, int size)
Store large tree as Libav's vlc codes.
static const float pred[4]
8 bit with PIX_FMT_RGB32 palette
#define AV_LOG_INFO
Standard information.
AVCodec ff_smackaud_decoder
main external API structure.
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx)
Decode header tree.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int palette_has_changed
Tell user application that palette has changed from previous frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_const int sign_extend(int val, unsigned bits)
#define MKTAG(a, b, c, d)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
common internal api header.
static av_always_inline int smk_get_code(GetBitContext *gb, int *recode, int *last)
static av_cold int init(AVCodecParserContext *s)
int channels
number of audio channels
VLC_TYPE(* table)[2]
code, bits
int key_frame
1 -> keyframe, 0-> not
static int decode_header_trees(SmackVContext *smk)
static av_always_inline void last_reset(int *recode, int *last)
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
void ff_free_vlc(VLC *vlc)
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...