e1070a113e53792c18d694644459ee0ed380a2b4
[framework/web/wrt-plugins-common.git] / src / modules / tizen / DEPRACATED / Camera / Camera.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @author      Karol Majewski (k.majewski@samsung.com)
18  * @version     0.1
19  * @brief
20  */
21
22 #ifndef WRTPLUGINSCAMERA_H_
23 #define WRTPLUGINSCAMERA_H_
24
25 #include <string>
26 #include <mm_types.h>
27 #include <mm_error.h>
28 #include <mm_camcorder.h>
29 #include <dpl/log/log.h>
30 #include <dpl/generic_event.h>
31 #include <dpl/event/controller.h>
32 #include <dpl/type_list.h>
33 #include <API/Camera/ICamera.h>
34 #include <API/Camera/ICaptureOptions.h>
35 #include <API/Camera/EventTakePicture.h>
36 #include <API/Camera/EventBeginRecording.h>
37 #include <API/Camera/EventEndRecording.h>
38 #include <API/Camera/EventRequestLiveVideo.h>
39 #include <platform/commons/Dimension.h>
40
41 namespace WrtPlugins {
42 namespace Platform {
43 namespace Camera {
44 DECLARE_GENERIC_EVENT_0(JobDoneEvent)
45 //=============================================================================
46 class Camera : public Api::Camera::ICamera,
47     public DPL::Event::Controller<DPL::TypeListDecl<JobDoneEvent>::Type >
48 {
49   public:
50     enum CameraState
51     {
52         IDLE,               //camera is ready to take action
53         PROCESSING,             //camera object is under destruction or performing some inner operations - can't change the state
54         CAPTURING_IMAGE,    //image capture is in progress
55         CAPTURING_VIDEO    //video capture is in progress
56     };
57
58   private:
59     typedef Dimension Resolution;
60
61   private:
62
63     /*setting some default attributes for camcorder*/
64     void setDefaultAttributes();
65     /*
66      * Sets camcorder attributes based on capture options
67      */
68     void setCaptureOptions(
69             const Api::Camera::ICaptureOptionsPtr &captureOptions);
70
71     /*
72      * checks if given error code means invalid parameter
73      */
74     void tryIsInvalidParameterError(int errorCode);
75
76     MMCamPreset m_camcorderPreset;
77
78     MMHandleType m_camcorderHandle;
79
80     /*
81      * Current camera state
82      */
83     CameraState m_state;
84
85     /*
86      * Mutex for m_state
87      */
88     pthread_mutex_t m_stateMutex;
89
90     int reInitializeCamcorderForPicture(
91             const Api::Camera::ICaptureOptionsPtr &captureOptions);
92
93     int reInitializeCamcorderForVideo(
94             const Api::Camera::ICaptureOptionsPtr &captureOptions);
95
96     /*
97      * Wrapper for realizing camcorder
98      */
99     bool realizeCamcoder();
100
101     /*
102      * Wrapper for unrealizing camcorder
103      */
104     int unRealizeCamcoder();
105
106     /* Body of the callback function msg_callback */
107     static int camcorderMessageCallback(int msg_type,
108             void *msg_param,
109             void *user_param);
110
111     static int camcorderVideoCaptureCallback(MMCamcorderCaptureDataType *src,
112             MMCamcorderCaptureDataType *thumb,
113             void *data);
114
115     CameraState getState() const
116     {
117         return m_state;
118     }
119
120     void setState(CameraState newState)
121     {
122         m_state = newState;
123     }
124
125     static int lockCameraMutex(Camera *camera);
126
127     static void unlockCameraMutex(Camera *camera);
128
129     /* logs current camcorder state*/
130     void logCamcorderState();
131
132     Resolution getCaptureResolution(bool low) const;
133
134     Api::Camera::EventTakePictureSharedPtr m_eventTakePicture;
135     Api::Camera::EventBeginRecordingSharedPtr m_eventBeginRecording;
136     Api::Camera::EventEndRecordingSharedPtr m_eventEndRecording;
137     Api::Camera::EventRequestLiveVideoSharedPtr m_eventRequestLiveVideo;
138
139   public:
140     Camera();
141     void init(MMCamPreset preset);
142     virtual ~Camera();
143
144     virtual void OnRequestReceived(
145             const Api::Camera::EventTakePictureSharedPtr &event);
146     virtual void OnRequestReceived(
147             const Api::Camera::EventBeginRecordingSharedPtr &event);
148     virtual void OnRequestReceived(
149             const Api::Camera::EventEndRecordingSharedPtr &event);
150     virtual void OnRequestReceived(
151             const Api::Camera::EventRequestLiveVideoSharedPtr &event);
152     virtual void OnEventReceived(const JobDoneEvent &event);
153
154     virtual std::string getDescription() const;
155 };
156 //=============================================================================
157 }
158 }
159 }
160 #endif /* WRTPLUGINSCAMERA_H_ */