GStreamerVideoCapturer.cpp [plain text]
#include "config.h"
#if ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) && USE(GSTREAMER)
#include "GStreamerVideoCapturer.h"
namespace WebCore {
GStreamerVideoCapturer::GStreamerVideoCapturer(GStreamerCaptureDevice device)
: GStreamerCapturer(device, adoptGRef(gst_caps_new_empty_simple("video/x-raw")))
{
}
GStreamerVideoCapturer::GStreamerVideoCapturer(const char* sourceFactory)
: GStreamerCapturer(sourceFactory, adoptGRef(gst_caps_new_empty_simple("video/x-raw")))
{
}
GstElement* GStreamerVideoCapturer::createConverter()
{
auto converter = gst_parse_bin_from_description("videoscale ! videoconvert ! videorate drop-only=1 average-period=1", TRUE, nullptr);
ASSERT(converter);
return converter;
}
GstVideoInfo GStreamerVideoCapturer::getBestFormat()
{
GRefPtr<GstCaps> caps = adoptGRef(gst_caps_fixate(gst_device_get_caps(m_device.get())));
GstVideoInfo info;
gst_video_info_from_caps(&info, caps.get());
return info;
}
bool GStreamerVideoCapturer::setSize(int width, int height)
{
if (!width || !height)
return false;
m_caps = adoptGRef(gst_caps_copy(m_caps.get()));
gst_caps_set_simple(m_caps.get(), "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, nullptr);
if (!m_capsfilter)
return false;
g_object_set(m_capsfilter.get(), "caps", m_caps.get(), nullptr);
return true;
}
bool GStreamerVideoCapturer::setFrameRate(double frameRate)
{
int numerator, denominator;
gst_util_double_to_fraction(frameRate, &numerator, &denominator);
if (numerator < -G_MAXINT) {
GST_INFO_OBJECT(m_pipeline.get(), "Framerate %f not allowed", frameRate);
return false;
}
if (!numerator) {
GST_INFO_OBJECT(m_pipeline.get(), "Do not force variable framerate");
return false;
}
m_caps = adoptGRef(gst_caps_copy(m_caps.get()));
gst_caps_set_simple(m_caps.get(), "framerate", GST_TYPE_FRACTION, numerator, denominator, nullptr);
if (!m_capsfilter)
return false;
g_object_set(m_capsfilter.get(), "caps", m_caps.get(), nullptr);
return true;
}
}
#endif // ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) && USE(GSTREAMER)