From 96e954852fe963847c24779e18cd9ca4c17420da Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Sat, 30 Jul 2005 15:00:07 +0000 Subject: [PATCH] configure.ac: Use AC_SYS_LARGEFILE, which will set _FILE_OFFSET_BITS=64 and _LARGEFILE_SOURCE in config.h as required... Original commit message from CVS: * configure.ac: Use AC_SYS_LARGEFILE, which will set _FILE_OFFSET_BITS=64 and _LARGEFILE_SOURCE in config.h as required. Do not export those flags in our .pc files any longer (#142209). Remove unused GST_DISABLE_OMEGA_COTHREADS stuff. * gst/elements/gstfilesink.c: (gst_file_sink_class_init), (gst_file_sink_do_seek), (gst_file_sink_event), (gst_file_sink_get_current_offset), (gst_file_sink_render): Redo seek/tell calls with large file support in mind; add some debugging messages; add log message that tells us when large file support is unavailable or not enabled for some reason. * gst/elements/gstfilesrc.c: (gst_file_src_class_init): Add log message that tells us when large file support is unavailable or not enabled for some reason. --- ChangeLog | 20 ++++++++++++ configure.ac | 37 +++------------------ gst/elements/gstfilesink.c | 73 +++++++++++++++++++++++++++++++++--------- gst/elements/gstfilesrc.c | 4 +++ plugins/elements/gstfilesink.c | 73 +++++++++++++++++++++++++++++++++--------- plugins/elements/gstfilesrc.c | 4 +++ 6 files changed, 147 insertions(+), 64 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88caec3..340cf14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2005-07-30 Tim-Philipp Müller + + * configure.ac: + Use AC_SYS_LARGEFILE, which will set _FILE_OFFSET_BITS=64 + and _LARGEFILE_SOURCE in config.h as required. Do not + export those flags in our .pc files any longer (#142209). + + Remove unused GST_DISABLE_OMEGA_COTHREADS stuff. + + * gst/elements/gstfilesink.c: (gst_file_sink_class_init), + (gst_file_sink_do_seek), (gst_file_sink_event), + (gst_file_sink_get_current_offset), (gst_file_sink_render): + Redo seek/tell calls with large file support in mind; add some + debugging messages; add log message that tells us when large + file support is unavailable or not enabled for some reason. + + * gst/elements/gstfilesrc.c: (gst_file_src_class_init): + Add log message that tells us when large file support + is unavailable or not enabled for some reason. + 2005-07-29 Wim Taymans * check/gst/gstghostpad.c: (GST_START_TEST), (gst_ghost_pad_suite): diff --git a/configure.ac b/configure.ac index ff3024c..1d05ae0 100644 --- a/configure.ac +++ b/configure.ac @@ -1,3 +1,5 @@ +AC_PREREQ(2.52) + AC_INIT AC_CANONICAL_TARGET @@ -147,41 +149,12 @@ if test x$FLEX_PATH = xno; then AC_MSG_ERROR(Could not find flex) fi -dnl -dnl We should really use AC_SYS_LARGEFILE, but the problem is -dnl many of the plugins don't include "config.h". To assure -dnl binary compatibility, it is necessary that all gstreamer -dnl code be compiled with the same sizeof(off_t), so we use -dnl the following crude hack. -dnl - -AC_MSG_CHECKING(for large file support) -AC_TRY_RUN([ -#define _LARGEFILE_SOURCE -#define _FILE_OFFSET_BITS 64 -#include -int main () { return !(sizeof(off_t) == 8); } -], -[ - AC_MSG_RESULT(yes) - GST_PKG_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" -], -[ - AC_MSG_RESULT(no) -], -[ - AC_MSG_RESULT(no) -]) +dnl check for large file support (affected +dnl plugins must include config.h for this) +AC_SYS_LARGEFILE dnl check for mmap AC_FUNC_MMAP() -if test "$ac_cv_func_mmap_fixed_mapped" = "yes" ; then - GST_DISABLE_OMEGA_COTHREADS=no -else - GST_DISABLE_OMEGA_COTHREADS=yes -fi -dnl for future --disabling, maybe. Right now, it depends on HAVE_MMAP -AM_CONDITIONAL(GST_DISABLE_OMEGA_COTHREADS, test "x$GST_DISABLE_OMEGA_COTHREADS" = "xyes") dnl check for makecontext and define HAVE_MAKECONTEXT if we have it AC_CHECK_MCSC() diff --git a/gst/elements/gstfilesink.c b/gst/elements/gstfilesink.c index b2bc2e1..8fbaf2a 100644 --- a/gst/elements/gstfilesink.c +++ b/gst/elements/gstfilesink.c @@ -135,6 +135,10 @@ gst_file_sink_class_init (GstFileSinkClass * klass) gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_file_sink_render); gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_file_sink_event); + + if (sizeof (off_t) < 8) { + GST_LOG ("No large file support, sizeof (off_t) = %u", sizeof (off_t)); + } } static void @@ -282,6 +286,24 @@ gst_file_sink_query (GstPad * pad, GstQuery * query) } } +static void +gst_file_sink_do_seek (GstFileSink * filesink, guint64 new_offset) +{ + GST_DEBUG_OBJECT (filesink, "Seeking to offset %" G_GUINT64_FORMAT, + new_offset); + +#ifdef G_OS_UNIX + if (lseek (fileno (filesink->file), (off_t) new_offset, + SEEK_SET) != (off_t) - 1) + return; +#else + if (fseek (filesink->file, (long) new_offset, SEEK_SET) == 0) + return; +#endif + + GST_DEBUG_OBJECT (filesink, "Seeking failed: %s", g_strerror (errno)); +} + /* handle events (search) */ static gboolean gst_file_sink_event (GstBaseSink * sink, GstEvent * event) @@ -303,7 +325,9 @@ gst_file_sink_event (GstBaseSink * sink, GstEvent * event) NULL); if (format == GST_FORMAT_BYTES) { - fseek (filesink->file, soffset, SEEK_SET); + gst_file_sink_do_seek (filesink, (guint64) soffset); + } else { + GST_DEBUG ("Ignored NEWSEGMENT event of format %u", (guint) format); } break; } @@ -321,36 +345,53 @@ gst_file_sink_event (GstBaseSink * sink, GstEvent * event) return TRUE; } -/** - * gst_file_sink_chain: - * @pad: the pad this filesink is connected to - * @buf: the buffer that has to be absorbed - * - * take the buffer from the pad and write to file if it's open - */ +static gboolean +gst_file_sink_get_current_offset (GstFileSink * filesink, guint64 * p_pos) +{ + off_t ret; + +#ifdef G_OS_UNIX + ret = lseek (fileno (filesink->file), 0, SEEK_CUR); +#else + ret = (off_t) ftell (filesink->file); +#endif + + *p_pos = (guint64) ret; + + return (ret != (off_t) - 1); +} + static GstFlowReturn gst_file_sink_render (GstBaseSink * sink, GstBuffer * buffer) { GstFileSink *filesink; + guint64 cur_pos; guint size, back_pending = 0; size = GST_BUFFER_SIZE (buffer); filesink = GST_FILE_SINK (sink); - if (ftell (filesink->file) < filesink->data_written) - back_pending = filesink->data_written - ftell (filesink->file); + if (!gst_file_sink_get_current_offset (filesink, &cur_pos)) + goto handle_error; - if (fwrite (GST_BUFFER_DATA (buffer), size, 1, filesink->file) != 1) { - GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, - (_("Error while writing to file \"%s\"."), filesink->filename), - ("%s", g_strerror (errno))); - return GST_FLOW_ERROR; - } + if (cur_pos < filesink->data_written) + back_pending = filesink->data_written - cur_pos; + + if (fwrite (GST_BUFFER_DATA (buffer), size, 1, filesink->file) != 1) + goto handle_error; filesink->data_written += size - back_pending; return GST_FLOW_OK; + +handle_error: + + GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, + (_("Error while writing to file \"%s\"."), filesink->filename), + ("%s", g_strerror (errno))); + + return GST_FLOW_ERROR; } static GstElementStateReturn diff --git a/gst/elements/gstfilesrc.c b/gst/elements/gstfilesrc.c index 205af2f..a5de170 100644 --- a/gst/elements/gstfilesrc.c +++ b/gst/elements/gstfilesrc.c @@ -207,6 +207,10 @@ gst_file_src_class_init (GstFileSrcClass * klass) gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_file_src_is_seekable); gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_file_src_get_size); gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_file_src_create); + + if (sizeof (off_t) < 8) { + GST_LOG ("No large file support, sizeof (off_t) = %u!", sizeof (off_t)); + } } static void diff --git a/plugins/elements/gstfilesink.c b/plugins/elements/gstfilesink.c index b2bc2e1..8fbaf2a 100644 --- a/plugins/elements/gstfilesink.c +++ b/plugins/elements/gstfilesink.c @@ -135,6 +135,10 @@ gst_file_sink_class_init (GstFileSinkClass * klass) gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_file_sink_render); gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_file_sink_event); + + if (sizeof (off_t) < 8) { + GST_LOG ("No large file support, sizeof (off_t) = %u", sizeof (off_t)); + } } static void @@ -282,6 +286,24 @@ gst_file_sink_query (GstPad * pad, GstQuery * query) } } +static void +gst_file_sink_do_seek (GstFileSink * filesink, guint64 new_offset) +{ + GST_DEBUG_OBJECT (filesink, "Seeking to offset %" G_GUINT64_FORMAT, + new_offset); + +#ifdef G_OS_UNIX + if (lseek (fileno (filesink->file), (off_t) new_offset, + SEEK_SET) != (off_t) - 1) + return; +#else + if (fseek (filesink->file, (long) new_offset, SEEK_SET) == 0) + return; +#endif + + GST_DEBUG_OBJECT (filesink, "Seeking failed: %s", g_strerror (errno)); +} + /* handle events (search) */ static gboolean gst_file_sink_event (GstBaseSink * sink, GstEvent * event) @@ -303,7 +325,9 @@ gst_file_sink_event (GstBaseSink * sink, GstEvent * event) NULL); if (format == GST_FORMAT_BYTES) { - fseek (filesink->file, soffset, SEEK_SET); + gst_file_sink_do_seek (filesink, (guint64) soffset); + } else { + GST_DEBUG ("Ignored NEWSEGMENT event of format %u", (guint) format); } break; } @@ -321,36 +345,53 @@ gst_file_sink_event (GstBaseSink * sink, GstEvent * event) return TRUE; } -/** - * gst_file_sink_chain: - * @pad: the pad this filesink is connected to - * @buf: the buffer that has to be absorbed - * - * take the buffer from the pad and write to file if it's open - */ +static gboolean +gst_file_sink_get_current_offset (GstFileSink * filesink, guint64 * p_pos) +{ + off_t ret; + +#ifdef G_OS_UNIX + ret = lseek (fileno (filesink->file), 0, SEEK_CUR); +#else + ret = (off_t) ftell (filesink->file); +#endif + + *p_pos = (guint64) ret; + + return (ret != (off_t) - 1); +} + static GstFlowReturn gst_file_sink_render (GstBaseSink * sink, GstBuffer * buffer) { GstFileSink *filesink; + guint64 cur_pos; guint size, back_pending = 0; size = GST_BUFFER_SIZE (buffer); filesink = GST_FILE_SINK (sink); - if (ftell (filesink->file) < filesink->data_written) - back_pending = filesink->data_written - ftell (filesink->file); + if (!gst_file_sink_get_current_offset (filesink, &cur_pos)) + goto handle_error; - if (fwrite (GST_BUFFER_DATA (buffer), size, 1, filesink->file) != 1) { - GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, - (_("Error while writing to file \"%s\"."), filesink->filename), - ("%s", g_strerror (errno))); - return GST_FLOW_ERROR; - } + if (cur_pos < filesink->data_written) + back_pending = filesink->data_written - cur_pos; + + if (fwrite (GST_BUFFER_DATA (buffer), size, 1, filesink->file) != 1) + goto handle_error; filesink->data_written += size - back_pending; return GST_FLOW_OK; + +handle_error: + + GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, + (_("Error while writing to file \"%s\"."), filesink->filename), + ("%s", g_strerror (errno))); + + return GST_FLOW_ERROR; } static GstElementStateReturn diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c index 205af2f..a5de170 100644 --- a/plugins/elements/gstfilesrc.c +++ b/plugins/elements/gstfilesrc.c @@ -207,6 +207,10 @@ gst_file_src_class_init (GstFileSrcClass * klass) gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_file_src_is_seekable); gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_file_src_get_size); gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_file_src_create); + + if (sizeof (off_t) < 8) { + GST_LOG ("No large file support, sizeof (off_t) = %u!", sizeof (off_t)); + } } static void -- 2.7.4