From e15bff77fb4dcd9f36e9559f50981906bcfc9757 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Mon, 4 Apr 2011 15:56:50 +0300 Subject: [PATCH 01/12] Automatic update of common submodule From 1ccbe09 to c3cafe1 --- common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common b/common index 1ccbe098d6..c3cafe123f 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 1ccbe098d6379612fcef09f4000da23585af980a +Subproject commit c3cafe123f3a363d337a29ad32fdd6d3631f52c0 From 7b142178e4f26d23248928133e38e64649b9d317 Mon Sep 17 00:00:00 2001 From: Haakon Sporsheim Date: Mon, 4 Apr 2011 17:23:13 +0200 Subject: [PATCH 02/12] tag: Explicit cast to GThreadFunc to silence MS compiler. https://bugzilla.gnome.org/show_bug.cgi?id=646744 --- gst-libs/gst/tag/gstxmptag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gst-libs/gst/tag/gstxmptag.c b/gst-libs/gst/tag/gstxmptag.c index dce3e416d3..6c424baebb 100644 --- a/gst-libs/gst/tag/gstxmptag.c +++ b/gst-libs/gst/tag/gstxmptag.c @@ -837,7 +837,7 @@ deserialize_tiff_orientation (XmpTag * xmptag, GstTagList * taglist, * http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/XMP.html */ static gpointer -_init_xmp_tag_map () +_init_xmp_tag_map (gpointer user_data) { GPtrArray *array; XmpTag *xmpinfo; @@ -984,7 +984,7 @@ static void xmp_tags_initialize () { static GOnce my_once = G_ONCE_INIT; - g_once (&my_once, _init_xmp_tag_map, NULL); + g_once (&my_once, (GThreadFunc)_init_xmp_tag_map, NULL); } typedef struct _GstXmpNamespaceMatch GstXmpNamespaceMatch; From f7036eb26027dd5d08a8f88f3165f74dab2ac73d Mon Sep 17 00:00:00 2001 From: Haakon Sporsheim Date: Mon, 4 Apr 2011 17:23:53 +0200 Subject: [PATCH 03/12] tag: Remove constness to silence MS compiler. https://bugzilla.gnome.org/show_bug.cgi?id=646744 --- gst-libs/gst/tag/xmpwriter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gst-libs/gst/tag/xmpwriter.c b/gst-libs/gst/tag/xmpwriter.c index 573224cb1d..23282b8a32 100644 --- a/gst-libs/gst/tag/xmpwriter.c +++ b/gst-libs/gst/tag/xmpwriter.c @@ -297,7 +297,6 @@ gst_tag_xmp_writer_tag_list_to_xmp_buffer (GstTagXmpWriter * config, { GstTagXmpWriterData *data; GstBuffer *buf = NULL; - const gchar **array; gint i = 0; GSList *iter; @@ -307,12 +306,13 @@ gst_tag_xmp_writer_tag_list_to_xmp_buffer (GstTagXmpWriter * config, g_static_mutex_lock (&data->lock); if (data->schemas) { - array = g_new0 (const gchar *, g_slist_length (data->schemas) + 1); + gchar **array = g_new0 (gchar *, g_slist_length (data->schemas) + 1); if (array) { for (iter = data->schemas; iter; iter = g_slist_next (iter)) { - array[i++] = (const gchar *) iter->data; + array[i++] = (gchar *) iter->data; } - buf = gst_tag_list_to_xmp_buffer_full (taglist, read_only, array); + buf = gst_tag_list_to_xmp_buffer_full (taglist, read_only, + (const gchar **) array); g_free (array); } } From 834a5a478c127c992e15a16f49883be94a9e3980 Mon Sep 17 00:00:00 2001 From: Haakon Sporsheim Date: Mon, 4 Apr 2011 17:21:45 +0200 Subject: [PATCH 04/12] tag: use gst/math-compat.h header. https://bugzilla.gnome.org/show_bug.cgi?id=646744 --- gst-libs/gst/tag/gstexiftag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst-libs/gst/tag/gstexiftag.c b/gst-libs/gst/tag/gstexiftag.c index cc39acd1e3..360b4669f0 100644 --- a/gst-libs/gst/tag/gstexiftag.c +++ b/gst-libs/gst/tag/gstexiftag.c @@ -41,7 +41,7 @@ #include #include #include -#include +#include /* Some useful constants */ #define TIFF_LITTLE_ENDIAN 0x4949 From 80952f6aa41173b9d26cb3840c93a5fa82f19212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 4 Apr 2011 23:23:37 +0100 Subject: [PATCH 05/12] tests: ignore xmpwriter unit test binary --- tests/check/libs/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/check/libs/.gitignore b/tests/check/libs/.gitignore index e649eb33c6..462835712a 100644 --- a/tests/check/libs/.gitignore +++ b/tests/check/libs/.gitignore @@ -14,4 +14,4 @@ rtsp tag utils video - +xmpwriter From f728ee397848bfd8981688bc440548d4cbe06299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 4 Apr 2011 23:41:16 +0100 Subject: [PATCH 06/12] tag: fix compiler warning on OSX gstvorbistag.c: In function 'gst_tag_list_from_vorbiscomment_buffer': gstvorbistag.c:371: warning: 'data' may be used uninitialized in this function --- gst-libs/gst/tag/gstvorbistag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst-libs/gst/tag/gstvorbistag.c b/gst-libs/gst/tag/gstvorbistag.c index 4f16636e5e..400118bb1b 100644 --- a/gst-libs/gst/tag/gstvorbistag.c +++ b/gst-libs/gst/tag/gstvorbistag.c @@ -368,7 +368,7 @@ gst_vorbis_tag_add_metadata_block_picture (GstTagList * tags, guint32 img_len = 0, img_type = 0; guint32 img_mimetype_len = 0, img_description_len = 0; gsize decoded_len; - const guint8 *data; + const guint8 *data = NULL; /* img_data_base64 points to a temporary copy of the base64 encoded data, so * it's safe to do inpace decoding here From 5f61df82da8837522a4b75b5cc2e98802c67829e Mon Sep 17 00:00:00 2001 From: David Schleef Date: Mon, 4 Apr 2011 16:00:30 -0700 Subject: [PATCH 07/12] video: Fix YUV9 and YVU9 again --- gst-libs/gst/video/video.c | 6 +++--- tests/check/libs/video.c | 19 ++++++------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/gst-libs/gst/video/video.c b/gst-libs/gst/video/video.c index efb2e9f051..a423a7e8b9 100644 --- a/gst-libs/gst/video/video.c +++ b/gst-libs/gst/video/video.c @@ -1937,12 +1937,12 @@ gst_video_format_get_component_offset (GstVideoFormat format, if (component == 0) return 0; if (component == 1) { - return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height) + + return GST_ROUND_UP_4 (width) * height + GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4) * (GST_ROUND_UP_4 (height) / 4); } if (component == 2) - return GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height); + return GST_ROUND_UP_4 (width) * height; return 0; case GST_VIDEO_FORMAT_IYU1: if (component == 0) @@ -2054,7 +2054,7 @@ gst_video_format_get_size (GstVideoFormat format, int width, int height) return size; case GST_VIDEO_FORMAT_YUV9: case GST_VIDEO_FORMAT_YVU9: - size = GST_ROUND_UP_4 (width) * GST_ROUND_UP_2 (height); + size = GST_ROUND_UP_4 (width) * height; size += GST_ROUND_UP_4 (GST_ROUND_UP_4 (width) / 4) * (GST_ROUND_UP_4 (height) / 4) * 2; return size; diff --git a/tests/check/libs/video.c b/tests/check/libs/video.c index dc5ef88546..05b840cb8c 100644 --- a/tests/check/libs/video.c +++ b/tests/check/libs/video.c @@ -301,30 +301,25 @@ paint_setup_IMC4 (paintinfo * p, unsigned char *dest) static void paint_setup_YVU9 (paintinfo * p, unsigned char *dest) { - int h = GST_ROUND_UP_4 (p->height); - p->yp = dest; p->ystride = GST_ROUND_UP_4 (p->width); - p->vp = p->yp + p->ystride * GST_ROUND_UP_4 (p->height); + p->vp = p->yp + p->ystride * p->height; p->vstride = GST_ROUND_UP_4 (p->ystride / 4); - p->up = p->vp + p->vstride * GST_ROUND_UP_4 (h / 4); + p->up = p->vp + p->vstride * (GST_ROUND_UP_4 (p->height) / 4); p->ustride = GST_ROUND_UP_4 (p->ystride / 4); - p->endptr = p->up + p->ustride * GST_ROUND_UP_4 (h / 4); + p->endptr = p->up + p->ustride * (GST_ROUND_UP_4 (p->height) / 4); } static void paint_setup_YUV9 (paintinfo * p, unsigned char *dest) { - /* untested */ - int h = GST_ROUND_UP_4 (p->height); - p->yp = dest; p->ystride = GST_ROUND_UP_4 (p->width); - p->up = p->yp + p->ystride * h; + p->up = p->yp + p->ystride * p->height; p->ustride = GST_ROUND_UP_4 (p->ystride / 4); - p->vp = p->up + p->ustride * GST_ROUND_UP_4 (h / 4); + p->vp = p->up + p->ustride * (GST_ROUND_UP_4 (p->height) / 4); p->vstride = GST_ROUND_UP_4 (p->ystride / 4); - p->endptr = p->vp + p->vstride * GST_ROUND_UP_4 (h / 4); + p->endptr = p->vp + p->vstride * (GST_ROUND_UP_4 (p->height) / 4); } #define gst_video_format_is_packed video_format_is_packed @@ -429,8 +424,6 @@ GST_START_TEST (test_video_formats) fail_unless_equals_int (off1, (unsigned long) paintinfo.up); fail_unless_equals_int (off2, (unsigned long) paintinfo.vp); - skip_check: - /* should be 0 if there's no alpha component */ off3 = gst_video_format_get_component_offset (fmt, 3, w, h); fail_unless_equals_int (off3, (unsigned long) paintinfo.ap); From 38aba7853eb3027489fc2b67bafc9f4db6b89b39 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Tue, 5 Apr 2011 11:32:52 +0300 Subject: [PATCH 08/12] xvimagesink: don't paint the window black when going to NULL Leave dealing with the appearance of the window when we are not playing to the applications. We anyway want to go to NULL as quickly as possible. Fixes #635800 --- sys/xvimage/xvimagesink.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c index f5ee8666c2..51b2d9cf4e 100644 --- a/sys/xvimage/xvimagesink.c +++ b/sys/xvimage/xvimagesink.c @@ -1,6 +1,6 @@ /* GStreamer * Copyright (C) <2005> Julien Moutte - * <2009>,<2010> Stefan Kost + * <2009>,<2010> Stefan Kost * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -1085,13 +1085,6 @@ gst_xvimagesink_xwindow_clear (GstXvImageSink * xvimagesink, XvStopVideo (xvimagesink->xcontext->disp, xvimagesink->xcontext->xv_port_id, xwindow->win); - XSetForeground (xvimagesink->xcontext->disp, xwindow->gc, - xvimagesink->xcontext->black); - - XFillRectangle (xvimagesink->xcontext->disp, xwindow->win, xwindow->gc, - xvimagesink->render_rect.x, xvimagesink->render_rect.y, - xvimagesink->render_rect.w, xvimagesink->render_rect.h); - XSync (xvimagesink->xcontext->disp, FALSE); g_mutex_unlock (xvimagesink->x_lock); @@ -1879,7 +1872,7 @@ gst_xvimagesink_xcontext_get (GstXvImageSink * xvimagesink) for (i = 0; i < (sizeof (channels) / sizeof (char *)); i++) { XvAttribute *matching_attr = NULL; - /* Retrieve the property atom if it exists. If it doesn't exist, + /* Retrieve the property atom if it exists. If it doesn't exist, * the attribute itself must not either, so we can skip */ prop_atom = XInternAtom (xcontext->disp, channels[i], True); if (prop_atom == None) @@ -2206,7 +2199,7 @@ gst_xvimagesink_setcaps (GstBaseSink * bsink, GstCaps * caps) GST_VIDEO_SINK_HEIGHT (xvimagesink)); } - /* After a resize, we want to redraw the borders in case the new frame size + /* After a resize, we want to redraw the borders in case the new frame size * doesn't cover the same area */ xvimagesink->redraw_border = TRUE; From 1ad98b0d98c8701273b5e6e4e42b9daff4f40bec Mon Sep 17 00:00:00 2001 From: Pascal Buhler Date: Tue, 24 Aug 2010 13:14:33 +0200 Subject: [PATCH 09/12] rtcpbuffer: Round to next 32bit word, not current 32bit word at end of SDES chunk --- gst-libs/gst/rtp/gstrtcpbuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst-libs/gst/rtp/gstrtcpbuffer.c b/gst-libs/gst/rtp/gstrtcpbuffer.c index bdaf89bfcc..3b37c6fc7d 100644 --- a/gst-libs/gst/rtp/gstrtcpbuffer.c +++ b/gst-libs/gst/rtp/gstrtcpbuffer.c @@ -997,7 +997,7 @@ gst_rtcp_packet_sdes_next_item (GstRTCPPacket * packet) while (offset < len) { if (data[offset] == 0) { /* end of list, round to next 32-bit word */ - offset = (offset + 3) & ~3; + offset = (offset + 4) & ~3; break; } offset += data[offset + 1] + 2; From d3d8d5c2cc494dc07884e388ab33bff9b54862a9 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Tue, 5 Apr 2011 18:14:49 +0300 Subject: [PATCH 10/12] tests: add basic unit tests for discoverer --- tests/check/Makefile.am | 9 ++++ tests/check/libs/.gitignore | 1 + tests/check/libs/discoverer.c | 94 +++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 tests/check/libs/discoverer.c diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 8a7c7cdc0d..9a9a962296 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -140,6 +140,7 @@ check_PROGRAMS = \ libs/libsabi \ libs/audio \ libs/cddabasesrc \ + libs/discoverer \ libs/fft \ libs/mixer \ libs/navigation \ @@ -235,6 +236,14 @@ libs_cddabasesrc_LDADD = \ $(GST_BASE_LIBS) \ $(LDADD) +libs_discoverer_CFLAGS = \ + $(GST_PLUGINS_BASE_CFLAGS) \ + $(AM_CFLAGS) \ + -DGST_TEST_FILE="\"$(abs_top_srcdir)/tests/files/partialframe.mjpeg\"" +libs_discoverer_LDADD = \ + $(top_builddir)/gst-libs/gst/pbutils/libgstpbutils-@GST_MAJORMINOR@.la \ + $(GST_BASE_LIBS) $(LDADD) + libs_fft_CFLAGS = \ $(GST_PLUGINS_BASE_CFLAGS) \ $(GST_BASE_CFLAGS) \ diff --git a/tests/check/libs/.gitignore b/tests/check/libs/.gitignore index 462835712a..4972a9aee1 100644 --- a/tests/check/libs/.gitignore +++ b/tests/check/libs/.gitignore @@ -1,6 +1,7 @@ .dirstamp audio cddabasesrc +discoverer fft gstlibscpp libsabi diff --git a/tests/check/libs/discoverer.c b/tests/check/libs/discoverer.c new file mode 100644 index 0000000000..2d20576bbe --- /dev/null +++ b/tests/check/libs/discoverer.c @@ -0,0 +1,94 @@ +/* GStreamer unit tests for discoverer + * + * Copyright (C) 2011 Stefan Kost + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include +#include +#include + + +GST_START_TEST (test_disco_init) +{ + GError *err = NULL; + GstDiscoverer *dc; + + dc = gst_discoverer_new (GST_SECOND, &err); + fail_unless (dc != NULL); + fail_unless (err == NULL); + + g_object_unref (dc); +} + +GST_END_TEST; + +GST_START_TEST (test_disco_sync) +{ + GError *err = NULL; + GstDiscoverer *dc; + GstDiscovererInfo *info; + GstDiscovererResult result; + gchar *uri; + + dc = gst_discoverer_new (GST_SECOND, &err); + fail_unless (dc != NULL); + fail_unless (err == NULL); + + /* GST_TEST_FILE comes from makefile CFLAGS */ + GST_INFO ("discovering file '%s'", GST_TEST_FILE); + uri = g_filename_to_uri (GST_TEST_FILE, NULL, &err); + fail_unless (err == NULL); + GST_INFO ("discovering uri '%s'", uri); + + info = gst_discoverer_discover_uri (dc, uri, &err); + result = gst_discoverer_info_get_result (info); + GST_INFO ("result: %d", result); + gst_discoverer_info_unref (info); + g_free (uri); + + if (err) { + /* we won't have the codec for the jpeg */ + g_error_free (err); + } + + g_object_unref (dc); +} + +GST_END_TEST; + + +static Suite * +discoverer_suite (void) +{ + Suite *s = suite_create ("discoverer"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_disco_init); + tcase_add_test (tc_chain, test_disco_sync); + return s; +} + +GST_CHECK_MAIN (discoverer); From 5c8ed3bd47a9464de015a0b2b84ae077d0633ec1 Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Tue, 8 Feb 2011 14:02:20 +0100 Subject: [PATCH 11/12] audioresample: minor simplification ... which avoids crashing in the off-chance that structure == NULL. --- gst/audioresample/gstaudioresample.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gst/audioresample/gstaudioresample.c b/gst/audioresample/gstaudioresample.c index 90967c2671..92e38dd07f 100644 --- a/gst/audioresample/gstaudioresample.c +++ b/gst/audioresample/gstaudioresample.c @@ -473,7 +473,7 @@ gst_audio_resample_parse_caps (GstCaps * incaps, structure = gst_caps_get_structure (incaps, 0); - if (g_str_equal (gst_structure_get_name (structure), "audio/x-raw-float")) + if (gst_structure_has_name (structure, "audio/x-raw-float")) myfp = TRUE; else myfp = FALSE; From 9cf76f114f4088d700be3e26c0fafe09e1bce3a0 Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Fri, 25 Mar 2011 16:59:51 +0100 Subject: [PATCH 12/12] theoraenc: refactor multipass file writing --- ext/theora/gsttheoraenc.c | 96 +++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 54 deletions(-) diff --git a/ext/theora/gsttheoraenc.c b/ext/theora/gsttheoraenc.c index 6a09c2cf3e..c580675146 100644 --- a/ext/theora/gsttheoraenc.c +++ b/ext/theora/gsttheoraenc.c @@ -272,6 +272,9 @@ static void theora_enc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void theora_enc_finalize (GObject * object); +static gboolean theora_enc_write_multipass_cache (GstTheoraEnc * enc, + gboolean begin, gboolean eos); + static void gst_theora_enc_base_init (gpointer g_class) { @@ -483,44 +486,6 @@ theora_enc_finalize (GObject * object) G_OBJECT_CLASS (parent_class)->finalize (object); } -static gboolean -theora_enc_write_multipass_cache_beginning (GstTheoraEnc * enc, gboolean eos) -{ - GError *err = NULL; - GIOStatus stat; - gint bytes_read = 0; - gsize bytes_written = 0; - gchar *buf; - - stat = - g_io_channel_seek_position (enc->multipass_cache_fd, 0, G_SEEK_SET, &err); - if (stat != G_IO_STATUS_ERROR) { - do { - bytes_read = - th_encode_ctl (enc->encoder, TH_ENCCTL_2PASS_OUT, &buf, sizeof (buf)); - if (bytes_read > 0) - g_io_channel_write_chars (enc->multipass_cache_fd, buf, bytes_read, - &bytes_written, NULL); - } while (bytes_read > 0 && bytes_written > 0); - - } - - if (stat == G_IO_STATUS_ERROR || bytes_read < 0 || bytes_written < 0) { - if (eos) - GST_ELEMENT_WARNING (enc, RESOURCE, WRITE, (NULL), - ("Failed to seek to beginning of multipass cache file: %s", - err->message)); - else - GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL), - ("Failed to seek to beginning of multipass cache file: %s", - err->message)); - g_error_free (err); - - return FALSE; - } - return TRUE; -} - static void theora_enc_reset (GstTheoraEnc * enc) { @@ -569,7 +534,7 @@ theora_enc_reset (GstTheoraEnc * enc) /* Get placeholder data */ if (enc->multipass_cache_fd && enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS) - theora_enc_write_multipass_cache_beginning (enc, FALSE); + theora_enc_write_multipass_cache (enc, TRUE, FALSE); } static void @@ -904,7 +869,7 @@ theora_enc_sink_event (GstPad * pad, GstEvent * event) } if (enc->initialised && enc->multipass_cache_fd && enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS) - theora_enc_write_multipass_cache_beginning (enc, TRUE); + theora_enc_write_multipass_cache (enc, TRUE, TRUE); theora_enc_clear_multipass_cache (enc); @@ -1089,23 +1054,46 @@ theora_enc_read_multipass_cache (GstTheoraEnc * enc) } static gboolean -theora_enc_write_multipass_cache (GstTheoraEnc * enc) +theora_enc_write_multipass_cache (GstTheoraEnc * enc, gboolean begin, + gboolean eos) { - gchar *buf; - gint bytes_read; + GError *err = NULL; + GIOStatus stat = G_IO_STATUS_NORMAL; + gint bytes_read = 0; gsize bytes_written = 0; + gchar *buf; - do { - bytes_read = - th_encode_ctl (enc->encoder, TH_ENCCTL_2PASS_OUT, &buf, sizeof (buf)); - if (bytes_read > 0) - g_io_channel_write_chars (enc->multipass_cache_fd, buf, bytes_read, - &bytes_written, NULL); - } while (bytes_read > 0 && bytes_written > 0); + if (begin) + stat = g_io_channel_seek_position (enc->multipass_cache_fd, 0, G_SEEK_SET, + &err); + if (stat != G_IO_STATUS_ERROR) { + do { + bytes_read = + th_encode_ctl (enc->encoder, TH_ENCCTL_2PASS_OUT, &buf, sizeof (buf)); + if (bytes_read > 0) + g_io_channel_write_chars (enc->multipass_cache_fd, buf, bytes_read, + &bytes_written, NULL); + } while (bytes_read > 0 && bytes_written > 0); + + } + + if (stat == G_IO_STATUS_ERROR || bytes_read < 0 || bytes_written < 0) { + if (begin) { + if (eos) + GST_ELEMENT_WARNING (enc, RESOURCE, WRITE, (NULL), + ("Failed to seek to beginning of multipass cache file: %s", + err->message)); + else + GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL), + ("Failed to seek to beginning of multipass cache file: %s", + err->message)); + } else { + GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL), + ("Failed to write multipass cache file")); + } + if (err) + g_error_free (err); - if (bytes_read < 0 || bytes_written < 0) { - GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL), - ("Failed to write multipass cache file")); return FALSE; } return TRUE; @@ -1285,7 +1273,7 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer) if (enc->multipass_cache_fd && enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS) { - if (!theora_enc_write_multipass_cache (enc)) { + if (!theora_enc_write_multipass_cache (enc, FALSE, FALSE)) { ret = GST_FLOW_ERROR; goto multipass_write_failed; }