161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala/*
261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala * Copyright (C) 2012 The Android Open Source Project
361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala *
461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala * Licensed under the Apache License, Version 2.0 (the "License");
561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala * you may not use this file except in compliance with the License.
661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala * You may obtain a copy of the License at
761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala *
861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala *      http://www.apache.org/licenses/LICENSE-2.0
961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala *
1061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala * Unless required by applicable law or agreed to in writing, software
1161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala * distributed under the License is distributed on an "AS IS" BASIS,
1261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala * See the License for the specific language governing permissions and
1461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala * limitations under the License.
1561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala */
1661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
17cc27e117ed01c9a2b4def5a9c7a3103af83ee47eZhijun He#define LOG_TAG "Camera2Client"
18a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala#define ATRACE_TAG ATRACE_TAG_CAMERA
1961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala//#define LOG_NDEBUG 0
20a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala
21377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT#include <inttypes.h>
22f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala#include <utils/Log.h>
23a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala#include <utils/Trace.h>
2461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
2561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala#include <cutils/properties.h>
2661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala#include <gui/Surface.h>
27d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
2861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
297b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "api1/Camera2Client.h"
307b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala
317b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "api1/client2/StreamingProcessor.h"
327b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "api1/client2/JpegProcessor.h"
337b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "api1/client2/CaptureSequencer.h"
347b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "api1/client2/CallbackProcessor.h"
357b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "api1/client2/ZslProcessor.h"
36ae500e53efa1d26eb7c13e62d0ecc8d75db2473aIgor Murashkin
3761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala#define ALOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__);
3861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala#define ALOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__);
3961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
402e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvalanamespace android {
412e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvalausing namespace camera2;
422e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala
4361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatic int getCallingPid() {
4461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala    return IPCThreadState::self()->getCallingPid();
4561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
4661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
4761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala// Interface used by CameraService
4861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
4961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville TalvalaCamera2Client::Camera2Client(const sp<CameraService>& cameraService,
50d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala        const sp<hardware::ICameraClient>& cameraClient,
51ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala        const String16& clientPackageName,
5261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala        int cameraId,
5361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala        int cameraFacing,
54ecf17e82505fdb60d59e00b6dd59036df93de655Igor Murashkin        int clientPid,
55ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala        uid_t clientUid,
56a858ea0495c887621a2fd9c0afc13780deccb597Igor Murashkin        int servicePid,
57a858ea0495c887621a2fd9c0afc13780deccb597Igor Murashkin        bool legacyMode):
5844cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin        Camera2ClientBase(cameraService, cameraClient, clientPackageName,
592f09bac6632a5ee27ee14baa2aa1367f16b5b013Eino-Ville Talvala                String8::format("%d", cameraId), cameraFacing,
602f09bac6632a5ee27ee14baa2aa1367f16b5b013Eino-Ville Talvala                clientPid, clientUid, servicePid),
61cd8fce8fbe0f515e53a0ea0f50b739cf42ee57a4Yin-Chia Yeh        mParameters(cameraId, cameraFacing)
62f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala{
63a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
64228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
652e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
662e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    l.mParameters.state = Parameters::DISCONNECTED;
67a858ea0495c887621a2fd9c0afc13780deccb597Igor Murashkin
68a858ea0495c887621a2fd9c0afc13780deccb597Igor Murashkin    mLegacyMode = legacyMode;
69f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala}
70f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
71dce65c8103a8e8c3267590e90c5141d6bf842872Yin-Chia Yehstatus_t Camera2Client::initialize(sp<CameraProviderManager> manager) {
72dce65c8103a8e8c3267590e90c5141d6bf842872Yin-Chia Yeh    return initializeImpl(manager);
73dce65c8103a8e8c3267590e90c5141d6bf842872Yin-Chia Yeh}
74dce65c8103a8e8c3267590e90c5141d6bf842872Yin-Chia Yeh
75dce65c8103a8e8c3267590e90c5141d6bf842872Yin-Chia Yehtemplate<typename TProviderPtr>
76dce65c8103a8e8c3267590e90c5141d6bf842872Yin-Chia Yehstatus_t Camera2Client::initializeImpl(TProviderPtr providerPtr)
77f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala{
78a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
79c8474b68e435cd840ba66791fb09e3da59f1d93cEino-Ville Talvala    ALOGV("%s: Initializing client for camera %d", __FUNCTION__, mCameraId);
80f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    status_t res;
81f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
82dce65c8103a8e8c3267590e90c5141d6bf842872Yin-Chia Yeh    res = Camera2ClientBase::initialize(providerPtr);
83ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala    if (res != OK) {
84ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala        return res;
85ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala    }
86ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala
87fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala    {
88fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala        SharedParameters::Lock l(mParameters);
89fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala
90cd8fce8fbe0f515e53a0ea0f50b739cf42ee57a4Yin-Chia Yeh        res = l.mParameters.initialize(&(mDevice->info()), mDeviceVersion);
91fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala        if (res != OK) {
92fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala            ALOGE("%s: Camera %d: unable to build defaults: %s (%d)",
93fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala                    __FUNCTION__, mCameraId, strerror(-res), res);
94fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala            return NO_INIT;
95fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala        }
96f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    }
973cca136b73b0f4d058019230eb2070cc23e2bbb0Eino-Ville Talvala
98da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    String8 threadName;
99da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala
10073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    mStreamingProcessor = new StreamingProcessor(this);
101254446a80cb13d5beb606bfc3e60a17473869478Eino-Ville Talvala    threadName = String8::format("C2-%d-StreamProc",
102254446a80cb13d5beb606bfc3e60a17473869478Eino-Ville Talvala            mCameraId);
10373bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala
104ce124da179775a81ad7dcc3f33315eca451e66f2Igor Murashkin    mFrameProcessor = new FrameProcessor(mDevice, this);
1054bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-FrameProc",
106da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            mCameraId);
107da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mFrameProcessor->run(threadName.string());
108da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala
109da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mCaptureSequencer = new CaptureSequencer(this);
1104bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-CaptureSeq",
111da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            mCameraId);
112da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mCaptureSequencer->run(threadName.string());
113da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala
114da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mJpegProcessor = new JpegProcessor(this, mCaptureSequencer);
1154bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-JpegProc",
116ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala            mCameraId);
117da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mJpegProcessor->run(threadName.string());
118ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala
119d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    mZslProcessor = new ZslProcessor(this, mCaptureSequencer);
120d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala
1214bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-ZslProc",
122da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            mCameraId);
123d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    mZslProcessor->run(threadName.string());
124ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala
125d86a6880fe86bda21a9b53b240996fc410a512a5Eino-Ville Talvala    mCallbackProcessor = new CallbackProcessor(this);
1264bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-CallbkProc",
127da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            mCameraId);
128da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mCallbackProcessor->run(threadName.string());
129d86a6880fe86bda21a9b53b240996fc410a512a5Eino-Ville Talvala
130f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    if (gLogLevel >= 1) {
131fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala        SharedParameters::Lock l(mParameters);
132f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala        ALOGD("%s: Default parameters converted from camera %d:", __FUNCTION__,
133f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala              mCameraId);
1342e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        ALOGD("%s", l.mParameters.paramsFlattened.string());
135f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    }
136f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
137f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    return OK;
13861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
13961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
14061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville TalvalaCamera2Client::~Camera2Client() {
141a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
142d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala    ALOGV("~Camera2Client");
1434ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala
144f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    mDestructionStarted = true;
145f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
146c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala    disconnect();
147c8474b68e435cd840ba66791fb09e3da59f1d93cEino-Ville Talvala
148da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    ALOGI("Camera %d: Closed", mCameraId);
14961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
15061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
15161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::dump(int fd, const Vector<String16>& args) {
152c4003965258404a19b99280ac0f475e2f290bf27Eino-Ville Talvala    return BasicClient::dump(fd, args);
153c4003965258404a19b99280ac0f475e2f290bf27Eino-Ville Talvala}
154c4003965258404a19b99280ac0f475e2f290bf27Eino-Ville Talvala
155c4003965258404a19b99280ac0f475e2f290bf27Eino-Ville Talvalastatus_t Camera2Client::dumpClient(int fd, const Vector<String16>& args) {
156611f61998863d3a3ffae4e5f2b723b7319c59ddfEino-Ville Talvala    String8 result;
157cc776718c0be7c31fe5ab4fc1446d377be60369fRuben Brunk    result.appendFormat("Client2[%d] (%p) PID: %d, dump:\n", mCameraId,
158e992e75053e98e3699af6e344c11b787e30411adEino-Ville Talvala            (getRemoteCallback() != NULL ?
159f888020c6e2735624f2b2a30e72aca24e17b8b4dMarco Nelissen                    (IInterface::asBinder(getRemoteCallback()).get()) : NULL),
160611f61998863d3a3ffae4e5f2b723b7319c59ddfEino-Ville Talvala            mClientPid);
1617f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("  State: ");
1627f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala#define CASE_APPEND_ENUM(x) case x: result.append(#x "\n"); break;
1637f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
1642e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    const Parameters& p = mParameters.unsafeAccess();
165836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala
1662e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    result.append(Parameters::getStateName(p.state));
1677f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
1684ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala    result.append("\n  Current parameters:\n");
1697f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Preview size: %d x %d\n",
170836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.previewWidth, p.previewHeight);
1717f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Preview FPS range: %d - %d\n",
172836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.previewFpsRange[0], p.previewFpsRange[1]);
1737f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Preview HAL pixel format: 0x%x\n",
174836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.previewFormat);
17511b7cdef9726f8270f12f6c393600e8fb3c469deEino-Ville Talvala    result.appendFormat("    Preview transform: %x\n",
176836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.previewTransform);
1777f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Picture size: %d x %d\n",
178836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.pictureWidth, p.pictureHeight);
1797f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Jpeg thumbnail size: %d x %d\n",
180836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.jpegThumbSize[0], p.jpegThumbSize[1]);
1817f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Jpeg quality: %d, thumbnail quality: %d\n",
182836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.jpegQuality, p.jpegThumbQuality);
183836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    result.appendFormat("    Jpeg rotation: %d\n", p.jpegRotation);
1847f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    GPS tags %s\n",
185836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.gpsEnabled ? "enabled" : "disabled");
186836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    if (p.gpsEnabled) {
1877f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        result.appendFormat("    GPS lat x long x alt: %f x %f x %f\n",
188836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.gpsCoordinates[0], p.gpsCoordinates[1],
189836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.gpsCoordinates[2]);
190377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT        result.appendFormat("    GPS timestamp: %" PRId64 "\n",
191836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.gpsTimestamp);
1927f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        result.appendFormat("    GPS processing method: %s\n",
193836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.gpsProcessingMethod.string());
1947f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
1957f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
1967f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    White balance mode: ");
197836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.wbMode) {
198d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_AUTO)
199d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_INCANDESCENT)
200d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_FLUORESCENT)
201d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_WARM_FLUORESCENT)
202d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_DAYLIGHT)
203d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_CLOUDY_DAYLIGHT)
204d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_TWILIGHT)
205d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_MODE_SHADE)
2067f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2077f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2087f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2097f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Effect mode: ");
210836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.effectMode) {
211d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_OFF)
212d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_MONO)
213d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_NEGATIVE)
214d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_SOLARIZE)
215d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_SEPIA)
216d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_POSTERIZE)
217d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_WHITEBOARD)
218d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_BLACKBOARD)
219d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MODE_AQUA)
2207f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2217f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2227f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2237f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Antibanding mode: ");
224836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.antibandingMode) {
225d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO)
226d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF)
227d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_50HZ)
228d32b99b1a87497280add6efc0e99bd383e402de1Igor Murashkin        CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_MODE_60HZ)
2297f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2307f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2317f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2327f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Scene mode: ");
233836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.sceneMode) {
234c69b91ceae6255e41c5413796fb0ed4f7af45b15Ruben Brunk        case ANDROID_CONTROL_SCENE_MODE_DISABLED:
2357f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala            result.append("AUTO\n"); break;
2367f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_ACTION)
2377f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PORTRAIT)
2387f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_LANDSCAPE)
2397f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT)
2407f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT_PORTRAIT)
2417f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_THEATRE)
2427f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BEACH)
2437f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SNOW)
2447f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SUNSET)
2457f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_STEADYPHOTO)
2467f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_FIREWORKS)
2477f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SPORTS)
2487f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PARTY)
2497f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_CANDLELIGHT)
2507f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BARCODE)
2517f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2527f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2537f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2547f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Flash mode: ");
255836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.flashMode) {
2567f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_OFF)
2577f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_AUTO)
2587f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_ON)
2597f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_TORCH)
2607f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_RED_EYE)
2617f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_INVALID)
2627f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2637f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2647f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2657f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Focus mode: ");
266836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.focusMode) {
2677f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_AUTO)
2687f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_MACRO)
2697f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_VIDEO)
2707f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_PICTURE)
2717f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_EDOF)
2727f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INFINITY)
2737f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_FIXED)
2747f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INVALID)
2757f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2767f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2777f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
278d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala    result.append("   Focus state: ");
279d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala    switch (p.focusState) {
280d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_INACTIVE)
281d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN)
282d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED)
2834ad28ea0a76c7ecdfcc5b96af2b0afcb0c3e5120Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_UNFOCUSED)
284d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN)
285d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED)
286d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED)
287d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        default: result.append("UNKNOWN\n");
288d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala    }
289d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala
2907f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Focusing areas:\n");
291836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    for (size_t i = 0; i < p.focusingAreas.size(); i++) {
2927f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        result.appendFormat("      [ (%d, %d, %d, %d), weight %d ]\n",
293836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].left,
294836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].top,
295836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].right,
296836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].bottom,
297836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].weight);
2987f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2997f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3007f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Exposure compensation index: %d\n",
301836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.exposureCompensation);
3027f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3037f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    AE lock %s, AWB lock %s\n",
304836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.autoExposureLock ? "enabled" : "disabled",
305836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.autoWhiteBalanceLock ? "enabled" : "disabled" );
3067f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3077f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Metering areas:\n");
308836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    for (size_t i = 0; i < p.meteringAreas.size(); i++) {
3097f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        result.appendFormat("      [ (%d, %d, %d, %d), weight %d ]\n",
310836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].left,
311836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].top,
312836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].right,
313836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].bottom,
314836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].weight);
3157f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
3167f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
317836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    result.appendFormat("    Zoom index: %d\n", p.zoom);
318836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    result.appendFormat("    Video size: %d x %d\n", p.videoWidth,
319836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.videoHeight);
3207f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3213297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    result.appendFormat("    Recording hint is %s\n",
322836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.recordingHint ? "set" : "not set");
3237f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3243297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    result.appendFormat("    Video stabilization is %s\n",
325836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.videoStabilization ? "enabled" : "disabled");
3267f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3270181fde7bd20238cb13ae2665f0e5bfe7c2d9ac8Eino-Ville Talvala    result.appendFormat("    Selected still capture FPS range: %d - %d\n",
3280181fde7bd20238cb13ae2665f0e5bfe7c2d9ac8Eino-Ville Talvala            p.fastInfo.bestStillCaptureFpsRange[0],
3290181fde7bd20238cb13ae2665f0e5bfe7c2d9ac8Eino-Ville Talvala            p.fastInfo.bestStillCaptureFpsRange[1]);
3300181fde7bd20238cb13ae2665f0e5bfe7c2d9ac8Eino-Ville Talvala
331c451d0f8098c9efd21d796e32f739af1915f9abaEino-Ville Talvala    result.appendFormat("    Use zero shutter lag: %s\n",
332c451d0f8098c9efd21d796e32f739af1915f9abaEino-Ville Talvala            p.useZeroShutterLag() ? "yes" : "no");
333c451d0f8098c9efd21d796e32f739af1915f9abaEino-Ville Talvala
3343297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    result.append("  Current streams:\n");
335da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    result.appendFormat("    Preview stream ID: %d\n",
336da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            getPreviewStreamId());
337ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala    result.appendFormat("    Capture stream ID: %d\n",
338da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            getCaptureStreamId());
339da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    result.appendFormat("    Recording stream ID: %d\n",
340da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            getRecordingStreamId());
341e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala
342e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    result.append("  Quirks for this camera:\n");
343e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    bool haveQuirk = false;
344e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    if (p.quirks.triggerAfWithAuto) {
345e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        result.appendFormat("    triggerAfWithAuto\n");
346e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        haveQuirk = true;
347e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    }
348e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    if (p.quirks.useZslFormat) {
349e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        result.appendFormat("    useZslFormat\n");
350e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        haveQuirk = true;
351e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    }
3527373cbe85e617345f7002256a4be389fe62af913Igor Murashkin    if (p.quirks.meteringCropRegion) {
3537373cbe85e617345f7002256a4be389fe62af913Igor Murashkin        result.appendFormat("    meteringCropRegion\n");
3547373cbe85e617345f7002256a4be389fe62af913Igor Murashkin        haveQuirk = true;
3557373cbe85e617345f7002256a4be389fe62af913Igor Murashkin    }
356fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala    if (p.quirks.partialResults) {
357fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala        result.appendFormat("    usePartialResult\n");
358fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala        haveQuirk = true;
359fd6ecdd39bd83ea020f78b425e96310380d66c35Eino-Ville Talvala    }
360e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    if (!haveQuirk) {
361e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        result.appendFormat("    none\n");
362e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    }
363e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala
36473bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    write(fd, result.string(), result.size());
3653297daae9681004775012faba9181d65e097e00cEino-Ville Talvala
36673bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    mStreamingProcessor->dump(fd, args);
367428b77a2b94b74665a47375b3fdb893b98d71269Eino-Ville Talvala
368da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mCaptureSequencer->dump(fd, args);
369da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala
370c8474b68e435cd840ba66791fb09e3da59f1d93cEino-Ville Talvala    mFrameProcessor->dump(fd, args);
371c8474b68e435cd840ba66791fb09e3da59f1d93cEino-Ville Talvala
37297b38a81ac989ccba02d726011a82541f14166dfEino-Ville Talvala    mZslProcessor->dump(fd, args);
37397b38a81ac989ccba02d726011a82541f14166dfEino-Ville Talvala
37444cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    return dumpDevice(fd, args);
3757f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala#undef CASE_APPEND_ENUM
37661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
37761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
37861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala// ICamera interface
37961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
380d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvalabinder::Status Camera2Client::disconnect() {
381a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
38244cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
383c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala
384d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala    binder::Status res = binder::Status::ok();
38598a668f6ea51e4d894d2ebb61a0e18287fb14008Chien-Yu Chen    // Allow both client and the cameraserver to disconnect at all times
386c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala    int callingPid = getCallingPid();
387d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala    if (callingPid != mClientPid && callingPid != mServicePid) return res;
388ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
389d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala    if (mDevice == 0) return res;
390f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
39198bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    ALOGV("Camera %d: Shutting down", mCameraId);
39298bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
393d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala    /**
394d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala     * disconnect() cannot call any methods that might need to promote a
395d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala     * wp<Camera2Client>, since disconnect can be called from the destructor, at
396d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala     * which point all such promotions will fail.
397d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala     */
398d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala
399d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala    stopPreviewL();
4006db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
40198bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    {
40298bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala        SharedParameters::Lock l(mParameters);
403d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala        if (l.mParameters.state == Parameters::DISCONNECTED) return res;
40498bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala        l.mParameters.state = Parameters::DISCONNECTED;
40598bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    }
40698bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
40798bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mFrameProcessor->requestExit();
40898bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mCaptureSequencer->requestExit();
40998bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mJpegProcessor->requestExit();
410d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    mZslProcessor->requestExit();
41198bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mCallbackProcessor->requestExit();
41298bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
41398bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    ALOGV("Camera %d: Waiting for threads", mCameraId);
41498bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
415661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala    {
416661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala        // Don't wait with lock held, in case the other threads need to
417661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala        // complete callbacks that re-enter Camera2Client
418661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala        mBinderSerializationLock.unlock();
419661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala
420661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala        mFrameProcessor->join();
421661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala        mCaptureSequencer->join();
422661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala        mJpegProcessor->join();
423d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        mZslProcessor->join();
424661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala        mCallbackProcessor->join();
425661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala
426661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala        mBinderSerializationLock.lock();
427661c21da5592ca48256747ec220efb2e599eeb72Eino-Ville Talvala    }
42898bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
429dfe715582943b3fc9bab91f88257a3bba6c6deefRuben Brunk    ALOGV("Camera %d: Deleting streams", mCameraId);
430dfe715582943b3fc9bab91f88257a3bba6c6deefRuben Brunk
431dfe715582943b3fc9bab91f88257a3bba6c6deefRuben Brunk    mStreamingProcessor->deletePreviewStream();
432dfe715582943b3fc9bab91f88257a3bba6c6deefRuben Brunk    mStreamingProcessor->deleteRecordingStream();
433dfe715582943b3fc9bab91f88257a3bba6c6deefRuben Brunk    mJpegProcessor->deleteStream();
434dfe715582943b3fc9bab91f88257a3bba6c6deefRuben Brunk    mCallbackProcessor->deleteStream();
435dfe715582943b3fc9bab91f88257a3bba6c6deefRuben Brunk    mZslProcessor->deleteStream();
436dfe715582943b3fc9bab91f88257a3bba6c6deefRuben Brunk
43798bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    ALOGV("Camera %d: Disconnecting device", mCameraId);
43898bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
43998bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mDevice->disconnect();
44098bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
4413a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    mDevice.clear();
4428ce89d9e2b132bf58a030acec88acf0a998926a1Eino-Ville Talvala
44361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala    CameraService::Client::disconnect();
444d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala
445d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala    return res;
44661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
44761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
448d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvalastatus_t Camera2Client::connect(const sp<hardware::ICameraClient>& client) {
449a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
4509e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
45144cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
452ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
4539cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (mClientPid != 0 && getCallingPid() != mClientPid) {
4549cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        ALOGE("%s: Camera %d: Connection attempt from pid %d; "
4559cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala                "current locked to pid %d", __FUNCTION__,
4569cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala                mCameraId, getCallingPid(), mClientPid);
4579cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        return BAD_VALUE;
4589cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
4599cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
4609cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    mClientPid = getCallingPid();
4618ce89d9e2b132bf58a030acec88acf0a998926a1Eino-Ville Talvala
46244cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    mRemoteCallback = client;
46344cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    mSharedCameraCallbacks = client;
4649cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
4659cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    return OK;
46661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
46761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
46861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::lock() {
469a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
4709e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
47144cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
4729cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    ALOGV("%s: Camera %d: Lock call from pid %d; current client pid %d",
4739cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            __FUNCTION__, mCameraId, getCallingPid(), mClientPid);
474ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
4759cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (mClientPid == 0) {
4769cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        mClientPid = getCallingPid();
4779cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        return OK;
4789cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
4799cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
4809cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (mClientPid != getCallingPid()) {
4819cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        ALOGE("%s: Camera %d: Lock call from pid %d; currently locked to pid %d",
4829cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala                __FUNCTION__, mCameraId, getCallingPid(), mClientPid);
4839cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        return EBUSY;
4849cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
4859cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
4869cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    return OK;
48761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
48861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
48961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::unlock() {
490a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
4919e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
49244cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
4939cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    ALOGV("%s: Camera %d: Unlock call from pid %d; current client pid %d",
4949cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            __FUNCTION__, mCameraId, getCallingPid(), mClientPid);
495ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
4969cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (mClientPid == getCallingPid()) {
497907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala        SharedParameters::Lock l(mParameters);
498907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala        if (l.mParameters.state == Parameters::RECORD ||
499907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala                l.mParameters.state == Parameters::VIDEO_SNAPSHOT) {
500907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala            ALOGD("Not allowed to unlock camera during recording.");
501907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala            return INVALID_OPERATION;
502907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala        }
5039cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        mClientPid = 0;
50444cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin        mRemoteCallback.clear();
50544cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin        mSharedCameraCallbacks.clear();
5069cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        return OK;
5079cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
5089cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
5099cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    ALOGE("%s: Camera %d: Unlock call from pid %d; currently locked to pid %d",
5109cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            __FUNCTION__, mCameraId, getCallingPid(), mClientPid);
5119cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    return EBUSY;
51261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
51361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
5141ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvalastatus_t Camera2Client::setPreviewTarget(
5158ba01021b573889802e67e029225a96f0dfa471aAndy McFadden        const sp<IGraphicBufferProducer>& bufferProducer) {
516a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
5179e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
51844cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
5193a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
5203a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
521ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
5226db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    sp<IBinder> binder;
523727d172137b4f32681c098de8e2623c0b65a6406Eino-Ville Talvala    sp<Surface> window;
5248ba01021b573889802e67e029225a96f0dfa471aAndy McFadden    if (bufferProducer != 0) {
525f888020c6e2735624f2b2a30e72aca24e17b8b4dMarco Nelissen        binder = IInterface::asBinder(bufferProducer);
5261ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala        // Using controlledByApp flag to ensure that the buffer queue remains in
5271ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala        // async mode for the old camera API, where many applications depend
5281ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala        // on that behavior.
5291ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala        window = new Surface(bufferProducer, /*controlledByApp*/ true);
5306db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
53136cdfb185877a7f573621d19ed2b2e1cac13d62eEino-Ville Talvala    return setPreviewWindowL(binder, window);
5326db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala}
5336db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
53436cdfb185877a7f573621d19ed2b2e1cac13d62eEino-Ville Talvalastatus_t Camera2Client::setPreviewWindowL(const sp<IBinder>& binder,
5358b0b971b1416738f22488a80be726d1ec12552a8Chih-Hung Hsieh        const sp<Surface>& window) {
536a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
5376db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    status_t res;
5386db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
5396db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    if (binder == mPreviewSurface) {
5409e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala        ALOGV("%s: Camera %d: New window is same as old window",
5419e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala                __FUNCTION__, mCameraId);
5426db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        return NO_ERROR;
5436db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
5446db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
545f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    Parameters::State state;
546f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    {
547f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala        SharedParameters::Lock l(mParameters);
548f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala        state = l.mParameters.state;
549f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    }
550f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    switch (state) {
5512e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::DISCONNECTED:
5522e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::RECORD:
5532e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STILL_CAPTURE:
5542e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::VIDEO_SNAPSHOT:
5559cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            ALOGE("%s: Camera %d: Cannot set preview display while in state %s",
5562e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    __FUNCTION__, mCameraId,
557f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala                    Parameters::getStateName(state));
5589cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            return INVALID_OPERATION;
5592e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STOPPED:
5602e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::WAITING_FOR_PREVIEW_WINDOW:
5619cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            // OK
5629cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            break;
5632e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::PREVIEW:
5649cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            // Already running preview - need to stop and create a new stream
565d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala            res = stopStream();
566d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala            if (res != OK) {
567d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala                ALOGE("%s: Unable to stop preview to swap windows: %s (%d)",
568d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala                        __FUNCTION__, strerror(-res), res);
569d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala                return res;
570d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala            }
571f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala            state = Parameters::WAITING_FOR_PREVIEW_WINDOW;
5729cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            break;
5739cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
5749cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
575bd47b7bcfe7f5a97fef81143f4282c41590626feEino-Ville Talvala    mPreviewSurface = binder;
57673bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    res = mStreamingProcessor->setPreviewWindow(window);
57773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    if (res != OK) {
57873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        ALOGE("%s: Unable to set new preview window: %s (%d)",
57973bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                __FUNCTION__, strerror(-res), res);
58073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        return res;
58173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    }
582bd47b7bcfe7f5a97fef81143f4282c41590626feEino-Ville Talvala
583f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    if (state == Parameters::WAITING_FOR_PREVIEW_WINDOW) {
584f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala        SharedParameters::Lock l(mParameters);
585f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala        l.mParameters.state = state;
5862e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        return startPreviewL(l.mParameters, false);
5876db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
5886db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
5896db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    return OK;
59061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
59161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
59261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalavoid Camera2Client::setPreviewCallbackFlag(int flag) {
593a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
594228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    ALOGV("%s: Camera %d: Flag 0x%x", __FUNCTION__, mCameraId, flag);
59544cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
596ddf3c5025e2f6f35a4c188c19f30142c64a092c4Igor Murashkin
597228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    if ( checkPid(__FUNCTION__) != OK) return;
598228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
5992e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
6002e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    setPreviewCallbackFlagL(l.mParameters, flag);
601228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala}
602228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
603228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvalavoid Camera2Client::setPreviewCallbackFlagL(Parameters &params, int flag) {
604228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    status_t res = OK;
605a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala
606a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala    switch(params.state) {
607a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        case Parameters::STOPPED:
608a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        case Parameters::WAITING_FOR_PREVIEW_WINDOW:
609a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        case Parameters::PREVIEW:
610a2520db02bead68d4980783c41500ae96511bdf8Zhijun He        case Parameters::STILL_CAPTURE:
611a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            // OK
612a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            break;
613a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        default:
614a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            if (flag & CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK) {
615a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                ALOGE("%s: Camera %d: Can't use preview callbacks "
616a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                        "in state %d", __FUNCTION__, mCameraId, params.state);
617a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                return;
618a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            }
619a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala    }
620a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala
621228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    if (flag & CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK) {
622228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        ALOGV("%s: setting oneshot", __FUNCTION__);
623228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        params.previewCallbackOneShot = true;
624228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    }
625228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    if (params.previewCallbackFlags != (uint32_t)flag) {
6263ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
627527748abf04c0060894fd7aace54959a2c343435Zhijun He        if (params.previewCallbackSurface && flag != CAMERA_FRAME_CALLBACK_FLAG_NOOP) {
6283ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            // Disable any existing preview callback window when enabling
6293ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            // preview callback flags
6303ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            res = mCallbackProcessor->setCallbackWindow(NULL);
6313ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            if (res != OK) {
6323ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala                ALOGE("%s: Camera %d: Unable to clear preview callback surface:"
6333ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala                        " %s (%d)", __FUNCTION__, mCameraId, strerror(-res), res);
6343ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala                return;
6353ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            }
6363ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            params.previewCallbackSurface = false;
6373ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        }
6383ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
639228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        params.previewCallbackFlags = flag;
6403ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
641a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        if (params.state == Parameters::PREVIEW) {
642228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            res = startPreviewL(params, true);
643a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            if (res != OK) {
644a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                ALOGE("%s: Camera %d: Unable to refresh request in state %s",
645a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                        __FUNCTION__, mCameraId,
646a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                        Parameters::getStateName(params.state));
647a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            }
6483ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        }
6493ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    }
6503ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala}
6513ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
6523ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvalastatus_t Camera2Client::setPreviewCallbackTarget(
6533ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        const sp<IGraphicBufferProducer>& callbackProducer) {
6543ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    ATRACE_CALL();
6553ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
6563ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    Mutex::Autolock icl(mBinderSerializationLock);
6573ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    status_t res;
6583ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
6593ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
660727d172137b4f32681c098de8e2623c0b65a6406Eino-Ville Talvala    sp<Surface> window;
6613ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    if (callbackProducer != 0) {
6623ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        window = new Surface(callbackProducer);
6633ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    }
6643ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
6653ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    res = mCallbackProcessor->setCallbackWindow(window);
6663ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    if (res != OK) {
6673ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        ALOGE("%s: Camera %d: Unable to set preview callback surface: %s (%d)",
6683ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala                __FUNCTION__, mCameraId, strerror(-res), res);
6693ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        return res;
6703ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    }
6713ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
6723ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
6733ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
6743ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    if (window != NULL) {
6753ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        // Disable traditional callbacks when a valid callback target is given
6763ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        l.mParameters.previewCallbackFlags = CAMERA_FRAME_CALLBACK_FLAG_NOOP;
6773ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        l.mParameters.previewCallbackOneShot = false;
6783ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        l.mParameters.previewCallbackSurface = true;
6793ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    } else {
6803ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        // Disable callback target if given a NULL interface.
6813ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        l.mParameters.previewCallbackSurface = false;
6823ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    }
6833ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
6843ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    switch(l.mParameters.state) {
6852e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::PREVIEW:
6863ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            res = startPreviewL(l.mParameters, true);
687228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            break;
6882e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::RECORD:
6892e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::VIDEO_SNAPSHOT:
6903ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            res = startRecordingL(l.mParameters, true);
691228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            break;
692228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        default:
693228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            break;
6943ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    }
6953ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    if (res != OK) {
6963ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        ALOGE("%s: Camera %d: Unable to refresh request in state %s",
6973ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala                __FUNCTION__, mCameraId,
6983ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala                Parameters::getStateName(l.mParameters.state));
699228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    }
700228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
7013ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    return OK;
70261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
70361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
7043ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
70561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::startPreview() {
706a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
7079e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
70844cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
7093a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
7103a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
7112e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
7122e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    return startPreviewL(l.mParameters, false);
713d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala}
714ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
715228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvalastatus_t Camera2Client::startPreviewL(Parameters &params, bool restart) {
716d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala    ATRACE_CALL();
7176db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    status_t res;
71822d58d37db6b5f48a10b3a19f69ffda09943c125Igor Murashkin
71922d58d37db6b5f48a10b3a19f69ffda09943c125Igor Murashkin    ALOGV("%s: state == %d, restart = %d", __FUNCTION__, params.state, restart);
72022d58d37db6b5f48a10b3a19f69ffda09943c125Igor Murashkin
721a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala    if ( (params.state == Parameters::PREVIEW ||
722a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala                    params.state == Parameters::RECORD ||
723a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala                    params.state == Parameters::VIDEO_SNAPSHOT)
724a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala            && !restart) {
725a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala        // Succeed attempt to re-enter a streaming state
726a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala        ALOGI("%s: Camera %d: Preview already active, ignoring restart",
727a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala                __FUNCTION__, mCameraId);
72877449ada4b5ca73a948aa4fef9aafe3079a66d61Alex Ray        return OK;
72977449ada4b5ca73a948aa4fef9aafe3079a66d61Alex Ray    }
73077449ada4b5ca73a948aa4fef9aafe3079a66d61Alex Ray    if (params.state > Parameters::PREVIEW && !restart) {
7314ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala        ALOGE("%s: Can't start preview in state %s",
7322e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                __FUNCTION__,
7332e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                Parameters::getStateName(params.state));
7344ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala        return INVALID_OPERATION;
7354ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala    }
7366db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
73773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    if (!mStreamingProcessor->haveValidPreviewWindow()) {
7382e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        params.state = Parameters::WAITING_FOR_PREVIEW_WINDOW;
7396db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        return OK;
7406db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
7412e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    params.state = Parameters::STOPPED;
742c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He    int lastPreviewStreamId = mStreamingProcessor->getPreviewStreamId();
7439cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
74473bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    res = mStreamingProcessor->updatePreviewStream(params);
745be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala    if (res != OK) {
746be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala        ALOGE("%s: Camera %d: Unable to update preview stream: %s (%d)",
747be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala                __FUNCTION__, mCameraId, strerror(-res), res);
748be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala        return res;
7496db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
75073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala
751c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He    bool previewStreamChanged = mStreamingProcessor->getPreviewStreamId() != lastPreviewStreamId;
752c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He
753a9c64a9398ac2e6173f99e252f305808a34cab1cEino-Ville Talvala    // We could wait to create the JPEG output stream until first actual use
754a9c64a9398ac2e6173f99e252f305808a34cab1cEino-Ville Talvala    // (first takePicture call). However, this would substantially increase the
755d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    // first capture latency on HAL3 devices.
756d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    // So create it unconditionally at preview start. As a drawback,
757a9c64a9398ac2e6173f99e252f305808a34cab1cEino-Ville Talvala    // this increases gralloc memory consumption for applications that don't
758355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh    // ever take a picture. Do not enter this mode when jpeg stream will slow
759355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh    // down preview.
760a9c64a9398ac2e6173f99e252f305808a34cab1cEino-Ville Talvala    // TODO: Find a better compromise, though this likely would involve HAL
761a9c64a9398ac2e6173f99e252f305808a34cab1cEino-Ville Talvala    // changes.
762e2d83756cb088db15fda73616ca097b8d190e1a1Zhijun He    int lastJpegStreamId = mJpegProcessor->getStreamId();
763355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh    // If jpeg stream will slow down preview, make sure we remove it before starting preview
764355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh    if (params.slowJpegMode) {
765355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh        mJpegProcessor->deleteStream();
766355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh    } else {
767355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh        res = updateProcessorStream(mJpegProcessor, params);
768355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh        if (res != OK) {
769355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh            ALOGE("%s: Camera %d: Can't pre-configure still image "
770355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh                    "stream: %s (%d)",
771355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh                    __FUNCTION__, mCameraId, strerror(-res), res);
772355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh            return res;
773355d9c6b74cd22a88fc7d1c9ba2e928ba566c69eYin-Chia Yeh        }
774a9c64a9398ac2e6173f99e252f305808a34cab1cEino-Ville Talvala    }
775e2d83756cb088db15fda73616ca097b8d190e1a1Zhijun He    bool jpegStreamChanged = mJpegProcessor->getStreamId() != lastJpegStreamId;
776a9c64a9398ac2e6173f99e252f305808a34cab1cEino-Ville Talvala
777d1d6467d3bcbc1305eeba0176a2edf04925c368eZhijun He    Vector<int32_t> outputStreams;
7783ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    bool callbacksEnabled = (params.previewCallbackFlags &
7793ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK) ||
7803ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            params.previewCallbackSurface;
7813ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
782228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    if (callbacksEnabled) {
783a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        // Can't have recording stream hanging around when enabling callbacks,
784a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        // since it exceeds the max stream count on some devices.
785a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        if (mStreamingProcessor->getRecordingStreamId() != NO_STREAM) {
786a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            ALOGV("%s: Camera %d: Clearing out recording stream before "
787a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                    "creating callback stream", __FUNCTION__, mCameraId);
788a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            res = mStreamingProcessor->stopStream();
789a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            if (res != OK) {
790a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                ALOGE("%s: Camera %d: Can't stop streaming to delete "
791a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                        "recording stream", __FUNCTION__, mCameraId);
792a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                return res;
793a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            }
794a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            res = mStreamingProcessor->deleteRecordingStream();
795a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            if (res != OK) {
796a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                ALOGE("%s: Camera %d: Unable to delete recording stream before "
797a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                        "enabling callbacks: %s (%d)", __FUNCTION__, mCameraId,
798a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                        strerror(-res), res);
799a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                return res;
800a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            }
801a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        }
802a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala
803d86a6880fe86bda21a9b53b240996fc410a512a5Eino-Ville Talvala        res = mCallbackProcessor->updateStream(params);
804228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        if (res != OK) {
805228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            ALOGE("%s: Camera %d: Unable to update callback stream: %s (%d)",
806228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala                    __FUNCTION__, mCameraId, strerror(-res), res);
807228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            return res;
808228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        }
80973bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        outputStreams.push(getCallbackStreamId());
810c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He    } else if (previewStreamChanged && mCallbackProcessor->getStreamId() != NO_STREAM) {
811c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He        /**
812c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He         * Delete the unused callback stream when preview stream is changed and
813c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He         * preview is not enabled. Don't need stop preview stream as preview is in
814c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He         * STOPPED state now.
815c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He         */
816c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He        ALOGV("%s: Camera %d: Delete unused preview callback stream.",  __FUNCTION__, mCameraId);
817c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He        res = mCallbackProcessor->deleteStream();
818c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He        if (res != OK) {
819c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He            ALOGE("%s: Camera %d: Unable to delete callback stream %s (%d)",
820c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He                    __FUNCTION__, mCameraId, strerror(-res), res);
821c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He            return res;
822c1b7cc4d3eeb55fd03ff77b099b827e7568480e4Zhijun He        }
823228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    }
824ca05ebd4c666322e754ac63236c8b329dbb53b00Yin-Chia Yeh
825c451d0f8098c9efd21d796e32f739af1915f9abaEino-Ville Talvala    if (params.useZeroShutterLag() &&
826ca05ebd4c666322e754ac63236c8b329dbb53b00Yin-Chia Yeh            getRecordingStreamId() == NO_STREAM) {
827dca254aef0c09867e50fe6613c6fad405de72842Igor Murashkin        res = updateProcessorStream(mZslProcessor, params);
828da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala        if (res != OK) {
829da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            ALOGE("%s: Camera %d: Unable to update ZSL stream: %s (%d)",
830da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala                    __FUNCTION__, mCameraId, strerror(-res), res);
831da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            return res;
832da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala        }
833e2d83756cb088db15fda73616ca097b8d190e1a1Zhijun He
834e2d83756cb088db15fda73616ca097b8d190e1a1Zhijun He        if (jpegStreamChanged) {
835e2d83756cb088db15fda73616ca097b8d190e1a1Zhijun He            ALOGV("%s: Camera %d: Clear ZSL buffer queue when Jpeg size is changed",
836e2d83756cb088db15fda73616ca097b8d190e1a1Zhijun He                    __FUNCTION__, mCameraId);
837e2d83756cb088db15fda73616ca097b8d190e1a1Zhijun He            mZslProcessor->clearZslQueue();
838e2d83756cb088db15fda73616ca097b8d190e1a1Zhijun He        }
83973bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        outputStreams.push(getZslStreamId());
840661076292093f82aec488baf8460cdf204a5efd2Zhijun He    } else {
841661076292093f82aec488baf8460cdf204a5efd2Zhijun He        mZslProcessor->deleteStream();
842da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    }
8436db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
84473bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    outputStreams.push(getPreviewStreamId());
84573bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala
8465a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala    if (!params.recordingHint) {
84773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        if (!restart) {
84873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            res = mStreamingProcessor->updatePreviewRequest(params);
8495a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala            if (res != OK) {
85073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                ALOGE("%s: Camera %d: Can't set up preview request: "
85173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                        "%s (%d)", __FUNCTION__, mCameraId,
85273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                        strerror(-res), res);
8535a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala                return res;
8545a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala            }
8555a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala        }
85673bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        res = mStreamingProcessor->startStream(StreamingProcessor::PREVIEW,
85773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                outputStreams);
8585a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala    } else {
85973bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        if (!restart) {
86073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            res = mStreamingProcessor->updateRecordingRequest(params);
86173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            if (res != OK) {
86273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                ALOGE("%s: Camera %d: Can't set up preview request with "
86373bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                        "record hint: %s (%d)", __FUNCTION__, mCameraId,
86473bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                        strerror(-res), res);
86573bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                return res;
86673bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            }
86773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        }
86873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        res = mStreamingProcessor->startStream(StreamingProcessor::RECORD,
86973bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                outputStreams);
870be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala    }
871be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala    if (res != OK) {
87273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        ALOGE("%s: Camera %d: Unable to start streaming preview: %s (%d)",
873be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala                __FUNCTION__, mCameraId, strerror(-res), res);
8746db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        return res;
8756db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
8766db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
8772e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    params.state = Parameters::PREVIEW;
8786db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    return OK;
87961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
88061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
88161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalavoid Camera2Client::stopPreview() {
882a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
8839e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
88444cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
8853a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
8863a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return;
88736cdfb185877a7f573621d19ed2b2e1cac13d62eEino-Ville Talvala    stopPreviewL();
888ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala}
889ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
89036cdfb185877a7f573621d19ed2b2e1cac13d62eEino-Ville Talvalavoid Camera2Client::stopPreviewL() {
891ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    ATRACE_CALL();
8924865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala    status_t res;
893d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala    const nsecs_t kStopCaptureTimeout = 3000000000LL; // 3 seconds
8942e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    Parameters::State state;
895228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    {
8962e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        SharedParameters::Lock l(mParameters);
8972e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        state = l.mParameters.state;
898228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    }
899228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
900228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    switch (state) {
9012e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::DISCONNECTED:
902ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala            // Nothing to do.
903d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala            break;
9042e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STOPPED:
905d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala        case Parameters::VIDEO_SNAPSHOT:
9062e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STILL_CAPTURE:
907d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala            mCaptureSequencer->waitUntilIdle(kStopCaptureTimeout);
908d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala            // no break
9092e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::RECORD:
9102e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::PREVIEW:
911a27c4aa222c8dd1712617dad954c5f3aa68d5427Ruben Brunk            syncWithDevice();
912d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala            res = stopStream();
913d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala            if (res != OK) {
914d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala                ALOGE("%s: Camera %d: Can't stop streaming: %s (%d)",
915d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala                        __FUNCTION__, mCameraId, strerror(-res), res);
916d09801b99503b57c35e321ad9afa7e861e012813Eino-Ville Talvala            }
9172cec0dfa9f97b87733b8b250b49729fc6bb3a60aRuchit Sharma
9182cec0dfa9f97b87733b8b250b49729fc6bb3a60aRuchit Sharma            // Flush all in-process captures and buffer in order to stop
9192cec0dfa9f97b87733b8b250b49729fc6bb3a60aRuchit Sharma            // preview faster.
9202cec0dfa9f97b87733b8b250b49729fc6bb3a60aRuchit Sharma            res = mDevice->flush();
9212cec0dfa9f97b87733b8b250b49729fc6bb3a60aRuchit Sharma            if (res != OK) {
9222cec0dfa9f97b87733b8b250b49729fc6bb3a60aRuchit Sharma                ALOGE("%s: Camera %d: Unable to flush pending requests: %s (%d)",
9232cec0dfa9f97b87733b8b250b49729fc6bb3a60aRuchit Sharma                        __FUNCTION__, mCameraId, strerror(-res), res);
9242cec0dfa9f97b87733b8b250b49729fc6bb3a60aRuchit Sharma            }
9252cec0dfa9f97b87733b8b250b49729fc6bb3a60aRuchit Sharma
9264865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala            res = mDevice->waitUntilDrained();
9274865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala            if (res != OK) {
9284865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala                ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)",
9294865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala                        __FUNCTION__, mCameraId, strerror(-res), res);
9304865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala            }
93128d0327bc80e1e424c3db34c62e8f73cd5ffab1eYin-Chia Yeh            // Clean up recording stream
93228d0327bc80e1e424c3db34c62e8f73cd5ffab1eYin-Chia Yeh            res = mStreamingProcessor->deleteRecordingStream();
93328d0327bc80e1e424c3db34c62e8f73cd5ffab1eYin-Chia Yeh            if (res != OK) {
93428d0327bc80e1e424c3db34c62e8f73cd5ffab1eYin-Chia Yeh                ALOGE("%s: Camera %d: Unable to delete recording stream before "
93528d0327bc80e1e424c3db34c62e8f73cd5ffab1eYin-Chia Yeh                        "stop preview: %s (%d)",
93628d0327bc80e1e424c3db34c62e8f73cd5ffab1eYin-Chia Yeh                        __FUNCTION__, mCameraId, strerror(-res), res);
93728d0327bc80e1e424c3db34c62e8f73cd5ffab1eYin-Chia Yeh            }
938228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            // no break
9392e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::WAITING_FOR_PREVIEW_WINDOW: {
9402e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala            SharedParameters::Lock l(mParameters);
9412e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala            l.mParameters.state = Parameters::STOPPED;
9422e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala            commandStopFaceDetectionL(l.mParameters);
943d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala            break;
944228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        }
945d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala        default:
946d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala            ALOGE("%s: Camera %d: Unknown state %d", __FUNCTION__, mCameraId,
947228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala                    state);
948d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala    }
94961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
95061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
95161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalabool Camera2Client::previewEnabled() {
952a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
95344cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
9543a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
9553a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return false;
9563a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala
9572e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
9582e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    return l.mParameters.state == Parameters::PREVIEW;
95961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
96061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
9618cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chenstatus_t Camera2Client::setVideoBufferMode(int32_t videoBufferMode) {
962a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
96344cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
9643a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
9653a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
9663a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala
9672e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
9682e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    switch (l.mParameters.state) {
9692e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::RECORD:
9702e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::VIDEO_SNAPSHOT:
97178822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala            ALOGE("%s: Camera %d: Can't be called in state %s",
9722e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    __FUNCTION__, mCameraId,
9732e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    Parameters::getStateName(l.mParameters.state));
97478822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala            return INVALID_OPERATION;
97578822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala        default:
97678822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala            // OK
97778822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala            break;
97878822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala    }
97978822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala
9808cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    if (videoBufferMode != VIDEO_BUFFER_MODE_BUFFER_QUEUE) {
9818cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        ALOGE("%s: %d: Only video buffer queue is supported", __FUNCTION__, __LINE__);
9828cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        return BAD_VALUE;
9838cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    }
9848cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen
9858cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    l.mParameters.videoBufferMode = videoBufferMode;
98678822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala
98778822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala    return OK;
98861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
98961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
99061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::startRecording() {
991a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
9929e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
99344cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
9949cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    status_t res;
9953a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
9962e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
997228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
9982e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    return startRecordingL(l.mParameters, false);
999228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala}
10003a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala
1001228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvalastatus_t Camera2Client::startRecordingL(Parameters &params, bool restart) {
10027fd5bdb5fa9db81f0293793b7b6d45dd833d05b2Yunlian Jiang    status_t res = OK;
100322d58d37db6b5f48a10b3a19f69ffda09943c125Igor Murashkin
100422d58d37db6b5f48a10b3a19f69ffda09943c125Igor Murashkin    ALOGV("%s: state == %d, restart = %d", __FUNCTION__, params.state, restart);
100522d58d37db6b5f48a10b3a19f69ffda09943c125Igor Murashkin
1006228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    switch (params.state) {
10072e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STOPPED:
1008228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            res = startPreviewL(params, false);
10099cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            if (res != OK) return res;
101096ff5c48a81f3f45c384113480bf5e28620a72aeZhijun He            // Make sure first preview request is submitted to the HAL device to avoid
101196ff5c48a81f3f45c384113480bf5e28620a72aeZhijun He            // two consecutive set of configure_streams being called into the HAL.
101296ff5c48a81f3f45c384113480bf5e28620a72aeZhijun He            // TODO: Refactor this to avoid initial preview configuration.
101396ff5c48a81f3f45c384113480bf5e28620a72aeZhijun He            syncWithDevice();
10149cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            break;
10152e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::PREVIEW:
10169cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            // Ready to go
10179cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            break;
10182e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::RECORD:
10192e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::VIDEO_SNAPSHOT:
1020228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            // OK to call this when recording is already on, just skip unless
1021228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            // we're looking to restart
1022228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            if (!restart) return OK;
10239cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            break;
10249cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        default:
10259cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            ALOGE("%s: Camera %d: Can't start recording in state %s",
10262e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    __FUNCTION__, mCameraId,
10272e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    Parameters::getStateName(params.state));
10289cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            return INVALID_OPERATION;
10299cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    };
10309cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
10318cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    if (params.videoBufferMode != VIDEO_BUFFER_MODE_BUFFER_QUEUE) {
10328cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        ALOGE("%s: Camera %d: Recording only supported buffer queue mode, but "
10338cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen                "mode %d is requested!", __FUNCTION__, mCameraId, params.videoBufferMode);
10348cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        return INVALID_OPERATION;
10358cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    }
10368cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen
10378cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    if (!mStreamingProcessor->haveValidRecordingWindow()) {
10388cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        ALOGE("%s: No valid recording window", __FUNCTION__);
103978822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala        return INVALID_OPERATION;
104078822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala    }
104178822d73af1e7f6b8b297fc7f98ef7f8257cc10aEino-Ville Talvala
104273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    if (!restart) {
10432f09bac6632a5ee27ee14baa2aa1367f16b5b013Eino-Ville Talvala        sCameraService->playSound(CameraService::SOUND_RECORDING_START);
104473bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        mStreamingProcessor->updateRecordingRequest(params);
104573bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        if (res != OK) {
104673bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            ALOGE("%s: Camera %d: Unable to update recording request: %s (%d)",
104773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                    __FUNCTION__, mCameraId, strerror(-res), res);
104873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            return res;
104973bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        }
105073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    }
1051609acc0c96bc2aedd42246862b537e045f5184b6Eino-Ville Talvala
1052a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala    // Not all devices can support a preview callback stream and a recording
1053a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala    // stream at the same time, so assume none of them can.
1054a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala    if (mCallbackProcessor->getStreamId() != NO_STREAM) {
1055a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        ALOGV("%s: Camera %d: Clearing out callback stream before "
1056a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                "creating recording stream", __FUNCTION__, mCameraId);
1057a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        res = mStreamingProcessor->stopStream();
1058a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        if (res != OK) {
1059a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            ALOGE("%s: Camera %d: Can't stop streaming to delete callback stream",
1060a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                    __FUNCTION__, mCameraId);
1061a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            return res;
1062a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        }
1063a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        res = mCallbackProcessor->deleteStream();
1064a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        if (res != OK) {
1065a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            ALOGE("%s: Camera %d: Unable to delete callback stream before "
1066a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                    "record: %s (%d)", __FUNCTION__, mCameraId,
1067a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala                    strerror(-res), res);
1068a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala            return res;
1069a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala        }
1070a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala    }
1071ca05ebd4c666322e754ac63236c8b329dbb53b00Yin-Chia Yeh
1072d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    // Clean up ZSL before transitioning into recording
1073d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    if (mZslProcessor->getStreamId() != NO_STREAM) {
1074d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        ALOGV("%s: Camera %d: Clearing out zsl stream before "
1075d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                "creating recording stream", __FUNCTION__, mCameraId);
1076d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        res = mStreamingProcessor->stopStream();
1077d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        if (res != OK) {
1078d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            ALOGE("%s: Camera %d: Can't stop streaming to delete callback stream",
1079d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    __FUNCTION__, mCameraId);
1080d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            return res;
1081d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        }
1082d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        res = mDevice->waitUntilDrained();
1083d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        if (res != OK) {
1084d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)",
1085d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    __FUNCTION__, mCameraId, strerror(-res), res);
1086d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        }
1087d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        res = mZslProcessor->clearZslQueue();
1088d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        if (res != OK) {
1089d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            ALOGE("%s: Camera %d: Can't clear zsl queue",
1090d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    __FUNCTION__, mCameraId);
1091d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            return res;
1092d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        }
1093d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        res = mZslProcessor->deleteStream();
1094d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        if (res != OK) {
1095d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            ALOGE("%s: Camera %d: Unable to delete zsl stream before "
1096d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    "record: %s (%d)", __FUNCTION__, mCameraId,
1097d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    strerror(-res), res);
1098d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            return res;
1099ca05ebd4c666322e754ac63236c8b329dbb53b00Yin-Chia Yeh        }
1100ca05ebd4c666322e754ac63236c8b329dbb53b00Yin-Chia Yeh    }
1101ca05ebd4c666322e754ac63236c8b329dbb53b00Yin-Chia Yeh
1102a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala    // Disable callbacks if they're enabled; can't record and use callbacks,
1103a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala    // and we can't fail record start without stagefright asserting.
1104a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala    params.previewCallbackFlags = 0;
1105a691ff3c03e38e148bbefed35ebb15e552a12613Eino-Ville Talvala
1106d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    // May need to reconfigure video snapshot JPEG sizes
1107d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    // during recording startup, so need a more complex sequence here to
1108d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    // ensure an early stream reconfiguration doesn't happen
1109d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    bool recordingStreamNeedsUpdate;
1110d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    res = mStreamingProcessor->recordingStreamNeedsUpdate(params, &recordingStreamNeedsUpdate);
1111d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    if (res != OK) {
1112d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        ALOGE("%s: Camera %d: Can't query recording stream",
1113d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                __FUNCTION__, mCameraId);
1114d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        return res;
1115d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    }
1116d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala
1117d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala    if (recordingStreamNeedsUpdate) {
1118d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        // Need to stop stream here so updateProcessorStream won't trigger configureStream
1119d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        // Right now camera device cannot handle configureStream failure gracefully
1120d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        // when device is streaming
1121d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        res = mStreamingProcessor->stopStream();
1122a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh        if (res != OK) {
1123d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            ALOGE("%s: Camera %d: Can't stop streaming to update record "
1124d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    "stream", __FUNCTION__, mCameraId);
1125a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh            return res;
1126a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh        }
1127d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        res = mDevice->waitUntilDrained();
1128d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala        if (res != OK) {
1129d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            ALOGE("%s: Camera %d: Waiting to stop streaming failed: "
1130d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    "%s (%d)", __FUNCTION__, mCameraId,
1131d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    strerror(-res), res);
1132a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh        }
1133d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala
1134a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh        res = updateProcessorStream<
1135d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            StreamingProcessor,
1136d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            &StreamingProcessor::updateRecordingStream>(
1137d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                                                        mStreamingProcessor,
1138d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                                                        params);
1139a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh        if (res != OK) {
1140d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala            ALOGE("%s: Camera %d: Unable to update recording stream: "
1141d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    "%s (%d)", __FUNCTION__, mCameraId,
1142d309fb9c8a2c4564d88fffba19c4e3688e4b862bEino-Ville Talvala                    strerror(-res), res);
1143a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh            return res;
1144a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh        }
1145a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh    }
1146a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh
1147d1d6467d3bcbc1305eeba0176a2edf04925c368eZhijun He    Vector<int32_t> outputStreams;
114873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    outputStreams.push(getPreviewStreamId());
114973bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    outputStreams.push(getRecordingStreamId());
11509cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
115173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    res = mStreamingProcessor->startStream(StreamingProcessor::RECORD,
115273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            outputStreams);
11533ea3fcd0822b2f43d87f1d8f67d7bf145864b201Yin-Chia Yeh
1154a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh    // startStream might trigger a configureStream call and device might fail
1155a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh    // configureStream due to jpeg size > video size. Try again with jpeg size overridden
1156a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh    // to video size.
1157a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh    if (res == BAD_VALUE) {
1158a53021f776d0c82271727e5817388936513feb92Yin-Chia Yeh        overrideVideoSnapshotSize(params);
11593ea3fcd0822b2f43d87f1d8f67d7bf145864b201Yin-Chia Yeh        res = mStreamingProcessor->startStream(StreamingProcessor::RECORD,
11603ea3fcd0822b2f43d87f1d8f67d7bf145864b201Yin-Chia Yeh                outputStreams);
11613ea3fcd0822b2f43d87f1d8f67d7bf145864b201Yin-Chia Yeh    }
11623ea3fcd0822b2f43d87f1d8f67d7bf145864b201Yin-Chia Yeh
11639cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (res != OK) {
116473bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        ALOGE("%s: Camera %d: Unable to start recording stream: %s (%d)",
11659cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala                __FUNCTION__, mCameraId, strerror(-res), res);
11669cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        return res;
11679cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
11689cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
11692e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    if (params.state < Parameters::RECORD) {
11702e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        params.state = Parameters::RECORD;
1171228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    }
11729cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
11739cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    return OK;
117461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
117561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
117661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalavoid Camera2Client::stopRecording() {
1177a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
11789e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
117944cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
11802e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
1181228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
11829cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    status_t res;
11833a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return;
11843a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala
11852e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    switch (l.mParameters.state) {
11862e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::RECORD:
11879cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            // OK to stop
11889cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            break;
11892e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STOPPED:
11902e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::PREVIEW:
11912e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STILL_CAPTURE:
11922e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::VIDEO_SNAPSHOT:
11939cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        default:
11949cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            ALOGE("%s: Camera %d: Can't stop recording in state %s",
11952e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    __FUNCTION__, mCameraId,
11962e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    Parameters::getStateName(l.mParameters.state));
11979cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            return;
11989cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    };
11999cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
12002f09bac6632a5ee27ee14baa2aa1367f16b5b013Eino-Ville Talvala    sCameraService->playSound(CameraService::SOUND_RECORDING_STOP);
1201609acc0c96bc2aedd42246862b537e045f5184b6Eino-Ville Talvala
12028cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    // Remove recording stream because the video target may be abandoned soon.
12038cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    res = stopStream();
12048cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    if (res != OK) {
12058cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        ALOGE("%s: Camera %d: Can't stop streaming: %s (%d)",
12068cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen                __FUNCTION__, mCameraId, strerror(-res), res);
1207092d49c26d77fafad5170bf709c2a716ec335855Yin-Chia Yeh    }
1208092d49c26d77fafad5170bf709c2a716ec335855Yin-Chia Yeh
12098cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    res = mDevice->waitUntilDrained();
12108cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    if (res != OK) {
12118cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)",
12128cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen                __FUNCTION__, mCameraId, strerror(-res), res);
12138cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    }
12148cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    // Clean up recording stream
12158cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    res = mStreamingProcessor->deleteRecordingStream();
12168cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    if (res != OK) {
12178cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        ALOGE("%s: Camera %d: Unable to delete recording stream before "
12188cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen                "stop preview: %s (%d)",
12198cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen                __FUNCTION__, mCameraId, strerror(-res), res);
12208cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    }
12218cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    l.mParameters.recoverOverriddenJpegSize();
12228cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen
12238cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    // Restart preview
12245a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala    res = startPreviewL(l.mParameters, true);
12259cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (res != OK) {
12265a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala        ALOGE("%s: Camera %d: Unable to return to preview",
12275a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala                __FUNCTION__, mCameraId);
12289cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
122961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
123061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
123161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalabool Camera2Client::recordingEnabled() {
1232a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
123344cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
12348da4cd7d706d9f551bf2d08cd8b61907a10cd38dJames Dong
12353a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( checkPid(__FUNCTION__) != OK) return false;
12363a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala
12378da4cd7d706d9f551bf2d08cd8b61907a10cd38dJames Dong    return recordingEnabledL();
12388da4cd7d706d9f551bf2d08cd8b61907a10cd38dJames Dong}
12398da4cd7d706d9f551bf2d08cd8b61907a10cd38dJames Dong
12408da4cd7d706d9f551bf2d08cd8b61907a10cd38dJames Dongbool Camera2Client::recordingEnabledL() {
12418da4cd7d706d9f551bf2d08cd8b61907a10cd38dJames Dong    ATRACE_CALL();
12422e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
12438da4cd7d706d9f551bf2d08cd8b61907a10cd38dJames Dong
12442e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    return (l.mParameters.state == Parameters::RECORD
12452e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala            || l.mParameters.state == Parameters::VIDEO_SNAPSHOT);
124661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
124761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
124861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalavoid Camera2Client::releaseRecordingFrame(const sp<IMemory>& mem) {
124998a668f6ea51e4d894d2ebb61a0e18287fb14008Chien-Yu Chen    (void)mem;
1250a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
12518cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    ALOGW("%s: Not supported in buffer queue mode.", __FUNCTION__);
125261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
125361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
12542d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chenvoid Camera2Client::releaseRecordingFrameHandle(native_handle_t *handle) {
12552d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen    (void)handle;
12562d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen    ATRACE_CALL();
12572d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen    ALOGW("%s: Not supported in buffer queue mode.", __FUNCTION__);
12582d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen}
12592d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen
1260b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yehvoid Camera2Client::releaseRecordingFrameHandleBatch(
1261b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        const std::vector<native_handle_t*>& handles) {
1262b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh    (void)handles;
1263b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh    ATRACE_CALL();
1264b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh    ALOGW("%s: Not supported in buffer queue mode.", __FUNCTION__);
1265b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh}
1266b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh
126761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::autoFocus() {
1268a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
126944cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin    Mutex::Autolock icl(mBinderSerializationLock);
12708a42dd8cd1a245d844f96cfd67dc342d7937e353Eino-Ville Talvala    ALOGV("%s: Camera %d", __FUNCTION__, mCameraId);
12713a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
12723a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
12733a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala
1274174181eec57c963a2a17bd156d81c3f18b3ba75cEino-Ville Talvala    int triggerId;
1275d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala    bool notifyImmediately = false;
1276d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala    bool notifySuccess = false;
1277174181eec57c963a2a17bd156d81c3f18b3ba75cEino-Ville Talvala    {
12782e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        SharedParameters::Lock l(mParameters);
12794865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala        if (l.mParameters.state < Parameters::PREVIEW) {
1280f79f8ca07f9130d67ba575748cf3481f32dcad9fZhijun He            ALOGE("%s: Camera %d: Call autoFocus when preview is inactive (state = %d).",
1281f79f8ca07f9130d67ba575748cf3481f32dcad9fZhijun He                    __FUNCTION__, mCameraId, l.mParameters.state);
12824865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala            return INVALID_OPERATION;
12834865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala        }
12844865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala
12855f0714eb039c07554bef6ec289c70ed1164fdf52Igor Murashkin        /**
12865f0714eb039c07554bef6ec289c70ed1164fdf52Igor Murashkin          * If the camera does not support auto-focus, it is a no-op and
12875f0714eb039c07554bef6ec289c70ed1164fdf52Igor Murashkin          * onAutoFocus(boolean, Camera) callback will be called immediately
12885f0714eb039c07554bef6ec289c70ed1164fdf52Igor Murashkin          * with a fake value of success set to true.
12899454a9710b13c7d9262fe1cbd910235a3cd35f20Eino-Ville Talvala          *
12909454a9710b13c7d9262fe1cbd910235a3cd35f20Eino-Ville Talvala          * Similarly, if focus mode is set to INFINITY, there's no reason to
12919454a9710b13c7d9262fe1cbd910235a3cd35f20Eino-Ville Talvala          * bother the HAL.
12925f0714eb039c07554bef6ec289c70ed1164fdf52Igor Murashkin          */
12939454a9710b13c7d9262fe1cbd910235a3cd35f20Eino-Ville Talvala        if (l.mParameters.focusMode == Parameters::FOCUS_MODE_FIXED ||
12949454a9710b13c7d9262fe1cbd910235a3cd35f20Eino-Ville Talvala                l.mParameters.focusMode == Parameters::FOCUS_MODE_INFINITY) {
1295d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala            notifyImmediately = true;
1296d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala            notifySuccess = true;
1297d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        }
1298d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        /**
1299d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala         * If we're in CAF mode, and AF has already been locked, just fire back
1300d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala         * the callback right away; the HAL would not send a notification since
1301d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala         * no state change would happen on a AF trigger.
1302d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala         */
1303d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        if ( (l.mParameters.focusMode == Parameters::FOCUS_MODE_CONTINUOUS_PICTURE ||
1304d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala                l.mParameters.focusMode == Parameters::FOCUS_MODE_CONTINUOUS_VIDEO) &&
1305d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala                l.mParameters.focusState == ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED ) {
1306d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala            notifyImmediately = true;
1307d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala            notifySuccess = true;
1308d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        }
1309d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        /**
1310d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala         * Send immediate notification back to client
1311d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala         */
1312d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        if (notifyImmediately) {
131344cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin            SharedCameraCallbacks::Lock l(mSharedCameraCallbacks);
131444cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin            if (l.mRemoteCallback != 0) {
131544cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin                l.mRemoteCallback->notifyCallback(CAMERA_MSG_FOCUS,
1316d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala                        notifySuccess ? 1 : 0, 0);
13175f0714eb039c07554bef6ec289c70ed1164fdf52Igor Murashkin            }
13185f0714eb039c07554bef6ec289c70ed1164fdf52Igor Murashkin            return OK;
13195f0714eb039c07554bef6ec289c70ed1164fdf52Igor Murashkin        }
1320d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        /**
1321d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala         * Handle quirk mode for AF in scene modes
1322d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala         */
132395069fefbdf54d87a624c2ac73727fce1c38545eEino-Ville Talvala        if (l.mParameters.quirks.triggerAfWithAuto &&
1324c69b91ceae6255e41c5413796fb0ed4f7af45b15Ruben Brunk                l.mParameters.sceneMode != ANDROID_CONTROL_SCENE_MODE_DISABLED &&
1325ac0cd56627b121081308213d5a327cfbae410f4dEino-Ville Talvala                l.mParameters.focusMode != Parameters::FOCUS_MODE_AUTO &&
1326ac0cd56627b121081308213d5a327cfbae410f4dEino-Ville Talvala                !l.mParameters.focusingAreas[0].isEmpty()) {
132795069fefbdf54d87a624c2ac73727fce1c38545eEino-Ville Talvala            ALOGV("%s: Quirk: Switching from focusMode %d to AUTO",
132895069fefbdf54d87a624c2ac73727fce1c38545eEino-Ville Talvala                    __FUNCTION__, l.mParameters.focusMode);
132995069fefbdf54d87a624c2ac73727fce1c38545eEino-Ville Talvala            l.mParameters.shadowFocusMode = l.mParameters.focusMode;
133095069fefbdf54d87a624c2ac73727fce1c38545eEino-Ville Talvala            l.mParameters.focusMode = Parameters::FOCUS_MODE_AUTO;
133195069fefbdf54d87a624c2ac73727fce1c38545eEino-Ville Talvala            updateRequests(l.mParameters);
133295069fefbdf54d87a624c2ac73727fce1c38545eEino-Ville Talvala        }
133395069fefbdf54d87a624c2ac73727fce1c38545eEino-Ville Talvala
13342e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        l.mParameters.currentAfTriggerId = ++l.mParameters.afTriggerCounter;
13352e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        triggerId = l.mParameters.currentAfTriggerId;
1336174181eec57c963a2a17bd156d81c3f18b3ba75cEino-Ville Talvala    }
13372b07e0207da44d7b3cc63c369fd10c9f12a5e2cdEino-Ville Talvala    ATRACE_ASYNC_BEGIN(kAutofocusLabel, triggerId);
13382b07e0207da44d7b3cc63c369fd10c9f12a5e2cdEino-Ville Talvala
13394865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala    syncWithDevice();
1340174181eec57c963a2a17bd156d81c3f18b3ba75cEino-Ville Talvala
1341174181eec57c963a2a17bd156d81c3f18b3ba75cEino-Ville Talvala    mDevice->triggerAutofocus(triggerId);
1342174181eec57c963a2a17bd156d81c3f18b3ba75cEino-Ville Talvala
13436db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    return OK;
134461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
134561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
134661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::cancelAutoFocus() {
1347a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
134844cfcf00b9008c1c04f4c8277c6c06af039fd976Igor Murashkin<