17fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala/*
27fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * Copyright (C) 2013 The Android Open Source Project
37fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala *
47fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * Licensed under the Apache License, Version 2.0 (the "License");
57fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * you may not use this file except in compliance with the License.
67fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * You may obtain a copy of the License at
77fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala *
87fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala *      http://www.apache.org/licenses/LICENSE-2.0
97fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala *
107fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * Unless required by applicable law or agreed to in writing, software
117fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * distributed under the License is distributed on an "AS IS" BASIS,
127fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * See the License for the specific language governing permissions and
147fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * limitations under the License.
157fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala */
167fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
177fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#ifndef ANDROID_SERVERS_CAMERA_CAMERADEVICEBASE_H
187fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#define ANDROID_SERVERS_CAMERA_CAMERADEVICEBASE_H
197fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
207fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/RefBase.h>
217fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/String8.h>
227fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/String16.h>
237fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/Vector.h>
247fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/Timers.h>
2590e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei#include <utils/List.h>
267fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
277fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include "hardware/camera2.h"
280ea8fa4ccbf9b2b179370b983f3887d3daf2381fZhijun He#include "hardware/camera3.h"
297fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include "camera/CameraMetadata.h"
30cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei#include "camera/CaptureResult.h"
31e074a93046ebe5cea0b55c3a479e082a426e1e07Yin-Chia Yeh#include "common/CameraModule.h"
32618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen#include "gui/IGraphicBufferProducer.h"
33125684aba1a11b7adbf5f9d607ee2bcc9449081cZhijun He#include "device3/Camera3StreamInterface.h"
34d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala#include "binder/Status.h"
357fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
367fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvalanamespace android {
377fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
387fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala/**
397fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * Base interface for version >= 2 camera device classes, which interface to
407fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * camera HAL device versions >= 2.
417fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala */
427fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvalaclass CameraDeviceBase : public virtual RefBase {
437fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala  public:
447fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual ~CameraDeviceBase();
457fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
4671381051e2d048b2705c447b3d59db6e972493eeIgor Murashkin    /**
4771381051e2d048b2705c447b3d59db6e972493eeIgor Murashkin     * The device's camera ID
4871381051e2d048b2705c447b3d59db6e972493eeIgor Murashkin     */
4971381051e2d048b2705c447b3d59db6e972493eeIgor Murashkin    virtual int      getId() const = 0;
5071381051e2d048b2705c447b3d59db6e972493eeIgor Murashkin
51e074a93046ebe5cea0b55c3a479e082a426e1e07Yin-Chia Yeh    virtual status_t initialize(CameraModule *module) = 0;
527fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t disconnect() = 0;
537fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
54cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t dump(int fd, const Vector<String16> &args) = 0;
557fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
567fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
577fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * The device's static characteristics metadata buffer
587fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
597fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual const CameraMetadata& info() const = 0;
607fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
617fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
627fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Submit request for capture. The CameraDevice takes ownership of the
637fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * passed-in buffer.
64cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the expected frame number of this request.
657fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
66cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) = 0;
677fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
687fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
6990e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei     * Submit a list of requests.
70cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the expected last frame number of the list of requests.
7190e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei     */
72cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t captureList(const List<const CameraMetadata> &requests,
73cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei                                 int64_t *lastFrameNumber = NULL) = 0;
7490e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei
7590e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei    /**
767fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Submit request for streaming. The CameraDevice makes a copy of the
777fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * passed-in buffer and the caller retains ownership.
78cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the last frame number of the previous streaming request.
797fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
80cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t setStreamingRequest(const CameraMetadata &request,
81cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei                                         int64_t *lastFrameNumber = NULL) = 0;
827fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
837fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
8490e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei     * Submit a list of requests for streaming.
85cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the last frame number of the previous streaming request.
8690e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei     */
87cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests,
88cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei                                             int64_t *lastFrameNumber = NULL) = 0;
8990e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei
9090e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei    /**
917fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Clear the streaming request slot.
92cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the last frame number of the previous streaming request.
937fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
94cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) = 0;
957fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
967fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
977fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Wait until a request with the given ID has been dequeued by the
987fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * HAL. Returns TIMED_OUT if the timeout duration is reached. Returns
997fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * immediately if the latest request received by the HAL has this id.
1007fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1017fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t waitUntilRequestReceived(int32_t requestId,
1027fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala            nsecs_t timeout) = 0;
1037fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1047fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
105b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh     * Create an output stream of the requested size, format, rotation and dataspace
1067fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     *
1073d82c0d9ed2b3e956ad699a9ca2c8a70c9d24678Eino-Ville Talvala     * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the
1083d82c0d9ed2b3e956ad699a9ca2c8a70c9d24678Eino-Ville Talvala     * logical dimensions of the buffer, not the number of bytes.
1097fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
110727d172137b4f32681c098de8e2623c0b65a6406Eino-Ville Talvala    virtual status_t createStream(sp<Surface> consumer,
1113d82c0d9ed2b3e956ad699a9ca2c8a70c9d24678Eino-Ville Talvala            uint32_t width, uint32_t height, int format,
112125684aba1a11b7adbf5f9d607ee2bcc9449081cZhijun He            android_dataspace dataSpace, camera3_stream_rotation_t rotation, int *id,
113125684aba1a11b7adbf5f9d607ee2bcc9449081cZhijun He            int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID) = 0;
1147fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1157fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
116618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen     * Create an input stream of width, height, and format.
117618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen     *
118618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen     * Return value is the stream ID if non-negative and an error if negative.
119618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen     */
120618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen    virtual status_t createInputStream(uint32_t width, uint32_t height,
121618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen            int32_t format, /*out*/ int32_t *id) = 0;
122618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen
123618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen    /**
1247fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Create an input reprocess stream that uses buffers from an existing
1257fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * output stream.
1267fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1277fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t createReprocessStreamFromStream(int outputId, int *id) = 0;
1287fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1297fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1307fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Get information about a given stream.
1317fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1327fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t getStreamInfo(int id,
133d46a6b9fd8b2a4f9098757384711e2cd03a91651Eino-Ville Talvala            uint32_t *width, uint32_t *height,
134d46a6b9fd8b2a4f9098757384711e2cd03a91651Eino-Ville Talvala            uint32_t *format, android_dataspace *dataSpace) = 0;
1357fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1367fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1377fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Set stream gralloc buffer transform
1387fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1397fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t setStreamTransform(int id, int transform) = 0;
1407fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1417fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1427fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Delete stream. Must not be called if there are requests in flight which
1437fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * reference that stream.
1447fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1457fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t deleteStream(int id) = 0;
1467fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1477fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1487fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Delete reprocess stream. Must not be called if there are requests in
1497fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * flight which reference that stream.
1507fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1517fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t deleteReprocessStream(int id) = 0;
1527fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1537fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
154e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * Take the currently-defined set of streams and configure the HAL to use
155e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * them. This is a long-running operation (may be several hundered ms).
156e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     *
157e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * The device must be idle (see waitUntilDrained) before calling this.
158e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     *
159e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * Returns OK on success; otherwise on error:
160e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * - BAD_VALUE if the set of streams was invalid (e.g. fmts or sizes)
161e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * - INVALID_OPERATION if the device was in the wrong state
162e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     */
1631fa8999c91d5df81949aa723000058380cd3faa2Zhijun He    virtual status_t configureStreams(bool isConstrainedHighSpeed = false) = 0;
164e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin
165618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen    // get the buffer producer of the input stream
166618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen    virtual status_t getInputBufferProducer(
167618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen            sp<IGraphicBufferProducer> *producer) = 0;
168618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen
169e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin    /**
1707fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Create a metadata buffer with fields that the HAL device believes are
1717fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * best for the given use case
1727fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1737fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t createDefaultRequest(int templateId,
1747fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala            CameraMetadata *request) = 0;
1757fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1767fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1777fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Wait until all requests have been processed. Returns INVALID_OPERATION if
1787fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * the streaming slot is not empty, or TIMED_OUT if the requests haven't
1797fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * finished processing in 10 seconds.
1807fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1817fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t waitUntilDrained() = 0;
1827fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1837fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
18428c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He     * Get Jpeg buffer size for a given jpeg resolution.
18528c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He     * Negative values are error codes.
18628c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He     */
18728c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He    virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const = 0;
18828c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He
18928c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He    /**
1907fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Abstract class for HAL notification listeners
1917fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1927fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    class NotificationListener {
1937fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala      public:
194f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // The set of notifications is a merge of the notifications required for
195f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // API1 and API2.
196f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala
197f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // Required for API 1 and 2
198d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala        virtual void notifyError(int32_t errorCode,
199cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei                                 const CaptureResultExtras &resultExtras) = 0;
200f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala
201f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // Required only for API2
202f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        virtual void notifyIdle() = 0;
203cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        virtual void notifyShutter(const CaptureResultExtras &resultExtras,
204f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala                nsecs_t timestamp) = 0;
2054d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala        virtual void notifyPrepared(int streamId) = 0;
206f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala
207f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // Required only for API1
2087fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala        virtual void notifyAutoFocus(uint8_t newState, int triggerId) = 0;
2097fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala        virtual void notifyAutoExposure(uint8_t newState, int triggerId) = 0;
2107fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala        virtual void notifyAutoWhitebalance(uint8_t newState,
2117fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala                int triggerId) = 0;
212e8c535e833ed135895e99ca81aa3b85d80d7cf3cChien-Yu Chen        virtual void notifyRepeatingRequestError(long lastFrameNumber) = 0;
2137fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala      protected:
2147fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala        virtual ~NotificationListener();
2157fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    };
2167fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2177fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2187fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Connect HAL notifications to a listener. Overwrites previous
2197fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * listener. Set to NULL to stop receiving notifications.
2207fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2217fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t setNotifyCallback(NotificationListener *listener) = 0;
2227fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2237fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
22446910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala     * Whether the device supports calling notifyAutofocus, notifyAutoExposure,
22546910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala     * and notifyAutoWhitebalance; if this returns false, the client must
22646910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala     * synthesize these notifications from received frame metadata.
22746910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala     */
22846910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala    virtual bool     willNotify3A() = 0;
22946910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala
23046910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala    /**
2317fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Wait for a new frame to be produced, with timeout in nanoseconds.
2327fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Returns TIMED_OUT when no frame produced within the specified duration
233f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala     * May be called concurrently to most methods, except for getNextFrame
2347fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2357fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t waitForNextFrame(nsecs_t timeout) = 0;
2367fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2377fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
238cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Get next capture result frame from the result queue. Returns NOT_ENOUGH_DATA
239cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * if the queue is empty; caller takes ownership of the metadata buffer inside
240cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * the capture result object's metadata field.
241cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * May be called concurrently to most methods, except for waitForNextFrame.
2427fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
243cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t getNextResult(CaptureResult *frame) = 0;
2447fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2457fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2467fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel
2477fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * autofocus call will be returned by the HAL in all subsequent AF
2487fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * notifications.
2497fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2507fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t triggerAutofocus(uint32_t id) = 0;
2517fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2527fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2537fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel
2547fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * autofocus call will be returned by the HAL in all subsequent AF
2557fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * notifications.
2567fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2577fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t triggerCancelAutofocus(uint32_t id) = 0;
2587fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2597fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2607fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Trigger pre-capture metering. The latest ID used in a trigger pre-capture
2617fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * call will be returned by the HAL in all subsequent AE and AWB
2627fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * notifications.
2637fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2647fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t triggerPrecaptureMetering(uint32_t id) = 0;
2657fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2667fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2677fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Abstract interface for clients that want to listen to reprocess buffer
2687fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * release events
2697fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2707fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    struct BufferReleasedListener : public virtual RefBase {
2717fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala        virtual void onBufferReleased(buffer_handle_t *handle) = 0;
2727fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    };
2737fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2747fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2757fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Push a buffer to be reprocessed into a reprocessing stream, and
2767fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * provide a listener to call once the buffer is returned by the HAL
2777fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2787fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t pushReprocessBuffer(int reprocessStreamId,
2797fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala            buffer_handle_t *buffer, wp<BufferReleasedListener> listener) = 0;
280abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala
281abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala    /**
282abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala     * Flush all pending and in-flight requests. Blocks until flush is
283abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala     * complete.
284cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the last frame number of the previous streaming request.
285abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala     */
286cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t flush(int64_t *lastFrameNumber = NULL) = 0;
287abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala
288204e3295e2814052aef7e45ee9edd60128efbbd0Zhijun He    /**
2894d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala     * Prepare stream by preallocating buffers for it asynchronously.
2904d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala     * Calls notifyPrepared() once allocation is complete.
2914d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala     */
2924d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala    virtual status_t prepare(int streamId) = 0;
2934d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala
2944d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala    /**
295b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala     * Free stream resources by dumping its unused gralloc buffers.
296b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala     */
297b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala    virtual status_t tearDown(int streamId) = 0;
298b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala
299b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala    /**
300b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang     * Add buffer listener for a particular stream in the device.
301b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang     */
302b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang    virtual status_t addBufferListenerForStream(int streamId,
303b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang            wp<camera3::Camera3StreamBufferListener> listener) = 0;
304b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang
305b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang    /**
306c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk     * Prepare stream by preallocating up to maxCount buffers for it asynchronously.
307c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk     * Calls notifyPrepared() once allocation is complete.
308c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk     */
309c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk    virtual status_t prepare(int maxCount, int streamId) = 0;
310c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk
311c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk    /**
312204e3295e2814052aef7e45ee9edd60128efbbd0Zhijun He     * Get the HAL device version.
313204e3295e2814052aef7e45ee9edd60128efbbd0Zhijun He     */
314204e3295e2814052aef7e45ee9edd60128efbbd0Zhijun He    virtual uint32_t getDeviceVersion() = 0;
3157fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala};
3167fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
3177fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala}; // namespace android
3187fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
3197fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#endif
320