[FFmpeg-devel] [PATCH v3] Canopus Lossless decoder
Derek Buitenhuis
derek.buitenhuis at gmail.com
Sun Jul 29 04:28:15 CEST 2012
On 28/07/2012 10:23 PM, Michael Niedermayer wrote:
> On Sat, Jul 28, 2012 at 06:28:50PM -0400, Derek Buitenhuis wrote:
>> At the moment it only does BGR24, but I plan to add the rest after.
>>
>> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
>> ---
>> Changelog | 1 +
>> MAINTAINERS | 1 +
>> doc/general.texi | 1 +
>> libavcodec/Makefile | 1 +
>> libavcodec/allcodecs.c | 1 +
>> libavcodec/avcodec.h | 1 +
>> libavcodec/cllc.c | 290 ++++++++++++++++++++++++++++++++++++++++++++++++
>> libavcodec/version.h | 2 +-
>> libavformat/riff.c | 1 +
>> 9 files changed, 298 insertions(+), 1 deletion(-)
>> create mode 100644 libavcodec/cllc.c
>>
>> diff --git a/Changelog b/Changelog
>> index 79a8f4c..813116a 100644
>> --- a/Changelog
>> +++ b/Changelog
>> @@ -38,6 +38,7 @@ version next:
>> - alphaextract and alphamerge filters
>> - concat filter
>> - flite filter
>> +- Canopus Lossless Codec decoder
>>
>>
>> version 0.11:
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 1a9f29b..f265907 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -132,6 +132,7 @@ Codecs:
>> celp_filters.* Vitor Sessak
>> cinepak.c Roberto Togni
>> cljr Alex Beregszaszi
>> + cllc.c Derek Buitenhuis
>> cook.c, cookdata.h Benjamin Larsson
>> crystalhd.c Philip Langdale
>> cscd.c Reimar Doeffinger
>> diff --git a/doc/general.texi b/doc/general.texi
>> index 1849aec..ebbe189 100644
>> --- a/doc/general.texi
>> +++ b/doc/general.texi
>> @@ -501,6 +501,7 @@ following image formats are supported:
>> @item Delphine Software International CIN video @tab @tab X
>> @tab Codec used in Delphine Software International games.
>> @item Discworld II BMV Video @tab @tab X
>> + at item Canopus Lossless Codec @tab @tab X
>> @item Cinepak @tab @tab X
>> @item Cirrus Logic AccuPak @tab X @tab X
>> @tab fourcc: CLJR
>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index b4138e8..bb9aa9a 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -131,6 +131,7 @@ OBJS-$(CONFIG_CDXL_DECODER) += cdxl.o
>> OBJS-$(CONFIG_CINEPAK_DECODER) += cinepak.o
>> OBJS-$(CONFIG_CLJR_DECODER) += cljr.o
>> OBJS-$(CONFIG_CLJR_ENCODER) += cljr.o
>> +OBJS-$(CONFIG_CLLC_DECODER) += cllc.o
>> OBJS-$(CONFIG_COOK_DECODER) += cook.o
>> OBJS-$(CONFIG_CSCD_DECODER) += cscd.o
>> OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o
>> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
>> index 6bcc3c2..43c6c16 100644
>> --- a/libavcodec/allcodecs.c
>> +++ b/libavcodec/allcodecs.c
>> @@ -94,6 +94,7 @@ void avcodec_register_all(void)
>> REGISTER_DECODER (CDXL, cdxl);
>> REGISTER_DECODER (CINEPAK, cinepak);
>> REGISTER_ENCDEC (CLJR, cljr);
>> + REGISTER_DECODER (CLLC, cllc);
>> REGISTER_DECODER (CSCD, cscd);
>> REGISTER_DECODER (CYUV, cyuv);
>> REGISTER_DECODER (DFA, dfa);
>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>> index edbc59b..b7f4a41 100644
>> --- a/libavcodec/avcodec.h
>> +++ b/libavcodec/avcodec.h
>> @@ -274,6 +274,7 @@ enum CodecID {
>> CODEC_ID_YUV4 = MKBETAG('Y','U','V','4'),
>> CODEC_ID_SANM = MKBETAG('S','A','N','M'),
>> CODEC_ID_PAF_VIDEO = MKBETAG('P','A','F','V'),
>> + CODEC_ID_CLLC = MKBETAG('C','L','L','C'),
>>
>> /* various PCM "codecs" */
>> CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
>> diff --git a/libavcodec/cllc.c b/libavcodec/cllc.c
>> new file mode 100644
>> index 0000000..586361d
>> --- /dev/null
>> +++ b/libavcodec/cllc.c
>> @@ -0,0 +1,290 @@
>> +/*
>> + * Canopus Lossless Codec decoder
>> + *
>> + * Copyright (c) 2012 Derek Buitenhuis
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>> + */
>> +
>> +#include "libavutil/intreadwrite.h"
>> +#include "dsputil.h"
>> +#include "get_bits.h"
>> +#include "avcodec.h"
>> +
>> +typedef struct CLLCContext {
>> + DSPContext dsp;
>> + AVCodecContext *avctx;
>> +
>> + uint8_t *swapped_buf;
>> + int swapped_buf_size;
>> + int8_t code_table[3][32768];
>> +} CLLCContext;
>> +
>> +/*
>> + * We could use ff_init_vlc_sparse and get_vlc2, but it would
>
>> + * provide basolutely no benefit in this case. The lookup table
>
> basolutely ?
Typo of absolutely. Fixed.
>
> [...]
>> +static int read_line(CLLCContext *ctx, GetBitContext *gb, int *top_left,
>> + int8_t *code_table, uint8_t *outbuf)
>> +{
>> + uint8_t *dst;
>> + int pred, skip;
>> + int i;
>> +
>> + dst = outbuf;
>> + pred = *top_left;
>> +
>> + /* Simultaniously read and restore the line */
>> + for (i = 0; i < ctx->avctx->width; i++) {
>> + pred += code_table[2 * show_bits(gb, 14)];
>> + skip = code_table[2 * show_bits(gb, 14) + 1];
>> +
>> + skip_bits(gb, skip);
>> +
>> + dst[0] = pred;
>> + dst += 3;
>> + }
>
> for strict correctness pred should be a unsigned type, due to overflow
> i dont think it makes any difference in practice though
>
> also if you want maximum speed GET_VLC() should be faster but the
> code would be more messy, get_vlc2() is a compromise
>
> these functions can also use a single table or use a smaller first
> level table (that fits in the L1 cache of your CPU) and only touch
> the 2nd level for less common longer vlc codes. Which of these
> 2 variants if faster depends on input data and cpu
I'm going to try an get get_vlc2() working tomorrow and see what sort of
performance hit or gain it has.
> [...]
>> +static av_cold int cllc_decode_close(AVCodecContext *avctx)
>> +{
>> + CLLCContext *ctx = avctx->priv_data;
>> +
>> + if (avctx->coded_frame->data[0])
>> + avctx->release_buffer(avctx, avctx->coded_frame);
>> +
>> + if (avctx->coded_frame)
>> + av_freep(&avctx->coded_frame);
>> +
>> + if (ctx->swapped_buf)
>> + av_freep(&ctx->swapped_buf);
>
> the if() are unneeded
Removed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 898 bytes
Desc: OpenPGP digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120728/d1f71c03/attachment.asc>
More information about the ffmpeg-devel
mailing list