History

lavc: add libdcadec decoder

Hendrik Leppkes committed 11 years ago

Commit 72025ac1 parent 6fe26415 files · +212 −0Browse files

Unified · Split

5 files
  1. Changelog +1 −0
  2. configure +4 −0
  3. libavcodec/Makefile +1 −0
  4. libavcodec/allcodecs.c +1 −0
  5. libavcodec/libdcadec.c +205 −0
Changelog+1−0
@@ -26,6 +26,7 @@ version <next>: · 25 unmodified lines
2626 - DTS lossless extension (XLL) decoding (not lossless, disabled by default)
2727 - Intel QSV-accelerated H.264 encoding
2828 - MMAL-accelerated H.264 decoding
29+- DTS decoding through libdcadec
2930
3031
3132 version 11:
configure+4−0
@@ -184,6 +184,7 @@ External library support: · 183 unmodified lines
184184 --enable-libcdio enable audio CD grabbing with libcdio
185185 --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394
186186 and libraw1394 [no]
187+ --enable-libdcadec enable DCA decoding via libdcadec [no]
187188 --enable-libfaac enable AAC encoding via libfaac [no]
188189 --enable-libfdk-aac enable AAC de/encoding via libfdk-aac [no]
189190 --enable-libfreetype enable libfreetype [no]
@@ -1150,6 +1151,7 @@ EXTERNAL_LIBRARY_LIST=" · 960 unmodified lines
11501151 libbs2b
11511152 libcdio
11521153 libdc1394
1154+ libdcadec
11531155 libfaac
11541156 libfdk_aac
11551157 libfontconfig
@@ -2016,6 +2018,7 @@ mpeg4video_parser_select="error_resilience h263dsp mpeg_er mpegvideo qpeldsp" · 860 unmodified lines
20162018 vc1_parser_select="mpegvideo startcode vc1_decoder"
20172019
20182020 # external libraries
2021+libdcadec_decoder_deps="libdcadec"
20192022 libfaac_encoder_deps="libfaac"
20202023 libfaac_encoder_select="audio_frame_queue"
20212024 libfdk_aac_decoder_deps="libfdk_aac"
@@ -4218,6 +4221,7 @@ enabled avisynth && { { check_header "avisynth/avisynth_c.h" && check_l · 2196 unmodified lines
42184221 enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
42194222 enabled gnutls && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init
42204223 enabled libbs2b && require_pkg_config libbs2b bs2b.h bs2b_open
4224+enabled libdcadec && require libdcadec libdcadec/dca_context.h dcadec_context_create -ldcadec
42214225 enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
42224226 enabled libfdk_aac && require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac
42234227 enabled libfontconfig && require_pkg_config fontconfig "fontconfig/fontconfig.h" FcInit
libavcodec/Makefile+1−0
@@ -611,6 +611,7 @@ OBJS-$(CONFIG_WEBM_MUXER) += mpeg4audio.o mpegaudiodata.o \ · 610 unmodified lines
611611 OBJS-$(CONFIG_WTV_DEMUXER) += mpeg4audio.o mpegaudiodata.o
612612
613613 # external codec libraries
614+OBJS-$(CONFIG_LIBDCADEC_DECODER) += libdcadec.o dca.o
614615 OBJS-$(CONFIG_LIBFAAC_ENCODER) += libfaac.o
615616 OBJS-$(CONFIG_LIBFDK_AAC_DECODER) += libfdk-aacdec.o
616617 OBJS-$(CONFIG_LIBFDK_AAC_ENCODER) += libfdk-aacenc.o
libavcodec/allcodecs.c+1−0
@@ -442,6 +442,7 @@ void avcodec_register_all(void) · 441 unmodified lines
442442 REGISTER_ENCDEC (XSUB, xsub);
443443
444444 /* external libraries */
445+ REGISTER_DECODER(LIBDCADEC, libdcadec)
445446 REGISTER_ENCODER(LIBFAAC, libfaac);
446447 REGISTER_ENCDEC (LIBFDK_AAC, libfdk_aac);
447448 REGISTER_ENCDEC (LIBGSM, libgsm);
libavcodec/libdcadec.c+205−0
@@ -0,0 +1,205 @@
1+/*
2+ * libdcadec decoder wrapper
3+ * Copyright (C) 2015 Hendrik Leppkes
4+ *
5+ * This file is part of Libav.
6+ *
7+ * Libav is free software; you can redistribute it and/or
8+ * modify it under the terms of the GNU Lesser General Public
9+ * License as published by the Free Software Foundation; either
10+ * version 2.1 of the License, or (at your option) any later version.
11+ *
12+ * Libav is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+ * Lesser General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU Lesser General Public
18+ * License along with Libav; if not, write to the Free Software
19+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+ */
21+
22+#include <libdcadec/dca_context.h>
23+
24+#include "libavutil/channel_layout.h"
25+#include "libavutil/common.h"
26+#include "libavutil/opt.h"
27+
28+#include "avcodec.h"
29+#include "dca.h"
30+#include "dca_syncwords.h"
31+#include "internal.h"
32+
33+typedef struct DCADecContext {
34+ struct dcadec_context *ctx;
35+ uint8_t *buffer;
36+ int buffer_size;
37+} DCADecContext;
38+
39+static int dcadec_decode_frame(AVCodecContext *avctx, void *data,
40+ int *got_frame_ptr, AVPacket *avpkt)
41+{
42+ DCADecContext *s = avctx->priv_data;
43+ AVFrame *frame = data;
44+ int ret, i, k;
45+ int **samples, nsamples, channel_mask, sample_rate, bits_per_sample, profile;
46+ uint32_t mrk;
47+ uint8_t *input = avpkt->data;
48+ int input_size = avpkt->size;
49+
50+ /* convert bytestream syntax to RAW BE format if required */
51+ if (input_size < 8) {
52+ av_log(avctx, AV_LOG_ERROR, "Input size too small\n");
53+ return AVERROR_INVALIDDATA;
54+ }
55+ mrk = AV_RB32(input);
56+ if (mrk != DCA_SYNCWORD_CORE_BE && mrk != DCA_SYNCWORD_SUBSTREAM) {
57+ s->buffer = av_fast_realloc(s->buffer, &s->buffer_size, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
58+ if (!s->buffer)
59+ return AVERROR(ENOMEM);
60+
61+ if ((ret = ff_dca_convert_bitstream(avpkt->data, avpkt->size, s->buffer, s->buffer_size)) < 0)
62+ return ret;
63+
64+ input = s->buffer;
65+ input_size = ret;
66+ }
67+
68+ if ((ret = dcadec_context_parse(s->ctx, input, input_size)) < 0) {
69+ av_log(avctx, AV_LOG_ERROR, "dcadec_context_parse() failed: %d (%s)\n", -ret, dcadec_strerror(ret));
70+ return AVERROR_UNKNOWN;
71+ }
72+ if ((ret = dcadec_context_filter(s->ctx, &samples, &nsamples, &channel_mask,
73+ &sample_rate, &bits_per_sample, &profile)) < 0) {
74+ av_log(avctx, AV_LOG_ERROR, "dcadec_context_filter() failed: %d (%s)\n", -ret, dcadec_strerror(ret));
75+ return AVERROR_UNKNOWN;
76+ }
77+
78+ avctx->channels = av_get_channel_layout_nb_channels(channel_mask);
79+ avctx->channel_layout = channel_mask;
80+ avctx->sample_rate = sample_rate;
81+
82+ if (bits_per_sample == 16)
83+ avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
84+ else if (bits_per_sample <= 24)
85+ avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
86+ else {
87+ av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits per sample: %d\n",
88+ bits_per_sample);
89+ return AVERROR(ENOSYS);
90+ }
91+
92+ avctx->bits_per_raw_sample = bits_per_sample;
93+
94+ switch (profile) {
95+ case DCADEC_PROFILE_DS:
96+ avctx->profile = FF_PROFILE_DTS;
97+ break;
98+ case DCADEC_PROFILE_DS_96_24:
99+ avctx->profile = FF_PROFILE_DTS_96_24;
100+ break;
101+ case DCADEC_PROFILE_DS_ES:
102+ avctx->profile = FF_PROFILE_DTS_ES;
103+ break;
104+ case DCADEC_PROFILE_HD_HRA:
105+ avctx->profile = FF_PROFILE_DTS_HD_HRA;
106+ break;
107+ case DCADEC_PROFILE_HD_MA:
108+ avctx->profile = FF_PROFILE_DTS_HD_MA;
109+ break;
110+ case DCADEC_PROFILE_EXPRESS:
111+ avctx->profile = FF_PROFILE_DTS_EXPRESS;
112+ break;
113+ case DCADEC_PROFILE_UNKNOWN:
114+ default:
115+ avctx->profile = FF_PROFILE_UNKNOWN;
116+ break;
117+ }
118+
119+ /* bitrate is only meaningful if there are no HD extensions, as they distort the bitrate */
120+ if (profile == DCADEC_PROFILE_DS || profile == DCADEC_PROFILE_DS_96_24 || profile == DCADEC_PROFILE_DS_ES) {
121+ struct dcadec_core_info *info = dcadec_context_get_core_info(s->ctx);
122+ avctx->bit_rate = info->bit_rate;
123+ dcadec_context_free_core_info(info);
124+ } else
125+ avctx->bit_rate = 0;
126+
127+ frame->nb_samples = nsamples;
128+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
129+ return ret;
130+
131+ for (i = 0; i < avctx->channels; i++) {
132+ if (frame->format == AV_SAMPLE_FMT_S16P) {
133+ int16_t *plane = (int16_t *)frame->extended_data[i];
134+ for (k = 0; k < nsamples; k++)
135+ plane[k] = samples[i][k];
136+ } else {
137+ int32_t *plane = (int32_t *)frame->extended_data[i];
138+ int shift = 32 - bits_per_sample;
139+ for (k = 0; k < nsamples; k++)
140+ plane[k] = samples[i][k] << shift;
141+ }
142+ }
143+
144+ *got_frame_ptr = 1;
145+
146+ return avpkt->size;
147+}
148+
149+static av_cold void dcadec_flush(AVCodecContext *avctx)
150+{
151+ DCADecContext *s = avctx->priv_data;
152+ dcadec_context_clear(s->ctx);
153+}
154+
155+static av_cold int dcadec_close(AVCodecContext *avctx)
156+{
157+ DCADecContext *s = avctx->priv_data;
158+
159+ dcadec_context_destroy(s->ctx);
160+ s->ctx = NULL;
161+
162+ av_freep(&s->buffer);
163+
164+ return 0;
165+}
166+
167+static av_cold int dcadec_init(AVCodecContext *avctx)
168+{
169+ DCADecContext *s = avctx->priv_data;
170+
171+ s->ctx = dcadec_context_create(0);
172+ if (!s->ctx)
173+ return AVERROR(ENOMEM);
174+
175+ avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
176+ avctx->bits_per_raw_sample = 24;
177+
178+ return 0;
179+}
180+
181+static const AVProfile profiles[] = {
182+ { FF_PROFILE_DTS, "DTS" },
183+ { FF_PROFILE_DTS_ES, "DTS-ES" },
184+ { FF_PROFILE_DTS_96_24, "DTS 96/24" },
185+ { FF_PROFILE_DTS_HD_HRA, "DTS-HD HRA" },
186+ { FF_PROFILE_DTS_HD_MA, "DTS-HD MA" },
187+ { FF_PROFILE_DTS_EXPRESS, "DTS Express" },
188+ { FF_PROFILE_UNKNOWN },
189+};
190+
191+AVCodec ff_libdcadec_decoder = {
192+ .name = "libdcadec",
193+ .long_name = NULL_IF_CONFIG_SMALL("dcadec DCA decoder"),
194+ .type = AVMEDIA_TYPE_AUDIO,
195+ .id = AV_CODEC_ID_DTS,
196+ .priv_data_size = sizeof(DCADecContext),
197+ .init = dcadec_init,
198+ .decode = dcadec_decode_frame,
199+ .close = dcadec_close,
200+ .flush = dcadec_flush,
201+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_CHANNEL_CONF,
202+ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32P, AV_SAMPLE_FMT_S16P,
203+ AV_SAMPLE_FMT_NONE },
204+ .profiles = NULL_IF_CONFIG_SMALL(profiles),
205+};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t