xiangpei
2024-08-21 4a4692342a4ba22283d5e580d15b645f3be65da0
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
package com.ycl.platform.wvp;
 
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import io.swagger.v3.oas.annotations.media.Schema;
 
import java.util.List;
 
/**
 * 视频信息
 */
@Schema(description = "视频信息")
public class MediaInfo {
    @Schema(description = "应用名")
    private String app;
    @Schema(description = "流ID")
    private String stream;
    @Schema(description = "流媒体节点")
    private MediaServer mediaServer;
    @Schema(description = "协议")
    private String schema;
 
    @Schema(description = "观看人数")
    private Integer readerCount;
    @Schema(description = "视频编码类型")
    private String videoCodec;
    @Schema(description = "视频宽度")
    private Integer width;
    @Schema(description = "视频高度")
    private Integer height;
    @Schema(description = "音频编码类型")
    private String audioCodec;
    @Schema(description = "音频通道数")
    private Integer audioChannels;
    @Schema(description = "音频采样率")
    private Integer audioSampleRate;
    @Schema(description = "音频采样率")
    private Long duration;
    @Schema(description = "在线")
    private Boolean online;
    @Schema(description = "unknown = 0,rtmp_push=1,rtsp_push=2,rtp_push=3,pull=4,ffmpeg_pull=5,mp4_vod=6,device_chn=7")
    private Integer originType;
    @Schema(description = "存活时间,单位秒")
    private Long aliveSecond;
    @Schema(description = "数据产生速度,单位byte/s")
    private Long bytesSpeed;
    @Schema(description = "鉴权参数")
    private String callId;
 
    public static MediaInfo getInstance(JSONObject jsonObject, MediaServer mediaServer) {
        MediaInfo mediaInfo = new MediaInfo();
        mediaInfo.setMediaServer(mediaServer);
        String app = jsonObject.getString("app");
        mediaInfo.setApp(app);
        String stream = jsonObject.getString("stream");
        mediaInfo.setStream(stream);
        String schema = jsonObject.getString("schema");
        mediaInfo.setSchema(schema);
        Integer totalReaderCount = jsonObject.getInteger("totalReaderCount");
        Boolean online = jsonObject.getBoolean("online");
        Integer originType = jsonObject.getInteger("originType");
        Long aliveSecond = jsonObject.getLong("aliveSecond");
        Long bytesSpeed = jsonObject.getLong("bytesSpeed");
        if (totalReaderCount != null) {
            mediaInfo.setReaderCount(totalReaderCount);
        }
        if (online != null) {
            mediaInfo.setOnline(online);
        }
        if (originType != null) {
            mediaInfo.setOriginType(originType);
        }
        if (aliveSecond != null) {
            mediaInfo.setAliveSecond(aliveSecond);
        }
        if (bytesSpeed != null) {
            mediaInfo.setBytesSpeed(bytesSpeed);
        }
        JSONArray jsonArray = jsonObject.getJSONArray("tracks");
        if (jsonArray.isEmpty()) {
            return null;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject trackJson = jsonArray.getJSONObject(i);
            Integer channels = trackJson.getInteger("channels");
            Integer codecId = trackJson.getInteger("codec_id");
            Integer codecType = trackJson.getInteger("codec_type");
            Integer sampleRate = trackJson.getInteger("sample_rate");
            Integer height = trackJson.getInteger("height");
            Integer width = trackJson.getInteger("height");
            Long duration = trackJson.getLongValue("duration");
            if (channels != null) {
                mediaInfo.setAudioChannels(channels);
            }
            if (sampleRate != null) {
                mediaInfo.setAudioSampleRate(sampleRate);
            }
            if (height != null) {
                mediaInfo.setHeight(height);
            }
            if (width != null) {
                mediaInfo.setWidth(width);
            }
            if (duration > 0L) {
                mediaInfo.setDuration(duration);
            }
            if (codecId != null) {
                switch (codecId) {
                    case 0:
                        mediaInfo.setVideoCodec("H264");
                        break;
                    case 1:
                        mediaInfo.setVideoCodec("H265");
                        break;
                    case 2:
                        mediaInfo.setAudioCodec("AAC");
                        break;
                    case 3:
                        mediaInfo.setAudioCodec("G711A");
                        break;
                    case 4:
                        mediaInfo.setAudioCodec("G711U");
                        break;
                }
            }
        }
        return mediaInfo;
    }
 
    public static MediaInfo getInstance(OnStreamChangedHookParam param, MediaServer mediaServer) {
 
        MediaInfo mediaInfo = new MediaInfo();
        mediaInfo.setApp(param.getApp());
        mediaInfo.setStream(param.getStream());
        mediaInfo.setSchema(param.getSchema());
        mediaInfo.setMediaServer(mediaServer);
        mediaInfo.setReaderCount(param.getTotalReaderCount());
        mediaInfo.setOnline(param.isRegist());
        mediaInfo.setOriginType(param.getOriginType());
        mediaInfo.setAliveSecond(param.getAliveSecond());
        mediaInfo.setBytesSpeed(param.getBytesSpeed());
        List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
        if (tracks == null || tracks.isEmpty()) {
            return mediaInfo;
        }
        for (OnStreamChangedHookParam.MediaTrack mediaTrack : tracks) {
            switch (mediaTrack.getCodec_id()) {
                case 0:
                    mediaInfo.setVideoCodec("H264");
                    break;
                case 1:
                    mediaInfo.setVideoCodec("H265");
                    break;
                case 2:
                    mediaInfo.setAudioCodec("AAC");
                    break;
                case 3:
                    mediaInfo.setAudioCodec("G711A");
                    break;
                case 4:
                    mediaInfo.setAudioCodec("G711U");
                    break;
            }
            if (mediaTrack.getSample_rate() > 0) {
                mediaInfo.setAudioSampleRate(mediaTrack.getSample_rate());
            }
            if (mediaTrack.getChannels() > 0) {
                mediaInfo.setAudioChannels(mediaTrack.getChannels());
            }
            if (mediaTrack.getHeight() > 0) {
                mediaInfo.setHeight(mediaTrack.getHeight());
            }
            if (mediaTrack.getWidth() > 0) {
                mediaInfo.setWidth(mediaTrack.getWidth());
            }
        }
        return mediaInfo;
    }
 
    public Integer getReaderCount() {
        return readerCount;
    }
 
    public void setReaderCount(Integer readerCount) {
        this.readerCount = readerCount;
    }
 
    public String getVideoCodec() {
        return videoCodec;
    }
 
    public void setVideoCodec(String videoCodec) {
        this.videoCodec = videoCodec;
    }
 
    public Integer getWidth() {
        return width;
    }
 
    public void setWidth(Integer width) {
        this.width = width;
    }
 
    public Integer getHeight() {
        return height;
    }
 
    public void setHeight(Integer height) {
        this.height = height;
    }
 
    public String getAudioCodec() {
        return audioCodec;
    }
 
    public void setAudioCodec(String audioCodec) {
        this.audioCodec = audioCodec;
    }
 
    public Integer getAudioChannels() {
        return audioChannels;
    }
 
    public void setAudioChannels(Integer audioChannels) {
        this.audioChannels = audioChannels;
    }
 
    public Integer getAudioSampleRate() {
        return audioSampleRate;
    }
 
    public void setAudioSampleRate(Integer audioSampleRate) {
        this.audioSampleRate = audioSampleRate;
    }
 
    public Long getDuration() {
        return duration;
    }
 
    public void setDuration(Long duration) {
        this.duration = duration;
    }
 
    public Boolean getOnline() {
        return online;
    }
 
    public void setOnline(Boolean online) {
        this.online = online;
    }
 
    public Integer getOriginType() {
        return originType;
    }
 
    public void setOriginType(Integer originType) {
        this.originType = originType;
    }
 
    public Long getAliveSecond() {
        return aliveSecond;
    }
 
    public void setAliveSecond(Long aliveSecond) {
        this.aliveSecond = aliveSecond;
    }
 
    public Long getBytesSpeed() {
        return bytesSpeed;
    }
 
    public void setBytesSpeed(Long bytesSpeed) {
        this.bytesSpeed = bytesSpeed;
    }
 
    public String getApp() {
        return app;
    }
 
    public void setApp(String app) {
        this.app = app;
    }
 
    public String getStream() {
        return stream;
    }
 
    public void setStream(String stream) {
        this.stream = stream;
    }
 
    public MediaServer getMediaServer() {
        return mediaServer;
    }
 
    public void setMediaServer(MediaServer mediaServer) {
        this.mediaServer = mediaServer;
    }
 
    public String getSchema() {
        return schema;
    }
 
    public void setSchema(String schema) {
        this.schema = schema;
    }
 
    public String getCallId() {
        return callId;
    }
 
    public void setCallId(String callId) {
        this.callId = callId;
    }
}