summaryrefslogtreecommitdiff
path: root/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad/0016-gstplayer-Add-play-stop-sync-API.patch
blob: a4ccc18bf3c15c90729f9fd67399080c4ea29a5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
From cbbb524a5e634463965935cf9b6d03ec91804e2d Mon Sep 17 00:00:00 2001
From: Lyon Wang <lyon.wang@nxp.com>
Date: Thu, 16 Feb 2017 18:50:28 +0800
Subject: [PATCH 16/26] gstplayer: Add play/stop sync API

- Add play/stop/pause sync API
      gst_player_play_sync()
      gst_player_stop_sync()
      gst_player_pause_sync()

https://bugzilla.gnome.org/show_bug.cgi?id=778390

Upstream-Status: Inappropriate [i.MX specific]

Signed-off-by: Lyon Wang <lyon.wang@nxp.com>

Conflicts:
	gst-libs/gst/player/gstplayer.c
---
 gst-libs/gst/player/gstplayer.c | 112 ++++++++++++++++++++++++++++++++++++++++
 gst-libs/gst/player/gstplayer.h |   4 ++
 2 files changed, 116 insertions(+)

diff --git a/gst-libs/gst/player/gstplayer.c b/gst-libs/gst/player/gstplayer.c
index ebad94e..8c94a98 100644
--- a/gst-libs/gst/player/gstplayer.c
+++ b/gst-libs/gst/player/gstplayer.c
@@ -200,6 +200,10 @@ struct _GstPlayer
   gchar *audio_sid;
   gchar *subtitle_sid;
   gulong stream_notify_id;
+
+  /* When error occur, will set this flag to TRUE,
+   * so that it could quit for sync play/stop loop */
+  gboolean got_error;
 };
 
 struct _GstPlayerClass
@@ -296,6 +300,7 @@ gst_player_init (GstPlayer * self)
   self->seek_position = GST_CLOCK_TIME_NONE;
   self->last_seek_time = GST_CLOCK_TIME_NONE;
   self->inhibit_sigs = FALSE;
+  self->got_error = FALSE;
 
   GST_TRACE_OBJECT (self, "Initialized");
 }
@@ -1055,6 +1060,8 @@ emit_error (GstPlayer * self, GError * err)
   GST_ERROR_OBJECT (self, "Error: %s (%s, %d)", err->message,
       g_quark_to_string (err->domain), err->code);
 
+  self->got_error = TRUE;
+
   if (g_signal_handler_find (self, G_SIGNAL_MATCH_ID,
           signals[SIGNAL_ERROR], 0, NULL, NULL, NULL) != 0) {
     ErrorSignalData *data = g_new (ErrorSignalData, 1);
@@ -5062,3 +5069,108 @@ gst_player_get_state (GstPlayer * self)
 
   return self->app_state;
 }
+
+/**
+ * gst_player_wait_state
+ * @player: #GstPlayer instance
+ * @target_state: target state
+ * @time_out:  time out value
+ *  negtive (< 0): infinitely waiting for state change.
+ *  positive (>0): wait until time out.
+ *  zero (0), do not wait for the state change.
+ *
+ * Wait for target state, quit loop when time out
+ */
+static void
+gst_player_wait_state (GstPlayer * self, GstPlayerState target_state,
+    gint time_out)
+{
+  gint wait_cnt = 0;
+
+  while (time_out < 0 || wait_cnt < time_out * 20) {
+    if (self->app_state == target_state) {
+      break;
+    } else if (self->got_error == TRUE) {
+      self->got_error = FALSE;
+      return;
+    } else if (self->is_eos == TRUE) {
+      return;
+    } else {
+      wait_cnt++;
+      usleep (50000);
+    }
+  }
+  if (time_out > 0 && wait_cnt >= time_out * 20) {
+    emit_error (self, g_error_new (GST_PLAYER_ERROR,
+            GST_PLAYER_ERROR_FAILED,
+            "try to play /stop /pause failed, time out"));
+  }
+
+  return;
+}
+
+/**
+ * gst_player_play_sync:
+ * @player: #GstPlayer instance
+ * @time_out:  time out value
+ *  negtive (< 0): infinitely waiting for state change.
+ *  positive (>0): wait until time out.
+ *  zero (0), do not wait for the state change.
+ *
+ * Request to play the loaded stream in sync mode.
+ */
+void
+gst_player_play_sync (GstPlayer * self, gint time_out)
+{
+  g_return_if_fail (GST_IS_PLAYER (self));
+
+  gst_player_play (self);
+
+  gst_player_wait_state (self, GST_PLAYER_STATE_PLAYING, time_out);
+
+  return;
+}
+
+/**
+ * gst_player_stop_sync:
+ * @player: #GstPlayer instance
+ * @time_out:  time out value
+ *  negtive (< 0): infinitely waiting for state change.
+ *  positive (>0): wait until time out.
+ *  zero (0), do not wait for the state change.
+ *
+ *  Stops playing the current stream in sync mode.
+ */
+void
+gst_player_stop_sync (GstPlayer * self, gint time_out)
+{
+  g_return_if_fail (GST_IS_PLAYER (self));
+
+  gst_player_stop (self);
+
+  gst_player_wait_state (self, GST_PLAYER_STATE_STOPPED, time_out);
+
+  return;
+}
+
+/**
+ * gst_player_pause_sync:
+ * @player: #GstPlayer instance
+ * @time_out:  time out value
+ *  negtive (< 0): infinitely waiting for state change.
+ *  positive (>0): wait until time out.
+ *  zero (0), do not wait for the state change.
+ *
+ *  Pause current stream in sync mode.
+ */
+void
+gst_player_pause_sync (GstPlayer * self, gint time_out)
+{
+  g_return_if_fail (GST_IS_PLAYER (self));
+
+  gst_player_pause (self);
+
+  gst_player_wait_state (self, GST_PLAYER_STATE_PAUSED, time_out);
+
+  return;
+}
diff --git a/gst-libs/gst/player/gstplayer.h b/gst-libs/gst/player/gstplayer.h
index 5ee3592..ee1a8da 100644
--- a/gst-libs/gst/player/gstplayer.h
+++ b/gst-libs/gst/player/gstplayer.h
@@ -230,6 +230,10 @@ GstElement * gst_player_get_text_sink (GstPlayer * player);
 
 GstPlayerState  gst_player_get_state (GstPlayer * player);
 
+void         gst_player_play_sync (GstPlayer * player, gint time_out);
+void         gst_player_stop_sync (GstPlayer * player, gint time_out);
+void         gst_player_pause_sync (GstPlayer * player, gint time_out);
+
 G_END_DECLS
 
 #endif /* __GST_PLAYER_H__ */
-- 
1.9.1