dtsdec: Use new DCA functions/constants as not all distros package the compat dts.h

For backward compatibility we define the DCA functions/constants to the
old DTS functions/constants if we're building against libdts.
This commit is contained in:
Sebastian Dröge 2009-02-24 16:21:18 +01:00
parent ab1c576ec2
commit da040c2a35
3 changed files with 74 additions and 36 deletions

View file

@ -572,11 +572,13 @@ dnl *** DTS ***
translit(dnm, m, l) AM_CONDITIONAL(USE_DTS, true) translit(dnm, m, l) AM_CONDITIONAL(USE_DTS, true)
AG_GST_CHECK_FEATURE(DTS, [dts library], dtsdec, [ AG_GST_CHECK_FEATURE(DTS, [dts library], dtsdec, [
HAVE_DTS="yes" HAVE_DTS="yes"
AG_GST_CHECK_LIBHEADER(DTS, dca, dca_init, -lm, dts.h, AG_GST_CHECK_LIBHEADER(DTS, dca, dca_init, -lm, dca.h,
DTS_LIBS="-ldca -lm", HAVE_DTS="no") DTS_LIBS="-ldca -lm", HAVE_DTS="no")
if test $HAVE_DTS = "no"; then if test $HAVE_DTS = "no"; then
AG_GST_CHECK_LIBHEADER(DTS, dts_pic, dts_init, -lm, dts.h, AG_GST_CHECK_LIBHEADER(DTS, dts_pic, dts_init, -lm, dts.h,
DTS_LIBS="-ldts_pic -lm") [ DTS_LIBS="-ldts_pic -lm"
AC_DEFINE(DTS_OLD, 1, [Define if an old libdts is used])
])
fi fi
AC_SUBST(DTS_LIBS) AC_SUBST(DTS_LIBS)
]) ])

View file

