From: <wt...@ke...> - 2006-06-16 16:28:54
|
CVS Root: /cvs/gstreamer Module: gstreamer Changes by: wtay Date: Fri Jun 16 2006 16:28:49 UTC Log message: * plugins/elements/gstfilesink.c: (gst_file_sink_open_file), (gst_file_sink_close_file), (gst_file_sink_do_seek), (gst_file_sink_event), (gst_file_sink_render): * plugins/elements/gstfilesink.h: Check if we can seek in the file instead of assuming we always can. Post an error when we are asked to seek in a non-seekable file (like a fifo). Fixes #343312. Some cleanups. Modified files: . : ChangeLog plugins/elements: gstfilesink.c gstfilesink.h Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/ChangeLog.diff?r1=1.2610&r2=1.2611 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/plugins/elements/gstfilesink.c.diff?r1=1.76&r2=1.77 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/plugins/elements/gstfilesink.h.diff?r1=1.14&r2=1.15 ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /cvs/gstreamer/gstreamer/ChangeLog,v retrieving revision 1.2610 retrieving revision 1.2611 diff -u -d -r1.2610 -r1.2611 --- ChangeLog 16 Jun 2006 14:31:07 -0000 1.2610 +++ ChangeLog 16 Jun 2006 16:28:37 -0000 1.2611 @@ -1,3 +1,14 @@ +2006-06-16 Wim Taymans <wi...@fl...> + + * plugins/elements/gstfilesink.c: (gst_file_sink_open_file), + (gst_file_sink_close_file), (gst_file_sink_do_seek), + (gst_file_sink_event), (gst_file_sink_render): + * plugins/elements/gstfilesink.h: + Check if we can seek in the file instead of assuming + we always can. Post an error when we are asked to seek in a + non-seekable file (like a fifo). Fixes #343312. + Some cleanups. 2006-06-16 Tim-Philipp Müller <tim at centricular dot net> * tools/gst-launch.1.in: Index: gstfilesink.c RCS file: /cvs/gstreamer/gstreamer/plugins/elements/gstfilesink.c,v retrieving revision 1.76 retrieving revision 1.77 diff -u -d -r1.76 -r1.77 --- gstfilesink.c 11 May 2006 18:10:33 -0000 1.76 +++ gstfilesink.c 16 Jun 2006 16:28:37 -0000 1.77 @@ -1,6 +1,7 @@ /* GStreamer * Copyright (C) 1999,2000 Erik Walthinsen <om...@cs...> * 2000 Wim Taymans <wt...@ch...> + * 2006 Wim Taymans <wi...@fl...> * * gstfilesink.c: @@ -80,6 +81,9 @@ static GstFlowReturn gst_file_sink_render (GstBaseSink * sink, GstBuffer * buffer); +static gboolean gst_file_sink_do_seek (GstFileSink * filesink, + guint64 new_offset); static gboolean gst_file_sink_query (GstPad * pad, GstQuery * query); static void gst_file_sink_uri_handler_init (gpointer g_iface, @@ -225,33 +229,55 @@ gst_file_sink_open_file (GstFileSink * sink) { /* open the file */ - if (sink->filename == NULL || sink->filename[0] == '\0') { + if (sink->filename == NULL || sink->filename[0] == '\0') + goto no_filename; + sink->file = fopen (sink->filename, "wb"); + if (sink->file == NULL) + goto open_failed; + sink->data_written = 0; + /* try to seek in the file to figure out if it is seekable */ + sink->seekable = gst_file_sink_do_seek (sink, 0); + GST_DEBUG_OBJECT (sink, "opened file %s, seekable %d", + sink->filename, sink->seekable); + return TRUE; + /* ERRORS */ +no_filename: + { GST_ELEMENT_ERROR (sink, RESOURCE, NOT_FOUND, (_("No file name specified for writing.")), (NULL)); return FALSE; } - - sink->file = fopen (sink->filename, "wb"); - if (sink->file == NULL) { +open_failed: GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (_("Could not open file \"%s\" for writing."), sink->filename), GST_ERROR_SYSTEM); - sink->data_written = 0; - return TRUE; } static void gst_file_sink_close_file (GstFileSink * sink) if (sink->file) { - if (fclose (sink->file) != 0) { - GST_ELEMENT_ERROR (sink, RESOURCE, CLOSE, - (_("Error closing file \"%s\"."), sink->filename), GST_ERROR_SYSTEM); - } + if (fclose (sink->file) != 0) + goto close_failed; + GST_DEBUG_OBJECT (sink, "closed file"); + } + return; +close_failed: + GST_ELEMENT_ERROR (sink, RESOURCE, CLOSE, + (_("Error closing file \"%s\"."), sink->filename), GST_ERROR_SYSTEM); + return; @@ -292,7 +318,7 @@ # define __GST_STDIO_SEEK_FUNCTION "fseek" #endif -static void +static gboolean gst_file_sink_do_seek (GstFileSink * filesink, guint64 new_offset) GST_DEBUG_OBJECT (filesink, "Seeking to offset %" G_GUINT64_FORMAT @@ -313,18 +339,18 @@ goto seek_failed; - return; /* ERRORS */ flush_failed: { GST_DEBUG_OBJECT (filesink, "Flush failed: %s", g_strerror (errno)); - return; + return FALSE; seek_failed: GST_DEBUG_OBJECT (filesink, "Seeking failed: %s", g_strerror (errno)); @@ -349,24 +375,39 @@ &eoffset, NULL); if (format == GST_FORMAT_BYTES) { - gst_file_sink_do_seek (filesink, (guint64) soffset); + if (!gst_file_sink_do_seek (filesink, (guint64) soffset)) + goto seek_failed; } else { - GST_DEBUG ("Ignored NEWSEGMENT event of format %u", (guint) format); + GST_DEBUG ("Ignored NEWSEGMENT event of format %u (%s)", + (guint) format, gst_format_get_name (format)); } break; } case GST_EVENT_EOS: - if (fflush (filesink->file)) { - GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, - (_("Error while writing to file \"%s\"."), filesink->filename), - GST_ERROR_SYSTEM); - } + if (fflush (filesink->file)) + goto flush_failed; default: return TRUE; +seek_failed: + GST_ELEMENT_ERROR (filesink, RESOURCE, SEEK, + (_("Error while seeking in file \"%s\"."), filesink->filename), + GST_ERROR_SYSTEM); +flush_failed: + GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, + (_("Error while writing to file \"%s\"."), filesink->filename), static gboolean @@ -403,8 +444,12 @@ filesink = GST_FILE_SINK (sink); - if (!gst_file_sink_get_current_offset (filesink, &cur_pos)) - goto handle_error; + 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; Index: gstfilesink.h RCS file: /cvs/gstreamer/gstreamer/plugins/elements/gstfilesink.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- gstfilesink.h 1 Jun 2006 18:22:14 -0000 1.14 +++ gstfilesink.h 16 Jun 2006 16:28:37 -0000 1.15 @@ -56,6 +56,7 @@ gchar *uri; FILE *file; + gboolean seekable; guint64 data_written; }; |