Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / MediaApp / MediaApp / project / src / Codec / VideoEncoderForm.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 _VIDEO_ENCODER_FORM_H_
19 #define _VIDEO_ENCODER_FORM_H_
20
21 namespace MediaAppVideoEncoder
22 {
23 enum VideoCodecType
24 {
25         CODEC_TYPE_H263,
26         CODEC_TYPE_MP4,
27         CODEC_TYPE_CODEC_UNKNOWN
28 };
29
30 enum responseType
31 {
32         ENCODE_DONE,
33         ENCODE_FAIL,
34         ENCODE_CANCELLED,
35         ENCODE_CONTINUE
36 };
37
38 //cosnt values for buttons
39 const int PREV_INDEX = 0;
40 const int NEXT_INDEX = 1;
41 const int ID_BACK = 100;
42 const int ID_PREV = 101;
43 const int ID_NEXT = 102;
44 const int ID_ENCODE = 103;
45 const int ID_PLAY = 104;
46 //sufficient buffer size
47 const int SRC_BUF_SIZE = 1024 * 500;
48 const int DST_BUF_SIZE = 1024 * 500;
49 const int MAX_PERCENT_COUNT = 100;
50 const int MIN_PERCENT_COUNT = 0;
51 const int PROGRESS_TIMER_DURATION = 1000;
52 const int DEFAULT_VOLUME_LEVEL = 50;
53 const int WAIT_FOR_EVENT_PROCESSING = 20;
54 //Quant values
55 const int QUANT_MIN = 1;
56 const int QUANT_MAX = 31;
57
58 };
59
60 class VideoEncoderForm
61         : public MultiForm
62         , public Osp::Ui::IKeyEventListener
63         , public Osp::Base::Runtime::ITimerEventListener
64 {
65
66 public:
67         VideoEncoderForm(void);
68         virtual ~VideoEncoderForm(void);
69         bool Initialize(void);
70
71 public:
72         virtual result OnInitializing(void);
73         virtual result OnTerminating(void);
74         virtual result OnActivate(void* activateParam);
75         virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId);
76         void OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs);
77         void OnFormBackRequested(Osp::Ui::Controls::Form& source);
78         virtual void OnBackground(void);
79         virtual void OnForeground(void);
80         result StartVideoEncoding();
81         void GetPathFromConfFile(void);
82         void EditFileName(int height, int width, int curPos, int finalPos);
83         void SetDefault(void);
84         result DisplayFrame(bool showDisplay, Osp::Base::ByteBuffer* pBuffer = null);
85         void EditResultValue(Osp::Base::String& r);
86         MediaAppVideoEncoder::VideoCodecType GetCodecFromCodecStringName(Osp::Base::String codecName);
87         result FillBufferFromFile(Osp::Io::File* fp, Osp::Base::ByteBuffer* pBuffer);
88         void EnableSelectedSoftKey();
89         result ShowEmptyFrame();
90         virtual void OnKeyPressed(const Control& source, Osp::Ui::KeyCode keyCode);
91         virtual void OnKeyReleased(const Control& source, Osp::Ui::KeyCode keyCode);
92         virtual void OnKeyLongPressed(const Control& source, Osp::Ui::KeyCode keyCode);
93         virtual void OnTimerExpired(Osp::Base::Runtime::Timer& timer);
94         void ShowError(result r, const char* pMethod, const char* pSrcfileName, int lineNo);
95         int ContinueEncoding();
96 private:
97         enum PlayState
98         {
99                 STATE_IDLE,
100                 STATE_ENCODING,
101                 STATE_PAUSE,
102                 STATE_ERROR,
103                 STATE_STOP
104         };
105         Osp::Ui::Controls::Progress* __pProgressBar;
106         Osp::Ui::Controls::OverlayRegion* __pOverlayRegion;
107         Osp::Ui::Controls::EditArea* __pEditFileInformations;
108         Osp::Base::String __filename;
109         Osp::Base::String __codecTypeString;
110         Osp::Base::String __filePath;
111         int __configFileCount;
112         int __codeccount;
113         int __frameWidth;
114         int __frameHeight;
115         int __maxBytes;
116
117         Osp::Base::ByteBuffer* __pSrcBuf;
118         Osp::Base::ByteBuffer* __pDstBuf;
119         int __consumedByte;
120         bool __stopEncodeTrigger;
121         bool __showDisplay;
122         bool __onBakgroundCalled;
123         bool __inErrorState;
124         bool __showErrorCalled;
125         PlayState __curState;
126         MediaAppVideoEncoder::VideoCodecType __codecType;
127         bool __dumpFlag;
128         bool __appTerminating;
129         Osp::Media::VideoEncoder* __pEnc;
130         Osp::Io::File __outputFile;
131         Osp::Io::File* __pSrcFile;
132         Osp::Base::Runtime::Timer __wakeUpTimer;
133
134         // Encoding Option Parameters
135         int __frameRate;
136         int __bitRate;
137         int __width;
138         int __height;
139         int __gopSize;
140         int __quantLevel;
141         int __sliceSize;
142         int __quantMin;
143         int __quantMax;
144         int __useFrameSkip;
145
146 };
147
148
149 #endif  //_VIDEO_ENCODER_FORM_H_