1 /* 2 * Copyright (C) 2025 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 AUDIO_STREAM_PLAYER_H 17 #define AUDIO_STREAM_PLAYER_H 18 19 #include "meta/format.h" 20 #include "lpp_common.h" 21 22 namespace OHOS { 23 namespace Media { 24 25 class AudioStreamerKeys { 26 public: 27 static constexpr std::string_view LPP_CURRENT_POSITION = "lpp_current_position"; 28 static constexpr std::string_view LPP_AUDIO_INTERRUPT_FORCE_TYPE = "lpp_audio_interrupt_force_type"; 29 static constexpr std::string_view LPP_AUDIO_INTERRUPT_HINT = "lpp_audio_interrupt_hint"; 30 static constexpr std::string_view LPP_AUDIO_DEVICE_CHANGE_REASON = "audio_device_change_reason"; 31 static constexpr std::string_view LPP_AUDIO_MAX_BUFFER_SIZE = "lpp_audio_max_buffer_size"; 32 static constexpr std::string_view LPP_AUDIO_MAX_FRAME_NUM = "lpp_audio_max_frame_num"; 33 }; 34 35 enum AudioStreamerOnInfoType : int32_t { 36 /* audio device change. */ 37 INFO_TYPE_LPP_AUDIO_DEVICE_CHANGE, 38 /* return the message when eos */ 39 INFO_TYPE_LPP_AUDIO_EOS, 40 /* return the message when Interrupted */ 41 INFO_TYPE_LPP_AUDIO_INTERRUPT, 42 /* return the message when dataNeeded */ 43 INFO_TYPE_LPP_AUDIO_DATA_NEEDED, 44 /* return the current posion of playback automatically. */ 45 INFO_TYPE_LPP_AUDIO_POSITION_UPDATE, 46 }; 47 48 class AudioStreamerCallback { 49 public: 50 virtual ~AudioStreamerCallback() = default; 51 52 virtual void OnError(int32_t errorCode, const std::string &errorMsg) = 0; 53 54 virtual void OnInfo(AudioStreamerOnInfoType type, int32_t extra, const Format &infoBody) = 0; 55 }; 56 57 class AudioStreamer { 58 public: 59 virtual ~AudioStreamer() = default; 60 61 virtual int32_t SetParameter(const Format ¶m) = 0; 62 63 virtual int32_t Configure(const Format ¶m) = 0; 64 65 virtual int32_t Prepare() = 0; 66 67 virtual int32_t Start() = 0; 68 69 virtual int32_t Pause() = 0; 70 71 virtual int32_t Resume() = 0; 72 73 virtual int32_t Flush() = 0; 74 75 virtual int32_t Stop() = 0; 76 77 virtual int32_t Reset() = 0; 78 79 virtual int32_t Release() = 0; 80 81 virtual int32_t SetVolume(float volume) = 0; 82 83 virtual int32_t SetPlaybackSpeed(float speed) = 0; 84 85 virtual int32_t ReturnFrames(sptr<LppDataPacket> framePacket) = 0; 86 87 virtual int32_t RegisterCallback() = 0; 88 89 virtual int32_t SetLppAudioStreamerCallback(const std::shared_ptr<AudioStreamerCallback> &callback) = 0; 90 91 virtual int32_t SetLppVideoStreamerId(std::string videoStreamerId) = 0; 92 93 virtual std::string GetStreamerId() = 0; 94 }; 95 96 class __attribute__((visibility("default"))) AudioStreamerFactory { 97 public: 98 #ifdef UNSUPPORT_LPP_AUDIO_STRAMER CreateByMime(const std::string & mime)99 static std::shared_ptr<AudioStreamer> CreateByMime(const std::string &mime) 100 { 101 (void)mime; 102 return nullptr; 103 } 104 #else 105 static std::shared_ptr<AudioStreamer> CreateByMime(const std::string &mime); 106 #endif 107 private: 108 AudioStreamerFactory() = default; 109 ~AudioStreamerFactory() = default; 110 }; 111 } // namespace Media 112 } // namespace OHOS 113 #endif // AUDIO_STREAM_PLAYER_H 114