648540858
2024-03-21 4134c73745ff63d44186ed608735ea432b244755
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
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 Track {
    @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;
 
    public static Track getInstance(JSONObject jsonObject) {
        Track track = new Track();
        Integer totalReaderCount = jsonObject.getInteger("totalReaderCount");
        if (totalReaderCount != null) {
            track.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");
            if (channels != null) {
                track.setAudioChannels(channels);
            }
            if (sampleRate != null) {
                track.setAudioSampleRate(sampleRate);
            }
            if (height != null) {
                track.setHeight(height);
            }
            if (width != null) {
                track.setWidth(width);
            }
            if (codecId != null) {
                switch (codecId) {
                    case 0:
                        track.setVideoCodec("H264");
                        break;
                    case 1:
                        track.setVideoCodec("H265");
                        break;
                    case 2:
                        track.setAudioCodec("AAC");
                        break;
                    case 3:
                        track.setAudioCodec("G711A");
                        break;
                    case 4:
                        track.setAudioCodec("G711U");
                        break;
                }
            }
        }
        return track;
    }
 
    public static Track getInstance(OnStreamChangedHookParam param) {
        List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
        Track track = new Track();
        track.setReaderCount(param.getTotalReaderCount());
        for (OnStreamChangedHookParam.MediaTrack mediaTrack : tracks) {
            switch (mediaTrack.getCodec_id()) {
                case 0:
                    track.setVideoCodec("H264");
                    break;
                case 1:
                    track.setVideoCodec("H265");
                    break;
                case 2:
                    track.setAudioCodec("AAC");
                    break;
                case 3:
                    track.setAudioCodec("G711A");
                    break;
                case 4:
                    track.setAudioCodec("G711U");
                    break;
            }
            if (mediaTrack.getSample_rate() > 0) {
                track.setAudioSampleRate(mediaTrack.getSample_rate());
            }
            if (mediaTrack.getChannels() > 0) {
                track.setAudioChannels(mediaTrack.getChannels());
            }
            if (mediaTrack.getHeight() > 0) {
                track.setHeight(mediaTrack.getHeight());
            }
            if (mediaTrack.getWidth() > 0) {
                track.setWidth(mediaTrack.getWidth());
            }
        }
        return track;
    }
 
    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;
    }
}