diff --git a/src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java index a7416a8e..dbb0a883 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java @@ -2,10 +2,11 @@ package com.genersoft.iot.vmp.conf; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.IMediaServerService; +import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; -import org.springframework.core.annotation.Order; +import org.json.JSONObject; import org.mitre.dsmiley.httpproxy.ProxyServlet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,13 +15,20 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; import org.springframework.util.ObjectUtils; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.ConnectException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * @author lin @@ -73,10 +81,39 @@ public class ProxyServletConfig { response.removeHeaders("Access-Control-Allow-Origin"); response.setHeader("Access-Control-Allow-Credentials","true"); response.removeHeaders("Access-Control-Allow-Credentials"); + if (servletResponse.getStatus() == HttpServletResponse.SC_OK) { + HttpEntity entity = response.getEntity(); + if (entity != null) { + if (entity.isChunked()) { + List byteList = new ArrayList<>(); + InputStream is = entity.getContent(); + OutputStream os = servletResponse.getOutputStream(); + byte[] buffer = new byte[10240]; + ByteBuffer byteBuffer = new ByteBuffer() + while(true) { + do { + int read; + if ((read = is.read(buffer)) == -1) { + return; + } + buffer + byteList.addAll(buffer.) + os.write(buffer, 0, read); + } while(!this.doHandleCompression && is.available() != 0); + + os.flush(); + } + } else { + OutputStream servletOutputStream = servletResponse.getOutputStream(); + entity.writeTo(servletOutputStream); + } + } + } return response; } + /** * 异常处理 */ diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnStreamChangedHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnStreamChangedHookParam.java index 4587fb0f..2cbdfc9b 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnStreamChangedHookParam.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnStreamChangedHookParam.java @@ -120,17 +120,17 @@ public class OnStreamChangedHookParam extends HookParam{ /** * H264 = 0, H265 = 1, AAC = 2, G711A = 3, G711U = 4 */ - private int codecId; + private int codec_id; /** * 编码类型名称 CodecAAC CodecH264 */ - private String codecIdName; + private String codec_id_name; /** * Video = 0, Audio = 1 */ - private int codecType; + private int codec_type; /** * 轨道是否准备就绪 @@ -145,7 +145,7 @@ public class OnStreamChangedHookParam extends HookParam{ /** * 音频采样率 */ - private int sampleRate; + private int sample_rate; /** * 视频fps @@ -170,28 +170,28 @@ public class OnStreamChangedHookParam extends HookParam{ this.channels = channels; } - public int getCodecId() { - return codecId; + public int getCodec_id() { + return codec_id; } - public void setCodecId(int codecId) { - this.codecId = codecId; + public void setCodec_id(int codec_id) { + this.codec_id = codec_id; } - public String getCodecIdName() { - return codecIdName; + public String getCodec_id_name() { + return codec_id_name; } - public void setCodecIdName(String codecIdName) { - this.codecIdName = codecIdName; + public void setCodec_id_name(String codec_id_name) { + this.codec_id_name = codec_id_name; } - public int getCodecType() { - return codecType; + public int getCodec_type() { + return codec_type; } - public void setCodecType(int codecType) { - this.codecType = codecType; + public void setCodec_type(int codec_type) { + this.codec_type = codec_type; } public boolean isReady() { @@ -210,12 +210,12 @@ public class OnStreamChangedHookParam extends HookParam{ this.sampleBit = sampleBit; } - public int getSampleRate() { - return sampleRate; + public int getSample_rate() { + return sample_rate; } - public void setSampleRate(int sampleRate) { - this.sampleRate = sampleRate; + public void setSample_rate(int sample_rate) { + this.sample_rate = sample_rate; } public int getFps() {