| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2017, The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #ifndef CCODEC_BUFFER_CHANNEL_H_ | 
|  | 18 |  | 
|  | 19 | #define CCODEC_BUFFER_CHANNEL_H_ | 
|  | 20 |  | 
| Brian Lindahl | 932bf60 | 2023-03-09 11:59:48 -0700 | [diff] [blame] | 21 | #include <deque> | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 22 | #include <map> | 
|  | 23 | #include <memory> | 
|  | 24 | #include <vector> | 
|  | 25 |  | 
|  | 26 | #include <C2Buffer.h> | 
|  | 27 | #include <C2Component.h> | 
|  | 28 | #include <Codec2Mapper.h> | 
|  | 29 |  | 
|  | 30 | #include <codec2/hidl/client.h> | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 31 | #include <media/stagefright/foundation/Mutexed.h> | 
|  | 32 | #include <media/stagefright/CodecBase.h> | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 33 |  | 
| Wonsik Kim | 469c834 | 2019-04-11 16:46:09 -0700 | [diff] [blame] | 34 | #include "CCodecBuffers.h" | 
| Wonsik Kim | e1104ca | 2020-11-24 15:01:33 -0800 | [diff] [blame] | 35 | #include "FrameReassembler.h" | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 36 | #include "InputSurfaceWrapper.h" | 
| Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 37 | #include "PipelineWatcher.h" | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 38 |  | 
|  | 39 | namespace android { | 
|  | 40 |  | 
| Wonsik Kim | 078b58e | 2019-01-09 15:08:06 -0800 | [diff] [blame] | 41 | class MemoryDealer; | 
|  | 42 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 43 | class CCodecCallback { | 
|  | 44 | public: | 
|  | 45 | virtual ~CCodecCallback() = default; | 
|  | 46 | virtual void onError(status_t err, enum ActionCode actionCode) = 0; | 
|  | 47 | virtual void onOutputFramesRendered(int64_t mediaTimeUs, nsecs_t renderTimeNs) = 0; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 48 | virtual void onOutputBuffersChanged() = 0; | 
| Guillaume Chelfi | 867d4dd | 2021-07-01 18:38:45 +0200 | [diff] [blame] | 49 | virtual void onFirstTunnelFrameReady() = 0; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 50 | }; | 
|  | 51 |  | 
|  | 52 | /** | 
|  | 53 | * BufferChannelBase implementation for CCodec. | 
|  | 54 | */ | 
|  | 55 | class CCodecBufferChannel | 
|  | 56 | : public BufferChannelBase, public std::enable_shared_from_this<CCodecBufferChannel> { | 
|  | 57 | public: | 
|  | 58 | explicit CCodecBufferChannel(const std::shared_ptr<CCodecCallback> &callback); | 
|  | 59 | virtual ~CCodecBufferChannel(); | 
|  | 60 |  | 
|  | 61 | // BufferChannelBase interface | 
| Wonsik Kim | 596187e | 2019-10-25 12:44:10 -0700 | [diff] [blame] | 62 | void setCrypto(const sp<ICrypto> &crypto) override; | 
|  | 63 | void setDescrambler(const sp<IDescrambler> &descrambler) override; | 
|  | 64 |  | 
| Brian Lindahl | aab4eda | 2023-11-19 02:48:49 +0000 | [diff] [blame] | 65 | status_t queueInputBuffer(const sp<MediaCodecBuffer> &buffer) override; | 
|  | 66 | status_t queueSecureInputBuffer( | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 67 | const sp<MediaCodecBuffer> &buffer, | 
|  | 68 | bool secure, | 
|  | 69 | const uint8_t *key, | 
|  | 70 | const uint8_t *iv, | 
|  | 71 | CryptoPlugin::Mode mode, | 
|  | 72 | CryptoPlugin::Pattern pattern, | 
|  | 73 | const CryptoPlugin::SubSample *subSamples, | 
|  | 74 | size_t numSubSamples, | 
|  | 75 | AString *errorDetailMsg) override; | 
| Brian Lindahl | aab4eda | 2023-11-19 02:48:49 +0000 | [diff] [blame] | 76 | status_t attachBuffer( | 
| Wonsik Kim | fb7a767 | 2019-12-27 17:13:33 -0800 | [diff] [blame] | 77 | const std::shared_ptr<C2Buffer> &c2Buffer, | 
|  | 78 | const sp<MediaCodecBuffer> &buffer) override; | 
| Brian Lindahl | aab4eda | 2023-11-19 02:48:49 +0000 | [diff] [blame] | 79 | status_t attachEncryptedBuffer( | 
| Wonsik Kim | fb7a767 | 2019-12-27 17:13:33 -0800 | [diff] [blame] | 80 | const sp<hardware::HidlMemory> &memory, | 
|  | 81 | bool secure, | 
|  | 82 | const uint8_t *key, | 
|  | 83 | const uint8_t *iv, | 
|  | 84 | CryptoPlugin::Mode mode, | 
|  | 85 | CryptoPlugin::Pattern pattern, | 
|  | 86 | size_t offset, | 
|  | 87 | const CryptoPlugin::SubSample *subSamples, | 
|  | 88 | size_t numSubSamples, | 
| Arun Johnson | 634d080 | 2023-02-14 22:07:51 +0000 | [diff] [blame] | 89 | const sp<MediaCodecBuffer> &buffer, | 
|  | 90 | AString* errorDetailMsg) override; | 
| Brian Lindahl | aab4eda | 2023-11-19 02:48:49 +0000 | [diff] [blame] | 91 | status_t renderOutputBuffer( | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 92 | const sp<MediaCodecBuffer> &buffer, int64_t timestampNs) override; | 
| Brian Lindahl | aab4eda | 2023-11-19 02:48:49 +0000 | [diff] [blame] | 93 | void pollForRenderedBuffers() override; | 
| Sungtak Lee | 214ce61 | 2023-11-01 10:01:13 +0000 | [diff] [blame] | 94 | void onBufferReleasedFromOutputSurface(uint32_t generation) override; | 
| Brian Lindahl | aab4eda | 2023-11-19 02:48:49 +0000 | [diff] [blame] | 95 | status_t discardBuffer(const sp<MediaCodecBuffer> &buffer) override; | 
|  | 96 | void getInputBufferArray(Vector<sp<MediaCodecBuffer>> *array) override; | 
|  | 97 | void getOutputBufferArray(Vector<sp<MediaCodecBuffer>> *array) override; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 98 |  | 
|  | 99 | // Methods below are interface for CCodec to use. | 
|  | 100 |  | 
|  | 101 | /** | 
|  | 102 | * Set the component object for buffer processing. | 
|  | 103 | */ | 
|  | 104 | void setComponent(const std::shared_ptr<Codec2Client::Component> &component); | 
|  | 105 |  | 
|  | 106 | /** | 
|  | 107 | * Set output graphic surface for rendering. | 
|  | 108 | */ | 
| Sungtak Lee | 214ce61 | 2023-11-01 10:01:13 +0000 | [diff] [blame] | 109 | status_t setSurface(const sp<Surface> &surface, uint32_t generation, bool pushBlankBuffer); | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 110 |  | 
|  | 111 | /** | 
|  | 112 | * Set GraphicBufferSource object from which the component extracts input | 
|  | 113 | * buffers. | 
|  | 114 | */ | 
|  | 115 | status_t setInputSurface(const std::shared_ptr<InputSurfaceWrapper> &surface); | 
|  | 116 |  | 
|  | 117 | /** | 
|  | 118 | * Signal EOS to input surface. | 
|  | 119 | */ | 
|  | 120 | status_t signalEndOfInputStream(); | 
|  | 121 |  | 
|  | 122 | /** | 
|  | 123 | * Set parameters. | 
|  | 124 | */ | 
|  | 125 | status_t setParameters(std::vector<std::unique_ptr<C2Param>> ¶ms); | 
|  | 126 |  | 
|  | 127 | /** | 
|  | 128 | * Start queueing buffers to the component. This object should never queue | 
|  | 129 | * buffers before this call has completed. | 
|  | 130 | */ | 
| Wonsik Kim | fb7a767 | 2019-12-27 17:13:33 -0800 | [diff] [blame] | 131 | status_t start( | 
|  | 132 | const sp<AMessage> &inputFormat, | 
|  | 133 | const sp<AMessage> &outputFormat, | 
|  | 134 | bool buffersBoundToCodec); | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 135 |  | 
|  | 136 | /** | 
| Wonsik Kim | 34b28b4 | 2022-05-20 15:49:32 -0700 | [diff] [blame] | 137 | * Prepare initial input buffers to be filled by client. | 
|  | 138 | * | 
|  | 139 | * \param clientInputBuffers[out]   pointer to slot index -> buffer map. | 
|  | 140 | *                                  On success, it contains prepared | 
|  | 141 | *                                  initial input buffers. | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 142 | */ | 
| Wonsik Kim | 34b28b4 | 2022-05-20 15:49:32 -0700 | [diff] [blame] | 143 | status_t prepareInitialInputBuffers( | 
| Arun Johnson | 326166e | 2023-07-28 19:11:52 +0000 | [diff] [blame] | 144 | std::map<size_t, sp<MediaCodecBuffer>> *clientInputBuffers, | 
|  | 145 | bool retry = false); | 
| Wonsik Kim | 34b28b4 | 2022-05-20 15:49:32 -0700 | [diff] [blame] | 146 |  | 
|  | 147 | /** | 
|  | 148 | * Request initial input buffers as prepared in clientInputBuffers. | 
|  | 149 | * | 
|  | 150 | * \param clientInputBuffers[in]    slot index -> buffer map with prepared | 
|  | 151 | *                                  initial input buffers. | 
|  | 152 | */ | 
|  | 153 | status_t requestInitialInputBuffers( | 
|  | 154 | std::map<size_t, sp<MediaCodecBuffer>> &&clientInputBuffers); | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 155 |  | 
|  | 156 | /** | 
| Sungtak Lee | d964e2e | 2022-07-30 08:43:58 +0000 | [diff] [blame] | 157 | * Stop using buffers of the current output surface for other Codec | 
|  | 158 | * instances to use the surface safely. | 
| Sungtak Lee | 80c8e1e | 2023-01-26 11:03:14 +0000 | [diff] [blame] | 159 | * | 
|  | 160 | * \param pushBlankBuffer[in]       push a blank buffer at the end if true | 
| Sungtak Lee | d964e2e | 2022-07-30 08:43:58 +0000 | [diff] [blame] | 161 | */ | 
| Sungtak Lee | 80c8e1e | 2023-01-26 11:03:14 +0000 | [diff] [blame] | 162 | void stopUseOutputSurface(bool pushBlankBuffer); | 
| Sungtak Lee | d964e2e | 2022-07-30 08:43:58 +0000 | [diff] [blame] | 163 |  | 
|  | 164 | /** | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 165 | * Stop queueing buffers to the component. This object should never queue | 
|  | 166 | * buffers after this call, until start() is called. | 
|  | 167 | */ | 
|  | 168 | void stop(); | 
|  | 169 |  | 
| Wonsik Kim | 936a89c | 2020-05-08 16:07:50 -0700 | [diff] [blame] | 170 | /** | 
|  | 171 | * Stop queueing buffers to the component and release all buffers. | 
|  | 172 | */ | 
|  | 173 | void reset(); | 
|  | 174 |  | 
|  | 175 | /** | 
|  | 176 | * Release all resources. | 
|  | 177 | */ | 
|  | 178 | void release(); | 
|  | 179 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 180 | void flush(const std::list<std::unique_ptr<C2Work>> &flushedWork); | 
|  | 181 |  | 
|  | 182 | /** | 
|  | 183 | * Notify input client about work done. | 
|  | 184 | * | 
|  | 185 | * @param workItems   finished work item. | 
|  | 186 | * @param outputFormat new output format if it has changed, otherwise nullptr | 
|  | 187 | * @param initData    new init data (CSD) if it has changed, otherwise nullptr | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 188 | */ | 
|  | 189 | void onWorkDone( | 
|  | 190 | std::unique_ptr<C2Work> work, const sp<AMessage> &outputFormat, | 
| Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 191 | const C2StreamInitDataInfo::output *initData); | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 192 |  | 
|  | 193 | /** | 
|  | 194 | * Make an input buffer available for the client as it is no longer needed | 
|  | 195 | * by the codec. | 
|  | 196 | * | 
| Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 197 | * @param frameIndex The index of input work | 
|  | 198 | * @param arrayIndex The index of buffer in the input work buffers. | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 199 | */ | 
| Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 200 | void onInputBufferDone(uint64_t frameIndex, size_t arrayIndex); | 
|  | 201 |  | 
|  | 202 | PipelineWatcher::Clock::duration elapsed(); | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 203 |  | 
|  | 204 | enum MetaMode { | 
|  | 205 | MODE_NONE, | 
|  | 206 | MODE_ANW, | 
|  | 207 | }; | 
|  | 208 |  | 
|  | 209 | void setMetaMode(MetaMode mode); | 
|  | 210 |  | 
| Songyue Han | 1e6769b | 2023-08-30 18:09:27 +0000 | [diff] [blame] | 211 | /** | 
|  | 212 | * get pixel format from output buffers. | 
|  | 213 | * | 
|  | 214 | * @return 0 if no valid pixel format found. | 
|  | 215 | */ | 
|  | 216 | uint32_t getBuffersPixelFormat(bool isEncoder); | 
|  | 217 |  | 
|  | 218 | void resetBuffersPixelFormat(bool isEncoder); | 
|  | 219 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 220 | private: | 
| Songyue Han | 1e6769b | 2023-08-30 18:09:27 +0000 | [diff] [blame] | 221 | uint32_t getInputBuffersPixelFormat(); | 
|  | 222 |  | 
|  | 223 | uint32_t getOutputBuffersPixelFormat(); | 
|  | 224 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 225 | class QueueGuard; | 
|  | 226 |  | 
|  | 227 | /** | 
|  | 228 | * Special mutex-like object with the following properties: | 
|  | 229 | * | 
|  | 230 | * - At STOPPED state (initial, or after stop()) | 
|  | 231 | *   - QueueGuard object gets created at STOPPED state, and the client is | 
|  | 232 | *     supposed to return immediately. | 
|  | 233 | * - At RUNNING state (after start()) | 
|  | 234 | *   - Each QueueGuard object | 
|  | 235 | */ | 
|  | 236 | class QueueSync { | 
|  | 237 | public: | 
|  | 238 | /** | 
|  | 239 | * At construction the sync object is in STOPPED state. | 
|  | 240 | */ | 
|  | 241 | inline QueueSync() {} | 
|  | 242 | ~QueueSync() = default; | 
|  | 243 |  | 
|  | 244 | /** | 
|  | 245 | * Transition to RUNNING state when stopped. No-op if already in RUNNING | 
|  | 246 | * state. | 
|  | 247 | */ | 
|  | 248 | void start(); | 
|  | 249 |  | 
|  | 250 | /** | 
|  | 251 | * At RUNNING state, wait until all QueueGuard object created during | 
|  | 252 | * RUNNING state are destroyed, and then transition to STOPPED state. | 
|  | 253 | * No-op if already in STOPPED state. | 
|  | 254 | */ | 
|  | 255 | void stop(); | 
|  | 256 |  | 
|  | 257 | private: | 
|  | 258 | Mutex mGuardLock; | 
|  | 259 |  | 
|  | 260 | struct Counter { | 
|  | 261 | inline Counter() : value(-1) {} | 
|  | 262 | int32_t value; | 
|  | 263 | Condition cond; | 
|  | 264 | }; | 
|  | 265 | Mutexed<Counter> mCount; | 
|  | 266 |  | 
|  | 267 | friend class CCodecBufferChannel::QueueGuard; | 
|  | 268 | }; | 
|  | 269 |  | 
|  | 270 | class QueueGuard { | 
|  | 271 | public: | 
|  | 272 | QueueGuard(QueueSync &sync); | 
|  | 273 | ~QueueGuard(); | 
|  | 274 | inline bool isRunning() { return mRunning; } | 
|  | 275 |  | 
|  | 276 | private: | 
|  | 277 | QueueSync &mSync; | 
|  | 278 | bool mRunning; | 
|  | 279 | }; | 
|  | 280 |  | 
| Brian Lindahl | 932bf60 | 2023-03-09 11:59:48 -0700 | [diff] [blame] | 281 | struct TrackedFrame { | 
|  | 282 | uint64_t number; | 
|  | 283 | int64_t mediaTimeUs; | 
|  | 284 | int64_t desiredRenderTimeNs; | 
|  | 285 | nsecs_t latchTime; | 
|  | 286 | sp<Fence> presentFence; | 
|  | 287 | }; | 
|  | 288 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 289 | void feedInputBufferIfAvailable(); | 
|  | 290 | void feedInputBufferIfAvailableInternal(); | 
| Sungtak Lee | 04b3035 | 2020-07-27 13:57:25 -0700 | [diff] [blame] | 291 | status_t queueInputBufferInternal(sp<MediaCodecBuffer> buffer, | 
|  | 292 | std::shared_ptr<C2LinearBlock> encryptedBlock = nullptr, | 
|  | 293 | size_t blockSize = 0); | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 294 | bool handleWork( | 
|  | 295 | std::unique_ptr<C2Work> work, const sp<AMessage> &outputFormat, | 
|  | 296 | const C2StreamInitDataInfo::output *initData); | 
|  | 297 | void sendOutputBuffers(); | 
| Wonsik Kim | fb7a767 | 2019-12-27 17:13:33 -0800 | [diff] [blame] | 298 | void ensureDecryptDestination(size_t size); | 
|  | 299 | int32_t getHeapSeqNum(const sp<hardware::HidlMemory> &memory); | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 300 |  | 
| Brian Lindahl | 932bf60 | 2023-03-09 11:59:48 -0700 | [diff] [blame] | 301 | void initializeFrameTrackingFor(ANativeWindow * window); | 
|  | 302 | void trackReleasedFrame(const IGraphicBufferProducer::QueueBufferOutput& qbo, | 
|  | 303 | int64_t mediaTimeUs, int64_t desiredRenderTimeNs); | 
|  | 304 | void processRenderedFrames(const FrameEventHistoryDelta& delta); | 
|  | 305 | int64_t getRenderTimeNs(const TrackedFrame& frame); | 
|  | 306 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 307 | QueueSync mSync; | 
|  | 308 | sp<MemoryDealer> mDealer; | 
|  | 309 | sp<IMemory> mDecryptDestination; | 
|  | 310 | int32_t mHeapSeqNum; | 
| Wonsik Kim | fb7a767 | 2019-12-27 17:13:33 -0800 | [diff] [blame] | 311 | std::map<wp<hardware::HidlMemory>, int32_t> mHeapSeqNumMap; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 312 |  | 
|  | 313 | std::shared_ptr<Codec2Client::Component> mComponent; | 
|  | 314 | std::string mComponentName; ///< component name for debugging | 
|  | 315 | const char *mName; ///< C-string version of component name | 
|  | 316 | std::shared_ptr<CCodecCallback> mCCodecCallback; | 
|  | 317 | std::shared_ptr<C2BlockPool> mInputAllocator; | 
|  | 318 | QueueSync mQueueSync; | 
|  | 319 | std::vector<std::unique_ptr<C2Param>> mParamsToBeSet; | 
| Houxiang Dai | e74e506 | 2022-05-19 15:32:54 +0800 | [diff] [blame] | 320 | sp<AMessage> mOutputFormat; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 321 |  | 
| Wonsik Kim | 5ecf383 | 2019-04-18 10:28:58 -0700 | [diff] [blame] | 322 | struct Input { | 
|  | 323 | Input(); | 
|  | 324 |  | 
|  | 325 | std::unique_ptr<InputBuffers> buffers; | 
|  | 326 | size_t numSlots; | 
|  | 327 | FlexBuffersImpl extraBuffers; | 
|  | 328 | size_t numExtraSlots; | 
|  | 329 | uint32_t inputDelay; | 
|  | 330 | uint32_t pipelineDelay; | 
| Wonsik Kim | 6b2c8be | 2021-09-28 05:11:04 -0700 | [diff] [blame] | 331 | c2_cntr64_t lastFlushIndex; | 
| Wonsik Kim | e1104ca | 2020-11-24 15:01:33 -0800 | [diff] [blame] | 332 |  | 
|  | 333 | FrameReassembler frameReassembler; | 
| Wonsik Kim | 5ecf383 | 2019-04-18 10:28:58 -0700 | [diff] [blame] | 334 | }; | 
|  | 335 | Mutexed<Input> mInput; | 
|  | 336 | struct Output { | 
|  | 337 | std::unique_ptr<OutputBuffers> buffers; | 
|  | 338 | size_t numSlots; | 
|  | 339 | uint32_t outputDelay; | 
| Wonsik Kim | 3722abc | 2023-05-17 13:26:31 -0700 | [diff] [blame] | 340 | // true iff the underlying block pool is bounded --- for example, | 
|  | 341 | // a BufferQueue-based block pool would be bounded by the BufferQueue. | 
|  | 342 | bool bounded; | 
| Wonsik Kim | 5ecf383 | 2019-04-18 10:28:58 -0700 | [diff] [blame] | 343 | }; | 
|  | 344 | Mutexed<Output> mOutput; | 
| Wonsik Kim | 5ebfcb2 | 2021-01-05 18:58:15 -0800 | [diff] [blame] | 345 | Mutexed<std::list<std::unique_ptr<C2Work>>> mFlushedConfigs; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 346 |  | 
|  | 347 | std::atomic_uint64_t mFrameIndex; | 
|  | 348 | std::atomic_uint64_t mFirstValidFrameIndex; | 
|  | 349 |  | 
|  | 350 | sp<MemoryDealer> makeMemoryDealer(size_t heapSize); | 
|  | 351 |  | 
| Brian Lindahl | 932bf60 | 2023-03-09 11:59:48 -0700 | [diff] [blame] | 352 | std::deque<TrackedFrame> mTrackedFrames; | 
| Brian Lindahl | d7967a9 | 2023-08-10 10:12:49 -0600 | [diff] [blame] | 353 | bool mAreRenderMetricsEnabled; | 
| Brian Lindahl | 2048d49 | 2023-04-05 08:49:23 -0600 | [diff] [blame] | 354 | bool mIsSurfaceToDisplay; | 
| Brian Lindahl | 932bf60 | 2023-03-09 11:59:48 -0700 | [diff] [blame] | 355 | bool mHasPresentFenceTimes; | 
|  | 356 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 357 | struct OutputSurface { | 
|  | 358 | sp<Surface> surface; | 
|  | 359 | uint32_t generation; | 
| Wonsik Kim | f5e5c83 | 2019-02-21 11:36:05 -0800 | [diff] [blame] | 360 | int maxDequeueBuffers; | 
| Byeongjo Park | 25c3a3d | 2020-06-12 17:24:21 +0900 | [diff] [blame] | 361 | std::map<uint64_t, int> rotation; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 362 | }; | 
|  | 363 | Mutexed<OutputSurface> mOutputSurface; | 
| Wonsik Kim | 3a692e6 | 2023-05-19 15:37:22 -0700 | [diff] [blame] | 364 | int mRenderingDepth; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 365 |  | 
|  | 366 | struct BlockPools { | 
|  | 367 | C2Allocator::id_t inputAllocatorId; | 
|  | 368 | std::shared_ptr<C2BlockPool> inputPool; | 
|  | 369 | C2Allocator::id_t outputAllocatorId; | 
|  | 370 | C2BlockPool::local_id_t outputPoolId; | 
|  | 371 | std::shared_ptr<Codec2Client::Configurable> outputPoolIntf; | 
|  | 372 | }; | 
|  | 373 | Mutexed<BlockPools> mBlockPools; | 
|  | 374 |  | 
|  | 375 | std::shared_ptr<InputSurfaceWrapper> mInputSurface; | 
|  | 376 |  | 
|  | 377 | MetaMode mMetaMode; | 
|  | 378 |  | 
| Wonsik Kim | ab34ed6 | 2019-01-31 15:28:46 -0800 | [diff] [blame] | 379 | Mutexed<PipelineWatcher> mPipelineWatcher; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 380 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 381 | std::atomic_bool mInputMetEos; | 
| Wonsik Kim | f7529dd | 2019-04-18 17:35:53 -0700 | [diff] [blame] | 382 | std::once_flag mRenderWarningFlag; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 383 |  | 
| Wonsik Kim | 596187e | 2019-10-25 12:44:10 -0700 | [diff] [blame] | 384 | sp<ICrypto> mCrypto; | 
|  | 385 | sp<IDescrambler> mDescrambler; | 
|  | 386 |  | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 387 | inline bool hasCryptoOrDescrambler() { | 
|  | 388 | return mCrypto != nullptr || mDescrambler != nullptr; | 
|  | 389 | } | 
| Sungtak Lee | 04b3035 | 2020-07-27 13:57:25 -0700 | [diff] [blame] | 390 | std::atomic_bool mSendEncryptedInfoBuffer; | 
| Wonsik Kim | ec585c3 | 2021-10-01 01:11:00 -0700 | [diff] [blame] | 391 |  | 
|  | 392 | std::atomic_bool mTunneled; | 
| Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame] | 393 | }; | 
|  | 394 |  | 
|  | 395 | // Conversion of a c2_status_t value to a status_t value may depend on the | 
|  | 396 | // operation that returns the c2_status_t value. | 
|  | 397 | enum c2_operation_t { | 
|  | 398 | C2_OPERATION_NONE, | 
|  | 399 | C2_OPERATION_Component_connectToOmxInputSurface, | 
|  | 400 | C2_OPERATION_Component_createBlockPool, | 
|  | 401 | C2_OPERATION_Component_destroyBlockPool, | 
|  | 402 | C2_OPERATION_Component_disconnectFromInputSurface, | 
|  | 403 | C2_OPERATION_Component_drain, | 
|  | 404 | C2_OPERATION_Component_flush, | 
|  | 405 | C2_OPERATION_Component_queue, | 
|  | 406 | C2_OPERATION_Component_release, | 
|  | 407 | C2_OPERATION_Component_reset, | 
|  | 408 | C2_OPERATION_Component_setOutputSurface, | 
|  | 409 | C2_OPERATION_Component_start, | 
|  | 410 | C2_OPERATION_Component_stop, | 
|  | 411 | C2_OPERATION_ComponentStore_copyBuffer, | 
|  | 412 | C2_OPERATION_ComponentStore_createComponent, | 
|  | 413 | C2_OPERATION_ComponentStore_createInputSurface, | 
|  | 414 | C2_OPERATION_ComponentStore_createInterface, | 
|  | 415 | C2_OPERATION_Configurable_config, | 
|  | 416 | C2_OPERATION_Configurable_query, | 
|  | 417 | C2_OPERATION_Configurable_querySupportedParams, | 
|  | 418 | C2_OPERATION_Configurable_querySupportedValues, | 
|  | 419 | C2_OPERATION_InputSurface_connectToComponent, | 
|  | 420 | C2_OPERATION_InputSurfaceConnection_disconnect, | 
|  | 421 | }; | 
|  | 422 |  | 
|  | 423 | status_t toStatusT(c2_status_t c2s, c2_operation_t c2op = C2_OPERATION_NONE); | 
|  | 424 |  | 
|  | 425 | }  // namespace android | 
|  | 426 |  | 
|  | 427 | #endif  // CCODEC_BUFFER_CHANNEL_H_ |