|
Packit |
971217 |
/* GStreamer interactive audioresample test
|
|
Packit |
971217 |
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
971217 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
971217 |
* License as published by the Free Software Foundation; either
|
|
Packit |
971217 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
971217 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
971217 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
971217 |
* Library General Public License for more details.
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
971217 |
* License along with this library; if not, write to the
|
|
Packit |
971217 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
971217 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
971217 |
*/
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
971217 |
#include "config.h"
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include <stdlib.h>
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include <gst/gst.h>
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static GstElement *
|
|
Packit |
971217 |
make_pipeline (gint type)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstElement *result;
|
|
Packit |
971217 |
gchar *pstr;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
switch (type) {
|
|
Packit |
971217 |
case 0:
|
|
Packit |
971217 |
pstr = g_strdup_printf ("audiotestsrc ! audio/x-raw,rate=44100 ! "
|
|
Packit |
971217 |
" audioresample ! capsfilter name=filter ! capssetter caps="
|
|
Packit |
971217 |
"audio/x-raw,rate=44100 ! wavenc ! filesink location=test.wav");
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
default:
|
|
Packit |
971217 |
return NULL;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
result = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL);
|
|
Packit |
971217 |
g_print ("created test %d: \"%s\"\n", type, pstr);
|
|
Packit |
971217 |
g_free (pstr);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return result;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
typedef struct
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
gint rate;
|
|
Packit |
971217 |
GstElement *filter;
|
|
Packit |
971217 |
} Data;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static GstPadProbeReturn
|
|
Packit |
971217 |
have_probe (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
Data *data = user_data;
|
|
Packit |
971217 |
gchar *capsstr;
|
|
Packit |
971217 |
GstCaps *caps;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
g_print ("resample to %d \r", data->rate);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
capsstr = g_strdup_printf ("audio/x-raw, rate=(int)%d", data->rate);
|
|
Packit |
971217 |
caps = gst_caps_from_string (capsstr);
|
|
Packit |
971217 |
g_free (capsstr);
|
|
Packit |
971217 |
g_object_set (data->filter, "caps", caps, NULL);
|
|
Packit |
971217 |
gst_caps_unref (caps);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
data->rate += 100;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (data->rate > 128000)
|
|
Packit |
971217 |
gst_element_post_message (data->filter,
|
|
Packit |
971217 |
gst_message_new_application (GST_OBJECT (data->filter),
|
|
Packit |
971217 |
gst_structure_new_empty ("my-message")));
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return GST_PAD_PROBE_OK;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
int
|
|
Packit |
971217 |
main (int argc, char **argv)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstElement *pipe;
|
|
Packit |
971217 |
GstMessage *message;
|
|
Packit |
971217 |
GstPad *srcpad;
|
|
Packit |
971217 |
Data data;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_init (&argc, &argv);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
pipe = make_pipeline (0);
|
|
Packit |
971217 |
if (pipe == NULL)
|
|
Packit |
971217 |
return -1;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
data.rate = 1000;
|
|
Packit |
971217 |
data.filter = gst_bin_get_by_name (GST_BIN (pipe), "filter");
|
|
Packit |
971217 |
g_assert (data.filter);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
srcpad = gst_element_get_static_pad (data.filter, "src");
|
|
Packit |
971217 |
gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM, have_probe,
|
|
Packit |
971217 |
&data, NULL);
|
|
Packit |
971217 |
gst_object_unref (srcpad);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_element_set_state (pipe, GST_STATE_PLAYING);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
while (TRUE) {
|
|
Packit |
971217 |
message =
|
|
Packit |
971217 |
gst_bus_poll (GST_ELEMENT_BUS (pipe),
|
|
Packit |
971217 |
GST_MESSAGE_ERROR | GST_MESSAGE_APPLICATION, 50 * GST_MSECOND);
|
|
Packit |
971217 |
if (message) {
|
|
Packit |
971217 |
g_print ("got error \n");
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_message_unref (message);
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
gst_object_unref (data.filter);
|
|
Packit |
971217 |
gst_element_set_state (pipe, GST_STATE_NULL);
|
|
Packit |
971217 |
gst_object_unref (pipe);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return 0;
|
|
Packit |
971217 |
}
|