On 1/9/2016 9:28 PM, Kieran Kunhya wrote: > --- > libavcodec/Makefile | 1 + > libavcodec/allcodecs.c | 1 + > libavcodec/avcodec.h | 1 + > libavcodec/cfhd.c | 565 > ++++++++++++++++++++++++++++++++++++++++++++++++ > libavcodec/cfhd.h | 99 +++++++++ > libavcodec/cfhddata.c | 470 ++++++++++++++++++++++++++++++++++++++++ > libavcodec/codec_desc.c | 6 + > 7 files changed, 1143 insertions(+) > create mode 100644 libavcodec/cfhd.c > create mode 100644 libavcodec/cfhd.h > create mode 100644 libavcodec/cfhddata.c > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > index b9ffdb9..c331a4f 100644 > --- a/libavcodec/Makefile > +++ b/libavcodec/Makefile > @@ -210,6 +210,7 @@ OBJS-$(CONFIG_CAVS_DECODER) += cavs.o > cavsdec.o cavsdsp.o \ > OBJS-$(CONFIG_CCAPTION_DECODER) += ccaption_dec.o > OBJS-$(CONFIG_CDGRAPHICS_DECODER) += cdgraphics.o > OBJS-$(CONFIG_CDXL_DECODER) += cdxl.o > +OBJS-$(CONFIG_CFHD_DECODER) += cfhd.o cfhddata.o > OBJS-$(CONFIG_CINEPAK_DECODER) += cinepak.o > OBJS-$(CONFIG_CINEPAK_ENCODER) += cinepakenc.o elbg.o > OBJS-$(CONFIG_CLJR_DECODER) += cljrdec.o > diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c > index 2128546..1d92c8b 100644 > --- a/libavcodec/allcodecs.c > +++ b/libavcodec/allcodecs.c > @@ -147,6 +147,7 @@ void avcodec_register_all(void) > REGISTER_DECODER(CAVS, cavs); > REGISTER_DECODER(CDGRAPHICS, cdgraphics); > REGISTER_DECODER(CDXL, cdxl); > + REGISTER_DECODER(CFHD, cfhd); > REGISTER_ENCDEC (CINEPAK, cinepak); > REGISTER_ENCDEC (CLJR, cljr); > REGISTER_DECODER(CLLC, cllc); > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h > index f365775..b958a6c 100644 > --- a/libavcodec/avcodec.h > +++ b/libavcodec/avcodec.h > @@ -315,6 +315,7 @@ enum AVCodecID { > AV_CODEC_ID_SMVJPEG, > AV_CODEC_ID_APNG, > AV_CODEC_ID_DAALA, > + AV_CODEC_ID_CFHD, > > /* various PCM "codecs" */ > AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the > start of audio codecs > diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c > new file mode 100644 > index 0000000..dc36889 > --- /dev/null > +++ b/libavcodec/cfhd.c > @@ -0,0 +1,565 @@ > +/* > + * Copyright (c) 2015 Kieran Kunhya
2015-2016? > + * > + * 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 > + */ > + > +/** > + * @file > + * CFHD Video Decoder > + */ > + > +#include "libavutil/buffer.h" > +#include "libavutil/common.h" > +#include "libavutil/intreadwrite.h" > +#include "libavutil/imgutils.h" > +#include "libavutil/opt.h" > + > +#include "avcodec.h" > +#include "bswapdsp.h" You're not using this. And if you were you'd need to add the relevant dependency to configure. > +#include "internal.h" > +#include "bytestream.h" > +#include "cfhd.h" [...] > + if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) { > + av_log(avctx, AV_LOG_DEBUG, "large len %x \n", ((tagu & 0xff) << > 16) | data); > + } else if (tag == 20) { > + av_log(avctx, AV_LOG_DEBUG, "Width %"PRIu16" \n", data); > + avctx->width = data; > + } else if (tag == 21) { > + av_log(avctx, AV_LOG_DEBUG, "Height %"PRIu16" \n", data); > + avctx->height = data; > + } else if (tag == 101) { > + av_log(avctx, AV_LOG_DEBUG, "Bits per component: %"PRIu16" \n", > data); > + s->bpc = data; > + } else if (tag == 12) { > + av_log(avctx, AV_LOG_DEBUG, "Channel Count: %"PRIu16" \n", data); > + s->channel_cnt = data; > + if (data != 3) { > + av_log(avctx, AV_LOG_ERROR, "Channel Count of %"PRIu16" is > unsupported\n", data); > + ret = AVERROR_PATCHWELCOME; > + break; > + } > + } else if (tag == 14) { > + av_log(avctx, AV_LOG_DEBUG, "Subband Count: %"PRIu16" \n", data); > + if (data != 10) { > + av_log(avctx, AV_LOG_ERROR, "Subband Count of %"PRIu16" is > unsupported\n", data); > + ret = AVERROR_PATCHWELCOME; > + break; > + } > + } else if (tag == 62) { > + s->channel_num = data; > + av_log(avctx, AV_LOG_DEBUG, "Channel number %"PRIu16" \n", data); > + init_plane_defaults(s); > + } else if (tag == 48) { > + if (s->subband_num != 0 && data == 1) // hack > + s->level++; > + av_log(avctx, AV_LOG_DEBUG, "Subband number %"PRIu16" \n", data); > + s->subband_num = data; > + } else if (tag == 51) { > + av_log(avctx, AV_LOG_DEBUG, "Subband number actual %"PRIu16" > \n", data); > + s->subband_num_actual = data; > + } else if (tag == 35) > + av_log(avctx, AV_LOG_DEBUG, "Lowpass precision bits: %"PRIu16" > \n", data); > + else if (tag == 53) { > + s->quantisation = data; > + av_log(avctx, AV_LOG_DEBUG, "Quantisation: %"PRIu16" \n", data); > + } else if (tag == 109) { > + s->prescale_shift[0] = (data >> 0) & 0x7; > + s->prescale_shift[1] = (data >> 3) & 0x7; > + s->prescale_shift[2] = (data >> 6) & 0x7; > + av_log(avctx, AV_LOG_DEBUG, "Prescale shift (VC-5): %x \n", > data); > + } else if (tag == 27) { > + s->plane[s->channel_num].band[0][0].width = data; > + s->plane[s->channel_num].band[0][0].stride = data; > + av_log(avctx, AV_LOG_DEBUG, "Lowpass width %"PRIu16" \n", data); > + } else if (tag == 28) { > + s->plane[s->channel_num].band[0][0].height = data; > + av_log(avctx, AV_LOG_DEBUG, "Lowpass height %"PRIu16" \n", data); > + } else if (tag == 1) > + av_log(avctx, AV_LOG_DEBUG, "Sample type? %"PRIu16" \n", data); > + else if (tag == 10) { > + if (data != 0) { > + av_log(avctx, AV_LOG_ERROR, "Transform type of %"PRIu16" is > unsupported\n", data); > + ret = AVERROR_PATCHWELCOME; > + break; > + } > + av_log(avctx, AV_LOG_DEBUG, "Transform-type? %"PRIu16" \n", > data); > + } else if (abstag >= 0x4000 && abstag <= 0x40ff) { > + av_log(avctx, AV_LOG_DEBUG, "Small chunk length %"PRIu16" %s > \n", data * 4, tag < 0 ? "optional" : "required"); > + bytestream2_skipu(&gb, data * 4); > + } else if (tag == 23) { > + av_log(avctx, AV_LOG_DEBUG, "Skip frame \n"); > + av_log(avctx, AV_LOG_ERROR, "Skip frame not supported \n"); > + ret = AVERROR_PATCHWELCOME; > + break; > + } else if (tag == 2) { > + av_log(avctx, AV_LOG_DEBUG, "tag=2 header - skipping %i > tag/value pairs \n", data); > + for (i = 0; i < data; i++) { > + av_log(avctx, AV_LOG_DEBUG, "Tag/Value = %x %x \n", > bytestream2_get_be16(&gb), bytestream2_get_be16(&gb)); > + } > + } else if (tag == 41) { > + s->plane[s->channel_num].band[s->level][s->subband_num].width = > data; > + s->plane[s->channel_num].band[s->level][s->subband_num].stride = > FFALIGN(data, 8); > + av_log(avctx, AV_LOG_DEBUG, "Highpass width %i channel %i level > %i subband %i \n", data, s->channel_num, s->level, s->subband_num); > + } else if (tag == 42) { > + s->plane[s->channel_num].band[s->level][s->subband_num].height = > data; > + av_log(avctx, AV_LOG_DEBUG, "Highpass height %i \n", data); > + } else if (tag == 49) { > + s->plane[s->channel_num].band[s->level][s->subband_num].width = > data; > + s->plane[s->channel_num].band[s->level][s->subband_num].stride = > FFALIGN(data, 8); > + av_log(avctx, AV_LOG_DEBUG, "Highpass width2 %i \n", data); > + } else if (tag == 50) { > + s->plane[s->channel_num].band[s->level][s->subband_num].height = > data; > + av_log(avctx, AV_LOG_DEBUG, "Highpass height2 %i \n", data); > + } else if (tag == 71) { > + s->codebook = data; > + av_log(avctx, AV_LOG_DEBUG, "Codebook %i \n", s->codebook); > + } else if (tag == 72) { > + s->codebook = data; > + av_log(avctx, AV_LOG_DEBUG, "Other codebook? %i \n", > s->codebook); > + } else > + av_log(avctx, AV_LOG_DEBUG, "Unknown tag %i data %x \n", tag, > data); Try to use a switch statement as Diego suggested. > +AVCodec ff_cfhd_decoder = { > + .name = "cfhd", > + .long_name = NULL_IF_CONFIG_SMALL("Cineform HD"), > + .type = AVMEDIA_TYPE_VIDEO, > + .id = AV_CODEC_ID_CFHD, > + .priv_data_size = sizeof(CFHDContext), > + .init = cfhd_decode_init, > + .close = cfhd_close_decoder, > + .decode = cfhd_decode, > + .capabilities = AV_CODEC_CAP_EXPERIMENTAL | AV_CODEC_CAP_DR1 | > AV_CODEC_CAP_FRAME_THREADS, Unless the decoder is prone to crash, i don't think setting it as experimental is a good idea. I assume most players out there will not use it because of that flag. This makes sense mainly with encoders, where we risk creating bad streams if it's not complete/correct. [...] > diff --git a/libavcodec/cfhddata.c b/libavcodec/cfhddata.c > new file mode 100644 > index 0000000..a08bfc7 > --- /dev/null > +++ b/libavcodec/cfhddata.c > @@ -0,0 +1,470 @@ > +/* > + * Copyright (c) 2015 Kieran Kunhya > + * > + * 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 "stdint.h" #include <stdint.h> > +#include "cfhd.h" > + > +/* some special codewords, not sure what they all mean */ > +#define TABLE_9_BAND_END1 0x1C7859Eh > +#define TABLE_9_BAND_END_LEN1 25 > +#define TABLE_9_BAND_END2 0x38F0B3Fh > +#define TABLE_9_BAND_END_LEN2 26 > +#define TABLE_9_BAND_END3 0x38F0B3Eh > +#define TABLE_9_BAND_END_LEN3 26 All these are unused. [...] > + > +static const uint16_t table_17_vlc_level[NB_VLC_TABLE_17] = { uint8_t? > + 0, 1, 2, 3, 4, 5, 8, 6, > + 0, 7, 0, 9, 10, 11, 0, 12, > + 13, 18, 14, 15, 0, 16, 17, 19, > + 20, 0, 21, 22, 29, 24, 25, 23, > + 26, 27, 28, 35, 30, 31, 0, 32, > + 33, 0, 34, 36, 37, 38, 39, 40, > + 46, 47, 42, 43, 41, 44, 45, 48, > + 49, 50, 53, 51, 52, 61, 60, 55, > + 56, 57, 58, 54, 59, 62, 63, 64, > + 65, 66, 67, 68, 69, 70, 71, 72, > + 73, 75, 76, 74, 77, 78, 79, 80, > + 81, 82, 83, 84, 85, 86, 87, 88, > + 89, 90, 91, 92, 93, 99, 100, 94, > + 95, 96, 97, 98, 102, 101, 103, 105, > + 104, 106, 107, 111, 109, 108, 113, 110, > + 112, 114, 115, 225, 189, 188, 203, 202, > + 197, 207, 169, 223, 159, 235, 152, 192, > + 179, 201, 172, 149, 178, 120, 219, 150, > + 127, 211, 125, 158, 247, 238, 163, 228, > + 183, 217, 168, 122, 128, 249, 187, 186, > + 136, 181, 255, 230, 135, 233, 222, 145, > + 134, 167, 248, 209, 243, 216, 164, 140, > + 157, 239, 191, 251, 156, 139, 242, 133, > + 162, 213, 165, 212, 227, 198, 236, 234, > + 117, 215, 124, 123, 254, 253, 148, 218, > + 146, 147, 224, 143, 184, 185, 166, 132, > + 129, 250, 151, 119, 193, 176, 245, 229, > + 206, 144, 208, 137, 241, 237, 190, 240, > + 131, 232, 252, 171, 205, 204, 118, 214, > + 180, 126, 182, 175, 141, 138, 177, 153, > + 194, 160, 121, 174, 246, 130, 200, 170, > + 221, 196, 142, 210, 199, 155, 154, 244, > + 220, 195, 161, 231, 173, 226, 116, > +}; [...] > diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c > index e814507..5d5568f 100644 > --- a/libavcodec/codec_desc.c > +++ b/libavcodec/codec_desc.c > @@ -1521,6 +1521,12 @@ static const AVCodecDescriptor codec_descriptors[] = { > .props = AV_CODEC_PROP_LOSSLESS, > .mime_types= MT("image/png"), > }, > + { > + .id = AV_CODEC_ID_CFHD, > + .type = AVMEDIA_TYPE_VIDEO, > + .name = "cfhd", > + .long_name = NULL_IF_CONFIG_SMALL("Cineform HD"), Missing .props > + }, > > /* various PCM "codecs" */ > { > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel