Skip to content

Commit

Permalink
move ts before read audio buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Nov 1, 2023
1 parent ed8c6d9 commit cc57414
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ public boolean isMuted() {
* @return Object with size and PCM buffer data
*/
protected Frame read() {
long timeStamp = System.nanoTime() / 1000;
int size = audioRecord.read(pcmBuffer, 0, pcmBuffer.length);
if (size < 0){
Log.e(TAG, "read error: " + size);
return null;
}
long timeStamp = System.nanoTime() / 1000;
return new Frame(muted ? pcmBufferMuted : customAudioEffect.process(pcmBuffer), 0, size, timeStamp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public boolean prepareAudio() {
}

@Override
protected boolean decodeOutput(ByteBuffer outputBuffer) {
long timeStamp = System.nanoTime() / 1000;
protected boolean decodeOutput(ByteBuffer outputBuffer, long timeStamp) {
//This buffer is PCM data
if (muted) {
outputBuffer.get(pcmBufferMuted, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public double getTime() {

protected abstract boolean extract(MediaExtractor extractor);

protected abstract boolean decodeOutput(ByteBuffer outputBuffer);
protected abstract boolean decodeOutput(ByteBuffer outputBuffer, long timeStamp);

protected abstract void finished();

Expand All @@ -248,7 +248,8 @@ private void decode() {
}
}
int inIndex = codec.dequeueInputBuffer(10000);
int sampleSize = 0;
int sampleSize;
long timeStamp = System.nanoTime() / 1000;
if (inIndex >= 0) {
ByteBuffer input;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -285,7 +286,7 @@ private void decode() {
} else {
output = codec.getOutputBuffers()[outIndex];
}
boolean render = decodeOutput(output);
boolean render = decodeOutput(output, timeStamp);
codec.releaseOutputBuffer(outIndex, render && bufferInfo.size != 0);
boolean finished = extractor.getSampleTime() < 0;
if (finished) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public boolean prepareVideo(Surface surface) {
}

@Override
protected boolean decodeOutput(ByteBuffer outputBuffer) {
protected boolean decodeOutput(ByteBuffer outputBuffer, long timeStamp) {
return true;
}

Expand Down

0 comments on commit cc57414

Please sign in to comment.