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

Commit bda93c4c authored by Chih-Chung Chang's avatar Chih-Chung Chang Committed by Android Git Automerger
Browse files

am 09b90057: Add multiple camera support for in MediaProfiles.

Merge commit '09b90057' into gingerbread-plus-aosp

* commit '09b90057':
  Add multiple camera support for in MediaProfiles.
parents d3233ae9 09b90057
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -87306,6 +87306,21 @@
<parameter name="quality" type="int">
</parameter>
</method>
<method name="get"
 return="android.media.CamcorderProfile"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cameraId" type="int">
</parameter>
<parameter name="quality" type="int">
</parameter>
</method>
<field name="QUALITY_HIGH"
 type="int"
 transient="false"
@@ -87478,6 +87493,21 @@
<parameter name="quality" type="int">
</parameter>
</method>
<method name="getJpegEncodingQualityParameter"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="cameraId" type="int">
</parameter>
<parameter name="quality" type="int">
</parameter>
</method>
<field name="QUALITY_HIGH"
 type="int"
 transient="false"
+20 −15
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ public:
    static MediaProfiles* getInstance();

    /**
     * Returns the value for the given param name at the given quality level,
     * or -1 if error.
     * Returns the value for the given param name for the given camera at
     * the given quality level, or -1 if error.
     *
     * Supported param name are:
     * duration - the recording duration.
@@ -64,7 +64,8 @@ public:
     * aud.hz - audio sample rate
     * aud.ch - number of audio channels
     */
    int getCamcorderProfileParamByName(const char *name, camcorder_quality quality) const;
    int getCamcorderProfileParamByName(const char *name, int cameraId,
                                       camcorder_quality quality) const;

    /**
     * Returns the output file formats supported.
@@ -124,12 +125,7 @@ public:
    /**
     * Returns the number of image encoding quality levels supported.
     */
    Vector<int> getImageEncodingQualityLevels() const;

    /**
     * Returns the maximum amount of memory in bytes we can use for decoding a JPEG file.
     */
    int getImageDecodingMaxMemory() const;
    Vector<int> getImageEncodingQualityLevels(int cameraId) const;

private:
    MediaProfiles& operator=(const MediaProfiles&);  // Don't call me
@@ -171,7 +167,8 @@ private:

    struct CamcorderProfile {
        CamcorderProfile()
            : mFileFormat(OUTPUT_FORMAT_THREE_GPP),
            : mCameraId(0),
              mFileFormat(OUTPUT_FORMAT_THREE_GPP),
              mQuality(CAMCORDER_QUALITY_HIGH),
              mDuration(0),
              mVideoCodec(0),
@@ -182,6 +179,7 @@ private:
            delete mAudioCodec;
        }

        int mCameraId;
        output_format mFileFormat;
        camcorder_quality mQuality;
        int mDuration;
@@ -249,6 +247,11 @@ private:
        int tag;
    };

    struct ImageEncodingQualityLevels {
        int mCameraId;
        Vector<int> mLevels;
    };

    // Debug
    static void logVideoCodec(const VideoCodec& codec);
    static void logAudioCodec(const AudioCodec& codec);
@@ -267,9 +270,11 @@ private:
    static VideoDecoderCap* createVideoDecoderCap(const char **atts);
    static VideoEncoderCap* createVideoEncoderCap(const char **atts);
    static AudioEncoderCap* createAudioEncoderCap(const char **atts);
    static CamcorderProfile* createCamcorderProfile(const char **atts);
    static int getImageEncodingQualityLevel(const char **atts);
    static int getImageDecodingMaxMemory(const char **atts);
    static CamcorderProfile* createCamcorderProfile(int cameraId, const char **atts);
    static int getCameraId(const char **atts);

    ImageEncodingQualityLevels* findImageEncodingQualityLevels(int cameraId) const;
    void addImageEncodingQualityLevel(int cameraId, const char** atts);

    // Customized element tag handler for parsing the xml configuration file.
    static void startElementHandler(void *userData, const char *name, const char **atts);
@@ -303,6 +308,7 @@ private:
    static bool sIsInitialized;
    static MediaProfiles *sInstance;
    static Mutex sLock;
    int mCurrentCameraId;

    Vector<CamcorderProfile*> mCamcorderProfiles;
    Vector<AudioEncoderCap*>  mAudioEncoders;
@@ -310,8 +316,7 @@ private:
    Vector<AudioDecoderCap*>  mAudioDecoders;
    Vector<VideoDecoderCap*>  mVideoDecoders;
    Vector<output_format>     mEncoderOutputFileFormats;
    Vector<int>               mImageEncodingQualityLevels;
    int                       mImageDecodingMaxMemory;
    Vector<ImageEncodingQualityLevels *>  mImageEncodingQualityLevels;
};

}; // namespace android
+15 −3
Original line number Diff line number Diff line
@@ -119,15 +119,26 @@ public class CamcorderProfile
    public int audioChannels;

    /**
     * Returns the camcorder profile for the given quality level.
     * Returns the camcorder profile for the default camera at the given
     * quality level.
     * @param quality the target quality level for the camcorder profile
     */
    public static CamcorderProfile get(int quality) {
        return get(0, quality);
    }

    /**
     * Returns the camcorder profile for the given camera at the given
     * quality level.
     * @param cameraId the id for the camera
     * @param quality the target quality level for the camcorder profile
     */
    public static CamcorderProfile get(int cameraId, int quality) {
        if (quality < QUALITY_LOW || quality > QUALITY_HIGH) {
            String errMessage = "Unsupported quality level: " + quality;
            throw new IllegalArgumentException(errMessage);
        }
        return native_get_camcorder_profile(quality);
        return native_get_camcorder_profile(cameraId, quality);
    }

    static {
@@ -165,5 +176,6 @@ public class CamcorderProfile

    // Methods implemented by JNI
    private static native final void native_init();
    private static native final CamcorderProfile native_get_camcorder_profile(int quality);
    private static native final CamcorderProfile native_get_camcorder_profile(
            int cameraId, int quality);
}
+29 −9
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.media;

import java.util.Arrays;
import java.util.HashMap;

