2 * This file is part of QMAFW
4 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
7 * Contact: Visa Smolander <visa.smolander@nokia.com>
9 * This software, including documentation, is protected by copyright controlled
10 * by Nokia Corporation. All rights are reserved. Copying, including
11 * reproducing, storing, adapting or translating, any or all of this material
12 * requires the prior written consent of Nokia Corporation. This material also
13 * contains confidential information which may not be disclosed to others
14 * without the prior written consent of Nokia.
18 #ifndef MAFW_GSTRENDERER_INTERFACE_H
19 #define MAFW_GSTRENDERER_INTERFACE_H
21 #include "mafw-gst-renderer-worker.h"
22 #include "MafwGstRendererHaltState.h"
24 #include <MafwBasicRenderer.h>
25 #include <MafwError.h>
26 #include <MafwMediaInfo.h>
31 class MafwBlankingPreventer;
32 class MafwGstRendererVolume;
33 class MafwGstRendererDolby;
34 class MafwGstRendererNetworkMonitor;
35 class ContextProperty;
37 class MafwGstRendererPlaylistFileUtility;
40 class MafwGstScreenshot;
41 class MafwGstRendererHaltState;
43 class QSparqlConnection;
47 * Implements MAFW GStreamer renderer.
48 * @credential TrackerReadAccess Tracker read access
49 * @credential TrackerWriteAccess Tracker write access
52 class MafwGstRenderer : public MafwBasicRenderer
58 * Callback function that gets called when the GStreamer worker pipeline has
59 * gone to playing state.
60 * @param worker Pointer to GStreamer worker instance
61 * @param owner Pointer to GStreamer worker owner (instance of this class)
63 static void playCallback(MafwGstRendererWorker *worker, gpointer owner);
66 * Callback function that gets called when the GStreamer worker pipeline has
67 * gone to paused state.
68 * @param worker Pointer to GStreamer worker instance
69 * @param owner Pointer to GStreamer worker owner (instance of this class)
71 static void pauseCallback(MafwGstRendererWorker *worker, gpointer owner);
74 * Callback function that gets called when the GStreamer worker pipeline has
76 * @param worker Pointer to GStreamer worker instance
77 * @param owner Pointer to GStreamer worker owner (instance of this class)
79 static void eosCallback(MafwGstRendererWorker *worker, gpointer owner);
82 * Callback for informing when resources are no longer used in PAUSED state.
83 * @param worker Pointer to GStreamer worker instance
84 * @param owner Pointer to GStreamer worker owner (instance of this class)
86 static void readyStateCallback(MafwGstRendererWorker *worker, gpointer owner);
89 * Callback function that gets called when the GStreamer worker signals an
91 * @param worker Pointer to GStreamer worker instance
92 * @param owner Pointer to GStreamer worker owner (instance of this class)
93 * @param error Pointer to signalled error
95 static void errorCallback(MafwGstRendererWorker *worker,
100 * Callback function that gets called when the GStreamer worker signals
102 * @param worker Pointer to GStreamer worker instance
103 * @param owner Pointer to GStreamer worker owner (instance of this class)
104 * @param key Metadata key indicating what metadata is signalled
105 * @param type Type of signalled metadata
106 * @param value Pointer to actual metadata value
108 static void metadataCallback(MafwGstRendererWorker *worker,
115 * Callback function that gets called when the GStreamer worker signals
116 * a (new) property value.
117 * @param worker Pointer to GStreamer worker instance
118 * @param owner Pointer to GStreamer worker owner (instance of this class)
119 * @param id ID indicating what property is signalled
120 * @param value Pointer to actual property value
122 static void propertyCallback(MafwGstRendererWorker *worker,
128 * Callback function that gets called when the GStreamer worker signals
129 * a status when it is buffering a stream.
130 * @param worker Pointer to GStreamer worker instance
131 * @param owner Pointer to GStreamer worker owner (instance of this class)
132 * @param percent Buffering percentage value
134 static void bufferStatusCallback(MafwGstRendererWorker *worker,
138 static void blankingControlCallback(MafwGstRendererWorker *worker,
143 * Callback funtion that gets called when we save new pause frame.
144 * @param worker Pointer to GStreamer worker instance
145 * @param owner Pointer to GStreamer worker owner (instence of this class)
146 * @param buffer Pointer to GstBuffer that contains pause frame data
147 * @param filename Location where the pause frame is saved
148 * @param cancel True if pause frame saving is canceled
150 static void screenshotCallback(MafwGstRendererWorker *worker,
153 const char *filename,
157 * Helper function to convert a GValue to a QVariant
158 * @param v Pointer to GValue to be converted
159 * @return QVariant holding the same value as the GValue held
161 static QVariant getValue(const GValue *v);
164 * Mapping between GStreamer worker metadata vs mafw metadata
166 static const QHash<int, QString>& metadataMap();
169 * Mapping of obtained audio route to internal type
171 static const QHash<QString, QList<int> >& audioRouteMap();
174 * Mapping of obtained video route to internal type
176 static const QHash<QString, QList<int> >& videoRouteMap();
179 * Mapping between GStreamer worker errors vs mafw errors
181 static const QHash<int, MafwError::Code>& errorMap();
185 MafwGstRenderer(const QString& uuid,
186 const QString& pluginName,
188 QObject* parent = 0);
195 * Initializes the renderer.
196 * @param settings Settings to use for configuration
197 * @return True on success, false otherwise
199 bool initialize(QSettings *settings);
201 public: //MafwBasicRenderer implementation
203 void doPlay(const MafwContent& content);
204 void doPlay(const MafwMediaInfo& mediaInfo);
212 void doSeek(int position, MafwRenderer::SeekMode);
214 bool doNextHint(const MafwContent& next);
215 bool doNextHint(const MafwMediaInfo& nextMediaInfo);
217 public: // MafwRenderer implementation
218 bool getPosition(QObject* resultsReceiver, const char* resultsMember);
220 bool setMafwProperty(const QString& name, const QVariant& value);
221 bool mafwProperty(QString& name, QObject* receiver, const char* member);
222 bool getCurrentMediaInfo(QObject* receiver, const char* member, const QString& metadataKey=0);
224 private: //functionality
225 void playURI(const QString& uri);
226 void sendMediaInfo(const MafwMediaInfo& content, QObject* receiver, const char* member);
227 bool connectNameOwnerChanged();
228 void setConfiguration(QSettings *settings);
229 QVariant readSettingsValue(QSettings *settings, const QString &valueName,
230 const QVariant &defaultValue) const;
231 /*Helper function for metadataCallback(). Appends related metadata to the result list for emitting metadataChanged().*/
232 void appendRelatedMetadata(const QString key, QList<QVariant>* results);
233 void stampIt(const QString& node, int usageCount, int mediaDuration);
235 * Helper function which sets the error code to be RendererError_UnsupportedResolution if
236 * resolution is above boundaries 720 x 1280, otherwise error code is to
237 * RendererError_UnsupportedResolution.
238 * @param error reference to error which code is set.
240 void handleResolutionError(MafwError& error);
241 /** Helper function for creating a MafwError from GError */
242 MafwError constructMafwError(const GError* error);
247 * Slot to call when the current playback position queried.
248 * @param resultsReceiver Pointer to object where to deliver result
249 * @param resultsMember Pointer to member where to deliver result
251 void slotGetPosition(QObject* resultsReceiver,
252 const char* resultsMember);
255 * Slot to call when a property value is queried.
256 * @param name Property name to be queried
257 * @param receiver Pointer to object where to deliver result
258 * @param member Pointer to member where to deliver result
260 void slotMafwProperty(const QString& name, QObject* receiver, const char* member);
263 * Store usageCounter and contentAccessed properties of currently playing media to Tracker.
268 * Slot to call when stampit has finished.
270 void slotStampItDone();
273 * usageCounter query ready in play uri case
275 void slotStampQueryReady();
278 * Commands the next URI to be played.
283 * Tries to play the next URI from the given playlist URI. If no next
284 * URI commands playNext()
286 void playNextURIFromPlaylist();
289 * Slot to call asynchronously to restart playback
290 * (e.g. when internet radio disconnect due to network issues)
295 * Query metadata from currently played clip or stream.
297 void slotGetCurrentMediaInfo(QObject* receiver, const char* member, const QString& metadataKey);
300 * Called when volume has been changed.
302 void handleVolumeChange(uint level);
305 * Slot called when audio/video route context framework property changes.
307 void slotRouteChanged();
310 * Called when a property has been changed.
312 void handlePropertyChanged(const QString& name, const QVariant& value);
315 * Called when Dolby Headphones Mobile music property has been changed.
317 void handleDHMMusicPropertyChanged();
320 * Called when Dolby Headphones Mobile video property has been changed.
322 void handleDHMVideoPropertyChanged();
325 * Handle NameOwnerChanged signal of policy-context-daemon.
327 void handleContextProviderRemoval( const QDBusMessage& message );
330 * Starts playing playlist file. This is called when parsing has been done.
332 void startPlayingPlaylistFile();
335 * Handles the errors occured while parsing playlist file.
336 * @param succeeded true if no errors occured.
338 void handlePlaylistFileParsingErrors(bool succeeded);
341 * Stops streaming if necessary
343 void stopStreaming();
346 * Halts streaming if necessary, stores the needed info for future reference (@see MafwGstRenderer::continueStreaming())
348 void haltStreaming();
351 * Continues streaming
353 void continueStreaming();
356 * Any timers e.g. playlist file util & stamping timers will be stopped here
361 * Called when new pause frame is ready or
362 * when there was error with pause frame encoding.
364 void handleScreenshot(char *location, GError *error);
367 * Called when pause frame is cancelled.
369 void cancelScreenshot();
372 * MMC going to be unmounted.
374 void mmcPreUnmount();
377 void signalGetPosition(QObject* resultsReceiver,
378 const char* resultsMember);
380 void signalMafwProperty(const QString& name, QObject* receiver,
383 void signalGetCurrentMediaInfo(QObject*, const char*, const QString);
388 * Has this instance been initialized?
393 * Helps determining whether to request a new item to play
395 MafwRenderer::State m_currentState;
398 * The next Content to play, if any.
400 MafwMediaInfo m_nextContent;
403 * The currently to be played Content
405 MafwMediaInfo m_currentContent;
407 QMap<QString, QList<QVariant> > m_currentMetaData;
410 * What item is the renderer currently playing?
412 MafwRendererPlayingUri m_playingItem;
415 * GStreamer renderer worker
417 MafwGstRendererWorker *m_worker;
420 * Timer for stamping media usageCount and contentAccessed
422 QTimer m_playedStampTimer;
424 MafwBlankingPreventer* m_blankingPreventer;
426 MafwGstScreenshot* m_screenshot;
429 * Help to monitor network access
431 MafwGstRendererNetworkMonitor *m_networkMonitor;
434 * "Halt" state to store state when changing network access point
436 MafwGstRendererHaltState m_haltState;
439 * Object to handle volume
441 MafwGstRendererVolume* m_volume;
444 * Object to handle Dolby Headphones Mobile plugin
446 MafwGstRendererDolby* m_dolby;
449 * Context framework property for video route
451 ContextProperty *m_videoRoute;
454 * Context framework property for audio route
456 ContextProperty *m_audioRoute;
459 * Is contentAccessed and usageCount of current playing item already updated. (Update process has started)
461 bool m_playedStamped;
462 int m_playedStampTryCounter;
465 * Used to stamp usageCount and updated duration
467 QSparqlConnection *m_sparqlConnection;
469 * If playing just an URI this result is used to get the tracker urn for it
471 QSparqlResult *m_urnQueryResult;
474 * Result handle for stampit actions
476 QSparqlResult *m_stampItResult;
479 * Pointer to playlist file parsing utility
481 MafwGstRendererPlaylistFileUtility* m_playlistFileUtil;
484 * Timer to try to play next item from given playlist URI, totem parser can be slow sometimes.
486 QTimer m_playlistNextTimer;
489 * Flag indicating whether we are playing playlist file.
491 bool m_playingPlaylistFile;
494 * The error we got when we have possibly tried gstreamer to play playlist file.
496 GError* m_unsupportedTypeError;
499 * Flag indicating whether we have already played an item from URI playlist.
500 * I.e. an URI was given which points to a playlist, this flag
501 * tells if rendererPlaying() signal has already been sent for URI.
503 bool m_playedPlaylistItem;
505 MafwMmcMonitor* m_mmcMonitor;
508 #endif // MAFW_GSTRENDERER_INTERFACE_H