1 /*
2  * Copyright (C) 2008 The Android Open Source Project
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 #ifndef ANDROID_HARDWARE_ICAMERA_H
18 #define ANDROID_HARDWARE_ICAMERA_H
19 
20 #include <utils/RefBase.h>
21 #include <binder/IInterface.h>
22 #include <binder/Parcel.h>
23 #include <binder/IMemory.h>
24 #include <binder/Status.h>
25 #include <utils/String8.h>
26 
27 namespace android {
28 
29 class IGraphicBufferProducer;
30 class Surface;
31 
32 namespace hardware {
33 
34 class ICameraClient;
35 
36 class ICamera: public IInterface
37 {
38     /**
39      * Keep up-to-date with ICamera.aidl in frameworks/base
40      */
41 public:
42     enum {
43         // Pass real YUV data in video buffers through ICameraClient.dataCallbackTimestamp().
44         VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV = 0,
45         // Pass metadata in video buffers through ICameraClient.dataCallbackTimestamp().
46         VIDEO_BUFFER_MODE_DATA_CALLBACK_METADATA = 1,
47         // Pass video buffers through IGraphicBufferProducer set with setVideoTarget().
48         VIDEO_BUFFER_MODE_BUFFER_QUEUE = 2,
49     };
50 
51     DECLARE_META_INTERFACE(Camera);
52 
53     virtual binder::Status  disconnect() = 0;
54 
55     // connect new client with existing camera remote
56     virtual status_t        connect(const sp<ICameraClient>& client) = 0;
57 
58     // prevent other processes from using this ICamera interface
59     virtual status_t        lock() = 0;
60 
61     // allow other processes to use this ICamera interface
62     virtual status_t        unlock() = 0;
63 
64     // pass the buffered IGraphicBufferProducer to the camera service
65     virtual status_t        setPreviewTarget(
66             const sp<IGraphicBufferProducer>& bufferProducer) = 0;
67 
68     // set the preview callback flag to affect how the received frames from
69     // preview are handled. Enabling preview callback flags disables any active
70     // preview callback surface set by setPreviewCallbackTarget().
71     virtual void            setPreviewCallbackFlag(int flag) = 0;
72     // set a buffer interface to use for client-received preview frames instead
73     // of preview callback buffers. Passing a valid interface here disables any
74     // active preview callbacks set by setPreviewCallbackFlag(). Passing NULL
75     // disables the use of the callback target.
76     virtual status_t        setPreviewCallbackTarget(
77             const sp<IGraphicBufferProducer>& callbackProducer) = 0;
78 
79     // start preview mode, must call setPreviewTarget first
80     virtual status_t        startPreview() = 0;
81 
82     // stop preview mode
83     virtual void            stopPreview() = 0;
84 
85     // get preview state
86     virtual bool            previewEnabled() = 0;
87 
88     // start recording mode
89     virtual status_t        startRecording() = 0;
90 
91     // stop recording mode
92     virtual void            stopRecording() = 0;
93 
94     // get recording state
95     virtual bool            recordingEnabled() = 0;
96 
97     // Release a recording frame that was received via ICameraClient::dataCallbackTimestamp.
98     virtual void            releaseRecordingFrame(const sp<IMemory>& mem) = 0;
99 
100     // Release a recording frame handle that was received via
101     // ICameraClient::recordingFrameHandleCallbackTimestamp.
102     virtual void            releaseRecordingFrameHandle(native_handle_t *handle) = 0;
103 
104     // auto focus
105     virtual status_t        autoFocus() = 0;
106 
107     // cancel auto focus
108     virtual status_t        cancelAutoFocus() = 0;
109 
110     /*
111      * take a picture.
112      * @param msgType the message type an application selectively turn on/off
113      * on a photo-by-photo basis. The supported message types are:
114      * CAMERA_MSG_SHUTTER, CAMERA_MSG_RAW_IMAGE, CAMERA_MSG_COMPRESSED_IMAGE,
115      * and CAMERA_MSG_POSTVIEW_FRAME. Any other message types will be ignored.
116      */
117     virtual status_t        takePicture(int msgType) = 0;
118 
119     // set preview/capture parameters - key/value pairs
120     virtual status_t        setParameters(const String8& params) = 0;
121 
122     // get preview/capture parameters - key/value pairs
123     virtual String8         getParameters() const = 0;
124 
125     // send command to camera driver
126     virtual status_t        sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) = 0;
127 
128 
129     // Tell camera how to pass video buffers. videoBufferMode is one of VIDEO_BUFFER_MODE_*.
130     // Returns OK if the specified video buffer mode is supported. If videoBufferMode is
131     // VIDEO_BUFFER_MODE_BUFFER_QUEUE, setVideoTarget() must be called before starting video
132     // recording.
133     virtual status_t        setVideoBufferMode(int32_t videoBufferMode) = 0;
134 
135     // Set the video buffer producer for camera to use in VIDEO_BUFFER_MODE_BUFFER_QUEUE mode.
136     virtual status_t        setVideoTarget(
137             const sp<IGraphicBufferProducer>& bufferProducer) = 0;
138 };
139 
140 // ----------------------------------------------------------------------------
141 
142 class BnCamera: public BnInterface<ICamera>
143 {
144 public:
145     virtual status_t    onTransact( uint32_t code,
146                                     const Parcel& data,
147                                     Parcel* reply,
148                                     uint32_t flags = 0);
149 };
150 
151 } // namespace hardware
152 } // namespace android
153 
154 #endif
155