--- /dev/null
+/*
+ * This file is part of QMAFW
+ *
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
+ * reserved.
+ *
+ * Contact: Visa Smolander <visa.smolander@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 MAFW_GSTRENDERER_INTERFACE_H
+#define MAFW_GSTRENDERER_INTERFACE_H
+
+#include "mafw-gst-renderer-worker.h"
+#include "MafwGstRendererHaltState.h"
+
+#include <MafwBasicRenderer.h>
+#include <MafwError.h>
+#include <MafwMediaInfo.h>
+
+#include <QTimer>
+#include <glib.h>
+
+class MafwBlankingPreventer;
+class MafwGstRendererVolume;
+class MafwGstRendererDolby;
+class MafwGstRendererNetworkMonitor;
+class ContextProperty;
+class QDBusMessage;
+class MafwGstRendererPlaylistFileUtility;
+class MafwMmcMonitor;
+class QSettings;
+class MafwGstScreenshot;
+class MafwGstRendererHaltState;
+
+class QSparqlConnection;
+class QSparqlResult;
+
+/**
+ * Implements MAFW GStreamer renderer.
+ * @credential TrackerReadAccess Tracker read access
+ * @credential TrackerWriteAccess Tracker write access
+ *
+ */
+class MafwGstRenderer : public MafwBasicRenderer
+{
+ Q_OBJECT
+
+private:
+ /**
+ * Callback function that gets called when the GStreamer worker pipeline has
+ * gone to playing state.
+ * @param worker Pointer to GStreamer worker instance
+ * @param owner Pointer to GStreamer worker owner (instance of this class)
+ */
+ static void playCallback(MafwGstRendererWorker *worker, gpointer owner);
+
+ /**
+ * Callback function that gets called when the GStreamer worker pipeline has
+ * gone to paused state.
+ * @param worker Pointer to GStreamer worker instance
+ * @param owner Pointer to GStreamer worker owner (instance of this class)
+ */
+ static void pauseCallback(MafwGstRendererWorker *worker, gpointer owner);
+
+ /**
+ * Callback function that gets called when the GStreamer worker pipeline has
+ * reached EOS state.
+ * @param worker Pointer to GStreamer worker instance
+ * @param owner Pointer to GStreamer worker owner (instance of this class)
+ */
+ static void eosCallback(MafwGstRendererWorker *worker, gpointer owner);
+
+ /**
+ * Callback for informing when resources are no longer used in PAUSED state.
+ * @param worker Pointer to GStreamer worker instance
+ * @param owner Pointer to GStreamer worker owner (instance of this class)
+ */
+ static void readyStateCallback(MafwGstRendererWorker *worker, gpointer owner);
+
+ /**
+ * Callback function that gets called when the GStreamer worker signals an
+ * error.
+ * @param worker Pointer to GStreamer worker instance
+ * @param owner Pointer to GStreamer worker owner (instance of this class)
+ * @param error Pointer to signalled error
+ */
+ static void errorCallback(MafwGstRendererWorker *worker,
+ gpointer owner,
+ const GError *error);
+
+ /**
+ * Callback function that gets called when the GStreamer worker signals
+ * new metadata.
+ * @param worker Pointer to GStreamer worker instance
+ * @param owner Pointer to GStreamer worker owner (instance of this class)
+ * @param key Metadata key indicating what metadata is signalled
+ * @param type Type of signalled metadata
+ * @param value Pointer to actual metadata value
+ */
+ static void metadataCallback(MafwGstRendererWorker *worker,
+ gpointer owner,
+ gint key,
+ GType type,
+ gpointer value);
+
+ /**
+ * Callback function that gets called when the GStreamer worker signals
+ * a (new) property value.
+ * @param worker Pointer to GStreamer worker instance
+ * @param owner Pointer to GStreamer worker owner (instance of this class)
+ * @param id ID indicating what property is signalled
+ * @param value Pointer to actual property value
+ */
+ static void propertyCallback(MafwGstRendererWorker *worker,
+ gpointer owner,
+ gint id,
+ GValue *value);
+
+ /**
+ * Callback function that gets called when the GStreamer worker signals
+ * a status when it is buffering a stream.
+ * @param worker Pointer to GStreamer worker instance
+ * @param owner Pointer to GStreamer worker owner (instance of this class)
+ * @param percent Buffering percentage value
+ */
+ static void bufferStatusCallback(MafwGstRendererWorker *worker,
+ gpointer owner,
+ gdouble percent);
+
+ static void blankingControlCallback(MafwGstRendererWorker *worker,
+ gpointer owner,
+ gboolean prohibit);
+
+ /**
+ * Callback funtion that gets called when we save new pause frame.
+ * @param worker Pointer to GStreamer worker instance
+ * @param owner Pointer to GStreamer worker owner (instence of this class)
+ * @param buffer Pointer to GstBuffer that contains pause frame data
+ * @param filename Location where the pause frame is saved
+ * @param cancel True if pause frame saving is canceled
+ */
+ static void screenshotCallback(MafwGstRendererWorker *worker,
+ gpointer owner,
+ GstBuffer *buffer,
+ const char *filename,
+ gboolean cancel);
+
+ /**
+ * Helper function to convert a GValue to a QVariant
+ * @param v Pointer to GValue to be converted
+ * @return QVariant holding the same value as the GValue held
+ */
+ static QVariant getValue(const GValue *v);
+
+ /**
+ * Mapping between GStreamer worker metadata vs mafw metadata
+ */
+ static const QHash<int, QString>& metadataMap();
+
+ /**
+ * Mapping of obtained audio route to internal type
+ */
+ static const QHash<QString, QList<int> >& audioRouteMap();
+
+ /**
+ * Mapping of obtained video route to internal type
+ */
+ static const QHash<QString, QList<int> >& videoRouteMap();
+
+ /**
+ * Mapping between GStreamer worker errors vs mafw errors
+ */
+ static const QHash<int, MafwError::Code>& errorMap();
+
+public:
+
+ MafwGstRenderer(const QString& uuid,
+ const QString& pluginName,
+ const QString& name,
+ QObject* parent = 0);
+ /**
+ * Desctructor
+ */
+ ~MafwGstRenderer();
+
+ /**
+ * Initializes the renderer.
+ * @param settings Settings to use for configuration
+ * @return True on success, false otherwise
+ */
+ bool initialize(QSettings *settings);
+
+public: //MafwBasicRenderer implementation
+
+ void doPlay(const MafwContent& content);
+ void doPlay(const MafwMediaInfo& mediaInfo);
+
+ void doStop();
+
+ void doPause();
+
+ void doResume();
+
+ void doSeek(int position, MafwRenderer::SeekMode);
+
+ bool doNextHint(const MafwContent& next);
+ bool doNextHint(const MafwMediaInfo& nextMediaInfo);
+
+public: // MafwRenderer implementation
+ bool getPosition(QObject* resultsReceiver, const char* resultsMember);
+
+ bool setMafwProperty(const QString& name, const QVariant& value);
+ bool mafwProperty(QString& name, QObject* receiver, const char* member);
+ bool getCurrentMediaInfo(QObject* receiver, const char* member, const QString& metadataKey=0);
+
+private: //functionality
+ void playURI(const QString& uri);
+ void sendMediaInfo(const MafwMediaInfo& content, QObject* receiver, const char* member);
+ bool connectNameOwnerChanged();
+ void setConfiguration(QSettings *settings);
+ QVariant readSettingsValue(QSettings *settings, const QString &valueName,
+ const QVariant &defaultValue) const;
+ /*Helper function for metadataCallback(). Appends related metadata to the result list for emitting metadataChanged().*/
+ void appendRelatedMetadata(const QString key, QList<QVariant>* results);
+ void stampIt(const QString& node, int usageCount, int mediaDuration);
+ /**
+ * Helper function which sets the error code to be RendererError_UnsupportedResolution if
+ * resolution is above boundaries 720 x 1280, otherwise error code is to
+ * RendererError_UnsupportedResolution.
+ * @param error reference to error which code is set.
+ */
+ void handleResolutionError(MafwError& error);
+ /** Helper function for creating a MafwError from GError */
+ MafwError constructMafwError(const GError* error);
+
+private Q_SLOTS:
+
+ /**
+ * Slot to call when the current playback position queried.
+ * @param resultsReceiver Pointer to object where to deliver result
+ * @param resultsMember Pointer to member where to deliver result
+ */
+ void slotGetPosition(QObject* resultsReceiver,
+ const char* resultsMember);
+
+ /**
+ * Slot to call when a property value is queried.
+ * @param name Property name to be queried
+ * @param receiver Pointer to object where to deliver result
+ * @param member Pointer to member where to deliver result
+ */
+ void slotMafwProperty(const QString& name, QObject* receiver, const char* member);
+
+ /**
+ * Store usageCounter and contentAccessed properties of currently playing media to Tracker.
+ */
+ void slotStamp();
+
+ /**
+ * Slot to call when stampit has finished.
+ */
+ void slotStampItDone();
+
+ /**
+ * usageCounter query ready in play uri case
+ */
+ void slotStampQueryReady();
+
+ /**
+ * Commands the next URI to be played.
+ */
+ void playNext();
+
+ /**
+ * Tries to play the next URI from the given playlist URI. If no next
+ * URI commands playNext()
+ */
+ void playNextURIFromPlaylist();
+
+ /**
+ * Slot to call asynchronously to restart playback
+ * (e.g. when internet radio disconnect due to network issues)
+ */
+ void restartPlay();
+
+ /**
+ * Query metadata from currently played clip or stream.
+ */
+ void slotGetCurrentMediaInfo(QObject* receiver, const char* member, const QString& metadataKey);
+
+ /**
+ * Called when volume has been changed.
+ */
+ void handleVolumeChange(uint level);
+
+ /**
+ * Slot called when audio/video route context framework property changes.
+ */
+ void slotRouteChanged();
+
+ /**
+ * Called when a property has been changed.
+ */
+ void handlePropertyChanged(const QString& name, const QVariant& value);
+
+ /**
+ * Called when Dolby Headphones Mobile music property has been changed.
+ */
+ void handleDHMMusicPropertyChanged();
+
+ /**
+ * Called when Dolby Headphones Mobile video property has been changed.
+ */
+ void handleDHMVideoPropertyChanged();
+
+ /**
+ * Handle NameOwnerChanged signal of policy-context-daemon.
+ */
+ void handleContextProviderRemoval( const QDBusMessage& message );
+
+ /**
+ * Starts playing playlist file. This is called when parsing has been done.
+ */
+ void startPlayingPlaylistFile();
+
+ /**
+ * Handles the errors occured while parsing playlist file.
+ * @param succeeded true if no errors occured.
+ */
+ void handlePlaylistFileParsingErrors(bool succeeded);
+
+ /**
+ * Stops streaming if necessary
+ */
+ void stopStreaming();
+
+ /**
+ * Halts streaming if necessary, stores the needed info for future reference (@see MafwGstRenderer::continueStreaming())
+ */
+ void haltStreaming();
+
+ /**
+ * Continues streaming
+ */
+ void continueStreaming();
+
+ /**
+ * Any timers e.g. playlist file util & stamping timers will be stopped here
+ */
+ void stopTimers();
+
+ /**
+ * Called when new pause frame is ready or
+ * when there was error with pause frame encoding.
+ */
+ void handleScreenshot(char *location, GError *error);
+
+ /**
+ * Called when pause frame is cancelled.
+ */
+ void cancelScreenshot();
+
+ /**
+ * MMC going to be unmounted.
+ */
+ void mmcPreUnmount();
+
+Q_SIGNALS:
+ void signalGetPosition(QObject* resultsReceiver,
+ const char* resultsMember);
+
+ void signalMafwProperty(const QString& name, QObject* receiver,
+ const char* member);
+
+ void signalGetCurrentMediaInfo(QObject*, const char*, const QString);
+
+private: //data
+
+ /**
+ * Has this instance been initialized?
+ */
+ bool m_initialized;
+
+ /**
+ * Helps determining whether to request a new item to play
+ */
+ MafwRenderer::State m_currentState;
+
+ /**
+ * The next Content to play, if any.
+ */
+ MafwMediaInfo m_nextContent;
+
+ /**
+ * The currently to be played Content
+ */
+ MafwMediaInfo m_currentContent;
+
+ QMap<QString, QList<QVariant> > m_currentMetaData;
+
+ /**
+ * What item is the renderer currently playing?
+ */
+ MafwRendererPlayingUri m_playingItem;
+
+ /**
+ * GStreamer renderer worker
+ */
+ MafwGstRendererWorker *m_worker;
+
+ /**
+ * Timer for stamping media usageCount and contentAccessed
+ */
+ QTimer m_playedStampTimer;
+
+ MafwBlankingPreventer* m_blankingPreventer;
+
+ MafwGstScreenshot* m_screenshot;
+
+ /**
+ * Help to monitor network access
+ */
+ MafwGstRendererNetworkMonitor *m_networkMonitor;
+
+ /**
+ * "Halt" state to store state when changing network access point
+ */
+ MafwGstRendererHaltState m_haltState;
+
+ /**
+ * Object to handle volume
+ */
+ MafwGstRendererVolume* m_volume;
+
+ /**
+ * Object to handle Dolby Headphones Mobile plugin
+ */
+ MafwGstRendererDolby* m_dolby;
+
+ /**
+ * Context framework property for video route
+ */
+ ContextProperty *m_videoRoute;
+
+ /**
+ * Context framework property for audio route
+ */
+ ContextProperty *m_audioRoute;
+
+ /**
+ * Is contentAccessed and usageCount of current playing item already updated. (Update process has started)
+ */
+ bool m_playedStamped;
+ int m_playedStampTryCounter;
+
+ /**
+ * Used to stamp usageCount and updated duration
+ */
+ QSparqlConnection *m_sparqlConnection;
+ /**
+ * If playing just an URI this result is used to get the tracker urn for it
+ */
+ QSparqlResult *m_urnQueryResult;
+
+ /**
+ * Result handle for stampit actions
+ */
+ QSparqlResult *m_stampItResult;
+
+ /**
+ * Pointer to playlist file parsing utility
+ */
+ MafwGstRendererPlaylistFileUtility* m_playlistFileUtil;
+
+ /**
+ * Timer to try to play next item from given playlist URI, totem parser can be slow sometimes.
+ */
+ QTimer m_playlistNextTimer;
+
+ /**
+ * Flag indicating whether we are playing playlist file.
+ */
+ bool m_playingPlaylistFile;
+
+ /**
+ * The error we got when we have possibly tried gstreamer to play playlist file.
+ */
+ GError* m_unsupportedTypeError;
+
+ /**
+ * Flag indicating whether we have already played an item from URI playlist.
+ * I.e. an URI was given which points to a playlist, this flag
+ * tells if rendererPlaying() signal has already been sent for URI.
+ */
+ bool m_playedPlaylistItem;
+
+ MafwMmcMonitor* m_mmcMonitor;
+};
+
+#endif // MAFW_GSTRENDERER_INTERFACE_H