Привет всем Я пытаюсь изменить скорость воспроизведения аудиофайла с помощью библиотеки gstreamer в c. Я следил за большинством руководств на веб-сайте gstreamer, но единственное, что не работает, это скорость воспроизведения.Как изменить скорость воспроизведения аудиопотока в Gstreamer?
Способ, которым он настроен прямо сейчас, скорость должна быть удвоена, когда «.» встречается, но ничего не происходит. Могут ли какие-либо опытные пользователи gstreamer дать некоторую информацию?
typedef struct bindata {
GMainLoop *loop;
GstElement *pipeline, *source, *mp3decoder, *volume, *pulseout;
gboolean playing;
} bindata;
static bindata data;
static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer *misc){
//GMainLoop *loop = (GMainLoop *) misc;
switch (GST_MESSAGE_TYPE(msg)){
case GST_MESSAGE_EOS: {
g_message("End of stream.\n");
g_main_loop_quit(data.loop);
break;
}
case GST_MESSAGE_ERROR:{
GError *error;
gst_message_parse_error(msg, &error, NULL);
g_printerr("%s\n", error->message);
g_error_free(error);
g_main_loop_quit(data.loop);
break;
}
default: break;
}
return TRUE;
}
static gboolean keypress (GIOChannel *src, GIOCondition cond, bindata *data){
int c;
gdouble vol;
GstFormat format = GST_FORMAT_TIME;
//if(g_io_channel_read_unichar(src, str, NULL) != G_IO_STATUS_NORMAL){
if((c = getchar()) == EOF){
return TRUE;
}
switch(c){
case '+':
g_object_get(data->volume, "volume", &vol,NULL);
if (vol >= 10) break;
g_object_set (data->volume, "volume", vol + 0.1, NULL);
break;
case '-':
g_object_get(data->volume, "volume", &vol, NULL);
if (vol <= 0.1) break;
g_object_set (data->volume, "volume", vol - 0.1, NULL);
break;
case '.':
g_print("speed up \n");
gst_element_send_event(data->pulseout, gst_event_new_step(format, 20, 2.0, TRUE, FALSE));
break;
case ',':
g_print("speed down \n");
break;
case ' ':
data->playing = !data->playing;
gst_element_set_state (data->pipeline, data->playing ? GST_STATE_PLAYING : GST_STATE_PAUSED);
break;
default:
break;
}
return TRUE;
}
int main(int argc, char *argv[]){
GstBus *bus;
guint bus_watch_id;
GIOChannel *io_stdin;
gst_init(&argc, &argv);
memset (&data, 0, sizeof(data));
data.loop = g_main_loop_new(NULL, false);
if(argc != 2){
g_printerr("Usage: ./play <URI: mp3 file>");
return -1;
}
io_stdin = g_io_channel_unix_new (fileno (stdin));
g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc) keypress, &data);
data.pipeline = gst_pipeline_new ("audio-player");
data.source = gst_element_factory_make ("filesrc", "file source");
data.mp3decoder = gst_element_factory_make ("mad", "mad mp3");
data.volume = gst_element_factory_make ("volume", "volume");
data.pulseout = gst_element_factory_make ("pulsesink", "pulse audio");
if(!data.pipeline || !data.source || !data.mp3decoder || !data.pulseout || !data.volume) {
g_printerr("Some element(s) could not be created. Exiting. \n");
return -1;
}
g_object_set (G_OBJECT (data.source), "location", argv[1], NULL);
g_object_set (G_OBJECT(data.volume), "volume", 0.01, NULL);
bus = gst_pipeline_get_bus(GST_PIPELINE(data.pipeline));
bus_watch_id = gst_bus_add_watch(bus, bus_call, NULL);
gst_object_unref(bus);
gst_bin_add_many(GST_BIN (data.pipeline), data.source, data.mp3decoder, data.volume, data.pulseout, NULL);
gst_element_link_many (data.source, data.mp3decoder, data.volume, data.pulseout, NULL);
gst_element_set_state(data.pipeline, GST_STATE_PLAYING);
data.playing = TRUE;
g_print ("Running...\n");
g_main_loop_run(data.loop);
g_print ("ended. \n");
gst_element_set_state(data.pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(data.pipeline));
g_source_remove (bus_watch_id);
g_main_loop_unref (data.loop);
return 0;
}
Я также попытался это и в соответствии с документацией , значение скорости в gst_event_new_step также должно выполнить ту же задачу. Несмотря на то, что gst_event_new_seek тоже не работал для меня, компилируется и работает нормально, но сообщений об ошибках нет. – oneb1got