Skip to content

Commit 849ef27

Browse files
Saqragnatario1
authored andcommitted
Don't validate PassThroughTrackTranscoder track format (deepmedia#11)
* PassThroughTrackTranscoder supports not checking MediaFormatValidator * throw InterruptedException when cancel transcode * TaskFuture#cancel will call Thread#interrupt. Thread#interrupt throw InterruptedException only when thread is bloking. So other situation can't stop transcode.
1 parent 51fcaaa commit 849ef27

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

lib/src/main/java/com/otaliastudios/transcoder/engine/TranscoderEngine.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ private void runPipelines() throws InterruptedException {
259259
TrackTranscoder videoTranscoder = mTranscoders.get(TrackType.VIDEO);
260260
TrackTranscoder audioTranscoder = mTranscoders.get(TrackType.AUDIO);
261261
while (!(videoTranscoder.isFinished() && audioTranscoder.isFinished())) {
262+
if (Thread.interrupted()) {
263+
throw new InterruptedException();
264+
}
262265
boolean stepped = videoTranscoder.transcode() || audioTranscoder.transcode();
263266
loopCount++;
264267
if (mDurationUs > 0 && loopCount % PROGRESS_INTERVAL_STEPS == 0) {

lib/src/main/java/com/otaliastudios/transcoder/engine/TranscoderMuxer.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class TranscoderMuxer {
3535

3636
private static final String TAG = TranscoderMuxer.class.getSimpleName();
3737
private static final Logger LOG = new Logger(TAG);
38+
private boolean mAudioTrackNeedsValidation = false;
39+
private boolean mVideoTrackNeedsValidation = false;
3840

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

@@ -74,8 +76,13 @@ private void toBufferInfo(@NonNull MediaCodec.BufferInfo bufferInfo, int offset)
7476
* @param trackType the sample type, either audio or video
7577
* @param format the new format
7678
*/
77-
public void setOutputFormat(@NonNull TrackType trackType, @NonNull MediaFormat format) {
79+
public void setOutputFormat(@NonNull TrackType trackType, @NonNull MediaFormat format, boolean needsValidation) {
7880
mTracks.outputFormat(trackType, format);
81+
if(trackType == TrackType.AUDIO) {
82+
mAudioTrackNeedsValidation = needsValidation;
83+
} else if(trackType == TrackType.VIDEO){
84+
mVideoTrackNeedsValidation = needsValidation;
85+
}
7986

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

9097
// If both video and audio are ready, validate the formats and go on.
9198
// We will stop buffering data and we will start actually muxing it.
92-
MediaFormatValidator formatValidator = new MediaFormatValidator();
93-
formatValidator.validateVideoOutputFormat(videoOutputFormat);
94-
formatValidator.validateAudioOutputFormat(audioOutputFormat);
99+
if(mVideoTrackNeedsValidation||mAudioTrackNeedsValidation) {
100+
MediaFormatValidator formatValidator = new MediaFormatValidator();
101+
if(mVideoTrackNeedsValidation) {
102+
formatValidator.validateVideoOutputFormat(videoOutputFormat);
103+
}
104+
if(mAudioTrackNeedsValidation) {
105+
formatValidator.validateAudioOutputFormat(audioOutputFormat);
106+
}
107+
}
95108

96109
if (isTranscodingVideo) {
97110
int videoIndex = mMuxer.addTrack(videoOutputFormat);

lib/src/main/java/com/otaliastudios/transcoder/transcode/BaseTrackTranscoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ protected void onEncoderOutputFormatChanged(@NonNull MediaCodec encoder, @NonNul
196196
throw new RuntimeException("Audio output format changed twice.");
197197
}
198198
mActualOutputFormat = format;
199-
mMuxer.setOutputFormat(mTrackType, mActualOutputFormat);
199+
mMuxer.setOutputFormat(mTrackType, mActualOutputFormat, true);
200200
}
201201

202202
@SuppressWarnings("SameParameterValue")

lib/src/main/java/com/otaliastudios/transcoder/transcode/PassThroughTrackTranscoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void setUp(@NonNull MediaFormat desiredOutputFormat) { }
7171
public boolean transcode() {
7272
if (mIsEOS) return false;
7373
if (!mOutputFormatSet) {
74-
mMuxer.setOutputFormat(mTrackType, mOutputFormat);
74+
mMuxer.setOutputFormat(mTrackType, mOutputFormat, false);
7575
mOutputFormatSet = true;
7676
}
7777
int trackIndex = mExtractor.getSampleTrackIndex();

0 commit comments

Comments
 (0)