Tizen 2.1 base
[platform/framework/web/wrt-plugins-common.git] / src / modules / tizen / MMPlayer / MMPlayer.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 #ifndef WRTDEVICEAPIS_MMPLAYER_MMPLAYER_H_
17 #define WRTDEVICEAPIS_MMPLAYER_MMPLAYER_H_
18
19 #include <mmf/mm.h>
20 #include <mm_player.h>
21 #include <dpl/shared_ptr.h>
22 #include <dpl/mutex.h>
23 #include <MMPlayer/IMMPlayer.h>
24 #include <MMPlayer/MMPlayerFactory.h>
25 #include <MMPlayer/EventOnStateChange.h>
26
27 namespace WrtDeviceApis {
28 namespace MMPlayer {
29 /**
30  * Event to send from callback when end of stream will be reported -> mm_player_stop should be executed
31  */
32 class EventOnEOS : public Commons::ListenerEvent<EventOnEOS>
33 {
34 };
35
36 typedef DPL::SharedPtr<EventOnEOS> EventOnEOSPtr;
37 typedef Commons::ListenerEventEmitter<EventOnEOS> EventOnEOSEmitter;
38 typedef DPL::SharedPtr<EventOnEOSEmitter> EventOnEOSEmitterPtr;
39
40 class MMPlayer :
41     public Api::IMMPlayer,
42     public Commons::EventListener<EventOnEOS>
43 {
44     friend class Api::MMPlayerFactory;
45
46   public:
47     typedef enum
48     {
49         STATE_OPENED,
50         STATE_STOPPED,
51         STATE_PLAYING,
52         STATE_PAUSED,
53         STATE_COMPLETED,
54         STATE_UNDEFINED
55     } MMPLAYER_STATES;
56
57   private:
58     MMHandleType m_player;
59     MMPLAYER_STATES m_currentState;
60     unsigned int m_repeatTimes;
61
62     /**
63      * MMPlayer constructor
64      * \exception Commons::PlatformException when platform error occurs
65      */
66     explicit MMPlayer();
67
68   public:
69     /**
70      * MMPlayer destructor
71      */
72     virtual ~MMPlayer();
73
74     /**
75      * Gets handler to platform player type
76      */
77     virtual MMHandleType getHandler() const;
78
79     /**
80      * @See Api::MMPlayer::IMMPlayer::setEmitter
81      */
82     virtual void setEmitter(
83             const Api::EventOnStateChangeEmitterPtr& emitter);
84     /**
85      * @See Api::MMPlayer::IMMPlayer::getEmitter
86      */
87     Api::EventOnStateChangeEmitterPtr getEmitter();
88     /**
89      * @See Api::MMPlayer::IMMPlayer::clearEmitter
90      */
91     virtual void clearEmitter();
92
93     /**
94      * Gets player state
95      */
96     virtual MMPlayerStateType getState() const;
97
98     /**
99      * Used to recieve EventOnEOS
100      */
101     virtual void onAnswerReceived(const EventOnEOSPtr& event);
102
103     virtual unsigned int getRepeatTimes() const;
104
105     virtual void setRepeatTimes(unsigned int count);
106
107   private:
108     /**
109      * Callback method called by platform when player state changes.
110      * @param message Platform message
111      * @param param Platform parameter
112      * @param data User data.
113      */
114     static int onStateChange(int message,
115             void* param,
116             void* data);
117
118     /**
119      * Initialize player
120      * @throw Commons::PlatformException when platform error occures
121      */
122     void init();
123     /**
124      * Finalize player
125      */
126     void finalize();
127
128     DPL::Mutex m_emitterMtx;
129     Api::EventOnStateChangeEmitterPtr m_onStateChangeEmitter;
130     EventOnEOSEmitterPtr m_onEOSEmitter;
131 };
132
133 typedef DPL::SharedPtr<MMPlayer> MMPlayerPtr;
134
135 }
136 }
137
138 #endif // WRTDEVICEAPIS_MMPLAYER_MMPLAYER_H_