-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This logic is currently in the player renderers. With multi-asset, the renderers will go into the AssetLoader, which shouldn't be responsible for muxing. PiperOrigin-RevId: 486860502
- Loading branch information
Showing
8 changed files
with
185 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...ansformer/src/main/java/com/google/android/exoplayer2/transformer/BaseSamplePipeline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2022 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 static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; | ||
|
||
import androidx.annotation.Nullable; | ||
import com.google.android.exoplayer2.Format; | ||
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; | ||
|
||
/* package */ abstract class BaseSamplePipeline implements SamplePipeline { | ||
|
||
private final int trackType; | ||
private final long streamStartPositionUs; | ||
private final MuxerWrapper muxerWrapper; | ||
|
||
private boolean muxerWrapperTrackAdded; | ||
private boolean isEnded; | ||
|
||
public BaseSamplePipeline(int trackType, long streamStartPositionUs, MuxerWrapper muxerWrapper) { | ||
this.trackType = trackType; | ||
this.streamStartPositionUs = streamStartPositionUs; | ||
this.muxerWrapper = muxerWrapper; | ||
} | ||
|
||
@Override | ||
public boolean processData() throws TransformationException { | ||
return feedMuxer() || processDataUpToMuxer(); | ||
} | ||
|
||
@Override | ||
public boolean isEnded() { | ||
return isEnded; | ||
} | ||
|
||
protected abstract boolean processDataUpToMuxer() throws TransformationException; | ||
|
||
@Nullable | ||
protected abstract Format getMuxerInputFormat() throws TransformationException; | ||
|
||
@Nullable | ||
protected abstract DecoderInputBuffer getMuxerInputBuffer() throws TransformationException; | ||
|
||
protected abstract void releaseMuxerInputBuffer() throws TransformationException; | ||
|
||
protected abstract boolean isMuxerInputEnded(); | ||
|
||
/** | ||
* Attempts to pass encoded data to the muxer, and returns whether it may be possible to pass more | ||
* data immediately by calling this method again. | ||
*/ | ||
private boolean feedMuxer() throws TransformationException { | ||
if (!muxerWrapperTrackAdded) { | ||
@Nullable Format inputFormat = getMuxerInputFormat(); | ||
if (inputFormat == null) { | ||
return false; | ||
} | ||
try { | ||
muxerWrapper.addTrackFormat(inputFormat); | ||
} catch (Muxer.MuxerException e) { | ||
throw TransformationException.createForMuxer( | ||
e, TransformationException.ERROR_CODE_MUXING_FAILED); | ||
} | ||
muxerWrapperTrackAdded = true; | ||
} | ||
|
||
if (isMuxerInputEnded()) { | ||
muxerWrapper.endTrack(trackType); | ||
isEnded = true; | ||
return false; | ||
} | ||
|
||
@Nullable DecoderInputBuffer muxerInputBuffer = getMuxerInputBuffer(); | ||
if (muxerInputBuffer == null) { | ||
return false; | ||
} | ||
|
||
long samplePresentationTimeUs = muxerInputBuffer.timeUs - streamStartPositionUs; | ||
// TODO(b/204892224): Consider subtracting the first sample timestamp from the sample pipeline | ||
// buffer from all samples so that they are guaranteed to start from zero in the output file. | ||
try { | ||
if (!muxerWrapper.writeSample( | ||
trackType, | ||
checkStateNotNull(muxerInputBuffer.data), | ||
muxerInputBuffer.isKeyFrame(), | ||
samplePresentationTimeUs)) { | ||
return false; | ||
} | ||
} catch (Muxer.MuxerException e) { | ||
throw TransformationException.createForMuxer( | ||
e, TransformationException.ERROR_CODE_MUXING_FAILED); | ||
} | ||
|
||
releaseMuxerInputBuffer(); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.