MediaInfo.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. package com.genersoft.iot.vmp.media.bean;
  2. import com.alibaba.fastjson2.JSONArray;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.genersoft.iot.vmp.media.zlm.dto.MediaServer;
  5. import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
  6. import io.swagger.v3.oas.annotations.media.Schema;
  7. import java.util.List;
  8. /**
  9. * 视频信息
  10. */
  11. @Schema(description = "视频信息")
  12. public class MediaInfo {
  13. @Schema(description = "应用名")
  14. private String app;
  15. @Schema(description = "流ID")
  16. private String stream;
  17. @Schema(description = "流媒体节点")
  18. private MediaServer mediaServer;
  19. @Schema(description = "协议")
  20. private String schema;
  21. @Schema(description = "观看人数")
  22. private Integer readerCount;
  23. @Schema(description = "视频编码类型")
  24. private String videoCodec;
  25. @Schema(description = "视频宽度")
  26. private Integer width;
  27. @Schema(description = "视频高度")
  28. private Integer height;
  29. @Schema(description = "音频编码类型")
  30. private String audioCodec;
  31. @Schema(description = "音频通道数")
  32. private Integer audioChannels;
  33. @Schema(description = "音频采样率")
  34. private Integer audioSampleRate;
  35. @Schema(description = "音频采样率")
  36. private Long duration;
  37. @Schema(description = "在线")
  38. private Boolean online;
  39. @Schema(description = "unknown = 0,rtmp_push=1,rtsp_push=2,rtp_push=3,pull=4,ffmpeg_pull=5,mp4_vod=6,device_chn=7")
  40. private Integer originType;
  41. @Schema(description = "存活时间,单位秒")
  42. private Long aliveSecond;
  43. @Schema(description = "数据产生速度,单位byte/s")
  44. private Long bytesSpeed;
  45. public static MediaInfo getInstance(JSONObject jsonObject, MediaServer mediaServer) {
  46. MediaInfo mediaInfo = new MediaInfo();
  47. mediaInfo.setMediaServer(mediaServer);
  48. String app = jsonObject.getString("app");
  49. mediaInfo.setApp(app);
  50. String stream = jsonObject.getString("stream");
  51. mediaInfo.setStream(stream);
  52. String schema = jsonObject.getString("schema");
  53. mediaInfo.setSchema(schema);
  54. Integer totalReaderCount = jsonObject.getInteger("totalReaderCount");
  55. Boolean online = jsonObject.getBoolean("online");
  56. Integer originType = jsonObject.getInteger("originType");
  57. Long aliveSecond = jsonObject.getLong("aliveSecond");
  58. Long bytesSpeed = jsonObject.getLong("bytesSpeed");
  59. if (totalReaderCount != null) {
  60. mediaInfo.setReaderCount(totalReaderCount);
  61. }
  62. if (online != null) {
  63. mediaInfo.setOnline(online);
  64. }
  65. if (originType != null) {
  66. mediaInfo.setOriginType(originType);
  67. }
  68. if (aliveSecond != null) {
  69. mediaInfo.setAliveSecond(aliveSecond);
  70. }
  71. if (bytesSpeed != null) {
  72. mediaInfo.setBytesSpeed(bytesSpeed);
  73. }
  74. JSONArray jsonArray = jsonObject.getJSONArray("tracks");
  75. if (jsonArray.isEmpty()) {
  76. return null;
  77. }
  78. for (int i = 0; i < jsonArray.size(); i++) {
  79. JSONObject trackJson = jsonArray.getJSONObject(i);
  80. Integer channels = trackJson.getInteger("channels");
  81. Integer codecId = trackJson.getInteger("codec_id");
  82. Integer codecType = trackJson.getInteger("codec_type");
  83. Integer sampleRate = trackJson.getInteger("sample_rate");
  84. Integer height = trackJson.getInteger("height");
  85. Integer width = trackJson.getInteger("height");
  86. Long duration = trackJson.getLongValue("duration");
  87. if (channels != null) {
  88. mediaInfo.setAudioChannels(channels);
  89. }
  90. if (sampleRate != null) {
  91. mediaInfo.setAudioSampleRate(sampleRate);
  92. }
  93. if (height != null) {
  94. mediaInfo.setHeight(height);
  95. }
  96. if (width != null) {
  97. mediaInfo.setWidth(width);
  98. }
  99. if (duration > 0L) {
  100. mediaInfo.setDuration(duration);
  101. }
  102. if (codecId != null) {
  103. switch (codecId) {
  104. case 0:
  105. mediaInfo.setVideoCodec("H264");
  106. break;
  107. case 1:
  108. mediaInfo.setVideoCodec("H265");
  109. break;
  110. case 2:
  111. mediaInfo.setAudioCodec("AAC");
  112. break;
  113. case 3:
  114. mediaInfo.setAudioCodec("G711A");
  115. break;
  116. case 4:
  117. mediaInfo.setAudioCodec("G711U");
  118. break;
  119. }
  120. }
  121. }
  122. return mediaInfo;
  123. }
  124. public static MediaInfo getInstance(OnStreamChangedHookParam param, MediaServer mediaServer) {
  125. MediaInfo mediaInfo = new MediaInfo();
  126. mediaInfo.setApp(param.getApp());
  127. mediaInfo.setStream(param.getStream());
  128. mediaInfo.setSchema(param.getSchema());
  129. mediaInfo.setMediaServer(mediaServer);
  130. mediaInfo.setReaderCount(param.getTotalReaderCount());
  131. mediaInfo.setOnline(param.isRegist());
  132. mediaInfo.setOriginType(param.getOriginType());
  133. mediaInfo.setAliveSecond(param.getAliveSecond());
  134. mediaInfo.setBytesSpeed(param.getBytesSpeed());
  135. List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
  136. if (tracks == null || tracks.isEmpty()) {
  137. return mediaInfo;
  138. }
  139. for (OnStreamChangedHookParam.MediaTrack mediaTrack : tracks) {
  140. switch (mediaTrack.getCodec_id()) {
  141. case 0:
  142. mediaInfo.setVideoCodec("H264");
  143. break;
  144. case 1:
  145. mediaInfo.setVideoCodec("H265");
  146. break;
  147. case 2:
  148. mediaInfo.setAudioCodec("AAC");
  149. break;
  150. case 3:
  151. mediaInfo.setAudioCodec("G711A");
  152. break;
  153. case 4:
  154. mediaInfo.setAudioCodec("G711U");
  155. break;
  156. }
  157. if (mediaTrack.getSample_rate() > 0) {
  158. mediaInfo.setAudioSampleRate(mediaTrack.getSample_rate());
  159. }
  160. if (mediaTrack.getChannels() > 0) {
  161. mediaInfo.setAudioChannels(mediaTrack.getChannels());
  162. }
  163. if (mediaTrack.getHeight() > 0) {
  164. mediaInfo.setHeight(mediaTrack.getHeight());
  165. }
  166. if (mediaTrack.getWidth() > 0) {
  167. mediaInfo.setWidth(mediaTrack.getWidth());
  168. }
  169. }
  170. return mediaInfo;
  171. }
  172. public Integer getReaderCount() {
  173. return readerCount;
  174. }
  175. public void setReaderCount(Integer readerCount) {
  176. this.readerCount = readerCount;
  177. }
  178. public String getVideoCodec() {
  179. return videoCodec;
  180. }
  181. public void setVideoCodec(String videoCodec) {
  182. this.videoCodec = videoCodec;
  183. }
  184. public Integer getWidth() {
  185. return width;
  186. }
  187. public void setWidth(Integer width) {
  188. this.width = width;
  189. }
  190. public Integer getHeight() {
  191. return height;
  192. }
  193. public void setHeight(Integer height) {
  194. this.height = height;
  195. }
  196. public String getAudioCodec() {
  197. return audioCodec;
  198. }
  199. public void setAudioCodec(String audioCodec) {
  200. this.audioCodec = audioCodec;
  201. }
  202. public Integer getAudioChannels() {
  203. return audioChannels;
  204. }
  205. public void setAudioChannels(Integer audioChannels) {
  206. this.audioChannels = audioChannels;
  207. }
  208. public Integer getAudioSampleRate() {
  209. return audioSampleRate;
  210. }
  211. public void setAudioSampleRate(Integer audioSampleRate) {
  212. this.audioSampleRate = audioSampleRate;
  213. }
  214. public Long getDuration() {
  215. return duration;
  216. }
  217. public void setDuration(Long duration) {
  218. this.duration = duration;
  219. }
  220. public Boolean getOnline() {
  221. return online;
  222. }
  223. public void setOnline(Boolean online) {
  224. this.online = online;
  225. }
  226. public Integer getOriginType() {
  227. return originType;
  228. }
  229. public void setOriginType(Integer originType) {
  230. this.originType = originType;
  231. }
  232. public Long getAliveSecond() {
  233. return aliveSecond;
  234. }
  235. public void setAliveSecond(Long aliveSecond) {
  236. this.aliveSecond = aliveSecond;
  237. }
  238. public Long getBytesSpeed() {
  239. return bytesSpeed;
  240. }
  241. public void setBytesSpeed(Long bytesSpeed) {
  242. this.bytesSpeed = bytesSpeed;
  243. }
  244. public String getApp() {
  245. return app;
  246. }
  247. public void setApp(String app) {
  248. this.app = app;
  249. }
  250. public String getStream() {
  251. return stream;
  252. }
  253. public void setStream(String stream) {
  254. this.stream = stream;
  255. }
  256. public MediaServer getMediaServer() {
  257. return mediaServer;
  258. }
  259. public void setMediaServer(MediaServer mediaServer) {
  260. this.mediaServer = mediaServer;
  261. }
  262. public String getSchema() {
  263. return schema;
  264. }
  265. public void setSchema(String schema) {
  266. this.schema = schema;
  267. }
  268. }