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
200129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang#include <list>
210129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang
227fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/RefBase.h>
237fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/String8.h>
247fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/String16.h>
257fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/Vector.h>
267fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include <utils/Timers.h>
2790e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei#include <utils/List.h>
287fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
297fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include "hardware/camera2.h"
300ea8fa4ccbf9b2b179370b983f3887d3daf2381fZhijun He#include "hardware/camera3.h"
317fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#include "camera/CameraMetadata.h"
32cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei#include "camera/CaptureResult.h"
33618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen#include "gui/IGraphicBufferProducer.h"
34125684aba1a11b7adbf5f9d607ee2bcc9449081cZhijun He#include "device3/Camera3StreamInterface.h"
35d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala#include "binder/Status.h"
367fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
377fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvalanamespace android {
387fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
392f09bac6632a5ee27ee14baa2aa1367f16b5b013Eino-Ville Talvalaclass CameraProviderManager;
402f09bac6632a5ee27ee14baa2aa1367f16b5b013Eino-Ville Talvala
410129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang// Mapping of output stream index to surface ids
420129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wangtypedef std::unordered_map<int, std::vector<size_t> > SurfaceMap;
430129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang
447fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala/**
457fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * Base interface for version >= 2 camera device classes, which interface to
467fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala * camera HAL device versions >= 2.
477fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala */
487fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvalaclass CameraDeviceBase : public virtual RefBase {
497fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala  public:
507fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual ~CameraDeviceBase();
517fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
5271381051e2d048b2705c447b3d59db6e972493eeIgor Murashkin    /**
5371381051e2d048b2705c447b3d59db6e972493eeIgor Murashkin     * The device's camera ID
5471381051e2d048b2705c447b3d59db6e972493eeIgor Murashkin     */
550b1cb14c804d7d4343fe91c78578da8db9a678d5Eino-Ville Talvala    virtual const String8& getId() const = 0;
5671381051e2d048b2705c447b3d59db6e972493eeIgor Murashkin
572f09bac6632a5ee27ee14baa2aa1367f16b5b013Eino-Ville Talvala    virtual status_t initialize(sp<CameraProviderManager> manager) = 0;
587fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t disconnect() = 0;
597fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
60cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t dump(int fd, const Vector<String16> &args) = 0;
617fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
627fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
637fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * The device's static characteristics metadata buffer
647fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
657fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual const CameraMetadata& info() const = 0;
667fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
677fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
687fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Submit request for capture. The CameraDevice takes ownership of the
697fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * passed-in buffer.
70cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the expected frame number of this request.
717fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
72cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) = 0;
737fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
747fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
7590e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei     * Submit a list of requests.
76cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the expected last frame number of the list of requests.
7790e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei     */
78cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t captureList(const List<const CameraMetadata> &requests,
790129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang                                 const std::list<const SurfaceMap> &surfaceMaps,
80cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei                                 int64_t *lastFrameNumber = NULL) = 0;
8190e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei
8290e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei    /**
837fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Submit request for streaming. The CameraDevice makes a copy of the
847fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * passed-in buffer and the caller retains ownership.
85cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the last frame number of the previous streaming request.
867fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
87cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t setStreamingRequest(const CameraMetadata &request,
88cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei                                         int64_t *lastFrameNumber = NULL) = 0;
897fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
907fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
9190e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei     * Submit a list of requests for streaming.
92cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the last frame number of the previous streaming request.
9390e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei     */
94cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests,
950129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang                                             const std::list<const SurfaceMap> &surfaceMaps,
96cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei                                             int64_t *lastFrameNumber = NULL) = 0;
9790e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei
9890e59c98c343e941b1a75307ffa4b4b5f1eb50d6Jianing Wei    /**
997fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Clear the streaming request slot.
100cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the last frame number of the previous streaming request.
1017fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
102cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) = 0;
1037fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1047fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1057fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Wait until a request with the given ID has been dequeued by the
1067fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * HAL. Returns TIMED_OUT if the timeout duration is reached. Returns
1077fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * immediately if the latest request received by the HAL has this id.
1087fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1097fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t waitUntilRequestReceived(int32_t requestId,
1107fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala            nsecs_t timeout) = 0;
1117fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1127fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
113b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh     * Create an output stream of the requested size, format, rotation and dataspace
1147fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     *
1153d82c0d9ed2b3e956ad699a9ca2c8a70c9d24678Eino-Ville Talvala     * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the
1163d82c0d9ed2b3e956ad699a9ca2c8a70c9d24678Eino-Ville Talvala     * logical dimensions of the buffer, not the number of bytes.
1177fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
118727d172137b4f32681c098de8e2623c0b65a6406Eino-Ville Talvala    virtual status_t createStream(sp<Surface> consumer,
1193d82c0d9ed2b3e956ad699a9ca2c8a70c9d24678Eino-Ville Talvala            uint32_t width, uint32_t height, int format,
120125684aba1a11b7adbf5f9d607ee2bcc9449081cZhijun He            android_dataspace dataSpace, camera3_stream_rotation_t rotation, int *id,
1215d677d1f0879d5101e38df480a38228a64d63959Zhijun He            int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID,
122758c215374dba397dabe17b8e96dd38593c09dd7Shuzhen Wang            bool isShared = false, uint32_t consumerUsage = 0) = 0;
1237fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1247fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1250129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang     * Create an output stream of the requested size, format, rotation and
1260129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang     * dataspace with a number of consumers.
1270129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang     *
1280129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang     * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the
1290129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang     * logical dimensions of the buffer, not the number of bytes.
1300129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang     */
1310129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang    virtual status_t createStream(const std::vector<sp<Surface>>& consumers,
1320129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang            bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
1330129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang            android_dataspace dataSpace, camera3_stream_rotation_t rotation, int *id,
1340129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang            int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID,
135758c215374dba397dabe17b8e96dd38593c09dd7Shuzhen Wang            bool isShared = false, uint32_t consumerUsage = 0) = 0;
1360129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang
1370129d52df9794d6fdf06be304722b5cb51a2eab5Shuzhen Wang    /**
138618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen     * Create an input stream of width, height, and format.
139618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen     *
140618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen     * Return value is the stream ID if non-negative and an error if negative.
141618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen     */
142618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen    virtual status_t createInputStream(uint32_t width, uint32_t height,
143618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen            int32_t format, /*out*/ int32_t *id) = 0;
144618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen
145618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen    /**
1467fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Get information about a given stream.
1477fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1487fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t getStreamInfo(int id,
149d46a6b9fd8b2a4f9098757384711e2cd03a91651Eino-Ville Talvala            uint32_t *width, uint32_t *height,
150d46a6b9fd8b2a4f9098757384711e2cd03a91651Eino-Ville Talvala            uint32_t *format, android_dataspace *dataSpace) = 0;
1517fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1527fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1537fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Set stream gralloc buffer transform
1547fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1557fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t setStreamTransform(int id, int transform) = 0;
1567fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1577fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1587fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Delete stream. Must not be called if there are requests in flight which
1597fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * reference that stream.
1607fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1617fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t deleteStream(int id) = 0;
1627fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1637fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
164e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * Take the currently-defined set of streams and configure the HAL to use
165e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * them. This is a long-running operation (may be several hundered ms).
166e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     *
167e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * The device must be idle (see waitUntilDrained) before calling this.
168e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     *
169e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * Returns OK on success; otherwise on error:
170e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * - BAD_VALUE if the set of streams was invalid (e.g. fmts or sizes)
171e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     * - INVALID_OPERATION if the device was in the wrong state
172e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin     */
173bbbbe84b3a7296c9c3266bb16e0dc98b11cb5939Eino-Ville Talvala    virtual status_t configureStreams(int operatingMode = 0) = 0;
174e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin
175618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen    // get the buffer producer of the input stream
176618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen    virtual status_t getInputBufferProducer(
177618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen            sp<IGraphicBufferProducer> *producer) = 0;
178618ff8a48a0c895a78f91f5692510c2a809425c3Chien-Yu Chen
179e2d167eb689d7a536805f950c31f11b9e9c578aeIgor Murashkin    /**
1807fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Create a metadata buffer with fields that the HAL device believes are
1817fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * best for the given use case
1827fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1837fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t createDefaultRequest(int templateId,
1847fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala            CameraMetadata *request) = 0;
1857fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1867fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
1877fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Wait until all requests have been processed. Returns INVALID_OPERATION if
1887fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * the streaming slot is not empty, or TIMED_OUT if the requests haven't
1897fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * finished processing in 10 seconds.
1907fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
1917fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t waitUntilDrained() = 0;
1927fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
1937fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
19428c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He     * Get Jpeg buffer size for a given jpeg resolution.
19528c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He     * Negative values are error codes.
19628c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He     */
19728c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He    virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const = 0;
19828c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He
19928c9b6f298134624cb52b1af4ed8716dddb983d3Zhijun He    /**
2007fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Abstract class for HAL notification listeners
2017fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
202e1c8063521b0645b091b080d896106b2e6fd8670Yin-Chia Yeh    class NotificationListener : public virtual RefBase {
2037fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala      public:
204f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // The set of notifications is a merge of the notifications required for
205f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // API1 and API2.
206f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala
207f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // Required for API 1 and 2
208d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala        virtual void notifyError(int32_t errorCode,
209cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei                                 const CaptureResultExtras &resultExtras) = 0;
210f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala
211f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // Required only for API2
212f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        virtual void notifyIdle() = 0;
213cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        virtual void notifyShutter(const CaptureResultExtras &resultExtras,
214f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala                nsecs_t timestamp) = 0;
2154d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala        virtual void notifyPrepared(int streamId) = 0;
2169d06601e54848f076b7472a376c672215cd70c46Shuzhen Wang        virtual void notifyRequestQueueEmpty() = 0;
217f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala
218f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala        // Required only for API1
2197fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala        virtual void notifyAutoFocus(uint8_t newState, int triggerId) = 0;
2207fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala        virtual void notifyAutoExposure(uint8_t newState, int triggerId) = 0;
2217fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala        virtual void notifyAutoWhitebalance(uint8_t newState,
2227fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala                int triggerId) = 0;
223e8c535e833ed135895e99ca81aa3b85d80d7cf3cChien-Yu Chen        virtual void notifyRepeatingRequestError(long lastFrameNumber) = 0;
2247fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala      protected:
2257fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala        virtual ~NotificationListener();
2267fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    };
2277fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2287fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2297fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Connect HAL notifications to a listener. Overwrites previous
2307fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * listener. Set to NULL to stop receiving notifications.
2317fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
232e1c8063521b0645b091b080d896106b2e6fd8670Yin-Chia Yeh    virtual status_t setNotifyCallback(wp<NotificationListener> listener) = 0;
2337fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2347fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
23546910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala     * Whether the device supports calling notifyAutofocus, notifyAutoExposure,
23646910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala     * and notifyAutoWhitebalance; if this returns false, the client must
23746910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala     * synthesize these notifications from received frame metadata.
23846910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala     */
23946910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala    virtual bool     willNotify3A() = 0;
24046910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala
24146910bdc57c35ac36bd4adcbb76f4f3a590e3f21Eino-Ville Talvala    /**
2427fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Wait for a new frame to be produced, with timeout in nanoseconds.
2437fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Returns TIMED_OUT when no frame produced within the specified duration
244f1e98d857ec377f2c9b916073d40732e6ebb7cedEino-Ville Talvala     * May be called concurrently to most methods, except for getNextFrame
2457fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2467fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t waitForNextFrame(nsecs_t timeout) = 0;
2477fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2487fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
249cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Get next capture result frame from the result queue. Returns NOT_ENOUGH_DATA
250cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * if the queue is empty; caller takes ownership of the metadata buffer inside
251cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * the capture result object's metadata field.
252cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * May be called concurrently to most methods, except for waitForNextFrame.
2537fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
254cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t getNextResult(CaptureResult *frame) = 0;
2557fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2567fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2577fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel
2587fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * autofocus call will be returned by the HAL in all subsequent AF
2597fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * notifications.
2607fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2617fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t triggerAutofocus(uint32_t id) = 0;
2627fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2637fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2647fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel
2657fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * autofocus call will be returned by the HAL in all subsequent AF
2667fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * notifications.
2677fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2687fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t triggerCancelAutofocus(uint32_t id) = 0;
2697fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2707fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
2717fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * Trigger pre-capture metering. The latest ID used in a trigger pre-capture
2727fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * call will be returned by the HAL in all subsequent AE and AWB
2737fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     * notifications.
2747fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala     */
2757fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    virtual status_t triggerPrecaptureMetering(uint32_t id) = 0;
2767fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
2777fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala    /**
278abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala     * Flush all pending and in-flight requests. Blocks until flush is
279abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala     * complete.
280cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei     * Output lastFrameNumber is the last frame number of the previous streaming request.
281abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala     */
282cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    virtual status_t flush(int64_t *lastFrameNumber = NULL) = 0;
283abaa51d3ca31f0eda99e1d271e6dc64c877dbf58Eino-Ville Talvala
284204e3295e2814052aef7e45ee9edd60128efbbd0Zhijun He    /**
2854d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala     * Prepare stream by preallocating buffers for it asynchronously.
2864d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala     * Calls notifyPrepared() once allocation is complete.
2874d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala     */
2884d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala    virtual status_t prepare(int streamId) = 0;
2894d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala
2904d44cad22ea925a651463f2d51d6586c14d4b787Eino-Ville Talvala    /**
291b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala     * Free stream resources by dumping its unused gralloc buffers.
292b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala     */
293b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala    virtual status_t tearDown(int streamId) = 0;
294b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala
295b25e3c87724b6147ed1da7c1d6617c39bfce2fbfEino-Ville Talvala    /**
296b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang     * Add buffer listener for a particular stream in the device.
297b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang     */
298b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang    virtual status_t addBufferListenerForStream(int streamId,
299b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang            wp<camera3::Camera3StreamBufferListener> listener) = 0;
300b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang
301b0fdc1ed2182fe851ef7ca98a1b4a552b53b3033Shuzhen Wang    /**
302c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk     * Prepare stream by preallocating up to maxCount buffers for it asynchronously.
303c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk     * Calls notifyPrepared() once allocation is complete.
304c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk     */
305c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk    virtual status_t prepare(int maxCount, int streamId) = 0;
306c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk
307c78ac26e3a65328fc0118f16ee76a800d0687eb7Ruben Brunk    /**
3085d677d1f0879d5101e38df480a38228a64d63959Zhijun He     * Set the deferred consumer surface and finish the rest of the stream configuration.
3095d677d1f0879d5101e38df480a38228a64d63959Zhijun He     */
310758c215374dba397dabe17b8e96dd38593c09dd7Shuzhen Wang    virtual status_t setConsumerSurfaces(int streamId,
311758c215374dba397dabe17b8e96dd38593c09dd7Shuzhen Wang            const std::vector<sp<Surface>>& consumers) = 0;
3125d677d1f0879d5101e38df480a38228a64d63959Zhijun He
3137fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala};
3147fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
3157fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala}; // namespace android
3167fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala
3177fa43f376ebd63fda24d85c9ebf97e0ddf534083Eino-Ville Talvala#endif
318