--- libdcadec is found here: https://github.com/foo86/dcadec
I wrote this mostly for myself, as its lossless and quite stable, and allows easy comparison to the state of the native decoder. Since I got a request to share it, I figured I might just send it, may it benefit anyone that is interested. diff --git a/configure b/configure index 586c26b..94f9d7b 100755 --- a/configure +++ b/configure @@ -210,6 +210,7 @@ External library support: --enable-libcdio enable audio CD grabbing with libcdio [no] --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394 and libraw1394 [no] + --enable-libdcadec enable DCA decoding via libdcadec [no] --enable-libfaac enable AAC encoding via libfaac [no] --enable-libfdk-aac enable AAC de/encoding via libfdk-aac [no] --enable-libflite enable flite (voice synthesis) support via libflite [no] @@ -1353,6 +1354,7 @@ EXTERNAL_LIBRARY_LIST=" libcdio libcelt libdc1394 + libdcadec libfaac libfdk_aac libflite @@ -2359,6 +2361,7 @@ vc1_parser_select="mpegvideo startcode vc1_decoder" # external libraries libaacplus_encoder_deps="libaacplus" libcelt_decoder_deps="libcelt" +libdcadec_decoder_deps="libdcadec" libfaac_encoder_deps="libfaac" libfaac_encoder_select="audio_frame_queue" libfdk_aac_decoder_deps="libfdk_aac" @@ -4923,6 +4926,7 @@ enabled libcelt && require libcelt celt/celt.h celt_decode -lcelt0 && { check_lib celt/celt.h celt_decoder_create_custom -lcelt0 || die "ERROR: libcelt must be installed and version must be >= 0.11.0."; } enabled libcaca && require_pkg_config caca caca.h caca_create_canvas +enabled libdcadec && require libdcadec dca_context.h dcadec_context_create -ldcadec enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac enabled libfdk_aac && require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac flite_libs="-lflite_cmu_time_awb -lflite_cmu_us_awb -lflite_cmu_us_kal -lflite_cmu_us_kal16 -lflite_cmu_us_rms -lflite_cmu_us_slt -lflite_usenglish -lflite_cmulex -lflite" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 4173f88..1a0c734 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -732,6 +732,7 @@ OBJS-$(CONFIG_ELBG_FILTER) += elbg.o # external codec libraries OBJS-$(CONFIG_LIBAACPLUS_ENCODER) += libaacplus.o OBJS-$(CONFIG_LIBCELT_DECODER) += libcelt_dec.o +OBJS-$(CONFIG_LIBDCADEC_DECODER) += libdcadec.o OBJS-$(CONFIG_LIBFAAC_ENCODER) += libfaac.o OBJS-$(CONFIG_LIBFDK_AAC_DECODER) += libfdk-aacdec.o OBJS-$(CONFIG_LIBFDK_AAC_ENCODER) += libfdk-aacenc.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 5194e74..bbf70a6 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -512,6 +512,7 @@ void avcodec_register_all(void) /* external libraries */ REGISTER_DECODER(LIBCELT, libcelt); + REGISTER_DECODER(LIBDCADEC, libdcadec) REGISTER_ENCODER(LIBFAAC, libfaac); REGISTER_ENCDEC (LIBFDK_AAC, libfdk_aac); REGISTER_ENCDEC (LIBGSM, libgsm); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index cdc8aa1..48e212f 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2851,6 +2851,7 @@ typedef struct AVCodecContext { #define FF_PROFILE_DTS_96_24 40 #define FF_PROFILE_DTS_HD_HRA 50 #define FF_PROFILE_DTS_HD_MA 60 +#define FF_PROFILE_DTS_EXPRESS 70 #define FF_PROFILE_MPEG2_422 0 #define FF_PROFILE_MPEG2_HIGH 1 diff --git a/libavcodec/libdcadec.c b/libavcodec/libdcadec.c new file mode 100644 index 0000000..3dc1d4d --- /dev/null +++ b/libavcodec/libdcadec.c @@ -0,0 +1,168 @@ +/* + * libdcadec decoder wrapper + * Copyright (C) 2015 Hendrik Leppkes + * + * 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 <stdbool.h> +#include <inttypes.h> +#include <dca_context.h> + +#include "libavutil/avassert.h" +#include "libavutil/channel_layout.h" +#include "libavutil/common.h" +#include "libavutil/opt.h" +#include "avcodec.h" +#include "internal.h" + +typedef struct DCADecContext { + struct dcadec_context *ctx; +} DCADecContext; + +static int dcadec_decode_frame(AVCodecContext *avctx, void *data, + int *got_frame_ptr, AVPacket *avpkt) +{ + DCADecContext *s = avctx->priv_data; + AVFrame *frame = data; + int ret, i, k; + int **samples, nsamples, channel_mask, sample_rate, bits_per_sample, profile; + + if ((ret = dcadec_context_parse(s->ctx, avpkt->data, avpkt->size)) < 0) { + av_log(avctx, AV_LOG_ERROR, "dcadec_context_parse() failed: %d\n", -ret); + return AVERROR_UNKNOWN; + } + if ((ret = dcadec_context_filter(s->ctx, &samples, &nsamples, &channel_mask, + &sample_rate, &bits_per_sample, &profile)) < 0) { + av_log(avctx, AV_LOG_ERROR, "dcadec_context_filter() failed: %d\n", -ret); + return AVERROR_UNKNOWN; + } + + avctx->channels = av_get_channel_layout_nb_channels(channel_mask); + avctx->channel_layout = channel_mask; + avctx->sample_rate = sample_rate; + + av_assert0(bits_per_sample >= 16 && bits_per_sample <= 24); + if (bits_per_sample == 16) + avctx->sample_fmt = AV_SAMPLE_FMT_S16P; + else + avctx->sample_fmt = AV_SAMPLE_FMT_S32P; + + avctx->bits_per_raw_sample = bits_per_sample; + + switch (profile) { + case DCADEC_PROFILE_DS: + avctx->profile = FF_PROFILE_DTS; + break; + case DCADEC_PROFILE_DS_96_24: + avctx->profile = FF_PROFILE_DTS_96_24; + break; + case DCADEC_PROFILE_DS_ES: + avctx->profile = FF_PROFILE_DTS_ES; + break; + case DCADEC_PROFILE_HD_HRA: + avctx->profile = FF_PROFILE_DTS_HD_HRA; + break; + case DCADEC_PROFILE_HD_MA: + avctx->profile = FF_PROFILE_DTS_HD_MA; + break; + case DCADEC_PROFILE_EXPRESS: + avctx->profile = FF_PROFILE_DTS_EXPRESS; + break; + case DCADEC_PROFILE_UNKNOWN: + default: + avctx->profile = FF_PROFILE_UNKNOWN; + break; + } + + frame->nb_samples = nsamples; + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + return ret; + + for (i = 0; i < avctx->channels; i++) { + if (frame->format == AV_SAMPLE_FMT_S16P) { + int16_t *plane = (int16_t *)frame->extended_data[i]; + for (k = 0; k < nsamples; k++) + plane[k] = samples[i][k]; + } else { + int32_t *plane = (int32_t *)frame->extended_data[i]; + int shift = 32 - bits_per_sample; + for (k = 0; k < nsamples; k++) + plane[k] = samples[i][k] << shift; + } + } + + *got_frame_ptr = 1; + + return avpkt->size; +} + +static av_cold void dcadec_flush(AVCodecContext *avctx) +{ + DCADecContext *s = avctx->priv_data; + dcadec_context_clear(s->ctx); +} + +static av_cold int dcadec_close(AVCodecContext *avctx) +{ + DCADecContext *s = avctx->priv_data; + + dcadec_context_destroy(s->ctx); + s->ctx = NULL; + + return 0; +} + +static av_cold int dcadec_init(AVCodecContext *avctx) +{ + DCADecContext *s = avctx->priv_data; + + s->ctx = dcadec_context_create(0); + if (!s->ctx) + return AVERROR(ENOMEM); + + avctx->sample_fmt = AV_SAMPLE_FMT_S32P; + avctx->bits_per_raw_sample = 24; + + return 0; +} + +static const AVProfile profiles[] = { + { FF_PROFILE_DTS, "DTS" }, + { FF_PROFILE_DTS_ES, "DTS-ES" }, + { FF_PROFILE_DTS_96_24, "DTS 96/24" }, + { FF_PROFILE_DTS_HD_HRA, "DTS-HD HRA" }, + { FF_PROFILE_DTS_HD_MA, "DTS-HD MA" }, + { FF_PROFILE_DTS_EXPRESS, "DTS Express" }, + { FF_PROFILE_UNKNOWN }, +}; + +AVCodec ff_libdcadec_decoder = { + .name = "libdcadec", + .long_name = NULL_IF_CONFIG_SMALL("dcadec DCA decoder"), + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_DTS, + .priv_data_size = sizeof(DCADecContext), + .init = dcadec_init, + .decode = dcadec_decode_frame, + .close = dcadec_close, + .flush = dcadec_flush, + .capabilities = CODEC_CAP_DR1 | CODEC_CAP_CHANNEL_CONF, + .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32P, AV_SAMPLE_FMT_S16P, + AV_SAMPLE_FMT_NONE }, + .profiles = NULL_IF_CONFIG_SMALL(profiles), +}; -- 1.9.5.msysgit.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel