law: use GstAudioInfo

Use GstAudioInfo to generate output caps.
This commit is contained in:
Wim Taymans 2012-03-07 14:51:09 +01:00
parent 688e820573
commit b55d5e23ee
4 changed files with 36 additions and 30 deletions

View file

@ -26,8 +26,6 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/audio/audio.h>
#include "alaw-decode.h" #include "alaw-decode.h"
extern GstStaticPadTemplate alaw_dec_src_factory; extern GstStaticPadTemplate alaw_dec_src_factory;
@ -123,6 +121,7 @@ gst_alaw_dec_setcaps (GstALawDec * alawdec, GstCaps * caps)
int rate, channels; int rate, channels;
gboolean ret; gboolean ret;
GstCaps *outcaps; GstCaps *outcaps;
GstAudioInfo info;
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
@ -131,17 +130,16 @@ gst_alaw_dec_setcaps (GstALawDec * alawdec, GstCaps * caps)
if (!ret) if (!ret)
return FALSE; return FALSE;
outcaps = gst_caps_new_simple ("audio/x-raw", gst_audio_info_init (&info);
"format", G_TYPE_STRING, GST_AUDIO_NE (S16), gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_S16, rate, channels, NULL);
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
outcaps = gst_audio_info_to_caps (&info);
ret = gst_pad_set_caps (alawdec->srcpad, outcaps); ret = gst_pad_set_caps (alawdec->srcpad, outcaps);
gst_caps_unref (outcaps); gst_caps_unref (outcaps);
if (ret) { if (ret) {
GST_DEBUG_OBJECT (alawdec, "rate=%d, channels=%d", rate, channels); GST_DEBUG_OBJECT (alawdec, "rate=%d, channels=%d", rate, channels);
alawdec->rate = rate; alawdec->info = info;
alawdec->channels = channels;
} }
return ret; return ret;
} }
@ -310,14 +308,14 @@ gst_alaw_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
GstMapInfo inmap, outmap; GstMapInfo inmap, outmap;
gint16 *linear_data; gint16 *linear_data;
guint8 *alaw_data; guint8 *alaw_data;
gsize alaw_size; gsize alaw_size, linear_size;
GstBuffer *outbuf; GstBuffer *outbuf;
gint i; gint i;
GstFlowReturn ret; GstFlowReturn ret;
alawdec = GST_ALAW_DEC (parent); alawdec = GST_ALAW_DEC (parent);
if (G_UNLIKELY (alawdec->rate == 0)) if (G_UNLIKELY (!GST_AUDIO_INFO_IS_VALID (&alawdec->info)))
goto not_negotiated; goto not_negotiated;
GST_LOG_OBJECT (alawdec, "buffer with ts=%" GST_TIME_FORMAT, GST_LOG_OBJECT (alawdec, "buffer with ts=%" GST_TIME_FORMAT,
@ -327,7 +325,9 @@ gst_alaw_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
alaw_data = inmap.data; alaw_data = inmap.data;
alaw_size = inmap.size; alaw_size = inmap.size;
outbuf = gst_buffer_new_allocate (NULL, alaw_size * 2, 0); linear_size = alaw_size * 2;
outbuf = gst_buffer_new_allocate (NULL, linear_size, 0);
gst_buffer_map (outbuf, &outmap, GST_MAP_WRITE); gst_buffer_map (outbuf, &outmap, GST_MAP_WRITE);
linear_data = (gint16 *) outmap.data; linear_data = (gint16 *) outmap.data;
@ -337,7 +337,13 @@ gst_alaw_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer); GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer); if (GST_BUFFER_DURATION_IS_VALID (buffer)) {
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer);
} else {
GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale_int (GST_SECOND,
linear_size, GST_AUDIO_INFO_RATE (&alawdec->info) *
GST_AUDIO_INFO_BPF (&alawdec->info));
}
for (i = 0; i < alaw_size; i++) { for (i = 0; i < alaw_size; i++) {
linear_data[i] = alaw_to_s16 (alaw_data[i]); linear_data[i] = alaw_to_s16 (alaw_data[i]);
@ -376,8 +382,7 @@ gst_alaw_dec_change_state (GstElement * element, GstStateChange transition)
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY: case GST_STATE_CHANGE_PAUSED_TO_READY:
dec->rate = 0; gst_audio_info_init (&dec->info);
dec->channels = 0;
break; break;
default: default:
break; break;

View file

@ -21,6 +21,7 @@
#define __GST_ALAW_DECODE_H__ #define __GST_ALAW_DECODE_H__
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/audio.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -42,8 +43,7 @@ struct _GstALawDec {
GstElement element; GstElement element;
GstPad *sinkpad,*srcpad; GstPad *sinkpad,*srcpad;
gint rate; GstAudioInfo info;
gint channels;
}; };
struct _GstALawDecClass { struct _GstALawDecClass {

View file

@ -26,7 +26,6 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/audio.h>
#include "mulaw-decode.h" #include "mulaw-decode.h"
#include "mulaw-conversion.h" #include "mulaw-conversion.h"
@ -64,6 +63,7 @@ mulawdec_setcaps (GstMuLawDec * mulawdec, GstCaps * caps)
int rate, channels; int rate, channels;
gboolean ret; gboolean ret;
GstCaps *outcaps; GstCaps *outcaps;
GstAudioInfo info;
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
ret = gst_structure_get_int (structure, "rate", &rate); ret = gst_structure_get_int (structure, "rate", &rate);
@ -71,16 +71,16 @@ mulawdec_setcaps (GstMuLawDec * mulawdec, GstCaps * caps)
if (!ret) if (!ret)
return FALSE; return FALSE;
outcaps = gst_caps_new_simple ("audio/x-raw", gst_audio_info_init (&info);
"format", G_TYPE_STRING, GST_AUDIO_NE (S16), gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_S16, rate, channels, NULL);
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, channels, NULL);
outcaps = gst_audio_info_to_caps (&info);
ret = gst_pad_set_caps (mulawdec->srcpad, outcaps); ret = gst_pad_set_caps (mulawdec->srcpad, outcaps);
gst_caps_unref (outcaps); gst_caps_unref (outcaps);
if (ret) { if (ret) {
GST_DEBUG_OBJECT (mulawdec, "rate=%d, channels=%d", rate, channels); GST_DEBUG_OBJECT (mulawdec, "rate=%d, channels=%d", rate, channels);
mulawdec->rate = rate; mulawdec->info = info;
mulawdec->channels = channels;
} }
return ret; return ret;
} }
@ -249,7 +249,7 @@ gst_mulawdec_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
mulawdec = GST_MULAWDEC (parent); mulawdec = GST_MULAWDEC (parent);
if (G_UNLIKELY (mulawdec->rate == 0)) if (G_UNLIKELY (!GST_AUDIO_INFO_IS_VALID (&mulawdec->info)))
goto not_negotiated; goto not_negotiated;
gst_buffer_map (buffer, &inmap, GST_MAP_READ); gst_buffer_map (buffer, &inmap, GST_MAP_READ);
@ -267,11 +267,13 @@ gst_mulawdec_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT); GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer); GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer);
if (GST_BUFFER_DURATION (outbuf) == GST_CLOCK_TIME_NONE) if (GST_BUFFER_DURATION_IS_VALID (buffer)) {
GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale_int (GST_SECOND,
linear_size, 2 * mulawdec->rate * mulawdec->channels);
else
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer); GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buffer);
} else {
GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale_int (GST_SECOND,
linear_size, GST_AUDIO_INFO_RATE (&mulawdec->info) *
GST_AUDIO_INFO_BPF (&mulawdec->info));
}
mulaw_decode (mulaw_data, linear_data, mulaw_size); mulaw_decode (mulaw_data, linear_data, mulaw_size);
@ -309,8 +311,7 @@ gst_mulawdec_change_state (GstElement * element, GstStateChange transition)
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY: case GST_STATE_CHANGE_PAUSED_TO_READY:
dec->rate = 0; gst_audio_info_init (&dec->info);
dec->channels = 0;
break; break;
default: default:
break; break;

View file

@ -21,6 +21,7 @@
#define __GST_MULAWDECODE_H__ #define __GST_MULAWDECODE_H__
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/audio.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -43,8 +44,7 @@ struct _GstMuLawDec {
GstPad *sinkpad,*srcpad; GstPad *sinkpad,*srcpad;
gint rate; GstAudioInfo info;
gint channels;
}; };
struct _GstMuLawDecClass { struct _GstMuLawDecClass {