void gbp_player_pause (GbpPlayer *player) { g_return_if_fail (player != NULL); if (player->priv->have_pipeline == FALSE) { if (!build_pipeline (player)) /* player::error has been emitted, return */ return; } if (player->priv->uri_changed) { gbp_player_stop (player); g_object_set (player->priv->pipeline, "uri", player->priv->uri, NULL); player->priv->uri_changed = FALSE; } if (player->priv->reset_state) { gbp_player_stop (player); player->priv->reset_state = FALSE; } gst_element_set_state (GST_ELEMENT (player->priv->pipeline), GST_STATE_PAUSED); }
/* Main method for the native code. This is executed on its own thread. */ void * app_function(void *userdata) { CustomData *data = (CustomData *) userdata; GPlayerDEBUG("Creating pipeline in CustomData at %p", data); /* Create our own GLib Main Context and make it the default one */ data->context = g_main_context_new(); g_main_context_push_thread_default(data->context); data->pipeline = gst_pipeline_new("test-pipeline"); build_pipeline(data); /* Create a GLib Main Loop and set it to run */ GPlayerDEBUG("Entering main loop... (CustomData:%p)", data); data->main_loop = g_main_loop_new(data->context, FALSE); check_initialization_complete(data); g_main_loop_run(data->main_loop); GPlayerDEBUG("Exited main loop"); /* Free resources */ g_main_context_pop_thread_default(data->context); g_main_context_unref(data->context); data->target_state = GST_STATE_NULL; gst_element_set_state(data->pipeline, GST_STATE_NULL); kill_object(data->pipeline); return NULL; }
Module GeneratorBase::build_module(const std::string &function_name, const LoweredFunc::LinkageType linkage_type) { build_params(); Pipeline pipeline = build_pipeline(); // Building the pipeline may mutate the params and imageparams. rebuild_params(); return pipeline.compile_to_module(get_filter_arguments(), function_name, target, linkage_type); }
std::vector<Argument> GeneratorBase::get_filter_output_types() { std::vector<Argument> output_types; Pipeline pipeline = build_pipeline(); std::vector<Func> pipeline_results = pipeline.outputs(); for (Func func : pipeline_results) { for (Halide::Type t : func.output_types()) { std::string name = "result_" + std::to_string(output_types.size()); output_types.push_back(Halide::Argument(name, Halide::Argument::OutputBuffer, t, func.dimensions())); } } return output_types; }
void GeneratorBase::emit_filter(const std::string &output_dir, const std::string &function_name, const std::string &file_base_name, const EmitOptions &options) { build_params(); Pipeline pipeline = build_pipeline(); std::vector<Halide::Argument> inputs = get_filter_arguments(); std::string base_path = output_dir + "/" + (file_base_name.empty() ? function_name : file_base_name); if (options.emit_o || options.emit_assembly || options.emit_bitcode) { Outputs output_files; if (options.emit_o) { // If the target arch is pnacl, then the output "object" file is // actually a pnacl bitcode file. if (Target(target).arch == Target::PNaCl) { output_files.object_name = base_path + ".bc"; } else if (Target(target).os == Target::Windows && !Target(target).has_feature(Target::MinGW)) { // If it's windows, then we're emitting a COFF file output_files.object_name = base_path + ".obj"; } else { // Otherwise it is an ELF or Mach-o output_files.object_name = base_path + ".o"; } } if (options.emit_assembly) { output_files.assembly_name = base_path + ".s"; } if (options.emit_bitcode) { // In this case, bitcode refers to the LLVM IR generated by Halide // and passed to LLVM, for both the pnacl and ordinary archs output_files.bitcode_name = base_path + ".bc"; } pipeline.compile_to(output_files, inputs, function_name, target); } if (options.emit_h) { pipeline.compile_to_header(base_path + ".h", inputs, function_name, target); } if (options.emit_cpp) { pipeline.compile_to_c(base_path + ".cpp", inputs, function_name, target); } if (options.emit_stmt) { pipeline.compile_to_lowered_stmt(base_path + ".stmt", inputs, Halide::Text, target); } if (options.emit_stmt_html) { pipeline.compile_to_lowered_stmt(base_path + ".html", inputs, Halide::HTML, target); } }
Func GeneratorBase::call_extern(std::initializer_list<ExternFuncArgument> function_arguments, std::string function_name){ Pipeline p = build_pipeline(); user_assert(p.outputs().size() == 1) \ << "Can only call_extern Pipelines with a single output Func\n"; Func f = p.outputs()[0]; Func f_extern; if (function_name.empty()) { function_name = generator_name(); user_assert(!function_name.empty()) << "call_extern: generator_name is empty\n"; } f_extern.define_extern(function_name, function_arguments, f.output_types(), f.dimensions()); return f_extern; }
void nsc_gstreamer_convert_file (NscGStreamer *gstreamer, GFile *src, GFile *sink, GError **error) { GstStateChangeReturn state_ret; NscGStreamerPrivate *priv; gint64 nanos; static GstFormat format = GST_FORMAT_TIME; g_return_if_fail (NSC_IS_GSTREAMER (gstreamer)); g_return_if_fail (src != NULL); g_return_if_fail (sink != NULL); priv = NSC_GSTREAMER_GET_PRIVATE (gstreamer); /* See if we need to rebuild the pipeline */ if (priv->rebuild_pipeline != FALSE) { build_pipeline (gstreamer); if (priv->construct_error != NULL) { g_propagate_error (error, priv->construct_error); priv->construct_error = NULL; return; } } /* Set the input file */ gst_element_set_state (priv->filesrc, GST_STATE_NULL); g_object_set (G_OBJECT (priv->filesrc), "file", src, NULL); /* Set the output filename */ gst_element_set_state (priv->filesink, GST_STATE_NULL); g_object_set (G_OBJECT (priv->filesink), "file", sink, NULL); /* Let's get ready to rumble! */ state_ret = gst_element_set_state (priv->pipeline, GST_STATE_PLAYING); if (state_ret == GST_STATE_CHANGE_ASYNC) { /* * Wait for the state change to either complete or fail, * but not for too long just to catch immediate errors. * The rest we'll handle asynchronously. */ state_ret = gst_element_get_state (priv->pipeline, NULL, NULL, GST_SECOND / 2); } if (state_ret == GST_STATE_CHANGE_FAILURE) { GstMessage *msg; msg = gst_bus_poll (GST_ELEMENT_BUS (priv->pipeline), GST_MESSAGE_ERROR, 0); if (msg) { gst_message_parse_error (msg, error, NULL); gst_message_unref (msg); } else if (error) { *error = g_error_new (NSC_ERROR, NSC_ERROR_INTERNAL_ERROR, "Error starting converting pipeline"); } gst_element_set_state (priv->pipeline, GST_STATE_NULL); priv->rebuild_pipeline = TRUE; return; } /* Get file duration */ if (!gst_element_query_duration (priv->pipeline, &format, &nanos)) { g_warning (_("Could not get current file duration")); } else { gint secs; secs = nanos / GST_SECOND; g_signal_emit (gstreamer, signals[DURATION], 0, secs); } priv->tick_id = g_timeout_add (250, (GSourceFunc)tick_timeout_cb, gstreamer); }
void sj_extractor_extract_track (SjExtractor *extractor, const TrackDetails *track, GFile *file, GError **error) { GParamSpec *spec; GstStateChangeReturn state_ret; SjExtractorPrivate *priv; GstIterator *iter; GValue item = {0, }; GstTagSetter *tagger; gboolean done; char *uri; g_return_if_fail (SJ_IS_EXTRACTOR (extractor)); g_return_if_fail (file != NULL); g_return_if_fail (track != NULL); priv = extractor->priv; /* See if we need to rebuild the pipeline */ if (priv->rebuild_pipeline != FALSE) { build_pipeline (extractor); if (priv->construct_error != NULL) { g_propagate_error (error, priv->construct_error); priv->construct_error = NULL; return; } } /* Need to do this, as playback will have locked the read speed to 2x previously */ spec = g_object_class_find_property (G_OBJECT_GET_CLASS (priv->cdsrc), "read-speed"); if (spec && spec->value_type == G_TYPE_INT) { g_object_set (G_OBJECT (priv->cdsrc), "read-speed", ((GParamSpecInt*)spec)->maximum, NULL); } /* Set the output filename */ gst_element_set_state (priv->filesink, GST_STATE_NULL); uri = g_file_get_uri (file); g_object_set (G_OBJECT (priv->filesink), "location", uri, NULL); g_free (uri); /* Set the metadata */ iter = gst_bin_iterate_all_by_interface (GST_BIN (priv->pipeline), GST_TYPE_TAG_SETTER); done = FALSE; while (!done) { switch (gst_iterator_next (iter, &item)) { case GST_ITERATOR_OK: /* TODO: generate this as a taglist once, and apply it to all elements */ tagger = g_value_get_object (&item); gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_REPLACE_ALL, GST_TAG_TITLE, track->title, GST_TAG_ARTIST, track->artist, GST_TAG_TRACK_NUMBER, track->number, GST_TAG_TRACK_COUNT, track->album->number, GST_TAG_ALBUM, track->album->title, GST_TAG_DURATION, track->duration * GST_SECOND, NULL); if (track->composer != NULL && strcmp (track->composer, "") != 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_COMPOSER, track->composer, NULL); } if (track->composer_sortname != NULL && strcmp (track->composer_sortname, "") != 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_COMPOSER_SORTNAME, track->composer_sortname, NULL); } if (track->album->album_id != NULL && strcmp (track->album->album_id, "") != 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_MUSICBRAINZ_ALBUMID, track->album->album_id, NULL); } if (track->album->artist_id != NULL && strcmp (track->album->artist_id, "") != 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_MUSICBRAINZ_ALBUMARTISTID, track->album->artist_id, NULL); } if (track->album->artist != NULL && strcmp (track->album->artist, "") != 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_ALBUM_ARTIST, track->album->artist, NULL); } if (track->album->artist_sortname != NULL && strcmp (track->album->artist_sortname, "") != 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_ALBUM_ARTIST_SORTNAME, track->album->artist_sortname, NULL); } if (track->artist_id != NULL && strcmp (track->artist_id, "") != 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_MUSICBRAINZ_ARTISTID, track->artist_id, NULL); } if (track->track_id != NULL && strcmp (track->track_id, "") != 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_MUSICBRAINZ_TRACKID, track->track_id, NULL); } if (track->artist_sortname != NULL && strcmp (track->artist_sortname, "") != 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_ARTIST_SORTNAME, track->artist_sortname, NULL); } if (track->album->genre != NULL && strcmp (track->album->genre, "") != 0) { char **values, **l; values = g_strsplit (track->album->genre, ",", 0); for (l = values; *l; l++) { g_strstrip (*l); gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_GENRE, *l, NULL); } g_strfreev (values); } if (track->album->release_date) { GDate *date; guint year = 1; guint month = 1; guint day = 1; if (gst_date_time_has_year (track->album->release_date)) { year = gst_date_time_get_year (track->album->release_date); } if (gst_date_time_has_month (track->album->release_date)) { month = gst_date_time_get_month (track->album->release_date); } if (gst_date_time_has_day (track->album->release_date)) { day = gst_date_time_get_day (track->album->release_date); } date = g_date_new_dmy (day, month, year); /* We set both GST_TAG_DATE_TIME and GST_TAG_DATE as most taggers * use GST_TAG__DATE_TIME, but a few (id3v2mux/apemux) are still using * GST_TAG_DATE */ gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_DATE_TIME, track->album->release_date, GST_TAG_DATE, date, NULL); g_date_free (date); } if (track->album->disc_number > 0) { gst_tag_setter_add_tags (tagger, GST_TAG_MERGE_APPEND, GST_TAG_ALBUM_VOLUME_NUMBER, track->album->disc_number, NULL); } g_value_unset (&item); break; case GST_ITERATOR_RESYNC: /* TODO? */ g_warning ("Got GST_ITERATOR_RESYNC, not sure what to do"); gst_iterator_resync (iter); break; case GST_ITERATOR_ERROR: done = TRUE; break; case GST_ITERATOR_DONE: done = TRUE; break; } } g_value_unset (&item); gst_iterator_free (iter); /* Seek to the right track */ g_object_set (G_OBJECT (priv->cdsrc), "track", track->number, NULL); /* Let's get ready to rumble! */ state_ret = gst_element_set_state (priv->pipeline, GST_STATE_PLAYING); if (state_ret == GST_STATE_CHANGE_ASYNC) { /* Wait for state change to either complete or fail, but not for too long, * just to catch immediate errors. The rest we'll handle asynchronously */ state_ret = gst_element_get_state (priv->pipeline, NULL, NULL, GST_SECOND / 2); } if (state_ret == GST_STATE_CHANGE_FAILURE) { GstMessage *msg; msg = gst_bus_poll (GST_ELEMENT_BUS (priv->pipeline), GST_MESSAGE_ERROR, 0); if (msg) { gst_message_parse_error (msg, error, NULL); gst_message_unref (msg); } else if (error) { /* this should never happen, create generic error just in case */ *error = g_error_new (SJ_ERROR, SJ_ERROR_INTERNAL_ERROR, "Error starting ripping pipeline"); } gst_element_set_state (priv->pipeline, GST_STATE_NULL); priv->rebuild_pipeline = TRUE; return; } priv->tick_id = g_timeout_add (250, (GSourceFunc)tick_timeout_cb, extractor); g_source_set_name_by_id (priv->tick_id, "[sound-juicer] tick_timeout_cb"); }