Parameter adjustment

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 8 years ago
parent 1e5c7c1675
commit 9f4e114308

@ -26,18 +26,18 @@ public class SrsEncoder {
public static String x264Preset = "veryfast"; public static String x264Preset = "veryfast";
public static int vPrevWidth = 640; public static int vPrevWidth = 640;
public static int vPrevHeight = 360; public static int vPrevHeight = 360;
public static int vPortraitWidth = 720; public static int vPortraitWidth = 360;
public static int vPortraitHeight = 1280; public static int vPortraitHeight = 640;
public static int vLandscapeWidth = 1280; public static int vLandscapeWidth = 640;
public static int vLandscapeHeight = 720; public static int vLandscapeHeight = 360;
public static int vOutWidth = 720; // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK public static int vOutWidth = 360; // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK
public static int vOutHeight = 1280; // Since Y component is quadruple size as U and V component, the stride must be set as 32x public static int vOutHeight = 640; // Since Y component is quadruple size as U and V component, the stride must be set as 32x
public static int vBitrate = 1200 * 1024; // 1200 kbps public static int vBitrate = 1200 * 1024; // 1200 kbps
public static final int VFPS = 24; public static final int VFPS = 24;
public static final int VGOP = 48; public static final int VGOP = 48;
public static final int ASAMPLERATE = 44100; public static final int ASAMPLERATE = 44100;
public static int aChannelConfig = AudioFormat.CHANNEL_IN_STEREO; public static int aChannelConfig = AudioFormat.CHANNEL_IN_STEREO;
public static final int ABITRATE = 128 * 1024; // 128 kbps public static final int ABITRATE = 64 * 1024; // 64 kbps
private SrsEncodeHandler mHandler; private SrsEncodeHandler mHandler;
@ -340,26 +340,31 @@ public class SrsEncoder {
} }
public void onGetPcmFrame(byte[] data, int size) { public void onGetPcmFrame(byte[] data, int size) {
ByteBuffer[] inBuffers = aencoder.getInputBuffers(); // Check video frame cache number to judge the networking situation.
ByteBuffer[] outBuffers = aencoder.getOutputBuffers(); // Just cache GOP / FPS seconds data according to latency.
AtomicInteger videoFrameCacheNumber = flvMuxer.getVideoFrameCacheNumber();
int inBufferIndex = aencoder.dequeueInputBuffer(-1); if (videoFrameCacheNumber != null && videoFrameCacheNumber.get() < VGOP) {
if (inBufferIndex >= 0) { ByteBuffer[] inBuffers = aencoder.getInputBuffers();
ByteBuffer bb = inBuffers[inBufferIndex]; ByteBuffer[] outBuffers = aencoder.getOutputBuffers();
bb.clear();
bb.put(data, 0, size); int inBufferIndex = aencoder.dequeueInputBuffer(-1);
long pts = System.nanoTime() / 1000 - mPresentTimeUs; if (inBufferIndex >= 0) {
aencoder.queueInputBuffer(inBufferIndex, 0, size, pts, 0); ByteBuffer bb = inBuffers[inBufferIndex];
} bb.clear();
bb.put(data, 0, size);
long pts = System.nanoTime() / 1000 - mPresentTimeUs;
aencoder.queueInputBuffer(inBufferIndex, 0, size, pts, 0);
}
for (; ; ) { for (; ; ) {
int outBufferIndex = aencoder.dequeueOutputBuffer(aebi, 0); int outBufferIndex = aencoder.dequeueOutputBuffer(aebi, 0);
if (outBufferIndex >= 0) { if (outBufferIndex >= 0) {
ByteBuffer bb = outBuffers[outBufferIndex]; ByteBuffer bb = outBuffers[outBufferIndex];
onEncodedAacFrame(bb, aebi); onEncodedAacFrame(bb, aebi);
aencoder.releaseOutputBuffer(outBufferIndex, false); aencoder.releaseOutputBuffer(outBufferIndex, false);
} else { } else {
break; break;
}
} }
} }
} }

Loading…
Cancel
Save