James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "MediaProfilesJNI" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <utils/threads.h> |
| 23 | |
| 24 | #include "jni.h" |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 25 | #include <nativehelper/JNIHelp.h> |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 26 | #include "android_runtime/AndroidRuntime.h" |
| 27 | #include <media/MediaProfiles.h> |
| 28 | |
| 29 | using namespace android; |
| 30 | |
| 31 | static Mutex sLock; |
| 32 | MediaProfiles *sProfiles = NULL; |
| 33 | |
| 34 | // This function is called from a static block in MediaProfiles.java class, |
| 35 | // which won't run until the first time an instance of this class is used. |
| 36 | static void |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 37 | android_media_MediaProfiles_native_init(JNIEnv* /* env */) |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 38 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 39 | ALOGV("native_init"); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 40 | Mutex::Autolock lock(sLock); |
| 41 | |
| 42 | if (sProfiles == NULL) { |
| 43 | sProfiles = MediaProfiles::getInstance(); |
| 44 | } |
| 45 | } |
| 46 | |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 47 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 48 | android_media_MediaProfiles_native_get_num_file_formats(JNIEnv* /* env */, jobject /* thiz */) |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 49 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 50 | ALOGV("native_get_num_file_formats"); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 51 | return (jint) sProfiles->getOutputFileFormats().size(); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 52 | } |
| 53 | |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 54 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 55 | android_media_MediaProfiles_native_get_file_format(JNIEnv *env, jobject /* thiz */, jint index) |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 56 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 57 | ALOGV("native_get_file_format: %d", index); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 58 | Vector<output_format> formats = sProfiles->getOutputFileFormats(); |
| 59 | int nSize = formats.size(); |
| 60 | if (index < 0 || index >= nSize) { |
| 61 | jniThrowException(env, "java/lang/IllegalArgumentException", "out of array boundary"); |
| 62 | return -1; |
| 63 | } |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 64 | return static_cast<jint>(formats[index]); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 65 | } |
| 66 | |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 67 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 68 | android_media_MediaProfiles_native_get_num_video_encoders(JNIEnv* /* env */, jobject /* thiz */) |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 69 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 70 | ALOGV("native_get_num_video_encoders"); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 71 | return sProfiles->getVideoEncoders().size(); |
| 72 | } |
| 73 | |
| 74 | static jobject |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 75 | android_media_MediaProfiles_native_get_video_encoder_cap(JNIEnv *env, jobject /* thiz */, |
| 76 | jint index) |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 77 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 78 | ALOGV("native_get_video_encoder_cap: %d", index); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 79 | Vector<video_encoder> encoders = sProfiles->getVideoEncoders(); |
| 80 | int nSize = encoders.size(); |
| 81 | if (index < 0 || index >= nSize) { |
| 82 | jniThrowException(env, "java/lang/IllegalArgumentException", "out of array boundary"); |
| 83 | return NULL; |
| 84 | } |
| 85 | |
| 86 | video_encoder encoder = encoders[index]; |
| 87 | int minBitRate = sProfiles->getVideoEncoderParamByName("enc.vid.bps.min", encoder); |
| 88 | int maxBitRate = sProfiles->getVideoEncoderParamByName("enc.vid.bps.max", encoder); |
| 89 | int minFrameRate = sProfiles->getVideoEncoderParamByName("enc.vid.fps.min", encoder); |
| 90 | int maxFrameRate = sProfiles->getVideoEncoderParamByName("enc.vid.fps.max", encoder); |
| 91 | int minFrameWidth = sProfiles->getVideoEncoderParamByName("enc.vid.width.min", encoder); |
| 92 | int maxFrameWidth = sProfiles->getVideoEncoderParamByName("enc.vid.width.max", encoder); |
| 93 | int minFrameHeight = sProfiles->getVideoEncoderParamByName("enc.vid.height.min", encoder); |
| 94 | int maxFrameHeight = sProfiles->getVideoEncoderParamByName("enc.vid.height.max", encoder); |
| 95 | |
| 96 | // Check on the values retrieved |
| 97 | if ((minBitRate == -1 || maxBitRate == -1) || |
| 98 | (minFrameRate == -1 || maxFrameRate == -1) || |
| 99 | (minFrameWidth == -1 || maxFrameWidth == -1) || |
| 100 | (minFrameHeight == -1 || maxFrameHeight == -1)) { |
| 101 | |
| 102 | jniThrowException(env, "java/lang/RuntimeException", "Error retrieving video encoder capability params"); |
| 103 | return NULL; |
| 104 | } |
| 105 | |
| 106 | // Construct an instance of the VideoEncoderCap and set its member variables |
| 107 | jclass videoEncoderCapClazz = env->FindClass("android/media/EncoderCapabilities$VideoEncoderCap"); |
| 108 | jmethodID videoEncoderCapConstructorMethodID = env->GetMethodID(videoEncoderCapClazz, "<init>", "(IIIIIIIII)V"); |
| 109 | jobject cap = env->NewObject(videoEncoderCapClazz, |
| 110 | videoEncoderCapConstructorMethodID, |
| 111 | static_cast<int>(encoder), |
| 112 | minBitRate, maxBitRate, |
| 113 | minFrameRate, maxFrameRate, |
| 114 | minFrameWidth, maxFrameWidth, |
| 115 | minFrameHeight, maxFrameHeight); |
| 116 | return cap; |
| 117 | } |
| 118 | |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 119 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 120 | android_media_MediaProfiles_native_get_num_audio_encoders(JNIEnv* /* env */, jobject /* thiz */) |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 121 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 122 | ALOGV("native_get_num_audio_encoders"); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 123 | return (jint) sProfiles->getAudioEncoders().size(); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static jobject |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 127 | android_media_MediaProfiles_native_get_audio_encoder_cap(JNIEnv *env, jobject /* thiz */, |
| 128 | jint index) |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 129 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 130 | ALOGV("native_get_audio_encoder_cap: %d", index); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 131 | Vector<audio_encoder> encoders = sProfiles->getAudioEncoders(); |
| 132 | int nSize = encoders.size(); |
| 133 | if (index < 0 || index >= nSize) { |
| 134 | jniThrowException(env, "java/lang/IllegalArgumentException", "out of array boundary"); |
| 135 | return NULL; |
| 136 | } |
| 137 | |
| 138 | audio_encoder encoder = encoders[index]; |
| 139 | int minBitRate = sProfiles->getAudioEncoderParamByName("enc.aud.bps.min", encoder); |
| 140 | int maxBitRate = sProfiles->getAudioEncoderParamByName("enc.aud.bps.max", encoder); |
| 141 | int minSampleRate = sProfiles->getAudioEncoderParamByName("enc.aud.hz.min", encoder); |
| 142 | int maxSampleRate = sProfiles->getAudioEncoderParamByName("enc.aud.hz.max", encoder); |
| 143 | int minChannels = sProfiles->getAudioEncoderParamByName("enc.aud.ch.min", encoder); |
| 144 | int maxChannels = sProfiles->getAudioEncoderParamByName("enc.aud.ch.max", encoder); |
| 145 | |
| 146 | // Check on the values retrieved |
| 147 | if ((minBitRate == -1 || maxBitRate == -1) || |
| 148 | (minSampleRate == -1 || maxSampleRate == -1) || |
| 149 | (minChannels == -1 || maxChannels == -1)) { |
| 150 | |
| 151 | jniThrowException(env, "java/lang/RuntimeException", "Error retrieving video encoder capability params"); |
| 152 | return NULL; |
| 153 | } |
| 154 | |
| 155 | jclass audioEncoderCapClazz = env->FindClass("android/media/EncoderCapabilities$AudioEncoderCap"); |
| 156 | jmethodID audioEncoderCapConstructorMethodID = env->GetMethodID(audioEncoderCapClazz, "<init>", "(IIIIIII)V"); |
| 157 | jobject cap = env->NewObject(audioEncoderCapClazz, |
| 158 | audioEncoderCapConstructorMethodID, |
| 159 | static_cast<int>(encoder), |
| 160 | minBitRate, maxBitRate, |
| 161 | minSampleRate, maxSampleRate, |
| 162 | minChannels, maxChannels); |
| 163 | return cap; |
| 164 | } |
| 165 | |
James Dong | 07b9ae3 | 2011-09-19 16:27:31 -0700 | [diff] [blame] | 166 | static bool isCamcorderQualityKnown(int quality) |
| 167 | { |
| 168 | return ((quality >= CAMCORDER_QUALITY_LIST_START && |
| 169 | quality <= CAMCORDER_QUALITY_LIST_END) || |
| 170 | (quality >= CAMCORDER_QUALITY_TIME_LAPSE_LIST_START && |
Zhijun He | f7badff | 2014-07-23 13:42:11 -0700 | [diff] [blame] | 171 | quality <= CAMCORDER_QUALITY_TIME_LAPSE_LIST_END) || |
| 172 | (quality >= CAMCORDER_QUALITY_HIGH_SPEED_LIST_START && |
| 173 | quality <= CAMCORDER_QUALITY_HIGH_SPEED_LIST_END)); |
James Dong | 07b9ae3 | 2011-09-19 16:27:31 -0700 | [diff] [blame] | 174 | } |
| 175 | |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 176 | static jobject |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 177 | android_media_MediaProfiles_native_get_camcorder_profile(JNIEnv *env, jobject /* thiz */, jint id, |
| 178 | jint quality) |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 179 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 180 | ALOGV("native_get_camcorder_profile: %d %d", id, quality); |
James Dong | 07b9ae3 | 2011-09-19 16:27:31 -0700 | [diff] [blame] | 181 | if (!isCamcorderQualityKnown(quality)) { |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 182 | jniThrowException(env, "java/lang/RuntimeException", "Unknown camcorder profile quality"); |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | camcorder_quality q = static_cast<camcorder_quality>(quality); |
Chih-Chung Chang | 09b9005 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 187 | int duration = sProfiles->getCamcorderProfileParamByName("duration", id, q); |
| 188 | int fileFormat = sProfiles->getCamcorderProfileParamByName("file.format", id, q); |
| 189 | int videoCodec = sProfiles->getCamcorderProfileParamByName("vid.codec", id, q); |
| 190 | int videoBitRate = sProfiles->getCamcorderProfileParamByName("vid.bps", id, q); |
| 191 | int videoFrameRate = sProfiles->getCamcorderProfileParamByName("vid.fps", id, q); |
| 192 | int videoFrameWidth = sProfiles->getCamcorderProfileParamByName("vid.width", id, q); |
| 193 | int videoFrameHeight = sProfiles->getCamcorderProfileParamByName("vid.height", id, q); |
| 194 | int audioCodec = sProfiles->getCamcorderProfileParamByName("aud.codec", id, q); |
| 195 | int audioBitRate = sProfiles->getCamcorderProfileParamByName("aud.bps", id, q); |
| 196 | int audioSampleRate = sProfiles->getCamcorderProfileParamByName("aud.hz", id, q); |
| 197 | int audioChannels = sProfiles->getCamcorderProfileParamByName("aud.ch", id, q); |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 198 | |
| 199 | // Check on the values retrieved |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 200 | if (duration == -1 || fileFormat == -1 || videoCodec == -1 || audioCodec == -1 || |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 201 | videoBitRate == -1 || videoFrameRate == -1 || videoFrameWidth == -1 || videoFrameHeight == -1 || |
| 202 | audioBitRate == -1 || audioSampleRate == -1 || audioChannels == -1) { |
| 203 | |
| 204 | jniThrowException(env, "java/lang/RuntimeException", "Error retrieving camcorder profile params"); |
| 205 | return NULL; |
| 206 | } |
| 207 | |
| 208 | jclass camcorderProfileClazz = env->FindClass("android/media/CamcorderProfile"); |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 209 | jmethodID camcorderProfileConstructorMethodID = env->GetMethodID(camcorderProfileClazz, "<init>", "(IIIIIIIIIIII)V"); |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 210 | return env->NewObject(camcorderProfileClazz, |
| 211 | camcorderProfileConstructorMethodID, |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 212 | duration, |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 213 | quality, |
| 214 | fileFormat, |
| 215 | videoCodec, |
| 216 | videoBitRate, |
| 217 | videoFrameRate, |
| 218 | videoFrameWidth, |
| 219 | videoFrameHeight, |
| 220 | audioCodec, |
| 221 | audioBitRate, |
| 222 | audioSampleRate, |
| 223 | audioChannels); |
| 224 | } |
| 225 | |
Nipun Kwatra | 9d61954 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 226 | static jboolean |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 227 | android_media_MediaProfiles_native_has_camcorder_profile(JNIEnv* /* env */, jobject /* thiz */, |
| 228 | jint id, jint quality) |
Nipun Kwatra | 9d61954 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 229 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 230 | ALOGV("native_has_camcorder_profile: %d %d", id, quality); |
James Dong | 07b9ae3 | 2011-09-19 16:27:31 -0700 | [diff] [blame] | 231 | if (!isCamcorderQualityKnown(quality)) { |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 232 | return JNI_FALSE; |
Nipun Kwatra | 9d61954 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | camcorder_quality q = static_cast<camcorder_quality>(quality); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 236 | return sProfiles->hasCamcorderProfile(id, q) ? JNI_TRUE : JNI_FALSE; |
Nipun Kwatra | 9d61954 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 237 | } |
| 238 | |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 239 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 240 | android_media_MediaProfiles_native_get_num_video_decoders(JNIEnv* /* env */, jobject /* thiz */) |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 241 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 242 | ALOGV("native_get_num_video_decoders"); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 243 | return (jint) sProfiles->getVideoDecoders().size(); |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 247 | android_media_MediaProfiles_native_get_video_decoder_type(JNIEnv *env, jobject /* thiz */, |
| 248 | jint index) |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 249 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 250 | ALOGV("native_get_video_decoder_type: %d", index); |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 251 | Vector<video_decoder> decoders = sProfiles->getVideoDecoders(); |
| 252 | int nSize = decoders.size(); |
| 253 | if (index < 0 || index >= nSize) { |
| 254 | jniThrowException(env, "java/lang/IllegalArgumentException", "out of array boundary"); |
| 255 | return -1; |
| 256 | } |
| 257 | |
| 258 | return static_cast<jint>(decoders[index]); |
| 259 | } |
| 260 | |
| 261 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 262 | android_media_MediaProfiles_native_get_num_audio_decoders(JNIEnv* /* env */, jobject /* thiz */) |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 263 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 264 | ALOGV("native_get_num_audio_decoders"); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 265 | return (jint) sProfiles->getAudioDecoders().size(); |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 269 | android_media_MediaProfiles_native_get_audio_decoder_type(JNIEnv *env, jobject /* thiz */, |
| 270 | jint index) |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 271 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 272 | ALOGV("native_get_audio_decoder_type: %d", index); |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 273 | Vector<audio_decoder> decoders = sProfiles->getAudioDecoders(); |
| 274 | int nSize = decoders.size(); |
| 275 | if (index < 0 || index >= nSize) { |
| 276 | jniThrowException(env, "java/lang/IllegalArgumentException", "out of array boundary"); |
| 277 | return -1; |
| 278 | } |
| 279 | |
| 280 | return static_cast<jint>(decoders[index]); |
| 281 | } |
| 282 | |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 283 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 284 | android_media_MediaProfiles_native_get_num_image_encoding_quality_levels(JNIEnv* /* env */, |
| 285 | jobject /* thiz */, |
| 286 | jint cameraId) |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 287 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 288 | ALOGV("native_get_num_image_encoding_quality_levels"); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 289 | return (jint) sProfiles->getImageEncodingQualityLevels(cameraId).size(); |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static jint |
Andreas Gampe | 5a15d0d | 2014-11-10 18:19:40 -0800 | [diff] [blame] | 293 | android_media_MediaProfiles_native_get_image_encoding_quality_level(JNIEnv *env, jobject /* thiz */, |
| 294 | jint cameraId, jint index) |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 295 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 296 | ALOGV("native_get_image_encoding_quality_level"); |
Chih-Chung Chang | 09b9005 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 297 | Vector<int> levels = sProfiles->getImageEncodingQualityLevels(cameraId); |
Ashok Bhat | 075e9a1 | 2014-01-06 13:45:09 +0000 | [diff] [blame] | 298 | if (index < 0 || index >= (jint) levels.size()) { |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 299 | jniThrowException(env, "java/lang/IllegalArgumentException", "out of array boundary"); |
| 300 | return -1; |
| 301 | } |
| 302 | return static_cast<jint>(levels[index]); |
| 303 | } |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 304 | static const JNINativeMethod gMethodsForEncoderCapabilitiesClass[] = { |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 305 | {"native_init", "()V", (void *)android_media_MediaProfiles_native_init}, |
| 306 | {"native_get_num_file_formats", "()I", (void *)android_media_MediaProfiles_native_get_num_file_formats}, |
| 307 | {"native_get_file_format", "(I)I", (void *)android_media_MediaProfiles_native_get_file_format}, |
| 308 | {"native_get_num_video_encoders", "()I", (void *)android_media_MediaProfiles_native_get_num_video_encoders}, |
| 309 | {"native_get_num_audio_encoders", "()I", (void *)android_media_MediaProfiles_native_get_num_audio_encoders}, |
| 310 | |
| 311 | {"native_get_video_encoder_cap", "(I)Landroid/media/EncoderCapabilities$VideoEncoderCap;", |
| 312 | (void *)android_media_MediaProfiles_native_get_video_encoder_cap}, |
| 313 | |
| 314 | {"native_get_audio_encoder_cap", "(I)Landroid/media/EncoderCapabilities$AudioEncoderCap;", |
| 315 | (void *)android_media_MediaProfiles_native_get_audio_encoder_cap}, |
| 316 | }; |
| 317 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 318 | static const JNINativeMethod gMethodsForCamcorderProfileClass[] = { |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 319 | {"native_init", "()V", (void *)android_media_MediaProfiles_native_init}, |
Chih-Chung Chang | 09b9005 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 320 | {"native_get_camcorder_profile", "(II)Landroid/media/CamcorderProfile;", |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 321 | (void *)android_media_MediaProfiles_native_get_camcorder_profile}, |
Nipun Kwatra | 9d61954 | 2010-09-09 16:25:08 -0700 | [diff] [blame] | 322 | {"native_has_camcorder_profile", "(II)Z", |
| 323 | (void *)android_media_MediaProfiles_native_has_camcorder_profile}, |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 324 | }; |
| 325 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 326 | static const JNINativeMethod gMethodsForDecoderCapabilitiesClass[] = { |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 327 | {"native_init", "()V", (void *)android_media_MediaProfiles_native_init}, |
| 328 | {"native_get_num_video_decoders", "()I", (void *)android_media_MediaProfiles_native_get_num_video_decoders}, |
| 329 | {"native_get_num_audio_decoders", "()I", (void *)android_media_MediaProfiles_native_get_num_audio_decoders}, |
| 330 | {"native_get_video_decoder_type", "(I)I", (void *)android_media_MediaProfiles_native_get_video_decoder_type}, |
| 331 | {"native_get_audio_decoder_type", "(I)I", (void *)android_media_MediaProfiles_native_get_audio_decoder_type}, |
| 332 | }; |
| 333 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 334 | static const JNINativeMethod gMethodsForCameraProfileClass[] = { |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 335 | {"native_init", "()V", (void *)android_media_MediaProfiles_native_init}, |
| 336 | {"native_get_num_image_encoding_quality_levels", |
Chih-Chung Chang | 09b9005 | 2010-06-22 20:50:55 +0800 | [diff] [blame] | 337 | "(I)I", (void *)android_media_MediaProfiles_native_get_num_image_encoding_quality_levels}, |
| 338 | {"native_get_image_encoding_quality_level","(II)I", (void *)android_media_MediaProfiles_native_get_image_encoding_quality_level}, |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 339 | }; |
| 340 | |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 341 | static const char* const kEncoderCapabilitiesClassPathName = "android/media/EncoderCapabilities"; |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 342 | static const char* const kDecoderCapabilitiesClassPathName = "android/media/DecoderCapabilities"; |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 343 | static const char* const kCamcorderProfileClassPathName = "android/media/CamcorderProfile"; |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 344 | static const char* const kCameraProfileClassPathName = "android/media/CameraProfile"; |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 345 | |
| 346 | // This function only registers the native methods, and is called from |
| 347 | // JNI_OnLoad in android_media_MediaPlayer.cpp |
| 348 | int register_android_media_MediaProfiles(JNIEnv *env) |
| 349 | { |
James Dong | e7038ac | 2010-02-03 16:50:18 -0800 | [diff] [blame] | 350 | int ret1 = AndroidRuntime::registerNativeMethods(env, |
| 351 | kEncoderCapabilitiesClassPathName, |
| 352 | gMethodsForEncoderCapabilitiesClass, |
| 353 | NELEM(gMethodsForEncoderCapabilitiesClass)); |
| 354 | |
| 355 | int ret2 = AndroidRuntime::registerNativeMethods(env, |
| 356 | kCamcorderProfileClassPathName, |
| 357 | gMethodsForCamcorderProfileClass, |
| 358 | NELEM(gMethodsForCamcorderProfileClass)); |
| 359 | |
James Dong | d32fba4 | 2010-02-11 14:32:13 -0800 | [diff] [blame] | 360 | int ret3 = AndroidRuntime::registerNativeMethods(env, |
| 361 | kDecoderCapabilitiesClassPathName, |
| 362 | gMethodsForDecoderCapabilitiesClass, |
| 363 | NELEM(gMethodsForDecoderCapabilitiesClass)); |
| 364 | |
James Dong | 9b433f0 | 2010-02-23 17:21:44 -0800 | [diff] [blame] | 365 | int ret4 = AndroidRuntime::registerNativeMethods(env, |
| 366 | kCameraProfileClassPathName, |
| 367 | gMethodsForCameraProfileClass, |
| 368 | NELEM(gMethodsForCameraProfileClass)); |
| 369 | |
| 370 | // Success if all return values from above are 0 |
Lajos Molnar | e0e77cb | 2014-04-21 15:34:02 -0700 | [diff] [blame] | 371 | return (ret1 || ret2 || ret3 || ret4); |
James Dong | c371194 | 2010-01-19 17:45:38 -0800 | [diff] [blame] | 372 | } |