Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / MediaApp / MediaApp / project / src / Codec / AudioDecoderForm.h
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.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
8 //
9 //     http://www.tizenopensource.org/license
10 //
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.
16 //
17
18 #ifndef _AUDIO_DECODER_FORM_H_
19 #define _AUDIO_DECODER_FORM_H_
20
21 namespace MediaAppAudioDecoder
22 {
23 enum responseType
24 {
25         DECODE_DONE,
26         DECODE_FAIL,
27         DECODE_CANCELLED,
28         DECODER_UI_UPDATE,
29         DECODE_AAC_DATA,
30         DECODE_MP3_DATA,
31         DECODE_AMR_DATA,
32         DECODE_VORBIS_DATA,
33 };
34
35 enum AudioCodecType
36 {
37         CODEC_TYPE_AAC = 0,
38         CODEC_TYPE_AMR,
39         CODEC_TYPE_MP3,
40         CODEC_TYPE_VORBIS,
41         CODEC_TYPE_CODEC_UNKNOWN,
42 };
43
44 // const values for buttons
45 const int PREV_INDEX = 0;
46 const int NEXT_INDEX = 1;
47 const int ID_BACK = 100;
48 const int ID_PREV = 101;
49 const int ID_NEXT = 102;
50 const int ID_DECODE = 103;
51 const int ID_PLAY = 104;
52 // Sufficeient buffer size
53 const int SRC_BUF_SIZE = 1024 * 16;
54 const int DST_BUF_SIZE = 1024 * 16 * 15;
55 const int MAX_PERCENT_COUNT = 100;
56 const int MIN_PERCENT_COUNT = 0;
57 const int PROGRESS_TIMER_DURATION = 1000;
58 const int DEFAULT_VOLUME_LEVEL = 50;
59 const int DEFAULT_SAMPLE_RATE = 44100;
60 const int DEFAULT_BIT_RATE = 64000;
61 const int WAIT_FOR_THREAD_EXIT = 150;
62 const int startPosion = 0;
63 const int DEFAULT_STACK_SIZE = 64 * 1024;
64 // Timer wait
65 const int DECODE_UPDATE_TIMEOUT = 50;
66 const int DATA_READ_THREAD_WAIT_PERIOD = 50;
67 const int MINIMUM_MP3_THRESHOLD_SIZE = 100;
68
69 };
70
71 class AudioDecoderForm
72         : public MultiForm
73         , public Osp::Ui::Controls::IFrameEventListener
74         , public Osp::Ui::IKeyEventListener
75         , public Osp::Base::Runtime::ITimerEventListener
76 {
77 public:
78         // Construction
79 public:
80         AudioDecoderForm(void);
81         virtual ~AudioDecoderForm(void);
82         bool Initialize(void);
83
84 public:
85         virtual result OnInitializing(void);
86         virtual result OnTerminating(void);
87         virtual result OnActivate(void* activateParam);
88         virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId);
89         void OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs);
90         void EditResultValue(Osp::Base::String& r);
91         result StartAudioDecoding();
92         void GetPathFromConfig(void);
93         void SetFooterText(void);
94         void EditFileName(int samplerate, int channeltype, int curPos, int finalPos);
95         void SetDefault(void);
96         MediaAppAudioDecoder::AudioCodecType GetCodecFromCodecStringName(Osp::Base::String codecName);
97         virtual void OnBackground(void);
98         virtual void OnForeground(void);
99         void OnFormBackRequested(Osp::Ui::Controls::Form& source);
100         void EnableSelectedSoftKey();
101         virtual void OnFrameTerminating(const Osp::Ui::Controls::Frame& source);
102         virtual void OnKeyPressed(const Control& source, Osp::Ui::KeyCode keyCode);
103         virtual void OnKeyReleased(const Control& source, Osp::Ui::KeyCode keyCode);
104         virtual void OnKeyLongPressed(const Control& source, Osp::Ui::KeyCode keyCode);
105         virtual void OnTimerExpired(Osp::Base::Runtime::Timer& timer);
106         void ShowError(result r, const char* pMethod, const char* pSrcfileName, int lineNo);
107         void ContinueAudioDecoding();
108
109 private:
110         enum PlayState
111         {
112                 PLAY_STATE_IDLE,
113                 PLAY_STATE_PLAYING,
114                 PLAY_STATE_PAUSE,
115                 PLAY_STATE_STOP,
116                 PLAY_STATE_ERROR
117         };
118         Osp::Ui::Controls::Progress* __pProgressBar;
119         Osp::Ui::Controls::EditArea* __pEditFileInformations;
120         Osp::Base::String __filename;
121         Osp::Base::String __filePath;
122         int __configFileCount;
123         Osp::Base::String __audioCodecString;
124         int __codeccount;
125         int __nextCount;
126         bool __stopDecodeTrigger;
127         bool __onBakgroundCalled;
128         volatile bool __appTerminating;
129         PlayState __curState;
130         MediaAppAudioDecoder::AudioCodecType __audioCodecType;
131         bool __dumpFlag;
132         bool __showErrorCalled;
133         Osp::Base::ByteBuffer* __pSrcBuf;
134         Osp::Base::ByteBuffer* __pDstBuf;
135         Osp::Media::AudioDecoder* __pDec;
136         int __maxBytes;
137         Osp::Io::File __destFile;
138         Osp::Base::Runtime::Timer __updateTimer;
139         bool __inErrorState;
140         Osp::Security::Crypto::Md5Hash* __pMD5; /*MD5 Changes*/
141         Osp::Base::ByteBuffer* __pMD5Result;
142         int __sampleRate;
143         int __channelCount;
144         Osp::Base::Collection::HashMapT< MediaAppAudioDecoder::AudioCodecType, CodecType > __codecMap;
145
146
147 };
148
149 #endif  //_AUDIO_DECODER_FORM_H_