Read optional video display dimensions.

Add RequiresApi annotations.

Fixes #8982
This commit is contained in:
Alan Evans 2019-08-18 11:52:19 +01:00 committed by Greyson Parrelli
parent c4a4374465
commit 1bd1e9cc65
2 changed files with 15 additions and 4 deletions

View file

@ -139,6 +139,7 @@ public final class MediaConverter {
} }
@WorkerThread @WorkerThread
@RequiresApi(23)
public void convert() throws EncodingException, IOException { public void convert() throws EncodingException, IOException {
// Exception that may be thrown during release. // Exception that may be thrown during release.
Exception exception = null; Exception exception = null;

View file

@ -8,6 +8,7 @@ import android.view.Surface;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
@ -27,6 +28,9 @@ final class VideoTrackConverter {
private static final int TIMEOUT_USEC = 10000; private static final int TIMEOUT_USEC = 10000;
private static final String MEDIA_FORMAT_KEY_DISPLAY_WIDTH = "display-width";
private static final String MEDIA_FORMAT_KEY_DISPLAY_HEIGHT = "display-height";
private final long mTimeFrom; private final long mTimeFrom;
private final long mTimeTo; private final long mTimeTo;
@ -60,8 +64,8 @@ final class VideoTrackConverter {
private Muxer mMuxer; private Muxer mMuxer;
static @Nullable @RequiresApi(23)
VideoTrackConverter create( static @Nullable VideoTrackConverter create(
final @NonNull MediaConverter.Input input, final @NonNull MediaConverter.Input input,
final long timeFrom, final long timeFrom,
final long timeTo, final long timeTo,
@ -78,6 +82,8 @@ final class VideoTrackConverter {
return new VideoTrackConverter(videoExtractor, videoInputTrack, timeFrom, timeTo, videoResolution, videoBitrate, videoCodec); return new VideoTrackConverter(videoExtractor, videoInputTrack, timeFrom, timeTo, videoResolution, videoBitrate, videoCodec);
} }
@RequiresApi(23)
private VideoTrackConverter( private VideoTrackConverter(
final @NonNull MediaExtractor videoExtractor, final @NonNull MediaExtractor videoExtractor,
final int videoInputTrack, final int videoInputTrack,
@ -104,8 +110,12 @@ final class VideoTrackConverter {
mInputDuration = inputVideoFormat.containsKey(MediaFormat.KEY_DURATION) ? inputVideoFormat.getLong(MediaFormat.KEY_DURATION) : 0; mInputDuration = inputVideoFormat.containsKey(MediaFormat.KEY_DURATION) ? inputVideoFormat.getLong(MediaFormat.KEY_DURATION) : 0;
final int rotation = inputVideoFormat.containsKey(MediaFormat.KEY_ROTATION) ? inputVideoFormat.getInteger(MediaFormat.KEY_ROTATION) : 0; final int rotation = inputVideoFormat.containsKey(MediaFormat.KEY_ROTATION) ? inputVideoFormat.getInteger(MediaFormat.KEY_ROTATION) : 0;
final int width = inputVideoFormat.getInteger(MediaFormat.KEY_WIDTH); final int width = inputVideoFormat.containsKey(MEDIA_FORMAT_KEY_DISPLAY_WIDTH)
final int height = inputVideoFormat.getInteger(MediaFormat.KEY_HEIGHT); ? inputVideoFormat.getInteger(MEDIA_FORMAT_KEY_DISPLAY_WIDTH)
: inputVideoFormat.getInteger(MediaFormat.KEY_WIDTH);
final int height = inputVideoFormat.containsKey(MEDIA_FORMAT_KEY_DISPLAY_HEIGHT)
? inputVideoFormat.getInteger(MEDIA_FORMAT_KEY_DISPLAY_HEIGHT)
: inputVideoFormat.getInteger(MediaFormat.KEY_HEIGHT);
int outputWidth = width; int outputWidth = width;
int outputHeight = height; int outputHeight = height;
if (outputWidth < outputHeight) { if (outputWidth < outputHeight) {