648540858
2024-03-21 b90dc789b429c31674c26bb3ff309b987afaa77a
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
package com.genersoft.iot.vmp.media.bean;
 
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
import io.swagger.v3.oas.annotations.media.Schema;
 
import java.util.List;
 
/**
 * 视频信息
 */
@Schema(description = "视频信息")
public class MediaInfo {
    @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;
 
    public static MediaInfo getInstance(JSONObject jsonObject) {
        MediaInfo mediaInfo = new MediaInfo();
        Integer totalReaderCount = jsonObject.getInteger("totalReaderCount");
        if (totalReaderCount != null) {
            mediaInfo.setReaderCount(totalReaderCount);
        }
        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) {
        List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
        MediaInfo mediaInfo = new MediaInfo();
        mediaInfo.setReaderCount(param.getTotalReaderCount());
        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;
    }
}