MediaInfo.java 7.7 KB

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