static void play_audio_file(AudioGraph *ag, GenesisAudioFile *audio_file, bool is_asset) { // TODO atomically modify the pipeline instead of stopping and starting stop_pipeline(ag); if (ag->preview_audio_file && !ag->preview_audio_file_is_asset) { genesis_audio_file_destroy(ag->preview_audio_file); ag->preview_audio_file = nullptr; } else if (ag->preview_audio_file && ag->preview_audio_file_is_asset) { ag->preview_audio_file = nullptr; } assert(!ag->preview_audio_file); ag->preview_audio_file = audio_file; ag->preview_audio_file_is_asset = is_asset; ag->audio_file_frame_count = 0; ag->audio_file_frame_index = 0; if (ag->preview_audio_file) { ag->audio_file_frame_count = genesis_audio_file_frame_count(audio_file); const struct SoundIoChannelLayout *channel_layout = genesis_audio_file_channel_layout(ag->preview_audio_file); for (int ch = 0; ch < channel_layout->channel_count; ch += 1) { struct PlayChannelContext *channel_context = &ag->audio_file_channel_context[ch]; channel_context->offset = 0; channel_context->iter = genesis_audio_file_iterator(ag->preview_audio_file, ch, 0); } } audio_graph_start_pipeline(ag); }
void audio_graph_stop_playback(AudioGraph *ag) { stop_pipeline(ag); ag->is_playing = false; ag->play_head_pos = 0.0; ag->start_play_head_pos = 0.0; ag->events.trigger(EventAudioGraphPlayHeadChanged); ag->events.trigger(EventAudioGraphPlayingChanged); }
void audio_graph_change_sample_rate(AudioGraph *ag, int new_sample_rate) { ag->play_head_pos = audio_graph_play_head_pos(ag); stop_pipeline(ag); GenesisNodeDescriptor *playback_node_descr = genesis_node_descriptor(ag->master_node); genesis_node_destroy(ag->master_node); ag->master_node = nullptr; genesis_node_descriptor_destroy(playback_node_descr); playback_node_descr = nullptr; genesis_pipeline_set_sample_rate(ag->pipeline, new_sample_rate); init_playback_node(ag); audio_graph_start_pipeline(ag); }
static void test_pipeline (const char *pipeline) { GstElement *bin, *sink; GstPad *pad, *sinkpad; GstBus *bus; GError *error = NULL; GMainLoop *loop; GstPadLinkReturn linkret; bin = gst_parse_launch (pipeline, &error); fail_unless (bin != NULL, "Error parsing pipeline: %s", error ? error->message : "(invalid error)"); pad = gst_bin_find_unlinked_pad (GST_BIN (bin), GST_PAD_SRC); fail_unless (pad != NULL, "Could not locate free src pad"); /* connect the fake sink */ sink = gst_element_factory_make ("fakesink", "fake_sink"); fail_unless (sink != NULL, "Could create fakesink"); fail_unless (gst_bin_add (GST_BIN (bin), sink), "Could not insert fakesink"); sinkpad = gst_element_get_static_pad (sink, "sink"); fail_unless (sinkpad != NULL, "Could not get fakesink src pad"); linkret = gst_pad_link (pad, sinkpad); fail_unless (GST_PAD_LINK_SUCCESSFUL (linkret), "Could not link to fake sink"); gst_object_unref (sinkpad); /* run until we receive EOS */ loop = g_main_loop_new (NULL, FALSE); bus = gst_element_get_bus (bin); gst_bus_add_watch (bus, (GstBusFunc) eos_watch, loop); gst_object_unref (bus); start_pipeline (bin, pad); g_main_loop_run (loop); stop_pipeline (bin, pad); /* clean up */ g_main_loop_unref (loop); gst_object_unref (pad); gst_object_unref (bin); }
void audio_graph_recover_sound_backend_disconnect(AudioGraph *ag) { if (!ag->master_node) return; ag->play_head_pos = audio_graph_play_head_pos(ag); GenesisNodeDescriptor *playback_node_descr = genesis_node_descriptor(ag->master_node); stop_pipeline(ag); genesis_node_destroy(ag->master_node); ag->master_node = nullptr; genesis_node_descriptor_destroy(playback_node_descr); playback_node_descr = nullptr; init_playback_node(ag); audio_graph_start_pipeline(ag); }
static void test_pipeline (const char *pipeline) { GstElement *bin, *sink; GstPad *pad, *sinkpad; GstBus *bus; GError *error = NULL; GMainLoop *loop; GstPadLinkReturn linkret; guint bus_watch = 0; bin = gst_parse_launch (pipeline, &error); fail_unless (bin != NULL, "Error parsing pipeline: %s", error ? error->message : "(invalid error)"); pad = gst_bin_find_unlinked_pad (GST_BIN (bin), GST_PAD_SRC); fail_unless (pad != NULL, "Could not locate free src pad"); /* connect the fake sink */ sink = gst_element_factory_make ("fakesink", "fake_sink"); fail_unless (sink != NULL, "Could create fakesink"); fail_unless (gst_bin_add (GST_BIN (bin), sink), "Could not insert fakesink"); sinkpad = gst_element_get_static_pad (sink, "sink"); fail_unless (sinkpad != NULL, "Could not get fakesink src pad"); linkret = gst_pad_link (pad, sinkpad); fail_unless (GST_PAD_LINK_SUCCESSFUL (linkret), "Could not link to fake sink"); gst_object_unref (sinkpad); /* run until we receive EOS */ loop = g_main_loop_new (NULL, FALSE); bus = gst_element_get_bus (bin); bus_watch = gst_bus_add_watch (bus, (GstBusFunc) eos_watch, loop); gst_object_unref (bus); start_pipeline (bin, pad); g_main_loop_run (loop); /* we're EOS now; make sure oggmux out caps have stream headers on them */ { GstStructure *s; GstCaps *muxcaps; muxcaps = gst_pad_get_negotiated_caps (sinkpad); fail_unless (muxcaps != NULL); s = gst_caps_get_structure (muxcaps, 0); fail_unless (gst_structure_has_name (s, "application/ogg")); fail_unless (gst_structure_has_field (s, "streamheader")); fail_unless (gst_structure_has_field_typed (s, "streamheader", GST_TYPE_ARRAY)); gst_caps_unref (muxcaps); } stop_pipeline (bin, pad); /* clean up */ g_main_loop_unref (loop); g_source_remove (bus_watch); gst_object_unref (pad); gst_object_unref (bin); }
void audio_graph_recover_stream(AudioGraph *ag, double new_latency) { ag->play_head_pos = audio_graph_play_head_pos(ag); stop_pipeline(ag); genesis_pipeline_set_latency(ag->pipeline, new_latency); audio_graph_start_pipeline(ag); }
void restart_pipeline(int effect_num){ stop_pipeline(); start_pipeline(effect_num); }