/**
 * The CameraProfile class is used to retrieve the pre-defined still image
@@ -40,36 +41,55 @@ public class CameraProfile
    /*
     * Cache the Jpeg encoding quality parameters
     */
    private static final int[] sJpegEncodingQualityParameters;
    private static final HashMap<Integer, int[]> sCache = new HashMap<Integer, int[]>();

    /**
     * Returns a pre-defined still image capture (jpeg) quality level
     * used for the given quality level in the Camera application.
     * used for the given quality level in the Camera application for
     * the default camera.
     *
     * @param quality The target quality level
     */
    public static int getJpegEncodingQualityParameter(int quality) {
        return getJpegEncodingQualityParameter(0, quality);
    }

    /**
     * Returns a pre-defined still image capture (jpeg) quality level
     * used for the given quality level in the Camera application for
     * the specified camera.
     *
     * @param cameraId The id of the camera
     * @param quality The target quality level
     */
    public static int getJpegEncodingQualityParameter(int cameraId, int quality) {
        if (quality < QUALITY_LOW || quality > QUALITY_HIGH) {
            throw new IllegalArgumentException("Unsupported quality level: " + quality);
        }
        return sJpegEncodingQualityParameters[quality];
        synchronized (sCache) {
            int[] levels = sCache.get(cameraId);
            if (levels == null) {
                levels = getImageEncodingQualityLevels(cameraId);
                sCache.put(cameraId, levels);
            }
            return levels[quality];
        }
    }

    static {
        System.loadLibrary("media_jni");
        native_init();
        sJpegEncodingQualityParameters = getImageEncodingQualityLevels();
    }

    private static int[] getImageEncodingQualityLevels() {
        int nLevels = native_get_num_image_encoding_quality_levels();
    private static int[] getImageEncodingQualityLevels(int cameraId) {
        int nLevels = native_get_num_image_encoding_quality_levels(cameraId);
        if (nLevels != QUALITY_HIGH + 1) {
            throw new RuntimeException("Unexpected Jpeg encoding quality levels " + nLevels);
        }

        int[] levels = new int[nLevels];
        for (int i = 0; i < nLevels; ++i) {
            levels[i] = native_get_image_encoding_quality_level(i);
            levels[i] = native_get_image_encoding_quality_level(cameraId, i);
        }
        Arrays.sort(levels);  // Lower quality level ALWAYS comes before higher one
        return levels;
@@ -77,6 +97,6 @@ public class CameraProfile

    // Methods implemented by JNI
    private static native final void native_init();
    private static native final int native_get_num_image_encoding_quality_levels();
    private static native final int native_get_image_encoding_quality_level(int index);
    private static native final int native_get_num_image_encoding_quality_levels(int cameraId);
    private static native final int native_get_image_encoding_quality_level(int cameraId, int index);
}
+20 −20
Original line number Diff line number Diff line
@@ -162,26 +162,26 @@ android_media_MediaProfiles_native_get_audio_encoder_cap(JNIEnv *env, jobject th
}

static jobject
android_media_MediaProfiles_native_get_camcorder_profile(JNIEnv *env, jobject thiz, jint quality)
android_media_MediaProfiles_native_get_camcorder_profile(JNIEnv *env, jobject thiz, jint id, jint quality)
{
    LOGV("native_get_camcorder_profile: %d", quality);
    LOGV("native_get_camcorder_profile: %d %d", id, quality);
    if (quality != CAMCORDER_QUALITY_HIGH && quality != CAMCORDER_QUALITY_LOW) {
        jniThrowException(env, "java/lang/RuntimeException", "Unknown camcorder profile quality");
        return NULL;
    }

    camcorder_quality q = static_cast<camcorder_quality>(quality);
    int duration         = sProfiles->getCamcorderProfileParamByName("duration", q);
    int fileFormat       = sProfiles->getCamcorderProfileParamByName("file.format", q);
    int videoCodec       = sProfiles->getCamcorderProfileParamByName("vid.codec",   q);
    int videoBitRate     = sProfiles->getCamcorderProfileParamByName("vid.bps",     q);
    int videoFrameRate   = sProfiles->getCamcorderProfileParamByName("vid.fps",     q);
    int videoFrameWidth  = sProfiles->getCamcorderProfileParamByName("vid.width",   q);
    int videoFrameHeight = sProfiles->getCamcorderProfileParamByName("vid.height",  q);
    int audioCodec       = sProfiles->getCamcorderProfileParamByName("aud.codec",   q);
    int audioBitRate     = sProfiles->getCamcorderProfileParamByName("aud.bps",     q);
    int audioSampleRate  = sProfiles->getCamcorderProfileParamByName("aud.hz",      q);
    int audioChannels    = sProfiles->getCamcorderProfileParamByName("aud.ch",      q);
    int duration         = sProfiles->getCamcorderProfileParamByName("duration",    id, q);
    int fileFormat       = sProfiles->getCamcorderProfileParamByName("file.format", id, q);
    int videoCodec       = sProfiles->getCamcorderProfileParamByName("vid.codec",   id, q);
    int videoBitRate     = sProfiles->getCamcorderProfileParamByName("vid.bps",     id, q);
    int videoFrameRate   = sProfiles->getCamcorderProfileParamByName("vid.fps",     id, q);
    int videoFrameWidth  = sProfiles->getCamcorderProfileParamByName("vid.width",   id, q);
    int videoFrameHeight = sProfiles->getCamcorderProfileParamByName("vid.height",  id, q);
    int audioCodec       = sProfiles->getCamcorderProfileParamByName("aud.codec",   id, q);
    int audioBitRate     = sProfiles->getCamcorderProfileParamByName("aud.bps",     id, q);
    int audioSampleRate  = sProfiles->getCamcorderProfileParamByName("aud.hz",      id, q);
    int audioChannels    = sProfiles->getCamcorderProfileParamByName("aud.ch",      id, q);

    // Check on the values retrieved
    if (duration == -1 || fileFormat == -1 || videoCodec == -1 || audioCodec == -1 ||
@@ -253,17 +253,17 @@ android_media_MediaProfiles_native_get_audio_decoder_type(JNIEnv *env, jobject t
}

static jint
android_media_MediaProfiles_native_get_num_image_encoding_quality_levels(JNIEnv *env, jobject thiz)
android_media_MediaProfiles_native_get_num_image_encoding_quality_levels(JNIEnv *env, jobject thiz, jint cameraId)
{
    LOGV("native_get_num_image_encoding_quality_levels");
    return sProfiles->getImageEncodingQualityLevels().size();
    return sProfiles->getImageEncodingQualityLevels(cameraId).size();
}

static jint
android_media_MediaProfiles_native_get_image_encoding_quality_level(JNIEnv *env, jobject thiz, jint index)
android_media_MediaProfiles_native_get_image_encoding_quality_level(JNIEnv *env, jobject thiz, jint cameraId, jint index)
{
    LOGV("native_get_image_encoding_quality_level");
    Vector<int> levels = sProfiles->getImageEncodingQualityLevels();
    Vector<int> levels = sProfiles->getImageEncodingQualityLevels(cameraId);
    if (index < 0 || index >= levels.size()) {
        jniThrowException(env, "java/lang/IllegalArgumentException", "out of array boundary");
        return -1;
@@ -287,7 +287,7 @@ static JNINativeMethod gMethodsForEncoderCapabilitiesClass[] = {

static JNINativeMethod gMethodsForCamcorderProfileClass[] = {
    {"native_init",                            "()V",                    (void *)android_media_MediaProfiles_native_init},
    {"native_get_camcorder_profile",           "(I)Landroid/media/CamcorderProfile;",
    {"native_get_camcorder_profile",           "(II)Landroid/media/CamcorderProfile;",
                                                                         (void *)android_media_MediaProfiles_native_get_camcorder_profile},
};

@@ -302,8 +302,8 @@ static JNINativeMethod gMethodsForDecoderCapabilitiesClass[] = {
static JNINativeMethod gMethodsForCameraProfileClass[] = {
    {"native_init",                            "()V",                    (void *)android_media_MediaProfiles_native_init},
    {"native_get_num_image_encoding_quality_levels",
                                               "()I",                    (void *)android_media_MediaProfiles_native_get_num_image_encoding_quality_levels},
    {"native_get_image_encoding_quality_level","(I)I",                   (void *)android_media_MediaProfiles_native_get_image_encoding_quality_level},
                                               "(I)I",                   (void *)android_media_MediaProfiles_native_get_num_image_encoding_quality_levels},
    {"native_get_image_encoding_quality_level","(II)I",                   (void *)android_media_MediaProfiles_native_get_image_encoding_quality_level},
};

static const char* const kEncoderCapabilitiesClassPathName = "android/media/EncoderCapabilities";
Loading