aboutsummaryrefslogtreecommitdiff
path: root/src/views
diff options
context:
space:
mode:
Diffstat (limited to 'src/views')
-rw-r--r--src/views/video/mgstvideo.cpp702
-rw-r--r--src/views/video/mgstvideo.h146
-rw-r--r--src/views/video/msink.c141
-rw-r--r--src/views/video/msink.h105
-rw-r--r--src/views/video/mvideowidgetview.cpp660
-rw-r--r--src/views/video/mvideowidgetview.h98
-rw-r--r--src/views/video/mvideowidgetview_p.h81
-rw-r--r--src/views/video/video.pri17
-rw-r--r--src/views/views.pro2
9 files changed, 0 insertions, 1952 deletions
diff --git a/src/views/video/mgstvideo.cpp b/src/views/video/mgstvideo.cpp
deleted file mode 100644
index 3004250d..00000000
--- a/src/views/video/mgstvideo.cpp
+++ /dev/null
@@ -1,702 +0,0 @@
-#include "mgstvideo.h"
-#include <gst/interfaces/xoverlay.h>
-#include <gst/video/gstvideosink.h>
-#include <gst/interfaces/propertyprobe.h>
-
-#include <QFileInfo>
-
-#include <mdebug.h>
-
-#include "msink.h"
-
-MGstVideo::MGstVideo()
- : gst_elem_pipeline(NULL),
- gst_elem_source(NULL),
- gst_elem_decoder(NULL),
- gst_elem_volume(NULL),
- gst_elem_audiosink(NULL),
- gst_elem_videosink(NULL),
- gst_elem_xvimagesink(NULL),
- gst_messagebus(NULL),
- gst_buffer(NULL),
- m_looping(true),
- m_seekable(false),
- m_ready(false),
- m_muted(false),
- m_volume(1.0),
- m_state(MVideo::NotReady),
- m_format(MVideo::RGB),
- m_renderTarget(MGstVideo::MSink),
- m_storedState(MVideo::NotReady),
- m_storedPosition(0),
- m_winId(0),
- m_colorKey(Qt::black),
- m_forceAspectRatio(true)
-{
- GError* error = NULL;
- if(!gst_init_check(NULL, NULL, &error)) {
- mWarning("MGstVideo") << "GStreamer initialization failed:" << (error ? error->message : "Unknown error");
- }
-}
-
-MGstVideo::~MGstVideo()
-{
- // It is normally not needed to call this function in a normal application
- // as the resources will automatically be freed when the program terminates.
- // gst_deinit();
-
- destroyPipeline();
-}
-
-bool MGstVideo::open(const QString& filename)
-{
- m_storedState = MVideo::NotReady;
- m_storedPosition = 0;
-
- //create absolute name for file including path
- QFileInfo info(filename);
- m_filename = info.absoluteFilePath();
-
- //check whether the file exists
- if (!info.exists() || !info.isReadable()) {
- mWarning("MGstVideo::openVideoFromFile()") << m_filename << "does not exist.";
- return false;
- }
-
- return constructPipeline();
-}
-
-bool MGstVideo::isReady() const
-{
- return m_state != MVideo::NotReady;
-}
-
-
-void MGstVideo::setVideoState(MVideo::State state)
-{
- MVideo::State new_state = m_state;
- if( gst_elem_pipeline ) {
- GstState current_gst_state;
- gst_element_get_state(gst_elem_pipeline, &current_gst_state, NULL, 0);
- if( (current_gst_state == GST_STATE_READY || current_gst_state == GST_STATE_PAUSED || current_gst_state == GST_STATE_PLAYING) && state != MVideo::NotReady ) {
- GstState new_gst_state = (state == MVideo::Paused || state == MVideo::Stopped) ? GST_STATE_PAUSED : GST_STATE_PLAYING;
- if( new_gst_state != current_gst_state ) {
- if( GST_STATE_CHANGE_FAILURE == gst_element_set_state(gst_elem_pipeline, new_gst_state) ) {
- mWarning("MGstVideo::setVideoState()") << "Failed to set state to" << state;
- new_state = MVideo::NotReady;
- }
- else {
- new_state = state;
- }
- }
- else {
- new_state = state;
- }
-
- //when moving to stopped state rewind the video to beginning
- if( new_state == MVideo::Stopped )
- seek(0);
- }
- else {
- mWarning("MGstVideo::setVideoState()") << "Video not ready yet, cannot set state to" << state;
- new_state = MVideo::NotReady;
- }
- }
- else if ( state != MVideo::NotReady ) {
- mWarning("MGstVideo::setVideoState()") << "Pipeline not created yet, cannot set state to" << state;
- new_state = MVideo::NotReady;
- } else
- new_state = MVideo::NotReady;
-
- //TODO: state changes should be emit in bus message method.
- if( m_state != new_state ) {
- m_state = new_state;
- emit stateChanged();
- }
-}
-
-MVideo::State MGstVideo::videoState() const
-{
- return m_state;
-}
-
-void MGstVideo::seek(quint64 time)
-{
- if( gst_elem_pipeline ) {
- if( !gst_element_seek_simple(gst_elem_pipeline, GST_FORMAT_TIME,
- (GstSeekFlags)(GST_SEEK_FLAG_FLUSH),// | GST_SEEK_FLAG_KEY_UNIT),
- time * GST_MSECOND) )
- mWarning("MGstVideo::seek()") << "FAILED.";
- /*gst_element_seek(gst_elem_pipeline, 1.0,
- GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
- GST_SEEK_TYPE_SET, time * GST_MSECOND,
- GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);*/
- }
-}
-
-quint64 MGstVideo::position() const
-{
- gint64 pos = 0;
- if( gst_elem_pipeline ) {
- GstFormat format = GST_FORMAT_TIME;
- if( gst_element_query_position(gst_elem_pipeline, &format, &pos) ) {
- pos /= 1000000;
- }
- }
- return (qint64)pos;
-}
-
-quint64 MGstVideo::length() const
-{
- gint64 length = 0;
- if( gst_elem_pipeline ) {
- GstFormat format = GST_FORMAT_TIME;
- if( gst_element_query_duration(gst_elem_pipeline, &format, &length) ) {
- length /= 1000000;
- }
- }
- return (qint64)length;
-}
-
-void MGstVideo::setMuted(bool muted)
-{
- if( gst_elem_volume ) {
- g_object_set(gst_elem_volume, "mute", muted, NULL);
- } else
- m_muted = muted;
-}
-
-bool MGstVideo::isMuted() const
-{
- gboolean muted = false;
- if( gst_elem_volume ) {
- g_object_get(gst_elem_volume, "mute", &muted, NULL);
- }
- return muted;
-}
-
-void MGstVideo::setVolume(qreal volume)
-{
- if( gst_elem_volume ) {
- g_object_set(gst_elem_volume, "volume", volume, NULL);
- } else
- m_volume = volume;
-}
-
-qreal MGstVideo::volume() const
-{
- gdouble volume = 0.0;
- if( gst_elem_volume ) {
- g_object_get(gst_elem_volume, "volume", &volume, NULL);
- }
- return volume;
-}
-
-
-QSize MGstVideo::resolution() const
-{
- if( m_renderTarget == MSink && gst_elem_videosink )
- return QSize(M_GST_VIDEO_SINK(gst_elem_videosink)->w, M_GST_VIDEO_SINK(gst_elem_videosink)->h);
- else if( gst_elem_xvimagesink )
- return QSize(GST_VIDEO_SINK_WIDTH(gst_elem_xvimagesink), GST_VIDEO_SINK_HEIGHT(gst_elem_xvimagesink));
- else
- return QSize(0,0);
-}
-
-uchar* MGstVideo::frameData() const
-{
- return gst_buffer ? GST_BUFFER_DATA(gst_buffer) : NULL;
-}
-
-MVideo::DataFormat MGstVideo::frameDataFormat() const
-{
- return m_format;
-}
-
-bool MGstVideo::lockFrameData()
-{
- return m_mutex.tryLock();
-}
-
-void MGstVideo::unlockFrameData()
-{
- m_mutex.unlock();
-}
-
-void MGstVideo::setRenderTarget(MGstVideo::RenderTarget targetSink)
-{
- //check if the change of the sink on fly is needed
- if( targetSink != m_renderTarget && isReady() ) {
- GstElement* videobin = gst_bin_get_by_name(GST_BIN_CAST(gst_elem_pipeline), "video bin");
- if( videobin ) {
- //stop playback of video bin to be able to make changes
- gst_element_set_locked_state(videobin, true);
- gst_element_set_state(videobin, GST_STATE_READY);
-
- //remove the currently active sink from video bin
- GstElement* active = activeSink();
- gst_object_ref(GST_OBJECT(active));
- gst_bin_remove(GST_BIN_CAST(videobin), active);
-
- //get colorspace element
- GstElement* colorspace = gst_bin_get_by_name(GST_BIN_CAST(videobin), "ffmpegcolorspace");
- if( colorspace ) {
-
- //change the sink to the wanted target, if there is no support
- //for xv rendering force texture rendering
- if( !gst_elem_xvimagesink )
- m_renderTarget = MSink;
- else
- m_renderTarget = targetSink;
-
-
- active = activeSink();
-
- if( active == gst_elem_xvimagesink ) {
- g_object_set(gst_elem_xvimagesink,
- "autopaint-colorkey", FALSE,
- "colorkey", m_colorKey.rgba() & 0x00FFFFFF,
- "force-aspect-ratio", m_forceAspectRatio,
- "draw-borders", TRUE,
- (void*) 0);
- gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(gst_elem_xvimagesink), m_winId);
- expose();
- }
-
- //link the new active sink with the colorspace element
- gst_bin_add(GST_BIN_CAST(videobin), active);
- gst_element_link_pads(colorspace, "src", active, "sink");
-
- //sync the state of videobin again with it's parent, sync the clock and
- //position manually as well because for some reason they do not
- //get automatically synced during runtime target switch
- gst_element_set_locked_state(videobin, false);
- gst_element_set_clock(videobin, gst_element_get_clock(gst_elem_pipeline));
- gst_element_sync_state_with_parent(videobin);
- gst_element_seek_simple(videobin, GST_FORMAT_TIME,
- (GstSeekFlags)(GST_SEEK_FLAG_FLUSH),
- position() * GST_MSECOND);
- }
- }
- } else
- m_renderTarget = targetSink;
-}
-
-MGstVideo::RenderTarget MGstVideo::renderTarget()
-{
- return m_renderTarget;
-}
-
-void MGstVideo::expose()
-{
- if( gst_elem_xvimagesink && m_renderTarget == XvSink ) {
- gst_x_overlay_expose(GST_X_OVERLAY(gst_elem_xvimagesink));
- }
-}
-
-void MGstVideo::setWinId(unsigned long id)
-{
- m_winId = id;
- if( gst_elem_xvimagesink )
- gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(gst_elem_xvimagesink), m_winId);
-}
-
-unsigned long MGstVideo::winId()
-{
- return m_winId;
-}
-
-void MGstVideo::setColorKey(const QColor& key)
-{
- m_colorKey = key;
-
- if( gst_elem_xvimagesink ) {
- g_object_set(gst_elem_xvimagesink,
- "autopaint-colorkey", FALSE,
- "colorkey", m_colorKey.rgba() & 0x00FFFFFF,
- (void*) 0);
- }
-}
-
-QColor MGstVideo::colorKey()
-{
- return m_colorKey;
-}
-
-void MGstVideo::forceAspectRatio(bool forceAspectRatio)
-{
- m_forceAspectRatio = forceAspectRatio;
- if( gst_elem_xvimagesink ) {
- g_object_set(gst_elem_xvimagesink,
- "force-aspect-ratio", m_forceAspectRatio,
- (void*) 0);
- }
-}
-
-
-/*
- * Gstreamer message callback for catching general
- * messages and errors in stream.
- */
-gboolean MGstVideo::bus_cb(GstBus *bus, GstMessage *message, void *data)
-{
- Q_UNUSED(bus);
-
- MGstVideo* gstVideo = (MGstVideo*) data;
-
- // video stream has reached end
- if( GST_MESSAGE_TYPE(message) == GST_MESSAGE_EOS ) {
- if( gstVideo->m_looping ) {
- if( gstVideo->m_seekable ) {
- gstVideo->seek(0);
- } else {
- //TODO: Reset the video by some other means than seeking to 0
- }
- }
- else
- {
- gstVideo->setVideoState(MVideo::Stopped);
- }
- }
- // some error has happened
- else if( GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR ) {
- GError *error = NULL;
- gst_message_parse_error(message, &error, NULL);
- mWarning("MGstVideo::bus_cb()") << "ERROR: " << error->message;
- g_error_free(error);
-
- // stop pipeline, we are in trouble
- return false;
- }
- else if ( GST_MESSAGE_TYPE(message)== GST_MESSAGE_STATE_CHANGED ) {
- if( GST_IS_PIPELINE(message->src) ) {
-
- GstState oldState, newState, pendingState;
- gst_message_parse_state_changed(message, &oldState, &newState, &pendingState);
- if( oldState == GST_STATE_READY && newState == GST_STATE_PAUSED ) {
- video_ready_cb(data);
- }
- }
- }
- return true;
-}
-
-/*
- * Called from msink when the natural size of video is known.
- */
-void MGstVideo::video_ready_cb(void* user_data)
-{
- if( user_data ) {
- MGstVideo* gstVideo = (MGstVideo*) user_data;
-
- //check if the video is seekable
- gstVideo->checkSeekable();
-
- if( gstVideo->m_storedState != MVideo::NotReady ) {
- //restore the stored state information
- gstVideo->seek(gstVideo->m_storedPosition);
- gstVideo->setVideoState(gstVideo->m_storedState);
- gstVideo->m_storedState = MVideo::NotReady;
- gstVideo->m_storedPosition = 0;
- }
- else {
- //automatically stop after buffering the first frame
- gstVideo->setVideoState(MVideo::Stopped);
- }
-
- emit gstVideo->videoReady();
- }
-}
-
-/*
- * Called from decodebin2 when unknown video format is encountered
- */
-void MGstVideo::unknownpad_cb(GstElement*/*bin*/,
- GstPad */*pad*/,
- GstCaps *caps,
- MGstVideo */*w*/)
-{
- GstStructure* type;
- type = gst_caps_get_structure(caps, 0);
- QString typeString = gst_structure_get_name(type);
- mWarning("MGstVideo::unknownpad_cb()") << typeString;
-}
-
-/*
- * Called from decodebin2 when known video format is encountered and it
- can be decoded to raw data automatically
- */
-void MGstVideo::newpad_cb(GstElement *decodebin,
- GstPad *pad,
- gboolean last,
- MGstVideo *w)
-{
- GstPad *sinkpad;
- GstCaps *caps;
- GstElement *sink;
- GstStructure *type;
- GstElement *bin;
-
- Q_UNUSED(decodebin);
- Q_UNUSED(last);
-
- caps = gst_pad_get_caps(pad);
- type = gst_caps_get_structure(caps, 0);
-
- QString typeString = gst_structure_get_name(type);
-
- //FIXME
- //Find compatible pads more accurately, add more error checking.
- if (g_strrstr(gst_structure_get_name(type), "video")) {
- bool yuv = false;
- if (g_strrstr(gst_structure_get_name(type), "yuv"))
- yuv = true;
-
- sink = w->makeSinks(yuv);
- w->m_format = yuv ? YUV : RGB;
-
- //FIXME:
- //Add ffmpegcolorspace plugin only when necessary
- if ( /*!yuv*//*!pad2*/true) {
- bin = gst_bin_new("video bin");
- GstElement *colorspace = gst_element_factory_make("ffmpegcolorspace", "ffmpegcolorspace");
-
- gst_bin_add(GST_BIN(bin), colorspace);
- gst_bin_add(GST_BIN(bin), sink);
- gst_element_link_pads(colorspace, "src", sink, "sink");
-
- GstPad *pad = gst_element_get_pad(colorspace, "sink");
-
- gst_element_add_pad(bin, gst_ghost_pad_new("sink", pad));
- gst_object_unref(pad);
-
- sink = bin;
- }
- } else if (g_strrstr(gst_structure_get_name(type), "audio")) {
- GstElement *vol;
-
- bin = gst_bin_new("audio bin");
- vol = w->makeVolume();
-
- sink = gst_element_factory_make("autoaudiosink", "sink");
-
- gst_bin_add(GST_BIN(bin), vol);
- gst_bin_add(GST_BIN(bin), sink);
- gst_element_link_pads(vol, "src", sink, "sink");
-
- GstPad *sinkpad = gst_element_get_compatible_pad(vol, pad, NULL);//gst_element_get_pad(vol, "sink");
-
- gst_element_add_pad(bin, gst_ghost_pad_new("sink", sinkpad));
- gst_object_unref(pad);
-
- sink = bin;
-
- } else {
- mWarning("MGstVideo::newpad_cb()") << "error creating sink for " << gst_structure_get_name(type);
- sink = NULL;
- }
-
- if (w->gst_elem_pipeline && sink) {
- gst_caps_unref(caps);
- gst_bin_add(GST_BIN_CAST(w->gst_elem_pipeline), sink);
- gst_element_set_state(sink, GST_STATE_PAUSED);
-
- sinkpad = gst_element_get_compatible_pad(sink, pad, NULL);//gst_element_get_pad(sink, "sink");
- if (sinkpad) {
- gst_pad_link(pad, sinkpad);
- gst_object_unref(sinkpad);
- }
- }
-}
-
-
-/*
- * Called from msink to render the current frame in video stream.
- */
-void MGstVideo::render_frame_cb(void* pointer, void* user_data)
-{
- if( user_data ) {
- //try to lock the mutex, if the we cannot lock it
- //a new frame is currently being rendered so no need
- //to create new one
- MGstVideo* gstVideo = (MGstVideo*) user_data;
- if( !gstVideo->lockFrameData() ) {
- mWarning("MGstVideo::render_frame_cb()") << "MUTEX LOCK CONFLICT!";
- gst_buffer_unref(GST_BUFFER(pointer));
- return;
- }
-
- //release old buffer and set new one
- if( gstVideo->gst_buffer ) {
- gst_buffer_unref(gstVideo->gst_buffer);
- gstVideo->gst_buffer = NULL;
- }
- gstVideo->gst_buffer = GST_BUFFER(pointer);
-
- gstVideo->unlockFrameData();
-
- emit gstVideo->frameReady();
- }
-}
-
-GstElement* MGstVideo::makeSinks(bool yuv)
-{
- if( gst_elem_videosink || gst_elem_xvimagesink ) {
- mWarning("MGstVideo::makeSink()") << "Sink already initialized. Call destroyPipeline() before initializing new sink.";
- return NULL;
- }
-
- //try to create xvimagesink, if it fails fallback to msink rendering
- gst_elem_xvimagesink = gst_element_factory_make("xvimagesink", "xvsink");
- if( gst_elem_xvimagesink && GST_IS_ELEMENT(gst_elem_xvimagesink) && m_renderTarget == XvSink ) {
- g_object_set(gst_elem_xvimagesink,
- "autopaint-colorkey", FALSE,
- "colorkey", m_colorKey.rgba() & 0x00FFFFFF,
- "force-aspect-ratio", m_forceAspectRatio,
- "draw-borders", TRUE,
- (void*) 0);
- gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(gst_elem_xvimagesink), m_winId);
- }else {
- mWarning("MGstVideo::makeSink()") << "xvimagesink doest not exist, falling back to texture rendering with msink.";
- }
-
- //setup textured video rendering using msink
- gst_elem_videosink = yuv ? m_gst_video_sink_yuv_new() : m_gst_video_sink_new();
- MGstVideoSink *msink = M_GST_VIDEO_SINK(gst_elem_videosink);
- msink->user_data = this;
- msink->frame_cb = render_frame_cb;
- msink->ready_cb = video_ready_cb;
-
- return activeSink();
-}
-
-GstElement* MGstVideo::activeSink()
-{
- if( m_renderTarget == XvSink && gst_elem_xvimagesink ) {
- m_renderTarget = XvSink;
- return gst_elem_xvimagesink;
- }
- else {
- m_renderTarget = MSink;
- return gst_elem_videosink;
- }
-}
-
-GstElement* MGstVideo::makeVolume()
-{
- gst_elem_volume = gst_element_factory_make("volume", "volume");
- setVolume(m_volume);
- setMuted(m_muted);
- return gst_elem_volume;
-}
-
-bool MGstVideo::constructPipeline()
-{
- destroyPipeline();
-
- bool ok = true;
-
- //create file source element
- gst_elem_source = gst_element_factory_make("filesrc", "file-source");
- if( gst_elem_source && GST_IS_ELEMENT(gst_elem_source) ) {
- g_object_set(G_OBJECT(gst_elem_source), "location", m_filename.toStdString().c_str(), NULL);
- }
- else {
- mWarning("MGstVideo::constructPipeline()") << "filesrc gstreamer plugin not found.";
- ok = false;
- }
-
- //create decoder element
- gst_elem_decoder = gst_element_factory_make("decodebin2", "decoder");
- if( gst_elem_decoder && GST_IS_ELEMENT(gst_elem_decoder) ) {
- g_signal_connect(gst_elem_decoder, "new-decoded-pad", G_CALLBACK(newpad_cb), this);
- g_signal_connect(gst_elem_decoder, "unknown-type", G_CALLBACK(unknownpad_cb), this);
- }
- else {
- mWarning("MGstVideo::constructPipeline()") << "decodebin2 gstreamer plugin not found.";
- ok = false;
- }
-
- //check if everything is still ok, if not do some cleanup and stop pipeline creation
- if( !ok ) {
- mWarning("MGstVideo::constructPipeline()") << "Core gstreamer plugin(s) are missing, cannot construct pipeline.";
- gst_object_unref(gst_elem_source);
- gst_object_unref(gst_elem_decoder);
- return false;
- }
-
- //create pipeline from source and decoder elements
- gst_elem_pipeline = gst_pipeline_new("m-gst-video");
- gst_bin_add_many(GST_BIN(gst_elem_pipeline), gst_elem_source, gst_elem_decoder, NULL);
- if( !gst_element_link_many(gst_elem_source, gst_elem_decoder, NULL) ) {
- mWarning("MGstVideo::constructPipeline()") << "Failed to link elements.";
- destroyPipeline();
- return false;
- }
-
- //setup callback for pipeline bus messages
- gst_messagebus = gst_pipeline_get_bus(GST_PIPELINE(gst_elem_pipeline));
- gst_bus_add_watch(gst_messagebus, bus_cb, this);
- gst_object_unref(gst_messagebus);
-
- //start buiffering, this is done to get the first frame of the video and
- //thus be able to parse video format information
- if( GST_STATE_CHANGE_FAILURE == gst_element_set_state(gst_elem_pipeline, GST_STATE_PAUSED) ) {
- mWarning("MGstVideo::constructPipeline()") << "Failed to start buffering.";
- destroyPipeline();
- return false;
- }
-
- return true;
-}
-
-void MGstVideo::destroyPipeline()
-{
- m_mutex.lock();
- //if( gst_elem_videosink ) {
- // MGstVideoSink* msink = M_GST_VIDEO_SINK(gst_elem_videosink);
- // msink->user_data = NULL;
- //}
-
- if( gst_elem_pipeline ) {
- gst_element_set_state(gst_elem_pipeline, GST_STATE_NULL);
- gst_object_unref(GST_OBJECT(gst_elem_pipeline));
-
- if( activeSink() == gst_elem_xvimagesink ) {
- if( gst_elem_videosink )
- gst_object_unref(GST_OBJECT(gst_elem_videosink));
- }
- else if( gst_elem_xvimagesink )
- gst_object_unref(GST_OBJECT(gst_elem_xvimagesink));
- }
-
- //TODO should some of these be destroyed as well?
- gst_elem_pipeline = NULL;
- gst_elem_decoder = NULL;
- gst_elem_source = NULL;
- gst_elem_volume = NULL;
- gst_elem_videosink = NULL;
- gst_elem_audiosink = NULL;
- gst_elem_xvimagesink = NULL;
-
- setVideoState(MVideo::NotReady);
-
- m_mutex.unlock();
-}
-
-void MGstVideo::checkSeekable()
-{
- if( gst_elem_pipeline ) {
- GstQuery *query;
- gboolean result;
- query = gst_query_new_seeking(GST_FORMAT_TIME);
- result = gst_element_query(gst_elem_pipeline, query);
- if( result ) {
- gboolean seekable;
- gst_query_parse_seeking(query, NULL, &seekable, NULL, NULL);
- m_seekable = seekable;
- }
- gst_query_unref(query);
- }
-}
-
diff --git a/src/views/video/mgstvideo.h b/src/views/video/mgstvideo.h
deleted file mode 100644
index 0b4c6207..00000000
--- a/src/views/video/mgstvideo.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * This file is part of libmeegotouch *
- *
- * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
- * All rights reserved.
- *
- * Contact: Tomas Junnonen <tomas.junnonen@nokia.com>
- *
- * This software, including documentation, is protected by copyright
- * controlled by Nokia Corporation. All rights are reserved. Copying,
- * including reproducing, storing, adapting or translating, any or all of
- * this material requires the prior written consent of Nokia Corporation.
- * This material also contains confidential information which may not be
- * disclosed to others without the prior written consent of Nokia.
- */
-#ifndef MGSTVIDEO_P_H
-#define MGSTVIDEO_P_H
-
-#include <QObject>
-#include <QMutex>
-#include <QColor>
-
-#include <gst/gst.h>
-#include <gst/gstvalue.h>
-#include <gst/video/video.h>
-
-#include "mvideo.h"
-
-//! \internal
-
-class MGstVideo : public MVideo
-{
- Q_OBJECT
-
-public:
-
- enum RenderTarget
- {
- MSink,
- XvSink
- };
-
- MGstVideo();
- virtual ~MGstVideo();
-
- bool open(const QString& filename);
-
- bool isReady() const;
-
- void setVideoState(MVideo::State state);
- MVideo::State videoState() const;
-
- void seek(quint64 time);
- quint64 position() const;
- quint64 length() const;
-
- void setMuted(bool muted);
- bool isMuted() const;
- void setVolume(qreal volume);
- qreal volume() const;
-
- void setLooping(bool enabled) {m_looping = enabled;}
- bool isLooping() const {return m_looping;}
-
- QSize resolution() const;
-
- uchar* frameData() const;
- MVideo::DataFormat frameDataFormat() const;
-
- bool lockFrameData();
- void unlockFrameData();
-
- //gst and xv specific methods
- void setRenderTarget(MGstVideo::RenderTarget targetSink);
- MGstVideo::RenderTarget renderTarget();
-
- void expose();
- void setWinId(unsigned long id);
- unsigned long winId();
-
- void setColorKey(const QColor& key);
- QColor colorKey();
-
- void forceAspectRatio(bool forceAspectRatio);
-
-private:
-
- static gboolean bus_cb(GstBus *bus, GstMessage *message, void *data);
- static void video_ready_cb(void *user_data);
- static void unknownpad_cb( GstElement* bin,
- GstPad* pad,
- GstCaps* caps,
- MGstVideo* w);
- static void newpad_cb( GstElement* decodebin,
- GstPad* pad,
- gboolean last,
- MGstVideo* w);
- static void render_frame_cb(void* pointer, void* user_data);
-
- GstElement* makeSinks(bool yuv);
- GstElement* activeSink();
-
- GstElement* makeVolume();
-
- bool constructPipeline();
- void destroyPipeline();
-
- void checkSeekable();
-
- GstElement* gst_elem_pipeline;
- GstElement* gst_elem_source;
- GstElement* gst_elem_decoder;
- GstElement* gst_elem_volume;
-
- GstElement* gst_elem_audiosink;
-
- GstElement* gst_elem_videosink;
- GstElement* gst_elem_xvimagesink;
-
- GstBus* gst_messagebus;
- GstBuffer* gst_buffer;
-
- QString m_filename;
- bool m_looping;
- bool m_seekable;
- bool m_ready;
- bool m_muted;
- qreal m_volume;
- MVideo::State m_state;
- MVideo::DataFormat m_format;
-
- QMutex m_mutex;
-
- MGstVideo::RenderTarget m_renderTarget;
- MVideo::State m_storedState;
- quint64 m_storedPosition;
-
- unsigned long m_winId;
- QColor m_colorKey;
-
- bool m_forceAspectRatio;
-};
-
-//! \internal_end
-
-#endif
diff --git a/src/views/video/msink.c b/src/views/video/msink.c
deleted file mode 100644
index 8e85c6ab..00000000
--- a/src/views/video/msink.c
+++ /dev/null
@@ -1,141 +0,0 @@
-
-#include <gst/gst.h>
-#include <gst/video/video.h>
-
-#include "msink.h"
-
-static GstStaticPadTemplate sinktemplate
-= GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ IYUV, I420, YV12 }") ";" \
- GST_VIDEO_CAPS_RGBx ";" \
- GST_VIDEO_CAPS_BGRx ";" \
- GST_VIDEO_CAPS_RGB ";" \
- GST_VIDEO_CAPS_BGR));
-static GstStaticPadTemplate sinktemplate_rgb
-= GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB));
- /*GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx ";" \
- GST_VIDEO_CAPS_BGRx ";" \
- GST_VIDEO_CAPS_RGB ";" \
- GST_VIDEO_CAPS_BGR));*/
-static GstStaticPadTemplate sinktemplate_yuv
-= GST_STATIC_PAD_TEMPLATE ("sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ IYUV, I420, YV12 }")));
-
-G_DEFINE_TYPE (MGstVideoSink, m_gst_video_sink, GST_TYPE_BASE_SINK)
-
-static void
-m_gst_video_sink_init (MGstVideoSink *sink)
-{
- sink->w = sink->h = 0;
- sink->frameskip = 1;
-}
-
-static GstFlowReturn
-m_gst_video_sink_render (GstBaseSink *bsink, GstBuffer *buffer)
-{
- MGstVideoSink *sink;
- static int n = 1;
-
- sink = M_GST_VIDEO_SINK (bsink);
-
- if (buffer == NULL || G_UNLIKELY (!GST_IS_BUFFER (buffer))) {
- return FALSE;
- }
-
- // take ownership
- gst_buffer_ref (buffer);
-
- if (--n==0) {
- sink->frame_cb (buffer, sink->user_data);
- n = sink->frameskip;
- }
- else {
- gst_buffer_unref (buffer);
- }
-
- return GST_FLOW_OK;
-}
-
-static gboolean
-m_gst_video_sink_set_caps (GstBaseSink *bsink,
- GstCaps *caps)
-{
-
- MGstVideoSink *sink;
- GstStructure *structure;
-
- sink = M_GST_VIDEO_SINK (bsink);
-
- if (sink->yuv_mode) {
- gst_caps_intersect
- (gst_static_pad_template_get_caps (&sinktemplate_yuv),
- caps);
- } else {
- gst_caps_intersect
- (gst_static_pad_template_get_caps (&sinktemplate_rgb),
- caps);
- }
-
- structure = gst_caps_get_structure (caps, 0);
-
- gst_structure_get_int (structure, "width", &sink->w);
- gst_structure_get_int (structure, "height", &sink->h);
-
- //sink->ready_cb(sink->user_data);
- return TRUE;
-}
-
-static GstCaps*
-m_gst_video_sink_get_caps (GstBaseSink *bsink)
-{
- MGstVideoSink *sink;
-
- sink = M_GST_VIDEO_SINK (bsink);
-
- if (sink->yuv_mode)
- return gst_static_pad_template_get_caps (&sinktemplate_yuv);
- else
- return gst_static_pad_template_get_caps (&sinktemplate_rgb);
-}
-
-
-static void
-m_gst_video_sink_class_init (MGstVideoSinkClass *klass)
-{
- GstBaseSinkClass *gstbase_sink_class = GST_BASE_SINK_CLASS (klass);
- GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
-
- gstbase_sink_class->render = m_gst_video_sink_render;
- gstbase_sink_class->preroll = m_gst_video_sink_render;
- gstbase_sink_class->set_caps = m_gst_video_sink_set_caps;
- gstbase_sink_class->get_caps = m_gst_video_sink_get_caps;
-
- gst_element_class_add_pad_template
- (element_class,
- gst_static_pad_template_get (&sinktemplate));
-}
-
-GstElement *
-m_gst_video_sink_new ()
-{
- GstElement *sink = g_object_new (M_GST_TYPE_VIDEO_SINK, NULL);
- M_GST_VIDEO_SINK (sink)->yuv_mode = 0;
-
- return sink;
-}
-
-GstElement *
-m_gst_video_sink_yuv_new ()
-{
- GstElement *sink = g_object_new (M_GST_TYPE_VIDEO_SINK, NULL);
- M_GST_VIDEO_SINK (sink)->yuv_mode = 1;
-
- return sink;
-}
diff --git a/src/views/video/msink.h b/src/views/video/msink.h
deleted file mode 100644
index b23a31be..00000000
--- a/src/views/video/msink.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (directui@nokia.com)
-**
-** This file is part of libmeegotouch.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at directui@nokia.com.
-**
-** This library is free software; you can redistribute it and/or
-** modify it under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation
-** and appearing in the file LICENSE.LGPL included in the packaging
-** of this file.
-**
-****************************************************************************/
-
-#ifndef _HAVE_M_GST_VIDEO_SINK_H
-#define _HAVE_M_GST_VIDEO_SINK_H
-
-#include <glib-object.h>
-#include <gst/base/gstbasesink.h>
-#include <gst/gstplugin.h>
-
-//! \cond
-G_BEGIN_DECLS
-
-#define M_GST_TYPE_VIDEO_SINK m_gst_video_sink_get_type()
-
-#define M_GST_VIDEO_SINK(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
- M_GST_TYPE_VIDEO_SINK, MGstVideoSink))
-
-#define M_GST_VIDEO_SINK_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), \
- M_GST_TYPE_VIDEO_SINK, MGstVideoSinkClass))
-
-#define M_GST_IS_VIDEO_SINK(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
- M_GST_TYPE_VIDEO_SINK))
-
-#define M_GST_IS_VIDEO_SINK_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), \
- M_GST_TYPE_VIDEO_SINK))
-
-#define M_GST_VIDEO_SINK_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), \
- M_GST_TYPE_VIDEO_SINK, MGstVideoSinkClass))
-
-typedef struct _MGstVideoSink MGstVideoSink;
-typedef struct _MGstVideoSinkClass MGstVideoSinkClass;
-
-/*!
- * \class MGstVideoSink
- * \brief MGstVideoSink is a simple video sink with a render callback function.
- *
- * MGstVideoSink provides callbacks for custom video rendering offering gstbuffer
- * to the frame_cb function.
- */
-struct _MGstVideoSink {
- GstBaseSink parent;
-
- /*! render frame callback function
- * \param void pointer to GstBuffer
- * \param void pointer to user specified data
- */
- void (*frame_cb)(void *, void *);
-
- /*! render frame callback function
- * \param void pointer to user specified data
- */
- void (*ready_cb)(void *);
-
- void *user_data;
-
- int frameskip;
- guint yuv_mode;
-
- int w;
- int h;
-};
-
-struct _MGstVideoSinkClass {
- GstBaseSinkClass parent_class;
-};
-
-GType m_gst_video_sink_get_type(void) G_GNUC_CONST;
-
-/*!
- * \brief Constructor - creates RGB|BGR sink
- */
-GstElement *m_gst_video_sink_new();
-
-/*!
- * \brief Constructor - creates YUV sink
- */
-GstElement *m_gst_video_sink_yuv_new();
-
-
-G_END_DECLS
-//! \endcond
-
-#endif
diff --git a/src/views/video/mvideowidgetview.cpp b/src/views/video/mvideowidgetview.cpp
deleted file mode 100644
index c683b930..00000000
--- a/src/views/video/mvideowidgetview.cpp
+++ /dev/null
@@ -1,660 +0,0 @@
-/* * This file is part of libmeegotouch *
- *
- * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
- * All rights reserved.
- *
- * Contact: Tomas Junnonen <tomas.junnonen@nokia.com>
- *
- * This software, including documentation, is protected by copyright
- * controlled by Nokia Corporation. All rights are reserved. Copying,
- * including reproducing, storing, adapting or translating, any or all of
- * this material requires the prior written consent of Nokia Corporation.
- * This material also contains confidential information which may not be
- * disclosed to others without the prior written consent of Nokia.
- */
-
-#include "mvideowidgetview.h"
-#include "mvideowidgetview_p.h"
-#include "mvideowidget.h"
-
-#include "mapplication.h"
-#include "mapplicationwindow.h"
-
-#include <gst/gst.h>
-#include <gst/gstvalue.h>
-#include <gst/video/video.h>
-
-#include "mgles2renderer.h"
-#include "mgstvideo.h"
-
-#include "msink.h"
-#include "mdebug.h"
-
-#include <mscene.h>
-
-MVideoWidgetViewPrivate::MVideoWidgetViewPrivate()
- : m_useSingleYuvTexture(false),
- image(NULL),
- bits(NULL),
- scaleOffsets(NULL),
- m_needFillBg(false),
- m_fullscreen(false),
- m_gstVideo(new MGstVideo()),
- m_updateEnabled(false)
-{
- m_textures[0] = 0;
- m_textures[1] = 0;
- m_textures[2] = 0;
-
- qRegisterMetaType< QList<const char*> >("QList<const char*>");
-#ifdef M_USE_OPENGL
- glGenTextures(3, &m_textures[0]);
-#endif
-}
-
-MVideoWidgetViewPrivate::~MVideoWidgetViewPrivate()
-{
- delete image;
- delete[] bits;
- delete[] scaleOffsets;
-
- delete m_gstVideo;
-
-#ifdef M_USE_OPENGL
- glDeleteTextures(3, &m_textures[0]);
-#endif
-}
-
-const MVideoWidgetModel* MVideoWidgetViewPrivate::model() const
-{
- Q_Q(const MVideoWidgetView);
- return q->model();
-}
-
-MVideoWidgetModel* MVideoWidgetViewPrivate::model()
-{
- Q_Q(MVideoWidgetView);
- return q->model();
-}
-
-void MVideoWidgetViewPrivate::update()
-{
- Q_Q(MVideoWidgetView);
- if( m_updateEnabled )
- q->update();
-}
-
-void MVideoWidgetViewPrivate::updateGeometry()
-{
- Q_Q(MVideoWidgetView);
- q->updateGeometry();
-}
-
-void MVideoWidgetViewPrivate::videoReady()
-{
- model()->setLength(m_gstVideo->length());
-
- updateVideoGeometry();
- updateGeometry();
- update();
-}
-
-void MVideoWidgetViewPrivate::frameReady()
-{
- model()->setPositionNoEmit(m_gstVideo->position());
-
- if( m_updateEnabled ) {
- if( MApplication::softwareRendering()) {
- blitSwFrame();
- } else {
- #ifdef M_USE_OPENGL
- blitGLFrame();
- #else
- blitSwFrame();
- #endif
- }
- update();
- }
-}
-
-void MVideoWidgetViewPrivate::stateChanged()
-{
- model()->setState(m_gstVideo->videoState());
-}
-
-
-void MVideoWidgetViewPrivate::updateVideoGeometry()
-{
- Q_Q(MVideoWidgetView);
-
- QSize videoSize = m_gstVideo->resolution();
- QSize widgetSize = q->size().toSize();
-
- if( model()->scaleMode() == MVideoWidgetModel::ScaleToFit ) {
- if( model()->aspectRatioMode() == MVideoWidgetModel::AspectRatioOriginal ) {
- //scale but preserve the original aspect ratio
- videoSize.scale(widgetSize, Qt::KeepAspectRatio);
- qreal dx = (widgetSize.width() - videoSize.width()) / 2.0;
- qreal dy = (widgetSize.height() - videoSize.height()) / 2.0;
- m_scaledVideoRect.setRect(dx, dy, videoSize.width(), videoSize.height());
- m_needFillBg = widgetSize != videoSize;
- }
- else {
- //scale the video to match exactly the widget's size
- m_scaledVideoRect.setRect(0, 0, widgetSize.width(), widgetSize.height());
- m_needFillBg = false;
- }
- }
- else {
- //do not scale just center the video inside the widget
- qreal dx = (widgetSize.width() - videoSize.width()) / 2.0;
- qreal dy = (widgetSize.height() - videoSize.height()) / 2.0;
- m_scaledVideoRect.setRect(dx, dy, videoSize.width(), videoSize.height());
- m_needFillBg = widgetSize != videoSize;
- }
-}
-
-void MVideoWidgetViewPrivate::blitGLFrame()
-{
- if( !m_gstVideo->frameData() )
- return;
-
- //try to lock the frame data if the we cannot lock it
- //a new frame is currently being received and there will update
- //call when the new frame has been completely received so we
- //can safely skip the new frame texture creation for now
- if( !m_gstVideo->lockFrameData() ) {
- mWarning("MVideoWidgetViewPrivate::blitGLFrame()") << "MUTEX LOCK CONFLICT!";
- return;
- }
-
- //create texture from the data
- if( m_gstVideo->frameDataFormat() == MGstVideo::RGB ) {
- blitRgbTexture(m_gstVideo->frameData(), m_gstVideo->resolution().width(), m_gstVideo->resolution().height());
- } else {
- m_useSingleYuvTexture ? blitSingleYuvTexture(m_gstVideo->frameData(), m_gstVideo->resolution().width(), m_gstVideo->resolution().height()) :
- blitMultiYuvTexture(m_gstVideo->frameData(), m_gstVideo->resolution().width(), m_gstVideo->resolution().height());
- }
-
- m_gstVideo->unlockFrameData();
-}
-
-void MVideoWidgetViewPrivate::blitRgbTexture(const uchar* data, int width, int height)
-{
-#ifdef M_USE_OPENGL
- GLuint target = GL_TEXTURE_2D;
- GLuint format = GL_RGB;
- glBindTexture(target, m_textures[0]);
- glTexImage2D(target, 0, format, width, height, 0, format,
- GL_UNSIGNED_BYTE, data);
-#else
- Q_UNUSED(data)
- Q_UNUSED(width)
- Q_UNUSED(height)
-#endif
-}
-
-void MVideoWidgetViewPrivate::blitMultiYuvTexture(const uchar* data, int width, int height)
-{
-#ifdef M_USE_OPENGL
- GLuint target = GL_TEXTURE_2D;
- GLuint format = GL_LUMINANCE;
-
- int w[3] = {width, width / 2, width / 2};
- int h[3] = {height, height / 2, height / 2};
- int offs[3] = {0, width*height, width*height*5 / 4 };
- for (int i = 0; i < 3; ++i) {
- glBindTexture(target, m_textures[i]);
- glTexImage2D(target, 0, format, w[i], h[i], 0,
- GL_LUMINANCE, GL_UNSIGNED_BYTE, data + offs[i]);
- }
-#else
- Q_UNUSED(data)
- Q_UNUSED(width)
- Q_UNUSED(height)
-#endif
-}
-
-void MVideoWidgetViewPrivate::blitSingleYuvTexture(const uchar* data, int width, int height)
-{
-#ifdef M_USE_OPENGL
- const uchar *sp = data;
- uchar *texdata = new uchar[width * height * 3];
- uchar *dp = texdata;
-
- //do some precalculations for indexing the yuv data buffer
- int w_x_h = width * height;
- int w_x_h_div_4 = w_x_h / 4;
- int w_div_2 = width / 2;
-
- for (int y = 0; y < height; ++y) {
- int idx = y / 2 * w_div_2;
-
- for (int x = 0; x < width; ++x, dp += 3) {
- int x_div_2 = x / 2;
-
- // find yuv components from yuv420
- uchar y_val = sp[y * width + x];
- uchar u_val = sp[idx + x_div_2 + w_x_h];
- uchar v_val = sp[idx + x_div_2 + w_x_h + w_x_h_div_4];
-
- //fill texture data buffer
- dp[0] = y_val;
- dp[1] = u_val;
- dp[2] = v_val;
- }
- }
-
- //create the actual gl texture from the data
- GLuint target = GL_TEXTURE_2D;
- GLuint format = GL_RGB;
- glBindTexture(target, m_textures[0]);
- glTexImage2D(target, 0, format, width, height, 0,
- format, GL_UNSIGNED_BYTE, texdata);
- delete[] texdata;
-#else
- Q_UNUSED(data)
- Q_UNUSED(width)
- Q_UNUSED(height)
-#endif
-}
-
-/*
- * Precalculates a linear scale table for software blit.
- */
-static const int*
-calc_linear_scale(int src_w, int src_h, int dst_w, int dst_h)
-{
- int *table = new int[dst_w * dst_h];
- for (int y = 0, i = 0; y < dst_h; ++y) {
- int s_scan = ((y * src_h) / dst_h) * (src_w * 3);
- for (int x = 0; x < dst_w; ++x, ++i) {
- table[i] = s_scan + ((x * src_w) / dst_w) * 3;
- }
- }
- return table;
-}
-
-void MVideoWidgetViewPrivate::blitSwFrame()
-{
- if( !m_gstVideo->frameData() )
- return;
-
- //try to lock the frame data if the we cannot lock it
- //a new frame is currently being received and there will update
- //call when the new frame has been completely received so we
- //can safely skip the new frame texture creation for now
- if( !m_gstVideo->lockFrameData() ) {
- mWarning("MVideoWidgetViewPrivate::blitSwFrame()") << "MUTEX LOCK CONFLICT!";
- return;
- }
-
- blit(m_gstVideo->frameData(), m_gstVideo->resolution().width(), m_gstVideo->resolution().height());
-
- m_gstVideo->unlockFrameData();
-}
-
-/*
- * Prepare software blit, set correct image size, create
- * buffers & scaling offset table.
- */
-void MVideoWidgetViewPrivate::prepareBlit(int w, int h)
-{
- if (image && (image->width() != w || image->height() != h)) {
- delete image;
- delete[] bits;
- image = NULL;
- bits = NULL;
- }
-
- if (!image) {
- if (scaleOffsets)
- delete[] scaleOffsets;
-
- scaleOffsets = calc_linear_scale(m_gstVideo->resolution().width(), m_gstVideo->resolution().height(), w, h);
-
- bits = new uchar[w * h * 4];
- image = new QImage(bits, w, h, QImage::Format_RGB32);
- image->fill(0);
- }
-}
-
-/*
- * Blits the video frame using software rendering. Uses the
- * scale offset table precalculated in prepareBlit()
- */
-void MVideoWidgetViewPrivate::blit(const uchar* data, int w, int h)
-{
- QSize videoSize = m_gstVideo->resolution();
-
- //FIXME: non scaling method crashes currently.
- /*if( videoSize.width() == w && videoSize.height() == h ) {
- //blit without scaling
- blit(data);
- return;
- }else*/
- if (w > videoSize.width() || h > videoSize.height()) {
- // only downscaling supported
- mWarning("MVideoWidgetPrivate::blit()") << "error - upscaling not supported with sw rendering";
- return;
- }
-
- prepareBlit(w, h);
-
- // for each pixel in video frame
- uchar *sp, *dp;
- dp = bits;
- for (int i = 0, x = 0, y = 0; i < w*h; ++i, ++x, dp += 4) {
- sp = (uchar*)data + scaleOffsets[i];
- if (m_gstVideo->frameDataFormat() == MGstVideo::RGB) {
- // BGR -> RGB
- dp[0] = sp[2];
- dp[1] = sp[1];
- dp[2] = sp[0];
- } else {
-
- if (x == w) {
- x = 0;
- ++y;
- }
-
- int xx = (x * videoSize.width()) / w;
- int yy = (y * videoSize.height()) / h;
-
- // YUV420->RGB implementation (http://en.wikipedia.org/wiki/YUV#Y.27UV444)
- const uchar *srcp = data;
- // find yuv components from yuv420
- int y_val = srcp[yy * videoSize.width() + xx];
- int u_val = srcp[(yy/2) * (videoSize.width()/2) + xx/2 + videoSize.width()*videoSize.height()];
- int v_val = srcp[(yy/2) * (videoSize.width()/2) + xx/2 + videoSize.width()*videoSize.height() + ((videoSize.width()*videoSize.height())/4)];
-
- // fixed point yuv -> rgb conversion
- int r = (298 * (y_val - 16) + 409 * (v_val - 128) + 128) >> 8;
- int g = (298 * (y_val - 16) - 100 * (u_val - 128) - 208 * (v_val - 128) + 128) >> 8;
- int b = (298 * (y_val - 16) + 516 * (u_val - 128) + 128) >> 8;
-
- dp[0] = CLAMP(b, 0, 255);
- dp[1] = CLAMP(g, 0, 255);
- dp[2] = CLAMP(r, 0, 255);
- }
- }
-
- //force change of QImage::cacheKey(), to make sure the gl texture caching works.
- image->setPixel(0,0, image->pixel(0,0));
-}
-
-/*
- * Blits the video frame using software rendering
- * without any scaling.
- */
-void MVideoWidgetViewPrivate::blit(const uchar* data)
-{
- QSize videoSize = m_gstVideo->resolution();
- prepareBlit(videoSize.width(), videoSize.height());
-
- const uchar *sp = data;
- uchar *dp = bits;
- for (int x = 0, y = 0; y < videoSize.height(); ++x, sp += 3, dp += 4) {
-
- if (m_gstVideo->frameDataFormat() == MGstVideo::RGB) {
- // BGR -> RGB
- dp[0] = sp[2];
- dp[1] = sp[1];
- dp[2] = sp[0];
- } else {
- // YUV420->RGB implementation (http://en.wikipedia.org/wiki/YUV#Y.27UV444)
-
- // find yuv components from yuv420
- int y_val = sp[y * videoSize.width() + x];
- int u_val = sp[(y/2) * (videoSize.width()/2) + x/2 + videoSize.width()*videoSize.height()];
- int v_val = sp[(y/2) * (videoSize.width()/2) + x/2 + videoSize.width()*videoSize.height() + ((videoSize.width()*videoSize.height())/4)];
-
- // fixed point yuv -> rgb conversion
- int r = (298 * (y_val - 16) + 409 * (v_val - 128) + 128) >> 8;
- int g = (298 * (y_val - 16) - 100 * (u_val - 128) - 208 * (v_val - 128) + 128) >> 8;
- int b = (298 * (y_val - 16) + 516 * (u_val - 128) + 128) >> 8;
-
- dp[0] = CLAMP(b, 0, 255);
- dp[1] = CLAMP(g, 0, 255);
- dp[2] = CLAMP(r, 0, 255);
- }
-
- if (x == videoSize.width()) {
- x = 0;
- ++y;
- }
- }
-}
-
-unsigned long MVideoWidgetViewPrivate::currentWinId() const
-{
- return MApplication::activeApplicationWindow()->viewport()->effectiveWinId();
-}
-
-void MVideoWidgetViewPrivate::_q_enableVisualUpdates()
-{
- m_updateEnabled = true;
-}
-
-void MVideoWidgetViewPrivate::_q_disableVisualUpdates()
-{
- m_updateEnabled = false;
-}
-
-MVideoWidgetView::MVideoWidgetView(MVideoWidget* controller) :
- MWidgetView(* new MVideoWidgetViewPrivate, controller)
-{
- Q_D(MVideoWidgetView);
- connect(d->m_gstVideo, SIGNAL(videoReady()),
- SLOT(videoReady()));
- connect(d->m_gstVideo, SIGNAL(frameReady()),
- SLOT(frameReady()));
- connect(d->m_gstVideo, SIGNAL(stateChanged()),
- SLOT(stateChanged()));
-
- connect(controller, SIGNAL(displayEntered()),SLOT(_q_enableVisualUpdates()));
- connect(controller, SIGNAL(displayExited()), SLOT(_q_disableVisualUpdates()));
-}
-
-MVideoWidgetView::MVideoWidgetView(MVideoWidgetViewPrivate &dd, MVideoWidget *controller) :
- MWidgetView(dd, controller)
-{
- Q_D(MVideoWidgetView);
- connect(d->m_gstVideo, SIGNAL(videoReady()),
- SLOT(videoReady()));
- connect(d->m_gstVideo, SIGNAL(frameReady()),
- SLOT(frameReady()));
- connect(d->m_gstVideo, SIGNAL(stateChanged()),
- SLOT(stateChanged()));
-
- connect(controller, SIGNAL(displayEntered()),SLOT(_q_enableVisualUpdates()));
- connect(controller, SIGNAL(displayExited()), SLOT(_q_disableVisualUpdates()));
-}
-
-MVideoWidgetView::~MVideoWidgetView()
-{
-}
-
-void MVideoWidgetView::drawContents(QPainter* painter, const QStyleOptionGraphicsItem* option) const
-{
- Q_UNUSED(option);
-
- Q_D(const MVideoWidgetView);
-
- if( d->m_gstVideo->renderTarget() == MGstVideo::MSink ) {
- if (d->m_needFillBg && style()->backgroundColor().isValid()) {
- painter->fillRect(boundingRect(), style()->backgroundColor());
- }
-
- if( !d->m_gstVideo->isReady() )
- return;
-
- MGLES2Renderer* r = MGLES2Renderer::instance();
- if( r ) {
- bool yuv = d->m_gstVideo->frameDataFormat() == MGstVideo::YUV;
- if( yuv ) {
- if( d->m_useSingleYuvTexture ) {
- r->begin(painter, r->getShaderProgram(M_SHADER_SOURCE_DIR "/yuv1.frag" ));
- r->bindTexture(d->m_textures[0], QSize(-1,-1), 0, "textureYUV");
- } else {
- r->begin(painter, r->getShaderProgram(M_SHADER_SOURCE_DIR "/yuv3.frag"));
- r->bindTexture(d->m_textures[0], QSize(-1,-1), 0, "textureY");
- r->bindTexture(d->m_textures[1], QSize(-1,-1), 1, "textureU");
- r->bindTexture(d->m_textures[2], QSize(-1,-1), 2, "textureV");
- }
- } else {
- r->begin(painter);
- r->bindTexture(d->m_textures[0]);
- }
- r->setInvertTexture(true);
- r->draw(d->m_scaledVideoRect.toRect());
- r->end();
- }
- else if( d->image ) {
- // SW rendering
- painter->drawImage(d->m_scaledVideoRect.toRect(), *d->image);
- }
- } else {
- painter->fillRect(boundingRect(), style()->colorKey());
- unsigned long id = d->currentWinId();
- if( d->m_gstVideo->winId() != id && id != 0 )
- d->m_gstVideo->setWinId(id);
- d->m_gstVideo->expose();
- }
-}
-
-QSizeF MVideoWidgetView::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
-{
- Q_D(const MVideoWidgetView);
- Q_UNUSED(constraint);
-
- if( d->m_gstVideo->isReady() ) {
- if (which == Qt::PreferredSize) {
- MWindow* w = MApplication::activeWindow();
- return model()->fullscreen() ? w->visibleSceneSize() : d->m_gstVideo->resolution();
- }
- }
- return QSizeF(-1, -1);
-}
-
-void MVideoWidgetView::resizeEvent(QGraphicsSceneResizeEvent* event)
-{
- Q_UNUSED(event);
- Q_D(MVideoWidgetView);
- d->updateVideoGeometry();
-}
-
-void MVideoWidgetView::applyStyle()
-{
- Q_D(MVideoWidgetView);
-
- if( model()->fullscreen() ) {
- style().setModeFullscreen();
- d->m_gstVideo->setColorKey(style()->colorKey());
- }
- else {
- style().setModeDefault();
- }
-
- MWidgetView::applyStyle();
-
- d->update();
-}
-
-void MVideoWidgetView::mousePressEvent(QGraphicsSceneMouseEvent *event)
-{
- Q_UNUSED(event);
-}
-
-void MVideoWidgetView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
-{
- Q_UNUSED(event);
-}
-
-void MVideoWidgetView::cancelEvent(MCancelEvent *event)
-{
- Q_UNUSED(event);
-}
-
-void MVideoWidgetView::updateData(const QList<const char*>& modifications)
-{
- Q_D(MVideoWidgetView);
-
- MWidgetView::updateData(modifications);
-
- const char* member;
- foreach(member, modifications) {
- if(member == MVideoWidgetModel::Filename ) {
- model()->setLength(0);
- if( !d->m_gstVideo->open(model()->filename()) ) {
- }
- }
- else if( member == MVideoWidgetModel::State ) {
- d->m_gstVideo->setVideoState(model()->state());
- }
- else if( member == MVideoWidgetModel::Position ) {
- d->m_gstVideo->seek(model()->position());
- d->update();
- }
- else if( member == MVideoWidgetModel::Looping ) {
- d->m_gstVideo->setLooping(model()->looping());
- }
- else if( member == MVideoWidgetModel::Muted ) {
- d->m_gstVideo->setMuted(model()->muted());
- }
- else if( member == MVideoWidgetModel::Volume ) {
- d->m_gstVideo->setVolume(model()->volume());
- }
- else if( member == MVideoWidgetModel::Fullscreen ) {
- applyStyle();
-
- if( model()->fullscreen() ) {
- d->m_gstVideo->setWinId(d->currentWinId());
- d->m_gstVideo->setRenderTarget(MGstVideo::XvSink);
- }
- else {
- d->m_gstVideo->setRenderTarget(MGstVideo::MSink);
- }
-
- updateGeometry();
- d->update();
- }
- else if( member == MVideoWidgetModel::ScaleMode ) {
- d->updateVideoGeometry();
- d->update();
- }
- else if( member == MVideoWidgetModel::AspectRatioMode ) {
- d->m_gstVideo->forceAspectRatio(model()->aspectRatioMode() == MVideoWidgetModel::AspectRatioOriginal);
- d->updateVideoGeometry();
- d->update();
- }
- }
-}
-
-void MVideoWidgetView::setupModel()
-{
- MWidgetView::setupModel();
-
- Q_D(MVideoWidgetView);
-
- applyStyle();
-
- if( model()->fullscreen() ) {
- d->m_gstVideo->setWinId(d->currentWinId());
- d->m_gstVideo->setRenderTarget(MGstVideo::XvSink);
- }
- else {
- d->m_gstVideo->setRenderTarget(MGstVideo::MSink);
- }
-
- d->m_gstVideo->forceAspectRatio(model()->aspectRatioMode() == MVideoWidgetModel::AspectRatioOriginal);
-
- d->m_gstVideo->setLooping(model()->looping());
- d->m_gstVideo->open(model()->filename());
-
- updateGeometry();
- d->update();
-}
-
-M_REGISTER_VIEW_NEW(MVideoWidgetView, MVideoWidget)
-#include "moc_mvideowidgetview.cpp"
diff --git a/src/views/video/mvideowidgetview.h b/src/views/video/mvideowidgetview.h
deleted file mode 100644
index 2bc064e3..00000000
--- a/src/views/video/mvideowidgetview.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* * This file is part of libmeegotouch *
- *
- * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
- * All rights reserved.
- *
- * Contact: Tomas Junnonen <tomas.junnonen@nokia.com>
- *
- * This software, including documentation, is protected by copyright
- * controlled by Nokia Corporation. All rights are reserved. Copying,
- * including reproducing, storing, adapting or translating, any or all of
- * this material requires the prior written consent of Nokia Corporation.
- * This material also contains confidential information which may not be
- * disclosed to others without the prior written consent of Nokia.
- */
-#ifndef MVIDEOWIDGETVIEW_H
-#define MVIDEOWIDGETVIEW_H
-
-#include <mwidgetview.h>
-#include <mvideowidgetmodel.h>
-#include <mvideowidgetstyle.h>
-
-class MVideoWidgetViewPrivate;
-class MVideoWidget;
-
-class QGraphicsSceneResizeEvent;
-
-/*!
- \class MVideoWidgetView
- \brief View class for a video frame.
-
- \ingroup views
-
- \section MVideoWidgetViewOverview Overview
- Standard view for displaying video frames without any other graphical
- components.
-
- \section MVideoWidgetViewInteractions Interactions
-
- \section MVideoWidgetViewOpenIssues Open issues
-
- \sa MVideoWidget MVideoWidgetStyle
-*/
-class M_VIEWS_EXPORT MVideoWidgetView : public MWidgetView
-{
- Q_OBJECT
- M_VIEW(MVideoWidgetModel, MVideoWidgetStyle)
-
-public:
-
- /*!
- \brief Constructs the view.
- \param Pointer to the controller.
- */
- MVideoWidgetView(MVideoWidget* controller);
-
- /*!
- \brief Destructs the view.
- */
- virtual ~MVideoWidgetView();
-
- //! \reimp
- virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
- //! \reimp_end
-
-protected:
-
- //! \reimp
- virtual void drawContents(QPainter* painter, const QStyleOptionGraphicsItem* option) const;
- virtual void applyStyle();
- virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
- virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
- virtual void setupModel();
- virtual void cancelEvent(MCancelEvent* event);
- virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint = QSizeF()) const;
- //! \reimp_end
-
- //! \cond
- MVideoWidgetView(MVideoWidgetViewPrivate& dd, MVideoWidget* controller);
- //! \endcond
-
-protected Q_SLOTS:
- //! \reimp
- virtual void updateData(const QList<const char*>& modifications);
- //! \reimp_end
-
-private:
- Q_DISABLE_COPY(MVideoWidgetView)
- Q_DECLARE_PRIVATE(MVideoWidgetView)
-
- Q_PRIVATE_SLOT(d_func(), void videoReady())
- Q_PRIVATE_SLOT(d_func(), void frameReady())
- Q_PRIVATE_SLOT(d_func(), void stateChanged())
-
- Q_PRIVATE_SLOT(d_func(), void _q_enableVisualUpdates())
- Q_PRIVATE_SLOT(d_func(), void _q_disableVisualUpdates())
-};
-
-#endif
diff --git a/src/views/video/mvideowidgetview_p.h b/src/views/video/mvideowidgetview_p.h
deleted file mode 100644
index 89940caf..00000000
--- a/src/views/video/mvideowidgetview_p.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* This file is part of libmeegotouch
- *
- * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
- * All rights reserved.
- *
- * Contact: Tomas Junnonen <tomas.junnonen@nokia.com>
- *
- * This software, including documentation, is protected by copyright
- * controlled by Nokia Corporation. All rights are reserved. Copying,
- * including reproducing, storing, adapting or translating, any or all of
- * this material requires the prior written consent of Nokia Corporation.
- * This material also contains confidential information which may not be
- * disclosed to others without the prior written consent of Nokia.
- */
-#ifndef MVIDEOWIDGETVIEW_P_H
-#define MVIDEOWIDGETVIEW_P_H
-
-#include "private/mwidgetview_p.h"
-
-class MVideoWidgetView;
-class MVideoWidgetModel;
-class MGstVideo;
-class QGLShaderProgram;
-
-class MVideoWidgetViewPrivate : public MWidgetViewPrivate
-{
-public:
-
- Q_DECLARE_PUBLIC(MVideoWidgetView)
-
- MVideoWidgetViewPrivate();
- virtual ~MVideoWidgetViewPrivate();
-
- const MVideoWidgetModel* model() const;
- MVideoWidgetModel* model();
-
- void update();
- void updateGeometry();
-
- void videoReady();
- void frameReady();
- void stateChanged();
-
- void updateVideoGeometry();
-
- void blitGLFrame();
- void blitRgbTexture(const uchar* data, int width, int height);
- void blitMultiYuvTexture(const uchar* data, int width, int height);
- void blitSingleYuvTexture(const uchar* data, int width, int height);
-
- void blitSwFrame();
- void prepareBlit(int w, int h);
- void blit(const uchar* data);
- void blit(const uchar* data, int w, int h);
-
- unsigned long currentWinId() const;
-
- void _q_enableVisualUpdates();
- void _q_disableVisualUpdates();
-
- bool m_useSingleYuvTexture;
- unsigned int m_textures[3];
-
- QImage *image;
- uchar *bits;
- const int *scaleOffsets;
-
- bool m_needFillBg;
-
- QString m_videoFilename;
-
- QRectF m_scaledVideoRect;
-
- bool m_fullscreen;
-
- MGstVideo* m_gstVideo;
-
- bool m_updateEnabled;
-};
-
-#endif
diff --git a/src/views/video/video.pri b/src/views/video/video.pri
deleted file mode 100644
index 921a8791..00000000
--- a/src/views/video/video.pri
+++ /dev/null
@@ -1,17 +0,0 @@
-VIDEO_SRC_DIR = ./video
-INCLUDEPATH +=./video
-
-contains( DEFINES, HAVE_GSTREAMER) {
- PUBLIC_HEADERS += \
- $$VIDEO_SRC_DIR/mvideowidgetview.h \
-
- PRIVATE_HEADERS += \
- $$VIDEO_SRC_DIR/mvideowidgetview_p.h \
- $$VIDEO_SRC_DIR/msink.h \
- $$VIDEO_SRC_DIR/mgstvideo.h \
-
- SOURCES += \
- $$VIDEO_SRC_DIR/mvideowidgetview.cpp \
- $$VIDEO_SRC_DIR/msink.c \
- $$VIDEO_SRC_DIR/mgstvideo.cpp \
-}
diff --git a/src/views/views.pro b/src/views/views.pro
index 316f0241..01807a69 100644
--- a/src/views/views.pro
+++ b/src/views/views.pro
@@ -12,7 +12,6 @@ INCLUDEPATH += \
../corelib/widgets/views \
../corelib/widgets \
../corelib/core \
- ../corelib/video \
../corelib/.gen \
include(effects/effects.pri)
@@ -20,7 +19,6 @@ include(views.pri)
include(widgets/widgets.pri)
include(animations/animations.pri)
include(style/style.pri)
-include(video/video.pri)
LIBS += $$mAddLibrary(meegotouchcore)
SOURCES += mviewslibrary.cpp