Camera3Stream.h revision f0d962a6737eb8eec002d6804d9ffbe7bee672a0
19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Copyright (C) 2013 The Android Open Source Project 39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License"); 59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License. 69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at 79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software 119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and 149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License. 159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#ifndef ANDROID_SERVERS_CAMERA3_STREAM_H 189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#define ANDROID_SERVERS_CAMERA3_STREAM_H 199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include <gui/Surface.h> 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include <utils/RefBase.h> 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include <utils/String8.h> 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include <utils/String16.h> 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include <utils/List.h> 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include "hardware/camera3.h" 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include "Camera3StreamBufferListener.h" 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson#include "Camera3StreamInterface.h" 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonnamespace android { 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonnamespace camera3 { 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * A class for managing a single stream of input or output data from the camera 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * device. 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The stream has an internal state machine to track whether it's 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * connected/configured/etc. 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * States: 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_ERROR: A serious error has occurred, stream is unusable. Outstanding 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * buffers may still be returned. 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_CONSTRUCTED: The stream is ready for configuration, but buffers cannot 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * be gotten yet. Not connected to any endpoint, no buffers are registered 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * with the HAL. 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_IN_CONFIG: Configuration has started, but not yet concluded. During this 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * time, the usage, max_buffers, and priv fields of camera3_stream returned by 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * startConfiguration() may be modified. 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_IN_RE_CONFIG: Configuration has started, and the stream has been 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * configured before. Need to track separately from IN_CONFIG to avoid 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * re-registering buffers with HAL. 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_CONFIGURED: Stream is configured, and has registered buffers with the 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * HAL. The stream's getBuffer/returnBuffer work. The priv pointer may still be 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * modified. 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Transition table: 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <none> => STATE_CONSTRUCTED: 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When constructed with valid arguments 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <none> => STATE_ERROR: 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When constructed with invalid arguments 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_CONSTRUCTED => STATE_IN_CONFIG: 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When startConfiguration() is called 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_IN_CONFIG => STATE_CONFIGURED: 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When finishConfiguration() is called 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_IN_CONFIG => STATE_ERROR: 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When finishConfiguration() fails to allocate or register buffers. 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_CONFIGURED => STATE_IN_RE_CONFIG: * 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When startConfiguration() is called again, after making sure stream is 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * idle with waitUntilIdle(). 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_IN_RE_CONFIG => STATE_CONFIGURED: 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When finishConfiguration() is called. 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_IN_RE_CONFIG => STATE_ERROR: 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When finishConfiguration() fails to allocate or register buffers. 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * STATE_CONFIGURED => STATE_CONSTRUCTED: 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When disconnect() is called after making sure stream is idle with 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * waitUntilIdle(). 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Status Tracking: 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Each stream is tracked by StatusTracker as a separate component, 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * depending on the handed out buffer count. The state must be STATE_CONFIGURED 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in order for the component to be marked. 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * It's marked in one of two ways: 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * - ACTIVE: One or more buffers have been handed out (with #getBuffer). 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * - IDLE: All buffers have been returned (with #returnBuffer), and their 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * respective release_fence(s) have been signaled. 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * A typical use case is output streams. When the HAL has any buffers 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * dequeued, the stream is marked ACTIVE. When the HAL returns all buffers 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * (e.g. if no capture requests are active), the stream is marked IDLE. 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * In this use case, the app consumer does not affect the component status. 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonclass Camera3Stream : 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected camera3_stream, 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public virtual Camera3StreamInterface, 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public virtual RefBase { 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public: 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson virtual ~Camera3Stream(); 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static Camera3Stream* cast(camera3_stream *stream); 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static const Camera3Stream* cast(const camera3_stream *stream); 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the stream's ID 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int getId() const; 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the stream's dimensions and format 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson uint32_t getWidth() const; 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson uint32_t getHeight() const; 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int getFormat() const; 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Start the stream configuration process. Returns a handle to the stream's 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * information to be passed into the HAL device's configure_streams call. 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Until finishConfiguration() is called, no other methods on the stream may be 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * called. The usage and max_buffers fields of camera3_stream may be modified 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * between start/finishConfiguration, but may not be changed after that. 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The priv field of camera3_stream may be modified at any time after 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * startConfiguration. 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns NULL in case of error starting configuration. 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson camera3_stream* startConfiguration(); 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Check if the stream is mid-configuration (start has been called, but not 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * finish). Used for lazy completion of configuration. 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson bool isConfiguring() const; 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Completes the stream configuration process. During this call, the stream 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * may call the device's register_stream_buffers() method. The stream 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * information structure returned by startConfiguration() may no longer be 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * modified after this call, but can still be read until the destruction of 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the stream. 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns: 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * OK on a successful configuration 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NO_INIT in case of a serious error from the HAL device 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NO_MEMORY in case of an error registering buffers 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * INVALID_OPERATION in case connecting to the consumer failed 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson status_t finishConfiguration(camera3_device *hal3Device); 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Fill in the camera3_stream_buffer with the next valid buffer for this 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * stream, to hand over to the HAL. 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This method may only be called once finishConfiguration has been called. 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * For bidirectional streams, this method applies to the output-side 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * buffers. 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson status_t getBuffer(camera3_stream_buffer *buffer); 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return a buffer to the stream after use by the HAL. 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This method may only be called for buffers provided by getBuffer(). 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * For bidirectional streams, this method applies to the output-side buffers 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson status_t returnBuffer(const camera3_stream_buffer &buffer, 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson nsecs_t timestamp); 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Fill in the camera3_stream_buffer with the next valid buffer for this 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * stream, to hand over to the HAL. 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This method may only be called once finishConfiguration has been called. 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * For bidirectional streams, this method applies to the input-side 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * buffers. 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson status_t getInputBuffer(camera3_stream_buffer *buffer); 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return a buffer to the stream after use by the HAL. 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This method may only be called for buffers provided by getBuffer(). 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * For bidirectional streams, this method applies to the input-side buffers 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson status_t returnInputBuffer(const camera3_stream_buffer &buffer); 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Whether any of the stream's buffers are currently in use by the HAL, 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * including buffers that have been returned but not yet had their 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * release fence signaled. 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson bool hasOutstandingBuffers() const; 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson enum { 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson TIMEOUT_NEVER = -1 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson }; 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the status tracker to notify about idle transitions 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson virtual status_t setStatusTracker(sp<StatusTracker> statusTracker); 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Disconnect stream from its non-HAL endpoint. After this, 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * start/finishConfiguration must be called before the stream can be used 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * again. This cannot be called if the stream has outstanding dequeued 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * buffers. 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson status_t disconnect(); 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Debug dump of the stream's state. 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson virtual void dump(int fd, const Vector<String16> &args) const = 0; 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Add a camera3 buffer listener. Adding the same listener twice has 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * no effect. 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void addBufferListener( 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson wp<Camera3StreamBufferListener> listener); 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Remove a camera3 buffer listener. Removing the same listener twice 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or the listener that was never added has no effect. 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson void removeBufferListener( 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson const sp<Camera3StreamBufferListener>& listener); 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson protected: 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson const int mId; 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson const String8 mName; 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Zero for formats with fixed buffer size for given dimensions. 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson const size_t mMaxSize; 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson enum { 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson STATE_ERROR, 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson STATE_CONSTRUCTED, 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson STATE_IN_CONFIG, 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson STATE_IN_RECONFIG, 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson STATE_CONFIGURED 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } mState; 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson mutable Mutex mLock; 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Camera3Stream(int id, camera3_stream_type type, 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson uint32_t width, uint32_t height, size_t maxSize, int format); 261 262 /** 263 * Interface to be implemented by derived classes 264 */ 265 266 // getBuffer / returnBuffer implementations 267 268 // Since camera3_stream_buffer includes a raw pointer to the stream, 269 // cast to camera3_stream*, implementations must increment the 270 // refcount of the stream manually in getBufferLocked, and decrement it in 271 // returnBufferLocked. 272 virtual status_t getBufferLocked(camera3_stream_buffer *buffer); 273 virtual status_t returnBufferLocked(const camera3_stream_buffer &buffer, 274 nsecs_t timestamp); 275 virtual status_t getInputBufferLocked(camera3_stream_buffer *buffer); 276 virtual status_t returnInputBufferLocked( 277 const camera3_stream_buffer &buffer); 278 virtual bool hasOutstandingBuffersLocked() const = 0; 279 // Can return -ENOTCONN when we are already disconnected (not an error) 280 virtual status_t disconnectLocked() = 0; 281 282 // Configure the buffer queue interface to the other end of the stream, 283 // after the HAL has provided usage and max_buffers values. After this call, 284 // the stream must be ready to produce all buffers for registration with 285 // HAL. 286 virtual status_t configureQueueLocked() = 0; 287 288 // Get the total number of buffers in the queue 289 virtual size_t getBufferCountLocked() = 0; 290 291 // Get handout output buffer count. 292 virtual size_t getHandoutOutputBufferCountLocked() = 0; 293 294 // Get handout input buffer count. 295 virtual size_t getHandoutInputBufferCountLocked() = 0; 296 297 // Get the usage flags for the other endpoint, or return 298 // INVALID_OPERATION if they cannot be obtained. 299 virtual status_t getEndpointUsage(uint32_t *usage) = 0; 300 301 // Tracking for idle state 302 wp<StatusTracker> mStatusTracker; 303 // Status tracker component ID 304 int mStatusId; 305 306 private: 307 uint32_t oldUsage; 308 uint32_t oldMaxBuffers; 309 Condition mOutputBufferReturnedSignal; 310 Condition mInputBufferReturnedSignal; 311 static const nsecs_t kWaitForBufferDuration = 3000000000LL; // 3000 ms 312 313 // Gets all buffers from endpoint and registers them with the HAL. 314 status_t registerBuffersLocked(camera3_device *hal3Device); 315 316 void fireBufferListenersLocked(const camera3_stream_buffer& buffer, 317 bool acquired, bool output); 318 List<wp<Camera3StreamBufferListener> > mBufferListenerList; 319 320}; // class Camera3Stream 321 322}; // namespace camera3 323 324}; // namespace android 325 326#endif 327