1a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian/* 2a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * Copyright (C) 2013 The Android Open Source Project 3a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * 4a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * you may not use this file except in compliance with the License. 6a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * You may obtain a copy of the License at 7a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * 8a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * 10a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * Unless required by applicable law or agreed to in writing, software 11a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * See the License for the specific language governing permissions and 14a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * limitations under the License. 15a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian */ 16a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 177a63e83b303c550156e29eaabf437d174fae4dccDan Stoza#pragma once 18e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza 19e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza#include <binder/IInterface.h> 207a63e83b303c550156e29eaabf437d174fae4dccDan Stoza#include <binder/SafeInterface.h> 21a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 22a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#include <utils/Errors.h> 23a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#include <utils/RefBase.h> 24a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 257a63e83b303c550156e29eaabf437d174fae4dccDan Stoza#include <cstdint> 26ce796e78a57018f186b062199c75d94545318acaPablo Ceballos 27a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopiannamespace android { 28a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 298dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stozaclass BufferItem; 307a63e83b303c550156e29eaabf437d174fae4dccDan Stozaclass FrameEventHistoryDelta; 317a63e83b303c550156e29eaabf437d174fae4dccDan Stozastruct NewFrameEventsEntry; 328dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza 33e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza// ConsumerListener is the interface through which the BufferQueue notifies the consumer of events 34e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza// that the consumer may wish to react to. Because the consumer will generally have a mutex that is 35e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza// locked during calls from the consumer to the BufferQueue, these calls from the BufferQueue to the 36a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// consumer *MUST* be called only when the BufferQueue mutex is NOT locked. 37a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 38a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianclass ConsumerListener : public virtual RefBase { 39a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianpublic: 40e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza ConsumerListener() {} 4197b64dbe717b7daf29962f44c1b621c633473556Colin Cross virtual ~ConsumerListener(); 42a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 435ea5e5905170f32d5cf45ad35c552d64743892c3Brian Anderson // onDisconnect is called when a producer disconnects from the BufferQueue. 445ea5e5905170f32d5cf45ad35c552d64743892c3Brian Anderson virtual void onDisconnect() {} /* Asynchronous */ 455ea5e5905170f32d5cf45ad35c552d64743892c3Brian Anderson 46e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // onFrameAvailable is called from queueBuffer each time an additional frame becomes available 47e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // for consumption. This means that frames that are queued while in asynchronous mode only 48e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // trigger the callback if no previous frames are pending. Frames queued while in synchronous 49e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // mode always trigger the callback. The item passed to the callback will contain all of the 50e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // information about the queued frame except for its GraphicBuffer pointer, which will always be 51e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // null (except if the consumer is SurfaceFlinger). 528dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // 53e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // This is called without any lock held and can be called concurrently by multiple threads. 548dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza virtual void onFrameAvailable(const BufferItem& item) = 0; /* Asynchronous */ 558dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza 56e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // onFrameReplaced is called from queueBuffer if the frame being queued is replacing an existing 57e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // slot in the queue. Any call to queueBuffer that doesn't call onFrameAvailable will call this 58e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // callback instead. The item passed to the callback will contain all of the information about 59e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // the queued frame except for its GraphicBuffer pointer, which will always be null. 60a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // 61e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // This is called without any lock held and can be called concurrently by multiple threads. 62a32900deec6284973100a29f7b399d061f82b3a8Andreas Gampe virtual void onFrameReplaced(const BufferItem& /* item */) {} /* Asynchronous */ 63a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 64e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // onBuffersReleased is called to notify the buffer consumer that the BufferQueue has released 65e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // its references to one or more GraphicBuffers contained in its slots. The buffer consumer 66e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // should then call BufferQueue::getReleasedBuffers to retrieve the list of buffers. 67a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // 68e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // This is called without any lock held and can be called concurrently by multiple threads. 69a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian virtual void onBuffersReleased() = 0; /* Asynchronous */ 70399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall 71e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // onSidebandStreamChanged is called to notify the buffer consumer that the BufferQueue's 72e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // sideband buffer stream has changed. This is called when a stream is first attached and when 73e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // it is either detached or replaced by a different stream. 74399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall virtual void onSidebandStreamChanged() = 0; /* Asynchronous */ 75ce796e78a57018f186b062199c75d94545318acaPablo Ceballos 76e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // Notifies the consumer of any new producer-side timestamps and returns the combined frame 77e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza // history that hasn't already been retrieved. 787a63e83b303c550156e29eaabf437d174fae4dccDan Stoza // 797a63e83b303c550156e29eaabf437d174fae4dccDan Stoza // WARNING: This method can only be called when the BufferQueue is in the consumer's process. 80e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza virtual void addAndGetFrameTimestamps(const NewFrameEventsEntry* /*newTimestamps*/, 81e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza FrameEventHistoryDelta* /*outDelta*/) {} 82a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian}; 83a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 84e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stozaclass IConsumerListener : public ConsumerListener, public IInterface { 85a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianpublic: 8617576de056a57753eb4af797545db88ef4f81ef0Colin Cross DECLARE_META_INTERFACE(ConsumerListener) 87a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian}; 88a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 897a63e83b303c550156e29eaabf437d174fae4dccDan Stozaclass BnConsumerListener : public SafeBnInterface<IConsumerListener> { 90a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianpublic: 917a63e83b303c550156e29eaabf437d174fae4dccDan Stoza BnConsumerListener() : SafeBnInterface<IConsumerListener>("BnConsumerListener") {} 927a63e83b303c550156e29eaabf437d174fae4dccDan Stoza 937a63e83b303c550156e29eaabf437d174fae4dccDan Stoza status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, 947a63e83b303c550156e29eaabf437d174fae4dccDan Stoza uint32_t flags = 0) override; 95a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian}; 96a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 97e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza} // namespace android 98