Skip to content
Snippets Groups Projects
Commit ff61ee42 authored by Leo Ma's avatar Leo Ma
Browse files

Audio record improvement


Signed-off-by: default avatarLeo Ma <begeekmyfriend@gmail.com>
parent f166368c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -31,12 +31,12 @@ public class SrsEncoder {
public static int vLandscapeHeight = 384;
public static int vOutWidth = 384; // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK
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 = 500 * 1000; // 500kbps
public static int vBitrate = 1200 * 1024; // 1200 kbps
public static final int VFPS = 24;
public static final int VGOP = 48;
public static final int ASAMPLERATE = 44100;
public static int aChannelConfig = AudioFormat.CHANNEL_IN_STEREO;
public static final int ABITRATE = 32 * 1000; // 32kbps
public static final int ABITRATE = 128 * 1024; // 128 kbps
private int mOrientation = Configuration.ORIENTATION_PORTRAIT;
Loading
Loading
@@ -235,12 +235,12 @@ public class SrsEncoder {
}
public void setVideoHDMode() {
vBitrate = 1200 * 1000; // 1200 kbps
vBitrate = 1200 * 1024; // 1200 kbps
x264Preset = "veryfast";
}
public void setVideoSmoothMode() {
vBitrate = 500 * 1000; // 500 kbps
vBitrate = 500 * 1024; // 500 kbps
x264Preset = "superfast";
}
Loading
Loading
@@ -447,10 +447,11 @@ public class SrsEncoder {
}
public AudioRecord chooseAudioRecord() {
int minBufferSize = AudioRecord.getMinBufferSize(SrsEncoder.ASAMPLERATE, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);
AudioRecord mic = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, SrsEncoder.ASAMPLERATE, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize);
AudioRecord mic = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, SrsEncoder.ASAMPLERATE,
AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, getPcmBufferSize() * 4);
if (mic.getState() != AudioRecord.STATE_INITIALIZED) {
mic = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, SrsEncoder.ASAMPLERATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize);
mic = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, SrsEncoder.ASAMPLERATE,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, getPcmBufferSize() * 4);
if (mic.getState() != AudioRecord.STATE_INITIALIZED) {
mic = null;
} else {
Loading
Loading
@@ -463,6 +464,12 @@ public class SrsEncoder {
return mic;
}
private int getPcmBufferSize() {
int pcmBufSize = AudioRecord.getMinBufferSize(ASAMPLERATE, AudioFormat.CHANNEL_IN_STEREO,
AudioFormat.ENCODING_PCM_16BIT) + 8191;
return pcmBufSize - (pcmBufSize % 8192);
}
// choose the video encoder by name.
private MediaCodecInfo chooseVideoEncoder(String name) {
int nbCodecs = MediaCodecList.getCodecCount();
Loading
Loading
Loading
Loading
@@ -18,6 +18,7 @@ public class SrsPublisher {
private static AudioRecord mic;
private static AcousticEchoCanceler aec;
private static AutomaticGainControl agc;
private byte[] mPcmBuffer = new byte[4096];
private boolean aloop = false;
private Thread aworker;
Loading
Loading
@@ -211,14 +212,12 @@ public class SrsPublisher {
private void startAudio() {
if (mic != null) {
mic.startRecording();
byte pcmBuffer[] = new byte[4096];
while (aloop && !Thread.interrupted()) {
int size = mic.read(pcmBuffer, 0, pcmBuffer.length);
int size = mic.read(mPcmBuffer, 0, mPcmBuffer.length);
if (size <= 0) {
break;
}
mEncoder.onGetPcmFrame(pcmBuffer, size);
mEncoder.onGetPcmFrame(mPcmBuffer, size);
}
}
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment