summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2013-05-07 10:13:18 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2013-05-07 10:23:16 +0200
commita3bd8d3e8c4aff737497a2400d9868007008282b (patch)
tree3ef80dbce1f6ca5b3b2f434d3251cad2b84aca8e
parenta808ed7f6acc84314c87de6c56a56798c74ccda9 (diff)
theoraenc: Fix error handling when reading or writing multipass cache data fails
-rw-r--r--ext/theora/gsttheoraenc.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/ext/theora/gsttheoraenc.c b/ext/theora/gsttheoraenc.c
index a02a745c3..6c00626ce 100644
--- a/ext/theora/gsttheoraenc.c
+++ b/ext/theora/gsttheoraenc.c
@@ -786,22 +786,11 @@ theora_enc_write_multipass_cache (GstTheoraEnc * enc, gboolean begin,
gsize bytes_written = 0;
gchar *buf;
- if (begin)
+ 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) {
- if (begin) {
+ if (stat == G_IO_STATUS_ERROR) {
if (eos)
GST_ELEMENT_WARNING (enc, RESOURCE, WRITE, (NULL),
("Failed to seek to beginning of multipass cache file: %s",
@@ -810,15 +799,34 @@ theora_enc_write_multipass_cache (GstTheoraEnc * enc, gboolean begin,
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;
+ }
+ }
+
+
+ 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, &err);
+ } while (bytes_read > 0 && bytes_written > 0 && !err);
+
+ if (bytes_read < 0 || err) {
+ if (bytes_read < 0) {
+ GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL),
+ ("Failed to read multipass cache data: %d", bytes_read));
} else {
GST_ELEMENT_ERROR (enc, RESOURCE, WRITE, (NULL),
- ("Failed to write multipass cache file"));
+ ("Failed to write multipass cache file: %s", err->message));
}
if (err)
g_error_free (err);
return FALSE;
}
+
return TRUE;
}