[totem/wip/hadess/less-mpeg-errors: 6/6] backend: Don't throw error when EOS'ing an MPEG file




commit 76fd144810e304e3ba4376f28a9d31ef91aaf1ba
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Sep 29 12:05:51 2020 +0200

    backend: Don't throw error when EOS'ing an MPEG file
    
    When seeking an MPEG file past the end, mpeg2dec would throw an error
    about "No valid frames decoded before end of stream". Catch that error
    and emit an EOS message instead, so that we don't block MPEG playback
    every second.

 src/backend/bacon-video-widget.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)
---
diff --git a/src/backend/bacon-video-widget.c b/src/backend/bacon-video-widget.c
index e2a2dd65e..e254786c0 100644
--- a/src/backend/bacon-video-widget.c
+++ b/src/backend/bacon-video-widget.c
@@ -2045,6 +2045,35 @@ bvw_check_missing_plugins_error (BaconVideoWidget * bvw, GstMessage * err_msg)
   return ret;
 }
 
+static gboolean
+bvw_check_mpeg_eos (BaconVideoWidget *bvw, GstMessage *err_msg)
+{
+  gboolean ret = FALSE;
+  g_autoptr(GError) err = NULL;
+  g_autofree char *dbg = NULL;
+
+  gst_message_parse_error (err_msg, &err, &dbg);
+
+  /* Error from gst-libs/gst/video/gstvideodecoder.c
+   * thrown by mpeg2dec */
+
+  if (err != NULL &&
+      dbg != NULL &&
+      is_error (err, STREAM, DECODE) &&
+      strstr (dbg, "no valid frames found")) {
+    if (bvw->priv->eos_id == 0) {
+      bvw->priv->eos_id = g_idle_add (bvw_signal_eos_delayed, bvw);
+      g_source_set_name_by_id (bvw->priv->eos_id, "[totem] bvw_signal_eos_delayed");
+      GST_DEBUG ("Throwing EOS instead of an error when seeking to the end of an MPEG file");
+    } else {
+      GST_DEBUG ("Not throwing EOS instead of an error when seeking to the end of an MPEG file, EOS already 
planned");
+    }
+    ret = TRUE;
+  }
+
+  return ret;
+}
+
 /* returns TRUE if the error/signal has been handled and should be ignored */
 static gboolean
 bvw_check_missing_plugins_on_preroll (BaconVideoWidget * bvw)
@@ -2413,7 +2442,8 @@ bvw_bus_message_cb (GstBus * bus, GstMessage * message, BaconVideoWidget *bvw)
       totem_gst_message_print (message, bvw->priv->play, "totem-error");
 
       if (!bvw_check_missing_plugins_error (bvw, message) &&
-         !bvw_check_missing_auth (bvw, message)) {
+         !bvw_check_missing_auth (bvw, message) &&
+         !bvw_check_mpeg_eos (bvw, message)) {
         GError *error;
 
         error = bvw_error_from_gst_error (bvw, message);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]