static gboolean
backend_extract_async (GUPnPDLNAMetadataExtractor  *extractor,
                       const gchar                 *uri,
                       guint                        timeout,
                       GError                     **error)
{
        GError *gst_error = NULL;
        GstClockTime clock_time = GST_MSECOND * timeout;
        GstDiscoverer *discoverer = gst_discoverer_new (clock_time, &gst_error);

        if (gst_error) {
                g_propagate_error (error, gst_error);

                return FALSE;
        }

        g_signal_connect_swapped (discoverer,
                                  "discovered",
                                  G_CALLBACK (gupnp_dlna_discovered_cb),
                                  extractor);
        gst_discoverer_start (discoverer);

        return gst_discoverer_discover_uri_async (discoverer,
                                                  uri);
}
static void
generate_xml_media_descriptor (InsanityTest * test)
{
  GError *err = NULL;
  GstDiscovererInfo *info = NULL;
  gchar *sublocation = NULL, *suburi = NULL;

  GstDiscoverer *discoverer = gst_discoverer_new (5 * GST_SECOND, NULL);

  insanity_test_get_string_argument (test, "sublocation", &sublocation);

  if (G_UNLIKELY (discoverer == NULL)) {
    ERROR (test, "Error creating discoverer: %s\n", err->message);
    g_clear_error (&err);

    insanity_test_done (test);
    goto done;
  }

  suburi = gst_filename_to_uri (sublocation, &err);
  if (err) {
    ERROR (test, "Could not construct filename");
    g_clear_error (&err);
    goto done;
  }

  info = gst_discoverer_discover_uri (discoverer, suburi, &err);
  if (info == NULL) {
    ERROR (test, "Error discovering: %s\n", err->message);
    g_clear_error (&err);

    insanity_test_done (test);
    goto done;
  }

  glob_duration = gst_discoverer_info_get_duration (info);
  glob_seekable = gst_discoverer_info_get_seekable (info);

  glob_writer = media_descriptor_writer_new (test,
      sublocation, glob_duration, glob_seekable);

  glob_in_progress = TEST_SUBTTILE_DESCRIPTOR_GENERATION;

  g_idle_add ((GSourceFunc) idle_restart_pipeline, NULL);

  media_descriptor_writer_add_stream (glob_writer,
      glob_suboverlay_src_probe->pad);

done:
  if (discoverer != NULL)
    g_object_unref (discoverer);

  if (info != NULL)
    gst_discoverer_info_unref (info);

  g_free (sublocation);
  g_free (suburi);
}
Example #3
0
 extern "C" void C_Func_MediaInfo (char * filename) {
  CustomData data;
  GError *err = NULL;
  gchar *uri = filename;
   
  /* if a URI was provided, use it instead of the default one */
//  if (argc > 1) {
 //   uri = argv[1];
 // }
   
  /* Initialize cumstom data structure */
  memset (&data, 0, sizeof (data));
   
  /* Initialize GStreamer */
 // gst_init (NULL,NULL);
   
  g_print ("Discovering '%s'\n", uri);
   
  /* Instantiate the Discoverer */
  data.discoverer = gst_discoverer_new (5 * GST_SECOND, &err);
  if (!data.discoverer) {
    g_print ("Error creating discoverer instance: %s\n", err->message);
    g_clear_error (&err);
    //return -1;
  } else {
		 
		/* Connect to the interesting signals */
		g_signal_connect (data.discoverer, "discovered", G_CALLBACK (on_discovered_cb), &data);
		g_signal_connect (data.discoverer, "finished", G_CALLBACK (on_finished_cb), &data);
		 
		/* Start the discoverer process (nothing to do yet) */
		gst_discoverer_start (data.discoverer);
		 
		/* Add a request to process asynchronously the URI passed through the command line */
		if (!gst_discoverer_discover_uri_async (data.discoverer, uri)) {
		  g_print ("Failed to start discovering URI '%s'\n", uri);
		  g_object_unref (data.discoverer);
		  
		} else {
			 
			/* Create a GLib Main Loop and set it to run, so we can wait for the signals */
			data.loop = g_main_loop_new (NULL, FALSE);
			g_main_loop_run (data.loop);
		}
	/* Stop the discoverer process */
		gst_discoverer_stop (data.discoverer);
		 
		/* Free resources */
		g_object_unref (data.discoverer);
		g_main_loop_unref (data.loop);
 	}  
//  return 0;
}
gboolean
gst_validate_media_info_inspect_uri (GstValidateMediaInfo * mi,
    const gchar * uri, gboolean discover_only, GError ** err)
{
  GstDiscovererInfo *info;
  GstDiscoverer *discoverer = gst_discoverer_new (GST_SECOND * 60, err);
  gboolean ret = TRUE;

  g_return_val_if_fail (uri != NULL, FALSE);

  g_free (mi->uri);
  mi->uri = g_strdup (uri);

  if (!discoverer) {
    return FALSE;
  }

  info = gst_discoverer_discover_uri (discoverer, uri, err);

  if (gst_discoverer_info_get_result (info) != GST_DISCOVERER_OK) {
    gst_object_unref (discoverer);
    return FALSE;
  }

  mi->is_image = check_is_image (info);
  ret = check_file_size (mi) & ret;
  ret = check_encoding_profile (mi, info) & ret;
  ret = check_file_duration (mi, info) & ret;

  if (mi->is_image)
    goto done;

  check_seekable (mi, info);
  if (discover_only)
    goto done;

  ret = check_playback (mi, &mi->playback_error) & ret;
  ret = check_reverse_playback (mi, &mi->reverse_playback_error) & ret;
  ret = check_track_selection (mi, &mi->track_switch_error) & ret;

done:
  gst_object_unref (discoverer);

  return ret;
}
Example #5
0
static void
test_disco_sync_reuse (const gchar * test_fn, guint num, GstClockTime timeout)
{
  GError *err = NULL;
  GstDiscoverer *dc;
  GstDiscovererInfo *info;
  GstDiscovererResult result;
  gchar *uri, *path;
  int i;

  dc = gst_discoverer_new (timeout, &err);
  fail_unless (dc != NULL);
  fail_unless (err == NULL);

  /* GST_TEST_FILE comes from makefile CFLAGS */
  path = g_build_filename (GST_TEST_FILES_PATH, test_fn, NULL);
  uri = gst_filename_to_uri (path, &err);
  g_free (path);
  fail_unless (err == NULL);

  for (i = 0; i < num; ++i) {
    GST_INFO ("[%02d] discovering uri '%s'", i, uri);
    info = gst_discoverer_discover_uri (dc, uri, &err);
    if (info) {
      result = gst_discoverer_info_get_result (info);
      GST_INFO ("result: %d", result);
      gst_discoverer_info_unref (info);
    }
    /* in case we don't have some of the elements needed */
    if (err) {
      g_error_free (err);
      err = NULL;
    }
  }
  g_free (uri);

  g_object_unref (dc);
}
Example #6
0
int
main (int argc, char **argv)
{
  GError *err = NULL;
  GstDiscoverer *dc;
  gint timeout = 10;
  GOptionEntry options[] = {
    {"async", 'a', 0, G_OPTION_ARG_NONE, &async,
        "Run asynchronously", NULL},
    {"silent", 's', 0, G_OPTION_ARG_NONE, &silent,
        "Don't output the information structure", NULL},
    {"timeout", 't', 0, G_OPTION_ARG_INT, &timeout,
        "Specify timeout (in seconds, default 10)", "T"},
    /* {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek, */
    /*     "Seek on elements instead of pads", NULL}, */
    {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
        "Verbose properties", NULL},
    {NULL}
  };
  GOptionContext *ctx;

  if (!g_thread_supported ())
    g_thread_init (NULL);

  ctx =
      g_option_context_new
      ("- discover files synchronously with GstDiscoverer");
  g_option_context_add_main_entries (ctx, options, NULL);
  g_option_context_add_group (ctx, gst_init_get_option_group ());

  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
    g_print ("Error initializing: %s\n", err->message);
    exit (1);
  }

  g_option_context_free (ctx);

  if (argc < 2) {
    g_print ("usage: %s <uris>\n", argv[0]);
    exit (-1);
  }

  dc = gst_discoverer_new (timeout * GST_SECOND, &err);
  if (G_UNLIKELY (dc == NULL)) {
    g_print ("Error initializing: %s\n", err->message);
    exit (1);
  }

  if (async == FALSE) {
    gint i;
    for (i = 1; i < argc; i++)
      process_file (dc, argv[i]);
  } else {
    PrivStruct *ps = g_new0 (PrivStruct, 1);
    GMainLoop *ml = g_main_loop_new (NULL, FALSE);

    ps->dc = dc;
    ps->argc = argc;
    ps->argv = argv;

    /* adding uris will be started when the mainloop runs */
    g_idle_add ((GSourceFunc) _run_async, ps);

    /* connect signals */
    g_signal_connect (dc, "discovered", G_CALLBACK (_new_discovered_uri), NULL);
    g_signal_connect (dc, "finished", G_CALLBACK (_discoverer_finished), ml);

    gst_discoverer_start (dc);
    /* run mainloop */
    g_main_loop_run (ml);

    gst_discoverer_stop (dc);
    g_free (ps);
    g_main_loop_unref (ml);
  }
  g_object_unref (dc);

  return 0;
}
                                  extractor);
        gst_discoverer_start (discoverer);

        return gst_discoverer_discover_uri_async (discoverer,
                                                  uri);
}

