1 | /* GStreamer |
---|
2 | * Copyright (C) 2004 Wim Taymans <wim@fluendo.com> |
---|
3 | * |
---|
4 | * This library is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU General Public |
---|
6 | * License as published by the Free Software Foundation; either |
---|
7 | * version 2 of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This library is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
12 | * General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public |
---|
15 | * License along with this library; if not, write to the Free |
---|
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
17 | */ |
---|
18 | |
---|
19 | #include <unistd.h> |
---|
20 | |
---|
21 | #include <gst/gst.h> |
---|
22 | |
---|
23 | static gboolean empty; |
---|
24 | static gboolean bug; |
---|
25 | static gboolean handoff; |
---|
26 | static GstElement *pipeline2; |
---|
27 | |
---|
28 | static void |
---|
29 | queue_empty (GstElement * element) |
---|
30 | { |
---|
31 | g_print ("queue empty\n"); |
---|
32 | if (!handoff) |
---|
33 | bug = TRUE; |
---|
34 | } |
---|
35 | |
---|
36 | static void |
---|
37 | queue_filled (GstElement * element) |
---|
38 | { |
---|
39 | g_print ("queue filled\n"); |
---|
40 | empty = FALSE; |
---|
41 | |
---|
42 | /* read from the other end */ |
---|
43 | handoff = FALSE; |
---|
44 | bug = FALSE; |
---|
45 | |
---|
46 | alarm (5); |
---|
47 | |
---|
48 | g_print ("emptying queue with 5 second timeout...\n"); |
---|
49 | while (!bug && !handoff) { |
---|
50 | gst_bin_iterate (GST_BIN (pipeline2)); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | static void |
---|
55 | handoff_identity (GstElement * element) |
---|
56 | { |
---|
57 | g_print ("identity handoff\n"); |
---|
58 | handoff = TRUE; |
---|
59 | } |
---|
60 | |
---|
61 | gint |
---|
62 | main (gint argc, gchar ** argv) |
---|
63 | { |
---|
64 | GstElement *pipeline, *src, *sink, *queue, *id; |
---|
65 | |
---|
66 | gst_init (&argc, &argv); |
---|
67 | |
---|
68 | g_print ("setting up...\n"); |
---|
69 | /* setup pipeline */ |
---|
70 | pipeline = gst_element_factory_make ("pipeline", NULL); |
---|
71 | g_assert (pipeline); |
---|
72 | src = gst_element_factory_make ("fakesrc", NULL); |
---|
73 | g_assert (src); |
---|
74 | queue = gst_element_factory_make ("queue", NULL); |
---|
75 | g_assert (queue); |
---|
76 | g_signal_connect (G_OBJECT (queue), "overrun", (GCallback) queue_filled, |
---|
77 | NULL); |
---|
78 | g_signal_connect (G_OBJECT (queue), "underrun", (GCallback) queue_empty, |
---|
79 | NULL); |
---|
80 | gst_bin_add_many (GST_BIN (pipeline), src, queue, NULL); |
---|
81 | |
---|
82 | gst_element_link_pads (src, "src", queue, "sink"); |
---|
83 | |
---|
84 | /* second pipeline for sinks */ |
---|
85 | pipeline2 = gst_element_factory_make ("pipeline", NULL); |
---|
86 | g_assert (pipeline2); |
---|
87 | id = gst_element_factory_make ("identity", NULL); |
---|
88 | g_assert (id); |
---|
89 | g_signal_connect (G_OBJECT (id), "handoff", (GCallback) handoff_identity, |
---|
90 | NULL); |
---|
91 | |
---|
92 | sink = gst_element_factory_make ("fakesink", NULL); |
---|
93 | g_assert (sink); |
---|
94 | gst_bin_add_many (GST_BIN (pipeline2), id, sink, NULL); |
---|
95 | |
---|
96 | gst_element_link_pads (queue, "src", id, "sink"); |
---|
97 | gst_element_link_pads (id, "src", sink, "sink"); |
---|
98 | |
---|
99 | if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS) |
---|
100 | g_assert_not_reached (); |
---|
101 | |
---|
102 | if (gst_element_set_state (pipeline2, GST_STATE_PLAYING) != GST_STATE_SUCCESS) |
---|
103 | g_assert_not_reached (); |
---|
104 | |
---|
105 | g_print ("running...\n"); |
---|
106 | /* fill queue */ |
---|
107 | empty = TRUE; |
---|
108 | while (empty) { |
---|
109 | gst_bin_iterate (GST_BIN (pipeline)); |
---|
110 | } |
---|
111 | g_assert (!bug); |
---|
112 | |
---|
113 | if (gst_element_set_state (pipeline2, GST_STATE_READY) != GST_STATE_SUCCESS) |
---|
114 | g_assert_not_reached (); |
---|
115 | |
---|
116 | g_print ("relinking...\n"); |
---|
117 | /* now unlink and link id and sink */ |
---|
118 | gst_element_unlink_pads (id, "src", sink, "sink"); |
---|
119 | gst_element_link_pads (id, "src", sink, "sink"); |
---|
120 | |
---|
121 | if (gst_element_set_state (pipeline2, GST_STATE_PLAYING) != GST_STATE_SUCCESS) |
---|
122 | g_assert_not_reached (); |
---|
123 | |
---|
124 | g_print ("running again...\n"); |
---|
125 | /* fill queue */ |
---|
126 | empty = TRUE; |
---|
127 | while (empty) { |
---|
128 | gst_bin_iterate (GST_BIN (pipeline)); |
---|
129 | } |
---|
130 | g_assert (!bug); |
---|
131 | |
---|
132 | /* trigger the bug */ |
---|
133 | |
---|
134 | |
---|
135 | g_print ("cleaning up...\n"); |
---|
136 | gst_object_unref (GST_OBJECT (pipeline)); |
---|
137 | gst_object_unref (GST_OBJECT (pipeline2)); |
---|
138 | src = id = sink = pipeline = pipeline2 = NULL; |
---|
139 | |
---|
140 | g_print ("done.\n"); |
---|
141 | return 0; |
---|
142 | } |
---|