forked from alibaba/CicadaPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMediaPlayerAnalyticsUtil.h
99 lines (66 loc) · 2.71 KB
/
MediaPlayerAnalyticsUtil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// Created by SuperMan on 2021/10/28.
//
#ifndef QALIYUNPLAYERTEST_MEDIAPLAYERANALYTICSUTIL_H
#define QALIYUNPLAYERTEST_MEDIAPLAYERANALYTICSUTIL_H
#include <list>
#include <map>
#include <mutex>
#include <utils/CicadaJSON.h>
#include "demuxer/demuxer_service.h"
#include "native_cicada_player_def.h"
#include "utils/AFMediaType.h"
namespace Cicada {
class RenderInfo {
public:
RenderInfo();
~RenderInfo();
void reset();
void videoRendered(bool rendered);
std::string toString();
public:
int JANK_GAP = 200;
int MAX_GRADE_NUM = 5;//0~200,...,800~1s,1s~
int totalCount{0};
int droppedCount{0};
std::map<int, int> jankTimesMap{};
std::map<int, int64_t> jankCostMap{};
private:
int64_t lastRenderedTimeMs{INT64_MIN};
};
class MediaPlayerAnalyticsUtil {
public:
MediaPlayerAnalyticsUtil();
~MediaPlayerAnalyticsUtil();
void reset();
std::map<int64_t, int64_t> getNetworkSpeed(int64_t timeFrom, int64_t timeTo);
std::map<int64_t, std::string> getBufferInfo(int64_t timeFrom, int64_t timeTo);
std::string getNetworkRequestInfos(int64_t timeFrom, int64_t timeTo);
std::string getRenderInfoAndReset();
void updateNetworkReadSize(uint64_t size);
void updateBufferInfo(bool force, int64_t videoDuration, int64_t audioDuration);
void notifyNetworkEvent(const std::string &url, const CicadaJSONItem &eventParam);
void videoRendered(bool rendered);
public:
static void getPropertyJSONStr(const std::string &name, CicadaJSONArray &array, bool isArray,
std::deque<StreamInfo *> &streamInfoQueue, demuxer_service *service);
static void addPropertyType(CicadaJSONItem &item, StreamType type);
static void addURLProperty(const std::string &name, CicadaJSONArray &array, IDataSource *dataSource);
private:
static void filterNetworkInfo(CicadaJSONArray &info, int64_t timeFrom, int64_t timeTo,
const std::function<void(CicadaJSONItem &event)> &callback);
private:
std::mutex utilMutex{};
const int MAX_COUNT = 600;
std::map<int64_t, float> mNetworkSpeed{};
std::map<int64_t, std::string> mBufferInfo{};
std::list<std::string> mNetworkUrls{};
std::map<std::string, std::string> mNetworkInfos{};
int64_t updateBufferInfoLastTimeMs{INT64_MIN};
uint64_t mLastReadTime{0};
std::atomic<uint64_t> mReadGotSize{0};
std::mutex renderInfoMutex{};
RenderInfo mRenderInfo{};
};
}// namespace Cicada
#endif//QALIYUNPLAYERTEST_MEDIAPLAYERANALYTICSUTIL_H