Fix SetChunkSize command bug

The chunk size of RTMP packet means two things: When the SetChunkSize
command comes from the server, it changes rx chunk size of the peer
while the tx chunk size still stays unchanged.

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 9 years ago
parent 2e751b2027
commit e087e07e85

@ -464,7 +464,7 @@ public class SrsEncoder {
String[] types = mci.getSupportedTypes(); String[] types = mci.getSupportedTypes();
for (int j = 0; j < types.length; j++) { for (int j = 0; j < types.length; j++) {
if (types[j].equalsIgnoreCase(VCODEC)) { if (types[j].equalsIgnoreCase(VCODEC)) {
//Log.i(TAG, String.format("vencoder %s types: %s", mci.getName(), types[j])); Log.i(TAG, String.format("vencoder %s types: %s", mci.getName(), types[j]));
if (name == null) { if (name == null) {
return mci; return mci;
} }
@ -482,9 +482,9 @@ public class SrsEncoder {
// choose the right supported color format. @see below: // choose the right supported color format. @see below:
private int chooseVideoEncoder() { private int chooseVideoEncoder() {
// choose the encoder "video/avc": // choose the encoder "video/avc":
// 1. select one when type matched. // 1. select default one when type matched.
// 2. perfer google avc. // 2. google avc is unusable.
// 3. perfer qcom avc. // 3. choose qcom avc.
vmci = chooseVideoEncoder(null); vmci = chooseVideoEncoder(null);
//vmci = chooseVideoEncoder("google"); //vmci = chooseVideoEncoder("google");
//vmci = chooseVideoEncoder("qcom"); //vmci = chooseVideoEncoder("qcom");

@ -39,10 +39,10 @@ public class RtmpDecoder {
chunkStreamInfo.setPrevHeaderRx(header); chunkStreamInfo.setPrevHeaderRx(header);
if (header.getPacketLength() > rtmpSessionInfo.getChunkSize()) { if (header.getPacketLength() > rtmpSessionInfo.getRxChunkSize()) {
//Log.d(TAG, "readPacket(): packet size (" + header.getPacketLength() + ") is bigger than chunk size (" + rtmpSessionInfo.getChunkSize() + "); storing chunk data"); //Log.d(TAG, "readPacket(): packet size (" + header.getPacketLength() + ") is bigger than chunk size (" + rtmpSessionInfo.getChunkSize() + "); storing chunk data");
// This packet consists of more than one chunk; store the chunks in the chunk stream until everything is read // This packet consists of more than one chunk; store the chunks in the chunk stream until everything is read
if (!chunkStreamInfo.storePacketChunk(in, rtmpSessionInfo.getChunkSize())) { if (!chunkStreamInfo.storePacketChunk(in, rtmpSessionInfo.getRxChunkSize())) {
Log.d(TAG, " readPacket(): returning null because of incomplete packet"); Log.d(TAG, " readPacket(): returning null because of incomplete packet");
return null; // packet is not yet complete return null; // packet is not yet complete
} else { } else {
@ -59,7 +59,7 @@ public class RtmpDecoder {
SetChunkSize setChunkSize = new SetChunkSize(header); SetChunkSize setChunkSize = new SetChunkSize(header);
setChunkSize.readBody(in); setChunkSize.readBody(in);
Log.d(TAG, "readPacket(): Setting chunk size to: " + setChunkSize.getChunkSize()); Log.d(TAG, "readPacket(): Setting chunk size to: " + setChunkSize.getChunkSize());
rtmpSessionInfo.setChunkSize(setChunkSize.getChunkSize()); rtmpSessionInfo.setRxChunkSize(setChunkSize.getChunkSize());
return null; return null;
} }
case ABORT: case ABORT:

@ -19,7 +19,8 @@ public class RtmpSessionInfo {
private int totalBytesRead = 0; private int totalBytesRead = 0;
/** Default chunk size is 128 bytes */ /** Default chunk size is 128 bytes */
private int chunkSize = 128; private int rxChunkSize = 128;
private int txChunkSize = 128;
private Map<Integer, ChunkStreamInfo> chunkChannels = new HashMap<Integer, ChunkStreamInfo>(); private Map<Integer, ChunkStreamInfo> chunkChannels = new HashMap<Integer, ChunkStreamInfo>();
private Map<Integer, String> invokedMethods = new ConcurrentHashMap<Integer, String>(); private Map<Integer, String> invokedMethods = new ConcurrentHashMap<Integer, String>();
@ -40,12 +41,20 @@ public class RtmpSessionInfo {
return invokedMethods.put(transactionId, commandName); return invokedMethods.put(transactionId, commandName);
} }
public int getChunkSize() { public int getRxChunkSize() {
return chunkSize; return rxChunkSize;
} }
public void setChunkSize(int chunkSize) { public void setRxChunkSize(int chunkSize) {
this.chunkSize = chunkSize; this.rxChunkSize = chunkSize;
}
public int getTxChunkSize() {
return txChunkSize;
}
public void setTxChunkSize(int chunkSize) {
this.txChunkSize = chunkSize;
} }
public int getAcknowledgementWindowSize() { public int getAcknowledgementWindowSize() {

@ -41,7 +41,7 @@ public class WriteThread extends Thread {
RtmpPacket rtmpPacket = writeQueue.poll(); RtmpPacket rtmpPacket = writeQueue.poll();
final ChunkStreamInfo chunkStreamInfo = rtmpSessionInfo.getChunkStreamInfo(rtmpPacket.getHeader().getChunkStreamId()); final ChunkStreamInfo chunkStreamInfo = rtmpSessionInfo.getChunkStreamInfo(rtmpPacket.getHeader().getChunkStreamId());
chunkStreamInfo.setPrevHeaderTx(rtmpPacket.getHeader()); chunkStreamInfo.setPrevHeaderTx(rtmpPacket.getHeader());
rtmpPacket.writeTo(out, rtmpSessionInfo.getChunkSize(), chunkStreamInfo); rtmpPacket.writeTo(out, rtmpSessionInfo.getTxChunkSize(), chunkStreamInfo);
Log.d(TAG, "WriteThread: wrote packet: " + rtmpPacket + ", size: " + rtmpPacket.getHeader().getPacketLength()); Log.d(TAG, "WriteThread: wrote packet: " + rtmpPacket + ", size: " + rtmpPacket.getHeader().getPacketLength());
if (rtmpPacket instanceof Command) { if (rtmpPacket instanceof Command) {
rtmpSessionInfo.addInvokedCommand(((Command) rtmpPacket).getTransactionId(), ((Command) rtmpPacket).getCommandName()); rtmpSessionInfo.addInvokedCommand(((Command) rtmpPacket).getTransactionId(), ((Command) rtmpPacket).getCommandName());

Loading…
Cancel
Save