1From 8486605464354e70f30626c1e12649128197e983 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Mon, 3 Oct 2022 15:07:33 +0800
4Subject: [PATCH 4/4] gst-launch: Fix random hang when EOS
5
6There's a race between the async initial pause and initial play.
7
8When the async pausing message arrives later than the playing one, the
9gstbin's state machine would be confused.
10
11Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
12---
13 tools/gst-launch.c | 12 ++++++++++++
14 1 file changed, 12 insertions(+)
15
16diff --git a/tools/gst-launch.c b/tools/gst-launch.c
17index 5733152..fdaf579 100644
18--- a/tools/gst-launch.c
19+++ b/tools/gst-launch.c
20@@ -78,6 +78,7 @@ static gboolean eos_on_shutdown = FALSE;
21 static gchar **exclude_args = NULL;
22
23 /* pipeline status */
24+static gboolean pending_async_done = FALSE;
25 static gboolean is_live = FALSE;
26 static gboolean buffering = FALSE;
27 static LaunchExitCode last_launch_code = LEC_NO_ERROR;
28@@ -737,12 +738,22 @@ bus_handler (GstBus * bus, GstMessage * message, gpointer data)
29             PRINT (_("Prerolled, waiting for progress to finish...\n"));
30             break;
31           }
32+          if (pending_async_done) {
33+            PRINT (_("Prerolled, waiting for async message to finish...\n"));
34+            break;
35+          }
36
37           do_initial_play (pipeline);
38         }
39         /* else not an interesting message */
40         break;
41       }
42+      case GST_MESSAGE_ASYNC_DONE:
43+      {
44+        if (target_state == GST_STATE_PAUSED)
45+          do_initial_play (pipeline);
46+        break;
47+      }
48       case GST_MESSAGE_BUFFERING:{
49         gint percent;
50
51@@ -1274,6 +1285,7 @@ main (int argc, char *argv[])
52         break;
53       case GST_STATE_CHANGE_ASYNC:
54         PRINT (_("Pipeline is PREROLLING ...\n"));
55+        pending_async_done = TRUE;
56         break;
57       default:
58         break;
59--
602.20.1
61
62