Merge changes I8462f040,Ie471f40f

* changes:
  MediaCodec: Allow getting the codec info directly
  MediaCodec: Allow getting the chosen component name
This commit is contained in:
Andreas Huber
2012-11-30 13:26:51 -08:00
committed by Gerrit Code Review
6 changed files with 86 additions and 0 deletions

View File

@ -11199,7 +11199,9 @@ package android.media {
method public final int dequeueInputBuffer(long);
method public final int dequeueOutputBuffer(android.media.MediaCodec.BufferInfo, long);
method public final void flush();
method public android.media.MediaCodecInfo getCodecInfo();
method public java.nio.ByteBuffer[] getInputBuffers();
method public final java.lang.String getName();
method public java.nio.ByteBuffer[] getOutputBuffers();
method public final android.media.MediaFormat getOutputFormat();
method public final void queueInputBuffer(int, int, int, long, int) throws android.media.MediaCodec.CryptoException;

View File

@ -16,6 +16,8 @@
package android.media;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.view.Surface;
@ -498,6 +500,22 @@ final public class MediaCodec {
*/
public native final void setVideoScalingMode(int mode);
/**
* Get the component name. If the codec was created by createDecoderByType
* or createEncoderByType, what component is chosen is not known beforehand.
*/
public native final String getName();
/**
* Get the codec info. If the codec was created by createDecoderByType
* or createEncoderByType, what component is chosen is not known beforehand,
* and thus the caller does not have the MediaCodecInfo.
*/
public MediaCodecInfo getCodecInfo() {
return MediaCodecList.getCodecInfoAt(
MediaCodecList.findCodecByName(getName()));
}
private native final ByteBuffer[] getBuffers(boolean input);
private static native final void native_init();

View File

@ -46,6 +46,8 @@ final public class MediaCodecList {
/* package private */ static native final MediaCodecInfo.CodecCapabilities
getCodecCapabilities(int index, String type);
/* package private */ static native final int findCodecByName(String codec);
private static native final void native_init();
private MediaCodecList() {}

View File

@ -264,6 +264,20 @@ status_t JMediaCodec::getBuffers(
return OK;
}
status_t JMediaCodec::getName(JNIEnv *env, jstring *nameStr) const {
AString name;
status_t err = mCodec->getName(&name);
if (err != OK) {
return err;
}
*nameStr = env->NewStringUTF(name.c_str());
return OK;
}
void JMediaCodec::setVideoScalingMode(int mode) {
if (mSurfaceTextureClient != NULL) {
native_window_set_scaling_mode(mSurfaceTextureClient.get(), mode);
@ -706,6 +720,29 @@ static jobjectArray android_media_MediaCodec_getBuffers(
return NULL;
}
static jobject android_media_MediaCodec_getName(
JNIEnv *env, jobject thiz) {
ALOGV("android_media_MediaCodec_getName");
sp<JMediaCodec> codec = getMediaCodec(env, thiz);
if (codec == NULL) {
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return NULL;
}
jstring name;
status_t err = codec->getName(env, &name);
if (err == OK) {
return name;
}
throwExceptionAsNecessary(env, err);
return NULL;
}
static void android_media_MediaCodec_setVideoScalingMode(
JNIEnv *env, jobject thiz, jint mode) {
sp<JMediaCodec> codec = getMediaCodec(env, thiz);
@ -826,6 +863,9 @@ static JNINativeMethod gMethods[] = {
{ "getBuffers", "(Z)[Ljava/nio/ByteBuffer;",
(void *)android_media_MediaCodec_getBuffers },
{ "getName", "()Ljava/lang/String;",
(void *)android_media_MediaCodec_getName },
{ "setVideoScalingMode", "(I)V",
(void *)android_media_MediaCodec_setVideoScalingMode },

View File

@ -81,6 +81,8 @@ struct JMediaCodec : public RefBase {
status_t getBuffers(
JNIEnv *env, bool input, jobjectArray *bufArray) const;
status_t getName(JNIEnv *env, jstring *name) const;
void setVideoScalingMode(int mode);
protected:

View File

@ -44,6 +44,25 @@ static jstring android_media_MediaCodecList_getCodecName(
return env->NewStringUTF(name);
}
static jint android_media_MediaCodecList_findCodecByName(
JNIEnv *env, jobject thiz, jstring name) {
if (name == NULL) {
jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
return -ENOENT;
}
const char *nameStr = env->GetStringUTFChars(name, NULL);
if (nameStr == NULL) {
// Out of memory exception already pending.
return -ENOENT;
}
jint ret = MediaCodecList::getInstance()->findCodecByName(nameStr);
env->ReleaseStringUTFChars(name, nameStr);
return ret;
}
static jboolean android_media_MediaCodecList_isEncoder(
JNIEnv *env, jobject thiz, jint index) {
return MediaCodecList::getInstance()->isEncoder(index);
@ -180,6 +199,9 @@ static JNINativeMethod gMethods[] = {
"(ILjava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;",
(void *)android_media_MediaCodecList_getCodecCapabilities },
{ "findCodecByName", "(Ljava/lang/String;)I",
(void *)android_media_MediaCodecList_findCodecByName },
{ "native_init", "()V", (void *)android_media_MediaCodecList_native_init },
};