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