Commit ce3fd0ba authored by Wim Taymans's avatar Wim Taymans

Add audio decoding to the dv decoder.

Original commit message from CVS:
Add audio decoding to the dv decoder.
parent dbe9f84e
...@@ -208,6 +208,8 @@ gst_dvdec_class_init (GstDVDecClass *klass) ...@@ -208,6 +208,8 @@ gst_dvdec_class_init (GstDVDecClass *klass)
static void static void
gst_dvdec_init(GstDVDec *dvdec) gst_dvdec_init(GstDVDec *dvdec)
{ {
gint i;
dvdec->sinkpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (sink_temp), "sink"); dvdec->sinkpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (sink_temp), "sink");
gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad); gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad);
...@@ -222,6 +224,11 @@ gst_dvdec_init(GstDVDec *dvdec) ...@@ -222,6 +224,11 @@ gst_dvdec_init(GstDVDec *dvdec)
dvdec->decoder = dv_decoder_new (0, 0, 0); dvdec->decoder = dv_decoder_new (0, 0, 0);
dvdec->decoder->quality = DV_QUALITY_BEST; dvdec->decoder->quality = DV_QUALITY_BEST;
dvdec->pool = NULL; dvdec->pool = NULL;
dvdec->length = 0;
for (i = 0; i <4; i++) {
dvdec->audio_buffers[i] = (gint16 *)g_malloc (DV_AUDIO_MAX_SAMPLES * sizeof (gint16));
}
} }
static gboolean static gboolean
...@@ -272,6 +279,8 @@ gst_dvdec_loop (GstElement *element) ...@@ -272,6 +279,8 @@ gst_dvdec_loop (GstElement *element)
gboolean PAL; gboolean PAL;
gint height; gint height;
guint32 length, got_bytes; guint32 length, got_bytes;
gint16 *a_ptr;
gint i, j;
dvdec = GST_DVDEC (element); dvdec = GST_DVDEC (element);
...@@ -288,6 +297,11 @@ gst_dvdec_loop (GstElement *element) ...@@ -288,6 +297,11 @@ gst_dvdec_loop (GstElement *element)
height = (PAL ? PAL_HEIGHT : NTSC_HEIGHT); height = (PAL ? PAL_HEIGHT : NTSC_HEIGHT);
length = (PAL ? PAL_BUFFER : NTSC_BUFFER); length = (PAL ? PAL_BUFFER : NTSC_BUFFER);
if (length != dvdec->length) {
dvdec->length = length;
gst_bytestream_size_hint (dvdec->bs, length);
}
/* then read the read data */ /* then read the read data */
got_bytes = gst_bytestream_read (dvdec->bs, &buf, length); got_bytes = gst_bytestream_read (dvdec->bs, &buf, length);
if (got_bytes < length) { if (got_bytes < length) {
...@@ -342,6 +356,39 @@ gst_dvdec_loop (GstElement *element) ...@@ -342,6 +356,39 @@ gst_dvdec_loop (GstElement *element)
return; return;
} }
} }
/* if we did not negotiate yet, do it now */
if (!GST_PAD_CAPS (dvdec->audiosrcpad)) {
gst_pad_try_set_caps (dvdec->audiosrcpad,
GST_CAPS_NEW (
"dvdec_audio_caps",
"audio/raw",
"format", GST_PROPS_STRING ("int"),
"rate", GST_PROPS_INT (dvdec->decoder->audio->frequency),
"law", GST_PROPS_INT (0),
"depth", GST_PROPS_INT (16),
"width", GST_PROPS_INT (16),
"signed", GST_PROPS_BOOLEAN (TRUE),
"channels", GST_PROPS_INT (dvdec->decoder->audio->num_channels),
"endianness", GST_PROPS_INT (G_LITTLE_ENDIAN)
));
}
dv_decode_full_audio (dvdec->decoder, GST_BUFFER_DATA (buf), dvdec->audio_buffers);
outbuf = gst_buffer_new ();
GST_BUFFER_SIZE (outbuf) = dvdec->decoder->audio->samples_this_frame * sizeof (gint16) * dvdec->decoder->audio->num_channels;
GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
a_ptr = (gint16 *) GST_BUFFER_DATA (outbuf);
for (i = 0; i < dvdec->decoder->audio->samples_this_frame; i++) {
for (j = 0; j < dvdec->decoder->audio->num_channels; j++) {
*(a_ptr++) = dvdec->audio_buffers[j][i];
}
}
gst_pad_push (dvdec->audiosrcpad, outbuf);
/* try to grab a pool */ /* try to grab a pool */
if (!dvdec->pool) { if (!dvdec->pool) {
dvdec->pool = gst_pad_get_bufferpool (dvdec->videosrcpad); dvdec->pool = gst_pad_get_bufferpool (dvdec->videosrcpad);
...@@ -359,6 +406,7 @@ gst_dvdec_loop (GstElement *element) ...@@ -359,6 +406,7 @@ gst_dvdec_loop (GstElement *element)
GST_BUFFER_SIZE (outbuf) = (720 * height) * dvdec->bpp; GST_BUFFER_SIZE (outbuf) = (720 * height) * dvdec->bpp;
GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf)); GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
} }
outframe = GST_BUFFER_DATA (outbuf); outframe = GST_BUFFER_DATA (outbuf);
......
...@@ -41,16 +41,21 @@ typedef struct _GstDVDec GstDVDec; ...@@ -41,16 +41,21 @@ typedef struct _GstDVDec GstDVDec;
* an Element or even an Object. * an Element or even an Object.
*/ */
struct _GstDVDec { struct _GstDVDec {
GstElement element; GstElement element;
/* We need to keep track of our pads, so we do so here. */ /* We need to keep track of our pads, so we do so here. */
GstPad *sinkpad,*videosrcpad,*audiosrcpad; GstPad *sinkpad,
*videosrcpad,
*audiosrcpad;
dv_decoder_t *decoder; dv_decoder_t *decoder;
GstByteStream *bs; GstByteStream *bs;
GstBufferPool *pool; GstBufferPool *pool;
dv_color_space_t space; dv_color_space_t space;
gint bpp; gint bpp;
gint length;
gint16 *audio_buffers[4];
}; };
/* The other half of the object is its class. The class also derives from /* The other half of the object is its class. The class also derives from
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment