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

Commit 1e7298b2 authored by ztenghui's avatar ztenghui Committed by Android (Google) Code Review
Browse files

Merge "Add the orientation hint to the MediaMuxer" into jb-mr2-dev

parents cc591168 effc9b48
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11589,6 +11589,7 @@ package android.media {
    ctor public MediaMuxer(java.lang.String, int) throws java.io.IOException;
    method public int addTrack(android.media.MediaFormat);
    method public void release();
    method public void setOrientationHint(int);
    method public void start();
    method public void stop();
    method public void writeSampleData(int, java.nio.ByteBuffer, android.media.MediaCodec.BufferInfo);
+28 −1
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@ final public class MediaMuxer {
    private static native void nativeStop(int nativeObject);
    private static native int nativeAddTrack(int nativeObject, String[] keys,
            Object[] values);
    private static native void nativeSetOrientationHint(int nativeObject,
            int degrees);
    private static native void nativeWriteSampleData(int nativeObject,
            int trackIndex, ByteBuffer byteBuf,
            int offset, int size, long presentationTimeUs, int flags);
@@ -109,7 +111,7 @@ final public class MediaMuxer {
    private int mNativeObject;

    /**
     * Constructor
     * Constructor.
     * Creates a media muxer that writes to the specified path.
     * @param path The path of the output media file.
     * @param format The format of the output media file.
@@ -138,6 +140,31 @@ final public class MediaMuxer {
        }
    }

    /**
     * Sets the orientation hint for output video playback.
     * <p>This method should be called before {@link #start}. Calling this
     * method will not rotate the video frame when muxer is generating the file,
     * but add a composition matrix containing the rotation angle in the output
     * video if the output format is
     * {@link OutputFormat#MUXER_OUTPUT_MPEG_4} so that a video player can
     * choose the proper orientation for playback. Note that some video players
     * may choose to ignore the composition matrix in a video during playback.
     * By default, the rotation degree is 0.</p>
     * @param degrees the angle to be rotated clockwise in degrees.
     * The supported angles are 0, 90, 180, and 270 degrees.
     */
    public void setOrientationHint(int degrees) {
        if (degrees != 0 && degrees != 90  && degrees != 180 && degrees != 270) {
            throw new IllegalArgumentException("Unsupported angle: " + degrees);
        }
        if (mState == MUXER_STATE_INITIALIZED) {
            nativeSetOrientationHint(mNativeObject, degrees);
        } else {
            throw new IllegalStateException("Can't set rotation degrees due" +
                    " to wrong state.");
        }
    }

    /**
     * Starts the muxer.
     * <p>Make sure this is called after {@link #addTrack} and before
+21 −0
Original line number Diff line number Diff line
@@ -146,6 +146,24 @@ static jint android_media_MediaMuxer_native_setup(
    return int(muxer.get());
}

static void android_media_MediaMuxer_setOrientationHint(
        JNIEnv *env, jclass clazz, jint nativeObject, jint degrees) {
    sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
    if (muxer == NULL) {
        jniThrowException(env, "java/lang/IllegalStateException",
                          "Muxer was not set up correctly");
        return;
    }
    status_t err = muxer->setOrientationHint(degrees);

    if (err != OK) {
        jniThrowException(env, "java/lang/IllegalStateException",
                          "Failed to set orientation hint");
        return;
    }

}

static void android_media_MediaMuxer_start(JNIEnv *env, jclass clazz,
                                           jint nativeObject) {
    sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
@@ -195,6 +213,9 @@ static JNINativeMethod gMethods[] = {
    { "nativeAddTrack", "(I[Ljava/lang/String;[Ljava/lang/Object;)I",
        (void *)android_media_MediaMuxer_addTrack },

    { "nativeSetOrientationHint", "(II)V",
        (void *)android_media_MediaMuxer_setOrientationHint},

    { "nativeStart", "(I)V", (void *)android_media_MediaMuxer_start},

    { "nativeWriteSampleData", "(IILjava/nio/ByteBuffer;IIJI)V",