Skip to content

PassThroughTrackTranscoder supports not checking MediaFormatValidator #11

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

Merged
merged 2 commits into from
Aug 2, 2019
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 @@ -259,6 +259,9 @@ private void runPipelines() throws InterruptedException {
TrackTranscoder videoTranscoder = mTranscoders.get(TrackType.VIDEO);
TrackTranscoder audioTranscoder = mTranscoders.get(TrackType.AUDIO);
while (!(videoTranscoder.isFinished() && audioTranscoder.isFinished())) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
boolean stepped = videoTranscoder.transcode() || audioTranscoder.transcode();
loopCount++;
if (mDurationUs > 0 && loopCount % PROGRESS_INTERVAL_STEPS == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class TranscoderMuxer {

private static final String TAG = TranscoderMuxer.class.getSimpleName();
private static final Logger LOG = new Logger(TAG);
private boolean mAudioTrackNeedsValidation = false;
private boolean mVideoTrackNeedsValidation = false;

private static final int BUFFER_SIZE = 64 * 1024; // I have no idea whether this value is appropriate or not...

Expand Down Expand Up @@ -74,8 +76,13 @@ private void toBufferInfo(@NonNull MediaCodec.BufferInfo bufferInfo, int offset)
* @param trackType the sample type, either audio or video
* @param format the new format
*/
public void setOutputFormat(@NonNull TrackType trackType, @NonNull MediaFormat format) {
public void setOutputFormat(@NonNull TrackType trackType, @NonNull MediaFormat format, boolean needsValidation) {
mTracks.outputFormat(trackType, format);
if(trackType == TrackType.AUDIO) {
mAudioTrackNeedsValidation = needsValidation;
} else if(trackType == TrackType.VIDEO){
mVideoTrackNeedsValidation = needsValidation;
}

// If we have both, go on.
boolean isTranscodingVideo = mTracks.status(TrackType.VIDEO).isTranscoding();
Expand All @@ -89,9 +96,15 @@ public void setOutputFormat(@NonNull TrackType trackType, @NonNull MediaFormat f

// If both video and audio are ready, validate the formats and go on.
// We will stop buffering data and we will start actually muxing it.
MediaFormatValidator formatValidator = new MediaFormatValidator();
formatValidator.validateVideoOutputFormat(videoOutputFormat);
formatValidator.validateAudioOutputFormat(audioOutputFormat);
if(mVideoTrackNeedsValidation||mAudioTrackNeedsValidation) {
MediaFormatValidator formatValidator = new MediaFormatValidator();
if(mVideoTrackNeedsValidation) {
formatValidator.validateVideoOutputFormat(videoOutputFormat);
}
if(mAudioTrackNeedsValidation) {
formatValidator.validateAudioOutputFormat(audioOutputFormat);
}
}

if (isTranscodingVideo) {
int videoIndex = mMuxer.addTrack(videoOutputFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ protected void onEncoderOutputFormatChanged(@NonNull MediaCodec encoder, @NonNul
throw new RuntimeException("Audio output format changed twice.");
}
mActualOutputFormat = format;
mMuxer.setOutputFormat(mTrackType, mActualOutputFormat);
mMuxer.setOutputFormat(mTrackType, mActualOutputFormat, true);
}

@SuppressWarnings("SameParameterValue")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void setUp(@NonNull MediaFormat desiredOutputFormat) { }
public boolean transcode() {
if (mIsEOS) return false;
if (!mOutputFormatSet) {
mMuxer.setOutputFormat(mTrackType, mOutputFormat);
mMuxer.setOutputFormat(mTrackType, mOutputFormat, false);
mOutputFormatSet = true;
}
int trackIndex = mExtractor.getSampleTrackIndex();
Expand Down