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