From 1bd1e9cc65b02b62ee4b112587941a3dc375c07e Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Sun, 18 Aug 2019 11:52:19 +0100 Subject: [PATCH] Read optional video display dimensions. Add RequiresApi annotations. Fixes #8982 --- .../video/videoconverter/MediaConverter.java | 1 + .../videoconverter/VideoTrackConverter.java | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/video/videoconverter/MediaConverter.java b/src/org/thoughtcrime/securesms/video/videoconverter/MediaConverter.java index e6640e9825..f3a74dfcfd 100644 --- a/src/org/thoughtcrime/securesms/video/videoconverter/MediaConverter.java +++ b/src/org/thoughtcrime/securesms/video/videoconverter/MediaConverter.java @@ -139,6 +139,7 @@ public final class MediaConverter { } @WorkerThread + @RequiresApi(23) public void convert() throws EncodingException, IOException { // Exception that may be thrown during release. Exception exception = null; diff --git a/src/org/thoughtcrime/securesms/video/videoconverter/VideoTrackConverter.java b/src/org/thoughtcrime/securesms/video/videoconverter/VideoTrackConverter.java index 457c3ef4c0..6a6a2a3e3e 100644 --- a/src/org/thoughtcrime/securesms/video/videoconverter/VideoTrackConverter.java +++ b/src/org/thoughtcrime/securesms/video/videoconverter/VideoTrackConverter.java @@ -8,6 +8,7 @@ import android.view.Surface; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; import org.thoughtcrime.securesms.logging.Log; @@ -27,6 +28,9 @@ final class VideoTrackConverter { 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 mTimeTo; @@ -60,8 +64,8 @@ final class VideoTrackConverter { private Muxer mMuxer; - static @Nullable - VideoTrackConverter create( + @RequiresApi(23) + static @Nullable VideoTrackConverter create( final @NonNull MediaConverter.Input input, final long timeFrom, final long timeTo, @@ -78,6 +82,8 @@ final class VideoTrackConverter { return new VideoTrackConverter(videoExtractor, videoInputTrack, timeFrom, timeTo, videoResolution, videoBitrate, videoCodec); } + + @RequiresApi(23) private VideoTrackConverter( final @NonNull MediaExtractor videoExtractor, final int videoInputTrack, @@ -104,8 +110,12 @@ final class VideoTrackConverter { 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 width = inputVideoFormat.getInteger(MediaFormat.KEY_WIDTH); - final int height = inputVideoFormat.getInteger(MediaFormat.KEY_HEIGHT); + final int width = inputVideoFormat.containsKey(MEDIA_FORMAT_KEY_DISPLAY_WIDTH) + ? 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 outputHeight = height; if (outputWidth < outputHeight) {