2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 // @file FMedia_TonePlayerImpl.h
20 // @brief This header file contains the declaration related to TonePlayer class
24 #ifndef _FMEDIA_INTERNAL_TONEPLAYER_IMPL_H_
25 #define _FMEDIA_INTERNAL_TONEPLAYER_IMPL_H_
28 #include <unique_ptr.h>
29 #include <FBaseColIList.h>
30 #include <FBaseByteBuffer.h>
31 #include <FBaseColArrayList.h>
32 #include <FBaseRtThread.h>
33 #include <FBaseObject.h>
34 #include <FBaseRtMutex.h>
35 #include <FBaseRtIRunnable.h>
36 #include <FMediaTone.h>
37 #include <FMediaAudioManagerTypes.h>
39 #define MAX_TONE_PLAYER_OUT_CAPACITY 16
41 namespace Tizen { namespace Media
44 class ITonePlayerEventListener;
45 class _TonePlayerWorker;
46 class _TonePlayerEvent;
49 : public virtual Tizen::Base::Object
52 _TonePlayerImpl(void);
53 virtual ~_TonePlayerImpl(void);
55 result Construct(const Tizen::Media::ITonePlayerEventListener& listener, const Tizen::Media::TonePlayer& tonePlayerInstance);
56 result Open(const Tizen::Base::Collection::IList& toneList, int repeatCount = 1);
57 result Open(const Tizen::Media::Tone& tone, int repeatCount = 1);
61 result SetVolume(int& volume);
62 int GetVolume(void) const;
64 TonePlayerState GetState(void) const;
65 result SetAudioStreamType(AudioStreamType type);
67 static void AudioIoInterrupted(audio_io_interrupted_code_e code, void *pUserData);
69 _TonePlayerImpl(const _TonePlayerImpl& rhs);
70 _TonePlayerImpl& operator =(const _TonePlayerImpl& rhs);
72 bool GetBuffer(Tizen::Base::ByteBuffer& toneBuffer);
73 bool GetNextToneBufferDetails(int bufferTobeFilledSize, int& firstFrequency, int& secondFrequency, long& startSample, long& endSample);
74 result SendEndOfTone(void);
75 result SendInterrupted(void);
76 result SendReleased(void);
77 result SendAudioFocusChanged();
78 result SendError(result r);
79 result MapExceptionToResult(int reason);
82 static _TonePlayerImpl* GetInstance(TonePlayer* pTonePlayer);
83 static const _TonePlayerImpl* GetInstance(const TonePlayer* pTonePlayer);
84 static void InitInstanceMutex(void);
85 static int __noOfInstances;
86 static int __instanceCount;
87 std::unique_ptr<Tizen::Base::ByteBuffer> __pToneBuffer;
88 std::unique_ptr<Tizen::Base::Collection::ArrayList> __pToneList;
89 std::unique_ptr<_TonePlayerEvent> __pTonePlayerEvent;
90 std::unique_ptr<Tizen::Base::Runtime::Thread> __pWorkerThread;
91 std::unique_ptr<_TonePlayerWorker> __pTonePlayerWorker;
92 std::unique_ptr<Tone> __pTone;
93 static std::unique_ptr<Tizen::Base::Runtime::Mutex> __pMutex;
94 static bool __isInstanceMutexInitialized;
96 Tizen::Media::ITonePlayerEventListener* __pTonePlayerEventListener;
98 int __tempRepeatCount;
104 TonePlayerState __tonePlayerState;
105 int __tobePlayedBuffCount;
106 bool __endOftoneReached;
108 long __sampleNumberArr[2];
109 int __tempRepeatCountArr[2];
110 int __toneListIndexArr[2];
111 bool __endOftoneReachedArr[2];
112 audio_out_h __audioOutHandle;
113 int __tonePlayerOptimalBufferSize;
115 AudioStreamType __audioStreamtype;
116 bool __interruptFlag;
118 }; //end of _TonePlayerImp
121 class _TonePlayerWorker
122 : public virtual Tizen::Base::Object
123 , public virtual Tizen::Base::Runtime::IRunnable
126 _TonePlayerWorker(void)
128 _pTonePlayerImpl = null;
130 void Initialize(_TonePlayerImpl* pTonePlayerImpl)
132 _pTonePlayerImpl = pTonePlayerImpl;
134 virtual Tizen::Base::Object* Run(void)
136 if (_pTonePlayerImpl)
138 _pTonePlayerImpl->Feed();
143 _TonePlayerImpl* _pTonePlayerImpl;
144 }; //end of _TonePlayerWorker