Skip to content

fix bug on Android R #112

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

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
}
Expand All @@ -20,7 +20,7 @@ allprojects {
}

ext {
compileSdkVersion = 28
compileSdkVersion = 30
minSdkVersion = 18
targetSdkVersion = 28
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
13 changes: 13 additions & 0 deletions lib/src/main/java/com/otaliastudios/transcoder/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ private boolean isCompleted(@NonNull TrackType type) {
&& mTranscoders.require(type).get(current).isFinished();
}

private boolean isLastPart(@NonNull TrackType type) {
if (mDataSources.require(type).isEmpty()) return true;
int current = mCurrentStep.require(type);
return current == mDataSources.require(type).size() - 1
&& current == mTranscoders.require(type).size() - 1;
}

private void openCurrentStep(@NonNull TrackType type, @NonNull TranscoderOptions options) {
int current = mCurrentStep.require(type);
TrackStatus status = mStatuses.require(type);
Expand Down Expand Up @@ -369,6 +376,12 @@ public void transcode(@NonNull TranscoderOptions options) throws InterruptedExce
videoCompleted = isCompleted(TrackType.VIDEO);
audioTranscoder = audioCompleted ? null : getCurrentTrackTranscoder(TrackType.AUDIO, options);
videoTranscoder = videoCompleted ? null : getCurrentTrackTranscoder(TrackType.VIDEO, options);
if (audioTranscoder != null) {
audioTranscoder.setIsLastPart(isLastPart(TrackType.AUDIO));
}
if (videoTranscoder != null) {
videoTranscoder.setIsLastPart(isLastPart(TrackType.VIDEO));
}
if (!audioCompleted) {
stepped |= audioTranscoder.transcode(forceAudioEos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.media.MediaCodec;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.os.Build;

import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -42,6 +43,7 @@ public abstract class BaseTrackTranscoder implements TrackTranscoder {
private boolean mIsDecoderEOS;
private boolean mIsEncoderEOS;
private boolean mIsExtractorEOS;
protected boolean isLastPart;

@SuppressWarnings("WeakerAccess")
protected BaseTrackTranscoder(@NonNull DataSource dataSource,
Expand Down Expand Up @@ -136,6 +138,11 @@ public final boolean isFinished() {
return mIsEncoderEOS;
}

@Override
public void setIsLastPart(boolean isLastPart) {
this.isLastPart = isLastPart;
}

@Override
public void release() {
if (mDecoder != null) {
Expand Down Expand Up @@ -278,7 +285,12 @@ private int drainEncoder(long timeoutUs) {

if ((mBufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
mIsEncoderEOS = true;
mBufferInfo.set(0, 0, 0, mBufferInfo.flags);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
mEncoder.releaseOutputBuffer(result, false);
return DRAIN_STATE_NONE;
} else {
mBufferInfo.set(0, 0, 0, mBufferInfo.flags);
}
}
if ((mBufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != 0) {
// SPS or PPS, which should be passed by MediaFormat.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public boolean isFinished() {
@Override
public void release() {
}

@Override
public void setIsLastPart(boolean isLastPart) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class PassThroughTrackTranscoder implements TrackTranscoder {
private final MediaFormat mOutputFormat;
private boolean mOutputFormatSet = false;
private TimeInterpolator mTimeInterpolator;
protected boolean isLastPart;

public PassThroughTrackTranscoder(@NonNull DataSource dataSource,
@NonNull DataSink dataSink,
Expand Down Expand Up @@ -69,8 +70,10 @@ public boolean transcode(boolean forceInputEos) {
}
if (mDataSource.isDrained() || forceInputEos) {
mDataChunk.buffer.clear();
mBufferInfo.set(0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
mDataSink.writeTrack(mTrackType, mDataChunk.buffer, mBufferInfo);
if (isLastPart) {
mBufferInfo.set(0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
mDataSink.writeTrack(mTrackType, mDataChunk.buffer, mBufferInfo);
}
mIsEOS = true;
return true;
}
Expand All @@ -95,4 +98,9 @@ public boolean isFinished() {
@Override
public void release() {
}

@Override
public void setIsLastPart(boolean isLastPart) {
this.isLastPart = isLastPart;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public interface TrackTranscoder {
boolean isFinished();

void release();

void setIsLastPart(boolean isLastPart);
}