1 /* 2 * Copyright (c) 2024-2024 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 DFX_AGENT_H 17 #define DFX_AGENT_H 18 19 #include "osal/task/task.h" 20 #include "demuxer_filter.h" 21 22 namespace OHOS { 23 namespace Media { 24 25 enum class PlayerDfxSourceType : uint8_t { 26 DFX_SOURCE_TYPE_URL_FILE = 0, 27 DFX_SOURCE_TYPE_URL_FD = 1, 28 DFX_SOURCE_TYPE_URL_NETWORK = 2, 29 DFX_SOURCE_TYPE_DATASRC = 3, 30 DFX_SOURCE_TYPE_MEDIASOURCE_LOCAL = 4, 31 DFX_SOURCE_TYPE_MEDIASOURCE_NETWORK = 5, 32 DFX_SOURCE_TYPE_UNKNOWN = 127, 33 }; 34 35 class DfxAgent : public std::enable_shared_from_this<DfxAgent> { 36 public: 37 DfxAgent(const std::string& groupId, const std::string& appName); 38 ~DfxAgent(); 39 void SetDemuxer(std::weak_ptr<Pipeline::DemuxerFilter> demuxer); 40 void SetSourceType(PlayerDfxSourceType type); 41 void SetInstanceId(const std::string& instanceId); 42 void OnAudioLagEvent(int64_t lagDuration); 43 void OnVideoLagEvent(int64_t lagDuration); 44 void OnStreamLagEvent(int64_t lagDuration); 45 void ResetAgent(); 46 private: 47 void ReportLagEvent(int64_t lagDuration, const std::string& eventMsg); 48 bool GetNetworkInfo(std::string& networkInfo); 49 std::string groupId_ {}; 50 std::string instanceId_ {}; 51 std::string appName_ {}; 52 PlayerDfxSourceType sourceType_ {PlayerDfxSourceType::DFX_SOURCE_TYPE_UNKNOWN}; 53 std::unique_ptr<Task> dfxTask_ {nullptr}; 54 bool hasReported_ {false}; 55 std::weak_ptr<Pipeline::DemuxerFilter> demuxer_ {}; 56 }; 57 58 } // namespace Media 59 } // namespace OHOS 60 #endif // DFX_AGENT_H