blob: b5a815ec0fd3187fabd873e0947d8037575a641d [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
78 sp<IOMXBufferSource> getSource();
79 void setFrameSize(uint32_t width, uint32_t height);
80
81private:
82 std::weak_ptr<Codec2Client::Component> mComp;
83 sp<IOMXBufferSource> mBufferSource;
84 std::shared_ptr<C2Allocator> mAllocator;
85 std::atomic_uint64_t mFrameIndex;
86 uint32_t mWidth;
87 uint32_t mHeight;
88 uint64_t mUsage;
89
90 // WORKAROUND: timestamp adjustment
91
92 // if >0: this is the max timestamp gap, if <0: this is -1 times the fixed timestamp gap
93 // if 0: no timestamp adjustment is made
94 // note that C2OMXNode can be recycled between encoding sessions.
95 int32_t mAdjustTimestampGapUs;
96 bool mFirstInputFrame; // true for first input
97 c2_cntr64_t mPrevInputTimestamp; // input timestamp for previous frame
98 c2_cntr64_t mPrevCodecTimestamp; // adjusted (codec) timestamp for previous frame
99};
100
101} // namespace android
102
103#endif // C2_OMX_NODE_H_