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
174bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala#define LOG_TAG "Camera2"
18a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala#define ATRACE_TAG ATRACE_TAG_CAMERA
1961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala//#define LOG_NDEBUG 0
20a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala
21f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala#include <utils/Log.h>
22a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala#include <utils/Trace.h>
2361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
2461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala#include <cutils/properties.h>
2561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala#include <gui/SurfaceTextureClient.h>
2661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala#include <gui/Surface.h>
27e538206d15282afbc5b168d60b1026a5dfcd13c0James Painter#include "camera2/Parameters.h"
2810894e509f777c6bd7e408a57f5cf21ee2b36a96James Painter#include "Camera2Client.h"
2961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
3061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala#define ALOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__);
3161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala#define ALOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__);
3261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
332e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvalanamespace android {
342e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvalausing namespace camera2;
352e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala
3661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatic int getCallingPid() {
3761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala    return IPCThreadState::self()->getCallingPid();
3861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
3961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
4061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatic int getCallingUid() {
4161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala    return IPCThreadState::self()->getCallingUid();
4261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
4361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
4461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala// Interface used by CameraService
4561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
4661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville TalvalaCamera2Client::Camera2Client(const sp<CameraService>& cameraService,
4761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala        const sp<ICameraClient>& cameraClient,
4861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala        int cameraId,
4961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala        int cameraFacing,
50ecf17e82505fdb60d59e00b6dd59036df93de655Igor Murashkin        int clientPid,
51ecf17e82505fdb60d59e00b6dd59036df93de655Igor Murashkin        int servicePid):
5261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala        Client(cameraService, cameraClient,
53ecf17e82505fdb60d59e00b6dd59036df93de655Igor Murashkin                cameraId, cameraFacing, clientPid, servicePid),
54ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala        mSharedCameraClient(cameraClient),
5573bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        mParameters(cameraId, cameraFacing)
56f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala{
57a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
58da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    ALOGI("Camera %d: Opened", cameraId);
5961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
60f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    mDevice = new Camera2Device(cameraId);
61228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
622e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
632e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    l.mParameters.state = Parameters::DISCONNECTED;
64f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala}
65f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
663a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvalastatus_t Camera2Client::checkPid(const char* checkLocation) const {
673a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    int callingPid = getCallingPid();
68c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala    if (callingPid == mClientPid) return NO_ERROR;
693a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala
703a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    ALOGE("%s: attempt to use a locked camera from a different process"
71c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala            " (old pid %d, new pid %d)", checkLocation, mClientPid, callingPid);
723a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    return PERMISSION_DENIED;
733a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala}
743a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala
75f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvalastatus_t Camera2Client::initialize(camera_module_t *module)
76f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala{
77a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
78c8474b68e435cd840ba66791fb09e3da59f1d93cEino-Ville Talvala    ALOGV("%s: Initializing client for camera %d", __FUNCTION__, mCameraId);
79f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    status_t res;
80f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
81f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    res = mDevice->initialize(module);
82f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    if (res != OK) {
83f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala        ALOGE("%s: Camera %d: unable to initialize device: %s (%d)",
84f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala                __FUNCTION__, mCameraId, strerror(-res), res);
85f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala        return NO_INIT;
86f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    }
87f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
88174181eec57c963a2a17bd156d81c3f18b3ba75cEino-Ville Talvala    res = mDevice->setNotifyCallback(this);
89174181eec57c963a2a17bd156d81c3f18b3ba75cEino-Ville Talvala
902e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
912e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala
922e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    res = l.mParameters.initialize(&(mDevice->info()));
93f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    if (res != OK) {
94f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala        ALOGE("%s: Camera %d: unable to build defaults: %s (%d)",
95f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala                __FUNCTION__, mCameraId, strerror(-res), res);
96f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala        return NO_INIT;
97f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    }
983cca136b73b0f4d058019230eb2070cc23e2bbb0Eino-Ville Talvala
99da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    String8 threadName;
100da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala
10173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    mStreamingProcessor = new StreamingProcessor(this);
10273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala
103ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala    mFrameProcessor = new FrameProcessor(this);
1044bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-FrameProc",
105da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            mCameraId);
106da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mFrameProcessor->run(threadName.string());
107da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala
108da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mCaptureSequencer = new CaptureSequencer(this);
1094bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-CaptureSeq",
110da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            mCameraId);
111da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mCaptureSequencer->run(threadName.string());
112da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala
113da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mJpegProcessor = new JpegProcessor(this, mCaptureSequencer);
1144bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-JpegProc",
115ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala            mCameraId);
116da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mJpegProcessor->run(threadName.string());
117ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala
118da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mZslProcessor = new ZslProcessor(this, mCaptureSequencer);
1194bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-ZslProc",
120da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            mCameraId);
121da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mZslProcessor->run(threadName.string());
122ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala
123d86a6880fe86bda21a9b53b240996fc410a512a5Eino-Ville Talvala    mCallbackProcessor = new CallbackProcessor(this);
1244bb8118816874c696d9f1adab48490df1da365f7Eino-Ville Talvala    threadName = String8::format("C2-%d-CallbkProc",
125da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            mCameraId);
126da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mCallbackProcessor->run(threadName.string());
127d86a6880fe86bda21a9b53b240996fc410a512a5Eino-Ville Talvala
128f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    if (gLogLevel >= 1) {
129f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala        ALOGD("%s: Default parameters converted from camera %d:", __FUNCTION__,
130f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala              mCameraId);
1312e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        ALOGD("%s", l.mParameters.paramsFlattened.string());
132f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    }
133f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
134f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    return OK;
13561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
13661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
13761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville TalvalaCamera2Client::~Camera2Client() {
138a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
1394ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala
140f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    mDestructionStarted = true;
141f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
142c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala    disconnect();
143c8474b68e435cd840ba66791fb09e3da59f1d93cEino-Ville Talvala
144da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    ALOGI("Camera %d: Closed", mCameraId);
14561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
14661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
14761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::dump(int fd, const Vector<String16>& args) {
148611f61998863d3a3ffae4e5f2b723b7319c59ddfEino-Ville Talvala    String8 result;
1493297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    result.appendFormat("Client2[%d] (%p) PID: %d, dump:\n",
150611f61998863d3a3ffae4e5f2b723b7319c59ddfEino-Ville Talvala            mCameraId,
151611f61998863d3a3ffae4e5f2b723b7319c59ddfEino-Ville Talvala            getCameraClient()->asBinder().get(),
152611f61998863d3a3ffae4e5f2b723b7319c59ddfEino-Ville Talvala            mClientPid);
1537f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("  State: ");
1547f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala#define CASE_APPEND_ENUM(x) case x: result.append(#x "\n"); break;
1557f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
1562e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    const Parameters& p = mParameters.unsafeAccess();
157836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala
1582e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    result.append(Parameters::getStateName(p.state));
1597f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
1604ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala    result.append("\n  Current parameters:\n");
1617f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Preview size: %d x %d\n",
162836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.previewWidth, p.previewHeight);
1637f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Preview FPS range: %d - %d\n",
164836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.previewFpsRange[0], p.previewFpsRange[1]);
1657f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Preview HAL pixel format: 0x%x\n",
166836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.previewFormat);
16711b7cdef9726f8270f12f6c393600e8fb3c469deEino-Ville Talvala    result.appendFormat("    Preview transform: %x\n",
168836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.previewTransform);
1697f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Picture size: %d x %d\n",
170836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.pictureWidth, p.pictureHeight);
1717f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Jpeg thumbnail size: %d x %d\n",
172836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.jpegThumbSize[0], p.jpegThumbSize[1]);
1737f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Jpeg quality: %d, thumbnail quality: %d\n",
174836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.jpegQuality, p.jpegThumbQuality);
175836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    result.appendFormat("    Jpeg rotation: %d\n", p.jpegRotation);
1767f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    GPS tags %s\n",
177836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.gpsEnabled ? "enabled" : "disabled");
178836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    if (p.gpsEnabled) {
1797f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        result.appendFormat("    GPS lat x long x alt: %f x %f x %f\n",
180836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.gpsCoordinates[0], p.gpsCoordinates[1],
181836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.gpsCoordinates[2]);
1827f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        result.appendFormat("    GPS timestamp: %lld\n",
183836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.gpsTimestamp);
1847f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        result.appendFormat("    GPS processing method: %s\n",
185836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.gpsProcessingMethod.string());
1867f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
1877f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
1887f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    White balance mode: ");
189836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.wbMode) {
1907f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_AUTO)
1917f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_INCANDESCENT)
1927f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_FLUORESCENT)
1937f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_WARM_FLUORESCENT)
1947f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_DAYLIGHT)
1957f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_CLOUDY_DAYLIGHT)
1967f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_TWILIGHT)
1977f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AWB_SHADE)
1987f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
1997f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2007f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2017f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Effect mode: ");
202836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.effectMode) {
2037f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_OFF)
2047f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_MONO)
2057f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_NEGATIVE)
2067f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_SOLARIZE)
2077f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_SEPIA)
2087f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_POSTERIZE)
2097f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_WHITEBOARD)
2107f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_BLACKBOARD)
2117f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_EFFECT_AQUA)
2127f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2137f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2147f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2157f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Antibanding mode: ");
216836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.antibandingMode) {
2177f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_AUTO)
2187f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_OFF)
2197f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_50HZ)
2207f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AE_ANTIBANDING_60HZ)
2217f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2227f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2237f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2247f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Scene mode: ");
225836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.sceneMode) {
2267f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        case ANDROID_CONTROL_SCENE_MODE_UNSUPPORTED:
2277f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala            result.append("AUTO\n"); break;
2287f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_ACTION)
2297f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PORTRAIT)
2307f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_LANDSCAPE)
2317f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT)
2327f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_NIGHT_PORTRAIT)
2337f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_THEATRE)
2347f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BEACH)
2357f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SNOW)
2367f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SUNSET)
2377f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_STEADYPHOTO)
2387f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_FIREWORKS)
2397f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_SPORTS)
2407f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PARTY)
2417f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_CANDLELIGHT)
2427f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_BARCODE)
2437f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2447f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2457f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2467f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Flash mode: ");
247836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.flashMode) {
2487f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_OFF)
2497f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_AUTO)
2507f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_ON)
2517f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_TORCH)
2527f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_RED_EYE)
2537f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FLASH_MODE_INVALID)
2547f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2557f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2567f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2577f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Focus mode: ");
258836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    switch (p.focusMode) {
2597f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_AUTO)
2607f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_MACRO)
2617f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_VIDEO)
2627f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_CONTINUOUS_PICTURE)
2637f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_EDOF)
2647f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INFINITY)
2657f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_FIXED)
2667f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        CASE_APPEND_ENUM(Parameters::FOCUS_MODE_INVALID)
2677f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        default: result.append("UNKNOWN\n");
2687f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2697f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
270d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala    result.append("   Focus state: ");
271d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala    switch (p.focusState) {
272d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_INACTIVE)
273d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN)
274d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED)
275d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN)
276d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED)
277d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        CASE_APPEND_ENUM(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED)
278d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala        default: result.append("UNKNOWN\n");
279d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala    }
280d6cc4a62f3d94cad4dd36bd0a844ba8764177d26Eino-Ville Talvala
2817f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.append("    Focusing areas:\n");
282836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    for (size_t i = 0; i < p.focusingAreas.size(); i++) {
2837f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        result.appendFormat("      [ (%d, %d, %d, %d), weight %d ]\n",
284836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].left,
285836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].top,
286836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].right,
287836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].bottom,
288836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.focusingAreas[i].weight);
2897f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
2907f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2917f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Exposure compensation index: %d\n",
292836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.exposureCompensation);
2937f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2947f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    AE lock %s, AWB lock %s\n",
295836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.autoExposureLock ? "enabled" : "disabled",
296836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.autoWhiteBalanceLock ? "enabled" : "disabled" );
2977f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
2987f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    result.appendFormat("    Metering areas:\n");
299836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    for (size_t i = 0; i < p.meteringAreas.size(); i++) {
3007f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala        result.appendFormat("      [ (%d, %d, %d, %d), weight %d ]\n",
301836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].left,
302836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].top,
303836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].right,
304836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].bottom,
305836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala                p.meteringAreas[i].weight);
3067f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala    }
3077f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
308836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    result.appendFormat("    Zoom index: %d\n", p.zoom);
309836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala    result.appendFormat("    Video size: %d x %d\n", p.videoWidth,
310836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.videoHeight);
3117f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3123297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    result.appendFormat("    Recording hint is %s\n",
313836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.recordingHint ? "set" : "not set");
3147f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3153297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    result.appendFormat("    Video stabilization is %s\n",
316836b81f3c5a5bacb800f698f90ded6bd6e6bc5ceEino-Ville Talvala            p.videoStabilization ? "enabled" : "disabled");
3177f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3183297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    result.append("  Current streams:\n");
319da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    result.appendFormat("    Preview stream ID: %d\n",
320da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            getPreviewStreamId());
321ea0d51b5ed0b474433b02414f9133b835f972569Eino-Ville Talvala    result.appendFormat("    Capture stream ID: %d\n",
322da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            getCaptureStreamId());
323da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    result.appendFormat("    Recording stream ID: %d\n",
324da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            getRecordingStreamId());
325e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala
326e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    result.append("  Quirks for this camera:\n");
327e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    bool haveQuirk = false;
328e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    if (p.quirks.triggerAfWithAuto) {
329e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        result.appendFormat("    triggerAfWithAuto\n");
330e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        haveQuirk = true;
331e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    }
332e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    if (p.quirks.useZslFormat) {
333e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        result.appendFormat("    useZslFormat\n");
334e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        haveQuirk = true;
335e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    }
3367373cbe85e617345f7002256a4be389fe62af913Igor Murashkin    if (p.quirks.meteringCropRegion) {
3377373cbe85e617345f7002256a4be389fe62af913Igor Murashkin        result.appendFormat("    meteringCropRegion\n");
3387373cbe85e617345f7002256a4be389fe62af913Igor Murashkin        haveQuirk = true;
3397373cbe85e617345f7002256a4be389fe62af913Igor Murashkin    }
340e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    if (!haveQuirk) {
341e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala        result.appendFormat("    none\n");
342e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala    }
343e382ee28709b83264a46b09e8f766c5ef42efa35Eino-Ville Talvala
34473bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    write(fd, result.string(), result.size());
3453297daae9681004775012faba9181d65e097e00cEino-Ville Talvala
34673bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    mStreamingProcessor->dump(fd, args);
347428b77a2b94b74665a47375b3fdb893b98d71269Eino-Ville Talvala
348da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mCaptureSequencer->dump(fd, args);
349da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala
350c8474b68e435cd840ba66791fb09e3da59f1d93cEino-Ville Talvala    mFrameProcessor->dump(fd, args);
351c8474b68e435cd840ba66791fb09e3da59f1d93cEino-Ville Talvala
35297b38a81ac989ccba02d726011a82541f14166dfEino-Ville Talvala    mZslProcessor->dump(fd, args);
35397b38a81ac989ccba02d726011a82541f14166dfEino-Ville Talvala
3543297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    result = "  Device dump:\n";
355611f61998863d3a3ffae4e5f2b723b7319c59ddfEino-Ville Talvala    write(fd, result.string(), result.size());
3567f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3573297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    status_t res = mDevice->dump(fd, args);
3583297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    if (res != OK) {
3593297daae9681004775012faba9181d65e097e00cEino-Ville Talvala        result = String8::format("   Error dumping device: %s (%d)",
3603297daae9681004775012faba9181d65e097e00cEino-Ville Talvala                strerror(-res), res);
3613297daae9681004775012faba9181d65e097e00cEino-Ville Talvala        write(fd, result.string(), result.size());
3623297daae9681004775012faba9181d65e097e00cEino-Ville Talvala    }
3637f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala
3647f61084a428a5c7afbeff2fa9e9839baf9018020Eino-Ville Talvala#undef CASE_APPEND_ENUM
365611f61998863d3a3ffae4e5f2b723b7319c59ddfEino-Ville Talvala    return NO_ERROR;
36661ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
36761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
36861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala// ICamera interface
36961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
37061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalavoid Camera2Client::disconnect() {
371a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
372ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    Mutex::Autolock icl(mICameraLock);
3733a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
374c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala
375c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala    // Allow both client and the media server to disconnect at all times
376c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala    int callingPid = getCallingPid();
377c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala    if (callingPid != mClientPid && callingPid != mServicePid) return;
378ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
379f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala    if (mDevice == 0) return;
380f69c70ded4316ea3ee504ac779bd024433ed4ef7Eino-Ville Talvala
38198bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    ALOGV("Camera %d: Shutting down", mCameraId);
38298bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
383d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala    stopPreviewL();
3846db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
38598bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    {
38698bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala        SharedParameters::Lock l(mParameters);
387c03792041b9dd6f7f54abd6c82bd6c755a336cd8Eino-Ville Talvala        if (l.mParameters.state == Parameters::DISCONNECTED) return;
38898bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala        l.mParameters.state = Parameters::DISCONNECTED;
38998bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    }
39098bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
39173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    mStreamingProcessor->deletePreviewStream();
39273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    mStreamingProcessor->deleteRecordingStream();
393da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    mJpegProcessor->deleteStream();
394d86a6880fe86bda21a9b53b240996fc410a512a5Eino-Ville Talvala    mCallbackProcessor->deleteStream();
395cf70d3469332445dc3ffd09729da3538612b1bb2Eino-Ville Talvala    mZslProcessor->deleteStream();
396cf70d3469332445dc3ffd09729da3538612b1bb2Eino-Ville Talvala
39798bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mFrameProcessor->requestExit();
39898bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mCaptureSequencer->requestExit();
39998bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mJpegProcessor->requestExit();
40098bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mZslProcessor->requestExit();
40198bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mCallbackProcessor->requestExit();
40298bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
40398bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    ALOGV("Camera %d: Waiting for threads", mCameraId);
40498bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
40598bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mFrameProcessor->join();
40698bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mCaptureSequencer->join();
40798bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mJpegProcessor->join();
40898bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mZslProcessor->join();
40998bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mCallbackProcessor->join();
41098bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
41198bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    ALOGV("Camera %d: Disconnecting device", mCameraId);
41298bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
41398bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala    mDevice->disconnect();
41498bb82d1bf7c94240956426812de6593801faad4Eino-Ville Talvala
4153a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    mDevice.clear();
4168ce89d9e2b132bf58a030acec88acf0a998926a1Eino-Ville Talvala
41761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala    CameraService::Client::disconnect();
41861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
41961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
42061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::connect(const sp<ICameraClient>& client) {
421a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
4229e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
423ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    Mutex::Autolock icl(mICameraLock);
424ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
4259cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (mClientPid != 0 && getCallingPid() != mClientPid) {
4269cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        ALOGE("%s: Camera %d: Connection attempt from pid %d; "
4279cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala                "current locked to pid %d", __FUNCTION__,
4289cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala                mCameraId, getCallingPid(), mClientPid);
4299cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        return BAD_VALUE;
4309cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
4319cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
4329cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    mClientPid = getCallingPid();
4338ce89d9e2b132bf58a030acec88acf0a998926a1Eino-Ville Talvala
4349cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    mCameraClient = client;
435a16733eeb9c40db4793bec408f29b4204e5f23b1Eino-Ville Talvala    mSharedCameraClient = client;
4369cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
4379cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    return OK;
43861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
43961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
44061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::lock() {
441a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
4429e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
443ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    Mutex::Autolock icl(mICameraLock);
4449cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    ALOGV("%s: Camera %d: Lock call from pid %d; current client pid %d",
4459cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            __FUNCTION__, mCameraId, getCallingPid(), mClientPid);
446ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
4479cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (mClientPid == 0) {
4489cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        mClientPid = getCallingPid();
4499cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        return OK;
4509cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
4519cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
4529cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (mClientPid != getCallingPid()) {
4539cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        ALOGE("%s: Camera %d: Lock call from pid %d; currently locked to pid %d",
4549cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala                __FUNCTION__, mCameraId, getCallingPid(), mClientPid);
4559cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        return EBUSY;
4569cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
4579cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
4589cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    return OK;
45961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
46061ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
46161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::unlock() {
462a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
4639e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
464ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    Mutex::Autolock icl(mICameraLock);
4659cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    ALOGV("%s: Camera %d: Unlock call from pid %d; current client pid %d",
4669cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            __FUNCTION__, mCameraId, getCallingPid(), mClientPid);
467ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
4689cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    if (mClientPid == getCallingPid()) {
469907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala        SharedParameters::Lock l(mParameters);
470907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala        if (l.mParameters.state == Parameters::RECORD ||
471907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala                l.mParameters.state == Parameters::VIDEO_SNAPSHOT) {
472907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala            ALOGD("Not allowed to unlock camera during recording.");
473907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala            return INVALID_OPERATION;
474907e5651c18d0e25073743a49a685fe1a385939aEino-Ville Talvala        }
4759cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        mClientPid = 0;
4769cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        mCameraClient.clear();
477a16733eeb9c40db4793bec408f29b4204e5f23b1Eino-Ville Talvala        mSharedCameraClient.clear();
4789cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala        return OK;
4799cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
4809cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
4819cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    ALOGE("%s: Camera %d: Unlock call from pid %d; currently locked to pid %d",
4829cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            __FUNCTION__, mCameraId, getCallingPid(), mClientPid);
4839cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    return EBUSY;
48461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
48561ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
4866db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvalastatus_t Camera2Client::setPreviewDisplay(
4876db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        const sp<Surface>& surface) {
488a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
4899e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
490ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    Mutex::Autolock icl(mICameraLock);
4913a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
4923a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
493ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
4946db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    sp<IBinder> binder;
4956db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    sp<ANativeWindow> window;
4966db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    if (surface != 0) {
4976db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        binder = surface->asBinder();
4986db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        window = surface;
4996db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
5006db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
50136cdfb185877a7f573621d19ed2b2e1cac13d62eEino-Ville Talvala    return setPreviewWindowL(binder,window);
50261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
50361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
5046db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvalastatus_t Camera2Client::setPreviewTexture(
5056db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        const sp<ISurfaceTexture>& surfaceTexture) {
506a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
5079e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
508ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    Mutex::Autolock icl(mICameraLock);
5093a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
5103a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
511ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
5126db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    sp<IBinder> binder;
5136db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    sp<ANativeWindow> window;
5146db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    if (surfaceTexture != 0) {
5156db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        binder = surfaceTexture->asBinder();
5166db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        window = new SurfaceTextureClient(surfaceTexture);
5176db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
51836cdfb185877a7f573621d19ed2b2e1cac13d62eEino-Ville Talvala    return setPreviewWindowL(binder, window);
5196db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala}
5206db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
52136cdfb185877a7f573621d19ed2b2e1cac13d62eEino-Ville Talvalastatus_t Camera2Client::setPreviewWindowL(const sp<IBinder>& binder,
522be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala        sp<ANativeWindow> window) {
523a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
5246db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    status_t res;
5256db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
5266db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    if (binder == mPreviewSurface) {
5279e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala        ALOGV("%s: Camera %d: New window is same as old window",
5289e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala                __FUNCTION__, mCameraId);
5296db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        return NO_ERROR;
5306db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
5316db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
532f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    Parameters::State state;
533f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    {
534f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala        SharedParameters::Lock l(mParameters);
535f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala        state = l.mParameters.state;
536f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    }
537f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    switch (state) {
5382e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::DISCONNECTED:
5392e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::RECORD:
5402e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STILL_CAPTURE:
5412e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::VIDEO_SNAPSHOT:
5429cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            ALOGE("%s: Camera %d: Cannot set preview display while in state %s",
5432e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    __FUNCTION__, mCameraId,
544f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala                    Parameters::getStateName(state));
5459cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            return INVALID_OPERATION;
5462e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STOPPED:
5472e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::WAITING_FOR_PREVIEW_WINDOW:
5489cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            // OK
5499cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            break;
5502e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::PREVIEW:
5519cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            // Already running preview - need to stop and create a new stream
5524865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala            mStreamingProcessor->stopStream();
553f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala            state = Parameters::WAITING_FOR_PREVIEW_WINDOW;
5549cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala            break;
5559cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala    }
5569cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
557bd47b7bcfe7f5a97fef81143f4282c41590626feEino-Ville Talvala    mPreviewSurface = binder;
55873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    res = mStreamingProcessor->setPreviewWindow(window);
55973bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    if (res != OK) {
56073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        ALOGE("%s: Unable to set new preview window: %s (%d)",
56173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                __FUNCTION__, strerror(-res), res);
56273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        return res;
56373bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    }
564bd47b7bcfe7f5a97fef81143f4282c41590626feEino-Ville Talvala
565f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala    if (state == Parameters::WAITING_FOR_PREVIEW_WINDOW) {
566f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala        SharedParameters::Lock l(mParameters);
567f1945f0435e431fab2e6b83337a1ffe71a8df28cEino-Ville Talvala        l.mParameters.state = state;
5682e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        return startPreviewL(l.mParameters, false);
5696db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
5706db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
5716db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    return OK;
57261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
57361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
57461ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalavoid Camera2Client::setPreviewCallbackFlag(int flag) {
575a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
576228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    ALOGV("%s: Camera %d: Flag 0x%x", __FUNCTION__, mCameraId, flag);
577ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    Mutex::Autolock icl(mICameraLock);
5783a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
579228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    if ( checkPid(__FUNCTION__) != OK) return;
580228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
5812e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
5822e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    setPreviewCallbackFlagL(l.mParameters, flag);
583228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala}
584228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
585228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvalavoid Camera2Client::setPreviewCallbackFlagL(Parameters &params, int flag) {
586228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    status_t res = OK;
587228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    if (flag & CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK) {
588228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        ALOGV("%s: setting oneshot", __FUNCTION__);
589228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        params.previewCallbackOneShot = true;
590228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    }
591228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    if (params.previewCallbackFlags != (uint32_t)flag) {
592228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        params.previewCallbackFlags = flag;
593228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        switch(params.state) {
5942e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::PREVIEW:
595228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            res = startPreviewL(params, true);
596228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            break;
5972e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::RECORD:
5982e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::VIDEO_SNAPSHOT:
599228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            res = startRecordingL(params, true);
600228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            break;
601228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        default:
602228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            break;
603228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        }
604228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        if (res != OK) {
605228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            ALOGE("%s: Camera %d: Unable to refresh request in state %s",
6062e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    __FUNCTION__, mCameraId,
6072e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                    Parameters::getStateName(params.state));
608228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        }
609228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    }
610228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
61161ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
61261ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
61361ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalastatus_t Camera2Client::startPreview() {
614a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
6159e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
616ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    Mutex::Autolock icl(mICameraLock);
6173a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
6183a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
6192e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    SharedParameters::Lock l(mParameters);
6202e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    return startPreviewL(l.mParameters, false);
621d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala}
622ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
623228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvalastatus_t Camera2Client::startPreviewL(Parameters &params, bool restart) {
624d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala    ATRACE_CALL();
6256db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    status_t res;
62622d58d37db6b5f48a10b3a19f69ffda09943c125Igor Murashkin
62722d58d37db6b5f48a10b3a19f69ffda09943c125Igor Murashkin    ALOGV("%s: state == %d, restart = %d", __FUNCTION__, params.state, restart);
62822d58d37db6b5f48a10b3a19f69ffda09943c125Igor Murashkin
629a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala    if ( (params.state == Parameters::PREVIEW ||
630a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala                    params.state == Parameters::RECORD ||
631a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala                    params.state == Parameters::VIDEO_SNAPSHOT)
632a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala            && !restart) {
633a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala        // Succeed attempt to re-enter a streaming state
634a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala        ALOGI("%s: Camera %d: Preview already active, ignoring restart",
635a14be59340219c47639ec77a352d2af362551a6fEino-Ville Talvala                __FUNCTION__, mCameraId);
63677449ada4b5ca73a948aa4fef9aafe3079a66d61Alex Ray        return OK;
63777449ada4b5ca73a948aa4fef9aafe3079a66d61Alex Ray    }
63877449ada4b5ca73a948aa4fef9aafe3079a66d61Alex Ray    if (params.state > Parameters::PREVIEW && !restart) {
6394ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala        ALOGE("%s: Can't start preview in state %s",
6402e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                __FUNCTION__,
6412e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala                Parameters::getStateName(params.state));
6424ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala        return INVALID_OPERATION;
6434ecfec32aca8749baeb634f7c961f804cb1e8f3eEino-Ville Talvala    }
6446db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
64573bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    if (!mStreamingProcessor->haveValidPreviewWindow()) {
6462e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        params.state = Parameters::WAITING_FOR_PREVIEW_WINDOW;
6476db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        return OK;
6486db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
6492e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    params.state = Parameters::STOPPED;
6509cca4c6d976d2d4127286e9eaa54d1b99880c25cEino-Ville Talvala
65173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    res = mStreamingProcessor->updatePreviewStream(params);
652be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala    if (res != OK) {
653be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala        ALOGE("%s: Camera %d: Unable to update preview stream: %s (%d)",
654be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala                __FUNCTION__, mCameraId, strerror(-res), res);
655be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala        return res;
6566db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
65773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala
65873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    Vector<uint8_t> outputStreams;
659228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    bool callbacksEnabled = params.previewCallbackFlags &
660228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK;
661228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    if (callbacksEnabled) {
662d86a6880fe86bda21a9b53b240996fc410a512a5Eino-Ville Talvala        res = mCallbackProcessor->updateStream(params);
663228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        if (res != OK) {
664228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            ALOGE("%s: Camera %d: Unable to update callback stream: %s (%d)",
665228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala                    __FUNCTION__, mCameraId, strerror(-res), res);
666228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            return res;
667228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala        }
66873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        outputStreams.push(getCallbackStreamId());
669228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    }
6705a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala    if (params.zslMode && !params.recordingHint) {
671da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala        res = mZslProcessor->updateStream(params);
672da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala        if (res != OK) {
673da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            ALOGE("%s: Camera %d: Unable to update ZSL stream: %s (%d)",
674da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala                    __FUNCTION__, mCameraId, strerror(-res), res);
675da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala            return res;
676da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala        }
67773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        outputStreams.push(getZslStreamId());
678da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala    }
6796db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
68073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala    outputStreams.push(getPreviewStreamId());
68173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala
6825a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala    if (!params.recordingHint) {
68373bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        if (!restart) {
68473bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            res = mStreamingProcessor->updatePreviewRequest(params);
6855a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala            if (res != OK) {
68673bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                ALOGE("%s: Camera %d: Can't set up preview request: "
68773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                        "%s (%d)", __FUNCTION__, mCameraId,
68873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                        strerror(-res), res);
6895a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala                return res;
6905a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala            }
6915a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala        }
69273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        res = mStreamingProcessor->startStream(StreamingProcessor::PREVIEW,
69373bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                outputStreams);
6945a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala    } else {
6955a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala        // With recording hint set, we're going to be operating under the
6965a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala        // assumption that the user will record video. To optimize recording
6975a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala        // startup time, create the necessary output streams for recording and
6985a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala        // video snapshot now if they don't already exist.
6995a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala        res = mJpegProcessor->updateStream(params);
7005a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala        if (res != OK) {
7015a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala            ALOGE("%s: Camera %d: Can't pre-configure still image "
7025a4f93eaaab7518fd734fdc9f0f686d632f31a59Eino-Ville Talvala                    "stream: %s (%d)",
703be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala                    __FUNCTION__, mCameraId, strerror(-res), res);
704be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala            return res;
705be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala        }
706da6665cbd06ca58d3357c3002b7366d13e23f152Eino-Ville Talvala
70773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        if (!restart) {
70873bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            res = mStreamingProcessor->updateRecordingRequest(params);
70973bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            if (res != OK) {
71073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                ALOGE("%s: Camera %d: Can't set up preview request with "
71173bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                        "record hint: %s (%d)", __FUNCTION__, mCameraId,
71273bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                        strerror(-res), res);
71373bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                return res;
71473bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            }
71573bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        }
71673bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        res = mStreamingProcessor->startStream(StreamingProcessor::RECORD,
71773bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala                outputStreams);
718be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala    }
719be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala    if (res != OK) {
72073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala        ALOGE("%s: Camera %d: Unable to start streaming preview: %s (%d)",
721be0573b93e2d6fa133579c885583af9ed16bc29dEino-Ville Talvala                __FUNCTION__, mCameraId, strerror(-res), res);
7226db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala        return res;
7236db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    }
7246db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala
7252e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    params.state = Parameters::PREVIEW;
7266db981c45a964f0d9df4c3451f064dff7954d78eEino-Ville Talvala    return OK;
72761ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala}
72861ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvala
72961ab9f93315ea817cd1ac110e2a95da4dab6b4d1Eino-Ville Talvalavoid Camera2Client::stopPreview() {
730a189097d0c96fac9afa86e644312ffbb0027b124Eino-Ville Talvala    ATRACE_CALL();
7319e4c3db01ba4eb1e5acbed113f78a31374900df6Eino-Ville Talvala    ALOGV("%s: E", __FUNCTION__);
732ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    Mutex::Autolock icl(mICameraLock);
7333a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    status_t res;
7343a609147811105d40766f8f8f5904bf71cb123cbEino-Ville Talvala    if ( (res = checkPid(__FUNCTION__) ) != OK) return;
73536cdfb185877a7f573621d19ed2b2e1cac13d62eEino-Ville Talvala    stopPreviewL();
736ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala}
737ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala
73836cdfb185877a7f573621d19ed2b2e1cac13d62eEino-Ville Talvalavoid Camera2Client::stopPreviewL() {
739ac45eb3dfa7347f7b8c98be1111b2a5f9e344c46Eino-Ville Talvala    ATRACE_CALL();
7404865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala    status_t res;
741d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala    const nsecs_t kStopCaptureTimeout = 3000000000LL; // 3 seconds
7422e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala    Parameters::State state;
743228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    {
7442e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        SharedParameters::Lock l(mParameters);
7452e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        state = l.mParameters.state;
746228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    }
747228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala
748228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala    switch (state) {
7492e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::DISCONNECTED:
750d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala            ALOGE("%s: Camera %d: Call before initialized",
751d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala                    __FUNCTION__, mCameraId);
752d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala            break;
7532e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STOPPED:
754d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala        case Parameters::VIDEO_SNAPSHOT:
7552e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::STILL_CAPTURE:
756d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala            mCaptureSequencer->waitUntilIdle(kStopCaptureTimeout);
757d5087f91357a9218580596b466926ab750bc8ea7Eino-Ville Talvala            // no break
7582e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::RECORD:
7592e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::PREVIEW:
76073bbd1f1c493835f191ea2b0b72439292496b40aEino-Ville Talvala            mStreamingProcessor->stopStream();
7614865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala            res = mDevice->waitUntilDrained();
7624865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala            if (res != OK) {
7634865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala                ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)",
7644865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala                        __FUNCTION__, mCameraId, strerror(-res), res);
7654865c526e681366481b0ab242ffa1ead57bb02ccEino-Ville Talvala            }
766228a53805808a24cb19fcf13b1f0bdc2ed89bbe1Eino-Ville Talvala            // no break
7672e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala        case Parameters::WAITING_FOR_PREVIEW_WINDOW: {
7682e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala            SharedParameters::Lock l(mParameters);
7692e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala            l.mParameters.state = Parameters::STOPPED;
7702e19c3c02957208371cdd491e6342ea7ddb440d9Eino-Ville Talvala            commandStopFaceDetectionL(l.mParameters);
771d4bcfde6bf3e7b28e36f6ec66e6d9e5adebfa949Eino-Ville Talvala            break;
772