Commit 8552345f by hschlueter Committed by tonihei

Add PassthroughSamplePipeline for audio.

When no transformation is needed, the passthrough pipeline allows us to skip decoding and re-encoding.

PiperOrigin-RevId: 407789767
parent 85e222a7
......@@ -366,6 +366,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
errorCode);
}
// TODO(internal b/204978301): Ensure encoder and decoder timestamps match when no speed change.
private static long getBufferDurationUs(long bytesWritten, int bytesPerFrame, int sampleRate) {
long framesWritten = bytesWritten / bytesPerFrame;
return framesWritten * C.MICROS_PER_SECOND / sampleRate;
......
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.transformer;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
/** Pipeline that passes through the samples without any re-encoding or transformation. */
/* package */ final class PassthroughSamplePipeline implements SamplePipeline {
private final DecoderInputBuffer buffer;
private final Format format;
private boolean hasPendingBuffer;
public PassthroughSamplePipeline(Format format) {
this.format = format;
buffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT);
hasPendingBuffer = false;
}
@Override
@Nullable
public DecoderInputBuffer dequeueInputBuffer() {
return hasPendingBuffer ? null : buffer;
}
@Override
public void queueInputBuffer() {
hasPendingBuffer = true;
}
@Override
public boolean processData() {
return false;
}
@Override
public Format getOutputFormat() {
return format;
}
@Override
@Nullable
public DecoderInputBuffer getOutputBuffer() {
return hasPendingBuffer ? buffer : null;
}
@Override
public void releaseOutputBuffer() {
buffer.clear();
hasPendingBuffer = false;
}
@Override
public boolean isEnded() {
return buffer.isEndOfStream();
}
@Override
public void release() {}
}
......@@ -89,8 +89,14 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
if (result != C.RESULT_FORMAT_READ) {
return false;
}
samplePipeline =
new AudioSamplePipeline(checkNotNull(formatHolder.format), transformation, getIndex());
Format decoderInputFormat = checkNotNull(formatHolder.format);
if ((transformation.audioMimeType != null
&& !transformation.audioMimeType.equals(decoderInputFormat.sampleMimeType))
|| transformation.flattenForSlowMotion) {
samplePipeline = new AudioSamplePipeline(decoderInputFormat, transformation, getIndex());
} else {
samplePipeline = new PassthroughSamplePipeline(decoderInputFormat);
}
return true;
}
......
containerMimeType = video/mp4
format 0:
id = 2
sampleMimeType = audio/mp4a-latm
codecs = mp4a.40.2
maxInputSize = 294
channelCount = 1
sampleRate = 44100
pcmEncoding = 2
language = und
metadata = entries=[TSSE: description=null: value=Lavf56.1.0]
initializationData:
data = length 2, hash 5F7
sample:
trackIndex = 0
dataHashCode = 1205768497
size = 23
isKeyFrame = true
presentationTimeUs = 0
presentationTimeUs = 44000
sample:
trackIndex = 0
dataHashCode = 837571078
size = 6
isKeyFrame = true
presentationTimeUs = 249
presentationTimeUs = 67219
sample:
trackIndex = 0
dataHashCode = -1991633045
size = 148
isKeyFrame = true
presentationTimeUs = 317
presentationTimeUs = 90439
sample:
trackIndex = 0
dataHashCode = -822987359
size = 189
isKeyFrame = true
presentationTimeUs = 1995
presentationTimeUs = 113659
sample:
trackIndex = 0
dataHashCode = -1141508176
size = 205
isKeyFrame = true
presentationTimeUs = 4126
presentationTimeUs = 136879
sample:
trackIndex = 0
dataHashCode = -226971245
size = 210
isKeyFrame = true
presentationTimeUs = 6438
presentationTimeUs = 160099
sample:
trackIndex = 0
dataHashCode = -2099636855
size = 210
isKeyFrame = true
presentationTimeUs = 8818
presentationTimeUs = 183319
sample:
trackIndex = 0
dataHashCode = 1541550559
size = 207
isKeyFrame = true
presentationTimeUs = 11198
presentationTimeUs = 206539
sample:
trackIndex = 0
dataHashCode = 411148001
size = 225
isKeyFrame = true
presentationTimeUs = 13533
presentationTimeUs = 229759
sample:
trackIndex = 0
dataHashCode = -897603973
size = 215
isKeyFrame = true
presentationTimeUs = 16072
presentationTimeUs = 252979
sample:
trackIndex = 0
dataHashCode = 1478106136
size = 211
isKeyFrame = true
presentationTimeUs = 18498
presentationTimeUs = 276199
sample:
trackIndex = 0
dataHashCode = -1380417145
size = 216
isKeyFrame = true
presentationTimeUs = 20878
presentationTimeUs = 299419
sample:
trackIndex = 0
dataHashCode = 780903644
size = 229
isKeyFrame = true
presentationTimeUs = 23326
presentationTimeUs = 322639
sample:
trackIndex = 0
dataHashCode = 586204432
size = 232
isKeyFrame = true
presentationTimeUs = 25911
presentationTimeUs = 345859
sample:
trackIndex = 0
dataHashCode = -2038771492
size = 235
isKeyFrame = true
presentationTimeUs = 28541
presentationTimeUs = 369079
sample:
trackIndex = 0
dataHashCode = -2065161304
size = 231
isKeyFrame = true
presentationTimeUs = 31194
presentationTimeUs = 392299
sample:
trackIndex = 0
dataHashCode = 468662933
size = 226
isKeyFrame = true
presentationTimeUs = 33801
presentationTimeUs = 415519
sample:
trackIndex = 0
dataHashCode = -358398546
size = 216
isKeyFrame = true
presentationTimeUs = 36363
presentationTimeUs = 438739
sample:
trackIndex = 0
dataHashCode = 1767325983
size = 229
isKeyFrame = true
presentationTimeUs = 38811
presentationTimeUs = 461959
sample:
trackIndex = 0
dataHashCode = 1093095458
size = 219
isKeyFrame = true
presentationTimeUs = 41396
presentationTimeUs = 485179
sample:
trackIndex = 0
dataHashCode = 1687543702
size = 241
isKeyFrame = true
presentationTimeUs = 43867
presentationTimeUs = 508399
sample:
trackIndex = 0
dataHashCode = 1675188486
size = 228
isKeyFrame = true
presentationTimeUs = 46588
presentationTimeUs = 531619
sample:
trackIndex = 0
dataHashCode = 888567545
size = 238
isKeyFrame = true
presentationTimeUs = 49173
presentationTimeUs = 554839
sample:
trackIndex = 0
dataHashCode = -439631803
size = 234
isKeyFrame = true
presentationTimeUs = 51871
presentationTimeUs = 578058
sample:
trackIndex = 0
dataHashCode = 1606694497
size = 231
isKeyFrame = true
presentationTimeUs = 54524
presentationTimeUs = 601278
sample:
trackIndex = 0
dataHashCode = 1747388653
size = 217
isKeyFrame = true
presentationTimeUs = 57131
presentationTimeUs = 624498
sample:
trackIndex = 0
dataHashCode = -734560004
size = 239
isKeyFrame = true
presentationTimeUs = 59579
presentationTimeUs = 647718
sample:
trackIndex = 0
dataHashCode = -975079040
size = 243
isKeyFrame = true
presentationTimeUs = 62277
presentationTimeUs = 670938
sample:
trackIndex = 0
dataHashCode = -1403504710
size = 231
isKeyFrame = true
presentationTimeUs = 65020
presentationTimeUs = 694158
sample:
trackIndex = 0
dataHashCode = 379512981
size = 230
isKeyFrame = true
presentationTimeUs = 67627
presentationTimeUs = 717378
sample:
trackIndex = 0
dataHashCode = -997198863
size = 238
isKeyFrame = true
presentationTimeUs = 70234
presentationTimeUs = 740598
sample:
trackIndex = 0
dataHashCode = 1394492825
size = 225
isKeyFrame = true
presentationTimeUs = 72932
presentationTimeUs = 763818
sample:
trackIndex = 0
dataHashCode = -885232755
size = 232
isKeyFrame = true
presentationTimeUs = 75471
presentationTimeUs = 787038
sample:
trackIndex = 0
dataHashCode = 260871367
size = 243
isKeyFrame = true
presentationTimeUs = 78101
presentationTimeUs = 810258
sample:
trackIndex = 0
dataHashCode = -1505318960
size = 232
isKeyFrame = true
presentationTimeUs = 80844
presentationTimeUs = 833478
sample:
trackIndex = 0
dataHashCode = -390625371
size = 237
isKeyFrame = true
presentationTimeUs = 83474
presentationTimeUs = 856698
sample:
trackIndex = 0
dataHashCode = 1067950751
size = 228
isKeyFrame = true
presentationTimeUs = 86149
presentationTimeUs = 879918
sample:
trackIndex = 0
dataHashCode = -1179436278
size = 235
isKeyFrame = true
presentationTimeUs = 88734
presentationTimeUs = 903138
sample:
trackIndex = 0
dataHashCode = 1906607774
size = 264
isKeyFrame = true
presentationTimeUs = 91387
presentationTimeUs = 926358
sample:
trackIndex = 0
dataHashCode = -800475828
size = 257
isKeyFrame = true
presentationTimeUs = 94380
presentationTimeUs = 949578
sample:
trackIndex = 0
dataHashCode = 1718972977
size = 227
isKeyFrame = true
presentationTimeUs = 97282
presentationTimeUs = 972798
sample:
trackIndex = 0
dataHashCode = -1120448741
size = 227
isKeyFrame = true
presentationTimeUs = 99844
presentationTimeUs = 996018
sample:
trackIndex = 0
dataHashCode = -1718323210
size = 235
isKeyFrame = true
presentationTimeUs = 102406
presentationTimeUs = 1019238
sample:
trackIndex = 0
dataHashCode = -422416
size = 229
isKeyFrame = true
presentationTimeUs = 105059
presentationTimeUs = 1042458
sample:
trackIndex = 0
dataHashCode = 833757830
size = 6
isKeyFrame = true
presentationTimeUs = 107644
presentationTimeUs = 1065678
released = true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment