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 LPP_PLAYER_SERVICE_SERVER_H 17 #define LPP_PLAYER_SERVICE_SERVER_H 18 19 #include <mutex> 20 21 #include "i_lpp_audio_streamer_service.h" 22 #include "i_lpp_audio_streamer.h" 23 #include "media_errors.h" 24 #include "nocopyable.h" 25 26 namespace OHOS { 27 namespace Media { 28 29 enum class LppAudioState : int32_t { 30 CREATED = 0, 31 INITIALIZED = 1, 32 READY = 2, 33 STARTING = 3, 34 PAUSED = 4, 35 EOS = 5, 36 STOPPED = 6, 37 RELEASED = 7, 38 ERROR = 32, 39 }; 40 41 class LppAudioStreamerServer 42 : public ILppAudioStreamerService, 43 public ILppAudioStreamerEngineObs, 44 public NoCopyable { 45 public: 46 static std::shared_ptr<ILppAudioStreamerService> Create(); 47 LppAudioStreamerServer(); 48 virtual ~LppAudioStreamerServer(); 49 50 int32_t Init(const std::string &mime) override; 51 52 int32_t SetParameter(const Format ¶m) override; 53 54 int32_t Configure(const Format ¶m) override; 55 56 int32_t Prepare() override; 57 58 int32_t Start() override; 59 60 int32_t Pause() override; 61 62 int32_t Resume() override; 63 64 int32_t Flush() override; 65 66 int32_t Stop() override; 67 68 int32_t Reset() override; 69 70 int32_t Release() override; 71 72 int32_t SetVolume(float volume) override; 73 74 int32_t SetPlaybackSpeed(float speed) override; 75 76 int32_t ReturnFrames(sptr<LppDataPacket> framePacket) override; 77 78 int32_t RegisterCallback() override; 79 80 int32_t SetLppAudioStreamerCallback(const std::shared_ptr<AudioStreamerCallback> &callback) override; 81 82 std::string GetStreamerId() override; 83 84 void OnDataNeeded(const int32_t maxBufferSize) override; 85 86 void OnPositionUpdated(const int64_t currentPositionMs) override; 87 88 void OnError(const LppErrCode errCode, const std::string &errMsg) override; 89 90 void OnEos() override; 91 92 void OnInterrupted(const int64_t forceType, const int64_t hint) override; 93 94 void OnDeviceChanged(const int64_t reason) override; 95 96 int32_t SetLppVideoStreamerId(const std::string videoStreamId) override; 97 98 private: 99 int32_t CreateStreamerEngine(); 100 bool StateEnter(LppAudioState targetState, const std::string funcName = ""); 101 bool StateCheck(LppAudioState curState); 102 bool ErrorCheck(int32_t errorCode); 103 104 LppAudioState state_ {LppAudioState::CREATED}; 105 std::mutex stateMutex_ {}; 106 107 std::string mime_ {}; 108 109 std::shared_ptr<AudioStreamerCallback> lppAudioStreamerCb_ = nullptr; 110 111 std::shared_ptr<ILppAudioStreamerEngine> streamerEngine_ = nullptr; 112 uint32_t appTokenId_ = 0; 113 int32_t appUid_ = 0; 114 int32_t appPid_ = 0; 115 std::string appName_; 116 }; 117 } // namespace Media 118 } // namespace OHOS 119 #endif // LPP_PLAYER_SERVICE_SERVER_H 120