1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup Codec 18 * @{ 19 * 20 * @brief Defines APIs related to the Codec module. 21 * 22 * The Codec module provides APIs for initializing the custom data and audio and video codecs, 23 * setting codec parameters, and controlling and transferring data. 24 * 25 * @since 3.1 26 */ 27 28 /** 29 * @file codec_callback_if.h 30 * 31 * @brief Defines the callbacks used to report codec events and processing results of the input and output buffers. 32 * 33 * @since 3.1 34 */ 35 36 #ifndef CODEC_CALLBACK_TYPE_H 37 #define CODEC_CALLBACK_TYPE_H 38 39 #include <stdint.h> 40 #include <netinet/in.h> 41 #include "codec_component_type.h" 42 #include "OMX_Core.h" 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif /* __cplusplus */ 47 48 /** 49 * @brief Defines the callbacks of the Codec module. 50 * 51 * The following callbacks are provided: 52 * 1. Callback used to report component error events, command completion events, and port setting events. 53 * For details, see {@link EventHandler}. 54 * 2. Callback invoked when the input port processes data in the buffer. For details, see {@link EmptyBufferDone}. 55 * 3. Callback invoked when the output port fills data into the buffer. For details, see {@link FillBufferDone}. 56 * The callbacks are registered by using: 57 * 1. {@link CreateComponent} when a component is created. 58 * 2. {@link SetCallbacks} when the component is in the OMX_StateLoaded state. 59 */ 60 struct CodecCallbackType { 61 struct HdfRemoteService *remote; 62 63 /** 64 * @brief Reports an event, such as an error, a command completion event, and port setting changes 65 * during the running of a component. 66 * 67 * When <b>eEvent</b> is <b>OMX_EventCmdComplete</b>, <b>eventData</b> is null, and <b>data1</b> is 68 * <b>OMX_COMMANDTYPE</b>, <b>data1</b> indicates a state, if <b>data1</b> is <b>OMX_CommandStateSet</b> 69 * and indicates a port in other cases. 70 * If <b>eEvent</b> is <b>OMX_EventError</b>, <b>data1</b> indicates an error code and <b>data2</b> and 71 * <b>eventData</b> are both <b>0</b>. 72 * If <b>eEvent</b> is <b>OMX_EventMark</b>, <b>data1</b> and <b>data2</b> are both <b>0</b> and 73 * <b>eventData</b> points to the mark. 74 * When <b>eEvent</b> is <b>OMX_EventPortSettingsChanged</b>, <b>data1</b> indicates a port and 75 * <b>data2</b> and <b>eventData</b> are <b>0</b>. 76 * When <b>eEvent</b> is <b>OMX_EventBufferFlag</b>, <b>data1</b> indicates a port, <b>data2</b> indicates a flag, 77 * and <b>eventData</b> is <b>0</b>. 78 * When <b>eEvent</b> is <b>OMX_EventResourcesAcquired</b> or <b>OMX_EventDynamicResourcesAvailable</b>, 79 * the values of <b>data1</b>, <b>data2</b>, and <b>eventData</b> are <b>0</b>. 80 * 81 * @param self Indicates the pointer to the callback to be invoked. 82 * @param appData Indicates the pointer to the upper-layer instance passed to the callback. 83 * @param appDataLen Indicates the length of <b>appData</b>, in bytes. 84 * @param eEvent Indicates the type of events to report. For details, see {@link OMX_EVENTTYPE}. 85 * @param data1 Indicates data 1 carried in the event. 86 * @param data2 Indicates data 2 carried in the event. 87 * @param eventData Indicates the pointer to the data carried in the event. 88 * @param eventDataLen Indicates the length of <b>eventData</b>, in bytes. 89 * 90 * @return Returns <b>HDF_SUCCESS</b> if the operation is successful. 91 * @return Returns <b>HDF_ERR_INVALID_PARAM</b> if the operation failed due to invalid parameters. 92 * @return Returns <b>HDF_ERR_INVALID_OBJECT</b> if the operation failed due to invalid objects. 93 * @return Returns <b>HDF_ERR_MALLOC_FAIL</b> if the operation failed due to insufficient memory. 94 */ 95 int32_t (*EventHandler)(struct CodecCallbackType *self, int8_t *appData, uint32_t appDataLen, 96 enum OMX_EVENTTYPE eEvent, uint32_t data1, uint32_t data2, int8_t *eventData, uint32_t eventDataLen); 97 98 /** 99 * @brief Reports an event indicating that the encoding or decoding in the input buffer is complete. 100 * 101 * @param self Indicates the pointer to the callback to be invoked. 102 * @param appData Indicates the pointer to the upper-layer instance passed to the callback. 103 * @param appDataLen Indicates the length of <b>appData</b>, in bytes. 104 * @param buffer Indicates the pointer to the input buffer {@link OmxCodecBuffer} that has data processed. 105 * 106 * @return Returns <b>HDF_SUCCESS</b> if the operation is successful. 107 * @return Returns <b>HDF_ERR_INVALID_PARAM</b> if the operation failed due to invalid parameters. 108 * @return Returns <b>HDF_ERR_INVALID_OBJECT</b> if the operation failed due to invalid objects. 109 * @return Returns <b>HDF_ERR_MALLOC_FAIL</b> if the operation failed due to insufficient memory. 110 */ 111 int32_t (*EmptyBufferDone)(struct CodecCallbackType *self, int8_t *appData, 112 uint32_t appDataLen, const struct OmxCodecBuffer *buffer); 113 114 /** 115 * @brief Reports an event indicating that the output buffer is filled. 116 * 117 * @param self Indicates the pointer to the callback to be invoked. 118 * @param appData Indicates the pointer to the upper-layer instance passed to the callback. 119 * @param appDataLen Indicates the length of <b>appData</b>, in bytes. 120 * @param buffer Indicates the pointer to the buffer {@link OmxCodecBuffer} that has data filled. 121 * 122 * @return Returns <b>HDF_SUCCESS</b> if the operation is successful. 123 * @return Returns <b>HDF_ERR_INVALID_PARAM</b> if the operation failed due to invalid parameters. 124 * @return Returns <b>HDF_ERR_INVALID_OBJECT</b> if the operation failed due to invalid objects. 125 * @return Returns <b>HDF_ERR_MALLOC_FAIL</b> if the operation failed due to insufficient memory. 126 */ 127 int32_t (*FillBufferDone)(struct CodecCallbackType *self, int8_t* appData, 128 uint32_t appDataLen, struct OmxCodecBuffer* buffer); 129 }; 130 131 /** 132 * @brief Instantiates a <b>CodecCallbackType</b> object. 133 * 134 * @param remote Indicates the pointer to the <b>HdfRemoteService</b>. 135 * 136 * @return Returns the <b>CodecCallbackType</b> object instantiated. 137 */ 138 struct CodecCallbackType *CodecCallbackTypeGet(struct HdfRemoteService *remote); 139 140 /** 141 * @brief Releases a <b>CodecCallbackType</b> instance. 142 * 143 * @param instance Indicates the pointer to the <b>CodecCallbackType</b> instance to release. 144 */ 145 void CodecCallbackTypeRelease(struct CodecCallbackType *instance); 146 147 #ifdef __cplusplus 148 } 149 #endif /* __cplusplus */ 150 151 #endif // CODEC_CALLBACK_TYPE_H