2005-08-31 11:53:35 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* Copyright (C) <2005> Jan Schmidt <jan@noraisin.net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:40:37 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2005-08-31 11:53:35 +00:00
|
|
|
*/
|
|
|
|
/* Element-Checklist-Version: TODO */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstdvdlpcmdec.h"
|
2012-01-04 14:26:56 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2005-08-31 11:53:35 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (dvdlpcm_debug);
|
|
|
|
#define GST_CAT_DEFAULT dvdlpcm_debug
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_dvdlpcmdec_sink_template =
|
2005-08-31 19:37:08 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
2005-08-31 11:53:35 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2005-08-31 19:37:08 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-private1-lpcm; "
|
2016-04-28 14:42:43 +00:00
|
|
|
"audio/x-private2-lpcm; "
|
2017-07-05 15:58:35 +00:00
|
|
|
"audio/x-private-ts-lpcm; "
|
2005-08-31 19:37:08 +00:00
|
|
|
"audio/x-lpcm, "
|
2005-08-31 11:53:35 +00:00
|
|
|
"width = (int) { 16, 20, 24 }, "
|
2007-08-24 15:55:03 +00:00
|
|
|
"rate = (int) { 32000, 44100, 48000, 96000 }, "
|
2005-08-31 11:53:35 +00:00
|
|
|
"channels = (int) [ 1, 8 ], "
|
|
|
|
"dynamic_range = (int) [ 0, 255 ], "
|
|
|
|
"emphasis = (boolean) { TRUE, FALSE }, "
|
2005-08-31 19:37:08 +00:00
|
|
|
"mute = (boolean) { TRUE, FALSE } ")
|
2005-08-31 11:53:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_dvdlpcmdec_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-09-27 18:32:46 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw, "
|
|
|
|
"format = (string) { S16BE, S24BE }, "
|
2012-01-04 14:26:56 +00:00
|
|
|
"layout = (string) interleaved, "
|
2007-08-24 15:55:03 +00:00
|
|
|
"rate = (int) { 32000, 44100, 48000, 96000 }, "
|
2011-09-27 18:32:46 +00:00
|
|
|
"channels = (int) [ 1, 8 ]")
|
2005-08-31 11:53:35 +00:00
|
|
|
);
|
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
#define gst_dvdlpcmdec_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstDvdLpcmDec, gst_dvdlpcmdec, GST_TYPE_AUDIO_DECODER);
|
2021-03-29 11:15:32 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE (dvdlpcmdec, "dvdlpcmdec", GST_RANK_PRIMARY,
|
|
|
|
GST_TYPE_DVDLPCMDEC);
|
2016-04-28 14:32:53 +00:00
|
|
|
|
|
|
|
static gboolean gst_dvdlpcmdec_set_format (GstAudioDecoder * bdec,
|
|
|
|
GstCaps * caps);
|
|
|
|
static GstFlowReturn gst_dvdlpcmdec_parse (GstAudioDecoder * bdec,
|
|
|
|
GstAdapter * adapter, gint * offset, gint * len);
|
|
|
|
static GstFlowReturn gst_dvdlpcmdec_handle_frame (GstAudioDecoder * bdec,
|
2005-08-31 19:37:08 +00:00
|
|
|
GstBuffer * buffer);
|
2016-04-28 14:32:53 +00:00
|
|
|
static GstFlowReturn gst_dvdlpcmdec_chain (GstPad * pad, GstObject * parent,
|
2005-08-31 19:37:08 +00:00
|
|
|
GstBuffer * buffer);
|
2005-08-31 11:53:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_dvdlpcmdec_class_init (GstDvdLpcmDecClass * klass)
|
2005-08-31 11:53:35 +00:00
|
|
|
{
|
2016-04-28 14:32:53 +00:00
|
|
|
GstElementClass *element_class;
|
|
|
|
GstAudioDecoderClass *gstbase_class;
|
|
|
|
|
|
|
|
element_class = (GstElementClass *) klass;
|
|
|
|
gstbase_class = (GstAudioDecoderClass *) klass;
|
|
|
|
|
|
|
|
gstbase_class->set_format = GST_DEBUG_FUNCPTR (gst_dvdlpcmdec_set_format);
|
|
|
|
gstbase_class->parse = GST_DEBUG_FUNCPTR (gst_dvdlpcmdec_parse);
|
|
|
|
gstbase_class->handle_frame = GST_DEBUG_FUNCPTR (gst_dvdlpcmdec_handle_frame);
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2016-03-04 07:14:44 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_dvdlpcmdec_sink_template);
|
|
|
|
gst_element_class_add_static_pad_template (element_class,
|
|
|
|
&gst_dvdlpcmdec_src_template);
|
2012-04-09 23:47:44 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
|
|
|
"DVD LPCM Audio decoder", "Codec/Decoder/Audio",
|
2010-03-18 14:53:14 +00:00
|
|
|
"Decode DVD LPCM frames into standard PCM audio",
|
|
|
|
"Jan Schmidt <jan@noraisin.net>, Michael Smith <msmith@fluendo.com>");
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (dvdlpcm_debug, "dvdlpcmdec", 0, "DVD LPCM Decoder");
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dvdlpcm_reset (GstDvdLpcmDec * dvdlpcmdec)
|
|
|
|
{
|
2011-09-27 18:32:46 +00:00
|
|
|
gst_audio_info_init (&dvdlpcmdec->info);
|
2005-08-31 11:53:35 +00:00
|
|
|
dvdlpcmdec->dynamic_range = 0;
|
|
|
|
dvdlpcmdec->emphasis = FALSE;
|
|
|
|
dvdlpcmdec->mute = FALSE;
|
|
|
|
|
2005-08-31 19:37:08 +00:00
|
|
|
dvdlpcmdec->header = 0;
|
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
dvdlpcmdec->mode = GST_LPCM_UNKNOWN;
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dvdlpcmdec_init (GstDvdLpcmDec * dvdlpcmdec)
|
|
|
|
{
|
|
|
|
gst_dvdlpcm_reset (dvdlpcmdec);
|
2016-04-28 14:32:53 +00:00
|
|
|
|
|
|
|
gst_audio_decoder_set_use_default_pad_acceptcaps (GST_AUDIO_DECODER_CAST
|
|
|
|
(dvdlpcmdec), TRUE);
|
|
|
|
GST_PAD_SET_ACCEPT_TEMPLATE (GST_AUDIO_DECODER_SINK_PAD (dvdlpcmdec));
|
|
|
|
|
|
|
|
/* retrieve and intercept base class chain.
|
|
|
|
* Quite HACKish, but that's dvd specs/caps for you,
|
|
|
|
* since one buffer needs to be split into 2 frames */
|
|
|
|
dvdlpcmdec->base_chain =
|
|
|
|
GST_PAD_CHAINFUNC (GST_AUDIO_DECODER_SINK_PAD (dvdlpcmdec));
|
|
|
|
gst_pad_set_chain_function (GST_AUDIO_DECODER_SINK_PAD (dvdlpcmdec),
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvdlpcmdec_chain));
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-04 14:26:56 +00:00
|
|
|
static const GstAudioChannelPosition channel_positions[][8] = {
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_MONO},
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID},
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT},
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID},
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_LFE1, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT},
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID},
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_LFE1, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT},
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID}
|
|
|
|
};
|
2009-05-26 23:16:30 +00:00
|
|
|
|
2017-07-05 15:58:35 +00:00
|
|
|
static const GstAudioChannelPosition bluray_channel_positions[][8] = {
|
|
|
|
/* invalid */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID},
|
|
|
|
/* mono */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_MONO},
|
|
|
|
/* invalid */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID},
|
|
|
|
/* stereo */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT},
|
|
|
|
/* surround */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER},
|
|
|
|
/* 2.1 */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER},
|
|
|
|
/* 4.0 */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_CENTER},
|
|
|
|
/* 2.2 */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT},
|
|
|
|
/* 5.0 */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT},
|
|
|
|
/* 5.1 */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_LFE1},
|
|
|
|
/* 7.0 */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT},
|
|
|
|
/* 7.1 */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
|
|
|
|
GST_AUDIO_CHANNEL_POSITION_LFE1},
|
|
|
|
/* invalid */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID},
|
|
|
|
/* invalid */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID},
|
|
|
|
/* invalid */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID},
|
|
|
|
/* invalid */
|
|
|
|
{GST_AUDIO_CHANNEL_POSITION_INVALID}
|
|
|
|
};
|
|
|
|
|
2009-05-26 23:16:30 +00:00
|
|
|
static void
|
|
|
|
gst_dvdlpcmdec_send_tags (GstDvdLpcmDec * dvdlpcmdec)
|
|
|
|
{
|
|
|
|
GstTagList *taglist;
|
2011-09-27 18:32:46 +00:00
|
|
|
guint bitrate;
|
|
|
|
gint bpf, rate;
|
|
|
|
|
|
|
|
bpf = GST_AUDIO_INFO_BPF (&dvdlpcmdec->info);
|
|
|
|
rate = GST_AUDIO_INFO_RATE (&dvdlpcmdec->info);
|
|
|
|
|
|
|
|
bitrate = bpf * 8 * rate;
|
2009-05-26 23:16:30 +00:00
|
|
|
|
2011-10-30 11:51:58 +00:00
|
|
|
taglist = gst_tag_list_new (GST_TAG_AUDIO_CODEC, "LPCM Audio",
|
|
|
|
GST_TAG_BITRATE, bitrate, NULL);
|
2009-05-26 23:16:30 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_audio_decoder_merge_tags (GST_AUDIO_DECODER (dvdlpcmdec), taglist,
|
|
|
|
GST_TAG_MERGE_REPLACE);
|
|
|
|
gst_tag_list_unref (taglist);
|
2009-05-26 23:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_dvdlpcmdec_set_output_format (GstDvdLpcmDec * dvdlpcmdec)
|
2009-05-26 23:16:30 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
res = gst_audio_decoder_set_output_format (GST_AUDIO_DECODER (dvdlpcmdec),
|
|
|
|
&dvdlpcmdec->info);
|
2009-05-26 23:16:30 +00:00
|
|
|
if (res) {
|
2016-04-28 14:32:53 +00:00
|
|
|
GST_DEBUG_OBJECT (dvdlpcmdec, "Successfully set output format");
|
2009-05-26 23:16:30 +00:00
|
|
|
|
|
|
|
gst_dvdlpcmdec_send_tags (dvdlpcmdec);
|
|
|
|
} else {
|
2016-04-28 14:32:53 +00:00
|
|
|
GST_DEBUG_OBJECT (dvdlpcmdec, "Failed to set output format");
|
2009-05-26 23:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-08-25 01:08:46 +00:00
|
|
|
static void
|
|
|
|
gst_dvdlpcmdec_update_audio_formats (GstDvdLpcmDec * dec, gint channels,
|
2017-07-05 15:58:35 +00:00
|
|
|
gint rate, GstAudioFormat format, guint8 channel_indicator,
|
|
|
|
const GstAudioChannelPosition positions[][8])
|
2015-08-25 01:08:46 +00:00
|
|
|
{
|
2017-07-05 15:58:35 +00:00
|
|
|
GST_DEBUG_OBJECT (dec, "got channels = %d, rate = %d, format = %d", channels,
|
2015-08-25 01:08:46 +00:00
|
|
|
rate, format);
|
|
|
|
|
|
|
|
/* Reorder the channel positions and set the default into for the audio */
|
|
|
|
if (channels < 9
|
2017-07-05 15:58:35 +00:00
|
|
|
&& positions[channel_indicator][0] !=
|
2015-08-25 01:08:46 +00:00
|
|
|
GST_AUDIO_CHANNEL_POSITION_INVALID) {
|
|
|
|
const GstAudioChannelPosition *position;
|
|
|
|
GstAudioChannelPosition sorted_position[8];
|
2015-09-26 08:23:05 +00:00
|
|
|
guint c;
|
2015-08-25 01:08:46 +00:00
|
|
|
|
2017-07-05 15:58:35 +00:00
|
|
|
position = positions[channel_indicator];
|
2015-09-26 08:23:05 +00:00
|
|
|
for (c = 0; c < channels; ++c)
|
|
|
|
sorted_position[c] = position[c];
|
2015-08-25 01:08:46 +00:00
|
|
|
gst_audio_channel_positions_to_valid_order (sorted_position, channels);
|
|
|
|
gst_audio_info_set_format (&dec->info, format, rate, channels,
|
|
|
|
sorted_position);
|
2016-04-28 14:32:53 +00:00
|
|
|
if (memcmp (position, sorted_position,
|
|
|
|
channels * sizeof (position[0])) != 0)
|
|
|
|
dec->lpcm_layout = position;
|
|
|
|
else
|
|
|
|
dec->lpcm_layout = NULL;
|
2015-08-25 01:08:46 +00:00
|
|
|
} else {
|
|
|
|
gst_audio_info_set_format (&dec->info, format, rate, channels, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-02 14:19:17 +00:00
|
|
|
static gboolean
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_dvdlpcmdec_set_format (GstAudioDecoder * bdec, GstCaps * caps)
|
2005-08-31 11:53:35 +00:00
|
|
|
{
|
2016-04-28 14:32:53 +00:00
|
|
|
GstDvdLpcmDec *dvdlpcmdec = GST_DVDLPCMDEC (bdec);
|
2005-08-31 11:53:35 +00:00
|
|
|
GstStructure *structure;
|
|
|
|
gboolean res = TRUE;
|
2011-09-27 18:32:46 +00:00
|
|
|
GstAudioFormat format;
|
|
|
|
gint rate, channels, width;
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_dvdlpcm_reset (dvdlpcmdec);
|
2005-08-31 11:53:35 +00:00
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2009-05-26 23:16:30 +00:00
|
|
|
/* If we have the DVD structured LPCM (including header) then we wait
|
|
|
|
* for incoming data before creating the output pad caps */
|
2005-08-31 19:37:08 +00:00
|
|
|
if (gst_structure_has_name (structure, "audio/x-private1-lpcm")) {
|
2016-04-28 14:32:53 +00:00
|
|
|
dvdlpcmdec->mode = GST_LPCM_DVD;
|
2005-09-01 11:52:34 +00:00
|
|
|
goto done;
|
2005-08-31 19:37:08 +00:00
|
|
|
}
|
2016-04-28 14:42:43 +00:00
|
|
|
if (gst_structure_has_name (structure, "audio/x-private2-lpcm")) {
|
|
|
|
dvdlpcmdec->mode = GST_LPCM_1394;
|
|
|
|
goto done;
|
|
|
|
}
|
2017-07-05 15:58:35 +00:00
|
|
|
if (gst_structure_has_name (structure, "audio/x-private-ts-lpcm")) {
|
|
|
|
dvdlpcmdec->mode = GST_LPCM_BLURAY;
|
|
|
|
goto done;
|
|
|
|
}
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
dvdlpcmdec->mode = GST_LPCM_RAW;
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2011-09-27 18:32:46 +00:00
|
|
|
res &= gst_structure_get_int (structure, "rate", &rate);
|
|
|
|
res &= gst_structure_get_int (structure, "channels", &channels);
|
|
|
|
res &= gst_structure_get_int (structure, "width", &width);
|
2005-08-31 11:53:35 +00:00
|
|
|
res &= gst_structure_get_int (structure, "dynamic_range",
|
|
|
|
&dvdlpcmdec->dynamic_range);
|
|
|
|
res &= gst_structure_get_boolean (structure, "emphasis",
|
|
|
|
&dvdlpcmdec->emphasis);
|
|
|
|
res &= gst_structure_get_boolean (structure, "mute", &dvdlpcmdec->mute);
|
|
|
|
|
2005-09-01 11:52:34 +00:00
|
|
|
if (!res)
|
|
|
|
goto caps_parse_error;
|
|
|
|
|
2011-09-27 18:32:46 +00:00
|
|
|
switch (width) {
|
|
|
|
case 24:
|
|
|
|
case 20:
|
|
|
|
format = GST_AUDIO_FORMAT_S24BE;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
format = GST_AUDIO_FORMAT_S16BE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = GST_AUDIO_FORMAT_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-04 14:26:56 +00:00
|
|
|
|
2017-07-05 15:58:35 +00:00
|
|
|
gst_dvdlpcmdec_update_audio_formats (dvdlpcmdec, channels, rate, format,
|
|
|
|
channels - 1, channel_positions);
|
2012-01-04 14:26:56 +00:00
|
|
|
|
2011-09-27 18:32:46 +00:00
|
|
|
dvdlpcmdec->width = width;
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
res = gst_dvdlpcmdec_set_output_format (dvdlpcmdec);
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2005-09-01 11:52:34 +00:00
|
|
|
done:
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
caps_parse_error:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (dvdlpcmdec, "Couldn't get parameters; missing caps?");
|
2009-05-26 23:16:30 +00:00
|
|
|
return FALSE;
|
2005-09-01 11:52:34 +00:00
|
|
|
}
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
2005-08-31 19:37:08 +00:00
|
|
|
static void
|
|
|
|
parse_header (GstDvdLpcmDec * dec, guint32 header)
|
|
|
|
{
|
2011-09-27 18:32:46 +00:00
|
|
|
GstAudioFormat format;
|
2012-11-05 21:16:52 +00:00
|
|
|
gint rate, channels, width;
|
2011-09-27 18:32:46 +00:00
|
|
|
|
2009-10-05 10:13:51 +00:00
|
|
|
/* We don't actually use 'dynamic range', 'mute', or 'emphasis' currently,
|
2005-08-31 19:37:08 +00:00
|
|
|
* but parse them out */
|
|
|
|
dec->dynamic_range = header & 0xff;
|
|
|
|
|
|
|
|
dec->mute = (header & 0x400000) != 0;
|
|
|
|
dec->emphasis = (header & 0x800000) != 0;
|
|
|
|
|
|
|
|
/* These two bits tell us the bit depth */
|
|
|
|
switch (header & 0xC000) {
|
|
|
|
case 0x8000:
|
2011-09-27 18:32:46 +00:00
|
|
|
/* 24 bits in 3 bytes */
|
|
|
|
format = GST_AUDIO_FORMAT_S24BE;
|
2012-11-05 21:16:52 +00:00
|
|
|
width = 24;
|
2005-08-31 19:37:08 +00:00
|
|
|
break;
|
|
|
|
case 0x4000:
|
2011-09-27 18:32:46 +00:00
|
|
|
/* 20 bits in 3 bytes */
|
|
|
|
format = GST_AUDIO_FORMAT_S24BE;
|
2012-11-05 21:16:52 +00:00
|
|
|
width = 20;
|
2005-08-31 19:37:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-09-27 18:32:46 +00:00
|
|
|
format = GST_AUDIO_FORMAT_S16BE;
|
2012-11-05 21:16:52 +00:00
|
|
|
width = 16;
|
2005-08-31 19:37:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-05 21:16:52 +00:00
|
|
|
dec->width = width;
|
|
|
|
|
2007-02-28 15:52:23 +00:00
|
|
|
/* Only four sample rates supported */
|
|
|
|
switch (header & 0x3000) {
|
|
|
|
case 0x0000:
|
2011-09-27 18:32:46 +00:00
|
|
|
rate = 48000;
|
2007-02-28 15:52:23 +00:00
|
|
|
break;
|
|
|
|
case 0x1000:
|
2011-09-27 18:32:46 +00:00
|
|
|
rate = 96000;
|
2007-02-28 15:52:23 +00:00
|
|
|
break;
|
|
|
|
case 0x2000:
|
2011-09-27 18:32:46 +00:00
|
|
|
rate = 44100;
|
2007-02-28 15:52:23 +00:00
|
|
|
break;
|
|
|
|
case 0x3000:
|
2011-09-27 18:32:46 +00:00
|
|
|
rate = 32000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rate = 0;
|
2007-02-28 15:52:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-31 19:37:08 +00:00
|
|
|
|
|
|
|
/* And, of course, the number of channels (up to 8) */
|
2011-09-27 18:32:46 +00:00
|
|
|
channels = ((header >> 8) & 0x7) + 1;
|
|
|
|
|
2017-07-05 15:58:35 +00:00
|
|
|
gst_dvdlpcmdec_update_audio_formats (dec, channels, rate, format,
|
|
|
|
channels - 1, channel_positions);
|
2005-08-31 19:37:08 +00:00
|
|
|
}
|
|
|
|
|
2005-08-31 11:53:35 +00:00
|
|
|
static GstFlowReturn
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_dvdlpcmdec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
2005-08-31 11:53:35 +00:00
|
|
|
{
|
2016-04-28 14:32:53 +00:00
|
|
|
GstDvdLpcmDec *dvdlpcmdec = GST_DVDLPCMDEC (parent);
|
|
|
|
guint8 data[2];
|
2011-09-27 18:32:46 +00:00
|
|
|
gsize size;
|
2005-09-01 11:52:34 +00:00
|
|
|
guint first_access;
|
|
|
|
GstBuffer *subbuf;
|
2006-05-11 16:17:44 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2005-09-01 11:52:34 +00:00
|
|
|
gint off, len;
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
if (dvdlpcmdec->mode != GST_LPCM_DVD)
|
|
|
|
return dvdlpcmdec->base_chain (pad, parent, buf);
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
size = gst_buffer_get_size (buf);
|
2011-09-27 18:32:46 +00:00
|
|
|
if (size < 5)
|
|
|
|
goto too_small;
|
2006-02-17 10:10:40 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_buffer_extract (buf, 0, data, 2);
|
2005-09-01 11:52:34 +00:00
|
|
|
first_access = (data[0] << 8) | data[1];
|
2011-09-27 18:32:46 +00:00
|
|
|
if (first_access > size)
|
|
|
|
goto invalid_data;
|
2006-02-17 10:10:40 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
/* After first_access, we have an additional 3 bytes of header data; this
|
|
|
|
* is included within the value of first_access.
|
2005-09-02 13:37:13 +00:00
|
|
|
* So a first_access value of between 1 and 3 is just broken, we treat that
|
|
|
|
* the same as zero. first_access == 4 means we only need to create a single
|
|
|
|
* sub-buffer, greater than that we need to create two. */
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
/* skip access unit bytes */
|
|
|
|
off = 2;
|
2005-09-01 11:52:34 +00:00
|
|
|
|
2005-09-02 13:37:13 +00:00
|
|
|
if (first_access > 4) {
|
2006-05-11 14:34:10 +00:00
|
|
|
/* length of first buffer */
|
2016-04-28 14:32:53 +00:00
|
|
|
len = first_access - 1;
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2006-05-11 16:17:44 +00:00
|
|
|
GST_LOG_OBJECT (dvdlpcmdec, "Creating first sub-buffer off %d, len %d",
|
|
|
|
off, len);
|
2005-09-02 13:37:13 +00:00
|
|
|
|
|
|
|
/* see if we need a subbuffer without timestamp */
|
2011-09-27 18:32:46 +00:00
|
|
|
if (off + len > size)
|
|
|
|
goto bad_first_access;
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2011-09-27 18:32:46 +00:00
|
|
|
subbuf = gst_buffer_copy_region (buf, GST_BUFFER_COPY_ALL, off, len);
|
2016-04-28 14:32:53 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (subbuf) = GST_CLOCK_TIME_NONE;
|
|
|
|
ret = dvdlpcmdec->base_chain (pad, parent, subbuf);
|
2006-05-11 14:34:10 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto done;
|
|
|
|
|
2005-09-02 13:37:13 +00:00
|
|
|
/* then the buffer with new timestamp */
|
|
|
|
off += len;
|
|
|
|
len = size - off;
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2005-09-02 13:37:13 +00:00
|
|
|
GST_LOG_OBJECT (dvdlpcmdec, "Creating next sub-buffer off %d, len %d", off,
|
|
|
|
len);
|
2005-09-01 11:52:34 +00:00
|
|
|
|
2006-05-11 14:34:10 +00:00
|
|
|
if (len > 0) {
|
2016-04-28 14:32:53 +00:00
|
|
|
GstMemory *header, *tmp;
|
2011-09-27 18:32:46 +00:00
|
|
|
subbuf = gst_buffer_copy_region (buf, GST_BUFFER_COPY_ALL, off, len);
|
2016-04-28 14:32:53 +00:00
|
|
|
tmp = gst_buffer_peek_memory (buf, 0);
|
|
|
|
header = gst_memory_copy (tmp, 2, 3);
|
|
|
|
gst_buffer_prepend_memory (subbuf, header);
|
2006-05-11 14:34:10 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (subbuf) = GST_BUFFER_TIMESTAMP (buf);
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
ret = dvdlpcmdec->base_chain (pad, parent, subbuf);
|
2006-05-11 14:34:10 +00:00
|
|
|
}
|
2005-09-02 13:37:13 +00:00
|
|
|
} else {
|
2011-11-21 21:02:07 +00:00
|
|
|
GST_LOG_OBJECT (dvdlpcmdec,
|
|
|
|
"Creating single sub-buffer off %d, len %" G_GSIZE_FORMAT, off,
|
|
|
|
size - off);
|
2011-09-27 18:32:46 +00:00
|
|
|
subbuf = gst_buffer_copy_region (buf, GST_BUFFER_COPY_ALL, off, size - off);
|
2006-05-11 14:34:10 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (subbuf) = GST_BUFFER_TIMESTAMP (buf);
|
2016-04-28 14:32:53 +00:00
|
|
|
ret = dvdlpcmdec->base_chain (pad, parent, subbuf);
|
2005-09-02 13:37:13 +00:00
|
|
|
}
|
2005-09-01 11:52:34 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2011-09-27 18:32:46 +00:00
|
|
|
too_small:
|
|
|
|
{
|
|
|
|
/* Buffer is too small */
|
|
|
|
GST_ELEMENT_WARNING (dvdlpcmdec, STREAM, DECODE,
|
|
|
|
("Invalid data found parsing LPCM packet"),
|
|
|
|
("LPCM packet was too small. Dropping"));
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
invalid_data:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (dvdlpcmdec, STREAM, DECODE,
|
|
|
|
("Invalid data found parsing LPCM packet"),
|
|
|
|
("LPCM packet contained invalid first access. Dropping"));
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
bad_first_access:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pad, "Bad first_access parameter in buffer");
|
|
|
|
GST_ELEMENT_ERROR (dvdlpcmdec, STREAM, DECODE,
|
|
|
|
(NULL),
|
|
|
|
("first_access parameter out of range: bad buffer from demuxer"));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2005-08-31 19:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_dvdlpcmdec_parse_dvd (GstDvdLpcmDec * dvdlpcmdec, GstAdapter * adapter,
|
|
|
|
gint * offset, gint * len)
|
|
|
|
{
|
|
|
|
guint32 header;
|
|
|
|
const guint8 *data;
|
|
|
|
|
|
|
|
data = (const guint8 *) gst_adapter_map (adapter, 3);
|
|
|
|
if (!data)
|
|
|
|
goto too_small;
|
|
|
|
|
|
|
|
/* Don't keep the 'frame number' low 5 bits of the first byte */
|
|
|
|
header = ((data[0] & 0xC0) << 16) | (data[1] << 8) | data[2];
|
|
|
|
|
|
|
|
gst_adapter_unmap (adapter);
|
|
|
|
|
|
|
|
/* see if we have a new header */
|
|
|
|
if (header != dvdlpcmdec->header) {
|
|
|
|
parse_header (dvdlpcmdec, header);
|
|
|
|
|
|
|
|
if (!gst_dvdlpcmdec_set_output_format (dvdlpcmdec))
|
|
|
|
goto negotiation_failed;
|
|
|
|
|
|
|
|
dvdlpcmdec->header = header;
|
|
|
|
}
|
|
|
|
|
|
|
|
*offset = 3;
|
|
|
|
*len = gst_adapter_available (adapter) - 3;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
too_small:
|
|
|
|
{
|
|
|
|
/* Buffer is too small */
|
|
|
|
GST_ELEMENT_WARNING (dvdlpcmdec, STREAM, DECODE,
|
|
|
|
("Invalid data found parsing LPCM packet"),
|
|
|
|
("LPCM packet was too small. Dropping"));
|
|
|
|
*offset = gst_adapter_available (adapter);
|
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
|
|
|
negotiation_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (dvdlpcmdec, STREAM, FORMAT, (NULL),
|
|
|
|
("Failed to configure output format"));
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:58:35 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_dvdlpcmdec_parse_bluray (GstDvdLpcmDec * dvdlpcmdec, GstAdapter * adapter,
|
|
|
|
gint * offset, gint * len)
|
|
|
|
{
|
|
|
|
guint32 header;
|
|
|
|
const guint8 *data;
|
|
|
|
guint8 channel_indicator;
|
|
|
|
|
|
|
|
data = (const guint8 *) gst_adapter_map (adapter, 4);
|
|
|
|
if (!data)
|
|
|
|
goto too_small;
|
|
|
|
|
|
|
|
header = GST_READ_UINT32_BE (data);
|
|
|
|
|
|
|
|
gst_adapter_unmap (adapter);
|
|
|
|
|
|
|
|
/* see if we have a new header */
|
|
|
|
if (header != dvdlpcmdec->header) {
|
|
|
|
GstAudioFormat format;
|
|
|
|
gint rate, channels;
|
|
|
|
|
|
|
|
switch ((header >> 6) & 0x3) {
|
|
|
|
case 0x1:
|
|
|
|
format = GST_AUDIO_FORMAT_S16BE;
|
|
|
|
dvdlpcmdec->width = 16;
|
|
|
|
break;
|
|
|
|
case 0x2:
|
|
|
|
format = GST_AUDIO_FORMAT_S24BE;
|
|
|
|
dvdlpcmdec->width = 20;
|
|
|
|
break;
|
|
|
|
case 0x3:
|
|
|
|
format = GST_AUDIO_FORMAT_S24BE;
|
|
|
|
dvdlpcmdec->width = 24;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = GST_AUDIO_FORMAT_UNKNOWN;
|
|
|
|
dvdlpcmdec->width = 0;
|
|
|
|
GST_WARNING ("Invalid sample depth!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((header >> 8) & 0xf) {
|
|
|
|
case 0x1:
|
|
|
|
rate = 48000;
|
|
|
|
break;
|
|
|
|
case 0x4:
|
|
|
|
rate = 96000;
|
|
|
|
break;
|
|
|
|
case 0x5:
|
|
|
|
rate = 192000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rate = 0;
|
|
|
|
GST_WARNING ("Invalid audio sampling frequency!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
channel_indicator = (header >> 12) & 0xf;
|
|
|
|
switch (channel_indicator) {
|
|
|
|
case 0x1:
|
|
|
|
channels = 1;
|
|
|
|
break;
|
|
|
|
case 0x3:
|
|
|
|
channels = 2;
|
|
|
|
break;
|
|
|
|
case 0x4:
|
|
|
|
case 0x5:
|
|
|
|
channels = 3;
|
|
|
|
break;
|
|
|
|
case 0x6:
|
|
|
|
case 0x7:
|
|
|
|
channels = 4;
|
|
|
|
break;
|
|
|
|
case 0x8:
|
|
|
|
channels = 5;
|
|
|
|
break;
|
|
|
|
case 0x9:
|
|
|
|
channels = 6;
|
|
|
|
break;
|
|
|
|
case 0xa:
|
|
|
|
channels = 7;
|
|
|
|
break;
|
|
|
|
case 0xb:
|
|
|
|
channels = 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
channels = 0;
|
|
|
|
GST_WARNING ("Invalid number of audio channels!");
|
2017-07-11 11:21:41 +00:00
|
|
|
goto negotiation_failed;
|
2017-07-05 15:58:35 +00:00
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (dvdlpcmdec, "got channels %d rate %d format %s",
|
|
|
|
channels, rate, gst_audio_format_to_string (format));
|
|
|
|
|
|
|
|
gst_dvdlpcmdec_update_audio_formats (dvdlpcmdec, channels, rate, format,
|
|
|
|
channel_indicator, bluray_channel_positions);
|
|
|
|
|
|
|
|
if (!gst_dvdlpcmdec_set_output_format (dvdlpcmdec))
|
|
|
|
goto negotiation_failed;
|
|
|
|
|
|
|
|
dvdlpcmdec->header = header;
|
|
|
|
}
|
|
|
|
|
|
|
|
*offset = 4;
|
|
|
|
*len = gst_adapter_available (adapter) - 4;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
too_small:
|
|
|
|
{
|
|
|
|
/* Buffer is too small */
|
|
|
|
GST_ELEMENT_WARNING (dvdlpcmdec, STREAM, DECODE,
|
|
|
|
("Invalid data found parsing LPCM packet"),
|
|
|
|
("LPCM packet was too small. Dropping"));
|
|
|
|
*offset = gst_adapter_available (adapter);
|
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
|
|
|
negotiation_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (dvdlpcmdec, STREAM, FORMAT, (NULL),
|
|
|
|
("Failed to configure output format"));
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-28 14:42:43 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_dvdlpcmdec_parse_1394 (GstDvdLpcmDec * dvdlpcmdec, GstAdapter * adapter,
|
|
|
|
gint * offset, gint * len)
|
|
|
|
{
|
|
|
|
guint32 header;
|
|
|
|
const guint8 *data;
|
|
|
|
|
|
|
|
data = (const guint8 *) gst_adapter_map (adapter, 4);
|
|
|
|
if (!data)
|
|
|
|
goto too_small;
|
|
|
|
|
|
|
|
header = GST_READ_UINT32_BE (data);
|
|
|
|
|
|
|
|
gst_adapter_unmap (adapter);
|
|
|
|
|
|
|
|
/* see if we have a new header */
|
|
|
|
if (header != dvdlpcmdec->header) {
|
|
|
|
GstAudioFormat format;
|
|
|
|
gint rate, channels;
|
|
|
|
|
|
|
|
if (header >> 24 != 0xa0)
|
|
|
|
goto invalid_data;
|
|
|
|
|
|
|
|
switch ((header >> 6) & 0x3) {
|
|
|
|
case 0x0:
|
|
|
|
format = GST_AUDIO_FORMAT_S16BE;
|
|
|
|
dvdlpcmdec->width = 16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = GST_AUDIO_FORMAT_UNKNOWN;
|
|
|
|
dvdlpcmdec->width = 0;
|
|
|
|
GST_WARNING ("Invalid quantization word length!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((header >> 3) & 0x7) {
|
|
|
|
case 0x1:
|
|
|
|
rate = 44100;
|
|
|
|
break;
|
|
|
|
case 0x2:
|
|
|
|
rate = 48000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rate = 0;
|
|
|
|
GST_WARNING ("Invalid audio sampling frequency!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (header & 0x7) {
|
|
|
|
case 0x0: /* 2 channels dual-mono */
|
2019-09-02 13:33:15 +00:00
|
|
|
case 0x1: /* 2 channels stereo */
|
2016-04-28 14:42:43 +00:00
|
|
|
channels = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
channels = 0;
|
|
|
|
GST_WARNING ("Invalid number of audio channels!");
|
2017-07-11 11:21:41 +00:00
|
|
|
goto negotiation_failed;
|
2016-04-28 14:42:43 +00:00
|
|
|
}
|
|
|
|
|
2017-07-05 15:58:35 +00:00
|
|
|
gst_dvdlpcmdec_update_audio_formats (dvdlpcmdec, channels, rate, format,
|
|
|
|
channels - 1, channel_positions);
|
2016-04-28 14:42:43 +00:00
|
|
|
|
|
|
|
if (!gst_dvdlpcmdec_set_output_format (dvdlpcmdec))
|
|
|
|
goto negotiation_failed;
|
|
|
|
|
|
|
|
dvdlpcmdec->header = header;
|
|
|
|
}
|
|
|
|
|
|
|
|
*offset = 4;
|
|
|
|
*len = gst_adapter_available (adapter) - 4;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
too_small:
|
|
|
|
{
|
|
|
|
/* Buffer is too small */
|
|
|
|
GST_ELEMENT_WARNING (dvdlpcmdec, STREAM, DECODE,
|
|
|
|
("Invalid data found parsing LPCM packet"),
|
|
|
|
("LPCM packet was too small. Dropping"));
|
|
|
|
*offset = gst_adapter_available (adapter);
|
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
|
|
|
invalid_data:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (dvdlpcmdec, STREAM, DECODE,
|
|
|
|
("Invalid data found parsing LPCM packet"),
|
|
|
|
("LPCM packet contains invalid sub_stream_id."));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
negotiation_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (dvdlpcmdec, STREAM, FORMAT, (NULL),
|
|
|
|
("Failed to configure output format"));
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_dvdlpcmdec_parse (GstAudioDecoder * bdec, GstAdapter * adapter,
|
|
|
|
gint * offset, gint * len)
|
|
|
|
{
|
|
|
|
GstDvdLpcmDec *dvdlpcmdec = GST_DVDLPCMDEC (bdec);
|
|
|
|
|
|
|
|
switch (dvdlpcmdec->mode) {
|
|
|
|
case GST_LPCM_UNKNOWN:
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
|
|
|
|
case GST_LPCM_RAW:
|
|
|
|
*offset = 0;
|
|
|
|
*len = gst_adapter_available (adapter);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
case GST_LPCM_DVD:
|
|
|
|
return gst_dvdlpcmdec_parse_dvd (dvdlpcmdec, adapter, offset, len);
|
2016-04-28 14:42:43 +00:00
|
|
|
|
|
|
|
case GST_LPCM_1394:
|
|
|
|
return gst_dvdlpcmdec_parse_1394 (dvdlpcmdec, adapter, offset, len);
|
2017-07-05 15:58:35 +00:00
|
|
|
|
|
|
|
case GST_LPCM_BLURAY:
|
|
|
|
return gst_dvdlpcmdec_parse_bluray (dvdlpcmdec, adapter, offset, len);
|
2016-04-28 14:32:53 +00:00
|
|
|
}
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_dvdlpcmdec_handle_frame (GstAudioDecoder * bdec, GstBuffer * buf)
|
2005-08-31 19:37:08 +00:00
|
|
|
{
|
2016-04-28 14:32:53 +00:00
|
|
|
GstDvdLpcmDec *dvdlpcmdec = GST_DVDLPCMDEC (bdec);
|
2011-09-27 18:32:46 +00:00
|
|
|
gsize size;
|
2005-09-01 11:52:34 +00:00
|
|
|
GstFlowReturn ret;
|
|
|
|
guint samples = 0;
|
2011-09-27 18:32:46 +00:00
|
|
|
gint rate, channels;
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
/* no fancy draining */
|
|
|
|
if (G_UNLIKELY (!buf))
|
|
|
|
return GST_FLOW_OK;
|
2005-08-31 19:37:08 +00:00
|
|
|
|
2011-09-27 18:32:46 +00:00
|
|
|
size = gst_buffer_get_size (buf);
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2006-05-11 16:17:44 +00:00
|
|
|
GST_LOG_OBJECT (dvdlpcmdec,
|
2011-11-21 21:02:07 +00:00
|
|
|
"got buffer %p of size %" G_GSIZE_FORMAT " with ts %" GST_TIME_FORMAT,
|
2006-05-11 16:17:44 +00:00
|
|
|
buf, size, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2011-09-27 18:32:46 +00:00
|
|
|
rate = GST_AUDIO_INFO_RATE (&dvdlpcmdec->info);
|
|
|
|
channels = GST_AUDIO_INFO_CHANNELS (&dvdlpcmdec->info);
|
|
|
|
|
|
|
|
if (rate == 0)
|
2005-09-01 11:52:34 +00:00
|
|
|
goto not_negotiated;
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2009-10-05 10:13:51 +00:00
|
|
|
/* We don't currently do anything at all regarding emphasis, mute or
|
2005-08-31 11:53:35 +00:00
|
|
|
* dynamic_range - I'm not sure what they're for */
|
|
|
|
switch (dvdlpcmdec->width) {
|
|
|
|
case 16:
|
|
|
|
{
|
2009-10-05 10:13:51 +00:00
|
|
|
/* We can just pass 16-bits straight through intact, once we set
|
2005-08-31 11:53:35 +00:00
|
|
|
* appropriate things on the buffer */
|
2011-09-27 18:32:46 +00:00
|
|
|
samples = size / channels / 2;
|
2009-05-26 23:16:30 +00:00
|
|
|
if (samples < 1)
|
|
|
|
goto drop;
|
2016-04-28 14:32:53 +00:00
|
|
|
|
|
|
|
gst_buffer_ref (buf);
|
2005-09-01 11:52:34 +00:00
|
|
|
break;
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
case 20:
|
|
|
|
{
|
|
|
|
/* Allocate a new buffer and copy 20-bit width to 24-bit */
|
|
|
|
gint64 samples = size * 8 / 20;
|
|
|
|
gint64 count = size / 10;
|
|
|
|
gint64 i;
|
2012-01-25 06:24:59 +00:00
|
|
|
GstMapInfo srcmap, destmap;
|
|
|
|
guint8 *src;
|
|
|
|
guint8 *dest;
|
2005-08-31 11:53:35 +00:00
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
2009-05-26 23:16:30 +00:00
|
|
|
if (samples < 1)
|
|
|
|
goto drop;
|
|
|
|
|
2012-03-15 12:38:16 +00:00
|
|
|
outbuf = gst_buffer_new_allocate (NULL, samples * 3, NULL);
|
2011-09-27 18:32:46 +00:00
|
|
|
gst_buffer_copy_into (outbuf, buf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2005-09-01 11:52:34 +00:00
|
|
|
/* adjust samples so we can calc the new timestamp */
|
2011-09-27 18:32:46 +00:00
|
|
|
samples = samples / channels;
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2012-01-25 06:24:59 +00:00
|
|
|
gst_buffer_map (buf, &srcmap, GST_MAP_READ);
|
|
|
|
gst_buffer_map (outbuf, &destmap, GST_MAP_WRITE);
|
|
|
|
src = srcmap.data;
|
|
|
|
dest = destmap.data;
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2009-10-05 10:13:51 +00:00
|
|
|
/* Copy 20-bit LPCM format to 24-bit buffers, with 0x00 in the lowest
|
2005-08-31 11:53:35 +00:00
|
|
|
* nibble. Note that the first 2 bytes are already correct */
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
dest[0] = src[0];
|
|
|
|
dest[1] = src[1];
|
|
|
|
dest[2] = src[8] & 0xf0;
|
|
|
|
dest[3] = src[2];
|
|
|
|
dest[4] = src[3];
|
|
|
|
dest[5] = (src[8] & 0x0f) << 4;
|
|
|
|
dest[6] = src[4];
|
|
|
|
dest[7] = src[5];
|
|
|
|
dest[8] = src[9] & 0x0f;
|
|
|
|
dest[9] = src[6];
|
|
|
|
dest[10] = src[7];
|
|
|
|
dest[11] = (src[9] & 0x0f) << 4;
|
|
|
|
|
|
|
|
src += 10;
|
|
|
|
dest += 12;
|
|
|
|
}
|
2012-01-25 06:24:59 +00:00
|
|
|
gst_buffer_unmap (outbuf, &destmap);
|
|
|
|
gst_buffer_unmap (buf, &srcmap);
|
2005-09-01 11:52:34 +00:00
|
|
|
buf = outbuf;
|
|
|
|
break;
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
case 24:
|
|
|
|
{
|
|
|
|
/* Rearrange 24-bit LPCM format in-place. Note that the first 2
|
|
|
|
* and last byte are already correct */
|
2005-09-01 11:52:34 +00:00
|
|
|
guint count = size / 12;
|
|
|
|
gint i;
|
2016-04-28 14:32:53 +00:00
|
|
|
GstMapInfo srcmap, destmap;
|
|
|
|
guint8 *src, *dest;
|
|
|
|
GstBuffer *outbuf;
|
2005-09-01 11:52:34 +00:00
|
|
|
|
2011-09-27 18:32:46 +00:00
|
|
|
samples = size / channels / 3;
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2009-05-26 23:16:30 +00:00
|
|
|
if (samples < 1)
|
|
|
|
goto drop;
|
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
outbuf = gst_buffer_new_allocate (NULL, size, NULL);
|
|
|
|
gst_buffer_copy_into (outbuf, buf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
|
2005-08-31 11:53:35 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_buffer_map (buf, &srcmap, GST_MAP_READ);
|
|
|
|
gst_buffer_map (outbuf, &destmap, GST_MAP_READWRITE);
|
|
|
|
src = srcmap.data;
|
|
|
|
dest = destmap.data;
|
2011-09-27 18:32:46 +00:00
|
|
|
|
2005-08-31 11:53:35 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2016-04-28 14:32:53 +00:00
|
|
|
dest[0] = src[0];
|
|
|
|
dest[1] = src[1];
|
|
|
|
dest[11] = src[11];
|
|
|
|
dest[10] = src[7];
|
|
|
|
dest[7] = src[5];
|
|
|
|
dest[5] = src[9];
|
|
|
|
dest[9] = src[6];
|
|
|
|
dest[6] = src[4];
|
|
|
|
dest[4] = src[3];
|
|
|
|
dest[3] = src[2];
|
|
|
|
dest[2] = src[8];
|
|
|
|
dest[8] = src[10];
|
|
|
|
|
|
|
|
src += 12;
|
|
|
|
dest += 12;
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
2016-04-28 14:32:53 +00:00
|
|
|
gst_buffer_unmap (outbuf, &destmap);
|
|
|
|
gst_buffer_unmap (buf, &srcmap);
|
|
|
|
buf = outbuf;
|
2005-09-01 11:52:34 +00:00
|
|
|
break;
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
default:
|
2005-09-01 11:52:34 +00:00
|
|
|
goto invalid_width;
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
if (dvdlpcmdec->lpcm_layout) {
|
|
|
|
buf = gst_buffer_make_writable (buf);
|
2012-01-04 14:26:56 +00:00
|
|
|
gst_audio_buffer_reorder_channels (buf, dvdlpcmdec->info.finfo->format,
|
|
|
|
dvdlpcmdec->info.channels, dvdlpcmdec->lpcm_layout,
|
|
|
|
dvdlpcmdec->info.position);
|
2016-04-28 14:32:53 +00:00
|
|
|
}
|
2012-01-04 14:26:56 +00:00
|
|
|
|
2016-04-28 14:32:53 +00:00
|
|
|
ret = gst_audio_decoder_finish_frame (bdec, buf, 1);
|
2005-09-01 11:52:34 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2009-05-26 23:16:30 +00:00
|
|
|
drop:
|
|
|
|
{
|
2011-11-21 21:02:07 +00:00
|
|
|
GST_DEBUG_OBJECT (dvdlpcmdec,
|
|
|
|
"Buffer of size %" G_GSIZE_FORMAT " is too small. Dropping", size);
|
2009-05-26 23:16:30 +00:00
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
goto done;
|
|
|
|
}
|
2005-09-01 11:52:34 +00:00
|
|
|
not_negotiated:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (dvdlpcmdec, STREAM, FORMAT, (NULL),
|
|
|
|
("Buffer pushed before negotiation"));
|
|
|
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
invalid_width:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (dvdlpcmdec, STREAM, WRONG_TYPE, (NULL),
|
|
|
|
("Invalid sample width configured"));
|
|
|
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
goto done;
|
|
|
|
}
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2021-03-29 11:15:32 +00:00
|
|
|
return GST_ELEMENT_REGISTER (dvdlpcmdec, plugin);
|
2005-08-31 11:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 15:40:12 +00:00
|
|
|
dvdlpcmdec,
|
2005-08-31 11:53:35 +00:00
|
|
|
"Decode DVD LPCM frames into standard PCM",
|
2006-04-01 09:54:39 +00:00
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|