Skip to content

Commit

Permalink
修改HTTP-CHUNKED封装的时机
Browse files Browse the repository at this point in the history
  • Loading branch information
glaciall committed Jun 23, 2020
1 parent aaf47c2 commit dd6f9fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.org.hentai.jtt1078.subscriber;

import cn.org.hentai.jtt1078.flv.FlvEncoder;
import cn.org.hentai.jtt1078.util.Packet;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
Expand Down Expand Up @@ -64,7 +65,12 @@ public void run()
try
{
byte[] data = take();
if (data != null) send(data).await();
if (data != null)
{
send(String.format("%x\r\n", data.length).getBytes()).await();
send(data).await();
send(new byte[] { (byte) '\r', (byte) '\n' }).await();
}
}
catch(Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import cn.org.hentai.jtt1078.flv.FlvEncoder;
import cn.org.hentai.jtt1078.util.ByteBufUtils;
import cn.org.hentai.jtt1078.util.FLVUtils;
import cn.org.hentai.jtt1078.util.HttpChunk;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

Expand Down Expand Up @@ -34,18 +33,15 @@ public void onVideoData(long timeoffset, byte[] data, FlvEncoder flvEncoder)
// 之前是不是已经发送过了?没有的话,需要补发FLV HEADER的。。。
if (videoHeaderSent == false && flvEncoder.videoReady())
{
enqueue(HttpChunk.make(flvEncoder.getHeader().getBytes()));
enqueue(HttpChunk.make(flvEncoder.getVideoHeader().getBytes()));
enqueue(flvEncoder.getHeader().getBytes());
enqueue(flvEncoder.getVideoHeader().getBytes());

// 如果第一次发送碰到的不是I祯,那就把上一个缓存的I祯发下去
if ((data[4] & 0x1f) != 0x05)
// 直接下发第一个I帧
byte[] iFrame = flvEncoder.getLastIFrame();
if (iFrame != null)
{
byte[] iFrame = flvEncoder.getLastIFrame();
if (iFrame != null)
{
FLVUtils.resetTimestamp(iFrame, (int) videoTimestamp);
enqueue(HttpChunk.make(iFrame));
}
FLVUtils.resetTimestamp(iFrame, (int) videoTimestamp);
enqueue(iFrame);
}

videoHeaderSent = true;
Expand All @@ -59,7 +55,7 @@ public void onVideoData(long timeoffset, byte[] data, FlvEncoder flvEncoder)
videoTimestamp += (int)(timeoffset - lastVideoFrameTimeOffset);
lastVideoFrameTimeOffset = timeoffset;

enqueue(HttpChunk.make(data));
enqueue(data);
}

private FlvAudioTagEncoder audioEncoder = new FlvAudioTagEncoder();
Expand Down Expand Up @@ -90,7 +86,7 @@ public void onAudioData(long timeoffset, byte[] data, FlvEncoder flvEncoder)
audioTimestamp += (int)(timeoffset - lastAudioFrameTimeOffset);
lastAudioFrameTimeOffset = timeoffset;

if (videoHeaderSent) enqueue(HttpChunk.make(frameData));
if (videoHeaderSent) enqueue(frameData);
}

@Override
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/cn/org/hentai/jtt1078/util/HttpChunk.java

This file was deleted.

0 comments on commit dd6f9fe

Please sign in to comment.