1 /* 2 * Copyright (c) 2021-2021 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 #ifndef HISTREAMER_PLUGIN_INTF_AUDIO_SINK_PLUGIN_H 17 #define HISTREAMER_PLUGIN_INTF_AUDIO_SINK_PLUGIN_H 18 19 #include "common/plugin_buffer.h" 20 #include "common/plugin_caps.h" 21 #include "plugin_base.h" 22 #include "plugin_definition.h" 23 24 namespace OHOS { 25 namespace Media { 26 namespace Plugin { 27 /** 28 * @brief Audio Sink Plugin. 29 * 30 * Component that receives media streams. 31 * 32 * @since 1.0 33 * @version 1.0 34 */ 35 struct AudioSinkPlugin : public PluginBase { 36 /// constructor AudioSinkPluginAudioSinkPlugin37 explicit AudioSinkPlugin(std::string name): PluginBase(std::move(name)) {} 38 /** 39 * @brief Get the mute operation set for the audio. 40 * 41 * This function can be called in any state except DESTROYED and INVALID. 42 * 43 * @param mute Indicates the mute operation set for the audio. 44 * Value true means that the audio is muted, and false means the opposite. 45 * @return Execution status return 46 * @retval OK: Plugin reset succeeded. 47 */ 48 virtual Status GetMute(bool& mute) = 0; 49 50 /** 51 * @brief Set the mute operation for the audio. 52 * 53 * This function can be called in any state except DESTROYED and INVALID. 54 * 55 * @param mute Indicates the mute operation set for the audio. 56 * Value true means that the audio is muted, and false means the opposite. 57 * @return Execution status return 58 * @retval OK: Plugin reset succeeded. 59 */ 60 virtual Status SetMute(bool mute) = 0; 61 62 /** 63 * @brief Get the audio volume. 64 * 65 * This function can be called in any state except DESTROYED and INVALID. 66 * 67 * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. 68 * @return Execution status return 69 * @retval OK: Plugin reset succeeded. 70 */ 71 virtual Status GetVolume(float& volume) = 0; 72 73 /** 74 * @brief Set the audio volume. 75 * 76 * This function can be called in any state except DESTROYED and INVALID. 77 * 78 * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. 79 * @return Execution status return 80 * @retval OK: Plugin reset succeeded. 81 * @retval ERROR_INVALID_DATA: The value is not in the valid range. 82 */ 83 virtual Status SetVolume(float volume) = 0; 84 85 /** 86 * @brief Get the current audio rendering speed. 87 * 88 * This function can be called in any state except DESTROYED and INVALID. 89 * 90 * @param speed Indicates the pointer to the current rendering speed to obtain. 91 * @return Execution status return 92 * @retval OK: Plugin reset succeeded. 93 */ 94 virtual Status GetSpeed(float& speed) = 0; 95 96 /** 97 * @brief Set the audio rendering speed. 98 * 99 * This function can be called in any state except DESTROYED and INVALID. 100 * 101 * @param speed speed Indicates the pointer to the current rendering speed to obtain. 102 * @return Execution status return 103 * @retval OK: Plugin reset succeeded. 104 * @retval ERROR_INVALID_DATA: The value is not in the valid range. 105 */ 106 virtual Status SetSpeed(float speed) = 0; 107 108 /** 109 * @brief Pauses audio rendering 110 * 111 * The function is valid only in the RUNNING state. If the pause is successful, 112 * the plugin enters the PAUSED state. 113 * 114 * @return Execution status return 115 * @retval OK: Plugin reset succeeded. 116 */ 117 virtual Status Pause() = 0; 118 119 /** 120 * @brief Resumes audio rendering 121 * 122 * The function is valid only in the PAUSED state. If the resume is successful, 123 * the plugin enters the RUNNING state. 124 * 125 * @return Execution status return 126 * @retval OK: Plugin reset succeeded. 127 */ 128 virtual Status Resume() = 0; 129 130 /** 131 * @brief Get the estimated latency of the audio device driver. 132 * 133 * The function is valid only in the after PREPARED state. 134 * 135 * @param nanoSec Indicates the pointer to the latency (in milliseconds) to be obtained. 136 * @return Execution status return 137 * @retval OK: Plugin reset succeeded. 138 */ 139 virtual Status GetLatency(uint64_t& nanoSec) = 0; 140 141 /** 142 * @brief Get the audio frame size, that is, the length (in bytes) of a frame. 143 * 144 * The function is valid only in the RUNNING state. 145 * 146 * @param size size Indicates the pointer to the audio frame size (in bytes). 147 * @return Execution status return 148 * @retval OK: Plugin reset succeeded. 149 */ 150 virtual Status GetFrameSize(size_t& size) = 0; 151 152 /** 153 * @brief Get the number of audio frames in the audio buffer. 154 * 155 * The function is valid only in the RUNNING state. 156 * 157 * @param count Indicates the pointer to the number of audio frames in the audio buffer. 158 * @return Execution status return 159 * @retval OK: Plugin reset succeeded. 160 */ 161 virtual Status GetFrameCount(uint32_t& count) = 0; 162 163 /** 164 * @brief Writes a frame of output data into the audio driver for rendering. 165 * 166 * The function is valid only in the RUNNING state. 167 * 168 * @param input Indicates the pointer to the frame to write. 169 * @return Execution status return 170 * @retval OK: Plugin reset succeeded. 171 */ 172 virtual Status Write(const std::shared_ptr<Buffer>& input) = 0; 173 174 /** 175 * @brief Flushes data in the audio buffer. 176 * 177 * The function is valid only in after RUNNING state. 178 * 179 * @return Execution status return 180 * @retval OK: Plugin reset succeeded. 181 */ 182 virtual Status Flush() = 0; 183 }; 184 185 /// Audio sink plugin api major number. 186 #define AUDIO_SINK_API_VERSION_MAJOR (1) 187 188 /// Audio sink plugin api minor number 189 #define AUDIO_SINK_API_VERSION_MINOR (0) 190 191 /// Audio sink plugin version 192 #define AUDIO_SINK_API_VERSION MAKE_VERSION(AUDIO_SINK_API_VERSION_MAJOR, AUDIO_SINK_API_VERSION_MINOR) 193 194 /** 195 * @brief Describes the audio sink plugin information. 196 * 197 * @since 1.0 198 * @version 1.0 199 */ 200 struct AudioSinkPluginDef : public PluginDefBase { 201 CapabilitySet inCaps {}; ///< Plug-in input capability, For details, @see Capability. 202 PluginCreatorFunc<AudioSinkPlugin> creator {nullptr}; ///< Audio sink plugin create function. AudioSinkPluginDefAudioSinkPluginDef203 AudioSinkPluginDef() 204 { 205 apiVersion = AUDIO_SINK_API_VERSION; ///< Audio sink plugin version. 206 pluginType = PluginType::AUDIO_SINK; ///< Plugin type, MUST be AUDIO_SINK. 207 } 208 }; 209 } // namespace Plugin 210 } // namespace Media 211 } // namespace OHOS 212 #endif // HISTREAMER_PLUGIN_INTF_AUDIO_SINK_PLUGIN_H 213