ACodec.h revision 098446ae4100dfd989c452bb67133559aa892cd3
127c174483a8ae9688d5d4897c19074f62c7f1701James Dong/*
227c174483a8ae9688d5d4897c19074f62c7f1701James Dong * Copyright (C) 2010 The Android Open Source Project
327c174483a8ae9688d5d4897c19074f62c7f1701James Dong *
427c174483a8ae9688d5d4897c19074f62c7f1701James Dong * Licensed under the Apache License, Version 2.0 (the "License");
527c174483a8ae9688d5d4897c19074f62c7f1701James Dong * you may not use this file except in compliance with the License.
627c174483a8ae9688d5d4897c19074f62c7f1701James Dong * You may obtain a copy of the License at
727c174483a8ae9688d5d4897c19074f62c7f1701James Dong *
827c174483a8ae9688d5d4897c19074f62c7f1701James Dong *      http://www.apache.org/licenses/LICENSE-2.0
927c174483a8ae9688d5d4897c19074f62c7f1701James Dong *
1027c174483a8ae9688d5d4897c19074f62c7f1701James Dong * Unless required by applicable law or agreed to in writing, software
1127c174483a8ae9688d5d4897c19074f62c7f1701James Dong * distributed under the License is distributed on an "AS IS" BASIS,
1227c174483a8ae9688d5d4897c19074f62c7f1701James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1327c174483a8ae9688d5d4897c19074f62c7f1701James Dong * See the License for the specific language governing permissions and
1427c174483a8ae9688d5d4897c19074f62c7f1701James Dong * limitations under the License.
1527c174483a8ae9688d5d4897c19074f62c7f1701James Dong */
1627c174483a8ae9688d5d4897c19074f62c7f1701James Dong
17f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#ifndef A_CODEC_H_
18f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
19f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#define A_CODEC_H_
20f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
21f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#include <stdint.h>
22f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#include <android/native_window.h>
23054219874873b41f1c815552987c10465c34ba2bLajos Molnar#include <media/hardware/MetadataBufferType.h>
24f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#include <media/IOMX.h>
25f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#include <media/stagefright/foundation/AHierarchicalStateMachine.h>
2605ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar#include <media/stagefright/CodecBase.h>
2790fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar#include <media/stagefright/FrameRenderTracker.h>
285b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnar#include <media/stagefright/MediaDefs.h>
298b71241ce7353731ab75322c46e090ee35014a33Marco Nelissen#include <media/stagefright/SkipCutBuffer.h>
30a63141af8f036bda0b8f7800107ca8a0e0623135Lajos Molnar#include <utils/NativeHandle.h>
315778822d86b0337407514b9372562b86edfa91cdAndreas Huber#include <OMX_Audio.h>
32f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
33d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber#define TRACK_BUFFER_TIMING     0
34d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber
35f933441648ef6a71dee783d733aac17b9508b452Andreas Hubernamespace android {
36f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
37f933441648ef6a71dee783d733aac17b9508b452Andreas Huberstruct ABuffer;
38f933441648ef6a71dee783d733aac17b9508b452Andreas Huberstruct MemoryDealer;
3973dd808754c641fe798273d356ee38368715fa7bLajos Molnarstruct DescribeColorFormat2Params;
405b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnarstruct DataConverter;
41f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
4205ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnarstruct ACodec : public AHierarchicalStateMachine, public CodecBase {
43f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    ACodec();
44f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
4505ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void setNotificationMessage(const sp<AMessage> &msg);
4605ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar
47f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    void initiateSetup(const sp<AMessage> &msg);
48f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
4905ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void initiateAllocateComponent(const sp<AMessage> &msg);
5005ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void initiateConfigureComponent(const sp<AMessage> &msg);
5105ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void initiateCreateInputSurface();
528f469e18c307cb9dc0d16ed9225972aa8be4516fChong Zhang    virtual void initiateSetInputSurface(const sp<PersistentSurface> &surface);
5305ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void initiateStart();
5405ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void initiateShutdown(bool keepComponentAllocated = false);
5505ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar
565b05e49e6550cb2abf1a88272d6cd460b8957176Lajos Molnar    virtual status_t queryCapabilities(
575b05e49e6550cb2abf1a88272d6cd460b8957176Lajos Molnar            const AString &name, const AString &mime, bool isEncoder,
585b05e49e6550cb2abf1a88272d6cd460b8957176Lajos Molnar            sp<MediaCodecInfo::Capabilities> *caps);
595b05e49e6550cb2abf1a88272d6cd460b8957176Lajos Molnar
601dcdfead2971c1fa7c02f24ba86f706890c9f99eLajos Molnar    virtual status_t setSurface(const sp<Surface> &surface);
611dcdfead2971c1fa7c02f24ba86f706890c9f99eLajos Molnar
6205ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void signalFlush();
6305ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void signalResume();
64a2eb22c1de262aa3fa7c356537ac2fe165afdf3dAndreas Huber
6505ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void signalSetParameters(const sp<AMessage> &msg);
6605ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void signalEndOfInputStream();
6705ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void signalRequestIDRFrame();
685778822d86b0337407514b9372562b86edfa91cdAndreas Huber
6905ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    // AHierarchicalStateMachine implements the message handling
7005ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    virtual void onMessageReceived(const sp<AMessage> &msg) {
7105ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar        handleMessage(msg);
7205ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    }
73496238cc7551d414067dcbbb4fe3bd801f205f95Andreas Huber
7405ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar    struct PortDescription : public CodecBase::PortDescription {
75eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber        size_t countBuffers();
76eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber        IOMX::buffer_id bufferIDAt(size_t index) const;
77eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber        sp<ABuffer> bufferAt(size_t index) const;
78a63141af8f036bda0b8f7800107ca8a0e0623135Lajos Molnar        sp<NativeHandle> handleAt(size_t index) const;
7986b997dcf1101cdd259460fb4f82204200a9a993Ronghua Wu        sp<RefBase> memRefAt(size_t index) const;
80eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber
81eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber    private:
82eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber        friend struct ACodec;
83eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber
84eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber        Vector<IOMX::buffer_id> mBufferIDs;
85eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber        Vector<sp<ABuffer> > mBuffers;
86a63141af8f036bda0b8f7800107ca8a0e0623135Lajos Molnar        Vector<sp<NativeHandle> > mHandles;
8786b997dcf1101cdd259460fb4f82204200a9a993Ronghua Wu        Vector<sp<RefBase> > mMemRefs;
88eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber
89eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber        PortDescription();
90a63141af8f036bda0b8f7800107ca8a0e0623135Lajos Molnar        void addBuffer(
91a63141af8f036bda0b8f7800107ca8a0e0623135Lajos Molnar                IOMX::buffer_id id, const sp<ABuffer> &buffer,
92a63141af8f036bda0b8f7800107ca8a0e0623135Lajos Molnar                const sp<NativeHandle> &handle, const sp<RefBase> &memRef);
93eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber
94eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber        DISALLOW_EVIL_CONSTRUCTORS(PortDescription);
95eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber    };
96eb61431af13741aa8b7e57a39f69bba5a6c190dcAndreas Huber
97229d242665c612fd97431d1e7ac004823b47f181Lajos Molnar    static bool isFlexibleColorFormat(
98a147b4f91143d9f2fb608e22f9fca14bbd029573Lajos Molnar            const sp<IOMX> &omx, IOMX::node_id node,
990d09182a1dde960f7acda1c28469e5deead1b996Lajos Molnar            uint32_t colorFormat, bool usingNativeBuffers, OMX_U32 *flexibleEquivalent);
100a147b4f91143d9f2fb608e22f9fca14bbd029573Lajos Molnar
101a147b4f91143d9f2fb608e22f9fca14bbd029573Lajos Molnar    // Returns 0 if configuration is not supported.  NOTE: this is treated by
102a147b4f91143d9f2fb608e22f9fca14bbd029573Lajos Molnar    // some OMX components as auto level, and by others as invalid level.
103a147b4f91143d9f2fb608e22f9fca14bbd029573Lajos Molnar    static int /* OMX_VIDEO_AVCLEVELTYPE */ getAVCLevelFor(
104a147b4f91143d9f2fb608e22f9fca14bbd029573Lajos Molnar            int width, int height, int rate, int bitrate,
105a147b4f91143d9f2fb608e22f9fca14bbd029573Lajos Molnar            OMX_VIDEO_AVCPROFILETYPE profile = OMX_VIDEO_AVCProfileBaseline);
106229d242665c612fd97431d1e7ac004823b47f181Lajos Molnar
107b60521e269e5aeca773853dfeb150e9a512c7334Lajos Molnar    // Quirk still supported, even though deprecated
108b60521e269e5aeca773853dfeb150e9a512c7334Lajos Molnar    enum Quirks {
109b60521e269e5aeca773853dfeb150e9a512c7334Lajos Molnar        kRequiresAllocateBufferOnInputPorts   = 1,
110b60521e269e5aeca773853dfeb150e9a512c7334Lajos Molnar        kRequiresAllocateBufferOnOutputPorts  = 2,
111b60521e269e5aeca773853dfeb150e9a512c7334Lajos Molnar    };
112b60521e269e5aeca773853dfeb150e9a512c7334Lajos Molnar
113a485208faef579d3d20ee56f29e81d9a5e32e14dLajos Molnar    static status_t getOMXChannelMapping(size_t numChannels, OMX_AUDIO_CHANNELTYPE map[]);
114a485208faef579d3d20ee56f29e81d9a5e32e14dLajos Molnar
115f933441648ef6a71dee783d733aac17b9508b452Andreas Huberprotected:
116f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual ~ACodec();
117f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
118f933441648ef6a71dee783d733aac17b9508b452Andreas Huberprivate:
119f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct BaseState;
120f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct UninitializedState;
121c95c2ddcdfc974f42408a377fbe2de51b94a8c94Andreas Huber    struct LoadedState;
122f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct LoadedToIdleState;
123f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct IdleToExecutingState;
124f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct ExecutingState;
125f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct OutputPortSettingsChangedState;
126f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct ExecutingToIdleState;
127f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct IdleToLoadedState;
128f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct FlushingState;
129ac0230da14a3d223c2144b165a3a163e8519d239Andreas Huber    struct DeathNotifier;
130f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
131f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    enum {
132f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kWhatSetup                   = 'setu',
133f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kWhatOMXMessage              = 'omx ',
134e421a32aa696cd8abbf8fdc97cc8f37dbf372cacLajos Molnar        // same as kWhatOMXMessage - but only used with
135e421a32aa696cd8abbf8fdc97cc8f37dbf372cacLajos Molnar        // handleMessage during OMX message-list handling
136e421a32aa696cd8abbf8fdc97cc8f37dbf372cacLajos Molnar        kWhatOMXMessageItem          = 'omxI',
13726a48f304a8754d655e554178ffb6d7ba4c5aac3Lajos Molnar        kWhatOMXMessageList          = 'omxL',
138f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kWhatInputBufferFilled       = 'inpF',
139f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kWhatOutputBufferDrained     = 'outD',
140f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kWhatShutdown                = 'shut',
141f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kWhatFlush                   = 'flus',
142f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kWhatResume                  = 'resm',
143f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kWhatDrainDeferredMessages   = 'drai',
1445778822d86b0337407514b9372562b86edfa91cdAndreas Huber        kWhatAllocateComponent       = 'allo',
1455778822d86b0337407514b9372562b86edfa91cdAndreas Huber        kWhatConfigureComponent      = 'conf',
1461dcdfead2971c1fa7c02f24ba86f706890c9f99eLajos Molnar        kWhatSetSurface              = 'setS',
1477cd58537932ef6f481f68be0b9c597a89cebdfecAndy McFadden        kWhatCreateInputSurface      = 'cisf',
1488f469e18c307cb9dc0d16ed9225972aa8be4516fChong Zhang        kWhatSetInputSurface         = 'sisf',
1497cd58537932ef6f481f68be0b9c597a89cebdfecAndy McFadden        kWhatSignalEndOfInputStream  = 'eois',
1505778822d86b0337407514b9372562b86edfa91cdAndreas Huber        kWhatStart                   = 'star',
151496238cc7551d414067dcbbb4fe3bd801f205f95Andreas Huber        kWhatRequestIDRFrame         = 'ridr',
152a2eb22c1de262aa3fa7c356537ac2fe165afdf3dAndreas Huber        kWhatSetParameters           = 'setP',
153054219874873b41f1c815552987c10465c34ba2bLajos Molnar        kWhatSubmitOutputMetadataBufferIfEOS = 'subm',
15405ca3bfb847ff3c1980f2f0922a4d494c0e7ebabLajos Molnar        kWhatOMXDied                 = 'OMXd',
15530358faf33fb9b638257b017fadb4c5f7352d903Lajos Molnar        kWhatReleaseCodecInstance    = 'relC',
156f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    };
157f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
158f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    enum {
159f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kPortIndexInput  = 0,
160f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        kPortIndexOutput = 1
161f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    };
162f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
163ed3e3e046840d5bf1ca84a8c0cc097425e89d6d6Andreas Huber    enum {
1640167414e261f88a96b5e4bf6cb592e6ca11e5a95Andreas Huber        kFlagIsSecure                                 = 1,
1650167414e261f88a96b5e4bf6cb592e6ca11e5a95Andreas Huber        kFlagPushBlankBuffersToNativeWindowOnShutdown = 2,
1661713460104b86f6be3a5d9993d9ace864d889b2dChong Zhang        kFlagIsGrallocUsageProtected                  = 4,
167ed3e3e046840d5bf1ca84a8c0cc097425e89d6d6Andreas Huber    };
168ed3e3e046840d5bf1ca84a8c0cc097425e89d6d6Andreas Huber
169f42917964a76720932b23e67a05d034cd0cf346bChong Zhang    enum {
170f42917964a76720932b23e67a05d034cd0cf346bChong Zhang        kVideoGrallocUsage = (GRALLOC_USAGE_HW_TEXTURE
171f42917964a76720932b23e67a05d034cd0cf346bChong Zhang                            | GRALLOC_USAGE_HW_COMPOSER
172f42917964a76720932b23e67a05d034cd0cf346bChong Zhang                            | GRALLOC_USAGE_EXTERNAL_DISP),
173f42917964a76720932b23e67a05d034cd0cf346bChong Zhang    };
174f42917964a76720932b23e67a05d034cd0cf346bChong Zhang
175f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    struct BufferInfo {
176f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        enum Status {
177f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            OWNED_BY_US,
178f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            OWNED_BY_COMPONENT,
179f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            OWNED_BY_UPSTREAM,
180f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            OWNED_BY_DOWNSTREAM,
181f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            OWNED_BY_NATIVE_WINDOW,
1820806340688c937e7b78c2d89db3809274130df4eLajos Molnar            UNRECOGNIZED,            // not a tracked buffer
183f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        };
184f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
1850806340688c937e7b78c2d89db3809274130df4eLajos Molnar        static inline Status getSafeStatus(BufferInfo *info) {
1860806340688c937e7b78c2d89db3809274130df4eLajos Molnar            return info == NULL ? UNRECOGNIZED : info->mStatus;
1870806340688c937e7b78c2d89db3809274130df4eLajos Molnar        }
1880806340688c937e7b78c2d89db3809274130df4eLajos Molnar
189f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        IOMX::buffer_id mBufferID;
190f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        Status mStatus;
191054e7347cc60ad4b9dd2e8f456406f122f9f5879Lajos Molnar        unsigned mDequeuedAt;
192f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
1935b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnar        sp<ABuffer> mData;      // the client's buffer; if not using data conversion, this is the
1945b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnar                                // codec buffer; otherwise, it is allocated separately
1955b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnar        sp<RefBase> mMemRef;    // and a reference to the IMemory, so it does not go away
1965b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnar        sp<ABuffer> mCodecData; // the codec's buffer
1975b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnar        sp<RefBase> mCodecRef;  // and a reference to the IMemory
198f933441648ef6a71dee783d733aac17b9508b452Andreas Huber        sp<GraphicBuffer> mGraphicBuffer;
199a63141af8f036bda0b8f7800107ca8a0e0623135Lajos Molnar        sp<NativeHandle> mNativeHandle;
20015ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar        int mFenceFd;
20190fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar        FrameRenderTracker::Info *mRenderInfo;
20215ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar
20315ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar        // The following field and 4 methods are used for debugging only
20415ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar        bool mIsReadFence;
20515ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar        // Store |fenceFd| and set read/write flag. Log error, if there is already a fence stored.
20615ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar        void setReadFence(int fenceFd, const char *dbg);
20715ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar        void setWriteFence(int fenceFd, const char *dbg);
20815ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar        // Log error, if the current fence is not a read/write fence.
20915ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar        void checkReadFence(const char *dbg);
21015ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar        void checkWriteFence(const char *dbg);
211f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    };
212f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
2130806340688c937e7b78c2d89db3809274130df4eLajos Molnar    static const char *_asString(BufferInfo::Status s);
2140806340688c937e7b78c2d89db3809274130df4eLajos Molnar    void dumpBuffers(OMX_U32 portIndex);
2150806340688c937e7b78c2d89db3809274130df4eLajos Molnar
21615ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar    // If |fd| is non-negative, waits for fence with |fd| and logs an error if it fails. Returns
21715ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar    // the error code or OK on success. If |fd| is negative, it returns OK
21815ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar    status_t waitForFence(int fd, const char *dbg);
21915ab4996019387f27a48b81cb4774c21502bc0e5Lajos Molnar
220d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber#if TRACK_BUFFER_TIMING
221d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber    struct BufferStats {
222d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber        int64_t mEmptyBufferTimeUs;
223d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber        int64_t mFillBufferDoneTimeUs;
224d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber    };
225d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber
226d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber    KeyedVector<int64_t, BufferStats> mBufferStats;
227d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber#endif
228d7bee3a9d2ad76d073d91f0ee36d5ac5f9df480cAndreas Huber
229f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<AMessage> mNotify;
230f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
231f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<UninitializedState> mUninitializedState;
232c95c2ddcdfc974f42408a377fbe2de51b94a8c94Andreas Huber    sp<LoadedState> mLoadedState;
233f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<LoadedToIdleState> mLoadedToIdleState;
234f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<IdleToExecutingState> mIdleToExecutingState;
235f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<ExecutingState> mExecutingState;
236f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<OutputPortSettingsChangedState> mOutputPortSettingsChangedState;
237f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<ExecutingToIdleState> mExecutingToIdleState;
238f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<IdleToLoadedState> mIdleToLoadedState;
239f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<FlushingState> mFlushingState;
2408b71241ce7353731ab75322c46e090ee35014a33Marco Nelissen    sp<SkipCutBuffer> mSkipCutBuffer;
241f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
242f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    AString mComponentName;
243ed3e3e046840d5bf1ca84a8c0cc097425e89d6d6Andreas Huber    uint32_t mFlags;
244afc16d667afa23f5aa00154ccad62f8c45cf5419Andreas Huber    uint32_t mQuirks;
245f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<IOMX> mOMX;
24623858874bbce68fb5ac83250087fa7788c97dd12Marco Nelissen    sp<IBinder> mNodeBinder;
247f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    IOMX::node_id mNode;
248f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<MemoryDealer> mDealer[2];
249f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
250b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    bool mUsingNativeWindow;
251f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<ANativeWindow> mNativeWindow;
252e3635355e4cae5af7550b49888c6a0e3530b8aeaLajos Molnar    int mNativeWindowUsageBits;
253fe73b95aaef79ad312d9dfdb6c8873bd50c6c19eLajos Molnar    android_native_rect_t mLastNativeWindowCrop;
254fe73b95aaef79ad312d9dfdb6c8873bd50c6c19eLajos Molnar    int32_t mLastNativeWindowDataSpace;
255b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    sp<AMessage> mConfigFormat;
256e0381245dff04aa823a59aa8b85869eddab0f39fLajos Molnar    sp<AMessage> mInputFormat;
257e0381245dff04aa823a59aa8b85869eddab0f39fLajos Molnar    sp<AMessage> mOutputFormat;
258697aedf61d6180e72102068a969383018eedfa1eLajos Molnar
259697aedf61d6180e72102068a969383018eedfa1eLajos Molnar    // Initial output format + configuration params that is reused as the base for all subsequent
260697aedf61d6180e72102068a969383018eedfa1eLajos Molnar    // format updates. This will equal to mOutputFormat until the first actual frame is received.
2614e865a3cfe4c955e0890321a6b488cf661808b63Lajos Molnar    sp<AMessage> mBaseOutputFormat;
262f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
26390fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    FrameRenderTracker mRenderTracker; // render information for buffers rendered by ACodec
264f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    Vector<BufferInfo> mBuffers[2];
265f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    bool mPortEOS[2];
266dc9bacd838442a524585887e6ea6696836be2edaAndreas Huber    status_t mInputEOSResult;
267f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
268f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    List<sp<AMessage> > mDeferredQueue;
269f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
270b0a4b9e917bd26bf366fb20c48315f51285c18f9Lajos Molnar    sp<AMessage> mLastOutputFormat;
2718db8813d39e3c8b5fbd580dfc3062830744afd63Ronghua Wu    bool mIsVideo;
2725778822d86b0337407514b9372562b86edfa91cdAndreas Huber    bool mIsEncoder;
273346de3c26a8fbd0fa0c8102f4a21ea4dcee4432aChong Zhang    bool mFatalError;
274c95c2ddcdfc974f42408a377fbe2de51b94a8c94Andreas Huber    bool mShutdownInProgress;
27554b0bc74e051bd7df10cd657b481d88db6cdaa27Lajos Molnar    bool mExplicitShutdown;
276f88dc1865408506f69c858818ea05f5248ff4462Hangyu Kuang    bool mIsLegacyVP9Decoder;
277c95c2ddcdfc974f42408a377fbe2de51b94a8c94Andreas Huber
278c95c2ddcdfc974f42408a377fbe2de51b94a8c94Andreas Huber    // If "mKeepComponentAllocated" we only transition back to Loaded state
279c95c2ddcdfc974f42408a377fbe2de51b94a8c94Andreas Huber    // and do not release the component instance.
280c95c2ddcdfc974f42408a377fbe2de51b94a8c94Andreas Huber    bool mKeepComponentAllocated;
281c95c2ddcdfc974f42408a377fbe2de51b94a8c94Andreas Huber
2829806555d3930be43e11106281dee354820ac1c88Andreas Huber    int32_t mEncoderDelay;
2839806555d3930be43e11106281dee354820ac1c88Andreas Huber    int32_t mEncoderPadding;
284e9e63bcf6c36351f1129b0bdc5e93f17f0f9f0b4Chong Zhang    int32_t mRotationDegrees;
2859806555d3930be43e11106281dee354820ac1c88Andreas Huber
2869806555d3930be43e11106281dee354820ac1c88Andreas Huber    bool mChannelMaskPresent;
2879806555d3930be43e11106281dee354820ac1c88Andreas Huber    int32_t mChannelMask;
288054e7347cc60ad4b9dd2e8f456406f122f9f5879Lajos Molnar    unsigned mDequeueCounter;
289054219874873b41f1c815552987c10465c34ba2bLajos Molnar    MetadataBufferType mInputMetadataType;
290054219874873b41f1c815552987c10465c34ba2bLajos Molnar    MetadataBufferType mOutputMetadataType;
291011778fd4cb9606b68bfea1ed483d73c04fc6dcdLajos Molnar    bool mLegacyAdaptiveExperiment;
292054219874873b41f1c815552987c10465c34ba2bLajos Molnar    int32_t mMetadataBuffersToSubmit;
293e257e5ebefdd50f808ee3b4d1596db261c9b62ddLajos Molnar    size_t mNumUndequeuedBuffers;
2945b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnar    sp<DataConverter> mConverter[2];
2959806555d3930be43e11106281dee354820ac1c88Andreas Huber
296a61285dcf1da8a2cf40c499ee3a7b9fc4d74ac58Andreas Huber    int64_t mRepeatFrameDelayUs;
29794ee4b708acfa941581160b267afb79192b1d816Chong Zhang    int64_t mMaxPtsGapUs;
29837b2b389139ed638831e49708c947863eef631efRonghua Wu    float mMaxFps;
299a61285dcf1da8a2cf40c499ee3a7b9fc4d74ac58Andreas Huber
3002c9c8cba8562cc3a27532e4cd348912cc78d8d98Chong Zhang    int64_t mTimePerFrameUs;
3012c9c8cba8562cc3a27532e4cd348912cc78d8d98Chong Zhang    int64_t mTimePerCaptureUs;
3022c9c8cba8562cc3a27532e4cd348912cc78d8d98Chong Zhang
30372cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang    bool mCreateInputBuffersSuspended;
30472cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang
305ab76066c11e988ca3d3a5d6d74dd510ae080322eRachad    bool mTunneled;
306ab76066c11e988ca3d3a5d6d74dd510ae080322eRachad
3078338519ba2d8d731072c4edf7b9953787ce834cfLajos Molnar    OMX_INDEXTYPE mDescribeColorAspectsIndex;
308db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang    OMX_INDEXTYPE mDescribeHDRStaticInfoIndex;
3098338519ba2d8d731072c4edf7b9953787ce834cfLajos Molnar
3100dbe5a9321b24b6883fbb2fe97cd9d525128b0b5James Dong    status_t setCyclicIntraMacroblockRefresh(const sp<AMessage> &msg, int32_t mode);
311f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t allocateBuffersOnPort(OMX_U32 portIndex);
312f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t freeBuffersOnPort(OMX_U32 portIndex);
313f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t freeBuffer(OMX_U32 portIndex, size_t i);
314f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
3151dcdfead2971c1fa7c02f24ba86f706890c9f99eLajos Molnar    status_t handleSetSurface(const sp<Surface> &surface);
316e3635355e4cae5af7550b49888c6a0e3530b8aeaLajos Molnar    status_t setupNativeWindowSizeFormatAndUsage(
317098446ae4100dfd989c452bb67133559aa892cd3Lajos Molnar            ANativeWindow *nativeWindow /* nonnull */, int *finalUsage /* nonnull */,
318098446ae4100dfd989c452bb67133559aa892cd3Lajos Molnar            bool reconnect);
3191dcdfead2971c1fa7c02f24ba86f706890c9f99eLajos Molnar
320054e7347cc60ad4b9dd2e8f456406f122f9f5879Lajos Molnar    status_t configureOutputBuffersFromNativeWindow(
321054e7347cc60ad4b9dd2e8f456406f122f9f5879Lajos Molnar            OMX_U32 *nBufferCount, OMX_U32 *nBufferSize,
322098446ae4100dfd989c452bb67133559aa892cd3Lajos Molnar            OMX_U32 *nMinUndequeuedBuffers, bool preregister);
323054219874873b41f1c815552987c10465c34ba2bLajos Molnar    status_t allocateOutputMetadataBuffers();
324054219874873b41f1c815552987c10465c34ba2bLajos Molnar    status_t submitOutputMetadataBuffer();
325054219874873b41f1c815552987c10465c34ba2bLajos Molnar    void signalSubmitOutputMetadataBufferIfEOS_workaround();
326f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t allocateOutputBuffersFromNativeWindow();
327f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t cancelBufferToNativeWindow(BufferInfo *info);
328349d3fcb4afacf754f7b5b5186d2f258f5bf35e7Andreas Huber    status_t freeOutputBuffersNotOwnedByComponent();
329f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    BufferInfo *dequeueBufferFromNativeWindow();
330f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
331054219874873b41f1c815552987c10465c34ba2bLajos Molnar    inline bool storingMetadataInDecodedBuffers() {
332054219874873b41f1c815552987c10465c34ba2bLajos Molnar        return mOutputMetadataType >= 0 && !mIsEncoder;
333054219874873b41f1c815552987c10465c34ba2bLajos Molnar    }
334054219874873b41f1c815552987c10465c34ba2bLajos Molnar
335054219874873b41f1c815552987c10465c34ba2bLajos Molnar    inline bool usingMetadataOnEncoderOutput() {
336054219874873b41f1c815552987c10465c34ba2bLajos Molnar        return mOutputMetadataType >= 0 && mIsEncoder;
337054219874873b41f1c815552987c10465c34ba2bLajos Molnar    }
338054219874873b41f1c815552987c10465c34ba2bLajos Molnar
339f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    BufferInfo *findBufferByID(
340f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            uint32_t portIndex, IOMX::buffer_id bufferID,
341f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            ssize_t *index = NULL);
342f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
3435778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t setComponentRole(bool isEncoder, const char *mime);
3445b05e49e6550cb2abf1a88272d6cd460b8957176Lajos Molnar    static const char *getComponentRole(bool isEncoder, const char *mime);
3455b05e49e6550cb2abf1a88272d6cd460b8957176Lajos Molnar    static status_t setComponentRole(
3465b05e49e6550cb2abf1a88272d6cd460b8957176Lajos Molnar            const sp<IOMX> &omx, IOMX::node_id node, const char *role);
3475b05e49e6550cb2abf1a88272d6cd460b8957176Lajos Molnar
3485778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t configureCodec(const char *mime, const sp<AMessage> &msg);
349f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
35097827bd7c7e64dec22c8fe0f9e734a3c432ad7eeRachad    status_t configureTunneledVideoPlayback(int32_t audioHwSync,
3515a446aafff3020d607ad6fb14cc7ae76dd8f7947Rachad            const sp<ANativeWindow> &nativeWindow);
3525a446aafff3020d607ad6fb14cc7ae76dd8f7947Rachad
353f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t setVideoPortFormatType(
354f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            OMX_U32 portIndex,
355f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            OMX_VIDEO_CODINGTYPE compressionFormat,
3560d09182a1dde960f7acda1c28469e5deead1b996Lajos Molnar            OMX_COLOR_FORMATTYPE colorFormat,
3570d09182a1dde960f7acda1c28469e5deead1b996Lajos Molnar            bool usingNativeBuffers = false);
358f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
3590d09182a1dde960f7acda1c28469e5deead1b996Lajos Molnar    status_t setSupportedOutputFormat(bool getLegacyFlexibleFormat);
360f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
361f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t setupVideoDecoder(
362b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            const char *mime, const sp<AMessage> &msg, bool usingNativeBuffers, bool haveSwRenderer,
3638338519ba2d8d731072c4edf7b9953787ce834cfLajos Molnar            sp<AMessage> &outputformat);
364f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
3655778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t setupVideoEncoder(
366b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            const char *mime, const sp<AMessage> &msg,
367b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            sp<AMessage> &outputformat, sp<AMessage> &inputformat);
3685778822d86b0337407514b9372562b86edfa91cdAndreas Huber
369f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t setVideoFormatOnPort(
370f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            OMX_U32 portIndex,
371f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            int32_t width, int32_t height,
37278b01639c08fe5e7e9c1be5e9dc5de560f1383f9Rachad            OMX_VIDEO_CODINGTYPE compressionFormat, float frameRate = -1.0);
373f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
374b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // gets index or sets it to 0 on error. Returns error from codec.
375b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    status_t initDescribeColorAspectsIndex();
376b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar
377b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // sets |params|. If |readBack| is true, it re-gets them afterwards if set succeeded.
378b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // returns the codec error.
379b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    status_t setCodecColorAspects(DescribeColorAspectsParams &params, bool readBack = false);
380b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar
381b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // gets |params|; returns the codec error. |param| should not change on error.
382b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    status_t getCodecColorAspects(DescribeColorAspectsParams &params);
383b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar
384b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // gets dataspace guidance from codec and platform. |params| should be set up with the color
385b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // aspects to use. If |tryCodec| is true, the codec is queried first. If it succeeds, we
386b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // return OK. Otherwise, we fall back to the platform guidance and return the codec error;
387b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // though, we return OK if the codec failed with UNSUPPORTED, as codec guidance is optional.
388b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    status_t getDataSpace(
389b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            DescribeColorAspectsParams &params, android_dataspace *dataSpace /* nonnull */,
390b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            bool tryCodec);
391b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar
392b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // sets color aspects for the encoder for certain |width/height| based on |configFormat|, and
393b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // set resulting color config into |outputFormat|. If |usingNativeWindow| is true, we use
394b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // video defaults if config is unspecified. Returns error from the codec.
395b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    status_t setColorAspectsForVideoDecoder(
396b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            int32_t width, int32_t height, bool usingNativeWindow,
397b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            const sp<AMessage> &configFormat, sp<AMessage> &outputFormat);
398b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar
399b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // gets color aspects for the encoder for certain |width/height| based on |configFormat|, and
400b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // set resulting color config into |outputFormat|. If |dataSpace| is non-null, it requests
401b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // dataspace guidance from the codec and platform and sets it into |dataSpace|. Returns the
402b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // error from the codec.
403b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    status_t getColorAspectsAndDataSpaceForVideoDecoder(
404b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            int32_t width, int32_t height, const sp<AMessage> &configFormat,
405b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            sp<AMessage> &outputFormat, android_dataspace *dataSpace);
406b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar
407b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // sets color aspects for the video encoder assuming bytebuffer mode for certain |configFormat|
408b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // and sets resulting color config into |outputFormat|. For mediarecorder, also set dataspace
409b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // into |inputFormat|. Returns the error from the codec.
410b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    status_t setColorAspectsForVideoEncoder(
411b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            const sp<AMessage> &configFormat,
412b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            sp<AMessage> &outputFormat, sp<AMessage> &inputFormat);
413b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar
414b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // sets color aspects for the video encoder in surface mode. This basically sets the default
415b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // video values for unspecified aspects and sets the dataspace to use in the input format.
416b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // Also sets the dataspace into |dataSpace|.
417b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // Returns any codec errors during this configuration, except for optional steps.
418b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    status_t setInitialColorAspectsForVideoEncoderSurfaceAndGetDataSpace(
419b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar            android_dataspace *dataSpace /* nonnull */);
420b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar
421b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // gets color aspects for the video encoder input port and sets them into the |format|.
422b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // Returns any codec errors.
423b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    status_t getInputColorAspectsForVideoEncoder(sp<AMessage> &format);
424b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar
425b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // updates the encoder output format with |aspects| defaulting to |dataSpace| for
426b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    // unspecified values.
427b77d03b62cb743d0faf74b54aa466b4d220b5e61Lajos Molnar    void onDataSpaceChanged(android_dataspace dataSpace, const ColorAspects &aspects);
4288338519ba2d8d731072c4edf7b9953787ce834cfLajos Molnar
429db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang    // gets index or sets it to 0 on error. Returns error from codec.
430db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang    status_t initDescribeHDRStaticInfoIndex();
431db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang
4325e2f5c10dcedbddd0ea0255f049468760aa09048Hangyu Kuang    // sets HDR static metadata for the video encoder/decoder based on |configFormat|, and
4335e2f5c10dcedbddd0ea0255f049468760aa09048Hangyu Kuang    // sets resulting HDRStaticInfo config into |outputFormat|. Returns error from the codec.
4345e2f5c10dcedbddd0ea0255f049468760aa09048Hangyu Kuang    status_t setHDRStaticInfoForVideoCodec(
4355e2f5c10dcedbddd0ea0255f049468760aa09048Hangyu Kuang            OMX_U32 portIndex, const sp<AMessage> &configFormat, sp<AMessage> &outputFormat);
436db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang
437db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang    // sets |params|. Returns the codec error.
438db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang    status_t setHDRStaticInfo(const DescribeHDRStaticInfoParams &params);
439db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang
440db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang    // gets |params|. Returns the codec error.
441db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang    status_t getHDRStaticInfo(DescribeHDRStaticInfoParams &params);
442db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang
4435e2f5c10dcedbddd0ea0255f049468760aa09048Hangyu Kuang    // gets HDR static information for the video encoder/decoder port and sets them into |format|.
4445e2f5c10dcedbddd0ea0255f049468760aa09048Hangyu Kuang    status_t getHDRStaticInfoForVideoCodec(OMX_U32 portIndex, sp<AMessage> &format);
445db318d40b90a456311b3920c605e33b763ca79f9Hangyu Kuang
4468045853d03649f43ea2f7107e7d2dbb9b2d20855Jean-Michel Trivi    typedef struct drcParams {
4478045853d03649f43ea2f7107e7d2dbb9b2d20855Jean-Michel Trivi        int32_t drcCut;
4488045853d03649f43ea2f7107e7d2dbb9b2d20855Jean-Michel Trivi        int32_t drcBoost;
4498045853d03649f43ea2f7107e7d2dbb9b2d20855Jean-Michel Trivi        int32_t heavyCompression;
4508045853d03649f43ea2f7107e7d2dbb9b2d20855Jean-Michel Trivi        int32_t targetRefLevel;
4518045853d03649f43ea2f7107e7d2dbb9b2d20855Jean-Michel Trivi        int32_t encodedTargetLevel;
4528045853d03649f43ea2f7107e7d2dbb9b2d20855Jean-Michel Trivi    } drcParams_t;
4538045853d03649f43ea2f7107e7d2dbb9b2d20855Jean-Michel Trivi
4545778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t setupAACCodec(
4555778822d86b0337407514b9372562b86edfa91cdAndreas Huber            bool encoder,
456ed3e3e046840d5bf1ca84a8c0cc097425e89d6d6Andreas Huber            int32_t numChannels, int32_t sampleRate, int32_t bitRate,
4578045853d03649f43ea2f7107e7d2dbb9b2d20855Jean-Michel Trivi            int32_t aacProfile, bool isADTS, int32_t sbrMode,
4582965f4eb7dceaf1173f0e2d93c11c28293aeead7Chong Zhang            int32_t maxOutputChannelCount, const drcParams_t& drc,
4592965f4eb7dceaf1173f0e2d93c11c28293aeead7Chong Zhang            int32_t pcmLimiterEnable);
4605778822d86b0337407514b9372562b86edfa91cdAndreas Huber
46197358c3e1adaf4a744cad78891a16d12e3e9c88eChangwan Ryu    status_t setupAC3Codec(bool encoder, int32_t numChannels, int32_t sampleRate);
46297358c3e1adaf4a744cad78891a16d12e3e9c88eChangwan Ryu
4638a4728966dc9c78e21c3c93a927707e93c05e5e0Rachad    status_t setupEAC3Codec(bool encoder, int32_t numChannels, int32_t sampleRate);
4648a4728966dc9c78e21c3c93a927707e93c05e5e0Rachad
4655778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t selectAudioPortFormat(
4665778822d86b0337407514b9372562b86edfa91cdAndreas Huber            OMX_U32 portIndex, OMX_AUDIO_CODINGTYPE desiredFormat);
4675778822d86b0337407514b9372562b86edfa91cdAndreas Huber
4685778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t setupAMRCodec(bool encoder, bool isWAMR, int32_t bitRate);
46917c39e708ed657b8fa66f8acce5128e51696915cMarco Nelissen    status_t setupG711Codec(bool encoder, int32_t sampleRate, int32_t numChannels);
470729de186450f78c099637e1fce743fe531862c52Andreas Huber
4712f74ef3cdc192f817ee1121f41765f0852c1d81eJean-Michel Trivi    status_t setupFlacCodec(
4722f74ef3cdc192f817ee1121f41765f0852c1d81eJean-Michel Trivi            bool encoder, int32_t numChannels, int32_t sampleRate, int32_t compressionLevel);
4732f74ef3cdc192f817ee1121f41765f0852c1d81eJean-Michel Trivi
474729de186450f78c099637e1fce743fe531862c52Andreas Huber    status_t setupRawAudioFormat(
4755b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnar            OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels,
4765b4401b28990107bb797dc0d5f3904cf27417e98Lajos Molnar            AudioEncoding encoding = kAudioEncodingPcm16bit);
477729de186450f78c099637e1fce743fe531862c52Andreas Huber
4788b806ea894ca098366629458bfdd1df4866afcdfRonghua Wu    status_t setPriority(int32_t priority);
479ed5554fb1c837f6b1008d3910018c979c57da502Ronghua Wu    status_t setOperatingRate(float rateFloat, bool isVideo);
480870aff9bd2442c8877f5d6b12c73032b5f24535aHangyu Kuang    status_t getIntraRefreshPeriod(uint32_t *intraRefreshPeriod);
481870aff9bd2442c8877f5d6b12c73032b5f24535aHangyu Kuang    status_t setIntraRefreshPeriod(uint32_t intraRefreshPeriod, bool inConfigure);
4828b806ea894ca098366629458bfdd1df4866afcdfRonghua Wu
483f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t setMinBufferSize(OMX_U32 portIndex, size_t size);
484f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
4855778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t setupMPEG4EncoderParameters(const sp<AMessage> &msg);
4865778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t setupH263EncoderParameters(const sp<AMessage> &msg);
4875778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t setupAVCEncoderParameters(const sp<AMessage> &msg);
488c8efda9e9cd61dfe8e486c93fa8940b77cc3ccebRachad    status_t setupHEVCEncoderParameters(const sp<AMessage> &msg);
48989b31a3f670d8bec87bed50aaad9bcd8edec66b6Andreas Huber    status_t setupVPXEncoderParameters(const sp<AMessage> &msg);
4905778822d86b0337407514b9372562b86edfa91cdAndreas Huber
4915778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t verifySupportForProfileAndLevel(int32_t profile, int32_t level);
49296076964863ee6887f0bed9d0f11f424b48ab9b9Andreas Huber
49396076964863ee6887f0bed9d0f11f424b48ab9b9Andreas Huber    status_t configureBitrate(
49496076964863ee6887f0bed9d0f11f424b48ab9b9Andreas Huber            int32_t bitrate, OMX_VIDEO_CONTROLRATETYPE bitrateMode);
49596076964863ee6887f0bed9d0f11f424b48ab9b9Andreas Huber
4965778822d86b0337407514b9372562b86edfa91cdAndreas Huber    status_t setupErrorCorrectionParameters();
4975778822d86b0337407514b9372562b86edfa91cdAndreas Huber
498f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    status_t initNativeWindow();
499f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
5007e7013392e302a28364df1dcee79b82ad90978b4Andreas Huber    // Returns true iff all buffers on the given port have status
5017e7013392e302a28364df1dcee79b82ad90978b4Andreas Huber    // OWNED_BY_US or OWNED_BY_NATIVE_WINDOW.
502f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    bool allYourBuffersAreBelongToUs(OMX_U32 portIndex);
503f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
504f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    bool allYourBuffersAreBelongToUs();
505f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
5067e7013392e302a28364df1dcee79b82ad90978b4Andreas Huber    void waitUntilAllPossibleNativeWindowBuffersAreReturnedToUs();
5077e7013392e302a28364df1dcee79b82ad90978b4Andreas Huber
508d3d822204249eaca4259bdf46f6f0357b96e8e21Andreas Huber    size_t countBuffersOwnedByComponent(OMX_U32 portIndex) const;
5097e7013392e302a28364df1dcee79b82ad90978b4Andreas Huber    size_t countBuffersOwnedByNativeWindow() const;
510d3d822204249eaca4259bdf46f6f0357b96e8e21Andreas Huber
511f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    void deferMessage(const sp<AMessage> &msg);
512f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    void processDeferredMessages();
513f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
51490fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    void onFrameRendered(int64_t mediaTimeUs, nsecs_t systemNano);
51590fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // called when we have dequeued a buffer |buf| from the native window to track render info.
51690fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // |fenceFd| is the dequeue fence, and |info| points to the buffer info where this buffer is
51790fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // stored.
51890fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    void updateRenderInfoForDequeuedBuffer(
51990fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar            ANativeWindowBuffer *buf, int fenceFd, BufferInfo *info);
52090fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar
52190fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // Checks to see if any frames have rendered up until |until|, and to notify client
52290fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // (MediaCodec) of rendered frames up-until the frame pointed to by |until| or the first
52390fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // unrendered frame. These frames are removed from the render queue.
52490fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // If |dropIncomplete| is true, unrendered frames up-until |until| will be dropped from the
52590fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // queue, allowing all rendered framed up till then to be notified of.
52690fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // (This will effectively clear the render queue up-until (and including) |until|.)
52790fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    // If |until| is NULL, or is not in the rendered queue, this method will check all frames.
52890fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar    void notifyOfRenderedFrames(
52990fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar            bool dropIncomplete = false, FrameRenderTracker::Info *until = NULL);
53090fcf68fd29f3cb695bd53a830ad984cb7d430c0Lajos Molnar
5311734c7d01c1567568ced29398b23abd601fd44cbLajos Molnar    // Pass |expectedFormat| to print a warning if the format differs from it.
5321734c7d01c1567568ced29398b23abd601fd44cbLajos Molnar    // Using sp<> instead of const sp<>& because expectedFormat is likely the current mOutputFormat
5331734c7d01c1567568ced29398b23abd601fd44cbLajos Molnar    // which will get updated inside.
5341734c7d01c1567568ced29398b23abd601fd44cbLajos Molnar    void onOutputFormatChanged(sp<const AMessage> expectedFormat = NULL);
535b0a4b9e917bd26bf366fb20c48315f51285c18f9Lajos Molnar    void addKeyFormatChangesToRenderBufferNotification(sp<AMessage> &notify);
536b0a4b9e917bd26bf366fb20c48315f51285c18f9Lajos Molnar    void sendFormatChange();
537b0a4b9e917bd26bf366fb20c48315f51285c18f9Lajos Molnar
538e0381245dff04aa823a59aa8b85869eddab0f39fLajos Molnar    status_t getPortFormat(OMX_U32 portIndex, sp<AMessage> &notify);
53931e2508c75018145a8238925ff1a08cbde4e799aAndreas Huber
5405778822d86b0337407514b9372562b86edfa91cdAndreas Huber    void signalError(
5415778822d86b0337407514b9372562b86edfa91cdAndreas Huber            OMX_ERRORTYPE error = OMX_ErrorUndefined,
5425778822d86b0337407514b9372562b86edfa91cdAndreas Huber            status_t internalError = UNKNOWN_ERROR);
543cc54fbaa69c0b69929467449d2c19192f15b5039Andreas Huber
54473dd808754c641fe798273d356ee38368715fa7bLajos Molnar    static bool describeDefaultColorFormat(DescribeColorFormat2Params &describeParams);
545229d242665c612fd97431d1e7ac004823b47f181Lajos Molnar    static bool describeColorFormat(
546229d242665c612fd97431d1e7ac004823b47f181Lajos Molnar        const sp<IOMX> &omx, IOMX::node_id node,
54773dd808754c641fe798273d356ee38368715fa7bLajos Molnar        DescribeColorFormat2Params &describeParams);
54803c556ae1eb409ad088c49037e185946c54e1d25Lajos Molnar
549496238cc7551d414067dcbbb4fe3bd801f205f95Andreas Huber    status_t requestIDRFrame();
550a2eb22c1de262aa3fa7c356537ac2fe165afdf3dAndreas Huber    status_t setParameters(const sp<AMessage> &params);
551496238cc7551d414067dcbbb4fe3bd801f205f95Andreas Huber
5526507d14c6d10f93d390de62b9eed267f9b544985Andy McFadden    // Send EOS on input stream.
5536507d14c6d10f93d390de62b9eed267f9b544985Andy McFadden    void onSignalEndOfInputStream();
5546507d14c6d10f93d390de62b9eed267f9b544985Andy McFadden
555f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    DISALLOW_EVIL_CONSTRUCTORS(ACodec);
556f933441648ef6a71dee783d733aac17b9508b452Andreas Huber};
557f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
558f933441648ef6a71dee783d733aac17b9508b452Andreas Huber}  // namespace android
559f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
560f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#endif  // A_CODEC_H_
561