Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / MediaApp / MediaApp / project / src / Recorder / VideoRecorderForm.cpp
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 #include <FApp.h>
19 #include <FBase.h>
20 #include "AppConfig.h"
21 #include "UnitTestFactory.h"
22 #include "VideoRecorderForm.h"
23 #include "MediaPlayerForm.h"
24
25 using namespace Osp::Base;
26 using namespace Osp::Base::Collection;
27 using namespace Osp::Graphics;
28 using namespace Osp::Ui;
29 using namespace Osp::Ui::Controls;
30 using namespace Osp::Io;
31 using namespace Osp::App;
32 using namespace Osp::System;
33
34
35 #define INIT                    -1
36 #define SECTION_NAME            L"VideoRecorder"
37 #define _TIMER_VALUE_           500
38 #define DEFAULT_MAXTIME         60      //Sec
39 #define DEFAULT_MAXSIZE         5000    //KB
40 #define METHOD_FILE_LINENO      __FUNCTION__, __FILE__, (__LINE__ - 3)
41 #define TEN                     10
42 #define KILOBYTE                1000
43 #define SIXTY_SECS              60
44
45 //Supported codec pop up
46 #define SUPPORTED_CODEC_POPUP_WIDTH 470
47 #define SUPPORTED_CODEC_POPUP_HEIGHT 480
48
49 #define SUPPORTED_CODEC_POPUP_BUTTON_X 150
50 #define SUPPORTED_CODEC_POPUP_BUTTON_Y 336
51 #define SUPPORTED_CODEC_POPUP_BUTTON_W 100
52 #define SUPPORTED_CODEC_POPUP_BUTTON_H 60
53
54 #define SUPPORTED_CODEC_POPUP_LABEL_X 0
55 #define SUPPORTED_CODEC_POPUP_LABEL_Y 0
56 #define SUPPORTED_CODEC_POPUP_LABEL_W 440
57 #define SUPPORTED_CODEC_POPUP_LABEL_H 300
58 #define SUPPORTED_CODEC_POPUP_LABEL_TEXT_FONT 30
59
60 /*Setting Pop coordinates*/
61 #define VR_FORM_POPUP_W 400
62 #define VR_FORM_POPUP_H 400
63 #define VR_FORM_OK_BUTTON_X 120
64 #define VR_FORM_OK_BUTTON_Y 270
65 #define VR_FORM_OK_BUTTON_W 120
66 #define VR_FORM_OK_BUTTON_H 60
67
68 #define VR_FORM_POPUP_SLIDER_W      VR_FORM_POPUP_W
69 #define VR_FORM_POPUP_SLIDER_H      340
70 #define VR_FORM_SLIDER_X            0
71 #define VR_FORM_SLIDER_Y            30
72 #define VR_FORM_SLIDER_W            (VR_FORM_POPUP_SLIDER_W - 30)
73 #define VR_FORM_SLIDER_H            150
74
75
76 #define VR_FORM_SLIDER_OK_BUTTON_X 140
77 #define VR_FORM_SLIDER_OK_BUTTON_Y 200
78 #define VR_FORM_SLIDER_OK_BUTTON_W 120
79 #define VR_FORM_SLIDER_OK_BUTTON_H 60
80 #define VR_FORM_LISTVIEW_H  250
81 #define MIN_THREAD_SLEEP_TIME 200
82
83 MULTI_FORM_REGISTER(VideoRecorderForm, L"VideoRecorderForm");
84
85 static result
86 RecorderFormFunc(void* param)
87 {
88         MultiForm::ActivateForm(L"VideoRecorderForm", 0, MultiForm::GetCurrentForm(), null);
89         return E_SUCCESS;
90 }
91
92 static UnitTestInfo tc01(L"Recorder", L"2.Video Recorder", (TestCaseFunc) RecorderFormFunc, 0);
93
94 typedef struct
95 {
96         Osp::Media::MediaContainerType container;
97         Osp::Media::CodecType audioCodec;
98         Osp::Media::CodecType videoCodec;
99 }VideoCodecContainerT;
100
101 const static VideoCodecContainerT supportedCodecContainerT[] =
102 {
103         {MEDIA_CONTAINER_3GP, CODEC_AMR_NB, CODEC_MPEG4},
104         {MEDIA_CONTAINER_3GP, CODEC_AAC, CODEC_MPEG4},
105         {MEDIA_CONTAINER_3GP, CODEC_AMR_NB, CODEC_H263},
106         {MEDIA_CONTAINER_MP4, CODEC_AAC, CODEC_MPEG4},
107 };
108
109 VideoRecorderForm::VideoRecorderForm(void)
110         : __pCamera(null)
111         , __pVideoRecorder(null)
112         , __pOverlay(null)
113         , __pPopupMessage(null)
114         , __pPopupEffect(null)
115         , __pPopupIso(null)
116         , __pPopupWhiteBalance(null)
117         , __pPopupFrameRate(null)
118         , __pPopupRecordingResolution(null)
119         , __pPopupRecordingQuality(null)
120         , __pPopupVideoCodec(null)
121         , __pPopupAudioCodec(null)
122         , __pPopupFileFormat(null)
123         , __pPopupSetting(null)
124         , __pPopupExposure(null)
125         , __pPopupBrightness(null)
126         , __pPopupContrast(null)
127         , __pPopupZoom(null)
128         , __pPopupFlip(null)
129         , __pListViewEffect(null)
130         , __pListViewIso(null)
131         , __pListViewWhitebalance(null)
132         , __pListViewFrameRate(null)
133         , __pListViewQuality(null)
134         , __pListViewSetting(null)
135         , __pListViewRecordingResolution(null)
136         , __pListViewVideoCodec(null)
137         , __pListViewAudioCodec(null)
138         , __pListViewFileFormat(null)
139         , __pListViewFlipType(null)
140         , __pButnEffectOK(null)
141         , __pButnIsoOK(null)
142         , __pButnWhitebalanceOK(null)
143         , __pButnFrameRateOK(null)
144         , __pButnRecordingResolutionOK(null)
145         , __pButnQualityOK(null)
146         , __pButnVideoCodecOK(null)
147         , __pButnAudioCodecOK(null)
148         , __pButnFileFormatOK(null)
149         , __pButnSettingOK(null)
150         , __pButnExposureOK(null)
151         , __pButnBrightnessOK(null)
152         , __pButnContrastOK(null)
153         , __pButnZoomOK(null)
154         , __pButnFlipTypeOK(null)
155         , __pPreviewFrameRateList(null)
156         , __pRecordingResolutionList(null)
157         , __pRecorderVideoCodecList(null)
158         , __pRecorderAudioCodecList(null)
159         , __pRecorderVideoContainerList(null)
160         , __pBrightnessSlider(null)
161         , __pContrastSlider(null)
162         , __pExposureSlider(null)
163         , __pZoomLevelSlider(null)
164         , __pConfig(null)
165         , __pProgress(null)
166         , __pTimer(null)
167         , __pSupportedCodecPopup(null)
168         , __pSupportedCodecPopupLable(null)
169         , __pSupportedCodecPopupBtn(null)
170         , __pElapsedTimeLable(null)
171         , __pElapsedRecordSizeLable(null)
172         , __pMegaByte(null)
173 {
174         __brightness = -1;
175         __exposure = -1;
176         __contrast = -1;
177         __effect = -1;
178         __isoLevel = -1;
179         __whiteBalance = -1;
180         __zoomLevel = -1;
181         __frameRateIndex = -1;
182         __frameRateIndexSec = -1;
183         __resolutionIndex = -1;
184         __resolutionIndexSec = -1;
185         __qualityIndex = -1;
186         __videoCodecIndex = -1;
187         __audioCodecIndex = -1;
188         __formatIndex = -1;
189         __backGround = false;
190         __currentListViewId = -1;
191         __camType = CAMERA_PRIMARY;
192         __flipType = CAMERA_FLIP_NONE;
193         __orientationStatus = ORIENTATION_STATUS_PORTRAIT;
194         __previewByCallback = 1;
195         __cameraCount = 1;
196         __batteryLevelFlag = false;
197         __rotateFlagSet = false;
198         __pSettingItemArrayList = null;
199         __pEffectList = null;
200         __pIsoList = null;
201         __pWbList = null;
202         __wbIndex = INIT;
203         __isoIndex = INIT;
204         __effectIndex = INIT;
205         __cameraError = false;
206         __brightnessSliderValue = 0;
207         __contrastSliderValue = 0;
208         __exposureSliderValue = 0;
209 }
210
211 VideoRecorderForm::~VideoRecorderForm(void)
212 {
213         SAFE_DELETE(__pOverlay);
214         DeletePopup(&__pPopupMessage);
215         DeletePopup(&__pPopupEffect);
216         DeletePopup(&__pPopupIso);
217         DeletePopup(&__pPopupWhiteBalance);
218         DeletePopup(&__pPopupFrameRate);
219         DeletePopup(&__pPopupRecordingResolution);
220         DeletePopup(&__pPopupRecordingQuality);
221         DeletePopup(&__pPopupVideoCodec);
222         DeletePopup(&__pPopupAudioCodec);
223         DeletePopup(&__pPopupFileFormat);
224         DeletePopup(&__pPopupSetting);
225         DeletePopup(&__pPopupExposure);
226         DeletePopup(&__pPopupBrightness);
227         DeletePopup(&__pPopupContrast);
228         DeletePopup(&__pPopupZoom);
229         FreeResources();
230
231         if (__pTimer)
232         {
233                 __pTimer->Cancel();
234                 SAFE_DELETE(__pTimer);
235         }
236         AppLog("VideoRecorderForm::~VideoRecorderForm");
237 }
238
239 bool
240 VideoRecorderForm::Initialize()
241 {
242         result r = E_SUCCESS;
243         r = Construct(L"IDF_VIDEO_RECORDER");
244         AppLog("Initialize return = %s", GetErrorMessage(r));
245         return true;
246 }
247
248 result
249 VideoRecorderForm::OnInitializing(void)
250 {
251         result r = E_SUCCESS;
252         Footer* pFooter = GetFooter();
253         Header* pHeader = GetHeader();
254         Rectangle rect = GetClientAreaBounds();
255         Rectangle clientRect = GetClientAreaBounds();
256         String recSize;
257
258         SetHeaderText("Video Recorder");
259         SetFooterStyle(FOOTER_STYLE_BUTTON_TEXT, ID_BACK, this);
260         AddFooterItem(L"Settings", ID_SETTING);
261         AddFooterItem(L"Primary", ID_TOGGLE_CAMERA_TYPE);
262         AddFooterItem(L"Start", ID_START);
263
264         __startTime = L"";
265         __startTime.Append(L"00");
266         __startTime.Append(L"");
267         __startTime.Append(L":");
268         __startTime.Append(L"00");
269         __startTime.Append(L"");
270         __startTime.Append(L":");
271         __startTime.Append(L"00");
272
273         __startSize = L"";
274         __startSize.Append(L"00");
275
276         recSize.Clear();
277         recSize.Append(__startSize);
278         recSize.Append(L" ");
279         recSize.Append(L"MB");
280
281         HideAndGetBounds(GetControl(L"IDC_BUTTON1"), rect);
282         AppLog("Original rect (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
283
284         __pProgress = static_cast< Progress* >(GetControl(L"IDC_PROGRESS1"));
285         if (__pProgress == null)
286         {
287                 goto FAIL;
288         }
289
290         clientRect = __pProgress->GetBounds();
291         AppLog("PROGRESS BOUNDS %d %d %d %d", clientRect.x, clientRect.y, clientRect.width, clientRect.height);
292
293         __pElapsedTimeLable = static_cast< Label* >(GetControl(L"IDC_ELAPSEDTIME"));
294         if (__pElapsedTimeLable == null)
295         {
296                 AppLog("__pElapsedTimeLable handle from UI builder is NULL");
297                 goto FAIL;
298         }
299         __pElapsedRecordSizeLable = static_cast< Label* >(GetControl(L"IDC_ELAPSEDSIZE"));
300         if (__pElapsedRecordSizeLable == null)
301         {
302                 AppLog("__pElapsedRecordSizeLable handle from UI builder is NULL");
303                 goto FAIL;
304         }
305
306         __pElapsedTimeLable->SetText(__startTime);
307         __pElapsedRecordSizeLable->SetText(__startSize);
308
309         __pElapsedTimeLable->RequestRedraw();
310         __pElapsedRecordSizeLable->RequestRedraw();
311
312         __pProgress->SetValue(0);
313         __pProgress->Draw();
314
315         __pTimer = new (std::nothrow) Osp::Base::Runtime::Timer;
316         if (__pTimer == null)
317         {
318                 r = E_FAILURE;
319                 goto FAIL;
320         }
321
322         r = __pTimer->Construct(*this);
323         if (IsFailed(r))
324         {
325                 r = E_FAILURE;
326                 goto FAIL;
327         }
328
329         AddTouchEventListener(*this);
330         pFooter->AddTouchEventListener(*this);
331         pHeader->AddTouchEventListener(*this);
332         __pConfig = AppConfig::GetInstance();
333         if (__pConfig == null)
334         {
335                 ShowError(E_FAILURE, METHOD_FILE_LINENO);
336                 goto FAIL;
337         }
338
339         AddKeyEventListener(*this);
340         return r;
341 FAIL:
342         SAFE_DELETE(__pTimer);
343         return r;
344 }
345
346 void
347 VideoRecorderForm::ShowError(result r, const char* pMethod, const char* pSrcfileName, int lineNo)
348 {
349         AppLog("method %s file name %s  line no. %d", pMethod, pSrcfileName, lineNo);
350         ShowErrorMessagePopup(SECTION_NAME, L"VideoRecorderForm", pMethod, r, pSrcfileName, lineNo, GetErrorMessage(r));
351 }
352
353 void
354 VideoRecorderForm::DeletePopup(Popup** pPopup)
355 {
356         if (pPopup != null && *pPopup != null)
357         {
358                 (*pPopup)->RemoveAllControls();
359                 delete (*pPopup);
360                 *pPopup = null;
361         }
362 }
363
364 result
365 VideoRecorderForm::CreatePopUp(Popup** pPopupCtrl, String title, Dimension dimension, bool hasTitle)
366 {
367         result r = E_SUCCESS;
368         Popup* pCtrl = new (std::nothrow) Popup();
369         if (pCtrl == null)
370         {
371                 r = E_FAILURE;
372                 goto FAIL;
373         }
374         *pPopupCtrl = pCtrl;
375         r = pCtrl->Construct(hasTitle, dimension);
376         if (IsFailed(r))
377         {
378                 ShowError(r, METHOD_FILE_LINENO);
379                 goto FAIL;
380         }
381
382         if (hasTitle)
383         {
384                 r = pCtrl->SetTitleText(String(title));
385                 if (IsFailed(r))
386                 {
387                         ShowError(r, METHOD_FILE_LINENO);
388                         goto FAIL;
389                 }
390         }
391         return r;
392 FAIL:
393         return r;
394
395 }
396
397 result
398 VideoRecorderForm::AddButton(Button** pButtonCtrl, String text, int actionId, Popup* pPopup, Rectangle dimension)
399 {
400         result r = E_SUCCESS;
401         Button* pCtrl = new (std::nothrow) Button();
402         if (pCtrl == null)
403         {
404                 r = E_FAILURE;
405                 goto FAIL;
406         }
407
408         r = pCtrl->Construct(dimension, text);
409         if (IsFailed(r))
410         {
411                 ShowError(r, METHOD_FILE_LINENO);
412                 SAFE_DELETE(pCtrl);
413                 goto FAIL;
414         }
415         pCtrl->SetActionId(actionId);
416         pCtrl->AddActionEventListener(*this);
417         r = pPopup->AddControl(*pCtrl);
418         if (IsFailed(r))
419         {
420                 ShowError(r, METHOD_FILE_LINENO);
421                 SAFE_DELETE(pCtrl);
422                 goto FAIL;
423         }
424         *pButtonCtrl = pCtrl;
425         return r;
426 FAIL:
427         return r;
428 }
429
430 void
431 VideoRecorderForm::ClearSupportedCodecPopup()
432 {
433         if (__pSupportedCodecPopup)
434         {
435                 __pSupportedCodecPopup->RemoveAllControls();
436                 __pSupportedCodecPopup->SetShowState(false);
437                 SAFE_DELETE(__pSupportedCodecPopup);
438         }
439 }
440
441 void
442 VideoRecorderForm::GetSupportedVideoRecordingList(String* pVideoFileFormat, String* pVideoCodecType, ArrayList* pAudioCodecList)
443 {
444         int tableCount = 0;
445         tableCount = sizeof(supportedCodecContainerT) / sizeof(supportedCodecContainerT[0]);
446
447         String tempVideoContainer;
448         String tempVideoCodec;
449         String* pTempAudioCodec = null;
450         Osp::Media::MediaContainerType* pVideoContainer = null;
451         Osp::Media::CodecType* pAudioCodec = null;
452         Osp::Media::CodecType* pVideoCodec = null;
453
454         for (int i = 0; i < tableCount; i++)
455         {
456                 pTempAudioCodec = null;
457
458                 //pTempAudioCodec string is deleted when ArrayList is deleted
459                 pTempAudioCodec = new (std::nothrow) String;
460                 if (pTempAudioCodec == null)
461                 {
462                         AppLog("pTempAudioCodec failed, no memory");
463                         goto FAIL;
464                 }
465                 pTempAudioCodec->Clear();
466
467                 pVideoContainer = new (std::nothrow) MediaContainerType;
468                 if (pVideoContainer == null)
469                 {
470                         AppLog("pVideoContainer failed, no memory");
471                         goto FAIL;
472                 }
473                 *pVideoContainer = supportedCodecContainerT[i].container;
474
475                 pVideoCodec = new (std::nothrow) CodecType;
476                 if (pVideoCodec == null)
477                 {
478                         AppLog("pVideoCodec failed, no memory");
479                         goto FAIL;
480                 }
481                 *pVideoCodec = supportedCodecContainerT[i].videoCodec;
482
483                 pAudioCodec = new (std::nothrow) CodecType;
484                 if (pAudioCodec == null)
485                 {
486                         AppLog("pAudioCodec failed, no memory");
487                         goto FAIL;
488                 }
489                 *pAudioCodec = supportedCodecContainerT[i].audioCodec;
490
491                 ConvertContainerToRawString(*pVideoContainer, tempVideoContainer);
492                 AppLog("ConvertContainerToRawString container is %ls", tempVideoContainer.GetPointer());
493
494                 ConvertCodecToString(*pVideoCodec, tempVideoCodec);
495                 AppLog("ConvertCodecToString video codec is %ls", tempVideoCodec.GetPointer());
496
497                 if ((String::Compare(tempVideoContainer, *pVideoFileFormat) == 0) &&
498                         (String::Compare(tempVideoCodec, *pVideoCodecType) == 0))
499                 {
500                         ConvertCodecToString(*pAudioCodec, *pTempAudioCodec);
501                         AppLog("ConvertCodecToString pTempAudioCodec is %ls", pTempAudioCodec->GetPointer());
502                         pAudioCodecList->Add(*pTempAudioCodec);
503                 }
504
505                 SAFE_DELETE(pVideoContainer);
506                 SAFE_DELETE(pAudioCodec);
507                 SAFE_DELETE(pVideoCodec);
508         }
509
510         return;
511 FAIL:
512         SAFE_DELETE(pTempAudioCodec);
513         SAFE_DELETE(pVideoContainer);
514         SAFE_DELETE(pAudioCodec);
515         SAFE_DELETE(pVideoCodec);
516 }
517
518 void
519 VideoRecorderForm::GetVideoCodecSelected(String* pVideoCodec)
520 {
521         if (__pRecorderVideoCodecList && (__pRecorderVideoCodecList->GetCount() > 0))
522         {
523                 CodecType* pCodec = null;
524                 bool flag = true;
525
526                 pCodec = new (std::nothrow) CodecType;
527                 if (pCodec == null)
528                 {
529                         AppLog("pCodec failed, no memory");
530                         pVideoCodec->Clear();
531                         pVideoCodec->Append("NULL");
532                         return;
533                 }
534
535                 __pRecorderVideoCodecList->GetAt(__videoCodecIndex, *pCodec);
536                 if (pCodec == null)
537                 {
538                         AppLog("__pRecorderVideoCodecList get at index %d is wrong", __videoCodecIndex);
539                         pVideoCodec->Clear();
540                         pVideoCodec->Append("NULL");
541                         SAFE_DELETE(pCodec);
542                         return;
543                 }
544
545                 flag = ConvertCodecToString(*pCodec, *pVideoCodec);
546                 if (flag == false)
547                 {
548                         AppLog("ConvertCodecToString returned error");
549                 }
550
551                 SAFE_DELETE(pCodec);
552         }
553 }
554
555 void
556 VideoRecorderForm::GetVideoFileFormatSelected(String* pVideoFileFormat)
557 {
558         if (__pRecorderVideoContainerList && (__pRecorderVideoContainerList->GetCount() > 0))
559         {
560                 MediaContainerType* pFileType = null;
561                 bool flag = true;
562
563                 pFileType = new (std::nothrow) MediaContainerType;
564                 __pRecorderVideoContainerList->GetAt(__formatIndex, *pFileType);
565                 if (pFileType == null)
566                 {
567                         AppLog("__pCodecTypeList get at index %d is wrong", __formatIndex);
568                         pVideoFileFormat->Clear();
569                         pVideoFileFormat->Append("NULL");
570                         SAFE_DELETE(pFileType);
571                         return;
572                 }
573
574                 flag = ConvertContainerToRawString(*pFileType, *pVideoFileFormat);
575                 if (flag == false)
576                 {
577                         AppLog("ConvertContainerToRawString returned error");
578                 }
579
580                 SAFE_DELETE(pFileType);
581         }
582 }
583
584 void
585 VideoRecorderForm::ShowSupportedCodecListPopUp()
586 {
587         String message;
588         String videoFileFormatSelected;
589         String videoCodecSelected;
590         ArrayList* pAudioCodecList = null;
591         result r = E_SUCCESS;
592
593         AppLog("VideoRecorderForm::ShowSupportedCodecListPopUp\n");
594
595         pAudioCodecList = new (std::nothrow) ArrayList;
596         if (pAudioCodecList == null)
597         {
598                 AppLog("pAudioCodecList created failed");
599                 return;
600         }
601         __pSupportedCodecPopup = new (std::nothrow) Popup;
602         if (__pSupportedCodecPopup == null)
603         {
604                 AppLog("__pSupportedCodecPopup creation failed");
605                 goto FAIL;
606         }
607         __pSupportedCodecPopup->Construct(true, Dimension(SUPPORTED_CODEC_POPUP_WIDTH, SUPPORTED_CODEC_POPUP_HEIGHT));
608         __pSupportedCodecPopup->SetTitleText(L"Supported Recording Options");
609
610         __pSupportedCodecPopupLable = new (std::nothrow) Label;
611         if (__pSupportedCodecPopupLable == null)
612         {
613                 AppLog("__pSupportedCodecPopupLable creation failed");
614                 goto FAIL;
615         }
616         __pSupportedCodecPopupLable->Construct(Rectangle(SUPPORTED_CODEC_POPUP_LABEL_X,
617                                                                                                          SUPPORTED_CODEC_POPUP_LABEL_Y,
618                                                                                                          SUPPORTED_CODEC_POPUP_LABEL_W,
619                                                                                                          SUPPORTED_CODEC_POPUP_LABEL_H), L"");
620         __pSupportedCodecPopup->AddControl(*__pSupportedCodecPopupLable);
621
622         __pSupportedCodecPopupBtn = new (std::nothrow) Button;
623         if (__pSupportedCodecPopupBtn == null)
624         {
625                 AppLog("__pSupportedCodecPopupBtn creation failed");
626                 goto FAIL;
627         }
628         __pSupportedCodecPopupBtn->Construct(Rectangle(SUPPORTED_CODEC_POPUP_BUTTON_X,
629                                                                                                    SUPPORTED_CODEC_POPUP_BUTTON_Y,
630                                                                                                    SUPPORTED_CODEC_POPUP_BUTTON_W,
631                                                                                                    SUPPORTED_CODEC_POPUP_BUTTON_H),
632                                                                                  L"Ok");
633         __pSupportedCodecPopupBtn->SetActionId(ID_BUTTON_SUPPORTED_CODEC_POPUP_OK);
634         __pSupportedCodecPopupBtn->AddActionEventListener(*this);
635
636         __pSupportedCodecPopup->AddControl(*__pSupportedCodecPopupBtn);
637
638         __pSupportedCodecPopup->SetShowState(true);
639
640         GetVideoFileFormatSelected(&videoFileFormatSelected);
641         //Check if we were able to retrieve it
642         if (String::Compare(videoFileFormatSelected, String(L"NULL")) == 0)
643         {
644                 AppLog("videoFileFormatSelected is NULL");
645                 goto FAIL;
646         }
647
648         GetVideoCodecSelected(&videoCodecSelected);
649         //Check if we were able to retrieve it
650         if (String::Compare(videoCodecSelected, String(L"NULL")) == 0)
651         {
652                 AppLog("videoCodecSelected is NULL");
653                 goto FAIL;
654         }
655
656         GetSupportedVideoRecordingList(&videoFileFormatSelected, &videoCodecSelected, pAudioCodecList);
657
658         //Convert to simple for display
659         if (String::Compare(videoFileFormatSelected, String(L"MEDIA_CONTAINER_3GP")) == 0)
660         {
661                 videoFileFormatSelected.Clear();
662                 videoFileFormatSelected.Append(L"3GP");
663         }
664         else if (String::Compare(videoFileFormatSelected, String(L"MEDIA_CONTAINER_MP4")) == 0)
665         {
666                 videoFileFormatSelected.Clear();
667                 videoFileFormatSelected.Append(L"MP4");
668         }
669         else
670         {
671                 goto FAIL;
672         }
673
674         if (pAudioCodecList->GetCount() == 0)
675         {
676                 message.Clear();
677                 message.Append("File");
678                 message.Append("\t");
679                 message.Append("\t");
680                 message.Append("\t");
681                 message.Append("\t");
682                 message.Append("\t");
683                 message.Append("\t");
684                 message.Append("\t");
685                 message.Append("\t");
686                 message.Append("Video");
687                 message.Append("\t");
688                 message.Append("\t");
689                 message.Append("\t");
690                 message.Append("\t");
691                 message.Append("\t");
692                 message.Append("\t");
693                 message.Append("Audio");
694                 message.Append("\n");
695
696                 message.Append("Format");
697                 message.Append("\t");
698                 message.Append("\t");
699                 message.Append("\t");
700                 message.Append("\t");
701                 message.Append("Codec");
702                 message.Append("\t");
703                 message.Append("\t");
704                 message.Append("\t");
705                 message.Append("\t");
706                 message.Append("Codec");
707                 message.Append("\n");
708                 message.Append("\n");
709
710                 message.Append("3GP");
711                 message.Append("\t");
712                 message.Append("\t");
713                 message.Append("\t");
714                 message.Append("\t");
715                 message.Append("\t");
716                 message.Append("\t");
717                 message.Append("\t");
718                 message.Append("MPEG4");
719                 message.Append("\t");
720                 message.Append("\t");
721                 message.Append("\t");
722                 message.Append("\t");
723                 message.Append("\t");
724                 message.Append("\t");
725                 message.Append("\t");
726                 message.Append("AMR");
727                 message.Append("\n");
728
729                 message.Append("3GP");
730                 message.Append("\t");
731                 message.Append("\t");
732                 message.Append("\t");
733                 message.Append("\t");
734                 message.Append("\t");
735                 message.Append("\t");
736                 message.Append("\t");
737                 message.Append("MPEG4");
738                 message.Append("\t");
739                 message.Append("\t");
740                 message.Append("\t");
741                 message.Append("\t");
742                 message.Append("\t");
743                 message.Append("\t");
744                 message.Append("AAC");
745                 message.Append("\n");
746
747                 message.Append("3GP");
748                 message.Append("\t");
749                 message.Append("\t");
750                 message.Append("\t");
751                 message.Append("\t");
752                 message.Append("\t");
753                 message.Append("\t");
754                 message.Append("\t");
755                 message.Append("H263");
756                 message.Append("\t");
757                 message.Append("\t");
758                 message.Append("\t");
759                 message.Append("\t");
760                 message.Append("\t");
761                 message.Append("\t");
762                 message.Append("\t");
763                 message.Append("\t");
764                 message.Append("\t");
765                 message.Append("\t");
766                 message.Append("AMR");
767                 message.Append("\n");
768
769                 message.Append("MP4");
770                 message.Append("\t");
771                 message.Append("\t");
772                 message.Append("\t");
773                 message.Append("\t");
774                 message.Append("\t");
775                 message.Append("\t");
776                 message.Append("\t");
777                 message.Append("MPEG4");
778                 message.Append("\t");
779                 message.Append("\t");
780                 message.Append("\t");
781                 message.Append("\t");
782                 message.Append("\t");
783                 message.Append("\t");
784                 message.Append("\t");
785                 message.Append("AAC");
786                 message.Append("\n");
787         }
788         else
789         {
790                 message.Append(L"Selected Video Format is ");
791                 message.Append('\n');
792                 message.Append(videoFileFormatSelected.GetPointer());
793                 message.Append('\n');
794                 message.Append(L"Selected Video Codec is ");
795                 message.Append('\n');
796                 message.Append(videoCodecSelected.GetPointer());
797                 message.Append('\n');
798                 message.Append('\n');
799                 message.Append("Possible Audio Codec options");
800                 message.Append('\n');
801                 message.Append((static_cast< String* >(pAudioCodecList->GetAt(0)))->GetPointer());
802         }
803
804         __pSupportedCodecPopupLable->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
805         __pSupportedCodecPopupLable->SetTextConfig(SUPPORTED_CODEC_POPUP_LABEL_TEXT_FONT, LABEL_TEXT_STYLE_NORMAL);
806         __pSupportedCodecPopupLable->SetText(message);
807         __pSupportedCodecPopupLable->RequestRedraw();
808
809         r = __pSupportedCodecPopup->Show();
810         AppLog("__pSupportedCodecPopup Show: %s\n", GetErrorMessage(r));
811
812         if (pAudioCodecList->GetCount())
813         {
814                 pAudioCodecList->RemoveAll(true);
815         }
816
817         SAFE_DELETE(pAudioCodecList);
818         return;
819
820 FAIL:
821         SAFE_DELETE(pAudioCodecList);
822         if (__pSupportedCodecPopup)
823         {
824                 __pSupportedCodecPopup->RemoveAllControls();
825                 __pSupportedCodecPopup->SetShowState(false);
826                 SAFE_DELETE(__pSupportedCodecPopup);
827         }
828 }
829
830
831 result
832 VideoRecorderForm::ShowPopUp(Popup* pPopUp)
833 {
834         result r = E_SUCCESS;
835         if (pPopUp == null)
836         {
837                 r = E_FAILURE;
838                 goto FAIL;
839         }
840         r = pPopUp->SetShowState(true);
841         if (IsFailed(r))
842         {
843                 ShowError(r, METHOD_FILE_LINENO);
844                 goto FAIL;
845         }
846         r = pPopUp->Show();
847         if (IsFailed(r))
848         {
849                 ShowError(r, METHOD_FILE_LINENO);
850                 goto FAIL;
851         }
852         return r;
853 FAIL:
854         return r;
855 }
856
857
858 void
859 VideoRecorderForm::HidePopUp(Popup* pPopUp)
860 {
861         if (pPopUp == null)
862         {
863                 return;
864         }
865         pPopUp->SetShowState(false);
866         Draw();
867         return;
868 }
869
870 result
871 VideoRecorderForm::AddListView(ListView** pListView, Popup* pPopup, int id)
872 {
873         result r = E_SUCCESS;
874         Rectangle popupRect = pPopup->GetClientAreaBounds();
875         ListView* pCtrl = new (std::nothrow) ListView();
876         if (pCtrl == null && (popupRect.width > 0 && popupRect.height > 0))
877         {
878                 r = E_FAILURE;
879                 goto FAIL;
880         }
881         //If listview height is lesser than popup area, use that height
882         if (popupRect.height > VR_FORM_LISTVIEW_H)
883         {
884                 popupRect.height = VR_FORM_LISTVIEW_H;
885         }
886
887         r = pCtrl->Construct(Rectangle(0, 0, popupRect.width, popupRect.height), true, false);
888         if (IsFailed(r))
889         {
890                 ShowError(r, METHOD_FILE_LINENO);
891                 SAFE_DELETE(pCtrl);
892                 goto FAIL;
893         }
894         SetCurrentListViewType(id);
895         pCtrl->SetItemProvider(*this);
896         pCtrl->AddListViewItemEventListener(*this);
897         r = pPopup->AddControl(*pCtrl);
898         if (IsFailed(r))
899         {
900                 ShowError(r, METHOD_FILE_LINENO);
901                 SAFE_DELETE(pCtrl);
902                 goto FAIL;
903         }
904         *pListView = pCtrl;
905         return r;
906 FAIL:
907         return r;
908 }
909
910
911 result
912 VideoRecorderForm::AddSlider(Slider** pSliderCtrl, int minval, int maxval, String title, Popup* pPopup)
913 {
914         result r = E_SUCCESS;
915         Slider* pCtrl = new (std::nothrow) Slider();
916         if (pCtrl == null)
917         {
918                 r = E_FAILURE;
919                 goto FAIL;
920         }
921
922         r = pCtrl->Construct(Rectangle(VR_FORM_SLIDER_X, VR_FORM_SLIDER_Y, VR_FORM_SLIDER_W, VR_FORM_SLIDER_H), BACKGROUND_STYLE_DEFAULT, true, minval, maxval);
923         if (IsFailed(r))
924         {
925                 ShowError(r, METHOD_FILE_LINENO);
926                 goto FAIL;
927         }
928
929         pCtrl->AddAdjustmentEventListener(*this);
930         r = pPopup->AddControl(*pCtrl);
931         if (IsFailed(r))
932         {
933                 ShowError(r, METHOD_FILE_LINENO);
934                 goto FAIL;
935         }
936         *pSliderCtrl = pCtrl;
937         return r;
938 FAIL:
939         return r;
940 }
941
942 void
943 VideoRecorderForm::SetCurrentListViewType(int id)
944 {
945         AppLog("Enter value = %d", id);
946         __currentListViewId = id;
947 }
948
949 int
950 VideoRecorderForm::GetItemCount(void)
951 {
952         AppLog("Enter here ");
953         switch (__currentListViewId)
954         {
955         case ID_BUTTON_SETTING_OK:
956         case ID_BUTTON_EFFECT_OK:
957         case ID_BUTTON_ISO_OK:
958         case ID_BUTTON_WHITEBALANCE_OK:
959         case ID_BUTTON_QUALITY_OK:
960         case ID_BUTTON_FRAMERATE_OK:
961         case ID_BUTTON_RECORDINGRESOLUTION_OK:
962         case ID_BUTTON_VIDEOCODEC_OK:
963         case ID_BUTTON_AUDIOCODEC_OK:
964         case ID_BUTTON_FILEFORMAT_OK:
965         case ID_BUTTON_FLIP_OK:
966         {
967                 if (__pSettingItemArrayList)
968                 {
969                         int count = __pSettingItemArrayList->GetCount();
970                         AppLog("count = %d ", count);
971                         return count;
972                 }
973                 else
974                 {
975                         return 0;
976                 }
977         }
978         break;
979
980         default:
981                 return 0;
982         }
983         return INIT;
984 }
985
986 void
987 VideoRecorderForm::OnListViewItemSwept(Osp::Ui::Controls::ListView& listView, int index, Osp::Ui::Controls::SweepDirection direction)
988 {
989         AppLog("Enter here");
990 }
991 void
992 VideoRecorderForm::OnListViewContextItemStateChanged(Osp::Ui::Controls::ListView& listView, int index, int elementId, Osp::Ui::Controls::ListContextItemStatus state)
993 {
994         AppLog("Enter here");
995 }
996
997 Osp::Ui::Controls::ListItemBase*
998 VideoRecorderForm::CreateItem(int index, int itemWidth)
999 {
1000         result r = E_SUCCESS;
1001         AppLog("Enter here index = %d", index);
1002         ListAnnexStyle style = (__currentListViewId != ID_BUTTON_SETTING_OK) ? LIST_ANNEX_STYLE_RADIO : LIST_ANNEX_STYLE_NORMAL;
1003         CustomItem* pItem = new (std::nothrow) CustomItem();
1004         if (pItem == null)
1005         {
1006                 goto FAIL;
1007         }
1008         r = pItem->Construct(Osp::Graphics::Dimension(itemWidth, LISTVIEW_ITEM_HEIGHT), style);
1009         if (IsFailed(r))
1010         {
1011                 ShowError(r, METHOD_FILE_LINENO);
1012                 goto FAIL;
1013         }
1014         switch (__currentListViewId)
1015         {
1016         case ID_BUTTON_SETTING_OK:
1017         case ID_BUTTON_EFFECT_OK:
1018         case ID_BUTTON_ISO_OK:
1019         case ID_BUTTON_WHITEBALANCE_OK:
1020         case ID_BUTTON_QUALITY_OK:
1021         case ID_BUTTON_FRAMERATE_OK:
1022         case ID_BUTTON_RECORDINGRESOLUTION_OK:
1023         case ID_BUTTON_VIDEOCODEC_OK:
1024         case ID_BUTTON_AUDIOCODEC_OK:
1025         case ID_BUTTON_FILEFORMAT_OK:
1026         case ID_BUTTON_FLIP_OK:
1027         {
1028                 if (__pSettingItemArrayList)
1029                 {
1030                         SettingListData* pItemValue = (SettingListData*) __pSettingItemArrayList->GetAt(index);
1031                         if (pItemValue)
1032                         {
1033                                 AppLog("item name at %d = %ls", index, pItemValue->pItemName->GetPointer());
1034                                 r = pItem->AddElement(Rectangle(0, 0, itemWidth, LISTVIEW_ITEM_HEIGHT), pItemValue->elementId, *(pItemValue->pItemName), true);
1035                                 if (IsFailed(r))
1036                                 {
1037                                         ShowError(r, METHOD_FILE_LINENO);
1038                                         goto FAIL;
1039                                 }
1040                         }
1041
1042                         if (index == (__pSettingItemArrayList->GetCount() - 1))
1043                         {
1044                                 SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
1045                         }
1046                 }
1047         }
1048         break;
1049
1050         default:
1051                 AppLog("default case matching = %d", __currentListViewId);
1052                 goto FAIL;
1053                 break;
1054         }
1055
1056         return pItem;
1057 FAIL:
1058         if (pItem)
1059         {
1060                 delete pItem;
1061         }
1062         return null;
1063 }
1064
1065 bool
1066 VideoRecorderForm::DeleteItem(int index, Osp::Ui::Controls::ListItemBase* pItem, int itemWidth)
1067 {
1068         AppLog("Enter here");
1069         delete pItem;
1070         pItem = null;
1071         return true;
1072 }
1073
1074 result
1075 VideoRecorderForm::OnActivate(void* activateParam)
1076 {
1077         result r = E_SUCCESS;
1078
1079         int tempVal = INIT;
1080         int index = 0;
1081         int count = 0;
1082         char* pTemp;
1083         Dimension tempDimention(INIT, INIT);
1084         CodecType tempAudioCodecType = CODEC_NONE;
1085         CodecType tempVideoCodecType = CODEC_NONE;
1086         MediaContainerType tempContainerType = MEDIA_CONTAINER_NONE;
1087
1088         AppLog("VideoRecorderForm::OnActivate enter CAM TYPE = %d", __camType);
1089
1090         Osp::System::BatteryLevel batteryLevel;
1091         Osp::System::Battery::GetCurrentLevel(batteryLevel);
1092
1093         String recSize;
1094         recSize.Clear();
1095         recSize.Append(__startSize);
1096         recSize.Append(L" ");
1097         recSize.Append(L"MB");
1098
1099         if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW)
1100         {
1101                 bool isCharging = false;
1102                 Osp::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging);
1103                 if ((!isCharging))
1104                 {
1105                         MessageBox msgBox;
1106                         int reslut_a;
1107                         msgBox.Construct("Info", "Please Charge the Battery to use the recorder", MSGBOX_STYLE_OK, 3000);
1108                         msgBox.ShowAndWait(reslut_a);
1109                         __pProgress->SetValue(0);
1110                         __pProgress->Draw();
1111                         __pElapsedTimeLable->SetText(__startTime);
1112                         __pElapsedRecordSizeLable->SetText(__startSize);
1113
1114                         __pElapsedTimeLable->RequestRedraw();
1115                         __pElapsedRecordSizeLable->RequestRedraw();
1116
1117                         EnableFooterItem(ID_SETTING, false);
1118                         EnableFooterItem(ID_TOGGLE_CAMERA_TYPE, false);
1119                         EnableFooterItem(ID_START, false);
1120                         __batteryLevelFlag = true;
1121                         return E_SUCCESS;
1122                 }
1123                 else
1124                 {
1125                         EnableFooterItem(ID_SETTING, true);
1126                         EnableFooterItem(ID_START, true);
1127                 }
1128         }
1129         else
1130         {
1131                 EnableFooterItem(ID_SETTING, true);
1132                 EnableFooterItem(ID_START, true);
1133         }
1134         __batteryLevelFlag = false;
1135         __backGround = false;
1136         __cameraError = false;
1137
1138         Osp::System::PowerManager::KeepScreenOnState(true, false);
1139         r = Osp::Media::MediaCapability::GetValue(CAMERA_COUNT, __cameraCount);
1140         AppLog("Camera Count = %d", __cameraCount);
1141
1142         SetOrientation(ORIENTATION_AUTOMATIC);
1143         r = CreateOverlayRegion();
1144         if (IsFailed(r))
1145         {
1146                 goto FAIL;
1147         }
1148
1149         AppLog("CreateOverlayRegion return %s", GetErrorMessage(r));
1150
1151         __pProgress->SetValue(0);
1152         __pProgress->Draw();
1153
1154         __pElapsedTimeLable->SetText(__startTime);
1155         __pElapsedRecordSizeLable->SetText(__startSize);
1156
1157         __pElapsedTimeLable->RequestRedraw();
1158         __pElapsedRecordSizeLable->RequestRedraw();
1159
1160         ShowFooterItem(0, true);
1161
1162         if (__cameraCount > 1)  //if camera count is 2 then only use secondary camera.
1163         {
1164                 ShowFooterItem(1, true);
1165         }
1166         else
1167         {
1168                 ShowFooterItem(1, false);
1169         }
1170
1171         ShowFooterItem(2, true);
1172         SetFooterItem(2, L"Start", ID_START);
1173
1174         __pCamera = new (std::nothrow) Camera();
1175         if (__pCamera == null)
1176         {
1177                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
1178                 goto FAIL;
1179         }
1180
1181         r = __pCamera->Construct(*this, __camType);
1182         if (IsFailed(r))
1183         {
1184                 ShowError(r, METHOD_FILE_LINENO);
1185                 goto FAIL;
1186         }
1187
1188
1189         r = __pCamera->PowerOn();
1190         if (IsFailed(r))
1191         {
1192                 ShowError(r, METHOD_FILE_LINENO);
1193                 goto FAIL;
1194         }
1195
1196         __pVideoRecorder = new (std::nothrow) Osp::Media::VideoRecorder();
1197         if (__pVideoRecorder == null)
1198         {
1199                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
1200                 goto FAIL;
1201         }
1202
1203         r = __pVideoRecorder->Construct(*this, *__pCamera);
1204         if (IsFailed(r))
1205         {
1206                 ShowError(r, METHOD_FILE_LINENO);
1207                 goto FAIL;
1208         }
1209
1210         __pPreviewFrameRateList = __pCamera->GetSupportedPreviewFrameRateListN();
1211         if (__pPreviewFrameRateList == null)
1212         {
1213                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
1214                 goto FAIL;
1215         }
1216
1217         __pRecordingResolutionList = __pVideoRecorder->GetSupportedRecordingResolutionListN();
1218         if (__pRecordingResolutionList == null)
1219         {
1220                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
1221                 goto FAIL;
1222         }
1223
1224         __pRecorderVideoCodecList = __pVideoRecorder->GetSupportedVideoCodecListN();
1225         if (__pRecorderVideoCodecList == null)
1226         {
1227                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
1228                 goto FAIL;
1229         }
1230
1231         __pRecorderAudioCodecList = __pVideoRecorder->GetSupportedAudioCodecListN();
1232         if (__pRecorderAudioCodecList == null)
1233         {
1234                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
1235                 goto FAIL;
1236         }
1237
1238         __pRecorderVideoContainerList = __pVideoRecorder->GetSupportedContainerListN();
1239         if (__pRecorderVideoContainerList == null)
1240         {
1241                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
1242                 goto FAIL;
1243         }
1244
1245         __previewByCallback = __pConfig->GetInt(1, SECTION_NAME, String(L"previewByCallback"));
1246         AppLog("Camera __bPreviewByCallback is = %d", __previewByCallback);
1247
1248         tempVal = (__camType == CAMERA_PRIMARY) ? __pConfig->GetInt(-1, SECTION_NAME, String(L"framerate")) : __pConfig->GetInt(-1, SECTION_NAME, String(L"framerateSec"));
1249         if (-1 == tempVal)
1250         {
1251                 tempVal = __pCamera->GetPreviewFrameRate();
1252         }
1253
1254         count = __pPreviewFrameRateList->GetCount();
1255
1256         for (index = 0; index < count; index++)
1257         {
1258                 int object = -1;
1259                 r = __pPreviewFrameRateList->GetAt(index, object);
1260                 if (IsFailed(r))
1261                 {
1262                         ShowError(r, METHOD_FILE_LINENO);
1263                         goto FAIL;
1264                 }
1265
1266                 if (tempVal == object)
1267                 {
1268                         (__camType == CAMERA_PRIMARY) ? __frameRateIndex = index : __frameRateIndexSec = index;
1269                         break;
1270                 }
1271         }
1272
1273         if (index >= count)
1274         {
1275                 ShowError(E_FAILURE, METHOD_FILE_LINENO);
1276                 goto FAIL;
1277         }
1278
1279         tempDimention.width = (__camType == CAMERA_PRIMARY) ? __pConfig->GetInt(-1, SECTION_NAME, String(L"resolutionWidth")) : __pConfig->GetInt(-1, SECTION_NAME, String(L"resolutionWidthSec"));
1280         tempDimention.height = (__camType == CAMERA_PRIMARY) ? __pConfig->GetInt(-1, SECTION_NAME, String(L"resolutionHeight")) : __pConfig->GetInt(-1, SECTION_NAME, String(L"resolutionHeightSec"));
1281         if ((-1 == tempDimention.width) || (-1 == tempDimention.height))
1282         {
1283                 tempDimention = __pVideoRecorder->GetRecordingResolution();
1284         }
1285
1286         count = __pRecordingResolutionList->GetCount();
1287
1288         for (index = 0; index < count; index++)
1289         {
1290                 Dimension* pDimention = null;
1291                 pDimention = static_cast< Dimension* >(__pRecordingResolutionList->GetAt(index));
1292                 if (pDimention == null)
1293                 {
1294                         ShowError(E_FAILURE, METHOD_FILE_LINENO);
1295                         r = E_FAILURE;
1296                         goto FAIL;
1297                 }
1298                 if (*pDimention == tempDimention)
1299                 {
1300                         (__camType == CAMERA_PRIMARY) ? __resolutionIndex = index : __resolutionIndexSec = index;
1301                         break;
1302                 }
1303         }
1304
1305         if (index >= count)
1306         {
1307                 ShowError(E_FAILURE, METHOD_FILE_LINENO);
1308                 goto FAIL;
1309         }
1310
1311         tempVal = __pConfig->GetInt(-1, SECTION_NAME, String(L"videocodec"));
1312         if (-1 == tempVal)
1313         {
1314                 r = __pVideoRecorder->GetFormat(tempAudioCodecType, tempVideoCodecType, tempContainerType);
1315                 if (IsFailed(r))
1316                 {
1317                         ShowError(r, METHOD_FILE_LINENO);
1318                         goto FAIL;
1319                 }
1320         }
1321         else
1322         {
1323                 tempVideoCodecType = static_cast< CodecType >(tempVal);
1324         }
1325
1326         count = __pRecorderVideoCodecList->GetCount();
1327
1328         for (index = 0; index < count; index++)
1329         {
1330                 CodecType codec = CODEC_NONE;
1331                 r = __pRecorderVideoCodecList->GetAt(index, codec);
1332                 if (IsFailed(r))
1333                 {
1334                         ShowError(r, METHOD_FILE_LINENO);
1335                         goto FAIL;
1336                 }
1337                 if (codec == tempVideoCodecType)
1338                 {
1339                         __videoCodecIndex = index;
1340                         break;
1341                 }
1342         }
1343
1344         if (index >= count)
1345         {
1346                 ShowError(E_FAILURE, METHOD_FILE_LINENO);
1347                 goto FAIL;
1348         }
1349
1350         tempVal = __pConfig->GetInt(-1, SECTION_NAME, String(L"audiocodec"));
1351
1352         if (-1 == tempVal)
1353         {
1354                 r = __pVideoRecorder->GetFormat(tempAudioCodecType, tempVideoCodecType, tempContainerType);
1355                 if (IsFailed(r))
1356                 {
1357                         ShowError(r, METHOD_FILE_LINENO);
1358                         goto FAIL;
1359                 }
1360         }
1361         else
1362         {
1363                 tempAudioCodecType = static_cast< CodecType >(tempVal);
1364         }
1365
1366         count = __pRecorderAudioCodecList->GetCount();
1367
1368         for (index = 0; index < count; index++)
1369         {
1370                 CodecType codec = CODEC_NONE;
1371                 r = __pRecorderAudioCodecList->GetAt(index, codec);
1372                 if (IsFailed(r))
1373                 {
1374                         ShowError(r, METHOD_FILE_LINENO);
1375                         goto FAIL;
1376                 }
1377                 if (codec == tempAudioCodecType)
1378                 {
1379                         __audioCodecIndex = index;
1380                         break;
1381                 }
1382         }
1383
1384         if (index >= count)
1385         {
1386                 ShowError(E_FAILURE, METHOD_FILE_LINENO);
1387                 goto FAIL;
1388         }
1389
1390         tempVal = __pConfig->GetInt(-1, SECTION_NAME, String(L"fileformat"));
1391         if (-1 == tempVal)
1392         {
1393                 r = __pVideoRecorder->GetFormat(tempAudioCodecType, tempVideoCodecType, tempContainerType);
1394                 if (IsFailed(r))
1395                 {
1396                         ShowError(r, METHOD_FILE_LINENO);
1397                         goto FAIL;
1398                 }
1399         }
1400         else
1401         {
1402                 tempContainerType = static_cast< MediaContainerType >(tempVal);
1403         }
1404         tempContainerType = MEDIA_CONTAINER_MP4;
1405
1406         pTemp = (char*) &tempContainerType;
1407
1408         AppLog("codec type %c %c %c %c", pTemp[0], pTemp[1], pTemp[2], pTemp[3]);
1409
1410         count = __pRecorderVideoContainerList->GetCount();
1411
1412         for (index = 0; index < count; index++)
1413         {
1414                 MediaContainerType container = MEDIA_CONTAINER_NONE;
1415                 r = __pRecorderVideoContainerList->GetAt(index, container);
1416                 if (IsFailed(r))
1417                 {
1418                         ShowError(r, METHOD_FILE_LINENO);
1419                         goto FAIL;
1420                 }
1421
1422                 pTemp = (char*) &container;
1423                 AppLog("[index = %d] codec type %c %c %c %c", index, pTemp[0], pTemp[1], pTemp[2], pTemp[3]);
1424                 if (container == tempContainerType)
1425                 {
1426                         if (__formatIndex == INIT)
1427                         {
1428                                 __formatIndex = index;
1429                         }
1430                         break;
1431                 }
1432         }
1433
1434         if (index >= count)
1435         {
1436                 ShowError(E_FAILURE, METHOD_FILE_LINENO);
1437                 goto FAIL;
1438         }
1439
1440         __qualityIndex = __pConfig->GetInt(-1, SECTION_NAME, String(L"quality"));
1441         if (__qualityIndex == -1)
1442         {
1443                 r = __pVideoRecorder->SetQuality(RECORDING_QUALITY_HIGH);
1444                 if (IsFailed(r))
1445                 {
1446                         ShowError(r, METHOD_FILE_LINENO);
1447                         goto FAIL;
1448                 }
1449                 __qualityIndex = __pVideoRecorder->GetQuality();
1450         }
1451         AppLog("quality index = %d", __qualityIndex);
1452
1453         r = __pOverlay->GetBackgroundBufferInfo(__bufferInfo);
1454         if (IsFailed(r))
1455         {
1456                 ShowError(r, METHOD_FILE_LINENO);
1457                 goto FAIL;
1458         }
1459
1460         r = __pPreviewFrameRateList->GetAt((CAMERA_PRIMARY == __camType) ? __frameRateIndex : __frameRateIndexSec, tempVal);
1461         if (IsFailed(r))
1462         {
1463                 ShowError(r, METHOD_FILE_LINENO);
1464                 goto FAIL;
1465         }
1466
1467         tempDimention = *(Dimension*) __pRecordingResolutionList->GetAt((CAMERA_PRIMARY == __camType) ? __resolutionIndex : __resolutionIndexSec);
1468
1469         r = __pCamera->SetPreviewResolution(tempDimention);
1470         if (IsFailed(r))
1471         {
1472                 ShowError(r, METHOD_FILE_LINENO);
1473                 goto FAIL;
1474         }
1475
1476         r = __pCamera->SetPreviewFrameRate(tempVal);
1477         if (IsFailed(r))
1478         {
1479                 ShowError(r, METHOD_FILE_LINENO);
1480                 goto FAIL;
1481         }
1482
1483         if (__previewByCallback == 1)
1484         {
1485                 r = __pCamera->StartPreview(NULL, true);
1486                 if (IsFailed(r))
1487                 {
1488                         ShowError(r, METHOD_FILE_LINENO);
1489                         goto FAIL;
1490                 }
1491         }
1492         else
1493         {
1494                 r = __pCamera->StartPreview(&__bufferInfo, false);
1495                 if (IsFailed(r))
1496                 {
1497                         ShowError(r, METHOD_FILE_LINENO);
1498                         goto FAIL;
1499                 }
1500         }
1501
1502         //Enable the fotter details
1503         SetFooterItem(0, String(L"Settings"), ID_SETTING);
1504         if (CAMERA_PRIMARY == __camType)
1505         {
1506                 SetFooterItem(1, String(L"Primary"), ID_TOGGLE_CAMERA_TYPE);
1507         }
1508         else
1509         {
1510                 SetFooterItem(1, String(L"Secondary"), ID_TOGGLE_CAMERA_TYPE);
1511         }
1512         SetFooterItem(2, String(L"Start"), ID_START);
1513
1514         ShowFooterItem(0, true);
1515         ShowFooterItem(1, true);
1516         ShowFooterItem(2, true);
1517
1518         return E_SUCCESS;
1519 FAIL:
1520         __cameraError = true;
1521         FreeResources();
1522         return E_FAILURE;
1523 }
1524
1525 result
1526 VideoRecorderForm::StartRecord(void)
1527 {
1528         result r = E_SUCCESS;
1529
1530         r = InitCameraRecorder();
1531         if (IsFailed(r))
1532         {
1533                 goto FAIL;
1534         }
1535
1536         r = __pTimer->Start(_TIMER_VALUE_);
1537         if (IsFailed(r) && r != E_INVALID_STATE)
1538         {
1539                 ShowError(r, METHOD_FILE_LINENO);
1540                 goto FAIL;
1541         }
1542
1543         return r;
1544 FAIL:
1545         return r;
1546 }
1547 result
1548 VideoRecorderForm::StopRecord()
1549 {
1550         result r = E_SUCCESS;
1551         __pTimer->Cancel();
1552         AppLog("StopRecord called");
1553         r = __pVideoRecorder->Stop();
1554         //Once stop is called. close will be called in OnVideoRecorderStopped()
1555         return r;
1556 }
1557 result
1558 VideoRecorderForm::InitCameraRecorder()
1559 {
1560         result r = E_SUCCESS;
1561         bool retVal = true;
1562         CodecType audioCodec = CODEC_NONE;
1563         CodecType videoCodec = CODEC_NONE;
1564         Osp::Graphics::Dimension* pResolution = null;
1565         MediaContainerType container = MEDIA_CONTAINER_NONE;
1566         String strFileFormat;
1567
1568         __filePath.Clear();
1569         __filePath.Append(Osp::App::App::GetInstance()->GetAppRootPath());
1570         __filePath.Append(__pConfig->GetString(SECTION_NAME, String(L"filename")));
1571         __filePath.Append(L".");
1572
1573         pResolution = static_cast< Dimension* >(__pRecordingResolutionList->GetAt((__camType == CAMERA_PRIMARY) ? __resolutionIndex : __resolutionIndexSec));
1574         if (pResolution == null)
1575         {
1576                 ShowError(E_FAILURE, METHOD_FILE_LINENO);
1577                 r = E_FAILURE;
1578                 goto FAIL;
1579         }
1580
1581         r = __pVideoRecorder->SetRecordingResolution(*pResolution);
1582         if (IsFailed(r))
1583         {
1584                 ShowError(r, METHOD_FILE_LINENO);
1585                 goto FAIL;
1586         }
1587
1588         r = __pRecorderVideoCodecList->GetAt(__videoCodecIndex, videoCodec);
1589         if (IsFailed(r))
1590         {
1591                 ShowError(r, METHOD_FILE_LINENO);
1592                 goto FAIL;
1593         }
1594
1595         r = __pRecorderAudioCodecList->GetAt(__audioCodecIndex, audioCodec);
1596         if (IsFailed(r))
1597         {
1598                 ShowError(r, METHOD_FILE_LINENO);
1599                 goto FAIL;
1600         }
1601
1602         r = __pRecorderVideoContainerList->GetAt(__formatIndex, container);
1603         if (IsFailed(r))
1604         {
1605                 ShowError(r, METHOD_FILE_LINENO);
1606                 goto FAIL;
1607         }
1608
1609         retVal = ConvertContainerToString(container, strFileFormat);
1610         if (!retVal)
1611         {
1612                 r = E_FAILURE;
1613                 ShowError(r, METHOD_FILE_LINENO);
1614                 goto FAIL;
1615         }
1616
1617         r = __filePath.Append(strFileFormat);
1618         if (IsFailed(r))
1619         {
1620                 ShowError(r, METHOD_FILE_LINENO);
1621                 goto FAIL;
1622         }
1623
1624         r = __pVideoRecorder->SetFormat(audioCodec, videoCodec, container);
1625         if (IsFailed(r))
1626         {
1627                 ShowSupportedCodecListPopUp();
1628                 //Enable Setting and primary button
1629                 goto FAIL;
1630         }
1631
1632         r = __pVideoRecorder->SetQuality(static_cast< RecordingQuality >(__qualityIndex));
1633         if (IsFailed(r))
1634         {
1635                 ShowError(r, METHOD_FILE_LINENO);
1636                 goto FAIL;
1637         }
1638
1639         __maxRecordingTime = __pConfig->GetInt(DEFAULT_MAXTIME, SECTION_NAME, String(L"maxtime"));
1640         r = __pVideoRecorder->SetMaxRecordingTime(__maxRecordingTime * KILOBYTE);
1641         if (IsFailed(r))
1642         {
1643                 ShowError(r, METHOD_FILE_LINENO);
1644                 goto FAIL;
1645         }
1646
1647         if (__pProgress)
1648         {
1649                 AppLog("recording max time is = %d", __maxRecordingTime);
1650                 __pProgress->SetRange(0, 100); //progress based on recorded %
1651         }
1652
1653         r = __pVideoRecorder->CreateVideoFile(__filePath, true);
1654         if (IsFailed(r))
1655         {
1656                 ShowError(r, METHOD_FILE_LINENO);
1657                 goto FAIL;
1658         }
1659
1660         r = __pVideoRecorder->Record();
1661         if (IsFailed(r))
1662         {
1663                 ShowError(r, METHOD_FILE_LINENO);
1664                 goto FAIL;
1665         }
1666
1667         AppLog("After record, state is %d", __pVideoRecorder->GetState());
1668
1669         return r;
1670 FAIL:
1671         __pVideoRecorder->Cancel();
1672         __pVideoRecorder->Close();
1673         return r;
1674 }
1675
1676 result
1677 VideoRecorderForm::OnTerminating(void)
1678 {
1679         result r = E_SUCCESS;
1680
1681         DeletePopup(&__pPopupMessage);
1682         DeletePopup(&__pPopupEffect);
1683         DeletePopup(&__pPopupIso);
1684         DeletePopup(&__pPopupWhiteBalance);
1685         DeletePopup(&__pPopupFrameRate);
1686         DeletePopup(&__pPopupRecordingResolution);
1687         DeletePopup(&__pPopupRecordingQuality);
1688         DeletePopup(&__pPopupVideoCodec);
1689         DeletePopup(&__pPopupAudioCodec);
1690         DeletePopup(&__pPopupFileFormat);
1691         FreeResources();
1692
1693         if (__pTimer)
1694         {
1695                 __pTimer->Cancel();
1696                 SAFE_DELETE(__pTimer);
1697         }
1698         AppLog("VideoRecorderForm::OnTerminating");
1699         return r;
1700 }
1701
1702 void
1703 VideoRecorderForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
1704 {
1705         result r = E_SUCCESS;
1706         AppLog("Enter action id = %d", actionId);
1707
1708         switch (actionId)
1709         {
1710         case ID_BACK:
1711         {
1712                 String recSize;
1713                 recSize.Clear();
1714                 recSize.Append(__startSize);
1715                 recSize.Append(L" ");
1716                 recSize.Append(L"MB");
1717
1718                 __pTimer->Cancel();
1719                 if (__pVideoRecorder->GetState() == RECORDER_STATE_RECORDING)
1720                 {
1721                         __pVideoRecorder->Cancel();
1722                 }
1723                 else
1724                 {
1725                         FreeResources();
1726                 }
1727                 SetFooterItem(2, L"Start", ID_START);
1728                 __pProgress->SetValue(0);
1729                 __pProgress->Draw();
1730
1731                 __pElapsedTimeLable->SetText(__startTime);
1732                 __pElapsedRecordSizeLable->SetText(__startSize);
1733
1734                 __pElapsedTimeLable->RequestRedraw();
1735                 __pElapsedRecordSizeLable->RequestRedraw();
1736
1737                 Deactivate();
1738         }
1739         break;
1740
1741         case ID_SETTING:
1742         {
1743                 if (RECORDER_STATE_RECORDING != __pVideoRecorder->GetState())
1744                 {
1745                         CreateSettingPopUp();
1746                         ShowPopUp(__pPopupSetting);
1747                 }
1748                 else
1749                 {
1750                         MessageBox msgBox;
1751                         int modalResult = 0;
1752                         msgBox.Construct(L"", L"Operation not allowed", MSGBOX_STYLE_NONE, 3000);
1753                         msgBox.ShowAndWait(modalResult);
1754                 }
1755         }
1756         break;
1757
1758         case ID_TOGGLE_CAMERA_TYPE:
1759         {
1760                 if (RECORDER_STATE_RECORDING != __pVideoRecorder->GetState())
1761                 {
1762                         ShowFooterItem(0, false);
1763                         ShowFooterItem(1, false);
1764                         ShowFooterItem(2, false);
1765                         SendUserEvent(RECORDER_TOGGLE_CAMERA, null);
1766                 }
1767                 else
1768                 {
1769                         MessageBox msgBox;
1770                         int modalResult = 0;
1771                         msgBox.Construct(L"", L"Operation not allowed", MSGBOX_STYLE_NONE, 3000);
1772                         msgBox.ShowAndWait(modalResult);
1773                 }
1774         }
1775         break;
1776
1777         case ID_BUTTON_SETTING_OK:
1778         {
1779                 HidePopUp(__pPopupSetting);
1780                 DeletePopup(&__pPopupSetting);
1781         }
1782         break;
1783
1784         case ID_START:
1785         {
1786                 Footer* pFotter = null;
1787                 ShowFooterItem(0, false);
1788                 ShowFooterItem(1, false);
1789                 ShowFooterItem(2, false);
1790                 SendUserEvent(RECORDER_START_STOP, null);
1791                 pFotter = GetFooter();
1792                 if (pFotter)
1793                 {
1794                         pFotter->SetBackButtonEnabled(false);
1795                         pFotter->Draw();
1796                 }
1797         }
1798         break;
1799
1800         case ID_BUTTON_EFFECT_OK:
1801         {
1802                 HidePopUp(__pPopupEffect);
1803                 DeletePopup(&__pPopupEffect);
1804         }
1805         break;
1806
1807         case ID_BUTTON_ISO_OK:
1808         {
1809                 HidePopUp(__pPopupIso);
1810                 DeletePopup(&__pPopupIso);
1811         }
1812         break;
1813
1814         case ID_BUTTON_WHITEBALANCE_OK:
1815         {
1816                 HidePopUp(__pPopupWhiteBalance);
1817                 DeletePopup(&__pPopupWhiteBalance);
1818         }
1819         break;
1820
1821         case ID_BUTTON_FRAMERATE_OK:
1822         {
1823                 HidePopUp(__pPopupFrameRate);
1824                 DeletePopup(&__pPopupFrameRate);
1825         }
1826         break;
1827
1828         case ID_BUTTON_RECORDINGRESOLUTION_OK:
1829         {
1830                 HidePopUp(__pPopupRecordingResolution);
1831                 DeletePopup(&__pPopupRecordingResolution);
1832         }
1833         break;
1834
1835         case ID_BUTTON_QUALITY_OK:
1836         {
1837                 HidePopUp(__pPopupRecordingQuality);
1838                 DeletePopup(&__pPopupRecordingQuality);
1839         }
1840         break;
1841
1842         case ID_BUTTON_VIDEOCODEC_OK:
1843         {
1844                 HidePopUp(__pPopupVideoCodec);
1845                 DeletePopup(&__pPopupVideoCodec);
1846         }
1847         break;
1848
1849         case ID_BUTTON_AUDIOCODEC_OK:
1850         {
1851                 HidePopUp(__pPopupAudioCodec);
1852                 DeletePopup(&__pPopupAudioCodec);
1853         }
1854         break;
1855
1856         case ID_BUTTON_FILEFORMAT_OK:
1857         {
1858                 HidePopUp(__pPopupFileFormat);
1859                 DeletePopup(&__pPopupFileFormat);
1860         }
1861         break;
1862
1863         case ID_BUTTON_ERROR_POPUP_OK:
1864         {
1865                 ClearErrorPopup();
1866                 if (__cameraError == true)
1867                 {
1868                         AppLog("VideoRecorderForm::OnActionPerformed");
1869                         FreeResources();
1870                         Deactivate();
1871                 }
1872         }
1873         break;
1874
1875         case ID_BUTTON_EXPOSURE_OK:
1876         {
1877                 HidePopUp(__pPopupExposure);
1878                 DeletePopup(&__pPopupExposure);
1879                 __pExposureSlider = null;
1880                 ShowFooterItems();
1881         }
1882         break;
1883
1884         case ID_BUTTON_BRIGHTNESS_OK:
1885         {
1886                 HidePopUp(__pPopupBrightness);
1887                 DeletePopup(&__pPopupBrightness);
1888                 __pBrightnessSlider = null;
1889                 ShowFooterItems();
1890         }
1891         break;
1892
1893         case ID_BUTTON_CONTRAST_OK:
1894         {
1895                 HidePopUp(__pPopupContrast);
1896                 DeletePopup(&__pPopupContrast);
1897                 __pContrastSlider = null;
1898                 ShowFooterItems();
1899         }
1900         break;
1901
1902         case ID_BUTTON_ZOOM_OK:
1903         {
1904                 HidePopUp(__pPopupZoom);
1905                 DeletePopup(&__pPopupZoom);
1906                 __pZoomLevelSlider = null;
1907                 ShowFooterItems();
1908         }
1909         break;
1910
1911         case ID_BUTTON_FLIP_OK:
1912         {
1913                 CameraFlipType flipType = __pCamera->GetFlip();
1914                 HidePopUp(__pPopupFlip);
1915                 if (flipType != __flipType)
1916                 {
1917                         r = __pCamera->StopPreview();
1918                         if (IsFailed(r))
1919                         {
1920                                 ShowError(r, METHOD_FILE_LINENO);
1921                         }
1922                         r = __pCamera->SetFlip(__flipType);
1923                         if (IsFailed(r))
1924                         {
1925                                 ShowError(r, METHOD_FILE_LINENO);
1926                         }
1927                         AppLog("Set Flip return = %s value = %d", GetErrorMessage(r), __flipType);
1928                         if (__previewByCallback == 1)
1929                         {
1930                                 r = __pCamera->StartPreview(NULL, true);
1931                                 if (IsFailed(r))
1932                                 {
1933                                         ShowError(r, METHOD_FILE_LINENO);
1934                                 }
1935                         }
1936                         else
1937                         {
1938                                 r = __pCamera->StartPreview(&__bufferInfo, false);
1939                                 if (IsFailed(r))
1940                                 {
1941                                         ShowError(r, METHOD_FILE_LINENO);
1942                                 }
1943                         }
1944                 }
1945                 DeletePopup(&__pPopupFlip);
1946         }
1947         break;
1948
1949         case ID_BUTTON_SUPPORTED_CODEC_POPUP_OK:
1950         {
1951                 ClearSupportedCodecPopup();
1952         }
1953         break;
1954
1955         default:
1956                 break;
1957         }
1958
1959         return;
1960 }
1961
1962 result
1963 VideoRecorderForm::ToggleCamera()
1964 {
1965         AppLog("ToggleCamera is triggered ");
1966         FreeResources();
1967         SAFE_DELETE(__pOverlay);
1968
1969         if (__camType == CAMERA_PRIMARY)
1970         {
1971                 __camType = CAMERA_SECONDARY;
1972                 CreateOverlayRegion();
1973                 SetFooterItem(1, L"Secondary", ID_TOGGLE_CAMERA_TYPE);
1974         }
1975         else
1976         {
1977                 __camType = CAMERA_PRIMARY;
1978                 CreateOverlayRegion();
1979                 SetFooterItem(1, L"Primary", ID_TOGGLE_CAMERA_TYPE);
1980         }
1981
1982         OnActivate(null);
1983         return E_SUCCESS;
1984 }
1985
1986
1987 void
1988 VideoRecorderForm::OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs)
1989 {
1990         result r = E_SUCCESS;
1991         AppLog("VideoRecorderForm::OnUserEventReceivedN : request id = %d", requestId);
1992         switch (requestId)
1993         {
1994         case RECORDER_START_STOP:
1995         {
1996                 if (__pVideoRecorder == null)
1997                 {
1998                         return;
1999                 }
2000                 RecorderState state = __pVideoRecorder->GetState();
2001                 AppLog("recorder state = %d", state);
2002                 if (state == RECORDER_STATE_STARTING)
2003                 {
2004                         AppLog("It is trying to start the recording ");
2005                         return;
2006                 }
2007
2008                 if ((RECORDER_STATE_INITIALIZED == state) || (RECORDER_STATE_OPENED == state) || \
2009                         (RECORDER_STATE_PAUSED == state) || (RECORDER_STATE_CLOSED == state) || \
2010                         (RECORDER_STATE_STOPPED == state))
2011                 {
2012                         AppLog("StartRecord");
2013                         __cameraError = false;
2014                         r = StartRecord();
2015                         if (IsFailed(r))
2016                         {
2017                                 goto FAIL;
2018                         }
2019                         AppLog("__orientationStatus set to = %d", __orientationStatus);
2020                         SetOrientation((Orientation) __orientationStatus);
2021                         SetFooterItem(2, L"Stop", ID_START);
2022                         r = GetFooter()->Draw();
2023                         if (IsFailed(r))
2024                         {
2025                                 ShowError(r, METHOD_FILE_LINENO);
2026                                 goto FAIL;
2027                         }
2028                 }
2029                 else
2030                 {
2031                         String recSize;
2032                         recSize.Clear();
2033                         recSize.Append(__startSize);
2034                         recSize.Append(L" ");
2035                         recSize.Append(L"MB");
2036
2037                         SetFooterItem(2, L"Start", ID_START);
2038                         ShowFooterItem(2, false);
2039                         r = StopRecord();
2040                         if (IsFailed(r))
2041                         {
2042                                 ShowError(r, METHOD_FILE_LINENO);
2043                                 goto FAIL;
2044                         }
2045                         __pProgress->SetValue(0);
2046                         __pProgress->Draw();
2047
2048                         __pElapsedTimeLable->SetText(__startTime);
2049                         __pElapsedRecordSizeLable->SetText(__startSize);
2050
2051                         __pElapsedTimeLable->RequestRedraw();
2052                         __pElapsedRecordSizeLable->RequestRedraw();
2053                 }
2054         }
2055         break;
2056
2057         case RECORDER_ON_CLOSE:
2058         {
2059                 FreeResources();
2060                 //To complete freeResource activity before launching MediaPlayerForm
2061                 Osp::Base::Runtime::Thread::Sleep(MIN_THREAD_SLEEP_TIME);
2062                 LaunchMediaPlayer(false);
2063         }
2064         break;
2065
2066         case RECORDER_ON_STOP:
2067         {
2068                 if (__pVideoRecorder != null)
2069                 {
2070                         AppLog("__pVideoRecorder->Close() is called");
2071                         __pVideoRecorder->Close();
2072                 }
2073         }
2074         break;
2075
2076         case RECORDER_TOGGLE_CAMERA:
2077         {
2078                 ToggleCamera();
2079                 Draw();
2080         }
2081         break;
2082
2083         case RECORDER_ROTATION:
2084         {
2085                 DoRotation();
2086         }
2087         break;
2088         }
2089         return;
2090
2091 FAIL:
2092
2093         __cameraError = true;
2094         Footer* pFotter = null;
2095         ShowFooterItem(0, true);
2096         ShowFooterItem(1, true);
2097         ShowFooterItem(2, true);
2098         pFotter = GetFooter();
2099         if (pFotter)
2100         {
2101                 pFotter->SetBackButtonEnabled(true);
2102                 pFotter->Draw();
2103         }
2104         return;
2105 }
2106
2107 void
2108 VideoRecorderForm::OnCameraAutoFocused(bool completeCondition)
2109 {
2110
2111 }
2112
2113 void
2114 VideoRecorderForm::OnCameraCaptured(Osp::Base::ByteBuffer& capturedData, result r)
2115 {
2116
2117 }
2118
2119 void
2120 VideoRecorderForm::OnCameraErrorOccurred(CameraErrorReason r)
2121 {
2122
2123 }
2124
2125 void
2126 VideoRecorderForm::OnCameraPreviewed(Osp::Base::ByteBuffer& previewedData, result r)
2127 {
2128         result res = E_SUCCESS;
2129         Dimension dataDim;
2130
2131         if (__pOverlay == NULL || __pCamera == NULL || __pRecordingResolutionList == NULL)
2132         {
2133                 AppLog("Overlay regions is null");
2134                 return;
2135         }
2136
2137         dataDim = (Dimension) __pCamera->GetPreviewResolution();
2138
2139         if (dataDim.width <= 0 || dataDim.height <= 0)
2140         {
2141                 AppLog("dimenstion is null");
2142                 return;
2143         }
2144
2145         PixelFormat pixelFormat = PIXEL_FORMAT_YCbCr420_PLANAR;
2146         OverlayRegionBufferPixelFormat bufferPixelFormat = OVERLAY_REGION_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR;
2147         switch (pixelFormat)
2148         {
2149         case PIXEL_FORMAT_RGB565:
2150                 bufferPixelFormat = OVERLAY_REGION_BUFFER_PIXEL_FORMAT_RGB565;
2151                 break;
2152
2153         case PIXEL_FORMAT_ARGB8888:
2154                 bufferPixelFormat = OVERLAY_REGION_BUFFER_PIXEL_FORMAT_ARGB8888;
2155                 break;
2156
2157         case PIXEL_FORMAT_YCbCr420_PLANAR:
2158                 bufferPixelFormat = OVERLAY_REGION_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR;
2159                 break;
2160
2161         default:
2162                 break;
2163         }
2164         res = __pOverlay->SetInputBuffer(previewedData, dataDim, bufferPixelFormat);
2165
2166         //      AppLog("SetInputbuffer return = %s pixel format = %d", GetErrorMessage(r), pixelFormat);
2167         __pOverlay->Show();
2168 }
2169
2170 void
2171 VideoRecorderForm::OnListViewItemStateChanged(Osp::Ui::Controls::ListView& source, int index, int elementId, Osp::Ui::Controls::ListItemStatus status)
2172 {
2173         AppLog("OnItemStateChanged enter index = %d elementId = %d", index, elementId);
2174         result r = E_SUCCESS;
2175
2176         if (&source == __pListViewEffect)
2177         {
2178                 int tempVal = 0;
2179                 __pListViewEffect->Draw();
2180                 if (__effectIndex == index)
2181                 {
2182                         r = __pListViewEffect->SetItemChecked(index, true);
2183                         if (IsFailed(r))
2184                         {
2185                                 ShowError(r, METHOD_FILE_LINENO);
2186                                 goto FAIL;
2187                         }
2188                         return;
2189                 }
2190                 r = __pEffectList->GetAt(index, tempVal);
2191                 if (IsFailed(r))
2192                 {
2193                         ShowError(r, METHOD_FILE_LINENO);
2194                         goto FAIL;
2195                 }
2196                 AppLog("__pEffectList->GetAt: tempVal = %d, r = %s", tempVal, GetErrorMessage(r));
2197
2198                 r = __pCamera->SetEffect((CameraEffect) tempVal);
2199                 if (IsFailed(r))
2200                 {
2201                         ShowError(r, METHOD_FILE_LINENO);
2202                         __pListViewEffect->SetItemChecked(index, false);
2203                         __pListViewEffect->SetItemChecked(GetIndexFromValue(__pEffectList, __pCamera->GetEffect()), true);
2204                         goto FAIL;
2205                 }
2206
2207                 r = __pListViewEffect->SetItemChecked(__effectIndex, false);
2208                 if (IsFailed(r))
2209                 {
2210                         ShowError(r, METHOD_FILE_LINENO);
2211                         goto FAIL;
2212                 }
2213                 __effectIndex = index;
2214         }
2215         else if (&source == __pListViewIso)
2216         {
2217                 int tempVal = 0;
2218                 __pListViewIso->Draw();
2219                 if (__isoIndex == index)
2220                 {
2221                         r = __pListViewIso->SetItemChecked(index, true);
2222                         if (IsFailed(r))
2223                         {
2224                                 ShowError(r, METHOD_FILE_LINENO);
2225                                 goto FAIL;
2226                         }
2227                         return;
2228                 }
2229
2230                 r = __pIsoList->GetAt(index, tempVal);
2231                 if (IsFailed(r))
2232                 {
2233                         ShowError(r, METHOD_FILE_LINENO);
2234                         goto FAIL;
2235                 }
2236
2237                 AppLog("__pIsoList->GetAt: tempVal = %d, r = %s", tempVal, GetErrorMessage(r));
2238                 r = __pCamera->SetIsoLevel((CameraIsoLevel) tempVal);
2239                 if (IsFailed(r))
2240                 {
2241                         ShowError(r, METHOD_FILE_LINENO);
2242                         __pListViewIso->SetItemChecked(index, false);
2243                         __pListViewIso->SetItemChecked(GetIndexFromValue(__pIsoList, __pCamera->GetIsoLevel()), true);
2244                         goto FAIL;
2245                 }
2246
2247                 r = __pListViewIso->SetItemChecked(__isoIndex, false);
2248                 if (IsFailed(r))
2249                 {
2250                         ShowError(r, METHOD_FILE_LINENO);
2251                         goto FAIL;
2252                 }
2253                 __isoIndex = index;
2254         }
2255         else if (&source == __pListViewWhitebalance)
2256         {
2257                 int tempVal = 0;
2258                 __pListViewWhitebalance->Draw();
2259                 if (__wbIndex == index)
2260                 {
2261                         r = __pListViewWhitebalance->SetItemChecked(index, true);
2262                         if (IsFailed(r))
2263                         {
2264                                 ShowError(r, METHOD_FILE_LINENO);
2265                                 goto FAIL;
2266                         }
2267                         return;
2268                 }
2269                 r = __pWbList->GetAt(index, tempVal);
2270                 if (IsFailed(r))
2271                 {
2272                         ShowError(r, METHOD_FILE_LINENO);
2273                         goto FAIL;
2274                 }
2275                 AppLog("__pWbList->GetAt: tempVal = %d, r = %s", tempVal, GetErrorMessage(r));
2276
2277                 r = __pCamera->SetWhiteBalance((CameraWhiteBalance) tempVal);
2278                 if (IsFailed(r))
2279                 {
2280                         ShowError(r, METHOD_FILE_LINENO);
2281                         __pListViewWhitebalance->SetItemChecked(index, false);
2282                         __pListViewWhitebalance->SetItemChecked(GetIndexFromValue(__pWbList, __pCamera->GetWhiteBalance()), true);
2283                         goto FAIL;
2284                 }
2285
2286                 r = __pListViewWhitebalance->SetItemChecked(__wbIndex, false);
2287                 if (IsFailed(r))
2288                 {
2289                         ShowError(r, METHOD_FILE_LINENO);
2290                         goto FAIL;
2291                 }
2292                 __wbIndex = index;
2293         }
2294         else if (&source == __pListViewFrameRate)
2295         {
2296                 int tempVal = 0;
2297                 __pListViewFrameRate->Draw();
2298                 if (__camType == CAMERA_PRIMARY && __frameRateIndex == index)
2299                 {
2300                         r = __pListViewFrameRate->SetItemChecked(index, true);
2301                         if (IsFailed(r))
2302                         {
2303                                 ShowError(r, METHOD_FILE_LINENO);
2304                                 goto FAIL;
2305                         }
2306                         return;
2307                 }
2308                 if (__camType == CAMERA_SECONDARY && __frameRateIndexSec == index)
2309                 {
2310                         r = __pListViewFrameRate->SetItemChecked(index, true);
2311                         if (IsFailed(r))
2312                         {
2313                                 ShowError(r, METHOD_FILE_LINENO);
2314                                 goto FAIL;
2315                         }
2316                         return;
2317                 }
2318
2319                 r = __pPreviewFrameRateList->GetAt(index, tempVal);
2320                 if (IsFailed(r))
2321                 {
2322                         ShowError(r, METHOD_FILE_LINENO);
2323                         goto FAIL;
2324                 }
2325
2326                 r = __pCamera->StopPreview();
2327                 if (IsFailed(r))
2328                 {
2329                         ShowError(r, METHOD_FILE_LINENO);
2330                         goto FAIL;
2331                 }
2332
2333                 r = __pCamera->SetPreviewFrameRate(tempVal);
2334                 if (IsFailed(r))
2335                 {
2336                         ShowError(r, METHOD_FILE_LINENO);
2337                         goto FAIL;
2338                 }
2339
2340                 r = __pOverlay->GetBackgroundBufferInfo(__bufferInfo);
2341                 if (IsFailed(r))
2342                 {
2343                         ShowError(r, METHOD_FILE_LINENO);
2344                         goto FAIL;
2345                 }
2346
2347                 if (__previewByCallback == 1)
2348                 {
2349                         r = __pCamera->StartPreview(NULL, true);
2350                         if (IsFailed(r))
2351                         {
2352                                 ShowError(r, METHOD_FILE_LINENO);
2353                                 goto FAIL;
2354                         }
2355                 }
2356                 else
2357                 {
2358                         r = __pCamera->StartPreview(&__bufferInfo, false);
2359                         if (IsFailed(r))
2360                         {
2361                                 ShowError(r, METHOD_FILE_LINENO);
2362                                 goto FAIL;
2363                         }
2364                 }
2365
2366                 r = __pListViewFrameRate->SetItemChecked((__camType == CAMERA_PRIMARY ? __frameRateIndex : __frameRateIndexSec), false);
2367                 if (IsFailed(r))
2368                 {
2369                         ShowError(r, METHOD_FILE_LINENO);
2370                         goto FAIL;
2371                 }
2372
2373                 (__camType == CAMERA_PRIMARY) ? __frameRateIndex = index : __frameRateIndexSec = index;
2374                 (__camType == CAMERA_PRIMARY) ? __pConfig->SetValue(SECTION_NAME, String(L"framerate"), tempVal) : __pConfig->SetValue(SECTION_NAME, String(L"framerateSec"), tempVal); //
2375         }
2376         else if (&source == __pListViewRecordingResolution)
2377         {
2378                 Dimension* pResolution = static_cast< Dimension* >(__pRecordingResolutionList->GetAt(index));
2379                 if (pResolution == null)
2380                 {
2381                         ShowError(E_FAILURE, METHOD_FILE_LINENO);
2382                         r = E_FAILURE;
2383                         goto FAIL;
2384                 }
2385                 __pListViewRecordingResolution->Draw();
2386
2387                 if (__camType == CAMERA_PRIMARY && __resolutionIndex == index)
2388                 {
2389                         r = __pListViewRecordingResolution->SetItemChecked(index, true);
2390                         if (IsFailed(r))
2391                         {
2392                                 ShowError(r, METHOD_FILE_LINENO);
2393                                 goto FAIL;
2394                         }
2395                         return;
2396                 }
2397                 if (__camType == CAMERA_SECONDARY && __resolutionIndexSec == index)
2398                 {
2399                         r = __pListViewRecordingResolution->SetItemChecked(index, true);
2400                         if (IsFailed(r))
2401                         {
2402                                 ShowError(r, METHOD_FILE_LINENO);
2403                                 goto FAIL;
2404                         }
2405                         return;
2406                 }
2407
2408                 r = __pCamera->StopPreview();
2409                 if (IsFailed(r))
2410                 {
2411                         ShowError(r, METHOD_FILE_LINENO);
2412                         goto FAIL;
2413                 }
2414
2415                 r = __pCamera->SetPreviewResolution(*pResolution);
2416                 if (IsFailed(r))
2417                 {
2418                         ShowError(r, METHOD_FILE_LINENO);
2419                         goto FAIL;
2420                 }
2421
2422                 r = __pOverlay->GetBackgroundBufferInfo(__bufferInfo);
2423                 if (IsFailed(r))
2424                 {
2425                         ShowError(r, METHOD_FILE_LINENO);
2426                         goto FAIL;
2427                 }
2428
2429                 if (__previewByCallback == 1)
2430                 {
2431                         r = __pCamera->StartPreview(NULL, true);
2432                         if (IsFailed(r))
2433                         {
2434                                 ShowError(r, METHOD_FILE_LINENO);
2435                                 goto FAIL;
2436                         }
2437                 }
2438                 else
2439                 {
2440                         r = __pCamera->StartPreview(&__bufferInfo, false);
2441                         if (IsFailed(r))
2442                         {
2443                                 ShowError(r, METHOD_FILE_LINENO);
2444                                 goto FAIL;
2445                         }
2446                 }
2447
2448                 r = __pListViewRecordingResolution->SetItemChecked((__camType == CAMERA_PRIMARY ? __resolutionIndex : __resolutionIndexSec), false);
2449                 if (IsFailed(r))
2450                 {
2451                         ShowError(r, METHOD_FILE_LINENO);
2452                         goto FAIL;
2453                 }
2454
2455                 (__camType == CAMERA_PRIMARY) ? __resolutionIndex = index : __resolutionIndexSec = index;
2456                 (__camType == CAMERA_PRIMARY) ? __pConfig->SetValue(SECTION_NAME, String(L"resolutionWidth"), pResolution->width) : __pConfig->SetValue(SECTION_NAME, String(L"resolutionWidthSec"), pResolution->width); //
2457                 (__camType == CAMERA_PRIMARY) ? __pConfig->SetValue(SECTION_NAME, String(L"resolutionHeight"), pResolution->height) : __pConfig->SetValue(SECTION_NAME, String(L"resolutionHeightSec"), pResolution->height); //
2458         }
2459         else if (&source == __pListViewQuality)
2460         {
2461                 __pListViewQuality->Draw();
2462                 if (__qualityIndex == index)
2463                 {
2464                         r = __pListViewQuality->SetItemChecked(index, true);
2465                         if (IsFailed(r))
2466                         {
2467                                 ShowError(r, METHOD_FILE_LINENO);
2468                                 goto FAIL;
2469                         }
2470                         return;
2471                 }
2472
2473                 r = __pListViewQuality->SetItemChecked(__qualityIndex, false);
2474                 if (IsFailed(r))
2475                 {
2476                         ShowError(r, METHOD_FILE_LINENO);
2477                         goto FAIL;
2478                 }
2479                 __qualityIndex = index;
2480                 __pConfig->SetValue(SECTION_NAME, String(L"quality"), __qualityIndex);
2481         }
2482         else if (&source == __pListViewVideoCodec)
2483         {
2484                 CodecType videoCodec = CODEC_NONE;
2485                 __pListViewVideoCodec->Draw();
2486                 if (__videoCodecIndex == index)
2487                 {
2488                         r = __pListViewVideoCodec->SetItemChecked(index, true);
2489                         if (IsFailed(r))
2490                         {
2491                                 ShowError(r, METHOD_FILE_LINENO);
2492                                 goto FAIL;
2493                         }
2494                         return;
2495                 }
2496
2497                 r = __pListViewVideoCodec->SetItemChecked(__videoCodecIndex, false);
2498                 if (IsFailed(r))
2499                 {
2500                         ShowError(r, METHOD_FILE_LINENO);
2501                         goto FAIL;
2502                 }
2503                 __videoCodecIndex = index;
2504                 r = __pRecorderVideoCodecList->GetAt(__videoCodecIndex, videoCodec);
2505                 if (IsFailed(r))
2506                 {
2507                         ShowError(r, METHOD_FILE_LINENO);
2508                         goto FAIL;
2509                 }
2510
2511                 __pConfig->SetValue(SECTION_NAME, String(L"videocodec"), videoCodec);
2512         }
2513         else if (&source == __pListViewAudioCodec)
2514         {
2515                 CodecType audioCodec = CODEC_NONE;
2516                 __pListViewAudioCodec->Draw();
2517                 if (__audioCodecIndex == index)
2518                 {
2519                         r = __pListViewAudioCodec->SetItemChecked(index, true);
2520                         if (IsFailed(r))
2521                         {
2522                                 ShowError(r, METHOD_FILE_LINENO);
2523                                 goto FAIL;
2524                         }
2525                         return;
2526                 }
2527
2528                 r = __pListViewAudioCodec->SetItemChecked(__audioCodecIndex, false);
2529                 if (IsFailed(r))
2530                 {
2531                         ShowError(r, METHOD_FILE_LINENO);
2532                         goto FAIL;
2533                 }
2534                 __audioCodecIndex = index;
2535                 r = __pRecorderAudioCodecList->GetAt(__audioCodecIndex, audioCodec);
2536                 if (IsFailed(r))
2537                 {
2538                         ShowError(r, METHOD_FILE_LINENO);
2539                         goto FAIL;
2540                 }
2541                 __pConfig->SetValue(SECTION_NAME, String(L"audiocodec"), audioCodec);
2542         }
2543         else if (&source == __pListViewFileFormat)
2544         {
2545                 MediaContainerType container = MEDIA_CONTAINER_NONE;
2546                 __pListViewFileFormat->Draw();
2547                 if (__formatIndex == index)
2548                 {
2549                         r = __pListViewFileFormat->SetItemChecked(index, true);
2550                         if (IsFailed(r))
2551                         {
2552                                 ShowError(r, METHOD_FILE_LINENO);
2553                                 goto FAIL;
2554                         }
2555                         return;
2556                 }
2557
2558                 r = __pListViewFileFormat->SetItemChecked(__formatIndex, false);
2559                 if (IsFailed(r))
2560                 {
2561                         ShowError(r, METHOD_FILE_LINENO);
2562                         goto FAIL;
2563                 }
2564                 __formatIndex = index;
2565                 r = __pRecorderVideoContainerList->GetAt(__formatIndex, container);
2566                 if (IsFailed(r))
2567                 {
2568                         ShowError(r, METHOD_FILE_LINENO);
2569                         goto FAIL;
2570                 }
2571                 __pConfig->SetValue(SECTION_NAME, String(L"fileformat"), container);
2572         }
2573         else if (&source == __pListViewFlipType)
2574         {
2575                 __pListViewFlipType->Draw();
2576                 if (__flipType == index)
2577                 {
2578                         r = __pListViewFlipType->SetItemChecked(index, true);
2579                         if (IsFailed(r))
2580                         {
2581                                 ShowError(r, METHOD_FILE_LINENO);
2582                                 goto FAIL;
2583                         }
2584                         return;
2585                 }
2586                 r = __pListViewFlipType->SetItemChecked(__flipType, false);
2587                 if (IsFailed(r))
2588                 {
2589                         ShowError(r, METHOD_FILE_LINENO);
2590                         goto FAIL;
2591                 }
2592                 __flipType = (CameraFlipType) index;
2593                 AppLog("flip type = %d selected", index);
2594         }
2595         else if (&source == __pListViewSetting)
2596         {
2597                 HidePopUp(__pPopupSetting);
2598                 switch (elementId)
2599                 {
2600                 case ID_MENU_BRIGHTNESS:
2601                         CreateBrightnessSlider();
2602                         break;
2603
2604                 case ID_MENU_EXPOSURE:
2605                         CreateExposureSlider();
2606                         break;
2607
2608                 case ID_MENU_CONTRAST:
2609                         CreateContrastSlider();
2610                         break;
2611
2612                 case ID_MENU_EFFECT:
2613                         CreateEffect();
2614                         break;
2615
2616                 case ID_MENU_ISOLEVEL:
2617                         CreateISO();
2618                         break;
2619
2620                 case ID_MENU_WHITEBALANCE:
2621                         CreateWhiteBalance();
2622                         break;
2623
2624                 case ID_MENU_ZOOMLEVEL:
2625                         CreateZoomLevelSlider();
2626                         break;
2627
2628                 case ID_MENU_FRAME_RATE:
2629                         CreateFrameRate();
2630                         break;
2631
2632                 case ID_MENU_RECORDING_RESOLUTION:
2633                         CreateRecordingResolution();
2634                         break;
2635
2636                 case ID_MENU_RECORDING_QUALITY:
2637                         CreateQuality();
2638                         break;
2639
2640                 case ID_MENU_VIDEO_CODEC:
2641                         CreateVideoCodec();
2642                         break;
2643
2644                 case ID_MENU_AUDIO_CODEC:
2645                         CreateAudioCodec();
2646                         break;
2647
2648                 case ID_MENU_FILE_FORMAT:
2649                         CreateFileFormat();
2650                         break;
2651
2652                 case ID_MENU_FLIP_TYPE:
2653                         CreateFlip();
2654                         break;
2655                 }
2656         }
2657
2658         return;
2659 FAIL:
2660         if (&source == __pListViewRecordingResolution)
2661         {
2662                 __pListViewRecordingResolution->Draw();
2663                 __pListViewRecordingResolution->SetItemChecked(index, false);
2664         }
2665         return;
2666 }
2667
2668 bool
2669 VideoRecorderForm::CreateEffect()
2670 {
2671         result r = E_SUCCESS;
2672         IList* pList = null;
2673         int effectCount = 0;
2674         int index = 0;
2675         const mchar* EffectMap[] =
2676         {
2677                 L"NONE",
2678                 L"COLOR",
2679                 L"BW",
2680                 L"SEPIA",
2681                 L"SOLARIZE",
2682                 L"NEGATIVE",
2683                 L"NIGHT",
2684         };
2685
2686         DeletePopup(&__pPopupEffect);
2687
2688         SAFE_DELETE_ARRAYLISTT(__pEffectList);
2689
2690         if (null == __pPopupEffect)
2691         {
2692                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
2693                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
2694                 r = CreatePopUp(&__pPopupEffect, L"Effect", dim, true);
2695                 if (IsFailed(r))
2696                 {
2697                         goto FAIL;
2698                 }
2699                 r = AddButton(&__pButnEffectOK, L"OK", ID_BUTTON_EFFECT_OK, __pPopupEffect, rect);
2700                 if (IsFailed(r))
2701                 {
2702                         goto FAIL;
2703                 }
2704
2705                 if (__camType == CAMERA_PRIMARY)
2706                 {
2707                         pList = MediaCapability::GetValueN(CAMERA_PRIMARY_EFFECT);
2708                 }
2709                 else
2710                 {
2711                         pList = MediaCapability::GetValueN(CAMERA_SECONDARY_EFFECT);
2712                 }
2713
2714                 if (pList && pList->GetCount() > 0)
2715                 {
2716                         effectCount = pList->GetCount();
2717
2718                         SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
2719                         __pSettingItemArrayList = new (std::nothrow) ArrayList;
2720                         __pEffectList = new (std::nothrow) ArrayListT< int >;
2721                         for (index = 0; index < effectCount; index++)
2722                         {
2723                                 Osp::Base::Integer* effectObj = (Osp::Base::Integer*) pList->GetAt(index);
2724                                 int effectType = effectObj ? effectObj->ToInt() : -1;
2725
2726                                 if (effectType <= 6 && effectType != -1)
2727                                 {
2728                                         SettingListData* pItemData = new (std::nothrow) SettingListData(new String(EffectMap[effectType]), effectType);
2729                                         __pSettingItemArrayList->Add(*pItemData);
2730                                         __pEffectList->Add(effectType);
2731                                         AppLog("effect return is = %d VALUE = %ls", effectType, EffectMap[effectType]);
2732                                 }
2733                                 else
2734                                 {
2735                                         AppLog("effect is out of range");
2736                                 }
2737                         }
2738                         r = E_SUCCESS;
2739                         SAFE_DELETE_ARRAYLIST(pList);
2740                 }
2741         }
2742
2743         r = AddListView(&__pListViewEffect, __pPopupEffect, ID_BUTTON_EFFECT_OK);
2744         if (IsFailed(r))
2745         {
2746                 goto FAIL;
2747         }
2748
2749         __effectIndex = GetIndexFromValue(__pEffectList, __pCamera->GetEffect());
2750         if (__effectIndex == INIT)
2751         {
2752                 goto FAIL;
2753         }
2754
2755         ShowPopUp(__pPopupEffect);
2756         __pListViewEffect->Draw();
2757         __pListViewEffect->SetItemChecked(GetIndexFromValue(__pEffectList, __pCamera->GetEffect()), true);
2758         return true;
2759
2760 FAIL:
2761         DeletePopup(&__pPopupEffect);
2762         SAFE_DELETE_ARRAYLISTT(__pEffectList);
2763         AppLog("%s", GetErrorMessage(r));
2764         return false;
2765 }
2766
2767 bool
2768 VideoRecorderForm::CreateISO()
2769 {
2770         result r = E_SUCCESS;
2771         IList* pList = null;
2772         int isoCount = 0;
2773         int index = 0;
2774         int isoIndex = 0;
2775         const mchar* isoMap[] =
2776         {
2777                 L"CAMERA_ISO_DEFAULT",          //< The device dependent default ISO level
2778                 L"CAMERA_ISO_MIN",              //< The minimum supported ISO level
2779                 L"AUTO",                        //< The auto ISO level
2780                 L"50",                          //< The ISO 50 level
2781                 L"100",                         //< The ISO 100 level
2782                 L"200",                         //< The ISO 200 level
2783                 L"400",                         //< The ISO 400 level
2784                 L"800",                         //< The ISO 800 level
2785                 L"1600",                        //< The ISO 1600 level
2786                 L"CAMERA_ISO_MAX"               //< The maximum supported ISO level
2787         };
2788         DeletePopup(&__pPopupIso);
2789         SAFE_DELETE_ARRAYLISTT(__pIsoList);
2790
2791         if (null == __pPopupIso)
2792         {
2793                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
2794                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
2795                 r = CreatePopUp(&__pPopupIso, L"Iso", dim, true);
2796                 if (IsFailed(r))
2797                 {
2798                         goto FAIL;
2799                 }
2800
2801                 r = AddButton(&__pButnIsoOK, L"OK", ID_BUTTON_ISO_OK, __pPopupIso, rect);
2802                 if (IsFailed(r))
2803                 {
2804                         goto FAIL;
2805                 }
2806
2807                 SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
2808                 __pSettingItemArrayList = new (std::nothrow) ArrayList;
2809                 __pIsoList = new (std::nothrow) ArrayListT< int >;
2810
2811                 // Adding DEFAULT and MIN values to the iso list, since these won't
2812                 // be returned by the capability class.
2813                 for (index = 0; index < 2; index++)
2814                 {
2815                         String* pIsoStrValue = new (std::nothrow) String(isoMap[index]);
2816                         SettingListData* pItemData = new (std::nothrow) SettingListData(pIsoStrValue, 0);
2817                         __pSettingItemArrayList->Add(*pItemData);
2818                         __pIsoList->Add(index);
2819                         AppLog("ISO return is = %d VALUE = %ls", index, pIsoStrValue->GetPointer());
2820                 }
2821
2822                 if (__camType == CAMERA_PRIMARY)
2823                 {
2824                         pList = MediaCapability::GetValueN(CAMERA_PRIMARY_ISO_LEVEL);
2825                 }
2826                 else
2827                 {
2828                         pList = MediaCapability::GetValueN(CAMERA_SECONDARY_ISO_LEVEL);
2829                 }
2830
2831                 if (pList && pList->GetCount() > 0)
2832                 {
2833                         isoCount = pList->GetCount();
2834                         for (index = 0; index < isoCount; index++)
2835                         {
2836                                 Osp::Base::Integer* isoObj = (Osp::Base::Integer*) pList->GetAt(index);
2837
2838                                 int isoType = isoObj ? isoObj->ToInt() : -1;
2839                                 if (isoType > 0 && isoType < 9)
2840                                 {
2841                                         String* pIsoStrValue = new (std::nothrow) String(isoMap[isoType]);
2842                                         SettingListData* pItemData = new (std::nothrow) SettingListData(pIsoStrValue, isoType);
2843                                         __pSettingItemArrayList->Add(*pItemData);
2844                                         __pIsoList->Add(isoType);
2845                                         AppLog("ISO return is = %d VALUE = %ls", isoType, pIsoStrValue->GetPointer());
2846                                 }
2847                                 else
2848                                 {
2849                                         AppLog("isoType out of range");
2850                                 }
2851                         }
2852                         r = E_SUCCESS;
2853                         pList->RemoveAll(true);
2854                         delete pList;
2855                 }
2856
2857         }
2858
2859         r = AddListView(&__pListViewIso, __pPopupIso, ID_BUTTON_ISO_OK);
2860         if (IsFailed(r))
2861         {
2862                 goto FAIL;
2863         }
2864
2865         isoIndex = GetIndexFromValue(__pIsoList, __pCamera->GetIsoLevel());
2866
2867         if (isoIndex == INIT)
2868         {
2869                 goto FAIL;
2870         }
2871
2872         __isoIndex = isoIndex;
2873
2874         ShowPopUp(__pPopupIso);
2875         __pListViewIso->Draw();
2876         __pListViewIso->SetItemChecked(isoIndex, true);
2877
2878         return true;
2879 FAIL:
2880         DeletePopup(&__pPopupIso);
2881         SAFE_DELETE_ARRAYLISTT(__pIsoList);
2882         AppLog("%s", GetErrorMessage(r));
2883         return false;
2884 }
2885
2886 bool
2887 VideoRecorderForm::CreateWhiteBalance()
2888 {
2889         result r = E_SUCCESS;
2890         IList* pList = null;
2891         int wbCount = 0;
2892         int index = 0;
2893         int wbIndex = 0;
2894         const mchar* whitebalance[] =
2895         {
2896                 L"Auto",
2897                 L"Sunny",
2898                 L"Cloudy",
2899                 L"Fluorescent",
2900                 L"Tungsten"
2901         };
2902         DeletePopup(&__pPopupWhiteBalance);
2903         SAFE_DELETE_ARRAYLISTT(__pWbList);
2904
2905         if (null == __pPopupWhiteBalance)
2906         {
2907                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
2908                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
2909                 r = CreatePopUp(&__pPopupWhiteBalance, L"White Balance", dim, true);
2910                 if (IsFailed(r))
2911                 {
2912                         goto FAIL;
2913                 }
2914
2915                 r = AddButton(&__pButnWhitebalanceOK, L"OK", ID_BUTTON_WHITEBALANCE_OK, __pPopupWhiteBalance, rect);
2916                 if (IsFailed(r))
2917                 {
2918                         goto FAIL;
2919                 }
2920
2921                 if (__camType == CAMERA_PRIMARY)
2922                 {
2923                         pList = MediaCapability::GetValueN(CAMERA_PRIMARY_WHITE_BALANCE);
2924                 }
2925                 else
2926                 {
2927                         pList = MediaCapability::GetValueN(CAMERA_SECONDARY_WHITE_BALANCE);
2928                 }
2929
2930
2931                 if (pList && pList->GetCount() > 0)
2932                 {
2933                         wbCount = pList->GetCount();
2934                         SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
2935                         __pSettingItemArrayList = new (std::nothrow) ArrayList;
2936                         __pWbList = new (std::nothrow) ArrayListT< int >;
2937                         for (index = 0; index < wbCount; index++)
2938                         {
2939                                 Osp::Base::Integer* wbObj = (Osp::Base::Integer*) pList->GetAt(index);
2940
2941                                 int wbType = wbObj ? wbObj->ToInt() : -1;
2942                                 if (wbType >= 0 && wbType <= 4)
2943                                 {
2944                                         String* pWbStrValue = new (std::nothrow) String(whitebalance[wbType]);
2945                                         SettingListData* pItemData = new (std::nothrow) SettingListData(pWbStrValue, wbType);
2946                                         __pSettingItemArrayList->Add(*pItemData);
2947                                         __pWbList->Add(wbType);
2948                                         AppLog("wb return is = %d VALUE = %ls", wbType, pWbStrValue->GetPointer());
2949                                 }
2950                                 else
2951                                 {
2952                                         AppLog("wb out of range");
2953                                 }
2954                         }
2955                         r = E_SUCCESS;
2956                         pList->RemoveAll(true);
2957                         delete pList;
2958                 }
2959
2960         }
2961
2962         r = AddListView(&__pListViewWhitebalance, __pPopupWhiteBalance, ID_BUTTON_WHITEBALANCE_OK);
2963         if (IsFailed(r))
2964         {
2965                 goto FAIL;
2966         }
2967
2968         wbIndex = GetIndexFromValue(__pWbList, __pCamera->GetWhiteBalance());
2969
2970         if (wbIndex == INIT)
2971         {
2972                 goto FAIL;
2973         }
2974
2975         __wbIndex = wbIndex;
2976
2977         ShowPopUp(__pPopupWhiteBalance);
2978         __pListViewWhitebalance->Draw();
2979         __pListViewWhitebalance->SetItemChecked(wbIndex, true);
2980
2981         return true;
2982
2983 FAIL:
2984         DeletePopup(&__pPopupWhiteBalance);
2985         SAFE_DELETE_ARRAYLISTT(__pWbList);
2986         AppLog("%s", GetErrorMessage(r));
2987         return false;
2988 }
2989
2990 bool
2991 VideoRecorderForm::CreateFrameRate()
2992 {
2993         result r = E_SUCCESS;
2994         int fpsCount = 0;
2995         int index = 0;
2996         int fpsIndex = 0;
2997
2998         DeletePopup(&__pPopupFrameRate);
2999
3000         if (null == __pPopupFrameRate)
3001         {
3002                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
3003                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
3004                 r = CreatePopUp(&__pPopupFrameRate, L"Frame Rate", dim, true);
3005                 if (IsFailed(r))
3006                 {
3007                         goto FAIL;
3008                 }
3009
3010                 r = AddButton(&__pButnFrameRateOK, L"OK", ID_BUTTON_FRAMERATE_OK, __pPopupFrameRate, rect);
3011                 if (IsFailed(r))
3012                 {
3013                         goto FAIL;
3014                 }
3015
3016                 if (__pPreviewFrameRateList && __pPreviewFrameRateList->GetCount() > 0)
3017                 {
3018                         fpsCount = __pPreviewFrameRateList->GetCount();
3019                         SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3020                         __pSettingItemArrayList = new (std::nothrow) ArrayList;
3021                         AppLog("fps count = %d", fpsCount);
3022                         for (index = 0; index < fpsCount; index++)
3023                         {
3024                                 int fpsType = INIT;
3025                                 r = __pPreviewFrameRateList->GetAt(index, fpsType);
3026
3027                                 if (fpsType > 0 && r == E_SUCCESS)
3028                                 {
3029                                         String* pfpsStrValue = new (std::nothrow) String();
3030                                         pfpsStrValue->Append(fpsType);
3031                                         SettingListData* pItemData = new (std::nothrow) SettingListData(pfpsStrValue, index);
3032                                         __pSettingItemArrayList->Add(*pItemData);
3033                                         AppLog("FPS return is = %d VALUE = %ls", fpsType, pfpsStrValue->GetPointer());
3034                                 }
3035                         }
3036                 }
3037         }
3038
3039         r = AddListView(&__pListViewFrameRate, __pPopupFrameRate, ID_BUTTON_FRAMERATE_OK);
3040         if (IsFailed(r))
3041         {
3042                 goto FAIL;
3043         }
3044
3045         fpsIndex = GetIndexFromValue(__pPreviewFrameRateList, __pCamera->GetPreviewFrameRate());
3046         if (fpsIndex == INIT)
3047         {
3048                 goto FAIL;
3049         }
3050
3051         if (__camType == CAMERA_PRIMARY)
3052         {
3053                 __frameRateIndex = fpsIndex;
3054         }
3055         else
3056         {
3057                 __frameRateIndexSec = fpsIndex;
3058         }
3059
3060         ShowPopUp(__pPopupFrameRate);
3061         __pListViewFrameRate->Draw();
3062         __pListViewFrameRate->SetItemChecked(fpsIndex, true);
3063
3064         return true;
3065
3066 FAIL:
3067         DeletePopup(&__pPopupFrameRate);
3068         SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3069         AppLog("%s", GetErrorMessage(r));
3070         return false;
3071 }
3072
3073 bool
3074 VideoRecorderForm::CreateRecordingResolution()
3075 {
3076         result r = E_SUCCESS;
3077         Dimension* dim = null;
3078         String* pRecordingResolutionStrValue = null;
3079         SettingListData* pItemData = null;
3080         Dimension recordingdim;
3081         DeletePopup(&__pPopupRecordingResolution);
3082         if (null == __pPopupRecordingResolution)
3083         {
3084                 Dimension dimn(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
3085                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
3086
3087                 int recordResCount = __pRecordingResolutionList->GetCount();
3088
3089                 SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3090
3091                 if (recordResCount > 0)
3092                 {
3093                         __pSettingItemArrayList = new (std::nothrow) ArrayList;
3094                 }
3095                 else
3096                 {
3097                         return false;
3098                 }
3099
3100                 r = CreatePopUp(&__pPopupRecordingResolution, L"Recording Resolution", dimn, true);
3101                 if (IsFailed(r))
3102                 {
3103                         goto FAIL;
3104                 }
3105
3106                 r = AddButton(&__pButnRecordingResolutionOK, L"OK", ID_BUTTON_RECORDINGRESOLUTION_OK, __pPopupRecordingResolution, rect);
3107                 if (IsFailed(r))
3108                 {
3109                         goto FAIL;
3110                 }
3111
3112                 for (int count = 0; count < recordResCount; count++)
3113                 {
3114                         String strTemp;
3115                         dim = (Dimension*) __pRecordingResolutionList->GetAt(count);
3116                         if (dim == null)
3117                         {
3118                                 goto FAIL;
3119                         }
3120
3121                         strTemp.Append(dim->width);
3122                         strTemp.Append(L"x");
3123                         strTemp.Append(dim->height);
3124
3125                         pRecordingResolutionStrValue = new (std::nothrow) String(strTemp);
3126                         pItemData = new (std::nothrow) SettingListData(pRecordingResolutionStrValue, count);
3127                         __pSettingItemArrayList->Add(*pItemData);
3128                 }
3129
3130                 r = AddListView(&__pListViewRecordingResolution, __pPopupRecordingResolution, ID_BUTTON_RECORDINGRESOLUTION_OK);
3131                 if (IsFailed(r))
3132                 {
3133                         goto FAIL;
3134                 }
3135         }
3136
3137         ShowPopUp(__pPopupRecordingResolution);
3138         __pListViewRecordingResolution->Draw();
3139         if (__camType == CAMERA_PRIMARY)
3140         {
3141                 __pListViewRecordingResolution->SetItemChecked(__resolutionIndex, true);
3142         }
3143         else
3144         {
3145                 __pListViewRecordingResolution->SetItemChecked(__resolutionIndexSec, true);
3146         }
3147
3148         return true;
3149 FAIL:
3150         DeletePopup(&__pPopupRecordingResolution);
3151         AppLog("%s", GetErrorMessage(r));
3152         return false;
3153 }
3154
3155 bool
3156 VideoRecorderForm::CreateQuality()
3157 {
3158         result r = E_SUCCESS;
3159
3160         if (__pPopupRecordingQuality == null)
3161         {
3162                 String strTemp;
3163                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
3164                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
3165
3166                 r = CreatePopUp(&__pPopupRecordingQuality, L"Recording Quality", dim, true);
3167                 if (IsFailed(r))
3168                 {
3169                         goto FAIL;
3170                 }
3171
3172                 r = AddButton(&__pButnQualityOK, L"OK", ID_BUTTON_QUALITY_OK, __pPopupRecordingQuality, rect);
3173                 if (IsFailed(r))
3174                 {
3175                         goto FAIL;
3176                 }
3177
3178                 SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3179
3180                 __pSettingItemArrayList = new (std::nothrow) ArrayList;
3181
3182                 String* pQualityStrValue = new (std::nothrow) String(L"Low");
3183                 SettingListData* pItemData = new (std::nothrow) SettingListData(pQualityStrValue, RECORDING_QUALITY_LOW);
3184                 __pSettingItemArrayList->Add(*pItemData);
3185
3186                 pQualityStrValue = new (std::nothrow) String(L"Medium");
3187                 pItemData = new (std::nothrow) SettingListData(pQualityStrValue, RECORDING_QUALITY_MEDIUM);
3188                 __pSettingItemArrayList->Add(*pItemData);
3189
3190                 pQualityStrValue = new (std::nothrow) String(L"High");
3191                 pItemData = new (std::nothrow) SettingListData(pQualityStrValue, RECORDING_QUALITY_HIGH);
3192                 __pSettingItemArrayList->Add(*pItemData);
3193
3194                 r = AddListView(&__pListViewQuality, __pPopupRecordingQuality, ID_BUTTON_QUALITY_OK);
3195                 if (IsFailed(r))
3196                 {
3197                         goto FAIL;
3198                 }
3199         }
3200
3201         if (__qualityIndex == INIT)
3202         {
3203                 goto FAIL;
3204         }
3205
3206         ShowPopUp(__pPopupRecordingQuality);
3207         __pListViewQuality->Draw();
3208         __pListViewQuality->SetItemChecked(__qualityIndex, true);
3209
3210         return true;
3211 FAIL:
3212         DeletePopup(&__pPopupRecordingQuality);
3213         AppLog("%s", GetErrorMessage(r));
3214
3215         return false;
3216 }
3217
3218 bool
3219 VideoRecorderForm::CreateVideoCodec()
3220 {
3221         result r = E_SUCCESS;
3222         String strTemp;
3223         String* pVideoCodecStrValue = null;
3224         SettingListData* pItemData = null;
3225         DeletePopup(&__pPopupVideoCodec);
3226         if (__pPopupVideoCodec == null)
3227         {
3228                 int count = __pRecorderVideoCodecList->GetCount();
3229                 CodecType tempCodec = CODEC_NONE;
3230                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
3231                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
3232
3233
3234                 SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3235
3236                 if (count > 0)
3237                 {
3238                         __pSettingItemArrayList = new (std::nothrow) ArrayList;
3239                 }
3240                 else
3241                 {
3242                         return false;
3243                 }
3244
3245                 r = CreatePopUp(&__pPopupVideoCodec, L"Video Codec", dim, true);
3246                 if (IsFailed(r))
3247                 {
3248                         ShowError(r, METHOD_FILE_LINENO);
3249                         goto FAIL;
3250                 }
3251
3252                 r = AddButton(&__pButnVideoCodecOK, L"OK", ID_BUTTON_VIDEOCODEC_OK, __pPopupVideoCodec, rect);
3253                 if (IsFailed(r))
3254                 {
3255                         ShowError(r, METHOD_FILE_LINENO);
3256                         goto FAIL;
3257                 }
3258
3259                 for (int i = 0; i < count; i++)
3260                 {
3261                         r = __pRecorderVideoCodecList->GetAt(i, tempCodec);
3262                         if (IsFailed(r))
3263                         {
3264                                 ShowError(r, METHOD_FILE_LINENO);
3265                                 goto FAIL;
3266                         }
3267                         ConvertCodecToString(tempCodec, strTemp);
3268                         pVideoCodecStrValue = new (std::nothrow) String(strTemp);
3269                         pItemData = new (std::nothrow) SettingListData(pVideoCodecStrValue, i);
3270                         __pSettingItemArrayList->Add(*pItemData);
3271                 }
3272                 r = AddListView(&__pListViewVideoCodec, __pPopupVideoCodec, ID_BUTTON_VIDEOCODEC_OK);
3273                 if (IsFailed(r))
3274                 {
3275                         goto FAIL;
3276                 }
3277         }
3278
3279         ShowPopUp(__pPopupVideoCodec);
3280         __pListViewVideoCodec->Draw();
3281         __pListViewVideoCodec->SetItemChecked(__videoCodecIndex, true);
3282
3283         return true;
3284 FAIL:
3285         DeletePopup(&__pPopupVideoCodec);
3286         AppLog("%s", GetErrorMessage(r));
3287         return false;
3288 }
3289
3290 bool
3291 VideoRecorderForm::CreateAudioCodec()
3292 {
3293         result r = E_SUCCESS;
3294         String strTemp;
3295         String* pAudioCodecStrValue = null;
3296         SettingListData* pItemData = null;
3297         DeletePopup(&__pPopupAudioCodec);
3298         if (__pPopupAudioCodec == null)
3299         {
3300                 int count = __pRecorderAudioCodecList->GetCount();
3301                 CodecType tempCodec = CODEC_NONE;
3302                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
3303                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
3304
3305                 SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3306                 if (count > 0)
3307                 {
3308                         __pSettingItemArrayList = new (std::nothrow) ArrayList;
3309                 }
3310                 else
3311                 {
3312                         return false;
3313                 }
3314
3315                 r = CreatePopUp(&__pPopupAudioCodec, L"Audio Codec", dim, true);
3316                 if (IsFailed(r))
3317                 {
3318                         goto FAIL;
3319                 }
3320
3321                 r = AddButton(&__pButnAudioCodecOK, L"OK", ID_BUTTON_AUDIOCODEC_OK, __pPopupAudioCodec, rect);
3322                 if (IsFailed(r))
3323                 {
3324                         ShowError(r, METHOD_FILE_LINENO);
3325                         goto FAIL;
3326                 }
3327
3328                 for (int i = 0; i < count; i++)
3329                 {
3330                         r = __pRecorderAudioCodecList->GetAt(i, tempCodec);
3331                         if (IsFailed(r))
3332                         {
3333                                 ShowError(r, METHOD_FILE_LINENO);
3334                                 goto FAIL;
3335                         }
3336                         ConvertCodecToString(tempCodec, strTemp);
3337                         pAudioCodecStrValue = new (std::nothrow) String(strTemp);
3338                         pItemData = new (std::nothrow) SettingListData(pAudioCodecStrValue, i);
3339                         __pSettingItemArrayList->Add(*pItemData);
3340                 }
3341
3342                 r = AddListView(&__pListViewAudioCodec, __pPopupAudioCodec, ID_BUTTON_AUDIOCODEC_OK);
3343                 if (IsFailed(r))
3344                 {
3345                         goto FAIL;
3346                 }
3347         }
3348
3349         if (__audioCodecIndex == INIT)
3350         {
3351                 goto FAIL;
3352         }
3353         ShowPopUp(__pPopupAudioCodec);
3354         __pListViewAudioCodec->Draw();
3355         __pListViewAudioCodec->SetItemChecked(__audioCodecIndex, true);
3356
3357         return true;
3358 FAIL:
3359         DeletePopup(&__pPopupAudioCodec);
3360         SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3361         AppLog("%s", GetErrorMessage(r));
3362         return false;
3363 }
3364
3365
3366
3367 bool
3368 VideoRecorderForm::CreateFlip()
3369 {
3370         result r = E_SUCCESS;
3371         DeletePopup(&__pPopupFlip);
3372         if (__pPopupFlip == null)
3373         {
3374                 String strTemp;
3375                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
3376                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
3377
3378                 r = CreatePopUp(&__pPopupFlip, L"Flip Type", dim, true);
3379                 if (IsFailed(r))
3380                 {
3381                         goto FAIL;
3382                 }
3383
3384                 r = AddButton(&__pButnFlipTypeOK, L"OK", ID_BUTTON_FLIP_OK, __pPopupFlip, rect);
3385                 if (IsFailed(r))
3386                 {
3387                         ShowError(r, METHOD_FILE_LINENO);
3388                         goto FAIL;
3389                 }
3390
3391                 SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3392
3393                 __pSettingItemArrayList = new (std::nothrow) ArrayList;
3394
3395                 String* pFlipStrValue = new (std::nothrow) String(L"FLIP NONE");
3396                 SettingListData* pItemData = new (std::nothrow) SettingListData(pFlipStrValue, 0);
3397                 __pSettingItemArrayList->Add(*pItemData);
3398
3399                 pFlipStrValue = new (std::nothrow) String(L"FLIP HORIZONTAL");
3400                 pItemData = new (std::nothrow) SettingListData(pFlipStrValue, 1);
3401                 __pSettingItemArrayList->Add(*pItemData);
3402
3403                 pFlipStrValue = new (std::nothrow) String(L"FLIP VERTICAL");
3404                 pItemData = new (std::nothrow) SettingListData(pFlipStrValue, 2);
3405                 __pSettingItemArrayList->Add(*pItemData);
3406
3407                 r = AddListView(&__pListViewFlipType, __pPopupFlip, ID_BUTTON_FLIP_OK);
3408                 if (IsFailed(r))
3409                 {
3410                         goto FAIL;
3411                 }
3412         }
3413
3414         __flipType = __pCamera->GetFlip();
3415
3416         AppLog("Camera return flip type = %d", __flipType);
3417
3418         ShowPopUp(__pPopupFlip);
3419         __pListViewFlipType->Draw();
3420         __pListViewFlipType->SetItemChecked(__flipType, true);
3421
3422         return true;
3423 FAIL:
3424         DeletePopup(&__pPopupFlip);
3425         SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3426         AppLog("%s", GetErrorMessage(r));
3427         return false;
3428 }
3429
3430 bool
3431 VideoRecorderForm::CreateFileFormat()
3432 {
3433         result r = E_SUCCESS;
3434         String strTemp;
3435         String* pFileFormatStrValue = null;
3436         SettingListData* pItemData = null;
3437         DeletePopup(&__pPopupFileFormat);
3438         if (__pPopupFileFormat == null)
3439         {
3440                 int count = __pRecorderVideoContainerList->GetCount();
3441                 MediaContainerType tempFormat;
3442                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
3443                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
3444
3445                 r = CreatePopUp(&__pPopupFileFormat, L"File Format", dim, true);
3446                 if (IsFailed(r))
3447                 {
3448                         goto FAIL;
3449                 }
3450
3451                 r = AddButton(&__pButnFileFormatOK, L"OK", ID_BUTTON_FILEFORMAT_OK, __pPopupFileFormat, rect);
3452                 if (IsFailed(r))
3453                 {
3454                         goto FAIL;
3455                 }
3456                 SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3457                 if (count > 0)
3458                 {
3459                         __pSettingItemArrayList = new (std::nothrow) ArrayList;
3460                 }
3461                 else
3462                 {
3463                         return false;
3464                 }
3465
3466                 for (int i = 0; i < count; i++)
3467                 {
3468                         r = __pRecorderVideoContainerList->GetAt(i, tempFormat);
3469                         if (IsFailed(r))
3470                         {
3471                                 ShowError(r, METHOD_FILE_LINENO);
3472                                 goto FAIL;
3473                         }
3474                         ConvertContainerToString(tempFormat, strTemp);
3475                         if (0 == String::Compare(strTemp, String(L"WAV")))
3476                         {
3477                                 strTemp.Clear();
3478                                 strTemp.Append(L"Wave");
3479                         }
3480                         pFileFormatStrValue = new (std::nothrow) String(strTemp);
3481                         pItemData = new (std::nothrow) SettingListData(pFileFormatStrValue, i);
3482                         __pSettingItemArrayList->Add(*pItemData);
3483
3484                 }
3485
3486                 r = AddListView(&__pListViewFileFormat, __pPopupFileFormat, ID_BUTTON_FILEFORMAT_OK);
3487                 if (IsFailed(r))
3488                 {
3489                         goto FAIL;
3490                 }
3491         }
3492
3493         if (__formatIndex == INIT)
3494         {
3495                 goto FAIL;
3496         }
3497
3498         ShowPopUp(__pPopupFileFormat);
3499         __pListViewFileFormat->Draw();
3500         __pListViewFileFormat->SetItemChecked(__formatIndex, true);
3501
3502         return true;
3503 FAIL:
3504         DeletePopup(&__pPopupFileFormat);
3505         SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3506         AppLog("%s", GetErrorMessage(r));
3507         return false;
3508 }
3509
3510 bool
3511 VideoRecorderForm::CreateSettingPopUp()
3512 {
3513         result r = E_SUCCESS;
3514         bool value = false;
3515
3516         DeletePopup(&__pPopupSetting);
3517         if (__pPopupSetting == null)
3518         {
3519                 SettingListData* pData;
3520                 Dimension dim(VR_FORM_POPUP_W, VR_FORM_POPUP_H);
3521                 Rectangle rect(VR_FORM_OK_BUTTON_X, VR_FORM_OK_BUTTON_Y, VR_FORM_OK_BUTTON_W, VR_FORM_OK_BUTTON_H);
3522
3523                 r = CreatePopUp(&__pPopupSetting, L"Settings", dim, true);
3524                 if (IsFailed(r))
3525                 {
3526                         goto FAIL;
3527                 }
3528
3529                 r = AddButton(&__pButnSettingOK, L"OK", ID_BUTTON_SETTING_OK, __pPopupSetting, rect);
3530                 if (IsFailed(r))
3531                 {
3532                         goto FAIL;
3533                 }
3534
3535                 SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3536
3537                 __pSettingItemArrayList = new (std::nothrow) ArrayList();
3538
3539                 if (__camType == CAMERA_PRIMARY)
3540                 {
3541                         r = GetMediaCapability(CAMERA_PRIMARY_SUPPORT_BRIGHTNESS, value);
3542                 }
3543                 else
3544                 {
3545                         r = GetMediaCapability(CAMERA_SECONDARY_SUPPORT_BRIGHTNESS, value);
3546                 }
3547                 if (value == true && r == E_SUCCESS)
3548                 {
3549
3550                         pData = new (std::nothrow) SettingListData(new String(L"Brightness"), (int) ID_MENU_BRIGHTNESS);
3551                         __pSettingItemArrayList->Add(*pData);
3552                 }
3553
3554                 if (__camType == CAMERA_PRIMARY)
3555                 {
3556                         r = GetMediaCapability(CAMERA_PRIMARY_SUPPORT_EXPOSURE, value);
3557                 }
3558                 else
3559                 {
3560                         r = GetMediaCapability(CAMERA_SECONDARY_SUPPORT_EXPOSURE, value);
3561                 }
3562
3563                 if (value == true && r == E_SUCCESS)
3564                 {
3565                         pData = new (std::nothrow) SettingListData(new String(L"Exposure"), (int) ID_MENU_EXPOSURE);
3566                         __pSettingItemArrayList->Add(*pData);
3567                 }
3568
3569                 if (__camType == CAMERA_PRIMARY)
3570                 {
3571                         r = GetMediaCapability(CAMERA_PRIMARY_SUPPORT_CONTRAST, value);
3572                 }
3573                 else
3574                 {
3575                         r = GetMediaCapability(CAMERA_SECONDARY_SUPPORT_CONTRAST, value);
3576                 }
3577                 if (value == true && r == E_SUCCESS)
3578                 {
3579                         pData = new (std::nothrow) SettingListData(new String(L"Contrast"), (int) ID_MENU_CONTRAST);
3580                         __pSettingItemArrayList->Add(*pData);
3581                 }
3582
3583                 if (__camType == CAMERA_PRIMARY)
3584                 {
3585                         r = GetMediaCapability(CAMERA_PRIMARY_EFFECT);
3586                 }
3587                 else
3588                 {
3589                         r = GetMediaCapability(CAMERA_SECONDARY_EFFECT);
3590                 }
3591
3592                 if (r == E_SUCCESS)
3593                 {
3594                         pData = new (std::nothrow) SettingListData(new String(L"Effect"), (int) ID_MENU_EFFECT);
3595                         __pSettingItemArrayList->Add(*pData);
3596                 }
3597                 if (__camType == CAMERA_PRIMARY)
3598                 {
3599                         r = GetMediaCapability(CAMERA_PRIMARY_ISO_LEVEL);
3600                 }
3601                 else
3602                 {
3603                         r = GetMediaCapability(CAMERA_SECONDARY_ISO_LEVEL);
3604                 }
3605                 if (r == E_SUCCESS)
3606                 {
3607                         pData = new (std::nothrow) SettingListData(new String(L"IsoLevel"), (int) ID_MENU_ISOLEVEL);
3608                         __pSettingItemArrayList->Add(*pData);
3609                 }
3610
3611                 if (__camType == CAMERA_PRIMARY)
3612                 {
3613                         r = GetMediaCapability(CAMERA_PRIMARY_WHITE_BALANCE);
3614                 }
3615                 else
3616                 {
3617                         r = GetMediaCapability(CAMERA_SECONDARY_WHITE_BALANCE);
3618                 }
3619                 if (r == E_SUCCESS)
3620                 {
3621                         pData = new (std::nothrow) SettingListData(new String(L"WhiteBalance"), (int) ID_MENU_WHITEBALANCE);
3622                         __pSettingItemArrayList->Add(*pData);
3623                 }
3624
3625                 if (__camType == CAMERA_PRIMARY)
3626                 {
3627                         r = GetMediaCapability(CAMERA_PRIMARY_SUPPORT_ZOOM, value);
3628                 }
3629                 else
3630                 {
3631                         r = GetMediaCapability(CAMERA_SECONDARY_SUPPORT_ZOOM, value);
3632                 }
3633                 if (value == true && r == E_SUCCESS)
3634                 {
3635                         pData = new (std::nothrow) SettingListData(new String(L"ZoomLevel"), (int) ID_MENU_ZOOMLEVEL);
3636                         __pSettingItemArrayList->Add(*pData);
3637                 }
3638
3639                 if (__camType == CAMERA_PRIMARY)
3640                 {
3641                         r = GetMediaCapability(CAMERA_PRIMARY_PREVIEW_FRAMERATE);
3642                 }
3643                 else
3644                 {
3645                         r = GetMediaCapability(CAMERA_SECONDARY_PREVIEW_FRAMERATE);
3646                 }
3647                 if (r == E_SUCCESS)
3648                 {
3649                         pData = new (std::nothrow) SettingListData(new String(L"Frame Rate"), (int) ID_MENU_FRAME_RATE);
3650                         __pSettingItemArrayList->Add(*pData);
3651                 }
3652
3653                 if (__camType == CAMERA_PRIMARY)
3654                 {
3655                         AppLog("CAMERA_PRIMARY_FLIP check");
3656                         r = GetMediaCapability(CAMERA_PRIMARY_FLIP);
3657                 }
3658                 else
3659                 {
3660                         AppLog("CAMERA_SECONDARY_FLIP check");
3661                         r = GetMediaCapability(CAMERA_SECONDARY_FLIP);
3662                 }
3663                 if (r == E_SUCCESS)
3664                 {
3665                         pData = new (std::nothrow) SettingListData(new String(L"Flip Type"), (int) ID_MENU_FLIP_TYPE);
3666                         __pSettingItemArrayList->Add(*pData);
3667                 }
3668
3669                 if (__camType == CAMERA_PRIMARY)
3670                 {
3671                         r = GetMediaCapability(CAMERA_PRIMARY_RECORDING_RESOLUTION);
3672                 }
3673                 else
3674                 {
3675                         r = GetMediaCapability(CAMERA_SECONDARY_RECORDING_RESOLUTION);
3676                 }
3677                 if (r == E_SUCCESS)
3678                 {
3679                         pData = new (std::nothrow) SettingListData(new String(L"Recording Resolution"), (int) ID_MENU_RECORDING_RESOLUTION);
3680                         __pSettingItemArrayList->Add(*pData);
3681                 }
3682
3683
3684                 pData = new (std::nothrow) SettingListData(new String(L"Recording Quality"), (int) ID_MENU_RECORDING_QUALITY);
3685                 __pSettingItemArrayList->Add(*pData);
3686
3687                 r = GetMediaCapability(VIDEORECORDER_VIDEO_CODEC);
3688                 if (r == E_SUCCESS)
3689                 {
3690                         pData = new (std::nothrow) SettingListData(new String(L"Video Codec"), (int) ID_MENU_VIDEO_CODEC);
3691                         __pSettingItemArrayList->Add(*pData);
3692                 }
3693
3694                 r = GetMediaCapability(VIDEORECORDER_AUDIO_CODEC);
3695                 if (r == E_SUCCESS)
3696                 {
3697                         pData = new (std::nothrow) SettingListData(new String(L"Audio Codec"), (int) ID_MENU_AUDIO_CODEC);
3698                         __pSettingItemArrayList->Add(*pData);
3699                 }
3700
3701                 r = GetMediaCapability(VIDEORECORDER_FORMAT);
3702                 if (r == E_SUCCESS)
3703                 {
3704                         pData = new (std::nothrow) SettingListData(new String(L"File Format"), (int) ID_MENU_FILE_FORMAT);
3705                         __pSettingItemArrayList->Add(*pData);
3706                 }
3707                 r = AddListView(&__pListViewSetting, __pPopupSetting, ID_BUTTON_SETTING_OK);
3708                 if (IsFailed(r))
3709                 {
3710                         goto FAIL;
3711                 }
3712         }
3713
3714         return true;
3715 FAIL:
3716         DeletePopup(&__pPopupSetting);
3717         SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
3718         AppLog("%s", GetErrorMessage(r));
3719         return false;
3720
3721 }
3722
3723
3724 void
3725 VideoRecorderForm::OnVideoRecorderCanceled(result r)
3726 {
3727         AppLog("RECORDER_STATE_RECORDING");
3728         __pTimer->Cancel();
3729         FreeResources();
3730 }
3731
3732 void
3733 VideoRecorderForm::OnVideoRecorderClosed(result r)
3734 {
3735         AppLog("VideoRecorderForm::OnVideoRecorderClosed");
3736
3737         if (!__backGround && __cameraError == false)
3738         {
3739                 SendUserEvent(RECORDER_ON_CLOSE, null);
3740         }
3741 }
3742
3743 void
3744 VideoRecorderForm::OnVideoRecorderEndReached(Osp::Media::RecordingEndCondition endCondition)
3745 {
3746         AppLog("VideoRecorderForm::OnVideoRecorderEndReached ");
3747         __pVideoRecorder->Close();
3748         __pTimer->Cancel();
3749         SetFooterItem(2, L"Start", ID_START);
3750         __pProgress->SetValue(100);
3751         __pProgress->Draw();
3752         __pProgress->Show();
3753 }
3754
3755 void
3756 VideoRecorderForm::OnVideoRecorderErrorOccurred(Osp::Media::RecorderErrorReason r)
3757 {
3758         AppLog("VideoRecorderForm::OnVideoRecorderErrorOccurred");
3759         __pVideoRecorder->Close();
3760         __pTimer->Cancel();
3761         if (IsFailed(r))
3762         {
3763                 ShowError(r, METHOD_FILE_LINENO);
3764                 goto FAIL;
3765         }
3766         return;
3767 FAIL:
3768         return;
3769 }
3770 void
3771 VideoRecorderForm::OnVideoRecorderPaused(result r)
3772 {
3773         AppLog("VideoRecorderForm::OnVideoRecorderPaused");
3774 }
3775
3776 void
3777 VideoRecorderForm::OnVideoRecorderStarted(result r)
3778 {
3779         Footer* pFotter = null;
3780         AppLog("OnVideoRecorderStarted");
3781         ShowFooterItem(0, true);
3782         ShowFooterItem(1, true);
3783         ShowFooterItem(2, true);
3784         pFotter = GetFooter();
3785         if (pFotter)
3786         {
3787                 pFotter->SetBackButtonEnabled(true);
3788                 pFotter->Draw();
3789         }
3790 }
3791
3792 void
3793 VideoRecorderForm::OnVideoRecorderStopped(result r)
3794 {
3795         Footer* pFotter = null;
3796         AppLog("VideoRecorderForm::OnVideoRecorderStopped ");
3797         SendUserEvent(RECORDER_ON_STOP, null);
3798         ShowFooterItem(0, true);
3799         ShowFooterItem(1, true);
3800         ShowFooterItem(2, true);
3801         pFotter = GetFooter();
3802         if (pFotter)
3803         {
3804                 pFotter->SetBackButtonEnabled(true);
3805                 pFotter->Draw();
3806         }
3807 }
3808
3809 void
3810 VideoRecorderForm::LaunchMediaPlayer(bool flag)
3811 {
3812         result r = E_SUCCESS;
3813         MediaPlayerForm* pMediaPlayerForm = null;
3814         Frame* pFrame = null;
3815
3816         OnBackground();
3817
3818         AppLog("MediaPlayerForm's LaunchMediaPlayer invoked file path %ls", __filePath.GetPointer());
3819         String mediaType;
3820         mediaType.Clear();
3821         mediaType.Append(L"VIDEO");
3822
3823         pMediaPlayerForm = new (std::nothrow) MediaPlayerForm(this, &mediaType, &__filePath);
3824         if (pMediaPlayerForm == null)
3825         {
3826                 AppLog("pMediaPlayerForm failed , no memory");
3827                 return;
3828         }
3829
3830         if (pMediaPlayerForm->Initialize() == false)
3831         {
3832                 AppLog("pMediaPlayerForm->Initialize() failed");
3833                 return;
3834         }
3835
3836         // Add the form to the frame
3837         pFrame = Osp::App::UiApp::GetInstance()->GetAppFrame()->GetFrame();
3838         if (pFrame == null)
3839         {
3840                 AppLog("pFrame returned null");
3841                 return;
3842         }
3843         r = pFrame->AddControl(*pMediaPlayerForm);
3844         if (IsFailed(r))
3845         {
3846                 ShowError(r, METHOD_FILE_LINENO);
3847                 AppLog("pFrame->AddControl failed %s", GetErrorMessage(r));
3848                 return;
3849         }
3850
3851         // Set the current form
3852         r = pFrame->SetCurrentForm(*pMediaPlayerForm);
3853         if (IsFailed(r))
3854         {
3855                 ShowError(r, METHOD_FILE_LINENO);
3856                 AppLog("pFrame->SetCurrentForm failed %s", GetErrorMessage(r));
3857                 return;
3858         }
3859
3860
3861         // Draw and Show the form
3862         pMediaPlayerForm->Draw();
3863         pMediaPlayerForm->Show();
3864
3865         if (pMediaPlayerForm->Start() == false)
3866         {
3867                 ShowError(r, METHOD_FILE_LINENO);
3868                 AppLog("pMediaPlayerForm->Start()");
3869                 return;
3870         }
3871
3872 }
3873
3874 void
3875 VideoRecorderForm::LaunchMediaPlayer()
3876 {
3877         result r = E_SUCCESS;
3878         ArrayList* pDataList = null;
3879         String* pData = null;
3880         AppLog("Enter");
3881
3882         ClearCanvas();
3883
3884         AppControl* pAc = AppManager::FindAppControlN(L"http://tizen.org/appcontrol/provider/video", L"http://tizen.org/appcontrol/operation/play");
3885         if (pAc == null)
3886         {
3887                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
3888                 goto FAIL;
3889         }
3890
3891         pDataList = new (std::nothrow) ArrayList();
3892         if (pDataList == null)
3893         {
3894                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
3895                 goto FAIL;
3896         }
3897
3898         r = pDataList->Construct();
3899         if (IsFailed(r))
3900         {
3901                 ShowError(r, METHOD_FILE_LINENO);
3902                 goto FAIL;
3903         }
3904
3905
3906         pData = new (std::nothrow) String(L"type:video");
3907         if (pData == null)
3908         {
3909                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
3910                 goto FAIL;
3911         }
3912
3913         r = pDataList->Add(*pData);
3914         if (IsFailed(r))
3915         {
3916                 ShowError(r, METHOD_FILE_LINENO);
3917                 goto FAIL;
3918         }
3919
3920         pData = new (std::nothrow) String(L"path:");
3921         if (pData == null)
3922         {
3923                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
3924                 goto FAIL;
3925         }
3926         (*pData).Append(__filePath);
3927         r = pDataList->Add(*pData);
3928         if (IsFailed(r))
3929         {
3930                 ShowError(r, METHOD_FILE_LINENO);
3931                 goto FAIL;
3932         }
3933
3934         r = pAc->Start(pDataList, null);
3935         if (IsFailed(r))
3936         {
3937                 ShowError(r, METHOD_FILE_LINENO);
3938                 goto FAIL;
3939         }
3940
3941         SAFE_DELETE(pAc);
3942
3943         if (pDataList)
3944         {
3945                 pDataList->RemoveAll(true);
3946         }
3947         SAFE_DELETE(pDataList);
3948
3949         __backGround = true;
3950         SetOrientation(ORIENTATION_AUTOMATIC);
3951         return;
3952
3953 FAIL:
3954         SAFE_DELETE(pAc);
3955         if (pDataList)
3956         {
3957                 pDataList->RemoveAll(true);
3958         }
3959         SAFE_DELETE(pDataList);
3960         return;
3961 }
3962
3963
3964 result
3965 VideoRecorderForm::GetMediaCapability(String key, bool& Value)
3966 {
3967         result r = E_SUCCESS;
3968         r = MediaCapability::GetValue(key, Value);
3969         AppLog("GetMediaCapability for %ls value = %d return = %s", key.GetPointer(), Value, GetErrorMessage(r));
3970         return r;
3971 }
3972
3973 result
3974 VideoRecorderForm::GetMediaCapability(String key)
3975 {
3976         result r = E_FAILURE;
3977         IList* pList = null;
3978         pList = MediaCapability::GetValueN(key);
3979
3980         if (pList && pList->GetCount() > 0)
3981         {
3982                 r = E_SUCCESS;
3983                 pList->RemoveAll(true);
3984                 delete pList;
3985         }
3986
3987         AppLog("GetMediaCapability for %ls return = %s", key.GetPointer(), GetErrorMessage(r));
3988         return r;
3989 }
3990
3991 void
3992 VideoRecorderForm::OnTimerExpired(Osp::Base::Runtime::Timer& timer)
3993 {
3994         AppLog("VideoRecorderForm::OnTimerExpired");
3995         if (&timer == __pTimer && __pVideoRecorder != null)
3996         {
3997                 long duration = __pVideoRecorder->GetRecordingTime();
3998                 long recordedSize = __pVideoRecorder->GetRecordingSize(); //size is in KB
3999                 if (__maxRecordingTime && (duration > 0) && (recordedSize > 0))
4000                 {
4001                         long sec;
4002                         long min;
4003                         long hour;
4004                         // (duration / 1000) ==>convert to seconds
4005                         // (((duration / 1000)/__maxRecordingTime))*100  ==> convert to %
4006                         int currTimePer = (duration) / (__maxRecordingTime * 10);
4007
4008                         int recSizeMB = recordedSize / KILOBYTE;
4009
4010                         AppLog("Recorded Duration = %d current time percentage = %d recorded size = %d", duration, currTimePer, recordedSize);
4011
4012                         __pProgress->SetValue(currTimePer);
4013
4014                         __pProgress->Draw();
4015                         __pProgress->Show();
4016
4017                         sec = duration / KILOBYTE;
4018                         min = sec / SIXTY_SECS;
4019                         sec = sec - min * SIXTY_SECS;
4020                         hour = min / SIXTY_SECS;
4021                         min = min - hour * SIXTY_SECS;
4022
4023                         String endtime = L"";
4024                         if (hour < TEN)
4025                                 endtime.Append(L"0");
4026                         endtime.Append(hour);
4027                         endtime.Append(L"");
4028                         endtime.Append(L":");
4029                         if (min < TEN)
4030                                 endtime.Append(L"0");
4031                         endtime.Append(min);
4032                         endtime.Append(L"");
4033                         endtime.Append(L":");
4034                         if (sec < TEN)
4035                                 endtime.Append(L"0");
4036                         endtime.Append(sec);
4037
4038                         String size = L"";
4039                         if (recSizeMB < TEN)
4040                                 size.Append(L"0");
4041                         size.Append(recSizeMB);
4042
4043                         __pElapsedRecordSizeLable->SetText(size);
4044                         __pElapsedRecordSizeLable->RequestRedraw();
4045
4046                         __pElapsedTimeLable->SetText(endtime);
4047                         __pElapsedTimeLable->RequestRedraw();
4048
4049                 }
4050                 timer.Start(_TIMER_VALUE_);
4051         }
4052 }
4053 void
4054 VideoRecorderForm::CreateExposureSlider()
4055 {
4056         result r = E_SUCCESS;
4057         String strTemp;
4058         int exposure = 0;
4059
4060         if (__pPopupExposure == null)
4061         {
4062                 Dimension dim(VR_FORM_POPUP_SLIDER_W, VR_FORM_POPUP_SLIDER_H);
4063                 Rectangle rect(VR_FORM_SLIDER_OK_BUTTON_X, VR_FORM_SLIDER_OK_BUTTON_Y, VR_FORM_SLIDER_OK_BUTTON_W, VR_FORM_SLIDER_OK_BUTTON_H);
4064                 r = CreatePopUp(&__pPopupExposure, L"Exposure", dim, true);
4065                 if (IsFailed(r))
4066                 {
4067                         goto FAIL;
4068                 }
4069                 r = AddSlider(&__pExposureSlider, 0, 9, L"", __pPopupExposure);
4070                 if (IsFailed(r))
4071                 {
4072                         goto FAIL;
4073                 }
4074                 r = AddButton(&__pButnExposureOK, L"OK", ID_BUTTON_EXPOSURE_OK, __pPopupExposure, rect);
4075                 if (IsFailed(r))
4076                 {
4077                         goto FAIL;
4078                 }
4079         }
4080
4081         exposure = __pCamera->GetExposure();
4082         if (IsFailed(GetLastResult()))
4083         {
4084                 ShowError(r, METHOD_FILE_LINENO);
4085                 goto FAIL;
4086         }
4087
4088         if (__exposureSliderValue != exposure &&
4089                 __exposureSliderValue != 0)
4090         {
4091                 exposure = __exposureSliderValue;
4092         }
4093
4094         __pExposureSlider->SetValue(exposure);
4095         strTemp.Format(50, L"Exposure : %d", exposure);
4096         __pExposureSlider->SetTitleText(strTemp);
4097
4098         EnableFooterItem(ID_SETTING, false);
4099         EnableFooterItem(ID_TOGGLE_CAMERA_TYPE, false);
4100         EnableFooterItem(ID_START, false);
4101
4102         ShowPopUp(__pPopupExposure);
4103
4104         return;
4105 FAIL:
4106         AppLog(" VideoRecorderForm::CreateExposureSlider() failed");
4107         DeletePopup(&__pPopupExposure);
4108         return;
4109 }
4110
4111 void
4112 VideoRecorderForm::CreateBrightnessSlider()
4113 {
4114         result r = E_SUCCESS;
4115         String strTemp;
4116         int brightness = 0;
4117
4118         if (__pPopupBrightness == null)
4119         {
4120                 Dimension dim(VR_FORM_POPUP_SLIDER_W, VR_FORM_POPUP_SLIDER_H);
4121                 Rectangle rect(VR_FORM_SLIDER_OK_BUTTON_X, VR_FORM_SLIDER_OK_BUTTON_Y, VR_FORM_SLIDER_OK_BUTTON_W, VR_FORM_SLIDER_OK_BUTTON_H);
4122                 r = CreatePopUp(&__pPopupBrightness, L"Brightness", dim, true);
4123                 if (IsFailed(r))
4124                 {
4125                         goto FAIL;
4126                 }
4127                 r = AddSlider(&__pBrightnessSlider, 0, 9, L"", __pPopupBrightness);
4128                 if (IsFailed(r))
4129                 {
4130                         goto FAIL;
4131                 }
4132                 r = AddButton(&__pButnBrightnessOK, L"OK", ID_BUTTON_BRIGHTNESS_OK, __pPopupBrightness, rect);
4133                 if (IsFailed(r))
4134                 {
4135                         goto FAIL;
4136                 }
4137         }
4138
4139         brightness = __pCamera->GetBrightness();
4140         if (IsFailed(GetLastResult()))
4141         {
4142                 ShowError(r, METHOD_FILE_LINENO);
4143                 goto FAIL;
4144         }
4145
4146         if (__brightnessSliderValue != brightness &&
4147                 __brightnessSliderValue != 0)
4148         {
4149                 brightness = __brightnessSliderValue;
4150         }
4151
4152         __pBrightnessSlider->SetValue(brightness);
4153         strTemp.Format(50, L"Brightness : %d", brightness);
4154         __pBrightnessSlider->SetTitleText(strTemp);
4155
4156         ShowPopUp(__pPopupBrightness);
4157
4158         EnableFooterItem(ID_SETTING, false);
4159         EnableFooterItem(ID_TOGGLE_CAMERA_TYPE, false);
4160         EnableFooterItem(ID_START, false);
4161         GetFooter()->SetBackButtonEnabled(false);
4162         GetFooter()->Draw();
4163
4164         return;
4165 FAIL:
4166         AppLog("VideoRecorderForm::CreateBrightnessSlider() failed");
4167         DeletePopup(&__pPopupBrightness);
4168         return;
4169 }
4170
4171 void
4172 VideoRecorderForm::CreateContrastSlider()
4173 {
4174         result r = E_SUCCESS;
4175         String strTemp;
4176         int contrast = 0;
4177
4178         if (__pPopupContrast == null)
4179         {
4180                 Dimension dim(VR_FORM_POPUP_SLIDER_W, VR_FORM_POPUP_SLIDER_H);
4181                 Rectangle rect(VR_FORM_SLIDER_OK_BUTTON_X, VR_FORM_SLIDER_OK_BUTTON_Y, VR_FORM_SLIDER_OK_BUTTON_W, VR_FORM_SLIDER_OK_BUTTON_H);
4182                 r = CreatePopUp(&__pPopupContrast, L"Contrast", dim, true);
4183                 if (IsFailed(r))
4184                 {
4185                         goto FAIL;
4186                 }
4187                 r = AddSlider(&__pContrastSlider, 0, 9, L"", __pPopupContrast);
4188                 if (IsFailed(r))
4189                 {
4190                         goto FAIL;
4191                 }
4192                 r = AddButton(&__pButnContrastOK, L"OK", ID_BUTTON_CONTRAST_OK, __pPopupContrast, rect);
4193                 if (IsFailed(r))
4194                 {
4195                         goto FAIL;
4196                 }
4197         }
4198
4199         contrast = __pCamera->GetContrast();
4200         if (IsFailed(GetLastResult()))
4201         {
4202                 ShowError(r, METHOD_FILE_LINENO);
4203                 goto FAIL;
4204         }
4205
4206         if (__contrastSliderValue != contrast &&
4207                 __contrastSliderValue != 0)
4208         {
4209                 contrast = __contrastSliderValue;
4210         }
4211
4212         __pContrastSlider->SetValue(contrast);
4213         strTemp.Format(50, L"Contrast : %d", contrast);
4214         __pContrastSlider->SetTitleText(strTemp);
4215
4216         EnableFooterItem(ID_SETTING, false);
4217         EnableFooterItem(ID_TOGGLE_CAMERA_TYPE, false);
4218         EnableFooterItem(ID_START, false);
4219         GetFooter()->SetBackButtonEnabled(false);
4220         GetFooter()->Draw();
4221
4222         ShowPopUp(__pPopupContrast);
4223         return;
4224 FAIL:
4225         AppLog("VideoRecorderForm::Contrast() failed");
4226         DeletePopup(&__pPopupContrast);
4227         return;
4228 }
4229
4230 void
4231 VideoRecorderForm::CreateZoomLevelSlider()
4232 {
4233         result r = E_SUCCESS;
4234         String strTemp;
4235         int zoom = 0;
4236
4237         AppLog("VideoRecorderForm::CreateZoomLevelSlider() ");
4238
4239         if (__pPopupZoom == null)
4240         {
4241                 zoom = __pCamera->GetMaxZoomLevel();
4242                 if (zoom <= 0)
4243                 {
4244                         if (IsFailed(GetLastResult()))
4245                         {
4246                                 ShowError(r, METHOD_FILE_LINENO);
4247                                 goto FAIL;
4248                         }
4249                 }
4250
4251                 Dimension dim(VR_FORM_POPUP_SLIDER_W, VR_FORM_POPUP_SLIDER_H);
4252                 Rectangle rect(VR_FORM_SLIDER_OK_BUTTON_X, VR_FORM_SLIDER_OK_BUTTON_Y, VR_FORM_SLIDER_OK_BUTTON_W, VR_FORM_SLIDER_OK_BUTTON_H);
4253                 r = CreatePopUp(&__pPopupZoom, L"Zoom Level", dim, true);
4254                 if (IsFailed(r))
4255                 {
4256                         goto FAIL;
4257                 }
4258                 r = AddSlider(&__pZoomLevelSlider, 0, zoom, L"", __pPopupZoom);
4259                 if (IsFailed(r))
4260                 {
4261                         goto FAIL;
4262                 }
4263                 r = AddButton(&__pButnZoomOK, L"OK", ID_BUTTON_ZOOM_OK, __pPopupZoom, rect);
4264                 if (IsFailed(r))
4265                 {
4266                         goto FAIL;
4267                 }
4268         }
4269
4270         zoom = __pCamera->GetZoomLevel();
4271
4272         __pZoomLevelSlider->SetValue(zoom);
4273         strTemp.Format(50, L"Zoom : %d", zoom);
4274         __pZoomLevelSlider->SetTitleText(strTemp);
4275
4276         ShowPopUp(__pPopupZoom);
4277
4278         EnableFooterItem(ID_SETTING, false);
4279         EnableFooterItem(ID_TOGGLE_CAMERA_TYPE, false);
4280         EnableFooterItem(ID_START, false);
4281         GetFooter()->SetBackButtonEnabled(false);
4282         GetFooter()->Draw();
4283
4284         return;
4285 FAIL:
4286         AppLog("VideoRecorderForm::CreateZoomLevelSlider() failed");
4287         DeletePopup(&__pPopupZoom);
4288 }
4289
4290 void
4291 VideoRecorderForm::OnAdjustmentValueChanged(const Osp::Ui::Control& source, int adjustment)
4292 {
4293         result r = E_SUCCESS;
4294         String strTemp;
4295
4296         AppLog("VideoRecorderForm::OnAdjustmentValueChanged() called");
4297         if (!__pCamera)
4298         {
4299                 return;
4300         }
4301         if (&source == __pBrightnessSlider)
4302         {
4303                 r = __pCamera->SetBrightness(adjustment);
4304                 if (IsFailed(r))
4305                 {
4306                         ShowError(r, METHOD_FILE_LINENO);
4307                         goto FAIL;
4308                 }
4309                 strTemp.Format(50, L"Brightness : %d", adjustment);
4310                 __pBrightnessSlider->SetTitleText(strTemp);
4311                 __pBrightnessSlider->Draw();
4312
4313                 __brightnessSliderValue = adjustment;
4314         }
4315         else if (&source == __pContrastSlider)
4316         {
4317                 r = __pCamera->SetContrast(adjustment);
4318                 if (IsFailed(r))
4319                 {
4320                         ShowError(r, METHOD_FILE_LINENO);
4321                         goto FAIL;
4322                 }
4323                 strTemp.Format(50, L"Contrast : %d", adjustment);
4324                 __pContrastSlider->SetTitleText(strTemp);
4325                 __pContrastSlider->Draw();
4326
4327                 __contrastSliderValue = adjustment;
4328         }
4329         else if (&source == __pExposureSlider)
4330         {
4331                 r = __pCamera->SetExposure(adjustment);
4332                 if (IsFailed(r))
4333                 {
4334                         ShowError(r, METHOD_FILE_LINENO);
4335                         goto FAIL;
4336                 }
4337                 strTemp.Format(50, L"Exposure : %d", adjustment);
4338                 __pExposureSlider->SetTitleText(strTemp);
4339                 __pExposureSlider->Draw();
4340
4341                 __exposureSliderValue = adjustment;
4342         }
4343         else if (&source == __pZoomLevelSlider)
4344         {
4345                 int zoomValue = __pCamera->GetZoomLevel();
4346                 if (zoomValue < adjustment)
4347                 {
4348                         for (int i = zoomValue; i < adjustment; i++)
4349                         {
4350                                 r = __pCamera->ZoomIn();
4351                                 if (IsFailed(r))
4352                                 {
4353                                         ShowError(r, METHOD_FILE_LINENO);
4354                                         goto FAIL;
4355                                 }
4356                         }
4357                 }
4358                 else
4359                 {
4360                         for (int i = zoomValue; i > adjustment; i--)
4361                         {
4362                                 r = __pCamera->ZoomOut();
4363                                 if (IsFailed(r))
4364                                 {
4365                                         ShowError(r, METHOD_FILE_LINENO);
4366                                         goto FAIL;
4367                                 }
4368                         }
4369                 }
4370                 strTemp.Format(50, L"Zoom : %d", adjustment);
4371                 __pZoomLevelSlider->SetTitleText(strTemp);
4372                 __pZoomLevelSlider->SetValue(__pCamera->GetZoomLevel());
4373                 __pZoomLevelSlider->Draw();
4374         }
4375
4376         return;
4377 FAIL:
4378         AppLog("VideoRecorderForm::OnAdjustmentValueChanged() failed");
4379         return;
4380 }
4381
4382
4383
4384 void
4385 VideoRecorderForm::OnTouchReleased(const Osp::Ui::Control& source, const Osp::Graphics::Point& currentPosition, const Osp::Ui::TouchEventInfo& touchInfo)
4386 {
4387         AppLog("VideoRecorderForm::OnTouchReleased() ");
4388 }
4389
4390 void
4391 VideoRecorderForm::OnBackground(void)
4392 {
4393
4394         AppLog("VideoRecorderForm::OnBackground Enter");
4395         __pTimer->Cancel();
4396         if (__pVideoRecorder)
4397         {
4398                 AppLog("VideoRecorderForm::OnBackground setting");
4399                 FreeResources();
4400         }
4401         __backGround = true;
4402         __pProgress->SetValue(0);
4403 }
4404
4405 void
4406 VideoRecorderForm::OnForeground(void)
4407 {
4408         AppLog("VideoRecorderForm::OnForeground Enter");
4409
4410         if (__backGround == true)
4411         {
4412                 VideoRecorderForm::OnActivate(null);
4413                 AppLog("VideoRecorderForm::OnForeground Enter 1");
4414                 Draw();
4415         }
4416         AppLog("VideoRecorderForm::OnForeground Exit");
4417         __backGround = false;
4418         return;
4419 }
4420
4421 bool
4422 VideoRecorderForm::ConvertContainerToRawString(MediaContainerType& containerType, String& strString)
4423 {
4424         strString.Clear();
4425
4426         switch (containerType)
4427         {
4428         case MEDIA_CONTAINER_NONE:
4429         {
4430                 strString.Append(L"MEDIA_CONTAINER_NONE");
4431                 return false;
4432                 break;
4433         }
4434
4435         case MEDIA_CONTAINER_WAV:
4436                 strString.Append(L"MEDIA_CONTAINER_WAV");
4437                 break;
4438
4439         case MEDIA_CONTAINER_AMR:
4440                 strString.Append(L"MEDIA_CONTAINER_AMR");
4441                 break;
4442
4443         case MEDIA_CONTAINER_AAC:
4444                 strString.Append(L"MEDIA_CONTAINER_AAC");
4445                 break;
4446
4447         case MEDIA_CONTAINER_MP3:
4448                 strString.Append(L"MEDIA_CONTAINER_MP3");
4449                 break;
4450
4451         case MEDIA_CONTAINER_FLAC:
4452                 strString.Append(L"MEDIA_CONTAINER_FLAC");
4453                 break;
4454
4455         case MEDIA_CONTAINER_3GP:
4456                 strString.Append(L"MEDIA_CONTAINER_3GP");
4457                 break;
4458
4459         case MEDIA_CONTAINER_MP4:
4460                 strString.Append(L"MEDIA_CONTAINER_MP4");
4461                 break;
4462
4463         case MEDIA_CONTAINER_AVI:
4464                 strString.Append(L"MEDIA_CONTAINER_AVI");
4465                 break;
4466
4467         case MEDIA_CONTAINER_ASF:
4468                 strString.Append(L"MEDIA_CONTAINER_ASF");
4469                 break;
4470
4471         case MEDIA_CONTAINER_MKV:
4472                 strString.Append(L"MEDIA_CONTAINER_MKV");
4473                 break;
4474
4475         case MEDIA_CONTAINER_MOV:
4476                 strString.Append(L"MEDIA_CONTAINER_MOV");
4477                 break;
4478
4479         case MEDIA_CONTAINER_OGG:
4480                 strString.Append(L"MEDIA_CONTAINER_OGG");
4481                 break;
4482
4483         case MEDIA_CONTAINER_UNKNOWN:
4484         {
4485                 strString.Append(L"MEDIA_CONTAINER_UNKNOWN");
4486                 return false;
4487                 break;
4488         }
4489
4490         default:
4491                 return false;
4492         }
4493
4494         return true;
4495 }
4496
4497 bool
4498 VideoRecorderForm::ConvertContainerToString(MediaContainerType& containerType, String& strString)
4499 {
4500         strString.Clear();
4501
4502         switch (containerType)
4503         {
4504         case MEDIA_CONTAINER_NONE:
4505                 return false;
4506                 break;
4507
4508         case MEDIA_CONTAINER_WAV:
4509                 strString.Append(L"WAV");
4510                 break;
4511
4512         case MEDIA_CONTAINER_AMR:
4513                 strString.Append(L"AMR");
4514                 break;
4515
4516         case MEDIA_CONTAINER_AAC:
4517                 strString.Append(L"AAC");
4518                 break;
4519
4520         case MEDIA_CONTAINER_MP3:
4521                 strString.Append(L"MP3");
4522                 break;
4523
4524         case MEDIA_CONTAINER_FLAC:
4525                 strString.Append(L"FLAC");
4526                 break;
4527
4528         case MEDIA_CONTAINER_3GP:
4529                 strString.Append(L"3GP");
4530                 break;
4531
4532         case MEDIA_CONTAINER_MP4:
4533                 strString.Append(L"MP4");
4534                 break;
4535
4536         case MEDIA_CONTAINER_AVI:
4537                 strString.Append(L"AVI");
4538                 break;
4539
4540         case MEDIA_CONTAINER_ASF:
4541                 strString.Append(L"ASF");
4542                 break;
4543
4544         case MEDIA_CONTAINER_MKV:
4545                 strString.Append(L"MKV");
4546                 break;
4547
4548         case MEDIA_CONTAINER_MOV:
4549                 strString.Append(L"MOV");
4550                 break;
4551
4552         case MEDIA_CONTAINER_OGG:
4553                 strString.Append(L"OGG");
4554                 break;
4555
4556         case MEDIA_CONTAINER_UNKNOWN:
4557                 return false;
4558                 break;
4559
4560         default:
4561                 return false;
4562         }
4563
4564         return true;
4565 }
4566 bool
4567 VideoRecorderForm::ConvertCodecToString(CodecType& codecType, String& strString)
4568 {
4569         strString.Clear();
4570
4571         switch (codecType)
4572         {
4573         case CODEC_NONE:
4574                 return false;
4575                 break;
4576
4577         case CODEC_LPCM:
4578                 strString.Append(L"Linear PCM");
4579                 break;
4580
4581         case CODEC_ALAW:
4582                 strString.Append(L"G.711 A-Law");
4583                 break;
4584
4585         case CODEC_ULAW:
4586                 strString.Append(L"G.711 u-Law");
4587                 break;
4588
4589         case CODEC_IMA_ADPCM:
4590                 strString.Append(L"IMA ADPCM");
4591                 break;
4592
4593         case CODEC_MS_ADPCM:
4594                 strString.Append(L"MS ADPCM");
4595                 break;
4596
4597         case CODEC_AMR_NB:
4598                 strString.Append(L"AMR-NB");
4599                 break;
4600
4601         case CODEC_FLAC:
4602                 strString.Append(L"FLAC");
4603                 break;
4604
4605         case CODEC_MP3:
4606                 strString.Append(L"MP3");
4607                 break;
4608
4609         case CODEC_AAC:
4610                 strString.Append(L"AAC");
4611                 break;
4612
4613         case CODEC_HEAAC:
4614                 strString.Append(L"Enhanced AAC");
4615                 break;
4616
4617         case CODEC_HEAAC_V2:
4618                 strString.Append(L"Enhanced AAC V2");
4619                 break;
4620
4621         case CODEC_AC3:
4622                 strString.Append(L"AC-3");
4623                 break;
4624
4625         case CODEC_VORBIS:
4626                 strString.Append(L"VORBIS");
4627                 break;
4628
4629         case CODEC_WMA:
4630                 strString.Append(L"WMA");
4631                 break;
4632
4633         case CODEC_MIDI:
4634                 strString.Append(L"MIDI");
4635                 break;
4636
4637         case CODEC_H263:
4638                 strString.Append(L"H.263");
4639                 break;
4640
4641         case CODEC_MPEG4:
4642                 strString.Append(L"MPEG4");
4643                 break;
4644
4645         case CODEC_H264:
4646                 strString.Append(L"H.264");
4647                 break;
4648
4649         case CODEC_THEORA:
4650                 strString.Append(L"THEORA");
4651                 break;
4652
4653         case CODEC_WMV:
4654                 strString.Append(L"WMV");
4655                 break;
4656
4657         case CODEC_JPEG:
4658                 strString.Append(L"JPEG");
4659                 break;
4660
4661         case CODEC_PNG:
4662                 strString.Append(L"PNG");
4663                 break;
4664
4665         case CODEC_GIF:
4666                 strString.Append(L"GIF");
4667                 break;
4668
4669         case CODEC_UNKNOWN:
4670                 return false;
4671                 break;
4672
4673         case CODEC_MAX:
4674                 return false;
4675                 break;
4676
4677         default:
4678                 return false;
4679         }
4680
4681         return true;
4682 }
4683
4684 void
4685 VideoRecorderForm::FreeResources()
4686 {
4687         AppLog("VideoRecorderForm::FreeResources enter");
4688         if (__pVideoRecorder)
4689         {
4690                 __pVideoRecorder->Cancel();
4691                 __pVideoRecorder->Close();
4692         }
4693
4694         if (__pCamera && __pCamera->IsPoweredOn())
4695         {
4696                 __pCamera->StopPreview();
4697         }
4698
4699         if (__pCamera && __pCamera->IsPoweredOn())
4700         {
4701                 __pCamera->PowerOff();
4702         }
4703
4704         SAFE_DELETE(__pVideoRecorder);
4705         SAFE_DELETE(__pCamera);
4706         SAFE_DELETE(__pOverlay);
4707
4708         SAFE_DELETE_ARRAYLIST(__pSettingItemArrayList);
4709         SAFE_DELETE_ARRAYLISTT(__pPreviewFrameRateList);
4710         SAFE_DELETE_ARRAYLISTT(__pRecorderVideoCodecList);
4711         SAFE_DELETE_ARRAYLISTT(__pRecorderAudioCodecList);
4712         SAFE_DELETE_ARRAYLISTT(__pRecorderVideoContainerList);
4713         SAFE_DELETE_ARRAYLIST(__pRecordingResolutionList);
4714         SAFE_DELETE_ARRAYLISTT(__pEffectList);
4715         SAFE_DELETE_ARRAYLISTT(__pIsoList);
4716         SAFE_DELETE_ARRAYLISTT(__pWbList);
4717 }
4718
4719 void
4720 VideoRecorderForm::OnFormBackRequested(Osp::Ui::Controls::Form& source)
4721 {
4722         AppLog("VideoRecorderForm::OnFormBackRequested called");
4723
4724         if (__pTimer != null)
4725         {
4726                 __pTimer->Cancel();
4727         }
4728
4729         //When Back is pressed, then perform FreeResource(), cancel
4730         //and close VideoRecording
4731         FreeResources();
4732
4733         SetFooterItem(2, L"Start", ID_START);
4734         Deactivate();
4735 }
4736
4737 result
4738 VideoRecorderForm::CreateOverlayRegion()
4739 {
4740         Rectangle rect = GetClientAreaBounds();
4741         Rectangle clientRect = GetClientAreaBounds();
4742         bool modified = false;
4743         bool isValidRect = false;
4744
4745         SAFE_DELETE(__pOverlay);
4746
4747         AppLog("Client area rect (%d,%d,%d,%d)", clientRect.x, clientRect.y, clientRect.width, clientRect.height);
4748         HideAndGetBounds(GetControl(L"IDC_BUTTON1"), rect);
4749         AppLog("Original w.r.t IDC_BUTTON1 rect (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
4750
4751         if (rect.width > clientRect.width || rect.height > clientRect.height)
4752         {
4753                 rect.width = clientRect.width;
4754                 rect.height = clientRect.height;
4755         }
4756
4757         __orientationStatus = GetOrientationStatus();
4758         AppLog("Current orientation is %d", __orientationStatus);
4759
4760         AppLog("Rect passed to OverlayRegion::EvaluateBounds is (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
4761         isValidRect = OverlayRegion::EvaluateBounds(OVERLAY_REGION_EVALUATION_OPTION_LESS_THAN, rect, modified);
4762         if (false == isValidRect)
4763         {
4764                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
4765                 goto FAIL;
4766         }
4767
4768         if (modified)
4769         {
4770                 AppLog("Bounds is modified to (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
4771         }
4772
4773         AppLog("Overlay region width = %d  height = %d", rect.width, rect.height);
4774
4775         __pOverlay = Osp::Ui::Controls::Form::GetOverlayRegionN(rect, (__camType == CAMERA_PRIMARY) ? OVERLAY_REGION_TYPE_PRIMARY_CAMERA : OVERLAY_REGION_TYPE_SECONDARY_CAMERA);
4776         AppLog("Overlay region pointer = %X width = %d  height = %d", __pOverlay, rect.width, rect.height);
4777
4778         if (__pOverlay == null)
4779         {
4780                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
4781                 goto FAIL;
4782         }
4783
4784         rect = __pOverlay->GetBounds();
4785         AppLog("overlay region  rect (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
4786
4787         return E_SUCCESS;
4788
4789 FAIL:
4790         return E_FAILURE;
4791 }
4792
4793 result
4794 VideoRecorderForm::DoRotation()
4795 {
4796         result r = E_SUCCESS;
4797         Draw();
4798
4799         AppLog("VideoRecorderForm::DoRotation");
4800
4801         r = CreateOverlayRegion();
4802         if (__pOverlay == NULL)
4803         {
4804                 AppLog("failed to get overlay region");
4805                 goto FAIL;
4806         }
4807
4808         AppLog("GetBackgroundBufferInfo handle ");
4809         r = __pOverlay->GetBackgroundBufferInfo(__bufferInfo);
4810         if (IsFailed(r))
4811         {
4812                 ShowError(r, METHOD_FILE_LINENO);
4813                 goto FAIL;
4814         }
4815
4816         if (__pCamera->GetState() == CAMERA_STATE_INITIALIZED ||
4817                 __pCamera->GetState() == CAMERA_STATE_CAPTURED)
4818         {
4819                 AppLog("start preview invoking = %s", GetErrorMessage(r));
4820                 if (__previewByCallback == 1)
4821                 {
4822                         r = __pCamera->StartPreview(NULL, true);
4823                         if (IsFailed(r))
4824                         {
4825                                 ShowError(r, METHOD_FILE_LINENO);
4826                                 goto FAIL;
4827                         }
4828                 }
4829                 else
4830                 {
4831                         r = __pCamera->StartPreview(&__bufferInfo, false);
4832                         if (IsFailed(r))
4833                         {
4834                                 ShowError(r, METHOD_FILE_LINENO);
4835                                 goto FAIL;
4836                         }
4837                 }
4838         }
4839
4840         SetFocus();
4841         Draw();
4842
4843         return r;
4844
4845 FAIL:
4846         AppLog("something failed in rotation");
4847         Draw();
4848         return r;
4849 }
4850
4851 void
4852 VideoRecorderForm::OnOrientationChanged(const Osp::Ui::Control& source, Osp::Ui::OrientationStatus orientationStatus)
4853 {
4854         result r = E_SUCCESS;
4855
4856         if (__pCamera == NULL || __pVideoRecorder == NULL)
4857         {
4858                 AppLog("Video Recorder is null");
4859                 return;
4860         }
4861
4862         AppLog("VideoRecorderForm::OnOrientationChanged called current = %d new (std::nothrow) = %d recorder state = %d", __orientationStatus, orientationStatus, __pVideoRecorder->GetState());
4863
4864         if (orientationStatus == __orientationStatus)
4865         {
4866                 AppLog("No change in orientation");
4867                 return;
4868         }
4869
4870         if (__pVideoRecorder->GetState() != RECORDER_STATE_RECORDING)
4871         {
4872                 if (!__pCamera)
4873                 {
4874                         return;
4875                 }
4876                 if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
4877                 {
4878                         r = __pCamera->StopPreview();
4879                         if (IsFailed(r))
4880                         {
4881                                 ShowError(r, METHOD_FILE_LINENO);
4882                         }
4883                 }
4884
4885                 //stop preview and recreate overlay region
4886                 ClearCanvas();
4887
4888                 SendUserEvent(RECORDER_ROTATION, null);
4889         }
4890 }
4891
4892 result
4893 VideoRecorderForm::OnDraw()
4894 {
4895         return E_SUCCESS;
4896 }
4897
4898 void
4899 VideoRecorderForm::ClearCanvas()
4900 {
4901         Osp::Graphics::Canvas* pCanvas = null;
4902         AppLog("ClearCanvas Invoked");
4903         if (__backGround == true)
4904         {
4905                 AppLog("No need to draw anything in background mode");
4906                 return;
4907         }
4908         pCanvas = GetClientAreaCanvasN();
4909         if (pCanvas == null)
4910         {
4911                 return;
4912         }
4913         pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
4914         pCanvas->Clear();
4915         Invalidate(false);
4916         delete pCanvas;
4917         return;
4918 }
4919
4920
4921 void
4922 VideoRecorderForm::OnKeyPressed(const Osp::Ui::Control& source, Osp::Ui::KeyCode keyCode)
4923 {
4924         switch (keyCode)
4925         {
4926         case KEY_SIDE_UP:
4927         {
4928                 ConsumeInputEvent();
4929         }
4930         break;
4931
4932         case KEY_SIDE_DOWN:
4933         {
4934                 ConsumeInputEvent();
4935         }
4936         break;
4937
4938         default:
4939                 break;
4940         }
4941 }
4942
4943
4944 void
4945 VideoRecorderForm::OnBatteryLevelChanged(Osp::System::BatteryLevel batteryLevel)
4946 {
4947         if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW)
4948         {
4949                 bool isCharging = false;
4950                 Osp::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging);
4951                 if ((!isCharging))
4952                 {
4953                         FreeResources();
4954                         Deactivate();
4955                 }
4956         }
4957         else
4958         {
4959                 if (__batteryLevelFlag)
4960                 {
4961                         this->OnActivate(null);
4962                 }
4963         }
4964 }
4965
4966 result
4967 VideoRecorderForm::EnableFooterItem(int actionId, bool enable)
4968 {
4969         result r = E_SUCCESS;
4970         Footer* pFooter = GetFooter();
4971         if (!pFooter)
4972         {
4973                 ShowError(GetLastResult(), METHOD_FILE_LINENO);
4974                 goto FAIL;
4975         }
4976         r = pFooter->SetItemEnabled((actionId - ID_SETTING), enable);
4977         if (IsFailed(r))
4978         {
4979                 ShowError(r, METHOD_FILE_LINENO);
4980                 goto FAIL;
4981         }
4982
4983         pFooter->RequestRedraw();
4984         return r;
4985 FAIL:
4986         return r;
4987 }
4988
4989 int
4990 VideoRecorderForm::GetIndexFromValue(Osp::Base::Collection::IListT< int >* pList, int value)
4991 {
4992         int count = pList->GetCount();
4993         result r = E_SUCCESS;
4994         int valueInList = INIT;
4995         for (int index = 0; index < count; index++)
4996         {
4997                 r = pList->GetAt(index, valueInList);
4998                 if (r == E_SUCCESS && value == valueInList)
4999                 {
5000                         AppLog("matching found at index = %d for value = %d", index, value);
5001                         return index;
5002                 }
5003         }
5004         AppLog("no matching for value = %d", value);
5005         return INIT;
5006 }
5007
5008 int
5009 VideoRecorderForm::GetIndexFromValue(Osp::Base::Collection::IList* pList, Osp::Graphics::Dimension& value)
5010 {
5011         int count = pList->GetCount();
5012         Osp::Graphics::Dimension* pDim = null;
5013         for (int index = 0; index < count; index++)
5014         {
5015                 pDim = (Dimension*) pList->GetAt(index);
5016                 if ((pDim != null) && value.Equals((*pDim)))
5017                 {
5018                         AppLog("matching found at index = %d for width = %d height = %d", index, value.width, value.height);
5019                         return index;
5020                 }
5021         }
5022         AppLog("no matching for value = %d %d", value.width, value.height);
5023         return INIT;
5024 }
5025
5026 void
5027 VideoRecorderForm::ShowFooterItems()
5028 {
5029         result r = E_SUCCESS;
5030         EnableFooterItem(ID_SETTING, true);
5031         EnableFooterItem(ID_TOGGLE_CAMERA_TYPE, true);
5032         EnableFooterItem(ID_START, true);
5033         r = GetFooter()->SetBackButtonEnabled(true);
5034         if (IsFailed(r))
5035         {
5036                 ShowError(r, METHOD_FILE_LINENO);
5037                 goto FAIL;
5038         }
5039         GetFooter()->Draw();
5040         return;
5041 FAIL:
5042         return;
5043 }