From 7d5fda88d4e88edb3b49e331ad54871052853144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Sun, 23 Oct 2005 10:29:51 +0000 Subject: [PATCH] gst/elements/gstfilesink.c: Use fseeko() and ftello() if available. When falling back on lseek() to get the current o... Original commit message from CVS: * gst/elements/gstfilesink.c: (gst_file_sink_do_seek), (gst_file_sink_get_current_offset): Use fseeko() and ftello() if available. When falling back on lseek() to get the current offset, fflush() first to make sure everything is up-to-date and we get the right offset. --- ChangeLog | 8 ++++++++ gst/elements/gstfilesink.c | 25 +++++++++++++++++++++---- plugins/elements/gstfilesink.c | 25 +++++++++++++++++++++---- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9830b8f8fe..5b5f2d25b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-10-23 Tim-Philipp Müller + + * gst/elements/gstfilesink.c: (gst_file_sink_do_seek), + (gst_file_sink_get_current_offset): + Use fseeko() and ftello() if available. When falling back on + lseek() to get the current offset, fflush() first to make sure + everything is up-to-date and we get the right offset. + 2005-10-23 Thomas Vander Stichele * gst/base/gstbasesink.c: (gst_base_sink_handle_object): diff --git a/gst/elements/gstfilesink.c b/gst/elements/gstfilesink.c index 8b5187d0cb..0e050001fb 100644 --- a/gst/elements/gstfilesink.c +++ b/gst/elements/gstfilesink.c @@ -298,16 +298,27 @@ gst_file_sink_query (GstPad * pad, GstQuery * query) } } +#if HAVE_FSEEKO +# define __GST_STDIO_SEEK_FUNCTION "fseeko" +#elif G_OS_UNIX +# define __GST_STDIO_SEEK_FUNCTION "lseek" +#else +# define __GST_STDIO_SEEK_FUNCTION "fseek" +#endif + static void gst_file_sink_do_seek (GstFileSink * filesink, guint64 new_offset) { - GST_DEBUG_OBJECT (filesink, "Seeking to offset %" G_GUINT64_FORMAT, - new_offset); + GST_DEBUG_OBJECT (filesink, "Seeking to offset %" G_GUINT64_FORMAT + " using " __GST_STDIO_SEEK_FUNCTION, new_offset); if (fflush (filesink->file)) goto flush_failed; -#ifdef G_OS_UNIX +#if HAVE_FSEEKO + if (fseeko (filesink->file, (off_t) new_offset, SEEK_SET) != 0) + goto seek_failed; +#elif G_OS_UNIX if (lseek (fileno (filesink->file), (off_t) new_offset, SEEK_SET) == (off_t) - 1) goto seek_failed; @@ -377,7 +388,13 @@ gst_file_sink_get_current_offset (GstFileSink * filesink, guint64 * p_pos) { off_t ret; -#ifdef G_OS_UNIX +#if HAVE_FTELLO + ret = ftello (filesink->file); +#elif G_OS_UNIX + if (fflush (filesink->file)) { + GST_DEBUG_OBJECT (filesink, "Flush failed: %s", g_strerror (errno)); + /* ignore and continue */ + } ret = lseek (fileno (filesink->file), 0, SEEK_CUR); #else ret = (off_t) ftell (filesink->file); diff --git a/plugins/elements/gstfilesink.c b/plugins/elements/gstfilesink.c index 8b5187d0cb..0e050001fb 100644 --- a/plugins/elements/gstfilesink.c +++ b/plugins/elements/gstfilesink.c @@ -298,16 +298,27 @@ gst_file_sink_query (GstPad * pad, GstQuery * query) } } +#if HAVE_FSEEKO +# define __GST_STDIO_SEEK_FUNCTION "fseeko" +#elif G_OS_UNIX +# define __GST_STDIO_SEEK_FUNCTION "lseek" +#else +# define __GST_STDIO_SEEK_FUNCTION "fseek" +#endif + static void gst_file_sink_do_seek (GstFileSink * filesink, guint64 new_offset) { - GST_DEBUG_OBJECT (filesink, "Seeking to offset %" G_GUINT64_FORMAT, - new_offset); + GST_DEBUG_OBJECT (filesink, "Seeking to offset %" G_GUINT64_FORMAT + " using " __GST_STDIO_SEEK_FUNCTION, new_offset); if (fflush (filesink->file)) goto flush_failed; -#ifdef G_OS_UNIX +#if HAVE_FSEEKO + if (fseeko (filesink->file, (off_t) new_offset, SEEK_SET) != 0) + goto seek_failed; +#elif G_OS_UNIX if (lseek (fileno (filesink->file), (off_t) new_offset, SEEK_SET) == (off_t) - 1) goto seek_failed; @@ -377,7 +388,13 @@ gst_file_sink_get_current_offset (GstFileSink * filesink, guint64 * p_pos) { off_t ret; -#ifdef G_OS_UNIX +#if HAVE_FTELLO + ret = ftello (filesink->file); +#elif G_OS_UNIX + if (fflush (filesink->file)) { + GST_DEBUG_OBJECT (filesink, "Flush failed: %s", g_strerror (errno)); + /* ignore and continue */ + } ret = lseek (fileno (filesink->file), 0, SEEK_CUR); #else ret = (off_t) ftell (filesink->file);