Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2011 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_RECORDING_PROXY_H
     18 #define ANDROID_HARDWARE_ICAMERA_RECORDING_PROXY_H
     19 
     20 #include <vector>
     21 #include <binder/IInterface.h>
     22 #include <cutils/native_handle.h>
     23 #include <utils/RefBase.h>
     24 
     25 namespace android {
     26 
     27 class ICameraRecordingProxyListener;
     28 class IMemory;
     29 class Parcel;
     30 
     31 /*
     32  * The purpose of ICameraRecordingProxy and ICameraRecordingProxyListener is to
     33  * allow applications using the camera during recording.
     34  *
     35  * Camera service allows only one client at a time. Since camcorder application
     36  * needs to own the camera to do things like zoom, the media recorder cannot
     37  * access the camera directly during recording. So ICameraRecordingProxy is a
     38  * proxy of ICamera, which allows the media recorder to start/stop the recording
     39  * and release recording frames. ICameraRecordingProxyListener is an interface
     40  * that allows the recorder to receive video frames during recording.
     41  *
     42  * ICameraRecordingProxy
     43  *   startRecording()
     44  *   stopRecording()
     45  *   releaseRecordingFrame()
     46  *
     47  * ICameraRecordingProxyListener
     48  *   dataCallbackTimestamp()
     49 
     50  * The camcorder app opens the camera and starts the preview. The app passes
     51  * ICamera and ICameraRecordingProxy to the media recorder by
     52  * MediaRecorder::setCamera(). The recorder uses ICamera to setup the camera in
     53  * MediaRecorder::start(). After setup, the recorder disconnects from camera
     54  * service. The recorder calls ICameraRecordingProxy::startRecording() and
     55  * passes a ICameraRecordingProxyListener to the app. The app connects back to
     56  * camera service and starts the recording. The app owns the camera and can do
     57  * things like zoom. The media recorder receives the video frames from the
     58  * listener and releases them by ICameraRecordingProxy::releaseRecordingFrame.
     59  * The recorder calls ICameraRecordingProxy::stopRecording() to stop the
     60  * recording.
     61  *
     62  * The call sequences are as follows:
     63  * 1. The app: Camera.unlock().
     64  * 2. The app: MediaRecorder.setCamera().
     65  * 3. Start recording
     66  *    (1) The app: MediaRecorder.start().
     67  *    (2) The recorder: ICamera.unlock() and ICamera.disconnect().
     68  *    (3) The recorder: ICameraRecordingProxy.startRecording().
     69  *    (4) The app: ICamera.reconnect().
     70  *    (5) The app: ICamera.startRecording().
     71  * 4. During recording
     72  *    (1) The recorder: receive frames from ICameraRecordingProxyListener.dataCallbackTimestamp()
     73  *    (2) The recorder: release frames by ICameraRecordingProxy.releaseRecordingFrame().
     74  * 5. Stop recording
     75  *    (1) The app: MediaRecorder.stop()
     76  *    (2) The recorder: ICameraRecordingProxy.stopRecording().
     77  *    (3) The app: ICamera.stopRecording().
     78  */
     79 
     80 class ICameraRecordingProxy: public IInterface
     81 {
     82 public:
     83     DECLARE_META_INTERFACE(CameraRecordingProxy);
     84 
     85     virtual status_t        startRecording(const sp<ICameraRecordingProxyListener>& listener) = 0;
     86     virtual void            stopRecording() = 0;
     87     virtual void            releaseRecordingFrame(const sp<IMemory>& mem) = 0;
     88     virtual void            releaseRecordingFrameHandle(native_handle_t *handle) = 0;
     89     virtual void            releaseRecordingFrameHandleBatch(
     90                                     const std::vector<native_handle_t*>& handles) = 0;
     91 };
     92 
     93 // ----------------------------------------------------------------------------
     94 
     95 class BnCameraRecordingProxy: public BnInterface<ICameraRecordingProxy>
     96 {
     97 public:
     98     virtual status_t    onTransact( uint32_t code,
     99                                     const Parcel& data,
    100                                     Parcel* reply,
    101                                     uint32_t flags = 0);
    102 };
    103 
    104 }; // namespace android
    105 
    106 #endif
    107