Small changes to audio recording. Still bug

pull/360/head
Mattia Iavarone 6 years ago
parent a87b73a35d
commit 20691effb3
  1. 14
      cameraview/src/main/gles/com/otaliastudios/cameraview/AudioMediaEncoder.java
  2. 2
      cameraview/src/main/gles/com/otaliastudios/cameraview/MediaEncoder.java
  3. 3
      cameraview/src/main/gles/com/otaliastudios/cameraview/MediaEncoderEngine.java

@ -67,18 +67,17 @@ class AudioMediaEncoder extends MediaEncoder {
@Override
void stop() {
mRequestStop = true;
try {
synchronized (mLock) {
synchronized (mLock) {
try {
mLock.wait();
}
} catch (InterruptedException e) {
// Ignore
} catch (InterruptedException e) {}
}
}
@Override
void release() {
super.release();
mRequestStop = false;
}
class AudioThread extends Thread {
@ -93,8 +92,7 @@ class AudioMediaEncoder extends MediaEncoder {
if (bufferSize < minBufferSize) {
bufferSize = ((minBufferSize / SAMPLES_PER_FRAME) + 1) * SAMPLES_PER_FRAME * 2;
}
mAudioRecord = new AudioRecord(
MediaRecorder.AudioSource.CAMCORDER, SAMPLE_RATE,
mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.CAMCORDER, SAMPLE_RATE,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
}
@ -120,6 +118,8 @@ class AudioMediaEncoder extends MediaEncoder {
encode(null, 0, getPresentationTime());
drain(false);
mAudioRecord.stop();
mAudioRecord.release();
mAudioRecord = null;
synchronized (mLock) {
mLock.notify();
}

@ -77,7 +77,7 @@ abstract class MediaEncoder {
*/
protected void encode(final ByteBuffer buffer, final int length, final long presentationTimeUs) {
final ByteBuffer[] inputBuffers = mMediaCodec.getInputBuffers();
while (true) { // TODO: stop if stop() is called!
while (true) {
final int inputBufferIndex = mMediaCodec.dequeueInputBuffer(TIMEOUT_USEC);
if (inputBufferIndex >= 0) {
final ByteBuffer inputBuffer = inputBuffers[inputBufferIndex];

@ -74,6 +74,7 @@ class MediaEncoderEngine {
if (!mMediaMuxerStarted) {
throw new IllegalStateException("Trying to write before muxer started");
}
Log.e("MediaEncoderEngine", "Writing data." + track);
mMediaMuxer.writeSampleData(track, encodedData, info);
}
}
@ -107,7 +108,6 @@ class MediaEncoderEngine {
for (MediaEncoder encoder : mEncoders) {
encoder.stop();
}
onStop.run();
for (MediaEncoder encoder : mEncoders) {
encoder.release();
}
@ -118,6 +118,7 @@ class MediaEncoderEngine {
mMediaMuxer.release();
mMediaMuxer = null;
}
onStop.run();
mMediaMuxerStartCount = 0;
mMediaMuxerStarted = false;
}

Loading…
Cancel
Save