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 LIVE_CONTROLLER_H 17 #define LIVE_CONTROLLER_H 18 19 #include "i_player_engine.h" 20 #include "osal/task/mutex.h" 21 #include "osal/task/task.h" 22 #include "osal/utils/steady_clock.h" 23 24 namespace OHOS { 25 namespace Media { 26 class LiveController : public IPlayerEngineObs { 27 public: 28 explicit LiveController(); 29 30 ~LiveController() override; 31 32 void Stop(); 33 34 void StartWithPlayerEngineObs(const std::weak_ptr<IPlayerEngineObs>& obs); 35 36 void SetPlayEngine(IPlayerEngine* engine, std::string playerId); 37 38 void StartCheckLiveDelayTime(int64_t updateIntervalMs = 1000); 39 40 void StopCheckLiveDelayTime(); 41 42 void OnError(PlayerErrorType errorType, int32_t errorCode) override; 43 44 void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) override; 45 46 void OnSystemOperation(PlayerOnSystemOperationType type, PlayerOperationReason reason) override; 47 48 private: 49 struct Event { EventEvent50 Event(int32_t inWhat, int64_t inWhenMs, Any inAny): what(inWhat), whenMs(inWhenMs), 51 detail(std::move(inAny)) {} 52 int32_t what {0}; 53 int64_t whenMs {INT64_MAX}; 54 Any detail; 55 }; 56 57 void Enqueue(const std::shared_ptr<Event>& event); 58 59 void LoopOnce(const std::shared_ptr<Event>& item); 60 61 void DoCheckLiveDalyTime(); 62 63 bool taskStarted_ {false}; 64 65 std::atomic<bool> isCheckLiveDelayTimeSet_ = false; 66 67 std::unique_ptr<OHOS::Media::Task> task_; 68 69 IPlayerEngine* playerEngine_ {}; 70 71 std::weak_ptr<IPlayerEngineObs> obs_ {}; 72 73 int64_t checkLiveDelayTimeIntervalMs_ {1000}; 74 }; 75 } // namespace Media 76 } // namespace OHOS 77 #endif // LIVE_CONTROLLER_H