audiovis: port to 0.11 some more
This commit is contained in:
parent
bc0dd274ee
commit
667c84b59c
@ -498,8 +498,7 @@ gst_base_audio_visualizer_init (GstBaseAudioVisualizer * scope,
|
|||||||
scope->frame_duration = GST_CLOCK_TIME_NONE;
|
scope->frame_duration = GST_CLOCK_TIME_NONE;
|
||||||
|
|
||||||
/* reset the initial audio state */
|
/* reset the initial audio state */
|
||||||
scope->rate = GST_AUDIO_DEF_RATE;
|
gst_audio_info_init (&scope->ainfo);
|
||||||
scope->channels = 2;
|
|
||||||
|
|
||||||
g_mutex_init (&scope->config_lock);
|
g_mutex_init (&scope->config_lock);
|
||||||
}
|
}
|
||||||
@ -583,49 +582,24 @@ static gboolean
|
|||||||
gst_base_audio_visualizer_sink_setcaps (GstBaseAudioVisualizer * scope,
|
gst_base_audio_visualizer_sink_setcaps (GstBaseAudioVisualizer * scope,
|
||||||
GstCaps * caps)
|
GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstStructure *structure;
|
GstAudioInfo info;
|
||||||
gint channels;
|
|
||||||
gint rate;
|
|
||||||
gboolean res = TRUE;
|
gboolean res = TRUE;
|
||||||
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
if (!gst_audio_info_from_caps (&info, caps))
|
||||||
|
goto wrong_caps;
|
||||||
|
|
||||||
if (!gst_structure_get_int (structure, "channels", &channels) ||
|
scope->ainfo = info;
|
||||||
!gst_structure_get_int (structure, "rate", &rate))
|
|
||||||
goto missing_caps_details;
|
|
||||||
|
|
||||||
if (channels != 2)
|
|
||||||
goto wrong_channels;
|
|
||||||
|
|
||||||
if (rate <= 0)
|
|
||||||
goto wrong_rate;
|
|
||||||
|
|
||||||
scope->channels = channels;
|
|
||||||
scope->rate = rate;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (scope, "audio: channels %d, rate %d",
|
GST_DEBUG_OBJECT (scope, "audio: channels %d, rate %d",
|
||||||
scope->channels, scope->rate);
|
GST_AUDIO_INFO_CHANNELS (&info), GST_AUDIO_INFO_RATE (&info));
|
||||||
|
|
||||||
done:
|
done:
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
/* Errors */
|
/* Errors */
|
||||||
missing_caps_details:
|
wrong_caps:
|
||||||
{
|
{
|
||||||
GST_WARNING_OBJECT (scope, "missing channels or rate in the caps");
|
GST_WARNING_OBJECT (scope, "could not parse caps");
|
||||||
res = FALSE;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
wrong_channels:
|
|
||||||
{
|
|
||||||
GST_WARNING_OBJECT (scope, "number of channels must be 2, but is %d",
|
|
||||||
channels);
|
|
||||||
res = FALSE;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
wrong_rate:
|
|
||||||
{
|
|
||||||
GST_WARNING_OBJECT (scope, "sample rate must be >0, but is %d", rate);
|
|
||||||
res = FALSE;
|
res = FALSE;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -652,7 +626,7 @@ gst_base_audio_visualizer_src_setcaps (GstBaseAudioVisualizer * scope,
|
|||||||
|
|
||||||
scope->frame_duration = gst_util_uint64_scale_int (GST_SECOND,
|
scope->frame_duration = gst_util_uint64_scale_int (GST_SECOND,
|
||||||
scope->fps_d, scope->fps_n);
|
scope->fps_d, scope->fps_n);
|
||||||
scope->spf = gst_util_uint64_scale_int (scope->rate,
|
scope->spf = gst_util_uint64_scale_int (GST_AUDIO_INFO_RATE (&scope->ainfo),
|
||||||
scope->fps_d, scope->fps_n);
|
scope->fps_d, scope->fps_n);
|
||||||
scope->req_spf = scope->spf;
|
scope->req_spf = scope->spf;
|
||||||
|
|
||||||
@ -795,6 +769,7 @@ gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
|
|||||||
gpointer adata;
|
gpointer adata;
|
||||||
gboolean (*render) (GstBaseAudioVisualizer * scope, GstBuffer * audio,
|
gboolean (*render) (GstBaseAudioVisualizer * scope, GstBuffer * audio,
|
||||||
GstBuffer * video);
|
GstBuffer * video);
|
||||||
|
gint bps, channels, rate;
|
||||||
|
|
||||||
scope = GST_BASE_AUDIO_VISUALIZER (parent);
|
scope = GST_BASE_AUDIO_VISUALIZER (parent);
|
||||||
klass = GST_BASE_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope));
|
klass = GST_BASE_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope));
|
||||||
@ -808,23 +783,27 @@ gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
|
|||||||
gst_adapter_clear (scope->adapter);
|
gst_adapter_clear (scope->adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scope->bps == 0) {
|
|
||||||
ret = GST_FLOW_NOT_NEGOTIATED;
|
|
||||||
goto beach;
|
|
||||||
}
|
|
||||||
/* Make sure have an output format */
|
/* Make sure have an output format */
|
||||||
ret = gst_base_audio_visualizer_ensure_negotiated (scope);
|
ret = gst_base_audio_visualizer_ensure_negotiated (scope);
|
||||||
if (ret != GST_FLOW_OK) {
|
if (ret != GST_FLOW_OK) {
|
||||||
gst_buffer_unref (buffer);
|
gst_buffer_unref (buffer);
|
||||||
goto beach;
|
goto beach;
|
||||||
}
|
}
|
||||||
|
channels = GST_AUDIO_INFO_CHANNELS (&scope->ainfo);
|
||||||
|
rate = GST_AUDIO_INFO_RATE (&scope->ainfo);
|
||||||
|
bps = GST_AUDIO_INFO_BPS (&scope->ainfo);
|
||||||
|
|
||||||
|
if (bps == 0) {
|
||||||
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
||||||
|
goto beach;
|
||||||
|
}
|
||||||
|
|
||||||
gst_adapter_push (scope->adapter, buffer);
|
gst_adapter_push (scope->adapter, buffer);
|
||||||
|
|
||||||
g_mutex_lock (&scope->config_lock);
|
g_mutex_lock (&scope->config_lock);
|
||||||
|
|
||||||
/* this is what we want */
|
/* this is what we want */
|
||||||
sbpf = scope->req_spf * scope->channels * sizeof (gint16);
|
sbpf = scope->req_spf * channels * sizeof (gint16);
|
||||||
|
|
||||||
inbuf = scope->inbuf;
|
inbuf = scope->inbuf;
|
||||||
/* FIXME: the timestamp in the adapter would be different */
|
/* FIXME: the timestamp in the adapter would be different */
|
||||||
@ -841,8 +820,8 @@ gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
|
|||||||
ts = gst_adapter_prev_timestamp (scope->adapter, &dist);
|
ts = gst_adapter_prev_timestamp (scope->adapter, &dist);
|
||||||
if (GST_CLOCK_TIME_IS_VALID (ts)) {
|
if (GST_CLOCK_TIME_IS_VALID (ts)) {
|
||||||
/* convert bytes to time */
|
/* convert bytes to time */
|
||||||
dist /= scope->bps;
|
dist /= bps;
|
||||||
ts += gst_util_uint64_scale_int (dist, GST_SECOND, scope->rate);
|
ts += gst_util_uint64_scale_int (dist, GST_SECOND, rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GST_CLOCK_TIME_IS_VALID (ts)) {
|
if (GST_CLOCK_TIME_IS_VALID (ts)) {
|
||||||
@ -870,7 +849,7 @@ gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
|
|||||||
ret = gst_buffer_pool_acquire_buffer (scope->pool, &outbuf, NULL);
|
ret = gst_buffer_pool_acquire_buffer (scope->pool, &outbuf, NULL);
|
||||||
g_mutex_lock (&scope->config_lock);
|
g_mutex_lock (&scope->config_lock);
|
||||||
/* recheck as the value could have changed */
|
/* recheck as the value could have changed */
|
||||||
sbpf = scope->req_spf * scope->channels * sizeof (gint16);
|
sbpf = scope->req_spf * channels * sizeof (gint16);
|
||||||
|
|
||||||
/* no buffer allocated, we don't care why. */
|
/* no buffer allocated, we don't care why. */
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
@ -919,7 +898,7 @@ gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
|
|||||||
|
|
||||||
skip:
|
skip:
|
||||||
/* recheck as the value could have changed */
|
/* recheck as the value could have changed */
|
||||||
sbpf = scope->req_spf * scope->channels * sizeof (gint16);
|
sbpf = scope->req_spf * channels * sizeof (gint16);
|
||||||
GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf);
|
GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf);
|
||||||
/* we want to take less or more, depending on spf : req_spf */
|
/* we want to take less or more, depending on spf : req_spf */
|
||||||
if (avail - sbpf >= sbpf) {
|
if (avail - sbpf >= sbpf) {
|
||||||
@ -1044,8 +1023,9 @@ gst_base_audio_visualizer_src_query (GstPad * pad, GstObject * parent,
|
|||||||
gboolean us_live;
|
gboolean us_live;
|
||||||
GstClockTime our_latency;
|
GstClockTime our_latency;
|
||||||
guint max_samples;
|
guint max_samples;
|
||||||
|
gint rate = GST_AUDIO_INFO_RATE (&scope->ainfo);
|
||||||
|
|
||||||
if (scope->rate == 0)
|
if (rate == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((res = gst_pad_peer_query (scope->sinkpad, query))) {
|
if ((res = gst_pad_peer_query (scope->sinkpad, query))) {
|
||||||
@ -1057,8 +1037,7 @@ gst_base_audio_visualizer_src_query (GstPad * pad, GstObject * parent,
|
|||||||
|
|
||||||
/* the max samples we must buffer buffer */
|
/* the max samples we must buffer buffer */
|
||||||
max_samples = MAX (scope->req_spf, scope->spf);
|
max_samples = MAX (scope->req_spf, scope->spf);
|
||||||
our_latency =
|
our_latency = gst_util_uint64_scale_int (max_samples, GST_SECOND, rate);
|
||||||
gst_util_uint64_scale_int (max_samples, GST_SECOND, scope->rate);
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (scope, "Our latency: %" GST_TIME_FORMAT,
|
GST_DEBUG_OBJECT (scope, "Our latency: %" GST_TIME_FORMAT,
|
||||||
GST_TIME_ARGS (our_latency));
|
GST_TIME_ARGS (our_latency));
|
||||||
|
@ -83,9 +83,6 @@ struct _GstBaseAudioVisualizer
|
|||||||
GstBaseAudioVisualizerShaderFunc shader;
|
GstBaseAudioVisualizerShaderFunc shader;
|
||||||
guint32 shade_amount;
|
guint32 shade_amount;
|
||||||
|
|
||||||
guint64 frame_duration;
|
|
||||||
guint bpf; /* bytes per frame */
|
|
||||||
guint bps; /* bytes per sample */
|
|
||||||
guint spf; /* samples per video frame */
|
guint spf; /* samples per video frame */
|
||||||
guint req_spf; /* min samples per frame wanted by the subclass */
|
guint req_spf; /* min samples per frame wanted by the subclass */
|
||||||
|
|
||||||
@ -94,12 +91,12 @@ struct _GstBaseAudioVisualizer
|
|||||||
gint fps_n, fps_d;
|
gint fps_n, fps_d;
|
||||||
gint width;
|
gint width;
|
||||||
gint height;
|
gint height;
|
||||||
|
guint64 frame_duration;
|
||||||
|
guint bpf; /* bytes per frame */
|
||||||
|
|
||||||
/* audio state */
|
/* audio state */
|
||||||
gint sample_rate;
|
GstAudioInfo ainfo;
|
||||||
gint channels;
|
|
||||||
gint rate;
|
|
||||||
|
|
||||||
/* configuration mutex */
|
/* configuration mutex */
|
||||||
GMutex config_lock;
|
GMutex config_lock;
|
||||||
|
|
||||||
|
@ -435,7 +435,8 @@ gst_space_scope_render (GstBaseAudioVisualizer * base, GstBuffer * audio,
|
|||||||
gst_buffer_map (audio, &amap, GST_MAP_READ);
|
gst_buffer_map (audio, &amap, GST_MAP_READ);
|
||||||
gst_buffer_map (video, &vmap, GST_MAP_WRITE);
|
gst_buffer_map (video, &vmap, GST_MAP_WRITE);
|
||||||
|
|
||||||
num_samples = amap.size / (base->channels * sizeof (gint16));
|
num_samples =
|
||||||
|
amap.size / (GST_AUDIO_INFO_CHANNELS (&base->ainfo) * sizeof (gint16));
|
||||||
scope->process (base, (guint32 *) vmap.data, (gint16 *) amap.data,
|
scope->process (base, (guint32 *) vmap.data, (gint16 *) amap.data,
|
||||||
num_samples);
|
num_samples);
|
||||||
gst_buffer_unmap (video, &vmap);
|
gst_buffer_unmap (video, &vmap);
|
||||||
|
@ -175,15 +175,18 @@ gst_spectra_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
|
|||||||
guint w = bscope->width;
|
guint w = bscope->width;
|
||||||
GstMapInfo amap, vmap;
|
GstMapInfo amap, vmap;
|
||||||
guint32 *vdata;
|
guint32 *vdata;
|
||||||
|
gint channels;
|
||||||
|
|
||||||
gst_buffer_map (audio, &amap, GST_MAP_READ);
|
gst_buffer_map (audio, &amap, GST_MAP_READ);
|
||||||
gst_buffer_map (video, &vmap, GST_MAP_WRITE);
|
gst_buffer_map (video, &vmap, GST_MAP_WRITE);
|
||||||
vdata = (guint32 *) vmap.data;
|
vdata = (guint32 *) vmap.data;
|
||||||
|
|
||||||
|
channels = GST_AUDIO_INFO_CHANNELS (&bscope->ainfo);
|
||||||
|
|
||||||
mono_adata = (gint16 *) g_memdup (amap.data, amap.size);
|
mono_adata = (gint16 *) g_memdup (amap.data, amap.size);
|
||||||
|
|
||||||
if (bscope->channels > 1) {
|
if (channels > 1) {
|
||||||
guint ch = bscope->channels;
|
guint ch = channels;
|
||||||
guint num_samples = amap.size / (ch * sizeof (gint16));
|
guint num_samples = amap.size / (ch * sizeof (gint16));
|
||||||
guint i, c, v, s = 0;
|
guint i, c, v, s = 0;
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ gst_synae_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
|
|||||||
guint32 *colors = scope->colors, c;
|
guint32 *colors = scope->colors, c;
|
||||||
guint *shade = scope->shade;
|
guint *shade = scope->shade;
|
||||||
//guint w2 = w /2;
|
//guint w2 = w /2;
|
||||||
guint ch = bscope->channels;
|
guint ch = GST_AUDIO_INFO_CHANNELS (&bscope->ainfo);
|
||||||
guint num_samples;
|
guint num_samples;
|
||||||
gint i, j, b;
|
gint i, j, b;
|
||||||
gint br, br1, br2;
|
gint br, br1, br2;
|
||||||
|
@ -181,7 +181,7 @@ gst_wave_scope_setup (GstBaseAudioVisualizer * bscope)
|
|||||||
if (scope->flt)
|
if (scope->flt)
|
||||||
g_free (scope->flt);
|
g_free (scope->flt);
|
||||||
|
|
||||||
scope->flt = g_new0 (gdouble, 6 * bscope->channels);
|
scope->flt = g_new0 (gdouble, 6 * GST_AUDIO_INFO_CHANNELS (&bscope->ainfo));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ static void
|
|||||||
render_dots (GstBaseAudioVisualizer * base, guint32 * vdata, gint16 * adata,
|
render_dots (GstBaseAudioVisualizer * base, guint32 * vdata, gint16 * adata,
|
||||||
guint num_samples)
|
guint num_samples)
|
||||||
{
|
{
|
||||||
gint channels = base->channels;
|
gint channels = GST_AUDIO_INFO_CHANNELS (&base->ainfo);
|
||||||
guint i, c, s, x, y, oy;
|
guint i, c, s, x, y, oy;
|
||||||
gfloat dx, dy;
|
gfloat dx, dy;
|
||||||
guint w = base->width;
|
guint w = base->width;
|
||||||
@ -263,7 +263,7 @@ static void
|
|||||||
render_lines (GstBaseAudioVisualizer * base, guint32 * vdata, gint16 * adata,
|
render_lines (GstBaseAudioVisualizer * base, guint32 * vdata, gint16 * adata,
|
||||||
guint num_samples)
|
guint num_samples)
|
||||||
{
|
{
|
||||||
gint channels = base->channels;
|
gint channels = GST_AUDIO_INFO_CHANNELS (&base->ainfo);
|
||||||
guint i, c, s, x, y, oy;
|
guint i, c, s, x, y, oy;
|
||||||
gfloat dx, dy;
|
gfloat dx, dy;
|
||||||
guint w = base->width;
|
guint w = base->width;
|
||||||
@ -308,7 +308,7 @@ render_color_dots (GstBaseAudioVisualizer * base, guint32 * vdata,
|
|||||||
gint16 * adata, guint num_samples)
|
gint16 * adata, guint num_samples)
|
||||||
{
|
{
|
||||||
GstWaveScope *scope = (GstWaveScope *) base;
|
GstWaveScope *scope = (GstWaveScope *) base;
|
||||||
gint channels = base->channels;
|
gint channels = GST_AUDIO_INFO_CHANNELS (&base->ainfo);
|
||||||
guint i, c, s, x, y, oy;
|
guint i, c, s, x, y, oy;
|
||||||
gfloat dx, dy;
|
gfloat dx, dy;
|
||||||
guint w = base->width;
|
guint w = base->width;
|
||||||
@ -348,7 +348,7 @@ render_color_lines (GstBaseAudioVisualizer * base, guint32 * vdata,
|
|||||||
gint16 * adata, guint num_samples)
|
gint16 * adata, guint num_samples)
|
||||||
{
|
{
|
||||||
GstWaveScope *scope = (GstWaveScope *) base;
|
GstWaveScope *scope = (GstWaveScope *) base;
|
||||||
gint channels = base->channels;
|
gint channels = GST_AUDIO_INFO_CHANNELS (&base->ainfo);
|
||||||
guint i, c, s, x, y, oy;
|
guint i, c, s, x, y, oy;
|
||||||
gfloat dx, dy;
|
gfloat dx, dy;
|
||||||
guint w = base->width;
|
guint w = base->width;
|
||||||
@ -409,11 +409,12 @@ gst_wave_scope_render (GstBaseAudioVisualizer * base, GstBuffer * audio,
|
|||||||
GstWaveScope *scope = GST_WAVE_SCOPE (base);
|
GstWaveScope *scope = GST_WAVE_SCOPE (base);
|
||||||
GstMapInfo amap, vmap;
|
GstMapInfo amap, vmap;
|
||||||
guint num_samples;
|
guint num_samples;
|
||||||
|
gint channels = GST_AUDIO_INFO_CHANNELS (&base->ainfo);
|
||||||
|
|
||||||
gst_buffer_map (audio, &amap, GST_MAP_READ);
|
gst_buffer_map (audio, &amap, GST_MAP_READ);
|
||||||
gst_buffer_map (video, &vmap, GST_MAP_WRITE);
|
gst_buffer_map (video, &vmap, GST_MAP_WRITE);
|
||||||
|
|
||||||
num_samples = amap.size / (base->channels * sizeof (gint16));
|
num_samples = amap.size / (channels * sizeof (gint16));
|
||||||
scope->process (base, (guint32 *) vmap.data, (gint16 *) amap.data,
|
scope->process (base, (guint32 *) vmap.data, (gint16 *) amap.data,
|
||||||
num_samples);
|
num_samples);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user