Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move ts before read audio buffer #1321

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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