Commit 8eaf66d0 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts Committed by Tim-Philipp Müller
Browse files

plugins/elements/gstfilesink.*: Fix position reporting; rename data_written...

plugins/elements/gstfilesink.*: Fix position reporting; rename data_written member to current_pos to reflect its real...

Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet be>
* plugins/elements/gstfilesink.c: (gst_file_sink_open_file),
(gst_file_sink_query), (gst_file_sink_do_seek),
(gst_file_sink_get_current_offset), (gst_file_sink_render):
* plugins/elements/gstfilesink.h:
Fix position reporting; rename data_written member to current_pos to
reflect its real meaning (fixes #412648).
parent 466218f4
2007-05-22 Tim-Philipp Müller <tim at centricular dot net>
Patch by: Mark Nauwelaerts <manauw at skynet be>
* plugins/elements/gstfilesink.c: (gst_file_sink_open_file),
(gst_file_sink_query), (gst_file_sink_do_seek),
(gst_file_sink_get_current_offset), (gst_file_sink_render):
* plugins/elements/gstfilesink.h:
Fix position reporting; rename data_written member to current_pos to
reflect its real meaning (fixes #412648).
2007-05-22 Edward Hervey <edward@fluendo.com>
 
* docs/gst/gstreamer-sections.txt:
......
......@@ -83,6 +83,8 @@ static GstFlowReturn gst_file_sink_render (GstBaseSink * sink,
static gboolean gst_file_sink_do_seek (GstFileSink * filesink,
guint64 new_offset);
static gboolean gst_file_sink_get_current_offset (GstFileSink * filesink,
guint64 * p_pos);
static gboolean gst_file_sink_query (GstPad * pad, GstQuery * query);
......@@ -242,7 +244,7 @@ gst_file_sink_open_file (GstFileSink * sink)
if (sink->file == NULL)
goto open_failed;
sink->data_written = 0;
sink->current_pos = 0;
/* try to seek in the file to figure out if it is seekable */
sink->seekable = gst_file_sink_do_seek (sink, 0);
......@@ -302,7 +304,7 @@ gst_file_sink_query (GstPad * pad, GstQuery * query)
switch (format) {
case GST_FORMAT_DEFAULT:
case GST_FORMAT_BYTES:
gst_query_set_position (query, GST_FORMAT_BYTES, self->data_written);
gst_query_set_position (query, GST_FORMAT_BYTES, self->current_pos);
return TRUE;
default:
return FALSE;
......@@ -346,6 +348,10 @@ gst_file_sink_do_seek (GstFileSink * filesink, guint64 new_offset)
goto seek_failed;
#endif
/* adjust position reporting after seek;
* presumably this should basically yield new_offset */
gst_file_sink_get_current_offset (filesink, &filesink->current_pos);
return TRUE;
/* ERRORS */
......@@ -438,7 +444,8 @@ gst_file_sink_get_current_offset (GstFileSink * filesink, guint64 * p_pos)
ret = (off_t) ftell (filesink->file);
#endif
*p_pos = (guint64) ret;
if (ret != (off_t) - 1)
*p_pos = (guint64) ret;
return (ret != (off_t) - 1);
}
......@@ -447,32 +454,20 @@ static GstFlowReturn
gst_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
{
GstFileSink *filesink;
guint64 cur_pos;
guint size;
guint64 back_pending = 0;
size = GST_BUFFER_SIZE (buffer);
filesink = GST_FILE_SINK (sink);
if (filesink->seekable) {
if (!gst_file_sink_get_current_offset (filesink, &cur_pos))
goto handle_error;
} else {
cur_pos = filesink->data_written;
}
if (cur_pos < filesink->data_written)
back_pending = filesink->data_written - cur_pos;
GST_DEBUG_OBJECT (filesink, "writing %u bytes at %" G_GUINT64_FORMAT,
size, cur_pos);
size, filesink->current_pos);
if (size > 0 && GST_BUFFER_DATA (buffer) != NULL) {
if (fwrite (GST_BUFFER_DATA (buffer), size, 1, filesink->file) != 1)
goto handle_error;
filesink->data_written += size - back_pending;
filesink->current_pos += size;
}
return GST_FLOW_OK;
......
......@@ -57,7 +57,7 @@ struct _GstFileSink {
FILE *file;
gboolean seekable;
guint64 data_written;
guint64 current_pos;
};
struct _GstFileSinkClass {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment