| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- 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;
- @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;
- public static MediaInfo getInstance(JSONObject jsonObject) {
- MediaInfo mediaInfo = new MediaInfo();
- 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) {
- List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
- MediaInfo mediaInfo = new MediaInfo();
- mediaInfo.setReaderCount(param.getTotalReaderCount());
- mediaInfo.setOnline(param.isRegist());
- mediaInfo.setOriginType(param.getOriginType());
- mediaInfo.setAliveSecond(param.getAliveSecond());
- mediaInfo.setBytesSpeed(param.getBytesSpeed());
- 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;
- }
- }
|