blob: b7bd696f75061e47100db548ecfc5fbee30f4312 [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
2 * Copyright 2018, 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 C2_OMX_NODE_H_
18#define C2_OMX_NODE_H_
19
20#include <atomic>
21
22#include <android/IOMXBufferSource.h>
23#include <media/IOMX.h>
24#include <media/OMXBuffer.h>
25#include <codec2/hidl/client.h>
26
27namespace android {
28
29/**
30 * IOmxNode implementation around codec 2.0 component, only to be used in
31 * IGraphicBufferSource::configure. Only subset of IOmxNode API is implemented
32 * and others are left as stub. As a result, one cannot expect this IOmxNode
33 * to work in any other usage than IGraphicBufferSource.
34 */
35struct C2OMXNode : public BnOMXNode {
36 explicit C2OMXNode(const std::shared_ptr<Codec2Client::Component> &comp);
37 ~C2OMXNode() override = default;
38
39 // IOMXNode
40 status_t freeNode() override;
41 status_t sendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param) override;
42 status_t getParameter(
43 OMX_INDEXTYPE index, void *params, size_t size) override;
44 status_t setParameter(
45 OMX_INDEXTYPE index, const void *params, size_t size) override;
46 status_t getConfig(
47 OMX_INDEXTYPE index, void *params, size_t size) override;
48 status_t setConfig(
49 OMX_INDEXTYPE index, const void *params, size_t size) override;
50 status_t setPortMode(OMX_U32 port_index, IOMX::PortMode mode) override;
51 status_t prepareForAdaptivePlayback(
52 OMX_U32 portIndex, OMX_BOOL enable,
53 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) override;
54 status_t configureVideoTunnelMode(
55 OMX_U32 portIndex, OMX_BOOL tunneled,
56 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) override;
57 status_t getGraphicBufferUsage(
58 OMX_U32 port_index, OMX_U32* usage) override;
59 status_t setInputSurface(
60 const sp<IOMXBufferSource> &bufferSource) override;
61 status_t allocateSecureBuffer(
62 OMX_U32 port_index, size_t size, buffer_id *buffer,
63 void **buffer_data, sp<NativeHandle> *native_handle) override;
64 status_t useBuffer(
65 OMX_U32 port_index, const OMXBuffer &omxBuf, buffer_id *buffer) override;
66 status_t freeBuffer(
67 OMX_U32 port_index, buffer_id buffer) override;
68 status_t fillBuffer(
69 buffer_id buffer, const OMXBuffer &omxBuf, int fenceFd) override;
70 status_t emptyBuffer(
71 buffer_id buffer, const OMXBuffer &omxBuf,
72 OMX_U32 flags, OMX_TICKS timestamp, int fenceFd) override;
73 status_t getExtensionIndex(
74 const char *parameter_name,
75 OMX_INDEXTYPE *index) override;
76 status_t dispatchMessage(const omx_message &msg) override;
77
Wonsik Kim4f3314d2019-03-26 17:00:34 -070078 /**
79 * Returns underlying IOMXBufferSource object.
80 */
Pawin Vongmasa36653902018-11-15 00:10:25 -080081 sp<IOMXBufferSource> getSource();
Wonsik Kim4f3314d2019-03-26 17:00:34 -070082
83 /**
84 * Configure the frame size.
85 */
Pawin Vongmasa36653902018-11-15 00:10:25 -080086 void setFrameSize(uint32_t width, uint32_t height);
87
Wonsik Kim4f3314d2019-03-26 17:00:34 -070088 /**
89 * Clean up work item reference.
90 *
91 * \param index input work index
92 */
93 void onInputBufferDone(c2_cntr64_t index);
94
Pawin Vongmasa36653902018-11-15 00:10:25 -080095private:
96 std::weak_ptr<Codec2Client::Component> mComp;
97 sp<IOMXBufferSource> mBufferSource;
98 std::shared_ptr<C2Allocator> mAllocator;
99 std::atomic_uint64_t mFrameIndex;
100 uint32_t mWidth;
101 uint32_t mHeight;
102 uint64_t mUsage;
103
104 // WORKAROUND: timestamp adjustment
105
106 // if >0: this is the max timestamp gap, if <0: this is -1 times the fixed timestamp gap
107 // if 0: no timestamp adjustment is made
108 // note that C2OMXNode can be recycled between encoding sessions.
109 int32_t mAdjustTimestampGapUs;
110 bool mFirstInputFrame; // true for first input
111 c2_cntr64_t mPrevInputTimestamp; // input timestamp for previous frame
112 c2_cntr64_t mPrevCodecTimestamp; // adjusted (codec) timestamp for previous frame
Wonsik Kim4f3314d2019-03-26 17:00:34 -0700113
114 std::map<uint64_t, buffer_id> mBufferIdsInUse;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800115};
116
117} // namespace android
118
119#endif // C2_OMX_NODE_H_