diff --git a/api/current.txt b/api/current.txt index c56e3b622fe2e..2403b8e76dc2b 100644 --- a/api/current.txt +++ b/api/current.txt @@ -11591,6 +11591,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); diff --git a/media/java/android/media/MediaMuxer.java b/media/java/android/media/MediaMuxer.java index c3cc1e66db634..1f5ca354635f7 100644 --- a/media/java/android/media/MediaMuxer.java +++ b/media/java/android/media/MediaMuxer.java @@ -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. + *
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.
+ * @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. *Make sure this is called after {@link #addTrack} and before
diff --git a/media/jni/android_media_MediaMuxer.cpp b/media/jni/android_media_MediaMuxer.cpp
index 30ebb00a0ad56..7517e8561a20f 100644
--- a/media/jni/android_media_MediaMuxer.cpp
+++ b/media/jni/android_media_MediaMuxer.cpp
@@ -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