Beispiel #1
0
static void
print_info (GstDiscovererInfo * info, GError * err)
{
  GstDiscovererResult result = gst_discoverer_info_get_result (info);
  GstDiscovererStreamInfo *sinfo;

  g_print ("Done discovering %s\n", gst_discoverer_info_get_uri (info));
  switch (result) {
    case GST_DISCOVERER_OK:
    {
      break;
    }
    case GST_DISCOVERER_URI_INVALID:
    {
      g_print ("URI is not valid\n");
      break;
    }
    case GST_DISCOVERER_ERROR:
    {
      g_print ("An error was encountered while discovering the file\n");
      g_print (" %s\n", err->message);
      break;
    }
    case GST_DISCOVERER_TIMEOUT:
    {
      g_print ("Analyzing URI timed out\n");
      break;
    }
    case GST_DISCOVERER_BUSY:
    {
      g_print ("Discoverer was busy\n");
      break;
    }
    case GST_DISCOVERER_MISSING_PLUGINS:
    {
      g_print ("Missing plugins\n");
      if (verbose) {
        gchar *tmp =
            gst_structure_to_string (gst_discoverer_info_get_misc (info));
        g_print (" (%s)\n", tmp);
        g_free (tmp);
      }
      break;
    }
  }

  if ((sinfo = gst_discoverer_info_get_stream_info (info))) {
    g_print ("\nTopology:\n");
    print_topology (sinfo, 1);
    g_print ("\nProperties:\n");
    print_properties (info, 1);
    gst_discoverer_stream_info_unref (sinfo);
  }

  g_print ("\n");
}
static void
asset_loaded_cb (GObject * source, GAsyncResult * res, GMainLoop * mainloop)
{
  GESUriClipAsset *mfs =
      GES_URI_CLIP_ASSET (ges_asset_request_finish (res, NULL));
  GstDiscovererInfo *discoverer_info = NULL;
  discoverer_info = ges_uri_clip_asset_get_info (mfs);

  GST_DEBUG ("Result is %d", gst_discoverer_info_get_result (discoverer_info));
  GST_DEBUG ("Info type is %s", G_OBJECT_TYPE_NAME (mfs));
  GST_DEBUG ("Duration is %" GST_TIME_FORMAT,
      GST_TIME_ARGS (ges_uri_clip_asset_get_duration (mfs)));

  gst_object_unref (mfs);

  g_main_loop_quit (mainloop);
}
/**
 * gst_encoding_profile_from_discoverer:
 * @info: (transfer none): The #GstDiscovererInfo to read from
 *
 * Creates a #GstEncodingProfile matching the formats from the given
 * #GstDiscovererInfo. Streams other than audio or video (eg,
 * subtitles), are currently ignored.
 *
 * Returns: (transfer full): The new #GstEncodingProfile or %NULL.
 */
GstEncodingProfile *
gst_encoding_profile_from_discoverer (GstDiscovererInfo * info)
{
  GstEncodingContainerProfile *profile;
  GstDiscovererStreamInfo *sinfo;
  GList *streams, *stream;
  GstCaps *caps = NULL;
  guint n_streams = 0;

  if (!info || gst_discoverer_info_get_result (info) != GST_DISCOVERER_OK)
    return NULL;

  sinfo = gst_discoverer_info_get_stream_info (info);
  if (!sinfo)
    return NULL;

  caps = gst_discoverer_stream_info_get_caps (sinfo);
  GST_LOG ("Container: %" GST_PTR_FORMAT "\n", caps);
  profile =
      gst_encoding_container_profile_new ("auto-generated",
      "Automatically generated from GstDiscovererInfo", caps, NULL);
  gst_caps_unref (caps);
  if (!profile) {
    GST_ERROR ("Failed to create container profile from caps %" GST_PTR_FORMAT,
        caps);
    return NULL;
  }

  streams =
      gst_discoverer_container_info_get_streams (GST_DISCOVERER_CONTAINER_INFO
      (sinfo));
  for (stream = streams; stream; stream = stream->next) {
    if (add_stream_to_profile (profile,
            (GstDiscovererStreamInfo *) stream->data))
      n_streams++;
  }
  gst_discoverer_stream_info_list_free (streams);

  if (n_streams == 0) {
    GST_ERROR ("Failed to add any streams");
    g_object_unref (profile);
    return NULL;
  }

  return (GstEncodingProfile *) profile;
}
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;
}
Beispiel #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);
}
static void
print_info (GstDiscovererInfo * info, GError * err)
{
  GstDiscovererResult result;
  GstDiscovererStreamInfo *sinfo;

  if (!info) {
    g_print ("Could not discover URI\n");
    g_print (" %s\n", err->message);
    return;
  }

  result = gst_discoverer_info_get_result (info);
  g_print ("Done discovering %s\n", gst_discoverer_info_get_uri (info));
  switch (result) {
    case GST_DISCOVERER_OK:
    {
      break;
    }
    case GST_DISCOVERER_URI_INVALID:
    {
      g_print ("URI is not valid\n");
      break;
    }
    case GST_DISCOVERER_ERROR:
    {
      g_print ("An error was encountered while discovering the file\n");
      g_print (" %s\n", err->message);
      break;
    }
    case GST_DISCOVERER_TIMEOUT:
    {
      g_print ("Analyzing URI timed out\n");
      break;
    }
    case GST_DISCOVERER_BUSY:
    {
      g_print ("Discoverer was busy\n");
      break;
    }
    case GST_DISCOVERER_MISSING_PLUGINS:
    {
      g_print ("Missing plugins\n");
      if (verbose) {
        gint i = 0;
        const gchar **installer_details =
            gst_discoverer_info_get_missing_elements_installer_details (info);

        while (installer_details[i]) {
          g_print (" (%s)\n", installer_details[i]);

          i++;
        }
      }
      break;
    }
  }

  if ((sinfo = gst_discoverer_info_get_stream_info (info))) {
    g_print ("\nTopology:\n");
    print_topology (sinfo, 1);
    g_print ("\nProperties:\n");
    print_properties (info, 1);
    gst_discoverer_stream_info_unref (sinfo);
  }

  g_print ("\n");
}
Beispiel #7
0
/* This function is called every time the discoverer has information regarding
 * one of the URIs we provided.*/
