Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 270bcaa9 authored by Rajneesh Chowdury's avatar Rajneesh Chowdury Committed by Android (Google) Code Review
Browse files

Merge "Fix for 5156702 Rotate video output for thumbnails and export"

parents 93d77b63 c847b1a8
Loading
Loading
Loading
Loading
+31 −5
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Matrix;
import android.media.videoeditor.VideoEditor.ExportProgressListener;
import android.media.videoeditor.VideoEditor.PreviewProgressListener;
import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener;
@@ -1050,6 +1051,10 @@ class MediaArtistNativeHelper {
         */
         public int rgbWidth;
         public int rgbHeight;
         /**
         * Video rotation degree.
         */
         public int rotationDegree;
    }

    /**
@@ -1700,6 +1705,11 @@ class MediaArtistNativeHelper {
         */
        public int audioVolumeValue;

        /**
         * Video rotation degree.
         */
        public int videoRotation;

        public String Id;
    }

@@ -2254,6 +2264,7 @@ class MediaArtistNativeHelper {
        lclipSettings.panZoomTopLeftXEnd = 0;
        lclipSettings.panZoomTopLeftYEnd = 0;
        lclipSettings.mediaRendering = 0;
        lclipSettings.rotationDegree = 0;
    }


@@ -3784,7 +3795,8 @@ class MediaArtistNativeHelper {
     **/
    void getPixelsList(String filename, final int width, final int height,
            long startMs, long endMs, int thumbnailCount, int[] indices,
            final MediaItem.GetThumbnailListCallback callback) {
            final MediaItem.GetThumbnailListCallback callback,
            final int videoRotation) {
        /* Make width and height as even */
        final int newWidth = (width + 1) & 0xFFFFFFFE;
        final int newHeight = (height + 1) & 0xFFFFFFFE;
@@ -3799,7 +3811,7 @@ class MediaArtistNativeHelper {
        final int[] rgb888 = new int[thumbnailSize];
        final IntBuffer tmpBuffer = IntBuffer.allocate(thumbnailSize);
        nativeGetPixelsList(filename, rgb888, newWidth, newHeight,
                thumbnailCount, startMs, endMs, indices,
                thumbnailCount, videoRotation, startMs, endMs, indices,
                new NativeGetPixelsListCallback() {
            public void onThumbnail(int index) {
                Bitmap bitmap = Bitmap.createBitmap(
@@ -3821,7 +3833,21 @@ class MediaArtistNativeHelper {

                    canvas.setBitmap(null);
                }

                if (videoRotation == 0) {
                    callback.onThumbnail(bitmap, index);
                } else {
                    Matrix mtx = new Matrix();
                    mtx.postRotate(videoRotation);
                    Bitmap rotatedBmp =
                        Bitmap.createBitmap(bitmap, 0, 0, width, height, mtx, false);
                    callback.onThumbnail(rotatedBmp, index);

                    if (bitmap != null) {
                        bitmap.recycle();
                    }
                }

            }
        });

@@ -3943,8 +3969,8 @@ class MediaArtistNativeHelper {
            long timeMS);

    private native int nativeGetPixelsList(String fileName, int[] pixelArray,
            int width, int height, int nosofTN, long startTimeMs, long endTimeMs,
            int[] indices, NativeGetPixelsListCallback callback);
            int width, int height, int nosofTN, int videoRotation, long startTimeMs,
            long endTimeMs, int[] indices, NativeGetPixelsListCallback callback);

    /**
     * Releases the JNI and cleans up the core native module.. Should be called
+1 −1
Original line number Diff line number Diff line
@@ -638,7 +638,7 @@ public class MediaImageItem extends MediaItem {
            }

            mMANativeHelper.getPixelsList(getGeneratedImageClip(), width,
                height, startMs, endMs, thumbnailCount, indices, callback);
                height, startMs, endMs, thumbnailCount, indices, callback, 0);
        }
    }

+17 −3
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public class MediaVideoItem extends MediaItem {
    private String mAudioWaveformFilename;
    private MediaArtistNativeHelper mMANativeHelper;
    private VideoEditorImpl mVideoEditor;
    private final int mVideoRotationDegree;
    /**
     *  The audio waveform data
     */
@@ -190,6 +191,7 @@ public class MediaVideoItem extends MediaItem {
        } else {
            mWaveformData = null;
        }
        mVideoRotationDegree = properties.videoRotation;
    }

    /**
@@ -317,7 +319,8 @@ public class MediaVideoItem extends MediaItem {
        }

        mMANativeHelper.getPixelsList(super.getFilename(), width,
                height, startMs, endMs, thumbnailCount, indices, callback);
                height, startMs, endMs, thumbnailCount, indices, callback,
                mVideoRotationDegree);
    }

    /*
@@ -425,16 +428,26 @@ public class MediaVideoItem extends MediaItem {
     */
    @Override
    public int getWidth() {
        if (mVideoRotationDegree == 90 ||
             mVideoRotationDegree == 270) {
            return mHeight;
        } else {
            return mWidth;
        }
    }

    /*
     * {@inheritDoc}
     */
    @Override
    public int getHeight() {
        if (mVideoRotationDegree == 90 ||
             mVideoRotationDegree == 270) {
            return mWidth;
        } else {
            return mHeight;
        }
    }

    /*
     * {@inheritDoc}
@@ -725,6 +738,7 @@ public class MediaVideoItem extends MediaItem {
        clipSettings.beginCutTime = (int)getBoundaryBeginTime();
        clipSettings.endCutTime = (int)getBoundaryEndTime();
        clipSettings.mediaRendering = mMANativeHelper.getMediaItemRenderingMode(getRenderingMode());
        clipSettings.rotationDegree = mVideoRotationDegree;

        return clipSettings;
    }
+15 −2
Original line number Diff line number Diff line
@@ -490,7 +490,8 @@ VIDEOEDIT_JAVA_DEFINE_FIELDS(Properties)
    VIDEOEDIT_JAVA_FIELD_INIT("audioDuration",          "I"),
    VIDEOEDIT_JAVA_FIELD_INIT("audioBitrate",           "I"),
    VIDEOEDIT_JAVA_FIELD_INIT("audioChannels",          "I"),
    VIDEOEDIT_JAVA_FIELD_INIT("audioSamplingFrequency", "I")
    VIDEOEDIT_JAVA_FIELD_INIT("audioSamplingFrequency", "I"),
    VIDEOEDIT_JAVA_FIELD_INIT("videoRotation",          "I")
};

VIDEOEDIT_JAVA_DEFINE_FIELD_CLASS(Properties, PROPERTIES_CLASS_NAME)
@@ -540,7 +541,8 @@ VIDEOEDIT_JAVA_DEFINE_FIELDS(ClipSettings)
    VIDEOEDIT_JAVA_FIELD_INIT("panZoomTopLeftYEnd",   "I"                 ),
    VIDEOEDIT_JAVA_FIELD_INIT("mediaRendering",       "I"                 ),
    VIDEOEDIT_JAVA_FIELD_INIT("rgbWidth",           "I"                 ),
    VIDEOEDIT_JAVA_FIELD_INIT("rgbHeight",          "I"                 )
    VIDEOEDIT_JAVA_FIELD_INIT("rgbHeight",          "I"                 ),
    VIDEOEDIT_JAVA_FIELD_INIT("rotationDegree",     "I"                 )
};

VIDEOEDIT_JAVA_DEFINE_FIELD_CLASS(ClipSettings, CLIP_SETTINGS_CLASS_NAME)
@@ -1402,6 +1404,10 @@ videoEditClasses_getClipSettings(
            VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR", \
                "getClipSettings-- rgbFileHeight %d ",
                pSettings->ClipProperties.uiStillPicHeight);

            // Set the video rotation degree
            pSettings->ClipProperties.videoRotationDegrees =
                (M4OSA_UInt32)pEnv->GetIntField(object, fieldIds.rotationDegree);
        }

        // Check if settings could be set.
@@ -1513,6 +1519,10 @@ videoEditClasses_createClipSettings(
                pSettings->ClipProperties.uiStillPicWidth ,
                pSettings->ClipProperties.uiStillPicHeight);

            // Set the video rotation
            pEnv->SetIntField(object, fieldIds.rotationDegree,
                pSettings->ClipProperties.videoRotationDegrees);

            // Return the object.
            (*pObject) = object;
        }
@@ -1609,6 +1619,9 @@ videoEditPropClass_createProperties(
            pEnv->SetIntField(object, fieldIds.audioSamplingFrequency,
                pProperties->uiSamplingFrequency);

            // Set the video rotation field.
            pEnv->SetIntField(object, fieldIds.videoRotation, pProperties->uiRotation);

            // Return the object.
            (*pObject) = object;
        }
+3 −0
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ typedef struct {
    M4OSA_UInt32 uiAudioBitrate;
    M4OSA_UInt32 uiNbChannels;
    M4OSA_UInt32 uiSamplingFrequency;
    M4OSA_UInt32 uiRotation;
} VideoEditPropClass_Properties;

typedef struct
@@ -166,6 +167,7 @@ typedef struct
    jfieldID audioBitrate;
    jfieldID audioChannels;
    jfieldID audioSamplingFrequency;
    jfieldID videoRotation;
} VideoEditJava_PropertiesFieldIds;


@@ -187,6 +189,7 @@ typedef struct
    jfieldID mediaRendering;
    jfieldID rgbFileWidth;
    jfieldID rgbFileHeight;
    jfieldID rotationDegree;
} VideoEditJava_ClipSettingsFieldIds;

typedef struct
Loading