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