openmeetings-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From codesite-nore...@google.com
Subject [red5phone] r102 committed - Video: video stream switching is added;...
Date Wed, 06 Mar 2013 05:44:32 GMT
Revision: 102
Author:   solomax666@gmail.com
Date:     Tue Mar  5 21:44:18 2013
Log:      Video: video stream switching is added;
	logs cleanup
http://code.google.com/p/red5phone/source/detail?r=102

Modified:
  /branches/red5sip/src/java/org/red5/sip/app/PlayNetStream.java
  /branches/red5sip/src/java/org/red5/sip/app/RTMPRoomClient.java
  /branches/red5sip/src/java/org/red5/sip/app/SIPVideoConverter.java

=======================================
--- /branches/red5sip/src/java/org/red5/sip/app/PlayNetStream.java	Tue Mar   
5 01:52:05 2013
+++ /branches/red5sip/src/java/org/red5/sip/app/PlayNetStream.java	Tue Mar   
5 21:44:18 2013
@@ -7,6 +7,7 @@
  import org.red5.server.net.rtmp.event.IRTMPEvent;
  import org.red5.server.net.rtmp.event.SerializeUtils;
  import org.red5.server.net.rtmp.event.VideoData;
+import org.red5.server.net.rtmp.event.VideoData.FrameType;
  import org.red5.server.stream.AbstractClientStream;
  import org.red5.server.stream.IStreamData;
  import org.slf4j.Logger;
@@ -24,10 +25,17 @@
  	private IMediaSender videoSender;

  	private IMediaStream videoStream;
+
+	private RTMPRoomClient client;
+
+	private int currentStreamID = -1;
+
+	private boolean keyframeReceived = false;

-	public PlayNetStream(IMediaSender audioSender, IMediaSender videoSender) {
+	public PlayNetStream(IMediaSender audioSender, IMediaSender videoSender,  
RTMPRoomClient client) {
  		this.audioSender = audioSender;
  		this.videoSender = videoSender;
+		this.client = client;
  	}

  	public void close() {
@@ -56,8 +64,6 @@
  			videoSender.deleteStream(getStreamId());
  		}
  	}
-
-	private long sipStream = -1;

  	public void dispatchEvent(IEvent event) {

@@ -79,9 +85,25 @@
  		}

  		if (rtmpEvent instanceof VideoData) {
-			if (sipStream == -1)
-				sipStream = rtmpEvent.getHeader().getStreamId();
-			if (rtmpEvent.getHeader().getStreamId() != sipStream) return;
+			int newStreamId = client.getActiveVideoStreamID();
+			if (rtmpEvent.getHeader().getStreamId() != newStreamId) {
+				return;
+			}
+
+			if (currentStreamID != newStreamId) {
+				logger.debug("switching video to a new stream: " + newStreamId);
+				currentStreamID = newStreamId;
+				keyframeReceived = false;
+			}
+
+			if (((VideoData) rtmpEvent).getFrameType() == FrameType.KEYFRAME) {
+				keyframeReceived = true;
+			}
+
+			if (!keyframeReceived) {
+				logger.debug("Keyframe is not received. Packet is ignored.");
+				return;
+			}

  			int videoTs = rtmpEvent.getTimestamp();
  			IoBuffer videoData = ((VideoData)  
rtmpEvent).getData().asReadOnlyBuffer();
=======================================
--- /branches/red5sip/src/java/org/red5/sip/app/RTMPRoomClient.java	Tue  
Mar  5 01:52:05 2013
+++ /branches/red5sip/src/java/org/red5/sip/app/RTMPRoomClient.java	Tue  
Mar  5 21:44:18 2013
@@ -82,6 +82,7 @@
  	final private int roomId;
  	final private String context;
  	final private String host;
+	private int activeVideoStreamID = -1;

  	public RTMPRoomClient(String host, String context, int roomId) {
  		super();
@@ -154,6 +155,10 @@
  	protected void listBroadcastIds() {
  		invoke("listRoomBroadcast", this);
  	}
+
+	public int getActiveVideoStreamID() {
+		return activeVideoStreamID;
+	}

  	private void createPlayStream(long broadCastId) {

@@ -177,12 +182,15 @@
  			if (conn != null && streamIdInt != null
  					&& (publishStreamId == null || streamIdInt.intValue() !=  
publishStreamId)) {
  				clientStreamMap.put(broadCastId, streamIdInt);
-				PlayNetStream stream = new PlayNetStream(audioSender, videoSender);
+				PlayNetStream stream = new PlayNetStream(audioSender, videoSender,  
RTMPRoomClient.this);
  				stream.setConnection(conn);
  				stream.setStreamId(streamIdInt.intValue());
  				conn.addClientStream(stream);
  				play(streamIdInt, "" + broadCastId, -2000, -1000);
  				stream.start();
+				if (activeVideoStreamID == -1) {
+					activeVideoStreamID = streamIdInt;
+				}
  			}
  		}
  	}
@@ -345,6 +353,13 @@
  			conn.getStreamById(streamId).stop();
  			conn.removeClientStream(streamId);
  			conn.deleteStreamById(streamId);
+			if (streamId == activeVideoStreamID) {
+				if (clientStreamMap.size() == 0) {
+					activeVideoStreamID = -1;
+				} else {
+					activeVideoStreamID = clientStreamMap.values().iterator().next();
+				}
+			}
  		}
  	}

=======================================
--- /branches/red5sip/src/java/org/red5/sip/app/SIPVideoConverter.java	Tue  
Mar  5 01:52:05 2013
+++ /branches/red5sip/src/java/org/red5/sip/app/SIPVideoConverter.java	Tue  
Mar  5 21:44:18 2013
@@ -69,12 +69,9 @@
  		if (data[0] == 0x17 && data[1] == 0) {
  			byte[] pdata = Arrays.copyOfRange(data, 2, data.length);
  			int cfgVer = pdata[3];
-			log.debug("cfgVer=" + cfgVer);
  			if (cfgVer == 1) {
  				int lenSize = pdata[7] & 0x03 + 1;
  				int numSPS = pdata[8] & 0x1f;
-				log.debug("lenSize=" + lenSize);
-				log.debug("numSPS=" + numSPS);
  				pdata = Arrays.copyOfRange(pdata, 9, pdata.length);
  				byte[] sps = null;
  				for (int i = 0; i < numSPS; i++) {
@@ -86,7 +83,6 @@
  					pdata = Arrays.copyOfRange(pdata, lenSPS, pdata.length);
  				}
  				int numPPS = pdata[0];
-				log.debug("numPPS=" + numSPS);
  				pdata = Arrays.copyOfRange(pdata, 1, pdata.length);
  				byte[] pps = null;
  				for (int i = 0; i < numPPS; i++) {
@@ -123,7 +119,6 @@
  			if (spsSent && ppsSent) {
  				List<ByteArrayBuilder> nals = new ArrayList<ByteArrayBuilder>();
  				byte[] pdata = Arrays.copyOfRange(data, 5, data.length);
-				log.debug("pdata.length=" + pdata.length);
  				while (pdata.length > 0) {
  					int nalSize = 0;
  					switch (lenSize) {
@@ -142,18 +137,15 @@
  					default:
  						throw new RuntimeException("Invalid length size: " + lenSize);
  					}
-					log.debug("nalSize=" + nalSize);
  					ByteArrayBuilder nalData = new  
ByteArrayBuilder(Arrays.copyOfRange(pdata, lenSize, lenSize + nalSize));
  					nals.add(nalData);
  					pdata = Arrays.copyOfRange(pdata, lenSize + nalSize, pdata.length);
  				}
-				log.debug("nals.size()=" + nals.size());
  				if (nals.size() > 0) {
  					byte[] remaining = nals.get(nals.size() - 1).buildArray();
  					int nalType = remaining[0] & 0x1f;
  					int nri = remaining[0] & 0x60;
  					int maxSize = 1446;
-					log.debug("nalType=" + nalType);
  					if (nalType == 5 || nalType == 1) {
  						long ts1 = ts * 90;
  						if (remaining.length < maxSize) {
@@ -186,7 +178,6 @@
  				}
  			}
  		}
-		log.debug("result.size()=" + result.size());
  		return result;
  	}


Mime
View raw message