mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Merge branch 'videoimpl-refactor' into setup/dakar-bideew-show-2016
# Conflicts: # mapmap.pro
This commit is contained in:
+14
-9
@@ -467,7 +467,7 @@ void MainWindow::importMedia()
|
||||
// Check if file is image or not
|
||||
// according to file extension
|
||||
if (!fileName.isEmpty()) {
|
||||
if (MM::IMAGE_FILES_FILTER.contains(QFileInfo(fileName).suffix(), Qt::CaseInsensitive))
|
||||
if (!QFileInfo(fileName).suffix().isEmpty() && MM::IMAGE_FILES_FILTER.contains(QFileInfo(fileName).suffix(), Qt::CaseInsensitive))
|
||||
importMediaFile(fileName, true);
|
||||
else
|
||||
importMediaFile(fileName, false);
|
||||
@@ -881,7 +881,7 @@ bool MainWindow::clearProject()
|
||||
}
|
||||
|
||||
uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y,
|
||||
bool isImage, bool live, double rate)
|
||||
bool isImage, VideoType type, double rate)
|
||||
{
|
||||
// Cannot create image with already existing id.
|
||||
if (Paint::getUidAllocator().exists(paintId))
|
||||
@@ -890,14 +890,14 @@ uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y,
|
||||
else
|
||||
{
|
||||
// Check if file exists before
|
||||
if (! fileExists(uri))
|
||||
uri = locateMediaFile(uri, isImage);
|
||||
//if (! fileExists(uri))
|
||||
//uri = locateMediaFile(uri, isImage);
|
||||
|
||||
Texture* tex = 0;
|
||||
if (isImage)
|
||||
tex = new Image(uri, paintId);
|
||||
else {
|
||||
tex = new Video(uri, live, rate, paintId);
|
||||
tex = new Video(uri, type, rate, paintId);
|
||||
}
|
||||
|
||||
// Create new image with corresponding ID.
|
||||
@@ -2378,14 +2378,19 @@ bool MainWindow::importMediaFile(const QString &fileName, bool isImage)
|
||||
{
|
||||
QFile file(fileName);
|
||||
QDir currentDir;
|
||||
VideoType type = VIDEO_URI;
|
||||
|
||||
if (!fileSupported(fileName, isImage))
|
||||
return false;
|
||||
|
||||
bool live = false;
|
||||
if (fileName.contains(QString("/dev/video"))) {
|
||||
type = VIDEO_WEBCAM;
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
if (file.isSequential())
|
||||
live = true;
|
||||
if (file.isSequential()) {
|
||||
type = VIDEO_SHMSRC;
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(this, tr("MapMap Project"),
|
||||
tr("Cannot read file %1:\n%2.")
|
||||
@@ -2398,7 +2403,7 @@ bool MainWindow::importMediaFile(const QString &fileName, bool isImage)
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
// Add media file to model.
|
||||
uint mediaId = createMediaPaint(NULL_UID, fileName, 0, 0, isImage, live);
|
||||
uint mediaId = createMediaPaint(NULL_UID, fileName, 0, 0, isImage, type);
|
||||
|
||||
// Initialize position (center).
|
||||
QSharedPointer<Video> media = qSharedPointerCast<Video>(mappingManager->getPaintById(mediaId));
|
||||
|
||||
+2
-1
@@ -55,6 +55,7 @@
|
||||
|
||||
MM_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
/**
|
||||
* This is the main window of MapMap. It acts as both a view and a controller interface.
|
||||
*/
|
||||
@@ -153,7 +154,7 @@ public slots:
|
||||
bool clearProject();
|
||||
|
||||
/// Create or replace a media paint (or image).
|
||||
uid createMediaPaint(uid paintId, QString uri, float x, float y, bool isImage, bool live=false, double rate=1.0);
|
||||
uid createMediaPaint(uid paintId, QString uri, float x, float y, bool isImage, VideoType type, double rate=1.0);
|
||||
|
||||
/// Create or replace a color paint.
|
||||
uid createColorPaint(uid paintId, QColor color);
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
|
||||
#include "Paint.h"
|
||||
#include "VideoImpl.h"
|
||||
#include "VideoUriDecodeBinImpl.h"
|
||||
#include "VideoV4l2SrcImpl.h"
|
||||
#include "VideoShmSrcImpl.h"
|
||||
#include <iostream>
|
||||
|
||||
MM_BEGIN_NAMESPACE
|
||||
@@ -79,17 +82,31 @@ Video::Video(int id) : Texture(id),
|
||||
_uri(""),
|
||||
_impl(NULL)
|
||||
{
|
||||
_impl = new VideoImpl(false);
|
||||
_impl = new VideoUriDecodeBinImpl();
|
||||
setRate(1);
|
||||
setVolume(1);
|
||||
}
|
||||
|
||||
Video::Video(const QString uri_, bool live, double rate, uid id):
|
||||
Video::Video(const QString uri_, VideoType type, double rate, uid id):
|
||||
Texture(id),
|
||||
_uri(""),
|
||||
_impl(NULL)
|
||||
{
|
||||
_impl = new VideoImpl(live);
|
||||
switch (type) {
|
||||
case VIDEO_URI:
|
||||
_impl = new VideoUriDecodeBinImpl();
|
||||
break;
|
||||
case VIDEO_WEBCAM:
|
||||
_impl = new VideoV4l2SrcImpl();
|
||||
break;
|
||||
case VIDEO_SHMSRC:
|
||||
_impl = new VideoShmSrcImpl();
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "Could not determine type for video source\n ");
|
||||
break;
|
||||
}
|
||||
//_impl = new VideoShmSrcImpl();//V4l2SrcImpl();//UriDecodeBinImpl();
|
||||
setRate(rate);
|
||||
setVolume(1);
|
||||
setUri(uri_);
|
||||
|
||||
@@ -39,6 +39,12 @@
|
||||
|
||||
MM_BEGIN_NAMESPACE
|
||||
|
||||
typedef enum {
|
||||
VIDEO_URI,
|
||||
VIDEO_WEBCAM,
|
||||
VIDEO_SHMSRC
|
||||
} VideoType;
|
||||
|
||||
/**
|
||||
* A Paint is a style that can be applied when drawing potentially any shape.
|
||||
*
|
||||
@@ -250,7 +256,7 @@ public:
|
||||
|
||||
public:
|
||||
Q_INVOKABLE Video(int id=NULL_UID);
|
||||
Video(const QString uri_, bool live, double rate, uid id=NULL_UID);
|
||||
Video(const QString uri_, VideoType type, double rate, uid id=NULL_UID);
|
||||
virtual ~Video();
|
||||
const QString getUri() const
|
||||
{
|
||||
|
||||
+6
-440
@@ -72,17 +72,6 @@ QString VideoImpl::getUri() const
|
||||
return _uri;
|
||||
}
|
||||
|
||||
bool VideoImpl::getAttached()
|
||||
{
|
||||
return _attached;
|
||||
}
|
||||
|
||||
void VideoImpl::setAttached(bool attach)
|
||||
{
|
||||
_attached = attach;
|
||||
}
|
||||
|
||||
|
||||
void VideoImpl::setRate(double rate)
|
||||
{
|
||||
if (rate == 0)
|
||||
@@ -175,8 +164,7 @@ GstFlowReturn VideoImpl::gstNewSampleCallback(GstElement*, VideoImpl *p)
|
||||
// For live sources, video dimensions have not been set, because
|
||||
// gstPadAddedCallback is never called. Fix dimensions from first sample /
|
||||
// caps we receive.
|
||||
if (p->_isSharedMemorySource &&
|
||||
( p->_width == -1 ||
|
||||
if (( p->_width == -1 ||
|
||||
p->_height == -1)) {
|
||||
GstCaps *caps = gst_sample_get_caps(sample);
|
||||
GstStructure *structure;
|
||||
@@ -206,12 +194,12 @@ GstFlowReturn VideoImpl::gstNewSampleCallback(GstElement*, VideoImpl *p)
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
VideoImpl::VideoImpl(bool live) :
|
||||
VideoImpl::VideoImpl() :
|
||||
_bus(NULL),
|
||||
_pipeline(NULL),
|
||||
_uridecodebin0(NULL),
|
||||
_queue0(NULL),
|
||||
_videoconvert0(NULL),
|
||||
capsfilter0(NULL),
|
||||
_appsink0(NULL),
|
||||
_audioqueue0(NULL),
|
||||
_audioconvert0(NULL),
|
||||
@@ -228,13 +216,11 @@ _duration(0),
|
||||
_data(NULL),
|
||||
_seekEnabled(false),
|
||||
_rate(1.0),
|
||||
_isSharedMemorySource(live),
|
||||
_attached(false),
|
||||
_movieReady(false),
|
||||
_playState(false),
|
||||
_uri("")
|
||||
{
|
||||
_pollSource = NULL;
|
||||
|
||||
_mutexLocker = new QMutexLocker(&_mutex);
|
||||
}
|
||||
|
||||
@@ -269,17 +255,11 @@ void VideoImpl::freeResources()
|
||||
}
|
||||
|
||||
// Reset pipeline elements.
|
||||
_uridecodebin0 = NULL;
|
||||
_queue0 = NULL;
|
||||
_videoconvert0 = NULL;
|
||||
_appsink0 = NULL;
|
||||
|
||||
// Unref the shmsrc poller.
|
||||
if (_pollSource)
|
||||
{
|
||||
g_source_unref(_pollSource);
|
||||
_pollSource = NULL;
|
||||
}
|
||||
|
||||
|
||||
qDebug() << "Freeing remaining samples/buffers" << endl;
|
||||
|
||||
@@ -313,325 +293,6 @@ void VideoImpl::resetMovie()
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gstPollShmsrc (void *user_data)
|
||||
{
|
||||
VideoImpl *p = (VideoImpl*) user_data;
|
||||
if (g_file_test(p->getUri().toUtf8().constData(), G_FILE_TEST_EXISTS) &&
|
||||
! p->getAttached())
|
||||
{
|
||||
if (! p->setPlayState(true))
|
||||
{
|
||||
qDebug() << "tried to attach, but starting pipeline failed!" << endl;
|
||||
return false;
|
||||
}
|
||||
p->setAttached(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VideoImpl::loadMovie(const QString& filename)
|
||||
{
|
||||
// Verify if file exists.
|
||||
const gchar* filetestpath = (const gchar*) filename.toUtf8().constData();
|
||||
if (FALSE == g_file_test(filetestpath, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
qDebug() << "File " << filename << " does not exist" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "Opening movie: " << filename << ".";
|
||||
|
||||
// Assign URI.
|
||||
_uri = filename;
|
||||
|
||||
// Free previously allocated structures
|
||||
unloadMovie();
|
||||
|
||||
// Initialize GStreamer.
|
||||
GstElement *capsfilter0 = NULL;
|
||||
GstElement *videoscale0 = NULL;
|
||||
|
||||
// Create the elements.
|
||||
if (_isSharedMemorySource)
|
||||
{
|
||||
_shmsrc0 = gst_element_factory_make ("shmsrc", "shmsrc0");
|
||||
_gdpdepay0 = gst_element_factory_make ("gdpdepay", "gdpdepay0");
|
||||
_pollSource = g_timeout_source_new (500);
|
||||
g_source_set_callback (_pollSource,
|
||||
gstPollShmsrc,
|
||||
this,
|
||||
NULL);
|
||||
g_source_attach (_pollSource, g_main_context_default());
|
||||
g_source_unref (_pollSource);
|
||||
}
|
||||
else {
|
||||
_uridecodebin0 = gst_element_factory_make ("uridecodebin", "uridecodebin0");
|
||||
}
|
||||
_queue0 = gst_element_factory_make ("queue", "queue0");
|
||||
_videoconvert0 = gst_element_factory_make ("videoconvert", "videoconvert0");
|
||||
videoscale0 = gst_element_factory_make ("videoscale", "videoscale0");
|
||||
capsfilter0 = gst_element_factory_make ("capsfilter", "capsfilter0");
|
||||
_appsink0 = gst_element_factory_make ("appsink", "appsink0");
|
||||
|
||||
// Prepare handler data.
|
||||
_videoIsConnected = false;
|
||||
|
||||
_audioqueue0 = gst_element_factory_make ("queue", "audioqueue0");
|
||||
_audioconvert0 = gst_element_factory_make ("audioconvert", "audioconvert0");
|
||||
_audioresample0 = gst_element_factory_make ("audioresample", "audioresample0");
|
||||
_audiovolume0 = gst_element_factory_make ("volume", "audiovolume0");
|
||||
_audiosink0 = gst_element_factory_make ("autoaudiosink", "audiosink0");
|
||||
|
||||
// Create the empty pipeline.
|
||||
_pipeline = gst_pipeline_new ( "video-source-pipeline" );
|
||||
|
||||
if (!_pipeline ||
|
||||
!_queue0 || !_videoconvert0 || ! videoscale0 || ! capsfilter0 ||
|
||||
!_appsink0 || !_audioqueue0 || !_audioconvert0 || !_audioresample0 ||
|
||||
!_audiovolume0 || !_audiosink0)
|
||||
{
|
||||
g_printerr ("Not all elements could be created.\n");
|
||||
|
||||
if (! _pipeline) g_printerr("_pipeline");
|
||||
if (! _queue0) g_printerr("_queue0");
|
||||
if (! _videoconvert0) g_printerr("_videoconvert0");
|
||||
if (! videoscale0) g_printerr("videoscale0");
|
||||
if (! capsfilter0) g_printerr("capsfilter0");
|
||||
if (! _appsink0) g_printerr("_appsink0");
|
||||
if (! _audioqueue0) g_printerr("_audioqueue0");
|
||||
if (! _audioconvert0) g_printerr("_audioconvert0");
|
||||
if (! _audioresample0) g_printerr("_audioresample0");
|
||||
if (! _audiovolume0) g_printerr("_audiovolume0");
|
||||
if (! _audiosink0) g_printerr("_audiosink0");
|
||||
|
||||
unloadMovie();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_isSharedMemorySource)
|
||||
{
|
||||
if (! _shmsrc0 || ! _gdpdepay0)
|
||||
{
|
||||
g_printerr ("Not all elements could be created.\n");
|
||||
if (! _shmsrc0) g_printerr("_shmsrc0");
|
||||
if (! _gdpdepay0) g_printerr("_gdpdepay0");
|
||||
unloadMovie();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! _uridecodebin0)
|
||||
{
|
||||
g_printerr ("Not all elements could be created.\n");
|
||||
if (! _uridecodebin0) g_printerr("_uridecodebin0");
|
||||
unloadMovie();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Build the pipeline. Note that we are NOT linking the source at this
|
||||
// point. We will do it later.
|
||||
gst_bin_add_many (GST_BIN (_pipeline),
|
||||
_isSharedMemorySource ? _shmsrc0 : _uridecodebin0, _queue0,
|
||||
_videoconvert0, videoscale0, capsfilter0, _appsink0,
|
||||
// _audioqueue0, _audioconvert0, _audioresample0, _audiovolume0, _audiosink0,
|
||||
NULL);
|
||||
|
||||
// special case for shmsrc
|
||||
if (_isSharedMemorySource)
|
||||
{
|
||||
gst_bin_add (GST_BIN(_pipeline), _gdpdepay0);
|
||||
if (! gst_element_link_many (_shmsrc0, _gdpdepay0, _queue0, NULL))
|
||||
{
|
||||
g_printerr ("Could not link shmsrc, deserializer and video queue.\n");
|
||||
}
|
||||
}
|
||||
// link uridecodebin -> queue will be performed by callback
|
||||
|
||||
if (! gst_element_link_many (_queue0, _videoconvert0, capsfilter0, videoscale0, _appsink0, NULL))
|
||||
{
|
||||
qDebug() << "Could not link video queue, colorspace converter, caps filter, scaler and app sink." << endl;
|
||||
unloadMovie();
|
||||
return false;
|
||||
}
|
||||
|
||||
// if (! gst_element_link_many (_audioqueue0, _audioconvert0, _audioresample0,
|
||||
// _audiovolume0, _audiosink0, NULL))
|
||||
// {
|
||||
// g_printerr ("Could not link audio queue, converter, resampler and audio sink.\n");
|
||||
// unloadMovie();
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// Process URI.
|
||||
QByteArray ba = filename.toLocal8Bit();
|
||||
gchar *filename_tmp = g_strdup((gchar*) filename.toUtf8().constData());
|
||||
gchar* uri = (gchar*) filename.toUtf8().constData();
|
||||
if (! _isSharedMemorySource &&
|
||||
! gst_uri_is_valid(uri))
|
||||
{
|
||||
// Try to convert filename to URI.
|
||||
GError* error = NULL;
|
||||
qDebug() << "Calling gst_filename_to_uri : " << uri << endl;
|
||||
uri = gst_filename_to_uri(filename_tmp, &error);
|
||||
if (error)
|
||||
{
|
||||
qDebug() << "Filename to URI error: " << error->message << endl;
|
||||
g_clear_error(&error);
|
||||
gst_object_unref (uri);
|
||||
freeResources();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
g_free(filename_tmp);
|
||||
|
||||
if (_isSharedMemorySource)
|
||||
{
|
||||
uri = (gchar*) ba.data();
|
||||
}
|
||||
|
||||
// Set URI to be played.
|
||||
qDebug() << "URI for uridecodebin: " << uri << endl;
|
||||
// FIXME: sometimes it's just the path to the directory that is given, not the file itself.
|
||||
|
||||
// Connect to the pad-added signal
|
||||
if (! _isSharedMemorySource)
|
||||
{
|
||||
// Extract meta info.
|
||||
GError* error = NULL;
|
||||
GstDiscoverer* discoverer = gst_discoverer_new(5*GST_SECOND, &error);
|
||||
if (!discoverer)
|
||||
{
|
||||
qDebug() << "Error creating discoverer: " << error->message << endl;
|
||||
g_clear_error (&error);
|
||||
return false;
|
||||
}
|
||||
|
||||
GstDiscovererInfo* info = gst_discoverer_discover_uri(discoverer, uri, &error);
|
||||
|
||||
if (!info)
|
||||
{
|
||||
qDebug() << "Error getting discoverer info: " << error->message << endl;
|
||||
g_clear_error (&error);
|
||||
return false;
|
||||
}
|
||||
|
||||
GstDiscovererResult result = gst_discoverer_info_get_result(info);
|
||||
|
||||
switch (result) {
|
||||
case GST_DISCOVERER_URI_INVALID:
|
||||
qDebug()<< "Invalid URI '" << uri << "'" << endl;
|
||||
break;
|
||||
case GST_DISCOVERER_ERROR:
|
||||
qDebug()<< "Discoverer error: " << error->message << endl;
|
||||
break;
|
||||
case GST_DISCOVERER_TIMEOUT:
|
||||
qDebug() << "Timeout" << endl;
|
||||
break;
|
||||
case GST_DISCOVERER_BUSY:
|
||||
qDebug() << "Busy" << endl;
|
||||
break;
|
||||
case GST_DISCOVERER_MISSING_PLUGINS:{
|
||||
const GstStructure *s;
|
||||
gchar *str;
|
||||
|
||||
s = gst_discoverer_info_get_misc (info);
|
||||
str = gst_structure_to_string (s);
|
||||
|
||||
qDebug() << "Missing plugins: " << str << endl;
|
||||
g_free (str);
|
||||
break;
|
||||
}
|
||||
case GST_DISCOVERER_OK:
|
||||
qDebug() << "Discovered '" << uri << "'" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
g_clear_error (&error);
|
||||
|
||||
if (result != GST_DISCOVERER_OK) {
|
||||
qDebug() << "This URI cannot be played" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Gather info from video.
|
||||
GList *videoStreams = gst_discoverer_info_get_video_streams (info);
|
||||
if (!videoStreams)
|
||||
{
|
||||
qDebug() << "This URI does not contain any video streams" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve meta-info.
|
||||
_width = gst_discoverer_video_info_get_width((GstDiscovererVideoInfo*)videoStreams->data);
|
||||
_height = gst_discoverer_video_info_get_height((GstDiscovererVideoInfo*)videoStreams->data);
|
||||
_duration = gst_discoverer_info_get_duration(info);
|
||||
_seekEnabled = gst_discoverer_info_get_seekable(info);
|
||||
|
||||
// Free everything.
|
||||
g_object_unref(discoverer);
|
||||
gst_discoverer_info_unref(info);
|
||||
gst_discoverer_stream_info_list_free(videoStreams);
|
||||
|
||||
// Connect pad signal.
|
||||
g_signal_connect (_uridecodebin0, "pad-added", G_CALLBACK (VideoImpl::gstPadAddedCallback), this);
|
||||
|
||||
// Set uri of decoder.
|
||||
g_object_set (_uridecodebin0, "uri", uri, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//qDebug() << "LIVE mode" << uri;
|
||||
g_object_set (_shmsrc0, "socket-path", uri, NULL);
|
||||
g_object_set (_shmsrc0, "is-live", TRUE, NULL);
|
||||
_videoIsConnected = true;
|
||||
}
|
||||
g_free(uri);
|
||||
|
||||
// Configure audio appsink.
|
||||
// TODO: change from mono to stereo
|
||||
// gchar* audioCapsText = g_strdup_printf ("audio/x-raw-float,channels=1,rate=%d,signed=(boolean)true,width=%d,depth=%d,endianness=BYTE_ORDER",
|
||||
// Engine::signalInfo().sampleRate(), (int)(sizeof(Signal_T)*8), (int)(sizeof(Signal_T)*8) );
|
||||
// GstCaps* audioCaps = gst_caps_from_string (audioCapsText);
|
||||
// g_object_set (_audioSink, "emit-signals", TRUE,
|
||||
// "caps", audioCaps,
|
||||
//// "max-buffers", 1, // only one buffer (the last) is maintained in the queue
|
||||
//// "drop", TRUE, // ... other buffers are dropped
|
||||
// NULL);
|
||||
// g_signal_connect (_audioSink, "new-buffer", G_CALLBACK (VideoImpl::gstNewAudioBufferCallback), &_newAudioBufferHandlerData);
|
||||
// gst_caps_unref (audioCaps);
|
||||
// g_free (audioCapsText);
|
||||
|
||||
|
||||
// Configure video appsink.
|
||||
GstCaps *videoCaps = gst_caps_from_string ("video/x-raw,format=RGBA");
|
||||
g_object_set (capsfilter0, "caps", videoCaps, NULL);
|
||||
g_object_set (_appsink0, "emit-signals", TRUE,
|
||||
"max-buffers", 1, // only one buffer (the last) is maintained in the queue
|
||||
"drop", TRUE, // ... other buffers are dropped
|
||||
"sync", TRUE,
|
||||
NULL);
|
||||
g_signal_connect (_appsink0, "new-sample", G_CALLBACK (VideoImpl::gstNewSampleCallback), this);
|
||||
gst_caps_unref (videoCaps);
|
||||
|
||||
// g_object_set (_audiovolume0, "mute", false, NULL);
|
||||
// g_object_set (_audiovolume0, "volume", 0.0, NULL);
|
||||
|
||||
// Listen to the bus.
|
||||
_bus = gst_element_get_bus (_pipeline);
|
||||
|
||||
// Start playing.
|
||||
if (! _isSharedMemorySource &&
|
||||
! setPlayState(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VideoImpl::update()
|
||||
{
|
||||
// Check for end-of-stream or terminate.
|
||||
@@ -766,13 +427,12 @@ void VideoImpl::_checkMessages()
|
||||
g_clear_error(&err);
|
||||
g_free(debug_info);
|
||||
|
||||
if (!_isSharedMemorySource)
|
||||
if (!isLive())
|
||||
{
|
||||
_terminate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_attached = false;
|
||||
gst_element_set_state (_pipeline, GST_STATE_PAUSED);
|
||||
gst_element_set_state (_pipeline, GST_STATE_NULL);
|
||||
gst_element_set_state (_pipeline, GST_STATE_READY);
|
||||
@@ -926,100 +586,6 @@ void VideoImpl::_freeCurrentSample() {
|
||||
_data = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: remove GOTO
|
||||
*/
|
||||
void VideoImpl::gstPadAddedCallback(GstElement *src, GstPad *newPad, VideoImpl* p)
|
||||
{
|
||||
(void)src; //Unused
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
#ifndef Q_OS_OSX
|
||||
// NOTE: This line was causing a problem on Mac OSX: it caused the software to freeze when loading a new movie.
|
||||
qDebug() << "Received new pad '" << GST_PAD_NAME(newPad) << "' from '" << GST_ELEMENT_NAME (src) << "'." << endl;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
GstPad *sinkPad = NULL;
|
||||
|
||||
// Check the new pad's type.
|
||||
GstCaps *newPadCaps = gst_pad_query_caps (newPad, NULL);
|
||||
GstStructure *newPadStruct = gst_caps_get_structure (newPadCaps, 0);
|
||||
const gchar *newPadType = gst_structure_get_name (newPadStruct);
|
||||
gchar *newPadStructStr = gst_structure_to_string(newPadStruct);
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
qDebug() << "Structure is " << newPadStructStr << "." << endl;
|
||||
#endif
|
||||
g_free(newPadStructStr);
|
||||
|
||||
// Check for video pads.
|
||||
if (g_str_has_prefix (newPadType, "video/x-raw"))
|
||||
{
|
||||
sinkPad = gst_element_get_static_pad (p->_queue0, "sink");
|
||||
gst_structure_get_int(newPadStruct, "width", &p->_width);
|
||||
gst_structure_get_int(newPadStruct, "height", &p->_height);
|
||||
}
|
||||
|
||||
// Check for audio pads.
|
||||
else if (g_str_has_prefix (newPadType, "audio/x-raw"))
|
||||
{
|
||||
sinkPad = gst_element_get_static_pad (p->_audioqueue0, "sink");
|
||||
}
|
||||
|
||||
// Other types: ignore.
|
||||
else {
|
||||
qDebug() << " It has type '" << newPadType << "' which is not raw audio/video: ignored." << endl;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// If our converter is already linked, we have nothing to do here.
|
||||
if (gst_pad_is_linked (sinkPad))
|
||||
{
|
||||
// Best prefixes.
|
||||
if (g_str_has_prefix (newPadType, "audio/x-raw-float") ||
|
||||
g_str_has_prefix (newPadType, "video/x-raw-int") )
|
||||
{
|
||||
qDebug() << " Found a better pad." << endl;
|
||||
GstPad* oldPad = gst_pad_get_peer(sinkPad);
|
||||
gst_pad_unlink(oldPad, sinkPad);
|
||||
g_object_unref(oldPad);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
qDebug() << " We are already linked: ignoring." << endl;
|
||||
#endif
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt the link.
|
||||
if (GST_PAD_LINK_FAILED (gst_pad_link (newPad, sinkPad)))
|
||||
{
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
qDebug() << " Type is '" << newPadType << "' but link failed." << endl;
|
||||
#endif // ifdef
|
||||
goto exit;
|
||||
} else {
|
||||
p->_videoIsConnected = true;
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
qDebug() << " Link succeeded (type '" << newPadType << "')." << endl;
|
||||
#endif // ifdef
|
||||
}
|
||||
|
||||
exit:
|
||||
// Unreference the new pad's caps, if we got them.
|
||||
if (newPadCaps != NULL)
|
||||
{
|
||||
gst_caps_unref (newPadCaps);
|
||||
}
|
||||
|
||||
// Unreference the sink pad.
|
||||
if (sinkPad != NULL)
|
||||
{
|
||||
gst_object_unref (sinkPad);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoImpl::lockMutex()
|
||||
{
|
||||
_mutexLocker->relock();
|
||||
|
||||
+151
-38
@@ -58,8 +58,10 @@ public:
|
||||
* This media player works for both video files and shared memory sockets.
|
||||
* If live is true, it's a shared memory socket.
|
||||
*/
|
||||
VideoImpl(bool live=false);
|
||||
~VideoImpl();
|
||||
VideoImpl();
|
||||
virtual ~VideoImpl();
|
||||
|
||||
|
||||
|
||||
// void setUri(const QString uri);
|
||||
/**
|
||||
@@ -88,12 +90,6 @@ public:
|
||||
*/
|
||||
QString getUri() const;
|
||||
|
||||
/**
|
||||
* When using the shared memory source, returns whether or not we
|
||||
* are attached to a shared memory socket.
|
||||
*/
|
||||
bool getAttached();
|
||||
|
||||
/**
|
||||
* Returns the raw image of the last video frame.
|
||||
* It is currently unused!
|
||||
@@ -115,20 +111,144 @@ public:
|
||||
bool isReady() const { return _isMovieReady() && videoIsConnected(); }
|
||||
|
||||
bool videoIsConnected() const { return _videoIsConnected; }
|
||||
void videoConnect() { _videoIsConnected = true; }
|
||||
|
||||
/**
|
||||
* Performs regular updates (checks if movie is ready and checks messages).
|
||||
*/
|
||||
void update();
|
||||
|
||||
// void runAudio();
|
||||
virtual bool isLive() = 0;
|
||||
|
||||
/**
|
||||
* Loads a new movie file.
|
||||
* Loads a new video stream
|
||||
*
|
||||
* Creates a new GStreamer pipeline, opens a movie or a shmsrc socket.
|
||||
* Creates a new GStreamer pipeline, opens a movie, webcam or shmsrc socket,
|
||||
* depending on subclass.
|
||||
*/
|
||||
bool loadMovie(const QString& filename);
|
||||
virtual bool loadMovie(const QString& filename) {
|
||||
// Verify if file exists.
|
||||
const gchar* filetestpath = (const gchar*) filename.toUtf8().constData();
|
||||
if (FALSE == g_file_test(filetestpath, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
qDebug() << "File " << filename << " does not exist" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "Opening movie: " << filename << ".";
|
||||
|
||||
// Assign URI.
|
||||
_uri = filename;
|
||||
|
||||
// Free previously allocated structures
|
||||
unloadMovie();
|
||||
|
||||
// Initialize GStreamer.
|
||||
|
||||
GstElement *videoscale0 = NULL;
|
||||
|
||||
// Create the elements.
|
||||
_queue0 = gst_element_factory_make ("queue", "queue0");
|
||||
_videoconvert0 = gst_element_factory_make ("videoconvert", "videoconvert0");
|
||||
videoscale0 = gst_element_factory_make ("videoscale", "videoscale0");
|
||||
capsfilter0 = gst_element_factory_make ("capsfilter", "capsfilter0");
|
||||
_appsink0 = gst_element_factory_make ("appsink", "appsink0");
|
||||
|
||||
// Prepare handler data.
|
||||
_videoIsConnected = false;
|
||||
|
||||
_audioqueue0 = gst_element_factory_make ("queue", "audioqueue0");
|
||||
_audioconvert0 = gst_element_factory_make ("audioconvert", "audioconvert0");
|
||||
_audioresample0 = gst_element_factory_make ("audioresample", "audioresample0");
|
||||
_audiovolume0 = gst_element_factory_make ("volume", "audiovolume0");
|
||||
_audiosink0 = gst_element_factory_make ("autoaudiosink", "audiosink0");
|
||||
|
||||
// Create the empty pipeline.
|
||||
_pipeline = gst_pipeline_new ( "video-source-pipeline" );
|
||||
if (!_pipeline ||
|
||||
!_queue0 || !_videoconvert0 || ! videoscale0 || ! capsfilter0 ||
|
||||
!_appsink0 || !_audioqueue0 || !_audioconvert0 || !_audioresample0 ||
|
||||
!_audiovolume0 || !_audiosink0)
|
||||
{
|
||||
g_printerr ("Not all elements could be created.\n");
|
||||
if (! _pipeline) g_printerr("_pipeline");
|
||||
if (! _queue0) g_printerr("_queue0");
|
||||
if (! _videoconvert0) g_printerr("_videoconvert0");
|
||||
if (! videoscale0) g_printerr("videoscale0");
|
||||
if (! capsfilter0) g_printerr("capsfilter0");
|
||||
if (! _appsink0) g_printerr("_appsink0");
|
||||
if (! _audioqueue0) g_printerr("_audioqueue0");
|
||||
if (! _audioconvert0) g_printerr("_audioconvert0");
|
||||
if (! _audioresample0) g_printerr("_audioresample0");
|
||||
if (! _audiovolume0) g_printerr("_audiovolume0");
|
||||
if (! _audiosink0) g_printerr("_audiosink0");
|
||||
unloadMovie();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Build the pipeline. Note that we are NOT linking the source at this
|
||||
// point. We will do it later.
|
||||
gst_bin_add_many (GST_BIN (_pipeline),
|
||||
_queue0, _videoconvert0, videoscale0, capsfilter0, _appsink0,
|
||||
// _audioqueue0, _audioconvert0, _audioresample0, _audiovolume0, _audiosink0,
|
||||
NULL);
|
||||
// special case for shmsrc
|
||||
// link uridecodebin -> queue will be performed by callback
|
||||
|
||||
if (! gst_element_link_many (_queue0, _videoconvert0, capsfilter0, videoscale0, _appsink0, NULL))
|
||||
{
|
||||
qDebug() << "Could not link video queue, colorspace converter, caps filter, scaler and app sink." << endl;
|
||||
unloadMovie();
|
||||
return false;
|
||||
}
|
||||
|
||||
// if (! gst_element_link_many (_audioqueue0, _audioconvert0, _audioresample0,
|
||||
// _audiovolume0, _audiosink0, NULL))
|
||||
// {
|
||||
// g_printerr ("Could not link audio queue, converter, resampler and audio sink.\n");
|
||||
// unloadMovie();
|
||||
// return false;
|
||||
// }
|
||||
// Configure audio appsink.
|
||||
// TODO: change from mono to stereo
|
||||
// gchar* audioCapsText = g_strdup_printf ("audio/x-raw-float,channels=1,rate=%d,signed=(boolean)true,width=%d,depth=%d,endianness=BYTE_ORDER",
|
||||
// Engine::signalInfo().sampleRate(), (int)(sizeof(Signal_T)*8), (int)(sizeof(Signal_T)*8) );
|
||||
// GstCaps* audioCaps = gst_caps_from_string (audioCapsText);
|
||||
// g_object_set (_audioSink, "emit-signals", TRUE,
|
||||
// "caps", audioCaps,
|
||||
//// "max-buffers", 1, // only one buffer (the last) is maintained in the queue
|
||||
//// "drop", TRUE, // ... other buffers are dropped
|
||||
// NULL);
|
||||
// g_signal_connect (_audioSink, "new-buffer", G_CALLBACK (VideoImpl::gstNewAudioBufferCallback), &_newAudioBufferHandlerData);
|
||||
// gst_caps_unref (audioCaps);
|
||||
// g_free (audioCapsText);
|
||||
|
||||
|
||||
// Configure video appsink.
|
||||
GstCaps *videoCaps = gst_caps_from_string ("video/x-raw,format=RGBA");
|
||||
g_object_set (capsfilter0, "caps", videoCaps, NULL);
|
||||
|
||||
g_object_set (_appsink0, "emit-signals", TRUE,
|
||||
"max-buffers", 1, // only one buffer (the last) is maintained in the queue
|
||||
"drop", TRUE, // ... other buffers are dropped
|
||||
"sync", TRUE,
|
||||
NULL);
|
||||
|
||||
g_signal_connect (_appsink0, "new-sample", G_CALLBACK (VideoImpl::gstNewSampleCallback), this);
|
||||
gst_caps_unref (videoCaps);
|
||||
|
||||
|
||||
// g_object_set (_audiovolume0, "mute", false, NULL);
|
||||
// g_object_set (_audiovolume0, "volume", 0.0, NULL);
|
||||
|
||||
// Listen to the bus.
|
||||
_bus = gst_element_get_bus (_pipeline);
|
||||
|
||||
// Start playing.
|
||||
|
||||
return true;
|
||||
}
|
||||
//virtual GstElement *buildPipeline(Element sink) = 0;
|
||||
//virtual void loadMovie(const QString& filename) = 0;
|
||||
|
||||
bool setPlayState(bool play);
|
||||
bool getPlayState() const { return _playState; }
|
||||
@@ -138,12 +258,6 @@ public:
|
||||
bool seekTo(double position);
|
||||
bool seekTo(guint64 positionNanoSeconds);
|
||||
|
||||
/**
|
||||
* Tells the VideoImpl that we are actually reading from a shmsrc.
|
||||
* Called from the GStreamer callback of the shmsrc.
|
||||
*/
|
||||
void setAttached(bool attach);
|
||||
|
||||
void setRate(double rate=1.0);
|
||||
double getRate() const { return _rate; }
|
||||
|
||||
@@ -185,7 +299,7 @@ public:
|
||||
|
||||
// GStreamer callback that plugs the audio/video pads into the proper elements when they
|
||||
// are made available by the source.
|
||||
static void gstPadAddedCallback(GstElement *src, GstPad *newPad, VideoImpl* p);
|
||||
//static void gstPadAddedCallback(GstElement *src, GstPad *newPad, VideoImpl* p);
|
||||
|
||||
/// Locks mutex (default = no effect).
|
||||
void lockMutex();
|
||||
@@ -196,19 +310,27 @@ public:
|
||||
/// Wait until first data samples are available (blocking).
|
||||
bool waitForNextBits(int timeout, const uchar** bits=0);
|
||||
|
||||
// FIXME these should be private, accessed my subclasses
|
||||
int _width;
|
||||
int _height;
|
||||
// bool _isSeekable;
|
||||
guint64 _duration; // duration (in nanoseconds) (unused for now)
|
||||
bool _videoIsConnected;
|
||||
GstElement *_queue0;
|
||||
GstElement *_audioqueue0;
|
||||
GstElement *_pipeline;
|
||||
GstElement *capsfilter0;
|
||||
bool _seekEnabled;
|
||||
|
||||
private:
|
||||
//locals
|
||||
|
||||
// gstreamer elements
|
||||
GstBus *_bus;
|
||||
GstElement *_pipeline;
|
||||
GstElement *_uridecodebin0;
|
||||
GstElement *_shmsrc0;
|
||||
GstElement *_gdpdepay0;
|
||||
GstElement *_queue0;
|
||||
|
||||
GstElement *_videoconvert0;
|
||||
GstElement *_appsink0;
|
||||
GstElement *_audioqueue0;
|
||||
|
||||
GstElement *_audioconvert0;
|
||||
GstElement *_audioresample0;
|
||||
GstElement *_audiovolume0;
|
||||
@@ -225,23 +347,15 @@ private:
|
||||
/**
|
||||
* Contains meta informations about current file.
|
||||
*/
|
||||
int _width;
|
||||
int _height;
|
||||
// bool _isSeekable;
|
||||
guint64 _duration; // duration (in nanoseconds) (unused for now)
|
||||
|
||||
bool _videoIsConnected;
|
||||
|
||||
/**
|
||||
* shmsrc socket poller.
|
||||
*/
|
||||
GSource *_pollSource;
|
||||
|
||||
|
||||
/// Raw image data of the last video frame.
|
||||
uchar *_data;
|
||||
|
||||
/// Is seek enabled on the current pipeline?
|
||||
bool _seekEnabled;
|
||||
|
||||
|
||||
/// Playback rate (negative ==> reverse).
|
||||
double _rate;
|
||||
@@ -251,8 +365,7 @@ private:
|
||||
/// Whether or not we are reading video from a shmsrc.
|
||||
bool _isSharedMemorySource;
|
||||
|
||||
/// Whether or not we are attached to a shmsrc, if using a shmsrc.
|
||||
bool _attached;
|
||||
|
||||
|
||||
// unused
|
||||
bool _terminate;
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* VideoShmSrcImpl.cpp
|
||||
*
|
||||
* (c) 2016 Vasilis Liaskovitis -- vliaskov@gmail.com
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
|
||||
* (c) 2012 Jean-Sebastien Senecal
|
||||
* (c) 2004 Mathieu Guindon, Julien Keable
|
||||
* Based on code from Drone http://github.com/sofian/drone
|
||||
* Based on code from the GStreamer Tutorials http://docs.gstreamer.com/display/GstSDK/Tutorials
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "VideoShmSrcImpl.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
MM_BEGIN_NAMESPACE
|
||||
|
||||
VideoShmSrcImpl::VideoShmSrcImpl() :
|
||||
_shmsrc0(NULL),
|
||||
_gdpdepay0(NULL),
|
||||
_pollSource(NULL),
|
||||
_attached(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool VideoShmSrcImpl::getAttached()
|
||||
{
|
||||
return _attached;
|
||||
}
|
||||
|
||||
void VideoShmSrcImpl::setAttached(bool attach)
|
||||
{
|
||||
_attached = attach;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gstPollShmsrc (void *user_data)
|
||||
{
|
||||
VideoShmSrcImpl *p = (VideoShmSrcImpl*) user_data;
|
||||
if (g_file_test(p->getUri().toUtf8().constData(), G_FILE_TEST_EXISTS) &&
|
||||
! p->getAttached())
|
||||
{
|
||||
if (! p->setPlayState(true))
|
||||
{
|
||||
qDebug() << "tried to attach, but starting pipeline failed!" << endl;
|
||||
return false;
|
||||
}
|
||||
p->setAttached(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VideoShmSrcImpl::loadMovie(const QString& path) {
|
||||
|
||||
VideoImpl::loadMovie(path);
|
||||
|
||||
_shmsrc0 = gst_element_factory_make ("shmsrc", "shmsrc0");
|
||||
_gdpdepay0 = gst_element_factory_make ("gdpdepay", "gdpdepay0");
|
||||
_pollSource = g_timeout_source_new (500);
|
||||
|
||||
g_source_set_callback (_pollSource,
|
||||
gstPollShmsrc,
|
||||
this,
|
||||
NULL);
|
||||
g_source_attach (_pollSource, g_main_context_default());
|
||||
g_source_unref (_pollSource);
|
||||
|
||||
if (! _shmsrc0 || ! _gdpdepay0)
|
||||
{
|
||||
g_printerr ("Not all elements could be created.\n");
|
||||
if (! _shmsrc0) g_printerr("_shmsrc0");
|
||||
if (! _gdpdepay0) g_printerr("_gdpdepay0");
|
||||
unloadMovie();
|
||||
return -1;
|
||||
}
|
||||
|
||||
gst_bin_add_many (GST_BIN(_pipeline), _shmsrc0, _gdpdepay0, NULL);
|
||||
if (! gst_element_link_many (_shmsrc0, _gdpdepay0, _queue0, NULL))
|
||||
{
|
||||
g_printerr ("Could not link shmsrc, deserializer and video queue.\n");
|
||||
}
|
||||
|
||||
QByteArray ba = path.toLocal8Bit();
|
||||
gchar* uri = (gchar*) path.toUtf8().constData();
|
||||
uri = (gchar*) ba.data();
|
||||
|
||||
//qDebug() << "LIVE mode" << uri;
|
||||
g_object_set (_shmsrc0, "socket-path", uri, NULL);
|
||||
g_object_set (_shmsrc0, "is-live", TRUE, NULL);
|
||||
_videoIsConnected = true;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VideoShmSrcImpl::~VideoShmSrcImpl()
|
||||
{
|
||||
// Unref the shmsrc poller.
|
||||
if (_pollSource)
|
||||
{
|
||||
g_source_unref(_pollSource);
|
||||
_pollSource = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
MM_END_NAMESPACE
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* VideoShmSrcImpl.h
|
||||
*
|
||||
* (c) 2016 Vasilis Liaskovitis -- vliaskov@gmail.com
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
|
||||
* (c) 2012 Jean-Sebastien Senecal
|
||||
* (c) 2004 Mathieu Guindon, Julien Keable
|
||||
* Based on code from Drone http://github.com/sofian/drone
|
||||
* Based on code from the GStreamer Tutorials http://docs.gstreamer.com/display/GstSDK/Tutorials
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_SHMSRC_IMPL_H_
|
||||
#define VIDEO_SHMSRC_IMPL_H_
|
||||
|
||||
// GStreamer includes.
|
||||
#include <gst/gst.h>
|
||||
#include <gst/app/gstappsink.h>
|
||||
#include <gst/pbutils/pbutils.h>
|
||||
|
||||
// Other includes.
|
||||
#include "MM.h"
|
||||
#include <QtOpenGL>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
|
||||
#include <glib.h>
|
||||
#if __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "VideoImpl.h"
|
||||
|
||||
MM_BEGIN_NAMESPACE
|
||||
|
||||
class VideoShmSrcImpl : public VideoImpl
|
||||
{
|
||||
public:
|
||||
VideoShmSrcImpl();
|
||||
~VideoShmSrcImpl();
|
||||
bool loadMovie(const QString& path);
|
||||
bool isLive() {return true;}
|
||||
bool getAttached();
|
||||
void setAttached(bool attach);
|
||||
|
||||
private:
|
||||
GstElement *_shmsrc0;
|
||||
GstElement *_gdpdepay0;
|
||||
/**
|
||||
* shmsrc socket poller.
|
||||
*/
|
||||
GSource *_pollSource;
|
||||
/// Whether or not we are attached to a shmsrc.
|
||||
bool _attached;
|
||||
};
|
||||
|
||||
MM_END_NAMESPACE
|
||||
#endif /* ifndef */
|
||||
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* VideoUriDecodeBinImpl.cpp
|
||||
*
|
||||
* (c) 2016 Vasilis Liaskovitis -- vliaskov@gmail.com
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
|
||||
* (c) 2012 Jean-Sebastien Senecal
|
||||
* (c) 2004 Mathieu Guindon, Julien Keable
|
||||
* Based on code from Drone http://github.com/sofian/drone
|
||||
* Based on code from the GStreamer Tutorials http://docs.gstreamer.com/display/GstSDK/Tutorials
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "VideoUriDecodeBinImpl.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
MM_BEGIN_NAMESPACE
|
||||
|
||||
VideoUriDecodeBinImpl::VideoUriDecodeBinImpl() :
|
||||
_uridecodebin0(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void VideoUriDecodeBinImpl::gstPadAddedCallback(GstElement *src, GstPad *newPad, VideoUriDecodeBinImpl* p)
|
||||
{
|
||||
(void)src; //Unused
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
#ifndef Q_OS_OSX
|
||||
// NOTE: This line was causing a problem on Mac OSX: it caused the software to freeze when loading a new movie.
|
||||
qDebug() << "Received new pad '" << GST_PAD_NAME(newPad) << "' from '" << GST_ELEMENT_NAME (src) << "'." << endl;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
GstPad *sinkPad = NULL;
|
||||
|
||||
// Check the new pad's type.
|
||||
GstCaps *newPadCaps = gst_pad_query_caps (newPad, NULL);
|
||||
GstStructure *newPadStruct = gst_caps_get_structure (newPadCaps, 0);
|
||||
const gchar *newPadType = gst_structure_get_name (newPadStruct);
|
||||
gchar *newPadStructStr = gst_structure_to_string(newPadStruct);
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
qDebug() << "Structure is " << newPadStructStr << "." << endl;
|
||||
#endif
|
||||
g_free(newPadStructStr);
|
||||
|
||||
// Check for video pads.
|
||||
if (g_str_has_prefix (newPadType, "video/x-raw"))
|
||||
{
|
||||
sinkPad = gst_element_get_static_pad (p->_queue0, "sink");
|
||||
gst_structure_get_int(newPadStruct, "width", &p->_width);
|
||||
gst_structure_get_int(newPadStruct, "height", &p->_height);
|
||||
}
|
||||
|
||||
// Check for audio pads.
|
||||
else if (g_str_has_prefix (newPadType, "audio/x-raw"))
|
||||
{
|
||||
sinkPad = gst_element_get_static_pad (p->_audioqueue0, "sink");
|
||||
}
|
||||
|
||||
// Other types: ignore.
|
||||
else {
|
||||
qDebug() << " It has type '" << newPadType << "' which is not raw audio/video: ignored." << endl;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// If our converter is already linked, we have nothing to do here.
|
||||
if (gst_pad_is_linked (sinkPad))
|
||||
{
|
||||
// Best prefixes.
|
||||
if (g_str_has_prefix (newPadType, "audio/x-raw-float") ||
|
||||
g_str_has_prefix (newPadType, "video/x-raw-int") )
|
||||
{
|
||||
qDebug() << " Found a better pad." << endl;
|
||||
GstPad* oldPad = gst_pad_get_peer(sinkPad);
|
||||
gst_pad_unlink(oldPad, sinkPad);
|
||||
g_object_unref(oldPad);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
qDebug() << " We are already linked: ignoring." << endl;
|
||||
#endif
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt the link.
|
||||
if (GST_PAD_LINK_FAILED (gst_pad_link (newPad, sinkPad)))
|
||||
{
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
qDebug() << " Type is '" << newPadType << "' but link failed." << endl;
|
||||
#endif // ifdef
|
||||
goto exit;
|
||||
} else {
|
||||
p->videoConnect();
|
||||
#ifdef VIDEO_IMPL_VERBOSE
|
||||
qDebug() << " Link succeeded (type '" << newPadType << "')." << endl;
|
||||
#endif // ifdef
|
||||
}
|
||||
|
||||
exit:
|
||||
// Unreference the new pad's caps, if we got them.
|
||||
if (newPadCaps != NULL)
|
||||
{
|
||||
gst_caps_unref (newPadCaps);
|
||||
}
|
||||
|
||||
// Unreference the sink pad.
|
||||
if (sinkPad != NULL)
|
||||
{
|
||||
gst_object_unref (sinkPad);
|
||||
}
|
||||
}
|
||||
|
||||
bool VideoUriDecodeBinImpl::loadMovie(const QString& path) {
|
||||
VideoImpl::loadMovie(path);
|
||||
|
||||
_uridecodebin0 = gst_element_factory_make("uridecodebin", NULL);
|
||||
_videoIsConnected = false;
|
||||
|
||||
if ( !_uridecodebin0)
|
||||
{
|
||||
g_printerr ("Not all elements could be created.\n");
|
||||
unloadMovie();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Build the pipeline. Note that we are NOT linking the source at this
|
||||
// point. We will do it later.
|
||||
gst_bin_add_many (GST_BIN (_pipeline),
|
||||
_uridecodebin0,
|
||||
NULL);
|
||||
|
||||
// Process URI.
|
||||
QByteArray ba = path.toLocal8Bit();
|
||||
gchar *filename_tmp = g_strdup((gchar*) path.toUtf8().constData());
|
||||
gchar* uri = (gchar*) path.toUtf8().constData();
|
||||
if (! gst_uri_is_valid(uri))
|
||||
{
|
||||
// Try to convert filename to URI.
|
||||
GError* error = NULL;
|
||||
qDebug() << "Calling gst_filename_to_uri : " << uri << endl;
|
||||
uri = gst_filename_to_uri(filename_tmp, &error);
|
||||
if (error)
|
||||
{
|
||||
qDebug() << "Filename to URI error: " << error->message << endl;
|
||||
g_clear_error(&error);
|
||||
gst_object_unref (uri);
|
||||
freeResources();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
g_free(filename_tmp);
|
||||
|
||||
// Connect to the pad-added signal
|
||||
// Extract meta info.
|
||||
GError* error = NULL;
|
||||
GstDiscoverer* discoverer = gst_discoverer_new(5*GST_SECOND, &error);
|
||||
if (!discoverer)
|
||||
{
|
||||
qDebug() << "Error creating discoverer: " << error->message << endl;
|
||||
g_clear_error (&error);
|
||||
return false;
|
||||
}
|
||||
|
||||
GstDiscovererInfo* info = gst_discoverer_discover_uri(discoverer, uri, &error);
|
||||
|
||||
if (!info)
|
||||
{
|
||||
qDebug() << "Error getting discoverer info: " << error->message << endl;
|
||||
g_clear_error (&error);
|
||||
return false;
|
||||
}
|
||||
|
||||
GstDiscovererResult result = gst_discoverer_info_get_result(info);
|
||||
|
||||
switch (result) {
|
||||
case GST_DISCOVERER_URI_INVALID:
|
||||
qDebug()<< "Invalid URI '" << uri << "'" << endl;
|
||||
break;
|
||||
case GST_DISCOVERER_ERROR:
|
||||
qDebug()<< "Discoverer error: " << error->message << endl;
|
||||
break;
|
||||
case GST_DISCOVERER_TIMEOUT:
|
||||
qDebug() << "Timeout" << endl;
|
||||
break;
|
||||
case GST_DISCOVERER_BUSY:
|
||||
qDebug() << "Busy" << endl;
|
||||
break;
|
||||
case GST_DISCOVERER_MISSING_PLUGINS:{
|
||||
const GstStructure *s;
|
||||
gchar *str;
|
||||
|
||||
s = gst_discoverer_info_get_misc (info);
|
||||
str = gst_structure_to_string (s);
|
||||
|
||||
qDebug() << "Missing plugins: " << str << endl;
|
||||
g_free (str);
|
||||
break;
|
||||
}
|
||||
case GST_DISCOVERER_OK:
|
||||
qDebug() << "Discovered '" << uri << "'" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
g_clear_error (&error);
|
||||
|
||||
if (result != GST_DISCOVERER_OK) {
|
||||
qDebug() << "This URI cannot be played" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Gather info from video.
|
||||
GList *videoStreams = gst_discoverer_info_get_video_streams (info);
|
||||
if (!videoStreams)
|
||||
{
|
||||
qDebug() << "This URI does not contain any video streams" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve meta-info.
|
||||
_width = gst_discoverer_video_info_get_width((GstDiscovererVideoInfo*)videoStreams->data);
|
||||
_height = gst_discoverer_video_info_get_height((GstDiscovererVideoInfo*)videoStreams->data);
|
||||
_duration = gst_discoverer_info_get_duration(info);
|
||||
_seekEnabled = gst_discoverer_info_get_seekable(info);
|
||||
|
||||
// Free everything.
|
||||
g_object_unref(discoverer);
|
||||
gst_discoverer_info_unref(info);
|
||||
gst_discoverer_stream_info_list_free(videoStreams);
|
||||
|
||||
// Connect pad signal.
|
||||
g_signal_connect (_uridecodebin0, "pad-added", G_CALLBACK (VideoUriDecodeBinImpl::gstPadAddedCallback), this);
|
||||
|
||||
// Set uri of decoder.
|
||||
g_object_set (_uridecodebin0, "uri", uri, NULL);
|
||||
|
||||
|
||||
|
||||
setPlayState(true);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VideoUriDecodeBinImpl::~VideoUriDecodeBinImpl()
|
||||
{
|
||||
}
|
||||
|
||||
MM_END_NAMESPACE
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* VideoUriDecodeBinImpl.h
|
||||
*
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
|
||||
* (c) 2012 Jean-Sebastien Senecal
|
||||
* (c) 2004 Mathieu Guindon, Julien Keable
|
||||
* Based on code from Drone http://github.com/sofian/drone
|
||||
* Based on code from the GStreamer Tutorials http://docs.gstreamer.com/display/GstSDK/Tutorials
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_URIDECODEBIN_IMPL_H_
|
||||
#define VIDEO_URIDECODEBIN_IMPL_H_
|
||||
|
||||
// GStreamer includes.
|
||||
#include <gst/gst.h>
|
||||
#include <gst/app/gstappsink.h>
|
||||
#include <gst/pbutils/pbutils.h>
|
||||
|
||||
// Other includes.
|
||||
#include "MM.h"
|
||||
#include <QtOpenGL>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
|
||||
#include <glib.h>
|
||||
#if __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "VideoImpl.h"
|
||||
|
||||
MM_BEGIN_NAMESPACE
|
||||
|
||||
class VideoUriDecodeBinImpl : public VideoImpl
|
||||
{
|
||||
public:
|
||||
VideoUriDecodeBinImpl();
|
||||
~VideoUriDecodeBinImpl();
|
||||
static void gstPadAddedCallback(GstElement *src, GstPad *newPad, VideoUriDecodeBinImpl* p);
|
||||
bool loadMovie(const QString& path);
|
||||
bool isLive() {return false;}
|
||||
|
||||
private:
|
||||
GstElement *_uridecodebin0;
|
||||
//bool _videoIsConnected;
|
||||
};
|
||||
|
||||
MM_END_NAMESPACE
|
||||
|
||||
#endif /* ifndef */
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* VideoV4l2SrcImpl.cpp
|
||||
*
|
||||
* (c) 2016 Vasilis Liaskovitis -- vliaskov@gmail.com
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
|
||||
* (c) 2012 Jean-Sebastien Senecal
|
||||
* (c) 2004 Mathieu Guindon, Julien Keable
|
||||
* Based on code from Drone http://github.com/sofian/drone
|
||||
* Based on code from the GStreamer Tutorials http://docs.gstreamer.com/display/GstSDK/Tutorials
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "VideoV4l2SrcImpl.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
MM_BEGIN_NAMESPACE
|
||||
|
||||
VideoV4l2SrcImpl::VideoV4l2SrcImpl() :
|
||||
_v4l2src0(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool VideoV4l2SrcImpl::loadMovie(const QString& path) {
|
||||
VideoImpl::loadMovie(path);
|
||||
|
||||
_v4l2src0 = gst_element_factory_make("v4l2src", NULL);
|
||||
_videoIsConnected = false;
|
||||
|
||||
if ( !_v4l2src0)
|
||||
{
|
||||
g_printerr ("Not all elements could be created.\n");
|
||||
unloadMovie();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Build the pipeline. Note that we are NOT linking the source at this
|
||||
// point. We will do it later.
|
||||
gst_bin_add_many (GST_BIN (_pipeline),
|
||||
_v4l2src0,
|
||||
NULL);
|
||||
|
||||
if (! gst_element_link_many (_v4l2src0, _queue0, NULL))
|
||||
{
|
||||
qDebug() << "Could not link v4l2src" << endl;
|
||||
unloadMovie();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Configure video appsink.
|
||||
GstCaps *videoCaps = gst_caps_from_string ("video/x-raw,format=RGBA,width=640,height=480");
|
||||
g_object_set (capsfilter0, "caps", videoCaps, NULL);
|
||||
gst_caps_unref (videoCaps);
|
||||
|
||||
// Retrieve meta-info.
|
||||
_width = 640;
|
||||
_height = 480;
|
||||
//_duration = ;
|
||||
_seekEnabled = false;
|
||||
|
||||
|
||||
setPlayState(true);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VideoV4l2SrcImpl::~VideoV4l2SrcImpl()
|
||||
{
|
||||
}
|
||||
MM_END_NAMESPACE
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* VideoV4l2SrcImpl.h
|
||||
*
|
||||
* (c) 2016 Vasilis Liaskovitis -- vliaskov@gmail.com
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
|
||||
* (c) 2012 Jean-Sebastien Senecal
|
||||
* (c) 2004 Mathieu Guindon, Julien Keable
|
||||
* Based on code from Drone http://github.com/sofian/drone
|
||||
* Based on code from the GStreamer Tutorials http://docs.gstreamer.com/display/GstSDK/Tutorials
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_V4L2SRC_IMPL_H_
|
||||
#define VIDEO_V4L2SRC_IMPL_H_
|
||||
|
||||
// GStreamer includes.
|
||||
#include <gst/gst.h>
|
||||
#include <gst/app/gstappsink.h>
|
||||
#include <gst/pbutils/pbutils.h>
|
||||
|
||||
// Other includes.
|
||||
#include "MM.h"
|
||||
#include <QtOpenGL>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
|
||||
#include <glib.h>
|
||||
#if __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "VideoImpl.h"
|
||||
|
||||
MM_BEGIN_NAMESPACE
|
||||
|
||||
class VideoV4l2SrcImpl : public VideoImpl
|
||||
{
|
||||
public:
|
||||
VideoV4l2SrcImpl();
|
||||
~VideoV4l2SrcImpl();
|
||||
bool loadMovie(const QString& path);
|
||||
bool isLive() {return true;}
|
||||
|
||||
private:
|
||||
GstElement *_v4l2src0;
|
||||
};
|
||||
|
||||
MM_END_NAMESPACE
|
||||
|
||||
#endif /* ifndef */
|
||||
+8
-2
@@ -46,7 +46,10 @@ HEADERS = \
|
||||
Triangle.h \
|
||||
UidAllocator.h \
|
||||
Util.h \
|
||||
VideoImpl.h
|
||||
VideoImpl.h \
|
||||
VideoUriDecodeBinImpl.h \
|
||||
VideoV4l2SrcImpl.h \
|
||||
VideoShmSrcImpl.h \
|
||||
|
||||
SOURCES = \
|
||||
Commands.cpp \
|
||||
@@ -83,7 +86,10 @@ SOURCES = \
|
||||
UidAllocator.cpp \
|
||||
Util.cpp \
|
||||
VideoImpl.cpp \
|
||||
main.cpp \
|
||||
VideoUriDecodeBinImpl.cpp \
|
||||
VideoV4l2SrcImpl.cpp \
|
||||
VideoShmSrcImpl.cpp \
|
||||
main.cpp
|
||||
|
||||
|
||||
include(contrib/qtpropertybrowser/src/qtpropertybrowser.pri)
|
||||
|
||||
Reference in New Issue
Block a user