1 /* 2 * Copyright (C) 2010 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 A_CODEC_H_ 18 #define A_CODEC_H_ 19 20 #include <stdint.h> 21 #include <android/native_window.h> 22 #include <media/hardware/MetadataBufferType.h> 23 #include <media/MediaCodecInfo.h> 24 #include <media/IOMX.h> 25 #include <media/stagefright/AHierarchicalStateMachine.h> 26 #include <media/stagefright/CodecBase.h> 27 #include <media/stagefright/FrameRenderTracker.h> 28 #include <media/stagefright/MediaDefs.h> 29 #include <media/stagefright/SkipCutBuffer.h> 30 #include <utils/NativeHandle.h> 31 #include <OMX_Audio.h> 32 #include <hardware/gralloc.h> 33 #include <nativebase/nativebase.h> 34 #include <android/hardware/graphics/common/1.2/types.h> 35 #include <android/hidl/allocator/1.0/IAllocator.h> 36 #include <android/hidl/memory/1.0/IMemory.h> 37 38 #define TRACK_BUFFER_TIMING 0 39 40 namespace android { 41 namespace hardware { 42 namespace media { 43 namespace omx { 44 namespace V1_0 { 45 struct IGraphicBufferSource; 46 } // namespace V1_0 47 } // namespace omx 48 } // namespace media 49 } // namespace hardware 50 51 struct ABuffer; 52 class ACodecBufferChannel; 53 class MediaCodecBuffer; 54 class MemoryDealer; 55 struct DescribeColorFormat2Params; 56 struct DataConverter; 57 58 using android::hardware::graphics::common::V1_2::BufferUsage; 59 typedef hidl::allocator::V1_0::IAllocator TAllocator; 60 typedef hidl::memory::V1_0::IMemory TMemory; 61 62 struct ACodec : public AHierarchicalStateMachine, public CodecBase { 63 ACodec(); 64 65 void initiateSetup(const sp<AMessage> &msg); 66 67 virtual std::shared_ptr<BufferChannelBase> getBufferChannel() override; 68 virtual void initiateAllocateComponent(const sp<AMessage> &msg); 69 virtual void initiateConfigureComponent(const sp<AMessage> &msg); 70 virtual void initiateCreateInputSurface(); 71 virtual void initiateSetInputSurface(const sp<PersistentSurface> &surface); 72 virtual void initiateStart(); 73 virtual void initiateShutdown(bool keepComponentAllocated = false); 74 virtual status_t querySupportedParameters(std::vector<std::string> *names) override; 75 virtual status_t subscribeToParameters(const std::vector<std::string> &names) override; 76 virtual status_t unsubscribeFromParameters(const std::vector<std::string> &names) override; 77 78 status_t queryCapabilities( 79 const char* owner, const char* name, 80 const char* mime, bool isEncoder, 81 MediaCodecInfo::CapabilitiesWriter* caps); 82 83 virtual status_t setSurface(const sp<Surface> &surface); 84 85 virtual void signalFlush(); 86 virtual void signalResume(); 87 88 virtual void signalSetParameters(const sp<AMessage> &msg); 89 virtual void signalEndOfInputStream(); 90 virtual void signalRequestIDRFrame(); 91 92 // AHierarchicalStateMachine implements the message handling onMessageReceivedACodec93 virtual void onMessageReceived(const sp<AMessage> &msg) { 94 handleMessage(msg); 95 } 96 97 // Returns 0 if configuration is not supported. NOTE: this is treated by 98 // some OMX components as auto level, and by others as invalid level. 99 static int /* OMX_VIDEO_AVCLEVELTYPE */ getAVCLevelFor( 100 int width, int height, int rate, int bitrate, 101 OMX_VIDEO_AVCPROFILEEXTTYPE profile = 102 (OMX_VIDEO_AVCPROFILEEXTTYPE)OMX_VIDEO_AVCProfileBaseline); 103 104 // Quirk still supported, even though deprecated 105 enum Quirks { 106 kRequiresAllocateBufferOnInputPorts = 1, 107 kRequiresAllocateBufferOnOutputPorts = 2, 108 }; 109 110 static status_t getOMXChannelMapping(size_t numChannels, OMX_AUDIO_CHANNELTYPE map[]); 111 112 protected: 113 virtual ~ACodec(); 114 115 private: 116 struct BaseState; 117 struct UninitializedState; 118 struct LoadedState; 119 struct LoadedToIdleState; 120 struct IdleToExecutingState; 121 struct ExecutingState; 122 struct OutputPortSettingsChangedState; 123 struct ExecutingToIdleState; 124 struct IdleToLoadedState; 125 struct FlushingState; 126 struct DeathNotifier; 127 128 enum { 129 kWhatSetup = 'setu', 130 kWhatOMXMessage = 'omx ', 131 // same as kWhatOMXMessage - but only used with 132 // handleMessage during OMX message-list handling 133 kWhatOMXMessageItem = 'omxI', 134 kWhatOMXMessageList = 'omxL', 135 kWhatInputBufferFilled = 'inpF', 136 kWhatOutputBufferDrained = 'outD', 137 kWhatShutdown = 'shut', 138 kWhatFlush = 'flus', 139 kWhatResume = 'resm', 140 kWhatDrainDeferredMessages = 'drai', 141 kWhatAllocateComponent = 'allo', 142 kWhatConfigureComponent = 'conf', 143 kWhatSetSurface = 'setS', 144 kWhatCreateInputSurface = 'cisf', 145 kWhatSetInputSurface = 'sisf', 146 kWhatSignalEndOfInputStream = 'eois', 147 kWhatStart = 'star', 148 kWhatRequestIDRFrame = 'ridr', 149 kWhatSetParameters = 'setP', 150 kWhatSubmitOutputMetadataBufferIfEOS = 'subm', 151 kWhatOMXDied = 'OMXd', 152 kWhatReleaseCodecInstance = 'relC', 153 kWhatForceStateTransition = 'fstt', 154 kWhatCheckIfStuck = 'Cstk', 155 kWhatSubmitExtraOutputMetadataBuffer = 'sbxo', 156 }; 157 158 enum { 159 kPortIndexInput = 0, 160 kPortIndexOutput = 1 161 }; 162 163 enum { 164 kFlagIsSecure = 1, 165 kFlagPushBlankBuffersToNativeWindowOnShutdown = 2, 166 kFlagIsGrallocUsageProtected = 4, 167 kFlagPreregisterMetadataBuffers = 8, 168 }; 169 170 enum { 171 kVideoGrallocUsage = (GRALLOC_USAGE_HW_TEXTURE 172 | GRALLOC_USAGE_HW_COMPOSER 173 | GRALLOC_USAGE_EXTERNAL_DISP) 174 | static_cast<uint64_t>(BufferUsage::VIDEO_DECODER), 175 }; 176 177 struct BufferInfo { 178 enum Status { 179 OWNED_BY_US, 180 OWNED_BY_COMPONENT, 181 OWNED_BY_UPSTREAM, 182 OWNED_BY_DOWNSTREAM, 183 OWNED_BY_NATIVE_WINDOW, 184 UNRECOGNIZED, // not a tracked buffer 185 }; 186 getSafeStatusACodec::BufferInfo187 static inline Status getSafeStatus(BufferInfo *info) { 188 return info == NULL ? UNRECOGNIZED : info->mStatus; 189 } 190 191 IOMX::buffer_id mBufferID; 192 Status mStatus; 193 unsigned mDequeuedAt; 194 195 sp<MediaCodecBuffer> mData; // the client's buffer; if not using data conversion, this is 196 // the codec buffer; otherwise, it is allocated separately 197 sp<RefBase> mMemRef; // and a reference to the IMemory, so it does not go away 198 sp<MediaCodecBuffer> mCodecData; // the codec's buffer 199 sp<RefBase> mCodecRef; // and a reference to the IMemory 200 201 sp<GraphicBuffer> mGraphicBuffer; 202 bool mNewGraphicBuffer; 203 int mFenceFd; 204 FrameRenderTracker::Info *mRenderInfo; 205 206 // The following field and 4 methods are used for debugging only 207 bool mIsReadFence; 208 // Store |fenceFd| and set read/write flag. Log error, if there is already a fence stored. 209 void setReadFence(int fenceFd, const char *dbg); 210 void setWriteFence(int fenceFd, const char *dbg); 211 // Log error, if the current fence is not a read/write fence. 212 void checkReadFence(const char *dbg); 213 void checkWriteFence(const char *dbg); 214 }; 215 216 static const char *_asString(BufferInfo::Status s); 217 void dumpBuffers(OMX_U32 portIndex); 218 219 // If |fd| is non-negative, waits for fence with |fd| and logs an error if it fails. Returns 220 // the error code or OK on success. If |fd| is negative, it returns OK 221 status_t waitForFence(int fd, const char *dbg); 222 223 #if TRACK_BUFFER_TIMING 224 struct BufferStats { 225 int64_t mEmptyBufferTimeUs; 226 int64_t mFillBufferDoneTimeUs; 227 }; 228 229 KeyedVector<int64_t, BufferStats> mBufferStats; 230 #endif 231 232 sp<UninitializedState> mUninitializedState; 233 sp<LoadedState> mLoadedState; 234 sp<LoadedToIdleState> mLoadedToIdleState; 235 sp<IdleToExecutingState> mIdleToExecutingState; 236 sp<ExecutingState> mExecutingState; 237 sp<OutputPortSettingsChangedState> mOutputPortSettingsChangedState; 238 sp<ExecutingToIdleState> mExecutingToIdleState; 239 sp<IdleToLoadedState> mIdleToLoadedState; 240 sp<FlushingState> mFlushingState; 241 sp<SkipCutBuffer> mSkipCutBuffer; 242 int32_t mSampleRate; 243 244 AString mComponentName; 245 uint32_t mFlags; 246 sp<IOMX> mOMX; 247 sp<IOMXNode> mOMXNode; 248 int32_t mNodeGeneration; 249 sp<TAllocator> mAllocator[2]; 250 251 bool mUsingNativeWindow; 252 sp<ANativeWindow> mNativeWindow; 253 int mNativeWindowUsageBits; 254 android_native_rect_t mLastNativeWindowCrop; 255 int32_t mLastNativeWindowDataSpace; 256 HDRStaticInfo mLastHDRStaticInfo; 257 sp<ABuffer> mHdr10PlusScratchBuffer; 258 sp<ABuffer> mLastHdr10PlusBuffer; 259 sp<AMessage> mConfigFormat; 260 sp<AMessage> mInputFormat; 261 sp<AMessage> mOutputFormat; 262 263 // Initial output format + configuration params that is reused as the base for all subsequent 264 // format updates. This will equal to mOutputFormat until the first actual frame is received. 265 sp<AMessage> mBaseOutputFormat; 266 267 FrameRenderTracker mRenderTracker; // render information for buffers rendered by ACodec 268 Vector<BufferInfo> mBuffers[2]; 269 bool mPortEOS[2]; 270 status_t mInputEOSResult; 271 272 List<sp<AMessage> > mDeferredQueue; 273 274 sp<AMessage> mLastOutputFormat; 275 bool mIsVideo; 276 bool mIsImage; 277 bool mIsEncoder; 278 bool mFatalError; 279 bool mShutdownInProgress; 280 bool mExplicitShutdown; 281 bool mIsLegacyVP9Decoder; 282 bool mIsStreamCorruptFree; 283 bool mIsLowLatency; 284 285 // If "mKeepComponentAllocated" we only transition back to Loaded state 286 // and do not release the component instance. 287 bool mKeepComponentAllocated; 288 289 int32_t mEncoderDelay; 290 int32_t mEncoderPadding; 291 int32_t mRotationDegrees; 292 293 bool mChannelMaskPresent; 294 int32_t mChannelMask; 295 unsigned mDequeueCounter; 296 IOMX::PortMode mPortMode[2]; 297 int32_t mMetadataBuffersToSubmit; 298 size_t mNumUndequeuedBuffers; 299 sp<DataConverter> mConverter[2]; 300 301 sp<hardware::media::omx::V1_0::IGraphicBufferSource> mGraphicBufferSource; 302 int64_t mRepeatFrameDelayUs; 303 int64_t mMaxPtsGapUs; 304 float mMaxFps; 305 double mFps; 306 double mCaptureFps; 307 bool mCreateInputBuffersSuspended; 308 std::optional<uint32_t> mLatency; 309 310 bool mTunneled; 311 312 OMX_INDEXTYPE mDescribeColorAspectsIndex; 313 OMX_INDEXTYPE mDescribeHDRStaticInfoIndex; 314 OMX_INDEXTYPE mDescribeHDR10PlusInfoIndex; 315 316 std::shared_ptr<ACodecBufferChannel> mBufferChannel; 317 318 int32_t mStateGeneration; 319 320 enum { 321 kExtensionsUnchecked, 322 kExtensionsNone, 323 kExtensionsExist, 324 } mVendorExtensionsStatus; 325 326 status_t setCyclicIntraMacroblockRefresh(const sp<AMessage> &msg, int32_t mode); 327 status_t allocateBuffersOnPort(OMX_U32 portIndex); 328 status_t freeBuffersOnPort(OMX_U32 portIndex); 329 status_t freeBuffer(OMX_U32 portIndex, size_t i); 330 331 status_t handleSetSurface(const sp<Surface> &surface); 332 status_t setPortMode(int32_t portIndex, IOMX::PortMode mode); 333 status_t setupNativeWindowSizeFormatAndUsage( 334 ANativeWindow *nativeWindow /* nonnull */, int *finalUsage /* nonnull */, 335 bool reconnect); 336 337 status_t configureOutputBuffersFromNativeWindow( 338 OMX_U32 *nBufferCount, OMX_U32 *nBufferSize, 339 OMX_U32 *nMinUndequeuedBuffers, bool preregister); 340 status_t allocateOutputMetadataBuffers(); 341 status_t submitOutputMetadataBuffer(); 342 void signalSubmitOutputMetadataBufferIfEOS_workaround(); 343 status_t allocateOutputBuffersFromNativeWindow(); 344 status_t cancelBufferToNativeWindow(BufferInfo *info); 345 status_t freeOutputBuffersNotOwnedByComponent(); 346 BufferInfo *dequeueBufferFromNativeWindow(); 347 storingMetadataInDecodedBuffersACodec348 inline bool storingMetadataInDecodedBuffers() { 349 return (mPortMode[kPortIndexOutput] == IOMX::kPortModeDynamicANWBuffer) && !mIsEncoder; 350 } 351 usingSecureBufferOnEncoderOutputACodec352 inline bool usingSecureBufferOnEncoderOutput() { 353 return (mPortMode[kPortIndexOutput] == IOMX::kPortModePresetSecureBuffer) && mIsEncoder; 354 } 355 356 BufferInfo *findBufferByID( 357 uint32_t portIndex, IOMX::buffer_id bufferID, 358 ssize_t *index = NULL); 359 360 status_t fillBuffer(BufferInfo *info); 361 362 status_t setComponentRole(bool isEncoder, const char *mime); 363 364 status_t configureCodec(const char *mime, const sp<AMessage> &msg); 365 366 status_t configureTunneledVideoPlayback(int32_t audioHwSync, 367 const sp<ANativeWindow> &nativeWindow); 368 369 status_t setVideoPortFormatType( 370 OMX_U32 portIndex, 371 OMX_VIDEO_CODINGTYPE compressionFormat, 372 OMX_COLOR_FORMATTYPE colorFormat, 373 bool usingNativeBuffers = false); 374 375 status_t setSupportedOutputFormat(bool getLegacyFlexibleFormat); 376 377 status_t setupVideoDecoder( 378 const char *mime, const sp<AMessage> &msg, bool usingNativeBuffers, bool haveSwRenderer, 379 sp<AMessage> &outputformat); 380 381 status_t setupVideoEncoder( 382 const char *mime, const sp<AMessage> &msg, 383 sp<AMessage> &outputformat, sp<AMessage> &inputformat); 384 385 status_t setVideoFormatOnPort( 386 OMX_U32 portIndex, 387 int32_t width, int32_t height, 388 OMX_VIDEO_CODINGTYPE compressionFormat, float frameRate = -1.0); 389 390 // sets |portIndex| port buffer numbers to be |bufferNum|. NOTE: Component could reject 391 // this setting if the |bufferNum| is less than the minimum buffer num of the port. 392 status_t setPortBufferNum(OMX_U32 portIndex, int bufferNum); 393 394 // gets index or sets it to 0 on error. Returns error from codec. 395 status_t initDescribeColorAspectsIndex(); 396 397 // sets |params|. If |readBack| is true, it re-gets them afterwards if set succeeded. 398 // returns the codec error. 399 status_t setCodecColorAspects(DescribeColorAspectsParams ¶ms, bool readBack = false); 400 401 // gets |params|; returns the codec error. |param| should not change on error. 402 status_t getCodecColorAspects(DescribeColorAspectsParams ¶ms); 403 404 // gets dataspace guidance from codec and platform. |params| should be set up with the color 405 // aspects to use. If |tryCodec| is true, the codec is queried first. If it succeeds, we 406 // return OK. Otherwise, we fall back to the platform guidance and return the codec error; 407 // though, we return OK if the codec failed with UNSUPPORTED, as codec guidance is optional. 408 status_t getDataSpace( 409 DescribeColorAspectsParams ¶ms, android_dataspace *dataSpace /* nonnull */, 410 bool tryCodec); 411 412 // sets color aspects for the encoder for certain |width/height| based on |configFormat|, and 413 // set resulting color config into |outputFormat|. If |usingNativeWindow| is true, we use 414 // video defaults if config is unspecified. Returns error from the codec. 415 status_t setColorAspectsForVideoDecoder( 416 int32_t width, int32_t height, bool usingNativeWindow, 417 const sp<AMessage> &configFormat, sp<AMessage> &outputFormat); 418 419 // gets color aspects for the encoder for certain |width/height| based on |configFormat|, and 420 // set resulting color config into |outputFormat|. If |dataSpace| is non-null, it requests 421 // dataspace guidance from the codec and platform and sets it into |dataSpace|. Returns the 422 // error from the codec. 423 status_t getColorAspectsAndDataSpaceForVideoDecoder( 424 int32_t width, int32_t height, const sp<AMessage> &configFormat, 425 sp<AMessage> &outputFormat, android_dataspace *dataSpace); 426 427 // sets color aspects for the video encoder assuming bytebuffer mode for certain |configFormat| 428 // and sets resulting color config into |outputFormat|. For mediarecorder, also set dataspace 429 // into |inputFormat|. Returns the error from the codec. 430 status_t setColorAspectsForVideoEncoder( 431 const sp<AMessage> &configFormat, 432 sp<AMessage> &outputFormat, sp<AMessage> &inputFormat); 433 434 // sets color aspects for the video encoder in surface mode. This basically sets the default 435 // video values for unspecified aspects and sets the dataspace to use in the input format. 436 // Also sets the dataspace into |dataSpace|. 437 // Returns any codec errors during this configuration, except for optional steps. 438 status_t setInitialColorAspectsForVideoEncoderSurfaceAndGetDataSpace( 439 android_dataspace *dataSpace /* nonnull */); 440 441 // gets color aspects for the video encoder input port and sets them into the |format|. 442 // Returns any codec errors. 443 status_t getInputColorAspectsForVideoEncoder(sp<AMessage> &format); 444 445 // updates the encoder output format with |aspects| defaulting to |dataSpace| for 446 // unspecified values. 447 void onDataSpaceChanged(android_dataspace dataSpace, const ColorAspects &aspects); 448 449 // notifies the codec that the config with |configIndex| has changed, the value 450 // can be queried by OMX getConfig, and the config should be applied to the next 451 // output buffer notified after this callback. 452 void onConfigUpdate(OMX_INDEXTYPE configIndex); 453 454 // gets index or sets it to 0 on error. Returns error from codec. 455 status_t initDescribeHDRStaticInfoIndex(); 456 457 // sets HDR static metadata for the video encoder/decoder based on |configFormat|, and 458 // sets resulting HDRStaticInfo config into |outputFormat|. Returns error from the codec. 459 status_t setHDRStaticInfoForVideoCodec( 460 OMX_U32 portIndex, const sp<AMessage> &configFormat, sp<AMessage> &outputFormat); 461 462 // sets |params|. Returns the codec error. 463 status_t setHDRStaticInfo(const DescribeHDRStaticInfoParams ¶ms); 464 465 // sets |hdr10PlusInfo|. Returns the codec error. 466 status_t setHdr10PlusInfo(const sp<ABuffer> &hdr10PlusInfo); 467 468 // gets |params|. Returns the codec error. 469 status_t getHDRStaticInfo(DescribeHDRStaticInfoParams ¶ms); 470 471 // gets HDR static information for the video encoder/decoder port and sets them into |format|. 472 status_t getHDRStaticInfoForVideoCodec(OMX_U32 portIndex, sp<AMessage> &format); 473 474 // gets DescribeHDR10PlusInfoParams params. If |paramSizeUsed| is zero, it's 475 // possible that the returned DescribeHDR10PlusInfoParams only has the 476 // nParamSizeUsed field updated, because the size of the storage is insufficient. 477 // In this case, getHDR10PlusInfo() should be called again with |paramSizeUsed| 478 // specified to the previous returned value. 479 DescribeHDR10PlusInfoParams* getHDR10PlusInfo(size_t paramSizeUsed = 0); 480 481 typedef struct drcParams { 482 int32_t drcCut; 483 int32_t drcBoost; 484 int32_t heavyCompression; 485 int32_t targetRefLevel; 486 int32_t encodedTargetLevel; 487 int32_t effectType; 488 int32_t albumMode; 489 int32_t outputLoudness; 490 } drcParams_t; 491 492 status_t setupAACCodec( 493 bool encoder, 494 int32_t numChannels, int32_t sampleRate, int32_t bitRate, 495 int32_t aacProfile, bool isADTS, int32_t sbrMode, 496 int32_t maxOutputChannelCount, const drcParams_t& drc, 497 int32_t pcmLimiterEnable); 498 499 status_t setupAC3Codec(bool encoder, int32_t numChannels, int32_t sampleRate); 500 501 status_t setupEAC3Codec(bool encoder, int32_t numChannels, int32_t sampleRate); 502 503 status_t setupAC4Codec(bool encoder, int32_t numChannels, int32_t sampleRate); 504 505 status_t selectAudioPortFormat( 506 OMX_U32 portIndex, OMX_AUDIO_CODINGTYPE desiredFormat); 507 508 status_t setupAMRCodec(bool encoder, bool isWAMR, int32_t bitRate); 509 status_t setupG711Codec(bool encoder, int32_t sampleRate, int32_t numChannels); 510 511 status_t setupOpusCodec(bool encoder, int32_t sampleRate, int32_t numChannels); 512 status_t setupFlacCodec( 513 bool encoder, int32_t numChannels, int32_t sampleRate, int32_t compressionLevel, 514 AudioEncoding encoding); 515 516 status_t setupRawAudioFormat( 517 OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels, 518 AudioEncoding encoding = kAudioEncodingPcm16bit); 519 520 status_t setPriority(int32_t priority); 521 status_t setLowLatency(int32_t lowLatency); 522 status_t setLatency(uint32_t latency); 523 status_t getLatency(uint32_t *latency); 524 status_t setTunnelPeek(int32_t tunnelPeek); 525 status_t setTunnelPeekLegacy(int32_t isLegacy); 526 status_t setAudioPresentation(int32_t presentationId, int32_t programId); 527 status_t setOperatingRate(float rateFloat, bool isVideo); 528 status_t getIntraRefreshPeriod(uint32_t *intraRefreshPeriod); 529 status_t setIntraRefreshPeriod(uint32_t intraRefreshPeriod, bool inConfigure); 530 531 // Configures temporal layering based on |msg|. |inConfigure| shall be true iff this is called 532 // during configure() call. on success the configured layering is set in |outputFormat|. If 533 // |outputFormat| is mOutputFormat, it is copied to trigger an output format changed event. 534 status_t configureTemporalLayers( 535 const sp<AMessage> &msg, bool inConfigure, sp<AMessage> &outputFormat); 536 537 status_t setMinBufferSize(OMX_U32 portIndex, size_t size); 538 539 status_t setupMPEG4EncoderParameters(const sp<AMessage> &msg); 540 status_t setupH263EncoderParameters(const sp<AMessage> &msg); 541 status_t setupAVCEncoderParameters(const sp<AMessage> &msg); 542 status_t setupHEVCEncoderParameters(const sp<AMessage> &msg, sp<AMessage> &outputFormat); 543 status_t setupVPXEncoderParameters(const sp<AMessage> &msg, sp<AMessage> &outputFormat); 544 545 status_t verifySupportForProfileAndLevel( 546 OMX_U32 portIndex, int32_t profile, int32_t level); 547 548 status_t configureImageGrid(const sp<AMessage> &msg, sp<AMessage> &outputFormat); 549 status_t configureBitrate( 550 OMX_VIDEO_CONTROLRATETYPE bitrateMode, int32_t bitrate, int32_t quality = 0); 551 void configureEncoderLatency(const sp<AMessage> &msg); 552 553 status_t setupErrorCorrectionParameters(); 554 555 // Returns true iff all buffers on the given port have status 556 // OWNED_BY_US or OWNED_BY_NATIVE_WINDOW. 557 bool allYourBuffersAreBelongToUs(OMX_U32 portIndex); 558 559 bool allYourBuffersAreBelongToUs(); 560 561 void waitUntilAllPossibleNativeWindowBuffersAreReturnedToUs(); 562 563 size_t countBuffersOwnedByComponent(OMX_U32 portIndex) const; 564 size_t countBuffersOwnedByNativeWindow() const; 565 566 void deferMessage(const sp<AMessage> &msg); 567 void processDeferredMessages(); 568 569 void onFrameRendered(int64_t mediaTimeUs, nsecs_t systemNano); 570 // called when we have dequeued a buffer |buf| from the native window to track render info. 571 // |fenceFd| is the dequeue fence, and |info| points to the buffer info where this buffer is 572 // stored. 573 void updateRenderInfoForDequeuedBuffer( 574 ANativeWindowBuffer *buf, int fenceFd, BufferInfo *info); 575 576 // Checks to see if any frames have rendered up until |until|, and to notify client 577 // (MediaCodec) of rendered frames up-until the frame pointed to by |until| or the first 578 // unrendered frame. These frames are removed from the render queue. 579 // If |dropIncomplete| is true, unrendered frames up-until |until| will be dropped from the 580 // queue, allowing all rendered framed up till then to be notified of. 581 // (This will effectively clear the render queue up-until (and including) |until|.) 582 // If |until| is NULL, or is not in the rendered queue, this method will check all frames. 583 void notifyOfRenderedFrames( 584 bool dropIncomplete = false, FrameRenderTracker::Info *until = NULL); 585 586 void onFirstTunnelFrameReady(); 587 588 // Pass |expectedFormat| to print a warning if the format differs from it. 589 // Using sp<> instead of const sp<>& because expectedFormat is likely the current mOutputFormat 590 // which will get updated inside. 591 void onOutputFormatChanged(sp<const AMessage> expectedFormat = NULL); 592 void addKeyFormatChangesToRenderBufferNotification(sp<AMessage> ¬ify); 593 void sendFormatChange(); 594 595 status_t getPortFormat(OMX_U32 portIndex, sp<AMessage> ¬ify); 596 597 void signalError( 598 OMX_ERRORTYPE error = OMX_ErrorUndefined, 599 status_t internalError = UNKNOWN_ERROR); 600 601 status_t requestIDRFrame(); 602 status_t setParameters(const sp<AMessage> ¶ms); 603 604 // set vendor extension parameters specified in params that are supported by the codec 605 status_t setVendorParameters(const sp<AMessage> ¶ms); 606 607 // get vendor extension parameters supported by the codec for a specific port and add it to 608 // |format| 609 status_t getVendorParameters(OMX_U32 portIndex, sp<AMessage> &format); 610 611 // Send EOS on input stream. 612 void onSignalEndOfInputStream(); 613 614 // Force EXEC->IDLE->LOADED shutdown sequence if not stale. 615 void forceStateTransition(int generation); 616 617 DISALLOW_EVIL_CONSTRUCTORS(ACodec); 618 }; 619 620 } // namespace android 621 622 #endif // A_CODEC_H_ 623