Skip to content

Commit

Permalink
Allow to use a test video source that outputs H264 video
Browse files Browse the repository at this point in the history
 This is enabled by setting the value of the environment variable
 OWR_USE_TEST_SOURCES to 'h264' or 'H264'.
 Any other value of the environment variable will enable the
 previous test sources with raw video format.
  • Loading branch information
clopez authored and Paul Mathieu committed May 22, 2017
1 parent 9a1e578 commit eb7e3dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions local/owr_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static GList *get_test_sources(OwrMediaType types)
OwrMediaType media_type;
GList *result_list = NULL;
GList *elem;
gboolean useh264 = g_ascii_strcasecmp (g_getenv("OWR_USE_TEST_SOURCES"),"H264") == 0;

if (g_once_init_enter(&cached_sources)) {
GList *sources = NULL;
Expand All @@ -73,6 +74,8 @@ static GList *get_test_sources(OwrMediaType types)
sources = g_list_append(sources, OWR_MEDIA_SOURCE(source));

source = _owr_local_media_source_new_cached(-1, "Video test source", OWR_MEDIA_TYPE_VIDEO, OWR_SOURCE_TYPE_TEST, NULL, OWR_MEDIA_SOURCE_SUPPORTS_NONE);
if (useh264)
_owr_media_source_set_codec(OWR_MEDIA_SOURCE(source), OWR_CODEC_TYPE_H264);
sources = g_list_append(sources, OWR_MEDIA_SOURCE(source));

g_once_init_leave(&cached_sources, sources);
Expand Down
29 changes: 25 additions & 4 deletions local/owr_local_media_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,14 @@ static GstElement *owr_local_media_source_request_source(OwrMediaSource *media_s
}
break;
case OWR_SOURCE_TYPE_TEST: {
GstElement *src, *time;
GstElement *src, *time, *h264enc = NULL;
GstPad *srcpad;
gboolean useh264 = g_ascii_strcasecmp (g_getenv("OWR_USE_TEST_SOURCES"),"H264") == 0;

if (useh264)
printf("video-source encoding: video/x-h264\n");
else
printf("video-source encoding: video/x-raw\n");

source = gst_bin_new("video-source");

Expand All @@ -789,9 +795,24 @@ static GstElement *owr_local_media_source_request_source(OwrMediaSource *media_s
g_object_set(time, "font-desc", "Sans 60", NULL);
gst_bin_add(GST_BIN(source), time);
gst_element_link(src, time);
srcpad = gst_element_get_static_pad(time, "src");
} else
srcpad = gst_element_get_static_pad(src, "src");
if (!useh264)
srcpad = gst_element_get_static_pad(time, "src");
} else if (!useh264)
srcpad = gst_element_get_static_pad(src, "src");

if (useh264) {
h264enc = gst_element_factory_make("openh264enc", "openh264enc");
if (!h264enc) {
GST_ERROR_OBJECT(source, "Failed to create openh264enc element!");
printf("Failed to create openh264enc element!\n");
}
gst_bin_add(GST_BIN(source), h264enc);
if (time)
gst_element_link(time, h264enc);
else
gst_element_link(src, h264enc);
srcpad = gst_element_get_static_pad(h264enc, "src");
}

gst_element_add_pad(source, gst_ghost_pad_new("src", srcpad));
gst_object_unref(srcpad);
Expand Down

0 comments on commit eb7e3dc

Please sign in to comment.