void on_discovered_cb (GstDiscoverer *discoverer, GstDiscovererInfo *info, GError *err, CustomData *data) {
  GstDiscovererResult result;
  const gchar *uri;
  const GstTagList *tags;
  GstDiscovererStreamInfo *sinfo;
   
  uri = gst_discoverer_info_get_uri (info);
  result = gst_discoverer_info_get_result (info);
  switch (result) {
    case GST_DISCOVERER_URI_INVALID:
      g_print ("Invalid URI '%s'\n", uri);
      break;
    case GST_DISCOVERER_ERROR:
      g_print ("Discoverer error: %s\n", err->message);
      break;
    case GST_DISCOVERER_TIMEOUT:
      g_print ("Timeout\n");
      break;
    case GST_DISCOVERER_BUSY:
      g_print ("Busy\n");
      break;
    case GST_DISCOVERER_MISSING_PLUGINS:{
      const GstStructure *s;
      gchar *str;
       
      s = gst_discoverer_info_get_misc (info);
      str = gst_structure_to_string (s);
       
      g_print ("Missing plugins: %s\n", str);
      g_free (str);
      break;
    }
    case GST_DISCOVERER_OK:
      g_print ("Discovered '%s'\n", uri);
      break;
  }
   
  if (result != GST_DISCOVERER_OK) {
    g_printerr ("This URI cannot be played\n");
    //return;
  }
   
  /* If we got no error, show the retrieved information */
   
  g_print ("\nDuration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (gst_discoverer_info_get_duration (info)));
   
  tags = gst_discoverer_info_get_tags (info);
  if (tags) {
    g_print ("Tags:\n");
    gst_tag_list_foreach (tags, print_tag_foreach, GINT_TO_POINTER (1));
  }
   
  g_print ("Seekable: %s\n", (gst_discoverer_info_get_seekable (info) ? "yes" : "no"));
   
  g_print ("\n");
   
  sinfo = gst_discoverer_info_get_stream_info (info);
  if (!sinfo)
    return;
   
  g_print ("Stream information:\n");
   
  print_topology (sinfo, 1);
   
  gst_discoverer_stream_info_unref (sinfo);
   
  g_print ("\n");
}
static void
rygel_media_export_metadata_extractor_on_done (RygelMediaExportMetadataExtractor *self,
                                               GstDiscovererInfo                 *gst_info,
                                               GError                            *err) {
  RygelMediaExportMetadataExtractorPrivate *priv;
  guint signal_id;
  const gchar *uri;
  GeeAbstractMap *abstract_file_hash;
  GstDiscovererResult result;
  GFile *file;

  g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_METADATA_EXTRACTOR (self));
  g_return_if_fail (GST_IS_DISCOVERER_INFO (gst_info));

  priv = self->priv;
  signal_id = 0;
  g_signal_parse_name ("discovered", GST_TYPE_DISCOVERER, &signal_id, NULL, FALSE);
  g_signal_handlers_disconnect_matched (priv->discoverer,
                                        G_SIGNAL_MATCH_ID |
                                        G_SIGNAL_MATCH_FUNC |
                                        G_SIGNAL_MATCH_DATA, signal_id,
                                        0,
                                        NULL,
                                        G_CALLBACK (rygel_media_export_metadata_extractor_on_done_gst_discoverer_discovered),
                                        self);

  g_object_unref (priv->discoverer);
  priv->discoverer = NULL;

  uri = gst_discoverer_info_get_uri (gst_info);
  abstract_file_hash = GEE_ABSTRACT_MAP (priv->file_hash);
  file = G_FILE (gee_abstract_map_get (abstract_file_hash, uri));
  if (!file) {
    g_warning ("File %s already handled, ignoring event", uri);
    return;
  }
  gee_abstract_map_unset (abstract_file_hash, uri, NULL);
  result = gst_discoverer_info_get_result (gst_info);

  if ((result & GST_DISCOVERER_ERROR) == GST_DISCOVERER_ERROR) {
    g_signal_emit (self, signals[ERROR], 0, file, err);
  } else {
    GUPnPDLNAProfile *dlna_profile;

    if ((result & GST_DISCOVERER_TIMEOUT) == GST_DISCOVERER_TIMEOUT) {
      gchar* file_uri = g_file_get_uri (file);

      g_debug ("Extraction timed out on %s", file_uri);
      g_free (file_uri);
      dlna_profile = NULL;
    } else {
      GUPnPDLNAInformation *dlna_info = gupnp_dlna_gst_utils_information_from_discoverer_info (gst_info);

      dlna_profile = gupnp_dlna_profile_guesser_guess_profile_from_info (priv->guesser,
                                                                         dlna_info);
      g_object_unref (dlna_info);
    }

    rygel_media_export_metadata_extractor_extract_basic_information (self,
                                                                     file,
                                                                     gst_info,
                                                                     dlna_profile);
  }

  g_object_unref (file);
}
Beispiel #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;
}
Beispiel #10
0
void Discoverer::on_discovered(GstDiscoverer *discoverer, GstDiscovererInfo *info, GError *err, Gstreamer *gst)
{
    Q_UNUSED(err);
    Q_UNUSED(discoverer);

    Metadata *meta = gst->getMetadata();
    delete meta;

    GstDiscovererResult result;
    result = gst_discoverer_info_get_result(info);
    if (result != GST_DISCOVERER_OK)
    {
        gst->setMetadata(nullptr);
        return;
    }

    meta = new Metadata();

    // is seekable
    meta->setSeekable(gst_discoverer_info_get_seekable(info));
    // extract duration
    qint64 time = gst_discoverer_info_get_duration(info);
    meta->setDuration(UTime(time));
    // extract filename
    QUrl uri(gst_discoverer_info_get_uri(info));
    meta->setFilename(uri.toLocalFile());
    // set filesize
    QFile file(uri.toLocalFile());
    meta->setSize(file.size());

    // extract tags
    const GstTagList *tags;
    tags = gst_discoverer_info_get_tags(info);
    if (tags)
    {
        gst_tag_list_foreach(tags, fillTags, meta);
    }

    GList *list, *iterator;

    // extract video streams
    iterator = list = gst_discoverer_info_get_video_streams(info);
    while (iterator)
    {
        Video video;
        GstDiscovererVideoInfo *vInfo = (GstDiscovererVideoInfo *)iterator->data;
        video.Width = gst_discoverer_video_info_get_width(vInfo);
        video.Height = gst_discoverer_video_info_get_height(vInfo);
        video.Framerate = double(gst_discoverer_video_info_get_framerate_num(vInfo)) /
                          double(gst_discoverer_video_info_get_framerate_denom(vInfo));
        meta->addVideo(video);
        iterator = iterator->next;
    }
    gst_discoverer_stream_info_list_free(list);

    // extract audio streams
    iterator = list = gst_discoverer_info_get_audio_streams(info);
    while (iterator)
    {
        Audio audio;
        GstDiscovererAudioInfo *aInfo = (GstDiscovererAudioInfo *)iterator->data;
        audio.Channels = gst_discoverer_audio_info_get_channels(aInfo);
        audio.SampleRate = gst_discoverer_audio_info_get_sample_rate(aInfo);
        audio.Language = gst_discoverer_audio_info_get_language(aInfo);
        meta->addAudio(audio);
        iterator = iterator->next;
    }
    gst_discoverer_stream_info_list_free(list);

    // extract subtitle streams
    iterator = list = gst_discoverer_info_get_subtitle_streams(info);
    while (iterator)
    {
        Subtitle subtitle;
        GstDiscovererSubtitleInfo *sInfo = (GstDiscovererSubtitleInfo *)iterator->data;
        gst_discoverer_subtitle_info_get_language(sInfo);
        subtitle.Language = gst_discoverer_subtitle_info_get_language(sInfo);
        meta->addSubtitles(subtitle);
        iterator = iterator->next;
    }
    gst_discoverer_stream_info_list_free(list);

    // fill metadata
    gst->setMetadata(meta);
    QObject::connect(gst->getMetadata(), SIGNAL(updated()), gst, SLOT(on_metadata_update()));
}