static GUPnPDLNAInformation *
backend_extract_sync (GUPnPDLNAMetadataExtractor  *extractor G_GNUC_UNUSED,
                      const gchar                 *uri,
                      guint                        timeout_in_ms,
                      GError                     **error)
{
        GError *gst_error = NULL;
        GstClockTime clock_time = GST_MSECOND * timeout_in_ms;
        GstDiscoverer *discoverer = gst_discoverer_new (clock_time, &gst_error);
        GstDiscovererInfo* info;
        GUPnPDLNAInformation *gupnp_info;

        if (gst_error) {
                g_propagate_error (error, gst_error);

                return NULL;
        }

        info = gst_discoverer_discover_uri (discoverer,
                                            uri,
                                            &gst_error);

        g_object_unref (discoverer);
        if (gst_error) {
bool GStreamerImageStream::open(const std::string& filename)
{
    setFileName(filename);

    GError *error = NULL;

    // get stream info

    bool has_audio_stream = false;

    gchar *uri = g_filename_to_uri(filename.c_str(), NULL, NULL);

    if( uri!=0 && gst_uri_is_valid(uri) )
    {
        GstDiscoverer *item = gst_discoverer_new(1*GST_SECOND, &error);
        GstDiscovererInfo *info = gst_discoverer_discover_uri(item, uri, &error);
        GList *audio_list = gst_discoverer_info_get_audio_streams(info);

        if( g_list_length(audio_list) > 0 )
            has_audio_stream = true;

        gst_discoverer_info_unref(info);
        g_free(uri);
    }

    // build pipeline
    const gchar *audio_pipe = "";
    if( has_audio_stream )
    {
        audio_pipe = "deco. ! queue ! audioconvert ! autoaudiosink";
    }

    gchar *string = g_strdup_printf("filesrc location=%s ! \
        decodebin name=deco \
        deco. ! queue ! videoconvert ! video/x-raw,format=RGB ! appsink name=sink emit-signals=true \
        %s", filename.c_str(), audio_pipe);

    _pipeline = gst_parse_launch(string, &error);

    g_free(string);

    if (error)
    {
        g_printerr("Error: %s\n", error->message);
        g_error_free(error);
    }

    if( _pipeline == NULL )
    {
        return false;
    }


    // bus
    GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(_pipeline));

    gst_bus_add_watch(bus, (GstBusFunc)on_message, this);

    gst_object_unref(bus);


    // sink

    GstElement *sink = gst_bin_get_by_name(GST_BIN(_pipeline), "sink");

    g_signal_connect(sink, "new-sample", G_CALLBACK(on_new_sample), this);
    g_signal_connect(sink, "new-preroll", G_CALLBACK(on_new_preroll), this);

    gst_object_unref(sink);

    gst_element_set_state(_pipeline, GST_STATE_PAUSED);
    gst_element_get_state(_pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); // wait until the state changed

    if (_width==0 || _height==0)
    {
        // no valid image has been setup by a on_new_preroll() call.
        return false;
    }

    // setLoopingMode(osg::ImageStream::NO_LOOPING);

    // start the thread to run gstreamer main loop
    start();

    return true;
}
Example #9
0
gchar *
lgm_filename_to_uri (const gchar *filename)
{
  gchar *uri, *path;
  GError *err = NULL;

#ifdef G_OS_WIN32
  if (g_path_is_absolute(filename) || !gst_uri_is_valid (filename)) {
#else
  if (!gst_uri_is_valid (filename)) {
#endif
    if (!g_path_is_absolute (filename)) {
      gchar *cur_dir;

      cur_dir = g_get_current_dir ();
      path = g_build_filename (cur_dir, filename, NULL);
      g_free (cur_dir);
    } else {
      path = g_strdup (filename);
    }

    uri = g_filename_to_uri (path, NULL, &err);
    g_free (path);
    path = NULL;

    if (err != NULL) {
      g_error_free (err);
      return NULL;
    }
  } else {
    uri = g_strdup (filename);
  }
  return uri;
}

GstDiscovererResult
lgm_discover_uri (
    const gchar *filename, guint64 *duration, guint *width,
    guint *height, guint *fps_n, guint *fps_d, guint *par_n, guint *par_d,
    gchar **container, gchar **video_codec, gchar **audio_codec,
    GError **err)
{
  GstDiscoverer *discoverer;
  GstDiscovererInfo *info;
  GList *videos = NULL, *audios = NULL;
  GstDiscovererStreamInfo *sinfo = NULL;
  GstDiscovererVideoInfo *vinfo = NULL;
  GstDiscovererAudioInfo *ainfo = NULL;
  GstDiscovererResult ret;
  gchar *uri;

  uri = lgm_filename_to_uri (filename);
  if (uri == NULL) {
    return GST_DISCOVERER_URI_INVALID;
  }

  *duration = *width = *height = *fps_n = *fps_d = *par_n = *par_d = 0;
  *container = *audio_codec = *video_codec = NULL;

  discoverer = gst_discoverer_new (4 * GST_SECOND, err);
  if (*err != NULL) {
    g_free (uri);
    return GST_DISCOVERER_ERROR;
  }

  info = gst_discoverer_discover_uri (discoverer, uri, err);
  g_free (uri);
  if (*err != NULL) {
    if (info != NULL) {
      return gst_discoverer_info_get_result (info);
    } else {
      return GST_DISCOVERER_ERROR;
    }
  }

  sinfo = gst_discoverer_info_get_stream_info (info);
  *duration = gst_discoverer_info_get_duration (info);

  if (GST_IS_DISCOVERER_CONTAINER_INFO (sinfo)) {
    GstCaps *caps;

    caps = gst_discoverer_stream_info_get_caps (
        GST_DISCOVERER_STREAM_INFO(sinfo));
    *container = gst_pb_utils_get_codec_description (caps);
    gst_caps_unref (caps);
  }

  if (GST_IS_DISCOVERER_AUDIO_INFO (sinfo)) {
    ainfo = GST_DISCOVERER_AUDIO_INFO (sinfo);
  } else {
    audios = gst_discoverer_info_get_audio_streams (info);
    if (audios != NULL) {
      ainfo = audios->data;
    }
  }

  if (ainfo != NULL) {
    GstCaps *caps;

    caps = gst_discoverer_stream_info_get_caps (
        GST_DISCOVERER_STREAM_INFO (ainfo));
    *audio_codec = gst_pb_utils_get_codec_description (caps);
    gst_caps_unref (caps);
  }
  if (audios != NULL) {
    gst_discoverer_stream_info_list_free (audios);
  }

  if (GST_IS_DISCOVERER_VIDEO_INFO (sinfo)) {
    vinfo = GST_DISCOVERER_VIDEO_INFO (sinfo);
  } else {
    videos = gst_discoverer_info_get_video_streams (info);
    if (videos != NULL) {
      vinfo = videos->data;
    }
  }

  if (vinfo != NULL) {
    GstCaps *caps;

    caps = gst_discoverer_stream_info_get_caps (
        GST_DISCOVERER_STREAM_INFO (vinfo));
    *video_codec = gst_pb_utils_get_codec_description (caps);
    gst_caps_unref (caps);
    *height = gst_discoverer_video_info_get_height (vinfo);
    *width = gst_discoverer_video_info_get_width (vinfo);
    *fps_n = gst_discoverer_video_info_get_framerate_num (vinfo);
    *fps_d = gst_discoverer_video_info_get_framerate_denom (vinfo);
    *par_n = gst_discoverer_video_info_get_par_num (vinfo);
    *par_d = gst_discoverer_video_info_get_par_denom (vinfo);
  }
  if (videos != NULL) {
    gst_discoverer_stream_info_list_free (videos);
  }

  ret = gst_discoverer_info_get_result (info);
  gst_discoverer_info_unref (info);
  g_object_unref (discoverer);

  return ret;
}