mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Refactor Video -> Media
This commit is contained in:
+12
-12
@@ -27,7 +27,7 @@
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
// Create model.
|
||||
if (Video::hasVideoSupport())
|
||||
if (Media::hasVideoSupport())
|
||||
std::cout << "Video support: yes" << std::endl;
|
||||
else
|
||||
std::cout << "Video support: no" << std::endl;
|
||||
@@ -430,7 +430,7 @@ bool MainWindow::clearProject()
|
||||
return true;
|
||||
}
|
||||
|
||||
uid MainWindow::createImagePaint(uid paintId, QString uri, float x, float y)
|
||||
uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y)
|
||||
{
|
||||
// Cannot create image with already existing id.
|
||||
if (Paint::getUidAllocator().exists(paintId))
|
||||
@@ -438,7 +438,7 @@ uid MainWindow::createImagePaint(uid paintId, QString uri, float x, float y)
|
||||
|
||||
else
|
||||
{
|
||||
Video* img = new Video(uri, paintId);
|
||||
Media* img = new Media(uri, paintId);
|
||||
// Image* img = new Image(uri, paintId);
|
||||
|
||||
// Create new image with corresponding ID.
|
||||
@@ -1147,15 +1147,15 @@ bool MainWindow::importMediaFile(const QString &fileName)
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
// Add image to model.
|
||||
uint imageId = createImagePaint(NULL_UID, fileName, 0, 0);
|
||||
// Add media file to model.
|
||||
uint mediaId = createMediaPaint(NULL_UID, fileName, 0, 0);
|
||||
|
||||
// Initialize position (center).
|
||||
std::tr1::shared_ptr<Image> image = std::tr1::static_pointer_cast<Image>(mappingManager->getPaintById(imageId));
|
||||
Q_CHECK_PTR(image);
|
||||
std::tr1::shared_ptr<Media> media = std::tr1::static_pointer_cast<Media>(mappingManager->getPaintById(mediaId));
|
||||
Q_CHECK_PTR(media);
|
||||
|
||||
image->setPosition((sourceCanvas->width() - image->getWidth() ) / 2.0f,
|
||||
(sourceCanvas->height() - image->getHeight()) / 2.0f );
|
||||
media->setPosition((sourceCanvas->width() - media->getWidth() ) / 2.0f,
|
||||
(sourceCanvas->height() - media->getHeight()) / 2.0f );
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
@@ -1168,7 +1168,7 @@ bool MainWindow::addColorPaint(const QColor& color)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
// Add image to model.
|
||||
// Add color to model.
|
||||
uint colorId = createColorPaint(NULL_UID, color);
|
||||
|
||||
// Initialize position (center).
|
||||
@@ -1187,7 +1187,7 @@ void MainWindow::addPaintItem(uid paintId, const QIcon& icon, const QString& nam
|
||||
Paint::ptr paint = mappingManager->getPaintById(paintId);
|
||||
Q_CHECK_PTR(paint);
|
||||
|
||||
// Add image to paintList widget.
|
||||
// Add paint item to paintList widget.
|
||||
QListWidgetItem* item = new QListWidgetItem(name);
|
||||
setItemId(*item, paintId); // TODO: could possibly be replaced by a Paint pointer
|
||||
item->setIcon(icon);
|
||||
@@ -1217,7 +1217,7 @@ void MainWindow::addMappingItem(uid mappingId)
|
||||
// Add mapper.
|
||||
// XXX hardcoded for textures
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping;
|
||||
if (paintType == "image" || paintType == "video")
|
||||
if (paintType == "media")
|
||||
{
|
||||
textureMapping = std::tr1::static_pointer_cast<TextureMapping>(mapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ public slots:
|
||||
bool clearProject();
|
||||
|
||||
/// Create an image paint.
|
||||
uid createImagePaint(uid paintId, QString uri, float x, float y);
|
||||
uid createMediaPaint(uid paintId, QString uri, float x, float y);
|
||||
|
||||
/// Create a color paint.
|
||||
uid createColorPaint(uid paintId, QColor color);
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
/*
|
||||
* VideoImpl.cpp
|
||||
* MediaImpl.cpp
|
||||
*
|
||||
* (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
|
||||
@@ -17,12 +21,12 @@
|
||||
* 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 "VideoImpl.h"
|
||||
#include "MediaImpl.h"
|
||||
#include <cstring>
|
||||
|
||||
// -------- private implementation of VideoImpl -------
|
||||
|
||||
bool VideoImpl::hasVideoSupport()
|
||||
bool MediaImpl::hasVideoSupport()
|
||||
{
|
||||
static bool did_print_gst_version = false;
|
||||
if (! did_print_gst_version)
|
||||
@@ -37,22 +41,22 @@ bool VideoImpl::hasVideoSupport()
|
||||
return true;
|
||||
}
|
||||
|
||||
int VideoImpl::getWidth() const
|
||||
int MediaImpl::getWidth() const
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
|
||||
int VideoImpl::getHeight() const
|
||||
int MediaImpl::getHeight() const
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
const uchar* VideoImpl::getBits() const
|
||||
const uchar* MediaImpl::getBits() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
void VideoImpl::build()
|
||||
void MediaImpl::build()
|
||||
{
|
||||
qDebug() << "Building video impl" << endl;
|
||||
if (!loadMovie(_uri))
|
||||
@@ -61,16 +65,16 @@ void VideoImpl::build()
|
||||
}
|
||||
}
|
||||
|
||||
VideoImpl::~VideoImpl()
|
||||
MediaImpl::~MediaImpl()
|
||||
{
|
||||
freeResources();
|
||||
if (_data)
|
||||
free(_data);
|
||||
}
|
||||
|
||||
bool VideoImpl::_videoPull()
|
||||
bool MediaImpl::_videoPull()
|
||||
{
|
||||
qDebug() << "video pull" << endl;
|
||||
// qDebug() << "video pull" << endl;
|
||||
|
||||
GstBuffer *buffer;
|
||||
|
||||
@@ -123,7 +127,7 @@ bool VideoImpl::_videoPull()
|
||||
|
||||
}
|
||||
|
||||
bool VideoImpl::_eos() const
|
||||
bool MediaImpl::_eos() const
|
||||
{
|
||||
if (_movieReady)
|
||||
{
|
||||
@@ -155,12 +159,12 @@ bool VideoImpl::_eos() const
|
||||
//}
|
||||
|
||||
|
||||
void VideoImpl::gstNewBufferCallback(GstElement*, int *newBufferCounter)
|
||||
void MediaImpl::gstNewBufferCallback(GstElement*, int *newBufferCounter)
|
||||
{
|
||||
(*newBufferCounter)++;
|
||||
}
|
||||
|
||||
VideoImpl::VideoImpl(const QString uri) :
|
||||
MediaImpl::MediaImpl(const QString uri) :
|
||||
_currentMovie(""),
|
||||
_bus(NULL),
|
||||
_pipeline(NULL),
|
||||
@@ -205,7 +209,7 @@ _uri(uri)
|
||||
// _audioBufferAdapter = gst_adapter_new();
|
||||
}
|
||||
|
||||
void VideoImpl::unloadMovie()
|
||||
void MediaImpl::unloadMovie()
|
||||
{
|
||||
// Free allocated resources.
|
||||
freeResources();
|
||||
@@ -224,7 +228,7 @@ void VideoImpl::unloadMovie()
|
||||
// unSynch(); // XXX: I'm not sure why we are doing this...
|
||||
}
|
||||
|
||||
void VideoImpl::freeResources()
|
||||
void MediaImpl::freeResources()
|
||||
{
|
||||
// Free resources.
|
||||
if (_bus)
|
||||
@@ -256,7 +260,7 @@ void VideoImpl::freeResources()
|
||||
|
||||
}
|
||||
|
||||
void VideoImpl::resetMovie()
|
||||
void MediaImpl::resetMovie()
|
||||
{
|
||||
// TODO: Check if we can still seek when we reach EOS. It seems like it's then impossible and we
|
||||
// have to reload but it seems weird so we should check.
|
||||
@@ -276,7 +280,7 @@ void VideoImpl::resetMovie()
|
||||
}
|
||||
}
|
||||
|
||||
bool VideoImpl::loadMovie(QString filename)
|
||||
bool MediaImpl::loadMovie(QString filename)
|
||||
{
|
||||
qDebug() << "Opening movie: " << filename << ".";
|
||||
|
||||
@@ -359,7 +363,7 @@ bool VideoImpl::loadMovie(QString filename)
|
||||
g_object_set (_source, "uri", uri, NULL);
|
||||
|
||||
// Connect to the pad-added signal
|
||||
g_signal_connect (_source, "pad-added", G_CALLBACK (VideoImpl::gstPadAddedCallback), &_padHandlerData);
|
||||
g_signal_connect (_source, "pad-added", G_CALLBACK (MediaImpl::gstPadAddedCallback), &_padHandlerData);
|
||||
|
||||
// Configure audio appsink.
|
||||
// TODO: change from mono to stereo
|
||||
@@ -383,7 +387,7 @@ bool VideoImpl::loadMovie(QString filename)
|
||||
"max-buffers", 1, // only one buffer (the last) is maintained in the queue
|
||||
"drop", TRUE, // ... other buffers are dropped
|
||||
NULL);
|
||||
g_signal_connect (_videoSink, "new-buffer", G_CALLBACK (VideoImpl::gstNewBufferCallback), &_videoNewBufferCounter);
|
||||
g_signal_connect (_videoSink, "new-buffer", G_CALLBACK (MediaImpl::gstNewBufferCallback), &_videoNewBufferCounter);
|
||||
gst_caps_unref (videoCaps);
|
||||
|
||||
// Listen to the bus.
|
||||
@@ -400,7 +404,7 @@ bool VideoImpl::loadMovie(QString filename)
|
||||
}
|
||||
|
||||
|
||||
void VideoImpl::runVideo() {
|
||||
void MediaImpl::runVideo() {
|
||||
|
||||
// if (!_VIDEO_OUT->connected())
|
||||
// return;
|
||||
@@ -453,7 +457,7 @@ void VideoImpl::runVideo() {
|
||||
// _postRun();
|
||||
//}
|
||||
|
||||
bool VideoImpl::_preRun()
|
||||
bool MediaImpl::_preRun()
|
||||
{
|
||||
// Check for end-of-stream or terminate.
|
||||
if (_eos() || _terminate)
|
||||
@@ -482,7 +486,7 @@ bool VideoImpl::_preRun()
|
||||
return true;
|
||||
}
|
||||
|
||||
void VideoImpl::_postRun()
|
||||
void MediaImpl::_postRun()
|
||||
{
|
||||
// Parse message.
|
||||
if (_bus != NULL)
|
||||
@@ -568,7 +572,7 @@ void VideoImpl::_postRun()
|
||||
}
|
||||
|
||||
|
||||
bool VideoImpl::_setPlayState(bool play)
|
||||
bool MediaImpl::_setPlayState(bool play)
|
||||
{
|
||||
if (_pipeline == NULL)
|
||||
return false;
|
||||
@@ -588,18 +592,18 @@ bool VideoImpl::_setPlayState(bool play)
|
||||
}
|
||||
}
|
||||
|
||||
void VideoImpl::_setReady(bool ready)
|
||||
void MediaImpl::_setReady(bool ready)
|
||||
{
|
||||
_movieReady = ready;
|
||||
// _VIDEO_OUT->sleeping(!ready);
|
||||
// _AUDIO_OUT->sleeping(!ready);
|
||||
}
|
||||
|
||||
void VideoImpl::_setFinished(bool finished) {
|
||||
qDebug() << "Clip " << (finished ? "finished" : "not finished") << endl;
|
||||
void MediaImpl::_setFinished(bool finished) {
|
||||
// qDebug() << "Clip " << (finished ? "finished" : "not finished") << endl;
|
||||
}
|
||||
|
||||
void VideoImpl::gstPadAddedCallback(GstElement *src, GstPad *newPad, VideoImpl::GstPadHandlerData* data) {
|
||||
void MediaImpl::gstPadAddedCallback(GstElement *src, GstPad *newPad, MediaImpl::GstPadHandlerData* data) {
|
||||
g_print ("Received new pad '%s' from '%s':\n", GST_PAD_NAME (newPad), GST_ELEMENT_NAME (src));
|
||||
bool isAudio = false;
|
||||
GstPad *sinkPad = NULL;
|
||||
@@ -708,13 +712,13 @@ exit:
|
||||
// }
|
||||
//}
|
||||
|
||||
void VideoImpl::internalPrePlay()
|
||||
void MediaImpl::internalPrePlay()
|
||||
{
|
||||
// Start/resume playback.
|
||||
_setPlayState(true);
|
||||
}
|
||||
|
||||
void VideoImpl::internalPostPlay()
|
||||
void MediaImpl::internalPostPlay()
|
||||
{
|
||||
// Pause playback.
|
||||
_setPlayState(false);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* VideoImpl.h
|
||||
* MediaImpl.h
|
||||
*
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
|
||||
@@ -40,11 +40,11 @@
|
||||
* This is done this way so that GStreamer header don't need to be
|
||||
* included in the whole project. (just in this file)
|
||||
*/
|
||||
class VideoImpl
|
||||
class MediaImpl
|
||||
{
|
||||
public:
|
||||
VideoImpl(const QString uri);
|
||||
~VideoImpl();
|
||||
MediaImpl(const QString uri);
|
||||
~MediaImpl();
|
||||
|
||||
// void setUri(const QString uri);
|
||||
static bool hasVideoSupport();
|
||||
@@ -110,7 +110,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::GstPadHandlerData* data);
|
||||
static void gstPadAddedCallback(GstElement *src, GstPad *newPad, MediaImpl::GstPadHandlerData* data);
|
||||
|
||||
private:
|
||||
// PlugOut<VideoRGBAType> *_VIDEO_OUT;
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "Paint.h"
|
||||
#include "VideoImpl.h"
|
||||
#include "MediaImpl.h"
|
||||
#include <iostream>
|
||||
|
||||
UidAllocator Paint::allocator;
|
||||
@@ -45,47 +45,47 @@ Paint::~Paint()
|
||||
|
||||
/* Implementation of the Video class */
|
||||
|
||||
Video::Video(const QString uri_, uid id):
|
||||
Media::Media(const QString uri_, uid id):
|
||||
Texture(id),
|
||||
uri(uri_),
|
||||
impl_(NULL)
|
||||
{
|
||||
impl_ = new VideoImpl(uri_);
|
||||
impl_ = new MediaImpl(uri_);
|
||||
}
|
||||
|
||||
// vertigo
|
||||
|
||||
Video::~Video()
|
||||
Media::~Media()
|
||||
{
|
||||
delete impl_;
|
||||
}
|
||||
|
||||
void Video::build()
|
||||
void Media::build()
|
||||
{
|
||||
this->impl_->build();
|
||||
}
|
||||
|
||||
int Video::getWidth() const
|
||||
int Media::getWidth() const
|
||||
{
|
||||
return this->impl_->getWidth();
|
||||
}
|
||||
|
||||
int Video::getHeight() const
|
||||
int Media::getHeight() const
|
||||
{
|
||||
return this->impl_->getHeight();
|
||||
}
|
||||
|
||||
void Video::update() {
|
||||
void Media::update() {
|
||||
impl_->runVideo();
|
||||
}
|
||||
|
||||
const uchar* Video::getBits() const
|
||||
const uchar* Media::getBits() const
|
||||
{
|
||||
return this->impl_->getBits();
|
||||
}
|
||||
|
||||
bool Video::hasVideoSupport()
|
||||
bool Media::hasVideoSupport()
|
||||
{
|
||||
return VideoImpl::hasVideoSupport();
|
||||
return MediaImpl::hasVideoSupport();
|
||||
}
|
||||
|
||||
|
||||
@@ -164,18 +164,18 @@ public:
|
||||
virtual const uchar* getBits() const { return image.bits(); }
|
||||
};
|
||||
|
||||
class VideoImpl; // forware declaration
|
||||
class MediaImpl; // forward declaration
|
||||
|
||||
/**
|
||||
* Paint that is a Texture retrieved via a video file.
|
||||
*/
|
||||
class Video : public Texture
|
||||
class Media : public Texture
|
||||
{
|
||||
protected:
|
||||
QString uri;
|
||||
public:
|
||||
Video(const QString uri_, uid id=NULL_UID);
|
||||
virtual ~Video();
|
||||
Media(const QString uri_, uid id=NULL_UID);
|
||||
virtual ~Media();
|
||||
const QString getUri() const
|
||||
{
|
||||
return uri;
|
||||
@@ -184,7 +184,7 @@ public:
|
||||
virtual void update();
|
||||
virtual QString getType() const
|
||||
{
|
||||
return "video";
|
||||
return "media";
|
||||
}
|
||||
virtual int getWidth() const;
|
||||
virtual int getHeight() const;
|
||||
@@ -198,7 +198,7 @@ private:
|
||||
* Private implementation, so that GStreamer headers don't need
|
||||
* to be included from every file in the project.
|
||||
*/
|
||||
VideoImpl * impl_; // PIMPL opaque pointer
|
||||
MediaImpl * impl_; // PIMPL opaque pointer
|
||||
};
|
||||
|
||||
#endif /* PAINT_H_ */
|
||||
|
||||
+3
-3
@@ -88,15 +88,15 @@ void ProjectReader::parsePaint(const QDomElement& paint)
|
||||
QString paintAttrName = paint.attribute("name", "");
|
||||
QString paintAttrType = paint.attribute("type", "");
|
||||
|
||||
if (paintAttrType == "image")
|
||||
if (paintAttrType == "media")
|
||||
{
|
||||
QString uri = paint.firstChildElement("uri").text();
|
||||
QString x = paint.firstChildElement("x").text();
|
||||
QString y = paint.firstChildElement("y").text();
|
||||
|
||||
uid id = _window->createImagePaint(paintAttrId.toInt(), uri, x.toFloat(), y.toFloat());
|
||||
uid id = _window->createMediaPaint(paintAttrId.toInt(), uri, x.toFloat(), y.toFloat());
|
||||
if (id == NULL_UID)
|
||||
_xml.raiseError(QObject::tr("Cannot create image with uri %1.").arg(uri));
|
||||
_xml.raiseError(QObject::tr("Cannot create media with uri %1.").arg(uri));
|
||||
}
|
||||
else if (paintAttrType == "color")
|
||||
{
|
||||
|
||||
+5
-5
@@ -57,21 +57,21 @@ void ProjectWriter::writeItem(Paint *item)
|
||||
_xml.writeAttribute("name", item->getName());
|
||||
_xml.writeAttribute("type", item->getType());
|
||||
|
||||
if (item->getType() == "image")
|
||||
if (item->getType() == "media")
|
||||
{
|
||||
// FIXME: check paint type before casting to Image
|
||||
Image *image = (Image *) item;
|
||||
Media *media = (Media *) item;
|
||||
|
||||
_xml.writeTextElement("uri", image->getUri());
|
||||
_xml.writeTextElement("uri", media->getUri());
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << image->getX();
|
||||
os << media->getX();
|
||||
_xml.writeTextElement("x", os.str().c_str());
|
||||
}
|
||||
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << image->getY();
|
||||
os << media->getY();
|
||||
_xml.writeTextElement("y", os.str().c_str());
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -14,6 +14,7 @@ HEADERS = \
|
||||
Mapping.h \
|
||||
MappingManager.h \
|
||||
Maths.h \
|
||||
MediaImpl.h \
|
||||
Paint.h \
|
||||
OscInterface.h \
|
||||
OscReceiver.h \
|
||||
@@ -24,8 +25,7 @@ HEADERS = \
|
||||
Shape.h \
|
||||
SourceGLCanvas.h \
|
||||
UidAllocator.h \
|
||||
Util.h \
|
||||
VideoImpl.h
|
||||
Util.h
|
||||
|
||||
SOURCES = \
|
||||
DestinationGLCanvas.cpp \
|
||||
@@ -35,6 +35,7 @@ SOURCES = \
|
||||
MapperGLCanvas.cpp \
|
||||
Mapping.cpp \
|
||||
MappingManager.cpp \
|
||||
MediaImpl.cpp \
|
||||
OscInterface.cpp \
|
||||
OscReceiver.cpp \
|
||||
OutputGLWindow.cpp \
|
||||
@@ -45,7 +46,6 @@ SOURCES = \
|
||||
SourceGLCanvas.cpp \
|
||||
UidAllocator.cpp \
|
||||
Util.cpp \
|
||||
VideoImpl.cpp \
|
||||
main.cpp
|
||||
|
||||
QT += gui opengl xml
|
||||
|
||||
Reference in New Issue
Block a user