Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 294a6e42 authored by James Dong's avatar James Dong Committed by Android (Google) Code Review
Browse files

Merge "Scale the thumbnail if display dimension is different from the actual buffer size"

parents 90298b56 9f2cde3c
Loading
Loading
Loading
Loading
+37 −6
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ struct fields_t {
    jclass bitmapClazz;
    jclass bitmapClazz;
    jfieldID nativeBitmap;
    jfieldID nativeBitmap;
    jmethodID createBitmapMethod;
    jmethodID createBitmapMethod;
    jmethodID createScaledBitmapMethod;
    jclass configClazz;
    jclass configClazz;
    jmethodID createConfigMethod;
    jmethodID createConfigMethod;
};
};
@@ -219,12 +220,14 @@ static jobject android_media_MediaMetadataRetriever_getFrameAtTime(JNIEnv *env,
                        SkBitmap::kRGB_565_Config);
                        SkBitmap::kRGB_565_Config);


    size_t width, height;
    size_t width, height;
    bool swapWidthAndHeight = false;
    if (videoFrame->mRotationAngle == 90 || videoFrame->mRotationAngle == 270) {
    if (videoFrame->mRotationAngle == 90 || videoFrame->mRotationAngle == 270) {
        width = videoFrame->mDisplayHeight;
        width = videoFrame->mHeight;
        height = videoFrame->mDisplayWidth;
        height = videoFrame->mWidth;
        swapWidthAndHeight = true;
    } else {
    } else {
        width = videoFrame->mDisplayWidth;
        width = videoFrame->mWidth;
        height = videoFrame->mDisplayHeight;
        height = videoFrame->mHeight;
    }
    }


    jobject jBitmap = env->CallStaticObjectMethod(
    jobject jBitmap = env->CallStaticObjectMethod(
@@ -240,11 +243,30 @@ static jobject android_media_MediaMetadataRetriever_getFrameAtTime(JNIEnv *env,
    bitmap->lockPixels();
    bitmap->lockPixels();
    rotate((uint16_t*)bitmap->getPixels(),
    rotate((uint16_t*)bitmap->getPixels(),
           (uint16_t*)((char*)videoFrame + sizeof(VideoFrame)),
           (uint16_t*)((char*)videoFrame + sizeof(VideoFrame)),
           videoFrame->mDisplayWidth,
           videoFrame->mWidth,
           videoFrame->mDisplayHeight,
           videoFrame->mHeight,
           videoFrame->mRotationAngle);
           videoFrame->mRotationAngle);
    bitmap->unlockPixels();
    bitmap->unlockPixels();


    if (videoFrame->mDisplayWidth  != videoFrame->mWidth ||
        videoFrame->mDisplayHeight != videoFrame->mHeight) {
        size_t displayWidth = videoFrame->mDisplayWidth;
        size_t displayHeight = videoFrame->mDisplayHeight;
        if (swapWidthAndHeight) {
            displayWidth = videoFrame->mDisplayHeight;
            displayHeight = videoFrame->mDisplayWidth;
        }
        LOGV("Bitmap dimension is scaled from %dx%d to %dx%d",
                width, height, displayWidth, displayHeight);
        jobject scaledBitmap = env->CallStaticObjectMethod(fields.bitmapClazz,
                                    fields.createScaledBitmapMethod,
                                    jBitmap,
                                    displayWidth,
                                    displayHeight,
                                    true);
        return scaledBitmap;
    }

    return jBitmap;
    return jBitmap;
}
}


@@ -352,6 +374,15 @@ static void android_media_MediaMetadataRetriever_native_init(JNIEnv *env)
                "Can't find Bitmap.createBitmap(int, int, Config)  method");
                "Can't find Bitmap.createBitmap(int, int, Config)  method");
        return;
        return;
    }
    }
    fields.createScaledBitmapMethod =
            env->GetStaticMethodID(fields.bitmapClazz, "createScaledBitmap",
                    "(Landroid/graphics/Bitmap;IIZ)"
                    "Landroid/graphics/Bitmap;");
    if (fields.createScaledBitmapMethod == NULL) {
        jniThrowException(env, "java/lang/RuntimeException",
                "Can't find Bitmap.createScaledBitmap(Bitmap, int, int, boolean)  method");
        return;
    }
    fields.nativeBitmap = env->GetFieldID(fields.bitmapClazz, "mNativeBitmap", "I");
    fields.nativeBitmap = env->GetFieldID(fields.bitmapClazz, "mNativeBitmap", "I");
    if (fields.nativeBitmap == NULL) {
    if (fields.nativeBitmap == NULL) {
        jniThrowException(env, "java/lang/RuntimeException",
        jniThrowException(env, "java/lang/RuntimeException",
+9 −1
Original line number Original line Diff line number Diff line
@@ -231,6 +231,14 @@ static VideoFrame *extractVideoFrameWithCodecFlags(
    frame->mData = new uint8_t[frame->mSize];
    frame->mData = new uint8_t[frame->mSize];
    frame->mRotationAngle = rotationAngle;
    frame->mRotationAngle = rotationAngle;


    int32_t displayWidth, displayHeight;
    if (meta->findInt32(kKeyDisplayWidth, &displayWidth)) {
        frame->mDisplayWidth = displayWidth;
    }
    if (meta->findInt32(kKeyDisplayHeight, &displayHeight)) {
        frame->mDisplayHeight = displayHeight;
    }

    int32_t srcFormat;
    int32_t srcFormat;
    CHECK(meta->findInt32(kKeyColorFormat, &srcFormat));
    CHECK(meta->findInt32(kKeyColorFormat, &srcFormat));


@@ -465,7 +473,7 @@ void StagefrightMetadataRetriever::parseMetaData() {
    }
    }


    if (numTracks == 1 && hasAudio && audioBitrate >= 0) {
    if (numTracks == 1 && hasAudio && audioBitrate >= 0) {
        sprintf(tmp, "%ld", audioBitrate);
        sprintf(tmp, "%d", audioBitrate);
        mMetaData.add(METADATA_KEY_BITRATE, String8(tmp));
        mMetaData.add(METADATA_KEY_BITRATE, String8(tmp));
    } else {
    } else {
        off64_t sourceSize;
        off64_t sourceSize;