@ -33,8 +33,40 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/multichannel.h> #include <gst/audio/multichannel.h>
#ifndef DTS_OLD
#include <dca.h>
#else
#include <dts.h> #include <dts.h>
typedef struct dts_state_s dca_state_t;
#define DCA_MONO DTS_MONO
#define DCA_CHANNEL DTS_CHANNEL
#define DCA_STEREO DTS_STEREO
#define DCA_STEREO_SUMDIFF DTS_STEREO_SUMDIFF
#define DCA_STEREO_TOTAL DTS_STEREO_TOTAL
#define DCA_3F DTS_3F
#define DCA_2F1R DTS_2F1R
#define DCA_3F1R DTS_3F1R
#define DCA_2F2R DTS_2F2R
#define DCA_3F2R DTS_3F2R
#define DCA_4F2R DTS_4F2R
#define DCA_DOLBY DTS_DOLBY
#define DCA_CHANNEL_MAX DTS_CHANNEL_MAX
#define DCA_CHANNEL_BITS DTS_CHANNEL_BITS
#define DCA_CHANNEL_MASK DTS_CHANNEL_MASK
#define DCA_LFE DTS_LFE
#define DCA_ADJUST_LEVEL DTS_ADJUST_LEVEL
#define dca_init dts_init
#define dca_syncinfo dts_syncinfo
#define dca_frame dts_frame
#define dca_dynrng dts_dynrng
#define dca_blocks_num dts_blocks_num
#define dca_block dts_block
#define dca_samples dts_samples
#define dca_free dts_free
#endif
#include "gstdtsdec.h" #include "gstdtsdec.h"
#include <liboil/liboil.h> #include <liboil/liboil.h>
@ -180,24 +212,24 @@ gst_dtsdec_channels (uint32_t flags, GstAudioChannelPosition ** pos)
return 0; return 0;
} }
switch (flags & DTS_CHANNEL_MASK) { switch (flags & DCA_CHANNEL_MASK) {
case DTS_MONO: case DCA_MONO:
chans = 1; chans = 1;
if (tpos) if (tpos)
tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO; tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO;
break; break;
/* case DTS_CHANNEL: */ /* case DCA_CHANNEL: */
case DTS_STEREO: case DCA_STEREO:
case DTS_STEREO_SUMDIFF: case DCA_STEREO_SUMDIFF:
case DTS_STEREO_TOTAL: case DCA_STEREO_TOTAL:
case DTS_DOLBY: case DCA_DOLBY:
chans = 2; chans = 2;
if (tpos) { if (tpos) {
tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
tpos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT; tpos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
} }
break; break;
case DTS_3F: case DCA_3F:
chans = 3; chans = 3;
if (tpos) { if (tpos) {
tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER; tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER;
@ -205,7 +237,7 @@ gst_dtsdec_channels (uint32_t flags, GstAudioChannelPosition ** pos)
tpos[2] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT; tpos[2] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
} }
break; break;
case DTS_2F1R: case DCA_2F1R:
chans = 3; chans = 3;
if (tpos) { if (tpos) {
tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
@ -213,7 +245,7 @@ gst_dtsdec_channels (uint32_t flags, GstAudioChannelPosition ** pos)
tpos[2] = GST_AUDIO_CHANNEL_POSITION_REAR_CENTER; tpos[2] = GST_AUDIO_CHANNEL_POSITION_REAR_CENTER;
} }
break; break;
case DTS_3F1R: case DCA_3F1R:
chans = 4; chans = 4;
if (tpos) { if (tpos) {
tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER; tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER;
@ -222,7 +254,7 @@ gst_dtsdec_channels (uint32_t flags, GstAudioChannelPosition ** pos)
tpos[3] = GST_AUDIO_CHANNEL_POSITION_REAR_CENTER; tpos[3] = GST_AUDIO_CHANNEL_POSITION_REAR_CENTER;
} }
break; break;
case DTS_2F2R: case DCA_2F2R:
chans = 4; chans = 4;
if (tpos) { if (tpos) {
tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
@ -231,7 +263,7 @@ gst_dtsdec_channels (uint32_t flags, GstAudioChannelPosition ** pos)
tpos[3] = GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT; tpos[3] = GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT;
} }
break; break;
case DTS_3F2R: case DCA_3F2R:
chans = 5; chans = 5;
if (tpos) { if (tpos) {
tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER; tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER;
@ -241,7 +273,7 @@ gst_dtsdec_channels (uint32_t flags, GstAudioChannelPosition ** pos)
tpos[4] = GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT; tpos[4] = GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT;
} }
break; break;
case DTS_4F2R: case DCA_4F2R:
chans = 6; chans = 6;
if (tpos) { if (tpos) {
tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER; tpos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER;
@ -256,7 +288,7 @@ gst_dtsdec_channels (uint32_t flags, GstAudioChannelPosition ** pos)
g_warning ("dtsdec: invalid flags 0x%x", flags); g_warning ("dtsdec: invalid flags 0x%x", flags);
return 0; return 0;
} }
if (flags & DTS_LFE) { if (flags & DCA_LFE) {
if (tpos) { if (tpos) {
tpos[chans] = GST_AUDIO_CHANNEL_POSITION_LFE; tpos[chans] = GST_AUDIO_CHANNEL_POSITION_LFE;
} }
@ -397,7 +429,7 @@ gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data,
gst_dtsdec_update_streaminfo (dts); gst_dtsdec_update_streaminfo (dts);
} }
if (dts->request_channels == DTS_CHANNEL) { if (dts->request_channels == DCA_CHANNEL) {
GstCaps *caps; GstCaps *caps;
caps = gst_pad_get_allowed_caps (dts->srcpad); caps = gst_pad_get_allowed_caps (dts->srcpad);
@ -406,12 +438,12 @@ gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data,
GstStructure *structure = gst_caps_get_structure (copy, 0); GstStructure *structure = gst_caps_get_structure (copy, 0);
gint channels; gint channels;
const int dts_channels[6] = { const int dts_channels[6] = {
DTS_MONO, DCA_MONO,
DTS_STEREO, DCA_STEREO,
DTS_STEREO | DTS_LFE, DCA_STEREO | DCA_LFE,
DTS_2F2R, DCA_2F2R,
DTS_2F2R | DTS_LFE, DCA_2F2R | DCA_LFE,
DTS_3F2R | DTS_LFE, DCA_3F2R | DCA_LFE,
}; };
/* Prefer the original number of channels, but fixate to something /* Prefer the original number of channels, but fixate to something
@ -429,7 +461,7 @@ gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data,
} else if (flags) { } else if (flags) {
dts->request_channels = dts->stream_channels; dts->request_channels = dts->stream_channels;
} else { } else {
dts->request_channels = DTS_3F2R | DTS_LFE; dts->request_channels = DCA_3F2R | DCA_LFE;
} }
if (caps) if (caps)
@ -437,15 +469,15 @@ gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data,
} }
/* process */ /* process */
flags = dts->request_channels | DTS_ADJUST_LEVEL; flags = dts->request_channels | DCA_ADJUST_LEVEL;
dts->level = 1; dts->level = 1;
if (dts_frame (dts->state, data, &flags, &dts->level, dts->bias)) { if (dca_frame (dts->state, data, &flags, &dts->level, dts->bias)) {
GST_WARNING ("dts_frame error"); GST_WARNING ("dts_frame error");
return GST_FLOW_OK; return GST_FLOW_OK;
} }
channels = flags & (DTS_CHANNEL_MASK | DTS_LFE); channels = flags & (DCA_CHANNEL_MASK | DCA_LFE);
if (dts->using_channels != channels) { if (dts->using_channels != channels) {
need_renegotiation = TRUE; need_renegotiation = TRUE;
@ -462,18 +494,18 @@ gst_dtsdec_handle_frame (GstDtsDec * dts, guint8 * data,
} }
if (dts->dynamic_range_compression == FALSE) { if (dts->dynamic_range_compression == FALSE) {
dts_dynrng (dts->state, NULL, NULL); dca_dynrng (dts->state, NULL, NULL);
} }
/* handle decoded data, one block is 256 samples */ /* handle decoded data, one block is 256 samples */
num_blocks = dts_blocks_num (dts->state); num_blocks = dca_blocks_num (dts->state);
for (i = 0; i < num_blocks; i++) { for (i = 0; i < num_blocks; i++) {
if (dts_block (dts->state)) { if (dca_block (dts->state)) {
GST_WARNING ("dts_block error %d", i); GST_WARNING ("dts_block error %d", i);
continue; continue;
} }
samples = dts_samples (dts->state); samples = dca_samples (dts->state);
num_c = gst_dtsdec_channels (dts->using_channels, NULL); num_c = gst_dtsdec_channels (dts->using_channels, NULL);
result = gst_pad_alloc_buffer_and_set_caps (dts->srcpad, 0, result = gst_pad_alloc_buffer_and_set_caps (dts->srcpad, 0,
@ -526,7 +558,7 @@ gst_dtsdec_chain_raw (GstPad * pad, GstBuffer * buf)
size = GST_BUFFER_SIZE (buf); size = GST_BUFFER_SIZE (buf);
length = 0; length = 0;
while (size >= 7) { while (size >= 7) {
length = dts_syncinfo (dts->state, data, &flags, length = dca_syncinfo (dts->state, data, &flags,
&sample_rate, &bit_rate, &frame_length); &sample_rate, &bit_rate, &frame_length);
if (length == 0) { if (length == 0) {
/* shift window to re-find sync */ /* shift window to re-find sync */
@ -647,16 +679,16 @@ gst_dtsdec_change_state (GstElement * element, GstStateChange transition)
GstDtsDecClass *klass; GstDtsDecClass *klass;
klass = GST_DTSDEC_CLASS (G_OBJECT_GET_CLASS (dts)); klass = GST_DTSDEC_CLASS (G_OBJECT_GET_CLASS (dts));
dts->state = dts_init (klass->dts_cpuflags); dts->state = dca_init (klass->dts_cpuflags);
break; break;
} }
case GST_STATE_CHANGE_READY_TO_PAUSED: case GST_STATE_CHANGE_READY_TO_PAUSED:
dts->samples = dts_samples (dts->state); dts->samples = dca_samples (dts->state);
dts->bit_rate = -1; dts->bit_rate = -1;
dts->sample_rate = -1; dts->sample_rate = -1;
dts->stream_channels = 0; dts->stream_channels = 0;
/* FIXME force stereo for now */ /* FIXME force stereo for now */
dts->request_channels = DTS_CHANNEL; dts->request_channels = DCA_CHANNEL;
dts->using_channels = 0; dts->using_channels = 0;
dts->level = 1; dts->level = 1;
dts->bias = 0; dts->bias = 0;
@ -681,7 +713,7 @@ gst_dtsdec_change_state (GstElement * element, GstStateChange transition)
} }
break; break;
case GST_STATE_CHANGE_READY_TO_NULL: case GST_STATE_CHANGE_READY_TO_NULL:
dts_free (dts->state); dca_free (dts->state);
dts->state = NULL; dts->state = NULL;
break; break;
default: default:

View file

@ -58,7 +58,11 @@ struct _GstDtsDec {
sample_t bias; sample_t bias;
gboolean dynamic_range_compression; gboolean dynamic_range_compression;
sample_t *samples; sample_t *samples;
#ifndef DTS_OLD
dca_state_t *state;
#else
dts_state_t *state; dts_state_t *state;
#endif
gboolean dvdmode; gboolean dvdmode;
/* Data left over from the previous buffer */ /* Data left over from the previous buffer */