1 /*
2  * Copyright (C) 2012 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_SERVERS_CAMERA_BURST_CAPTURE_H
18 #define ANDROID_SERVERS_CAMERA_BURST_CAPTURE_H
19 
20 #include <camera/CameraMetadata.h>
21 #include <binder/MemoryBase.h>
22 #include <binder/MemoryHeapBase.h>
23 #include <gui/CpuConsumer.h>
24 
25 #include "device2/Camera2Device.h"
26 
27 namespace android {
28 
29 class Camera2Client;
30 
31 namespace camera2 {
32 
33 class CaptureSequencer;
34 
35 class BurstCapture : public virtual Thread,
36                      public virtual CpuConsumer::FrameAvailableListener
37 {
38 public:
39     BurstCapture(wp<Camera2Client> client, wp<CaptureSequencer> sequencer);
40     virtual ~BurstCapture();
41 
42     virtual void onFrameAvailable(const BufferItem& item);
43     virtual status_t start(Vector<CameraMetadata> &metadatas, int32_t firstCaptureId);
44 
45 protected:
46     Mutex mInputMutex;
47     bool mInputChanged;
48     Condition mInputSignal;
49     int mCaptureStreamId;
50     wp<Camera2Client> mClient;
51     wp<CaptureSequencer> mSequencer;
52 
53     // Should only be accessed by processing thread
54     enum {
55         NO_STREAM = -1
56     };
57 
58     CpuConsumer::LockedBuffer* jpegEncode(
59         CpuConsumer::LockedBuffer *imgBuffer,
60         int quality);
61 
62     virtual status_t processFrameAvailable(sp<Camera2Client> &client);
63 
64 private:
65     virtual bool threadLoop();
66     static const nsecs_t kWaitDuration = 10000000; // 10 ms
67 };
68 
69 } // namespace camera2
70 } // namespace android
71 
72 #endif
73