diff options
author | Zhijun He <zhijunhe@google.com> | 2013-09-09 15:47:06 -0700 |
---|---|---|
committer | Zhijun He <zhijunhe@google.com> | 2013-09-10 07:52:25 -0700 |
commit | cfd47481d1b375663d4e8e8d0c292d9001aa384b (patch) | |
tree | fd994fd882fedf989245e0142f7c1705b5c7a93d /media | |
parent | e3d0f022826a2a16e64dc9b5353a2a514393881b (diff) | |
download | frameworks_base-cfd47481d1b375663d4e8e8d0c292d9001aa384b.zip frameworks_base-cfd47481d1b375663d4e8e8d0c292d9001aa384b.tar.gz frameworks_base-cfd47481d1b375663d4e8e8d0c292d9001aa384b.tar.bz2 |
MediaMuxer: Add setLocation API
This API could be used for camera recording when MediaMuxer is used to write
output media file.
Bug: 10594784
Change-Id: Ide2d6e1d87b246100a5def49bfb8646dc984a512
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/MediaMuxer.java | 36 | ||||
-rw-r--r-- | media/jni/android_media_MediaMuxer.cpp | 15 |
2 files changed, 51 insertions, 0 deletions
diff --git a/media/java/android/media/MediaMuxer.java b/media/java/android/media/MediaMuxer.java index 774964e..65a9308 100644 --- a/media/java/android/media/MediaMuxer.java +++ b/media/java/android/media/MediaMuxer.java @@ -92,6 +92,7 @@ final public class MediaMuxer { Object[] values); private static native void nativeSetOrientationHint(int nativeObject, int degrees); + private static native void nativeSetLocation(int nativeObject, int latitude, int longitude); private static native void nativeWriteSampleData(int nativeObject, int trackIndex, ByteBuffer byteBuf, int offset, int size, long presentationTimeUs, int flags); @@ -165,6 +166,41 @@ final public class MediaMuxer { } /** + * Set and store the geodata (latitude and longitude) in the output file. + * This method should be called before {@link #start}. The geodata is stored + * in udta box if the output format is + * {@link OutputFormat#MUXER_OUTPUT_MPEG_4}, and is ignored for other output + * formats. The geodata is stored according to ISO-6709 standard. + * + * @param latitude Latitude in degrees. Its value must be in the range [-90, + * 90]. + * @param longitude Longitude in degrees. Its value must be in the range + * [-180, 180]. + * @throws IllegalArgumentException If the given latitude or longitude is out + * of range. + * @throws IllegalStateException If this method is called after {@link #start}. + */ + public void setLocation(float latitude, float longitude) { + int latitudex10000 = (int) (latitude * 10000 + 0.5); + int longitudex10000 = (int) (longitude * 10000 + 0.5); + + if (latitudex10000 > 900000 || latitudex10000 < -900000) { + String msg = "Latitude: " + latitude + " out of range."; + throw new IllegalArgumentException(msg); + } + if (longitudex10000 > 1800000 || longitudex10000 < -1800000) { + String msg = "Longitude: " + longitude + " out of range"; + throw new IllegalArgumentException(msg); + } + + if (mState == MUXER_STATE_INITIALIZED && mNativeObject != 0) { + nativeSetLocation(mNativeObject, latitudex10000, longitudex10000); + } else { + throw new IllegalStateException("Can't set location due to wrong state."); + } + } + + /** * Starts the muxer. * <p>Make sure this is called after {@link #addTrack} and before * {@link #writeSampleData}.</p> diff --git a/media/jni/android_media_MediaMuxer.cpp b/media/jni/android_media_MediaMuxer.cpp index 7517e85..457b956 100644 --- a/media/jni/android_media_MediaMuxer.cpp +++ b/media/jni/android_media_MediaMuxer.cpp @@ -164,6 +164,18 @@ static void android_media_MediaMuxer_setOrientationHint( } +static void android_media_MediaMuxer_setLocation( + JNIEnv *env, jclass clazz, jint nativeObject, jint latitude, jint longitude) { + MediaMuxer* muxer = reinterpret_cast<MediaMuxer *>(nativeObject); + + status_t res = muxer->setLocation(latitude, longitude); + if (res != OK) { + jniThrowException(env, "java/lang/IllegalStateException", + "Failed to set location"); + return; + } +} + static void android_media_MediaMuxer_start(JNIEnv *env, jclass clazz, jint nativeObject) { sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject)); @@ -216,6 +228,9 @@ static JNINativeMethod gMethods[] = { { "nativeSetOrientationHint", "(II)V", (void *)android_media_MediaMuxer_setOrientationHint}, + { "nativeSetLocation", "(III)V", + (void *)android_media_MediaMuxer_setLocation}, + { "nativeStart", "(I)V", (void *)android_media_MediaMuxer_start}, { "nativeWriteSampleData", "(IILjava/nio/ByteBuffer;IIJI)V", |