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:13:18 +0200
commitf3b6548f095726acd8308fb98148321635b7b5bc (patch)
tree537fb2e2e4c104aed25f0da5bd218b60f25bb6e9
parentb719dd9f89e8b00c28262a6a4a73cb83720ea0e4 (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 0823e22bc..fcae87fa3 100644
--- a/ext/theora/gsttheoraenc.c
+++ b/ext/theora/gsttheoraenc.c
@@ -774,22 +774,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",
@@ -798,15 +787,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;
}