summaryrefslogtreecommitdiffstats
path: root/services/camera/libcameraservice/camera2/BurstCapture.cpp
blob: 50208195d17e72b0f140b509ae3c66bb7beeb97c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_NDEBUG 0
#define LOG_TAG "BurstCapture"

#include <utils/Log.h>
#include <utils/Trace.h>

#include "BurstCapture.h"

#include "JpegCompressor.h"
#include "../Camera2Client.h"

namespace android {
namespace camera2 {

BurstCapture::BurstCapture(wp<Camera2Client> client, wp<CaptureSequencer> sequencer):
    mCaptureStreamId(NO_STREAM),
    mClient(client),
    mSequencer(sequencer)
{
}

BurstCapture::~BurstCapture() {
}

status_t BurstCapture::start(Vector<CameraMetadata> &metadatas, int32_t firstCaptureId) {
    ALOGE("Not completely implemented");
    return INVALID_OPERATION;
}

void BurstCapture::onFrameAvailable() {
    ALOGV("%s", __FUNCTION__);
    Mutex::Autolock l(mInputMutex);
    if(!mInputChanged) {
        mInputChanged = true;
        mInputSignal.signal();
    }
}

bool BurstCapture::threadLoop() {
    status_t res;
    {
        Mutex::Autolock l(mInputMutex);
        while(!mInputChanged) {
            res = mInputSignal.waitRelative(mInputMutex, kWaitDuration);
            if(res == TIMED_OUT) return true;
        }
        mInputChanged = false;
    }

    do {
        sp<Camera2Client> client = mClient.promote();
        if(client == 0) return false;
        ALOGV("%s: Calling processFrameAvailable()", __FUNCTION__);
        res = processFrameAvailable(client);
    } while(res == OK);

    return true;
}

CpuConsumer::LockedBuffer* BurstCapture::jpegEncode(
    CpuConsumer::LockedBuffer *imgBuffer,
    int quality)
{
    ALOGV("%s", __FUNCTION__);

    CpuConsumer::LockedBuffer *imgEncoded = new CpuConsumer::LockedBuffer;
    uint8_t *data = new uint8_t[ANDROID_JPEG_MAX_SIZE];
    imgEncoded->data = data;
    imgEncoded->width = imgBuffer->width;
    imgEncoded->height = imgBuffer->height;
    imgEncoded->stride = imgBuffer->stride;

    Vector<CpuConsumer::LockedBuffer*> buffers;
    buffers.push_back(imgBuffer);
    buffers.push_back(imgEncoded);

    sp<JpegCompressor> jpeg = new JpegCompressor();
    status_t res = jpeg->start(buffers, 1);

    bool success = jpeg->waitForDone(10 * 1e9);
    if(success) {
        return buffers[1];
    }
    else {
        ALOGE("%s: JPEG encode timed out", __FUNCTION__);
        return NULL;  // TODO: maybe change function return value to status_t
    }
}

status_t BurstCapture::processFrameAvailable(sp<Camera2Client> &client) {
    ALOGE("Not implemented");
    return INVALID_OPERATION;
}

} // namespace camera2
} // namespace android