blob: 5549b886abd7da8da87308b9ce4df7dfbb3347ff [file] [log] [blame]
Sungtak Lee64c9d932024-03-26 03:46:53 +00001/*
2 * Copyright 2024, 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 <android/IOMXBufferSource.h>
21#include <codec2/hidl/client.h>
22#include <media/IOMX.h>
23#include <media/OMXBuffer.h>
24
25namespace android {
26
27struct C2NodeImpl;
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 /**
79 * Returns underlying IOMXBufferSource object.
80 */
81 sp<IOMXBufferSource> getSource();
82
83 /**
84 * Configure the frame size.
85 */
86 void setFrameSize(uint32_t width, uint32_t height);
87
88 /**
Wonsik Kim1951d932024-05-23 22:59:00 +000089 * Notify that the input buffer reference is no longer needed by the component.
90 * Clean up if necessary.
Sungtak Lee64c9d932024-03-26 03:46:53 +000091 *
92 * \param index input work index
93 */
94 void onInputBufferDone(c2_cntr64_t index);
95
96 /**
Wonsik Kim1951d932024-05-23 22:59:00 +000097 * Notify input buffer is emptied.
98 */
99 void onInputBufferEmptied();
100
101 /**
Sungtak Lee64c9d932024-03-26 03:46:53 +0000102 * Returns dataspace information from GraphicBufferSource.
103 */
104 android_dataspace getDataspace();
105
106 /**
107 * Returns dataspace information from GraphicBufferSource.
108 */
109 uint32_t getPixelFormat();
110
111 /**
112 * Sets priority of the queue thread.
113 */
114 void setPriority(int priority);
115
116private:
117 std::shared_ptr<C2NodeImpl> mImpl;
118};
119
120} // namespace android
121
122#endif // C2_OMX_NODE_H_