Пример #1
0
static gboolean
is_network_stream (GInputStream *stream)
{
	while (G_IS_FILTER_INPUT_STREAM (stream))
		stream = G_FILTER_INPUT_STREAM (stream)->base_stream;

	return !G_IS_FILE_INPUT_STREAM (stream);
}
Пример #2
0
/**
 * ev_document_factory_get_document_for_stream:
 * @stream: a #GInputStream
 * @mime_type: (allow-none): a mime type hint
 * @flags: flags from #EvDocumentLoadFlags
 * @cancellable: (allow-none): a #GCancellable, or %NULL
 * @error: (allow-none): a #GError location to store an error, or %NULL
 *
 * Synchronously creates a #EvDocument for the document from @stream; or, if no
 * backend handling the document's type is found, or an error occurred
 * on opening the document, returns %NULL and fills in @error.
 * If the document is encrypted, it is returned but also @error is set to
 * %EV_DOCUMENT_ERROR_ENCRYPTED.
 *
 * If @mime_type is non-%NULL, this overrides any type inferred from the stream.
 * If the mime type cannot be inferred from the stream, and @mime_type is %NULL,
 * an error is returned.
 *
 * Returns: (transfer full): a new #EvDocument, or %NULL
 *
 * Since: 3.6
 */
EvDocument*
ev_document_factory_get_document_for_stream (GInputStream *stream,
                                             const char *mime_type,
                                             EvDocumentLoadFlags flags,
                                             GCancellable *cancellable,
                                             GError **error)
{
        EvDocument *document;
        char *mime = NULL;

        g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL);
        g_return_val_if_fail (error == NULL || *error == NULL, NULL);

        if (mime_type == NULL && G_IS_FILE_INPUT_STREAM (stream)) {
                GFileInfo *file_info;
                const char *content_type;

                file_info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (stream),
                                                            G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
                                                            cancellable,
                                                            error);
                if (file_info != NULL) {
                        content_type = g_file_info_get_content_type (file_info);
                        if (content_type)
                                mime_type = mime = g_content_type_get_mime_type (content_type);
                        g_object_unref (file_info);
                }
        }

        if (mime_type == NULL) {
                g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                                     "Cannot query mime type from stream");
                return NULL;
        }

        document = ev_document_factory_new_document_for_mime_type (mime_type, error);
        g_free (mime);

        if (document == NULL)
                return NULL;

        if (!ev_document_load_stream (document, stream, flags, cancellable, error)) {
                g_object_unref (document);
                return NULL;
        }

        return document;
}
Пример #3
0
static gboolean
gst_gio_base_src_get_size (GstBaseSrc * base_src, guint64 * size)
{
  GstGioBaseSrc *src = GST_GIO_BASE_SRC (base_src);

  if (G_IS_FILE_INPUT_STREAM (src->stream)) {
    GFileInfo *info;
    GError *err = NULL;

    info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (src->stream),
        G_FILE_ATTRIBUTE_STANDARD_SIZE, src->cancel, &err);

    if (info != NULL) {
      *size = g_file_info_get_size (info);
      g_object_unref (info);
      GST_DEBUG_OBJECT (src, "found size: %" G_GUINT64_FORMAT, *size);
      return TRUE;
    }

    if (!gst_gio_error (src, "g_file_input_stream_query_info", &err, NULL)) {

      if (GST_GIO_ERROR_MATCHES (err, NOT_SUPPORTED))
        GST_DEBUG_OBJECT (src, "size information not available");
      else
        GST_WARNING_OBJECT (src, "size information retrieval failed: %s",
            err->message);

      g_clear_error (&err);
    }
  }

  if (GST_GIO_STREAM_IS_SEEKABLE (src->stream)) {
    goffset old;
    goffset stream_size;
    gboolean ret;
    GSeekable *seekable = G_SEEKABLE (src->stream);
    GError *err = NULL;

    old = g_seekable_tell (seekable);

    ret = g_seekable_seek (seekable, 0, G_SEEK_END, src->cancel, &err);
    if (!ret) {
      if (!gst_gio_error (src, "g_seekable_seek", &err, NULL)) {
        if (GST_GIO_ERROR_MATCHES (err, NOT_SUPPORTED))
          GST_DEBUG_OBJECT (src,
              "Seeking to the end of stream is not supported");
        else
          GST_WARNING_OBJECT (src, "Seeking to end of stream failed: %s",
              err->message);
        g_clear_error (&err);
      } else {
        GST_WARNING_OBJECT (src, "Seeking to end of stream failed");
      }
      return FALSE;
    }

    stream_size = g_seekable_tell (seekable);

    ret = g_seekable_seek (seekable, old, G_SEEK_SET, src->cancel, &err);
    if (!ret) {
      if (!gst_gio_error (src, "g_seekable_seek", &err, NULL)) {
        if (GST_GIO_ERROR_MATCHES (err, NOT_SUPPORTED))
          GST_ERROR_OBJECT (src, "Seeking to the old position not supported");
        else
          GST_ERROR_OBJECT (src, "Seeking to the old position failed: %s",
              err->message);
        g_clear_error (&err);
      } else {
        GST_ERROR_OBJECT (src, "Seeking to the old position faile");
      }
      return FALSE;
    }

    if (stream_size >= 0) {
      *size = stream_size;
      return TRUE;
    }
  }

  return FALSE;
}