--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
转自:http://docs.gstreamer.com/display/GstSDK/Basic+tutorial+12%3A+Streaming
playbin2中的buffering机制的使用方法:
We focus on some of the other properties of playbin2
, though:
50
51
52
53
54
|
/* Set flags to show Audio and Video but ignore Subtitles */
g_object_get (data.playbin2,
"flags"
, &flags, NULL);
flags |= GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO;
flags &= ~GST_PLAY_FLAG_TEXT;
g_object_set (data.playbin2,
"flags"
, flags, NULL);
|
playbin2
's behavior can be changed through its flags
property, which can have any combination of GstPlayFlags
. The most interesting values are:
|
Enable video rendering. If this flag is not set, there will be no video output. |
|
Enable audio rendering. If this flag is not set, there will be no audio output. |
|
Enable subtitle rendering. If this flag is not set, subtitles will not be shown in the video output. |
|
Enable rendering of visualisations when there is no video stream.Playback tutorial 6: Audio visualization goes into more details. |
|
See Basic tutorial 12: Streaming and Playback tutorial 4: Progressive streaming. |
|
See Basic tutorial 12: Streaming and Playback tutorial 4: Progressive streaming. |
|
If the video content was interlaced, this flag instructs |
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
|
#include
#include
typedef
struct
_CustomData {
gboolean is_live;
GstElement *pipeline;
GMainLoop *loop;
} CustomData;
static
void
cb_message (GstBus *bus, GstMessage *msg, CustomData *data) {
switch
(GST_MESSAGE_TYPE (msg)) {
case
GST_MESSAGE_ERROR: {
GError *err;
gchar *debug;
gst_message_parse_error (msg, &err, &debug);
g_print (
"Error: %s\n"
, err->message);
g_error_free (err);
g_free (debug);
gst_element_set_state (data->pipeline, GST_STATE_READY);
g_main_loop_quit (data->loop);
break
;
}
case
GST_MESSAGE_EOS:
/* end-of-stream */
gst_element_set_state (data->pipeline, GST_STATE_READY);
g_main_loop_quit (data->loop);
break
;
case
GST_MESSAGE_BUFFERING: {
gint percent = 0;
/* If the stream is live, we do not care about buffering. */
if
(data->is_live)
break
;
gst_message_parse_buffering (msg, &percent);
g_print (
"Buffering (%3d%%)\r"
, percent);
/* Wait until buffering is complete before start/resume playing */
if
(percent < 100)
gst_element_set_state (data->pipeline, GST_STATE_PAUSED);
else
gst_element_set_state (data->pipeline, GST_STATE_PLAYING);
break
;
}
case
GST_MESSAGE_CLOCK_LOST:
/* Get a new clock */
gst_element_set_state (data->pipeline, GST_STATE_PAUSED);
gst_element_set_state (data->pipeline, GST_STATE_PLAYING);
break
;
default
:
/* Unhandled message */
break
;
}
}
int
main(
int
argc,
char
*argv[]) {
GstElement *pipeline;
GstBus *bus;
GstStateChangeReturn ret;
GMainLoop *main_loop;
CustomData data;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Initialize our data structure */
memset
(&data, 0,
sizeof
(data));
/* Build the pipeline */
pipeline = gst_parse_launch (
"playbin2 uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm"
, NULL);
bus = gst_element_get_bus (pipeline);
/* Start playing */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if
(ret == GST_STATE_CHANGE_FAILURE) {
g_printerr (
"Unable to set the pipeline to the playing state.\n"
);
gst_object_unref (pipeline);
return
-1;
}
else
if
(ret == GST_STATE_CHANGE_NO_PREROLL) {
data.is_live = TRUE;
}
main_loop = g_main_loop_new (NULL, FALSE);
data.loop = main_loop;
data.pipeline = pipeline;
gst_bus_add_signal_watch (bus);
g_signal_connect (bus,
"message"
, G_CALLBACK (cb_message), &data);
g_main_loop_run (main_loop);
/* Free resources */
g_main_loop_unref (main_loop);
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return
0;
}
|