3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
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.
25 #include "SafeMacros.h"
26 #include "AppConfig.h"
27 #include "UnitTestFactory.h"
28 #include "MediaPlayerForm.h"
29 #include "VideoRecorderPlayerForm.h"
30 #include "AppResourceId.h"
33 using namespace Tizen::Ui;
34 using namespace Tizen::Io;
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::System;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui::Controls;
41 #define SECTION_NAME L"VideoRecorder_Player"
42 #define METHOD_FILE_LINENO __FUNCTION__, __FILE__, (__LINE__ - 1)
44 #define TIMER_VALUE 500
46 #define MESSAGE_BOX_TIMEOUT 10000
48 static const wchar_t* FORM_ID = L"VideoRecorderPlayerForm";
49 extern const wchar_t* VIDEO_RECORDER_PLAYER_SCENE_ID = L"VideoRecorderPlayerScene";
51 VideoRecorderPlayerForm*
52 VideoRecorderPlayerForm::CreateFormN(const Tizen::Ui::Scenes::SceneId &sceneId)
54 SceneManager* pSceneManager = SceneManager::GetInstance();
55 VideoRecorderPlayerForm* pForm = new (std::nothrow) VideoRecorderPlayerForm();
57 pSceneManager->AddSceneEventListener(sceneId, *(pForm->GetListener()));
61 MultiForm* VideoRecorderPlayerForm::FormCreateFunc()
63 VideoRecorderPlayerForm* pForm = VideoRecorderPlayerForm::CreateFormN(VIDEO_RECORDER_PLAYER_SCENE_ID);
67 String VideoRecorderPlayerForm::GetFormId()
72 SceneId VideoRecorderPlayerForm::GetSceneId()
74 return VIDEO_RECORDER_PLAYER_SCENE_ID;
76 VideoRecorderPlayerForm::VideoRecorderPlayerForm(void)
79 , __pCameraOverlay(null)
80 , __pPlayerOverlay(null)
81 , __batteryLevelFlag(false)
82 , __backGroundFlag(false)
83 , __cameraErrorFlag(false)
84 , __isHeadSetRemoved(false)
85 , __pVideoRecorder(null)
93 VideoRecorderPlayerForm::~VideoRecorderPlayerForm(void)
98 SAFE_DELETE(__pTimer);
101 SAFE_DELETE(__pCameraOverlay);
102 SAFE_DELETE(__pPlayerOverlay);
103 SAFE_DELETE(__pPlayer);
104 SAFE_DELETE(__pCamera);
105 SAFE_DELETE(__pVideoRecorder);
109 VideoRecorderPlayerForm::Initialize()
111 result r = E_SUCCESS;
112 r = Construct(IDF_VIDEO_RECORDER_PLAYER);
113 AppLog("Initialize return = %s", GetErrorMessage(r));
118 VideoRecorderPlayerForm::OnInitializing(void)
120 Footer* pFooter = GetFooter();
121 Header* pHeader = GetHeader();
123 SetHeaderText(L"Video recorder & player");
124 SetFooterStyle(FOOTER_STYLE_BUTTON_TEXT, ID_BUTTON_BACK, this);
125 AddFooterItem(L"Start", ID_BUTTON_START);
127 pFooter->AddTouchEventListener(*this);
128 pHeader->AddTouchEventListener(*this);
130 __pProgress = static_cast< Progress* >(GetControl(IDC_PROGRESS));
131 TryReturn(__pProgress != null, E_FAILURE,"__pProgress value is null from GetControl");
133 __pProgress->SetValue(0);
136 __pConfig = AppConfig::GetInstance();
137 TryReturn(__pConfig != null, ShowErrorResult(E_FAILURE, METHOD_FILE_LINENO),"__pConfig is null");
139 //disable all buttons until camera is ready
140 ShowFooterItem(0, false);
142 AppLog("VideoRecorderPlayerForm::OnInitializing returned success");
148 VideoRecorderPlayerForm::CreateOverlayRegionForCamera(void)
150 Rectangle rect = GetClientAreaBounds();
151 Rectangle clientRect = GetClientAreaBounds();
152 bool modified = false;
153 bool isValidRect = false;
155 SAFE_DELETE(__pCameraOverlay);
157 AppLog("Client area rect (%d,%d,%d,%d)", clientRect.x, clientRect.y, clientRect.width, clientRect.height);
158 HideAndGetBounds(GetControl(IDC_OVERLAY_REGION), rect);
159 AppLog("Original w.r.t IDC_BUTTON rect (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
161 if (rect.width > clientRect.width || rect.height > clientRect.height)
163 rect.width = clientRect.width;
164 rect.height = clientRect.height;
167 AppLog("Rect passed to OverlayRegion::EvaluateBounds is (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
168 isValidRect = OverlayRegion::EvaluateBounds(OVERLAY_REGION_EVALUATION_OPTION_LESS_THAN, rect, modified);
169 TryReturn(isValidRect == true, ShowErrorResult(GetLastResult(), METHOD_FILE_LINENO),"OverlayRegion::EvaluateBounds returned error");
171 if (modified == true)
173 AppLog("Bounds is modified to (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
176 AppLog("Overlay region width = %d height = %d", rect.width, rect.height);
178 __pCameraOverlay = Tizen::Ui::Controls::Form::GetOverlayRegionN(rect, OVERLAY_REGION_TYPE_PRIMARY_CAMERA);
179 AppLog("Overlay region pointer = %X x = %d, y = %d, width = %d height = %d", __pCameraOverlay, rect.x, rect.y, rect.width, rect.height);
181 TryReturn(__pCameraOverlay != null, ShowErrorResult(GetLastResult(), METHOD_FILE_LINENO),"__pCameraOverlay is null");
187 VideoRecorderPlayerForm::CreateOverlayRegionForPlayer(void)
189 Rectangle rect = GetClientAreaBounds();
190 Rectangle clientRect = GetClientAreaBounds();
191 bool modified = false;
192 bool isValidRect = false;
194 SAFE_DELETE(__pPlayerOverlay);
196 AppLog("Client area rect (%d,%d,%d,%d)", clientRect.x, clientRect.y, clientRect.width, clientRect.height);
197 HideAndGetBounds(GetControl(IDC_OVERLAY_REGION2), rect);
198 AppLog("Original rect (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
200 if (rect.width > clientRect.width || rect.height > clientRect.height)
202 rect.width = clientRect.width;
203 rect.height = clientRect.height;
206 isValidRect = OverlayRegion::EvaluateBounds(OVERLAY_REGION_EVALUATION_OPTION_LESS_THAN, rect, modified);
207 TryReturn(isValidRect == true, ShowErrorResult(GetLastResult(), METHOD_FILE_LINENO),"OverlayRegion::EvaluateBounds returned error");
209 if (modified == true)
211 AppLog("Bounds is modified to (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
214 AppLog("Overlay region width = %d height = %d", rect.width, rect.height);
216 __pPlayerOverlay = Tizen::Ui::Controls::Form::GetOverlayRegionN(rect, OVERLAY_REGION_TYPE_NORMAL);
217 AppLog("Overlay region pointer = %X x = %d, y = %d, width = %d height = %d", __pCameraOverlay, rect.x, rect.y, rect.width, rect.height);
219 TryReturn(__pPlayerOverlay != null, ShowErrorResult(GetLastResult(), METHOD_FILE_LINENO),"__pPlayerOverlay is null");
223 VideoRecorderPlayerForm*
224 VideoRecorderPlayerForm::GetListener(void)
229 VideoRecorderPlayerForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
230 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
235 VideoRecorderPlayerForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
236 const Tizen::Ui::Scenes::SceneId& nextSceneId)
241 VideoRecorderPlayerForm::Activate(void* activateParam)
243 result r = E_SUCCESS;
244 Tizen::System::BatteryLevel batteryLevel;
245 Tizen::System::Battery::GetCurrentLevel(batteryLevel);
247 __backGroundFlag = false;
248 __cameraErrorFlag = false;
250 if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW)
252 bool isCharging = false;
253 Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging);
254 if (isCharging == false)
256 ShowMessagePopup("Please Charge the Battery to use this feature", ID_BUTTON_ERROR_POPUP_OK);
261 EnableFooterItem(ID_BUTTON_START, true);
266 EnableFooterItem(ID_BUTTON_START, true);
269 __batteryLevelFlag = false;
271 Tizen::System::PowerManager::KeepScreenOnState(true, false);
272 SetOrientation(ORIENTATION_LANDSCAPE);
274 r = CreateOverlayRegionForCamera();
275 TryReturn(r == E_SUCCESS, r,"CreateOverlayRegionForCamera failed");
277 r = CreateOverlayRegionForPlayer();
278 TryReturn(r == E_SUCCESS, r,"CreateOverlayRegionForPlayer failed");
280 __pProgress->SetValue(0);
283 SAFE_DELETE(__pTimer);
284 __pTimer = new (std::nothrow) Tizen::Base::Runtime::Timer;
285 TryReturn(__pTimer != null, E_OUT_OF_MEMORY,"__pTimer creation failed, no memory");
287 r = __pTimer->Construct(*this);
288 TryReturn(r == E_SUCCESS, r,"[%s] __pTimer->Construct", GetErrorMessage(r));
291 TryReturn(r == E_SUCCESS, r,"[%s] createCamera failed", GetErrorMessage(r));
293 r = CreateVideoRecorder();
294 TryReturn(r == E_SUCCESS, r,"[%s] CreateVideoRecorder failed", GetErrorMessage(r));
296 SetFooterItem(0, L"Start", ID_BUTTON_START);
301 VideoRecorderPlayerForm::CreateCamera()
303 result r = E_SUCCESS;
305 __pCamera = new (std::nothrow) Camera();
306 TryReturn(__pCamera != null, ShowErrorResult(E_OUT_OF_MEMORY, METHOD_FILE_LINENO),"__pCamera creation failed, no memory");
308 r = __pCamera->Construct(*this, CAMERA_PRIMARY);
309 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pCamera->Construct", GetErrorMessage(r));
311 r = __pCamera->PowerOn();
312 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pCamera->PowerOn", GetErrorMessage(r));
318 VideoRecorderPlayerForm::CreateVideoRecorder()
320 result r = E_SUCCESS;
322 __pVideoRecorder = new (std::nothrow) Tizen::Media::VideoRecorder();
323 TryReturn(__pVideoRecorder != null, ShowErrorResult(E_OUT_OF_MEMORY, METHOD_FILE_LINENO),"__pVideoRecorder creation failed, no memory");
325 r = __pVideoRecorder->Construct(*this, *__pCamera);
326 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pVideoRecorder->Construct", GetErrorMessage(r));
332 VideoRecorderPlayerForm::CreatePlayer()
334 result r = E_SUCCESS;
335 Tizen::Graphics::BufferInfo bufferInfo;
338 filePath.Append(App::GetInstance()->GetAppRootPath());
339 filePath.Append(__pConfig->GetString(SECTION_NAME, String(L"playerFileName")));
341 AppLog("playerFileName is %ls", filePath.GetPointer());
343 SAFE_DELETE(__pPlayer);
345 __pPlayer = new (std::nothrow) Player();
346 TryReturn(__pPlayer != null, ShowErrorResult(E_OUT_OF_MEMORY, METHOD_FILE_LINENO),"__pPlayer creation failed, no memory");
348 r = __pPlayerOverlay->GetBackgroundBufferInfo(bufferInfo);
349 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pPlayerOverlay->GetBackgroundBufferInfo", GetErrorMessage(r));
351 r = __pPlayer->Construct(*this, &bufferInfo);
352 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pPlayer->Construct", GetErrorMessage(r));
354 AppLog("File path is %ls", filePath.GetPointer());
355 r = __pPlayer->OpenFile(filePath); // Sync open, at once
356 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] pPlayer->OpenFile", GetErrorMessage(r));
358 r = __pPlayer->SetLooping(true);
359 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pPlayer->SetLooping", GetErrorMessage(r));
361 r = __pPlayer->SetVolume(80);
362 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pPlayer->SetVolume", GetErrorMessage(r));
368 VideoRecorderPlayerForm::StartCamera()
370 result r = E_SUCCESS;
371 IList* pPreviewResolutionList = null;
372 Dimension* pResolution = null;
374 TryReturn(__pCameraOverlay != null, ShowErrorResult(E_FAILURE, METHOD_FILE_LINENO),"__pCameraOverlay handle is null");
375 TryReturn(__pCamera != null, ShowErrorResult(E_FAILURE, METHOD_FILE_LINENO),"__pCamera handle is null");
377 r = __pCameraOverlay->GetBackgroundBufferInfo(__bufferInfoCamera);
378 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"__pCameraOverlay->GetBackgroundBufferInfo");
380 pPreviewResolutionList = __pCamera->GetSupportedPreviewResolutionListN();
381 TryCatch(pPreviewResolutionList != null, ShowError(GetLastResult(), METHOD_FILE_LINENO), " __pCamera->GetSupportedPreviewResolutionListN returned empty");
383 pResolution = static_cast< Dimension* >(pPreviewResolutionList->GetAt(0));
384 TryCatch(pResolution != null, ShowError(E_SYSTEM, METHOD_FILE_LINENO),"pPreviewResolutionList->GetAt");
386 r = __pCamera->SetPreviewResolution(*pResolution);
387 TryCatch(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO),"[%s] __pCamera->SetPreviewResolution", GetErrorMessage(r));
388 AppLog(" PreviewResolution = width(%d) height(%d)", pResolution->width, pResolution->height);
391 AppLog("StartPreview called");
392 r = __pCamera->StartPreview(&__bufferInfoCamera, false);
393 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"__pCamera->StartPreview");
395 pPreviewResolutionList->RemoveAll(true);
396 delete pPreviewResolutionList;
400 if (pPreviewResolutionList != null)
402 pPreviewResolutionList->RemoveAll(true);
403 delete pPreviewResolutionList;
409 VideoRecorderPlayerForm::StopCamera()
411 result r = E_SUCCESS;
413 TryReturn(__pCamera != null, ShowErrorResult(E_FAILURE, METHOD_FILE_LINENO),"__pCamera handle is null");
415 if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
417 r = __pCamera->StopPreview();
418 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"__pCamera->StopPreview");
425 VideoRecorderPlayerForm::GetAudioCodecFormat(String& audioCodecType, CodecType& audioCodec)
427 //Only supported audio codecs are checked
428 if (audioCodecType == L"AMR_NB")
430 audioCodec = CODEC_AMR_NB;
432 else if (audioCodecType == L"AAC")
434 audioCodec = CODEC_AAC;
438 audioCodec = CODEC_NONE;
443 VideoRecorderPlayerForm::GetVideoCodecFormat(String& videoCodecType, CodecType& videoCodec)
445 //Only supported video codecs are checked
446 if (videoCodecType == L"H263")
448 videoCodec = CODEC_H263;
450 else if (videoCodecType == L"MPEG4")
452 videoCodec = CODEC_MPEG4;
454 else if (videoCodecType == L"H264")
456 videoCodec = CODEC_H264;
460 videoCodec = CODEC_NONE;
465 VideoRecorderPlayerForm::GetFileFormat(String& fileFormatType, MediaContainerType& fileformat)
467 //Only supported video codecs are checked
468 if (fileFormatType == L"3gp")
470 fileformat = MEDIA_CONTAINER_3GP;
472 else if (fileFormatType == L"MP4")
474 fileformat = MEDIA_CONTAINER_MP4;
478 fileformat = MEDIA_CONTAINER_NONE;
483 VideoRecorderPlayerForm::StartRecording()
485 result r = E_SUCCESS;
486 CodecType audioCodec = CODEC_NONE;
487 CodecType videoCodec = CODEC_NONE;
488 MediaContainerType container = MEDIA_CONTAINER_NONE;
489 unsigned int maxRecordingTime = 0;
490 String audioCodecType;
491 String videoCodectype;
492 String fileFormatType;
493 IList* pRecordingResolutionList = null;
494 Dimension* pResolution = null;
497 __filePath.Append(App::GetInstance()->GetAppRootPath() + L"data/Video/videorecorder.3gp");
499 maxRecordingTime = __pConfig->GetInt(0, SECTION_NAME, String(L"maxRecordingTime"));
501 if (maxRecordingTime == 0 || maxRecordingTime == 0)
503 maxRecordingTime = (15 * 1000); //15 sec
506 audioCodecType = __pConfig->GetString(SECTION_NAME, String(L"audioCodec"));
507 videoCodectype = __pConfig->GetString(SECTION_NAME, String(L"videoCodec"));
508 fileFormatType = __pConfig->GetString(SECTION_NAME, String(L"FileFormat"));
510 GetAudioCodecFormat(audioCodecType, audioCodec);
511 GetVideoCodecFormat(videoCodectype, videoCodec);
512 GetFileFormat(fileFormatType, container);
514 if (audioCodec == CODEC_NONE ||
515 videoCodec == CODEC_NONE ||
516 container == MEDIA_CONTAINER_NONE)
518 AppLog("reset- audioCodec is %d, videoCodec is %d, container is %d", audioCodec, videoCodec, container);
519 //set to default configuration
520 audioCodec = CODEC_AMR_NB;
521 videoCodec = CODEC_H263;
522 container = MEDIA_CONTAINER_3GP;
525 AppLog("maxRecordingTime is %d", maxRecordingTime);
527 __maxRecordingTime = (maxRecordingTime / KILOBYTE);
529 pRecordingResolutionList = __pVideoRecorder->GetSupportedRecordingResolutionListN();
530 TryCatch(pRecordingResolutionList != null, ShowError(GetLastResult(), METHOD_FILE_LINENO), " __pVideoRecorder->GetSupportedRecordingResolutionListN returned empty");
532 pResolution = static_cast< Dimension* >(pRecordingResolutionList->GetAt(0));
533 TryCatch(pResolution != null, ShowError(E_SYSTEM, METHOD_FILE_LINENO),"pRecordingResolutionList->GetAt");
534 AppLog(" RecordingResolution = width(%d) height(%d)", pResolution->width, pResolution->height);
536 r = __pVideoRecorder->SetRecordingResolution(*pResolution);
537 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->SetRecordingResolution", GetErrorMessage(r));
539 r = __pVideoRecorder->SetFormat(audioCodec, videoCodec, container);
540 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->SetFormat", GetErrorMessage(r));
542 r = __pVideoRecorder->SetQuality(RECORDING_QUALITY_HIGH);
543 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->SetQuality", GetErrorMessage(r));
545 r = __pVideoRecorder->SetMaxRecordingTime(maxRecordingTime);
546 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->SetMaxRecordingTime", GetErrorMessage(r));
550 __pProgress->SetRange(0, 100); //progress based on recorded %
553 r = __pVideoRecorder->CreateVideoFile(__filePath, true);
554 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->CreateVideoFile", GetErrorMessage(r));
556 r = __pVideoRecorder->Record();
557 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->Record", GetErrorMessage(r));
559 pRecordingResolutionList->RemoveAll(true);
560 delete pRecordingResolutionList;
563 if (pRecordingResolutionList != null)
565 pRecordingResolutionList->RemoveAll(true);
566 delete pRecordingResolutionList;
572 VideoRecorderPlayerForm::StartVideoRecorder()
574 if (__pVideoRecorder)
576 result r = E_SUCCESS;
577 RecorderState state = __pVideoRecorder->GetState();
579 if ((RECORDER_STATE_INITIALIZED == state) || (RECORDER_STATE_OPENED == state) || \
580 (RECORDER_STATE_PAUSED == state) || (RECORDER_STATE_CLOSED == state) || \
581 (RECORDER_STATE_STOPPED == state))
583 AppLog("Start video Recording");
585 r = StartRecording();
586 TryReturn(r == E_SUCCESS, E_FAILURE," Start Recording failed");
588 AppLog("__pTimer value is %x",__pTimer);
589 r = __pTimer->Start(TIMER_VALUE);
590 TryReturn((r == E_SUCCESS && r != E_INVALID_STATE), ShowErrorResult(r, METHOD_FILE_LINENO),"__pTimer->Start");
594 ShowErrorResult(E_INVALID_STATE, METHOD_FILE_LINENO);
595 return E_INVALID_STATE;
598 AppLog("__pVideoRecorder handle is null");
603 VideoRecorderPlayerForm::StopVideoRecorder()
605 result r = E_SUCCESS;
607 AppLog("StopRecord called");
610 r = __pVideoRecorder->Stop();
611 //Once stop is called. close will be called in OnVideoRecorderStopped()
618 VideoRecorderPlayerForm::StartPlayer()
620 result r = E_SUCCESS;
622 TryReturn(r == E_SUCCESS, r,"[%s] createPlayer failed", GetErrorMessage(r));
624 r = __pPlayer->Play();
625 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] Player Play has failed", GetErrorMessage(r));
631 VideoRecorderPlayerForm::StopPlayer()
635 result r = E_SUCCESS;
636 PlayerState nowState = __pPlayer->GetState();
639 if (nowState == PLAYER_STATE_PLAYING || nowState == PLAYER_STATE_PAUSED)
641 AppLog("Player Stop");
642 r = __pPlayer->Stop();
643 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] Player Stop failed", GetErrorMessage(r));
645 r = __pPlayer->Close();
646 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] Player Close failed", GetErrorMessage(r));
656 VideoRecorderPlayerForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
662 __pProgress->SetValue(0);
670 case ID_BUTTON_START:
672 SendUserEvent(START_RECORDING, null);
673 ShowFooterItem(0, false);
680 SendUserEvent(STOP_RECORDING, null);
681 ShowFooterItem(0, false);
682 __pProgress->SetValue(0);
687 case ID_BUTTON_ERROR_POPUP_OK:
689 AppLog("Destroy Error Message Popup\n");
690 MultiForm::ClearErrorPopup();
704 VideoRecorderPlayerForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
706 result r = E_SUCCESS;
707 AppLog("VideoRecorderPlayerForm::OnUserEventReceivedN : request id = %d", requestId);
710 case START_RECORDING:
713 TryCatch(r == E_SUCCESS, ,"[%s] StartCamera failed", GetErrorMessage(r));
715 r = StartVideoRecorder();
716 TryCatch(r == E_SUCCESS, ,"[%s] StartVideoRecorder failed", GetErrorMessage(r));
718 AppLog("Recorder started");
721 TryCatch(r == E_SUCCESS, ,"[%s] StartPlayer failed", GetErrorMessage(r));
723 AppLog("Player started");
725 SetFooterItem(0, L"Stop", ID_BUTTON_STOP);
733 TryCatch(r == E_SUCCESS, ,"[%s] StopPlayer failed", GetErrorMessage(r));
735 r = StopVideoRecorder();
736 TryCatch((r == E_SUCCESS || r == E_INVALID_STATE), ,"[%s] StopVideoRecorder failed", GetErrorMessage(r));
739 TryCatch(r == E_SUCCESS, ,"[%s] StopCamera failed", GetErrorMessage(r));
741 SetFooterItem(0, L"Start", ID_BUTTON_START);
745 case RECORDER_ON_STOP:
747 if (__pVideoRecorder)
749 AppLog("__pVideoRecorder->Close() is called");
750 __pVideoRecorder->Close();
755 case RECORDER_ON_CLOSE:
759 FreeCameraResource();
760 FreePlayerResource();
763 SAFE_DELETE(__pVideoRecorder);
764 SAFE_DELETE(__pCamera);
765 SAFE_DELETE(__pPlayer);
766 SAFE_DELETE(__pCameraOverlay);
767 SAFE_DELETE(__pPlayerOverlay);
768 AppLog("Launching the mediaPlayer");
769 //To complete freeResource activity before launching MediaPlayerForm
770 LaunchMediaPlayer(false);
771 __backGroundFlag = true;
782 AppLog("Error occured %s", GetErrorMessage(r));
783 __cameraErrorFlag = true;
788 VideoRecorderPlayerForm::LaunchMediaPlayer(bool flag)
790 ArrayList* pArg = null;
793 Integer* pDeviceOrientation = 0;
794 result r = E_SUCCESS;
796 AppLog("MediaPlayerForm's LaunchMediaPlayer invoked file path %ls", __filePath.GetPointer());
798 pMediaType = new (std::nothrow) String;
799 TryReturnVoid(pMediaType != null, "pMediaType string is null, no memory");
801 pMediaType->Append(L"VIDEO");
803 pFilePath = new (std::nothrow) String;
804 TryReturnVoid(pFilePath != null, "pFilePath string is null, no memory");
806 pFilePath->Append(__filePath);
808 pDeviceOrientation = new (std::nothrow) Integer(0);
809 TryReturnVoid(pDeviceOrientation != null, "pDeviceOrientation string is null, no memory");
811 pArg = new (std::nothrow) ArrayList;
812 TryReturnVoid(pArg != null, "ArrayList creation failed, no memory");
813 r = pArg->Construct();
814 TryReturnVoid(r == E_SUCCESS, "[%s] pArg->Construct()", GetErrorMessage(r));
816 pArg->Add(*pMediaType);
817 pArg->Add(*pFilePath);
818 pArg->Add(*pDeviceOrientation);
820 SceneManager* pSceneManager = SceneManager::GetInstance();
821 TryReturnVoid(pSceneManager != null, "pSceneManager handle is null");
823 pSceneManager->GoForward(ForwardSceneTransition(L"MediaPlayerScene"), pArg);
828 VideoRecorderPlayerForm::GetCameraToForeground(void)
830 AppLog("GetCameraForeground");
832 result r = E_SUCCESS;
833 if (__pCamera != null)
835 if (__pCamera->IsPoweredOn() == false)
837 r = __pCamera->PowerOn();
838 TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] __pCamera->PowerOn()", GetErrorMessage(r));
840 r = __pCameraOverlay->GetBackgroundBufferInfo(__bufferInfoCamera);
841 TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] __pCameraOverlay->GetBackgroundBufferInfo", GetErrorMessage(r));
843 r = __pCamera->StartPreview(&__bufferInfoCamera, false);
844 TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] __pCamera->StartPreview", GetErrorMessage(r));
850 VideoRecorderPlayerForm::GetVideoRecorderToForeground(void)
852 result r = E_SUCCESS;
853 r = CreateVideoRecorder();
854 TryReturnVoid(r == E_SUCCESS, "[%s] CreateVideoRecorder failed", GetErrorMessage(r));
857 VideoRecorderPlayerForm::GetPlayerToForeground(void)
859 result r = E_SUCCESS;
860 if (__pPlayer != null)
862 if (__pPlayer->GetState() == PLAYER_STATE_PAUSED)
864 r = __pPlayer->Play();
865 TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] Player->Play failed", GetErrorMessage(r));
867 else if (__pPlayer->GetState() == PLAYER_STATE_CLOSED)
875 VideoRecorderPlayerForm::OnForeground(void)
878 AppLog("VideoRecorderPlayerForm::OnForeground");
879 if (__backGroundFlag == true)
881 VideoRecorderPlayerForm::Activate(null);
884 __backGroundFlag = false;
885 __cameraErrorFlag = false;
889 VideoRecorderPlayerForm::PlayerPause()
891 if (__pPlayer != null)
893 result r = E_SUCCESS;
894 // Pause the playing.
895 if (__pPlayer->GetState() == PLAYER_STATE_PLAYING)
897 r = __pPlayer->Pause();
898 TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] Player->Pause failed", GetErrorMessage(r));
904 VideoRecorderPlayerForm::SendVideoRecorderToBackground(void)
906 if (__pVideoRecorder != null)
908 __pVideoRecorder->Cancel();
909 __pVideoRecorder->Close();
914 VideoRecorderPlayerForm::SendCameraToBackground(void)
916 result r = E_SUCCESS;
917 TryReturnVoid(__pCamera != null, "Camera handle is null");
919 if ( __pCamera->GetState() == CAMERA_STATE_PREVIEW)
921 r = __pCamera->StopPreview();
924 AppLog("OnBackground StopPreview error %s", GetErrorMessage(r));
925 ShowError(r, METHOD_FILE_LINENO);
928 if (__pCamera->IsPoweredOn() == true)
930 r = __pCamera->PowerOff();
931 TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] OnBackground PowerOff", GetErrorMessage(r));
937 VideoRecorderPlayerForm::SendPlayerToBackground(void)
939 TryReturnVoid(__pPlayer != null, "Player handle is null");
941 if (__pPlayer->GetState() == PLAYER_STATE_PLAYING)
948 VideoRecorderPlayerForm::OnBackground(void)
950 AppLog("OnBackground Enter");
953 if (__pTimer != null)
958 FreeVideoRecorderResource();
959 FreeCameraResource();
960 FreePlayerResource();
962 SAFE_DELETE(__pVideoRecorder);
963 SAFE_DELETE(__pCamera);
964 SAFE_DELETE(__pPlayer);
965 SAFE_DELETE(__pCameraOverlay);
966 SAFE_DELETE(__pPlayerOverlay);
968 ShowFooterItem(0, true);
969 __pProgress->SetValue(0);
971 SetFooterItem(0, L"Start", ID_BUTTON_START);
973 __backGroundFlag = true;
977 VideoRecorderPlayerForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
979 AppLog("CameraCaptureForm::OnFormBackRequested called");
981 __backGroundFlag = true;
982 ShowFooterItem(0, false);
984 SetFooterItem(0, L"Start", ID_BUTTON_START);
987 MultiForm::ClearErrorPopup();
993 VideoRecorderPlayerForm::FreeVideoRecorderResource(void)
995 if (__pVideoRecorder != null)
997 __pVideoRecorder->Cancel();
998 __pVideoRecorder->Close();
1003 VideoRecorderPlayerForm::FreeCameraResource(void)
1005 TryReturnVoid(__pCamera != null, "Camera handle is null");
1007 if (__pCamera->IsPoweredOn() == true)
1009 if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
1010 __pCamera->StopPreview();
1013 if (__pCamera->IsPoweredOn() == true)
1015 __pCamera->PowerOff();
1020 VideoRecorderPlayerForm::FreePlayerResource(void)
1026 VideoRecorderPlayerForm::FreeResources(void)
1028 if (__pTimer != null)
1032 FreeVideoRecorderResource();
1033 FreeCameraResource();
1034 FreePlayerResource();
1036 SAFE_DELETE(__pVideoRecorder);
1037 SAFE_DELETE(__pCamera);
1038 SAFE_DELETE(__pPlayer);
1039 SAFE_DELETE(__pCameraOverlay);
1040 SAFE_DELETE(__pPlayerOverlay);
1041 SAFE_DELETE(__pTimer);
1045 VideoRecorderPlayerForm::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
1047 AppLog("VideoRecorderPlayerForm::OnTimerExpired");
1048 if (&timer == __pTimer && __pVideoRecorder != null)
1050 long duration = __pVideoRecorder->GetRecordingTime();
1051 long recordedSize = __pVideoRecorder->GetRecordingSize(); //size is in KB
1052 if ( (__maxRecordingTime > 0) && (duration > 0) && (recordedSize > 0))
1054 int currTimePer = (duration) / (__maxRecordingTime * 10);
1056 AppLog("Recorded Duration = %d current time percentage = %d recorded size = %d", duration, currTimePer, recordedSize);
1058 __pProgress->SetValue(currTimePer);
1060 __pProgress->Draw();
1061 __pProgress->Show();
1064 timer.Start(TIMER_VALUE);
1068 VideoRecorderPlayerForm::OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel)
1070 if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW)
1072 bool isCharging = false;
1073 Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging);
1074 if (isCharging == false)
1082 if (__batteryLevelFlag == true)
1090 VideoRecorderPlayerForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
1094 case DEVICE_TYPE_CHARGER:
1100 case DEVICE_TYPE_WIRED_HEADSET:
1102 case DEVICE_TYPE_WIRED_HEADPHONE:
1104 __isHeadSetRemoved = true;
1113 VideoRecorderPlayerForm::EnableFooterItem(int actionId, bool enable)
1115 result r = E_SUCCESS;
1116 Footer* pFooter = GetFooter();
1117 TryReturn(pFooter != null, E_FAILURE, "GetFooter Failed");
1119 pFooter->SetItemEnabled((actionId - ID_BUTTON_START), enable);
1120 pFooter->RequestRedraw();
1125 VideoRecorderPlayerForm::ShowError(result r, const char* pMethod, const char* pSrcfileName, int lineNo)
1127 AppLog("method %s file name %s line no. %d", pMethod, pSrcfileName, lineNo);
1128 ShowErrorMessagePopup(SECTION_NAME, L"VideoRecorderPlayerForm", pMethod, r, pSrcfileName, lineNo, GetErrorMessage(r));
1132 VideoRecorderPlayerForm::ShowErrorResult(result r, const char* pMethod, const char* pSrcfileName, int lineNo)
1134 AppLog("method %s file name %s line no. %d", pMethod, pSrcfileName, lineNo);
1135 ShowErrorMessagePopup(SECTION_NAME, L"VideoRecorderPlayerForm", pMethod, r, pSrcfileName, lineNo, GetErrorMessage(r));
1140 VideoRecorderPlayerForm::DeletePopup(Popup** pPopup)
1142 if (pPopup != null && *pPopup != null)
1144 (*pPopup)->RemoveAllControls();
1151 VideoRecorderPlayerForm::CreatePopUp(Popup** pPopupCtrl, String title, Dimension dimension, bool hasTitle)
1153 result r = E_SUCCESS;
1154 Popup* pCtrl = new (std::nothrow) Popup();
1155 TryReturn(pCtrl != null, E_OUT_OF_MEMORY, "Popup creation Failed");
1157 *pPopupCtrl = pCtrl;
1158 r = pCtrl->Construct(hasTitle, dimension);
1159 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO), "[%s] Popup Construct Failed", GetErrorMessage(r));
1161 if (hasTitle == true)
1163 r = pCtrl->SetTitleText(String(title));
1164 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO), "[%s] Popup SetTitleText Failed", GetErrorMessage(r));
1171 VideoRecorderPlayerForm::ShowPopUp(Popup* pPopUp)
1173 result r = E_SUCCESS;
1175 TryReturn(pPopUp != null, E_FAILURE, "Popup handle is null");
1177 r = pPopUp->SetShowState(true);
1178 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO), "[%s] Popup SetShowState", GetErrorMessage(r));
1181 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO), "[%s] Popup show", GetErrorMessage(r));
1188 VideoRecorderPlayerForm::HidePopUp(Popup* pPopUp)
1190 TryReturnVoid(pPopUp != null, "Popup handle is null");
1192 pPopUp->SetShowState(false);
1198 VideoRecorderPlayerForm::OnTerminating(void)
1200 AppLog("OnTerminating");
1205 VideoRecorderPlayerForm::OnCameraAutoFocused(bool completeCondition)
1211 VideoRecorderPlayerForm::OnCameraCaptured(Tizen::Base::ByteBuffer& capturedData, result r)
1217 VideoRecorderPlayerForm::OnCameraErrorOccurred(CameraErrorReason r)
1219 AppLog("OnCameraErrorOccurred");
1220 __cameraErrorFlag = true;
1224 VideoRecorderPlayerForm::OnCameraPreviewed(Tizen::Base::ByteBuffer& previewedData, result r)
1230 VideoRecorderPlayerForm::OnPlayerOpened(result r)
1236 VideoRecorderPlayerForm::OnPlayerEndOfClip(void)
1242 VideoRecorderPlayerForm::OnPlayerBuffering(int percent)
1248 VideoRecorderPlayerForm::OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r)
1253 VideoRecorderPlayerForm::OnPlayerInterrupted(void)
1259 VideoRecorderPlayerForm::OnPlayerReleased(void)
1265 VideoRecorderPlayerForm::OnPlayerSeekCompleted(result r)
1271 VideoRecorderPlayerForm::OnPlayerAudioFocusChanged(void)
1273 AppLog("[rr]OnPlayerAudioFocusChanged");
1274 TryReturnVoid(__pPlayer != null, "Player handle is null");
1275 if ( __isHeadSetRemoved == true && (__pPlayer->GetState() == PLAYER_STATE_PAUSED))
1277 AppLog("[rr]__isHeadSetRemoved is true");
1278 result r = E_SUCCESS;
1279 r = __pPlayer->Play();
1280 TryReturnVoid(r == E_SUCCESS, "[%s] Player Play has failed", GetErrorMessage(r));
1281 __isHeadSetRemoved = false;
1286 VideoRecorderPlayerForm::OnVideoRecorderCanceled(result r)
1288 AppLog("OnVideoRecorderCanceled");
1293 VideoRecorderPlayerForm::OnVideoRecorderClosed(result r)
1295 AppLog("OnVideoRecorderClosed __backGroundFlag is %d,__cameraErrorFlag is %d ",__backGroundFlag,__cameraErrorFlag);
1297 if (!__backGroundFlag && __cameraErrorFlag == false)
1299 SendUserEvent(RECORDER_ON_CLOSE, null);
1300 ShowFooterItem(0, true);
1305 VideoRecorderPlayerForm::Activate(null);
1306 AppLog("Could not launch the mediaplayer");
1311 VideoRecorderPlayerForm::OnVideoRecorderEndReached(Tizen::Media::RecordingEndCondition endCondition)
1313 AppLog("OnVideoRecorderEndReached");
1314 __pVideoRecorder->Close();
1317 __pProgress->SetValue(100);
1318 __pProgress->Draw();
1319 __pProgress->Show();
1321 SetFooterItem(0, L"Start", ID_BUTTON_START);
1325 VideoRecorderPlayerForm::ConvertRecorderErrorToError(Tizen::Media::RecorderErrorReason r)
1327 result res = E_SUCCESS;
1330 case RECORDER_ERROR_OUT_OF_STORAGE:
1332 case RECORDER_ERROR_STORAGE_FAILED:
1333 res = E_STORAGE_FULL;
1343 VideoRecorderPlayerForm::OnVideoRecorderErrorOccurred(Tizen::Media::RecorderErrorReason r)
1345 AppLog("OnVideoRecorderErrorOccurred");
1347 result res = E_SUCCESS;
1349 res = ConvertRecorderErrorToError(r);
1350 if (res != E_SUCCESS)
1352 __pCamera->StopPreview();
1353 ShowErrorResult(res, METHOD_FILE_LINENO);
1358 __pVideoRecorder->Close();
1366 VideoRecorderPlayerForm::OnVideoRecorderPaused(result r)
1368 AppLog("OnVideoRecorderPaused");
1372 VideoRecorderPlayerForm::OnVideoRecorderStarted(result r)
1374 AppLog("OnVideoRecorderStarted");
1375 ShowFooterItem(0, true);
1379 VideoRecorderPlayerForm::OnVideoRecorderStopped(result r)
1381 AppLog("OnVideoRecorderStopped");
1382 __pVideoRecorder->Close();