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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "Camera2-BurstCapture"
19
20 #include <utils/Log.h>
21 #include <utils/Trace.h>
22
23 #include "BurstCapture.h"
24
25 #include "../Camera2Client.h"
26 #include "JpegCompressor.h"
27
28 namespace android {
29 namespace camera2 {
30
BurstCapture(wp<Camera2Client> client,wp<CaptureSequencer> sequencer)31 BurstCapture::BurstCapture(wp<Camera2Client> client, wp<CaptureSequencer> sequencer):
32 mCaptureStreamId(NO_STREAM),
33 mClient(client),
34 mSequencer(sequencer)
35 {
36 }
37
~BurstCapture()38 BurstCapture::~BurstCapture() {
39 }
40
start(Vector<CameraMetadata> & metadatas,int32_t firstCaptureId)41 status_t BurstCapture::start(Vector<CameraMetadata> &metadatas, int32_t firstCaptureId) {
42 ALOGE("Not completely implemented");
43 return INVALID_OPERATION;
44 }
45
onFrameAvailable()46 void BurstCapture::onFrameAvailable() {
47 ALOGV("%s", __FUNCTION__);
48 Mutex::Autolock l(mInputMutex);
49 if(!mInputChanged) {
50 mInputChanged = true;
51 mInputSignal.signal();
52 }
53 }
54
threadLoop()55 bool BurstCapture::threadLoop() {
56 status_t res;
57 {
58 Mutex::Autolock l(mInputMutex);
59 while(!mInputChanged) {
60 res = mInputSignal.waitRelative(mInputMutex, kWaitDuration);
61 if(res == TIMED_OUT) return true;
62 }
63 mInputChanged = false;
64 }
65
66 do {
67 sp<Camera2Client> client = mClient.promote();
68 if(client == 0) return false;
69 ALOGV("%s: Calling processFrameAvailable()", __FUNCTION__);
70 res = processFrameAvailable(client);
71 } while(res == OK);
72
73 return true;
74 }
75
jpegEncode(CpuConsumer::LockedBuffer * imgBuffer,int quality)76 CpuConsumer::LockedBuffer* BurstCapture::jpegEncode(
77 CpuConsumer::LockedBuffer *imgBuffer,
78 int quality)
79 {
80 ALOGV("%s", __FUNCTION__);
81
82 CpuConsumer::LockedBuffer *imgEncoded = new CpuConsumer::LockedBuffer;
83 uint8_t *data = new uint8_t[ANDROID_JPEG_MAX_SIZE];
84 imgEncoded->data = data;
85 imgEncoded->width = imgBuffer->width;
86 imgEncoded->height = imgBuffer->height;
87 imgEncoded->stride = imgBuffer->stride;
88
89 Vector<CpuConsumer::LockedBuffer*> buffers;
90 buffers.push_back(imgBuffer);
91 buffers.push_back(imgEncoded);
92
93 sp<JpegCompressor> jpeg = new JpegCompressor();
94 status_t res = jpeg->start(buffers, 1);
95
96 bool success = jpeg->waitForDone(10 * 1e9);
97 if(success) {
98 return buffers[1];
99 }
100 else {
101 ALOGE("%s: JPEG encode timed out", __FUNCTION__);
102 return NULL; // TODO: maybe change function return value to status_t
103 }
104 }
105
processFrameAvailable(sp<Camera2Client> & client)106 status_t BurstCapture::processFrameAvailable(sp<Camera2Client> &client) {
107 ALOGE("Not implemented");
108 return INVALID_OPERATION;
109 }
110
111 } // namespace camera2
112 } // namespace android
113