Permalink
Browse files

media source: optional OpenGL support

Enable OpenGL for peers that support it. This means that OWR will now use
GLMemory between source -> renderer and source -> apple h264 encoders.

The implication is that in the above cases color conversion and scaling are done
via GL shaders. Also on Mac and iOS, memory is shared directly between the
camera and the renderer/encoders saving expensive GPU => sysmem memory copies.

Closes #555.
  • Loading branch information...
alessandrod authored and superdump committed Feb 2, 2016
1 parent b43064a commit 37b507c90059764351740c0036744b0f6a2e9fc4
Showing with 40 additions and 18 deletions.
  1. +2 −3 local/owr_local_media_source.c
  2. +38 −15 owr/owr_media_source.c
@@ -352,9 +352,8 @@ fix_video_caps_framerate(GstCapsFeatures *f, GstStructure *s, gpointer user_data
{
GstCaps *ret = GST_CAPS(user_data);
gint fps_n, fps_d;
OWR_UNUSED(f);
gst_caps_append_structure(ret, gst_structure_copy(s));
gst_caps_append_structure_full(ret, gst_structure_copy(s), gst_caps_features_copy(f));
/* Don't mess with non-raw structures */
if (!gst_structure_has_name(s, "video/x-raw"))
@@ -364,7 +363,7 @@ fix_video_caps_framerate(GstCapsFeatures *f, GstStructure *s, gpointer user_data
if (gst_structure_get_fraction(s, "framerate", &fps_n, &fps_d)) {
GstStructure *tmp = gst_structure_copy(s);
gst_structure_remove_field(tmp, "framerate");
gst_caps_append_structure(ret, tmp);
gst_caps_append_structure_full(ret, tmp, gst_caps_features_copy(f));
}
done:
View
@@ -42,6 +42,8 @@
#include "owr_utils.h"
#include <gst/gst.h>
#define GST_USE_UNSTABLE_API
#include <gst/gl/gl.h>
#include <stdio.h>
#ifdef __APPLE__
@@ -309,8 +311,9 @@ static GstElement *owr_media_source_request_source_default(OwrMediaSource *media
}
case OWR_MEDIA_TYPE_VIDEO:
{
GstElement *videorate = NULL, *videoscale, *videoconvert;
GstElement *videorate = NULL, *videoscale = NULL, *videoconvert;
GstStructure *s;
GstCapsFeatures *features;
s = gst_caps_get_structure(caps, 0);
if (gst_structure_has_field(s, "framerate")) {
@@ -325,23 +328,43 @@ static GstElement *owr_media_source_request_source_default(OwrMediaSource *media
gst_structure_remove_field(s, "framerate");
gst_bin_add(GST_BIN(source_bin), videorate);
}
g_object_set(capsfilter, "caps", caps, NULL);
CREATE_ELEMENT_WITH_ID(videoconvert, VIDEO_CONVERT, "source-video-convert", source_id);
CREATE_ELEMENT_WITH_ID(videoscale, "videoscale", "source-video-scale", source_id);
gst_bin_add_many(GST_BIN(source_bin),
queue_pre, videoscale, videoconvert, capsfilter, queue_post, NULL);
LINK_ELEMENTS(capsfilter, queue_post);
features = gst_caps_get_features(caps, 0);
if (gst_caps_features_contains(features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY)) {
GstElement *glupload;
CREATE_ELEMENT_WITH_ID(glupload, "glupload", "source-glupload", source_id);
CREATE_ELEMENT_WITH_ID(videoconvert, "glcolorconvert", "source-glcolorconvert", source_id);
gst_bin_add_many(GST_BIN(source_bin),
queue_pre, glupload, videoconvert, capsfilter, queue_post, NULL);
if (videorate) {
LINK_ELEMENTS(queue_pre, videorate);
LINK_ELEMENTS(videorate, glupload);
} else {
LINK_ELEMENTS(queue_pre, glupload);
}
LINK_ELEMENTS(glupload, videoconvert);
} else {
GstElement *gldownload;
CREATE_ELEMENT_WITH_ID(gldownload, "gldownload", "source-gldownload", source_id);
CREATE_ELEMENT_WITH_ID(videoscale, "videoscale", "source-video-scale", source_id);
CREATE_ELEMENT_WITH_ID(videoconvert, VIDEO_CONVERT, "source-video-convert", source_id);
gst_bin_add_many(GST_BIN(source_bin),
queue_pre, gldownload, videoscale, videoconvert, capsfilter, queue_post, NULL);
if (videorate) {
LINK_ELEMENTS(queue_pre, videorate);
LINK_ELEMENTS(videorate, gldownload);
} else {
LINK_ELEMENTS(queue_pre, gldownload);
}
LINK_ELEMENTS(gldownload, videoscale);
LINK_ELEMENTS(videoscale, videoconvert);
}
LINK_ELEMENTS(videoconvert, capsfilter);
LINK_ELEMENTS(videoscale, videoconvert);
if (videorate) {
LINK_ELEMENTS(videorate, videoscale);
LINK_ELEMENTS(queue_pre, videorate);
} else
LINK_ELEMENTS(queue_pre, videoscale);
LINK_ELEMENTS(capsfilter, queue_post);
break;
}

0 comments on commit 37b507c

Please sign in to comment.