static jbyteArray wseemann_media_FFmpegMediaMetadataRetriever_getEmbeddedPicture(JNIEnv *env, jobject thiz) { //__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "getEmbeddedPicture"); MediaMetadataRetriever* retriever = getRetriever(env, thiz); if (retriever == 0) { jniThrowException(env, "java/lang/IllegalStateException", "No retriever available"); return NULL; } AVPacket packet; av_init_packet(&packet); jbyteArray array = NULL; if (retriever->extractAlbumArt(&packet) == 0) { int size = packet.size; uint8_t* data = packet.data; array = env->NewByteArray(size); if (!array) { // OutOfMemoryError exception has already been thrown. //__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "getEmbeddedPicture: OutOfMemoryError is thrown."); } else { //__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "getEmbeddedPicture: Found album art."); jbyte* bytes = env->GetByteArrayElements(array, NULL); if (bytes != NULL) { memcpy(bytes, data, size); env->ReleaseByteArrayElements(array, bytes, 0); } } } av_free_packet(&packet); return array; }
static jbyteArray android_media_MediaMetadataRetriever_getEmbeddedPicture( JNIEnv *env, jobject thiz, jint pictureType) { ALOGV("getEmbeddedPicture: %d", pictureType); MediaMetadataRetriever* retriever = getRetriever(env, thiz); if (retriever == 0) { jniThrowException(env, "java/lang/IllegalStateException", "No retriever available"); return NULL; } MediaAlbumArt* mediaAlbumArt = NULL; // FIXME: // Use pictureType to retrieve the intended embedded picture and also change // the method name to getEmbeddedPicture(). sp<IMemory> albumArtMemory = retriever->extractAlbumArt(); if (albumArtMemory != 0) { // cast the shared structure to a MediaAlbumArt object mediaAlbumArt = static_cast<MediaAlbumArt *>(albumArtMemory->pointer()); } if (mediaAlbumArt == NULL) { ALOGE("getEmbeddedPicture: Call to getEmbeddedPicture failed."); return NULL; } unsigned int len = mediaAlbumArt->mSize; char* data = (char*) mediaAlbumArt + sizeof(MediaAlbumArt); jbyteArray array = env->NewByteArray(len); if (!array) { // OutOfMemoryError exception has already been thrown. ALOGE("getEmbeddedPicture: OutOfMemoryError is thrown."); } else { jbyte* bytes = env->GetByteArrayElements(array, NULL); if (bytes != NULL) { memcpy(bytes, data, len); env->ReleaseByteArrayElements(array, bytes, 0); } } // No need to delete mediaAlbumArt here return array; }