Skip to content

Commit

Permalink
encoder: add ability to encode to a temporary file
Browse files Browse the repository at this point in the history
When given RB_ENCODER_DEST_TEMPFILE as the destination uri, the
encoder will now open a temporary file and write to that.  The
destination uri in the 'completed' signal will be that of the
temporary file.
  • Loading branch information
Jonathan Matthew committed Aug 5, 2018
1 parent 583f345 commit 2c45219
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions backends/gstreamer/rb-encoder-gst.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct _RBEncoderGstPrivate {
GCancellable *open_cancel;
GTask *open_task;

int tmpfile_fd;

GError *error;
};
Expand Down Expand Up @@ -198,6 +199,12 @@ bus_watch_cb (GstBus *bus, GstMessage *message, gpointer data)
NULL,
(GAsyncReadyCallback) output_close_cb,
g_object_ref (encoder));
} else if (encoder->priv->tmpfile_fd) {
rb_debug ("received EOS, closing temp file");
close (encoder->priv->tmpfile_fd);
encoder->priv->tmpfile_fd = 0;

rb_encoder_gst_emit_completed (encoder);
} else {
rb_debug ("received EOS, but there's no output stream");
rb_encoder_gst_emit_completed (encoder);
Expand Down Expand Up @@ -630,6 +637,36 @@ sink_open (GTask *task, gpointer source_object, gpointer task_data, GCancellable
RBEncoderGst *encoder = RB_ENCODER_GST (source_object);
GError *error = NULL;

if (g_str_equal (encoder->priv->dest_uri, RB_ENCODER_DEST_TEMPFILE)) {
GFile *tmpfile;
char *tmpfile_name;

encoder->priv->tmpfile_fd = g_file_open_tmp ("rb-encoder-XXXXXX",
&tmpfile_name,
&error);
if (error != NULL) {
g_set_error (&error, RB_ENCODER_ERROR, RB_ENCODER_ERROR_FILE_ACCESS,
_("Could not create a temporary file to write to: %s"),
error->message);
g_task_return_error (task, error);
g_object_unref (task);
return;
}

rb_debug ("opened temporary file %s", tmpfile_name);
encoder->priv->sink = gst_element_factory_make ("fdsink", NULL);
g_object_set (encoder->priv->sink, "fd", encoder->priv->tmpfile_fd, NULL);

tmpfile = g_file_new_for_commandline_arg (tmpfile_name);
g_free (encoder->priv->dest_uri);
encoder->priv->dest_uri = g_file_get_uri (tmpfile);
g_object_unref (tmpfile);
g_free (tmpfile_name);

g_task_return_boolean (task, TRUE);
return;
}

encoder->priv->sink = gst_element_factory_make ("giostreamsink", NULL);
if (encoder->priv->sink != NULL) {
GFile *file;
Expand Down
2 changes: 2 additions & 0 deletions backends/rb-encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ typedef enum
RB_ENCODER_ERROR_DEST_EXISTS
} RBEncoderError;

#define RB_ENCODER_DEST_TEMPFILE "x-rb-tmp://"

GType rb_encoder_error_get_type (void);
#define RB_TYPE_ENCODER_ERROR (rb_encoder_error_get_type())
#define RB_ENCODER_ERROR rb_encoder_error_quark ()
Expand Down

0 comments on commit 2c45219

Please sign in to comment.