Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multistream-server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Show Cases
IBC 2019
multistream-server
Commits
8ce66854
Commit
8ce66854
authored
Aug 23, 2019
by
Olivier Crête
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restart source on EOS
parent
ee8d4a95
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
1 deletion
+85
-1
src/main.c
src/main.c
+85
-1
No files found.
src/main.c
View file @
8ce66854
...
...
@@ -239,6 +239,80 @@ webrtc_client_disconnected_cb (MssHttpServer *server, MssClientId client_id,
}
}
struct
RestartData
{
GstElement
*
src
;
GstElement
*
pipeline
;
};
static
void
free_restart_data
(
gpointer
user_data
)
{
struct
RestartData
*
rd
=
user_data
;
gst_object_unref
(
rd
->
src
);
g_free
(
rd
);
}
static
gboolean
restart_source
(
gpointer
user_data
)
{
struct
RestartData
*
rd
=
user_data
;
GstElement
*
tsparse
;
GstStateChangeReturn
ret
;
gst_element_set_state
(
rd
->
src
,
GST_STATE_NULL
);
gst_element_set_locked_state
(
rd
->
src
,
TRUE
);
tsparse
=
gst_bin_get_by_name
(
GST_BIN
(
rd
->
pipeline
),
"tsparse"
);
gst_bin_add
(
GST_BIN
(
rd
->
pipeline
),
rd
->
src
);
gst_element_link
(
rd
->
src
,
tsparse
);
gst_element_set_locked_state
(
rd
->
src
,
FALSE
);
ret
=
gst_element_set_state
(
rd
->
src
,
GST_STATE_PLAYING
);
g_assert
(
ret
!=
GST_STATE_CHANGE_FAILURE
);
gst_object_unref
(
tsparse
);
g_debug
(
"Restarted source after EOS"
);
return
G_SOURCE_REMOVE
;
}
static
GstPadProbeReturn
src_event_cb
(
GstPad
*
pad
,
GstPadProbeInfo
*
info
,
gpointer
user_data
)
{
GstElement
*
pipeline
=
user_data
;
GstElement
*
src
;
struct
RestartData
*
rd
;
if
(
GST_EVENT_TYPE
(
GST_PAD_PROBE_INFO_EVENT
(
info
))
!=
GST_EVENT_EOS
)
return
GST_PAD_PROBE_PASS
;
src
=
gst_pad_get_parent_element
(
pad
);
gst_bin_remove
(
GST_BIN
(
pipeline
),
src
);
rd
=
g_new
(
struct
RestartData
,
1
);
rd
->
src
=
src
;
rd
->
pipeline
=
pipeline
;
g_idle_add_full
(
G_PRIORITY_HIGH_IDLE
,
restart_source
,
rd
,
free_restart_data
);
return
GST_PAD_PROBE_DROP
;
}
static
gboolean
print_stats
(
gpointer
user_data
)
{
GstElement
*
src
=
user_data
;
GstStructure
*
s
;
char
*
str
;
g_object_get
(
src
,
"stats"
,
&
s
,
NULL
);
str
=
gst_structure_to_string
(
s
);
g_debug
(
"%s"
,
str
);
g_free
(
str
);
gst_structure_free
(
s
);
return
G_SOURCE_CONTINUE
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
GOptionContext
*
option_context
;
...
...
@@ -247,6 +321,8 @@ int main (int argc, char *argv[])
GstElement
*
pipeline
;
GError
*
error
=
NULL
;
GstBus
*
bus
;
GstElement
*
src
;
GstPad
*
srcpad
;
GstStateChangeReturn
ret
;
option_context
=
g_option_context_new
(
NULL
);
...
...
@@ -266,7 +342,7 @@ int main (int argc, char *argv[])
http_server
=
mss_http_server_new
();
pipeline_str
=
g_strdup_printf
(
"srtsrc uri=%s?mode=listener
!
tsparse ! tee name=t ! "
pipeline_str
=
g_strdup_printf
(
"srtsrc uri=%s?mode=listener
name=src ! tsparse name=
tsparse ! tee name=t ! "
"queue ! tsdemux latency=50 ! decodebin ! videoconvert ! autovideosink "
"t. ! queue leaky=downstream max-size-buffers=400 ! tsdemux ! h264parse ! video/x-h264, stream-format=avc ! h264parse ! mpegtsmux ! hlssink location=%s/segment%%05d.ts playlist-location=%s/playlist.m3u8 target-duration=1 playlist-length=3 "
"t. ! queue leaky=downstream max-size-buffers=10 ! rtpmp2tpay ! ristsink bonding-addresses=%s "
...
...
@@ -304,6 +380,14 @@ int main (int argc, char *argv[])
srt_uri
,
rist_addresses
);
src
=
gst_bin_get_by_name
(
GST_BIN
(
pipeline
),
"src"
);
srcpad
=
gst_element_get_static_pad
(
src
,
"src"
);
gst_pad_add_probe
(
srcpad
,
GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM
,
src_event_cb
,
pipeline
,
NULL
);
g_timeout_add
(
1000
,
print_stats
,
src
);
gst_object_unref
(
srcpad
);
gst_object_unref
(
src
);
ret
=
gst_element_set_state
(
pipeline
,
GST_STATE_PLAYING
);
g_assert
(
ret
!=
GST_STATE_CHANGE_FAILURE
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment