Add video output FPS dectection

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 9 years ago
parent be1b7d888b
commit 4ec88b7131

@ -93,6 +93,10 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback, Ca
}
});
}
@Override
public void onRtmpOutputFps(final double fps) {
Log.i(TAG, String.format("Output Fps: %f", fps));
});
@Override

@ -84,5 +84,7 @@ public interface RtmpPublisher {
void onRtmpStopped(String msg);
void onRtmpDisconnected(String msg);
void onRtmpOutputFps(double fps);
}
}

@ -113,7 +113,7 @@ public class RtmpConnection implements RtmpPublisher, PacketRxHandler {
Log.d(TAG, "connect(): handshake done");
rtmpSessionInfo = new RtmpSessionInfo();
readThread = new ReadThread(rtmpSessionInfo, in, this);
writeThread = new WriteThread(rtmpSessionInfo, out, videoFrameCacheNumber);
writeThread = new WriteThread(rtmpSessionInfo, out, videoFrameCacheNumber, mHandler);
readThread.start();
writeThread.start();
@ -505,7 +505,7 @@ public class RtmpConnection implements RtmpPublisher, PacketRxHandler {
}
}
} else {
Log.e(TAG, "handleRxInvoke(): Uknown/unhandled server invoke: " + invoke);
Log.e(TAG, "handleRxInvoke(): Unknown/unhandled server invoke: " + invoke);
}
}

@ -7,6 +7,8 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import android.util.Log;
import net.ossrs.sea.rtmp.RtmpPublisher;
import net.ossrs.sea.rtmp.packets.Command;
import net.ossrs.sea.rtmp.packets.RtmpPacket;
import net.ossrs.sea.rtmp.packets.Video;
@ -20,18 +22,22 @@ public class WriteThread extends Thread {
private static final String TAG = "WriteThread";
private RtmpPublisher.EventHandler handler;
private RtmpSessionInfo rtmpSessionInfo;
private OutputStream out;
private ConcurrentLinkedQueue<RtmpPacket> writeQueue = new ConcurrentLinkedQueue<RtmpPacket>();
private final Object txPacketLock = new Object();
private volatile boolean active = true;
private int videoFrameCount;
private long lastTimeMillis;
private AtomicInteger videoFrameCacheNumber;
public WriteThread(RtmpSessionInfo rtmpSessionInfo, OutputStream out, AtomicInteger count) {
public WriteThread(RtmpSessionInfo rtmpSessionInfo, OutputStream out, AtomicInteger count, RtmpPublisher.EventHandler handler) {
super("RtmpWriteThread");
this.rtmpSessionInfo = rtmpSessionInfo;
this.out = out;
this.videoFrameCacheNumber = count;
this.handler = handler;
}
@Override
@ -51,6 +57,7 @@ public class WriteThread extends Thread {
}
if (rtmpPacket instanceof Video) {
videoFrameCacheNumber.getAndDecrement();
calcFps();
}
}
out.flush();
@ -100,4 +107,17 @@ public class WriteThread extends Thread {
txPacketLock.notify();
}
}
private void calcFps() {
if (videoFrameCount == 0) {
lastTimeMillis = System.nanoTime() / 1000000;
videoFrameCount++;
} else {
if (++videoFrameCount >= 48) {
long diffTimeMillis = System.nanoTime() / 1000000 - lastTimeMillis;
handler.onRtmpOutputFps((double) videoFrameCount * 1000 / diffTimeMillis);
videoFrameCount = 0;
}
}
}
}

Loading…
Cancel
Save