MTK 平台上如何给 camera 添加一种 preview size

时间:2022-05-16 12:08:16

1,首先检查该项目所使用的是哪一颗sensor, 就以OV2659 为例
OV2659 是一颗2M 的摄像头,Sensor 吐出的数据分辨率能达到 1600*1200,肯定是支持 1280*720 的分辨率喽。
那如何通过配置使其能够录制 720P 的视频呢,这个还是需要花费一番功夫的。
ALPS.ICS2.TDD.MP.V1.2_TD_20121019\mediatek\custom\common\hal\imgsensor\ov2659_yuv\cfg_ftbl_ov2659_yuv.h
在该文件中检查是否有设置 PREVIEW_SIZE_1280_720,如没有则加上

//  Preview Size
    CONFIG_FEATURE_SI(FID_PREVIEW_SIZE, 
        BY_DEFAULT(PREVIEW_SIZE_320_240), 
        PREVIEW_SIZE_176_144, PREVIEW_SIZE_320_240, 
        PREVIEW_SIZE_352_288, PREVIEW_SIZE_640_480, 
        PREVIEW_SIZE_720_480, PREVIEW_SIZE_1280_720
    )
 
2,检查是否有创建 MTKProfile,具体在下面这个 MediaProfiles.cpp 文件中操作
/trunk/ALPS.ICS2.TDD.MP.V1.2_TD_20121019/frameworks/base/media/libmedia/MediaProfiles.cpp
看 /*static*/ MediaProfiles::CamcorderProfile*
MediaProfiles::createMTKCamcorderProfile(camcorder_quality quality, camcorder_mode CamMode, camera_id CamId) 函数

// Setting for VIDEO Profile
 switch(quality)
 {
  case CAMCORDER_QUALITY_MTK_LOW:
  case CAMCORDER_QUALITY_MTK_NIGHT_LOW:
  case CAMCORDER_QUALITY_MTK_TIME_LAPSE_LOW:
  case CAMCORDER_QUALITY_MTK_TIME_LAPSE_NIGHT_LOW:
             videoCodec = new MediaProfiles::VideoCodec(VIDEO_ENCODER_MPEG_4_SP, 12500*1000/CamMode, 1280, 720, 30/CamMode);
    ……
    
中给其加上 Profiles

3,仍旧是 MediaProfiles.cpp 文件中操作
/*static*/ void
MediaProfiles::createDefaultCamcorderProfiles(MediaProfiles *profiles) 该函数中也需要加上相应的 Profiles

// front fine camcorder profiles.
    MediaProfiles::CamcorderProfile *FrontFineProfile =
            createMTKCamcorderProfile(CAMCORDER_QUALITY_MTK_FINE, CAMCORDER_DAY_MODE, FRONT_CAMERA);
 MediaProfiles::CamcorderProfile *FrontFineSpecificProfile =
      createMTKCamcorderProfile(CAMCORDER_QUALITY_MTK_FINE, CAMCORDER_DAY_MODE, FRONT_CAMERA);
    profiles->mCamcorderProfiles.add(FrontFineProfile);
    profiles->mCamcorderProfiles.add(FrontFineSpecificProfile);
 
 
 // front night fine camcorder profiles.
 MediaProfiles::CamcorderProfile *FrontNightFineProfile =
   createMTKCamcorderProfile(CAMCORDER_QUALITY_MTK_NIGHT_FINE, CAMCORDER_NIGHT_MODE, FRONT_CAMERA);
 MediaProfiles::CamcorderProfile *FrontNightFineSpecificProfile =
   createMTKCamcorderProfile(CAMCORDER_QUALITY_MTK_NIGHT_FINE, CAMCORDER_NIGHT_MODE, FRONT_CAMERA);
 profiles->mCamcorderProfiles.add(FrontNightFineProfile);
 profiles->mCamcorderProfiles.add(FrontNightFineSpecificProfile); 
 
 分别给其加上 front fine camcorder profiles 和 front night fine camcorder profiles
 
4, app 层在 CameraSettings.java 的 getMTKSupportedVideoQuality 函数中就可以通过 log 输出其分别支持哪些分辨率的录像了

private ArrayList<String> getMTKSupportedVideoQuality() {
        ArrayList<String> supported = new ArrayList<String>();
        // Check for supported quality
        if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_480P)) {
            supported.add(Integer.toString(CamcorderProfile.QUALITY_480P));
        }
        if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_1080P)) {
            supported.add(Integer.toString(CamcorderProfile.QUALITY_1080P));
        }
        
        if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_MTK_LOW)) {
            supported.add(Integer.toString(CamcorderProfile.QUALITY_MTK_LOW));
        }
        if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_MTK_MEDIUM)) {
            supported.add(Integer.toString(CamcorderProfile.QUALITY_MTK_MEDIUM));
        }
        if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_MTK_HIGH)) {
            supported.add(Integer.toString(CamcorderProfile.QUALITY_MTK_HIGH));
        }
        
        for(int i = 0 ; i < supported.size(); i++) 
         Log.e(TAG,"--------------getMTKSupportedVideoQuality----------i="+supported.get(i));
        return supported; 
    }

完了直接编译 ./mk -t mm framework/base/av/media/libmedia 即可,会得到一个 libmedia.so 库文件,push 到手机端 system/lib 目录下

reboot !

而 PreviewSizes 则可以通过下面这条 log 输出,具体可以添加到 VideoCamera.java 的 startPreview 函数中。
 
     List<Size> sizes1 = mParameters.getSupportedPreviewSizes();
        for (int i = 0; i < sizes1.size(); i++) {
            Log.d(TAG, "SupportedPreviewSizes : " + sizes1.get(i).width + "x" + sizes1.get(i).height);
        }

一般 CamcorderProfile.QUALITY_MTK_LOW 为 176X144
      CamcorderProfile.QUALITY_MTK_MEDIUM 为 480X320
   CamcorderProfile.QUALITY_MTK_HIGH 为 640X480
   CamcorderProfile.QUALITY_MTK_FINE 为 1280X720 
   
  对应的 enum 值分别为 8,9,10,11

转自:http://blog.csdn.net/fulinwsuafcie/article/details/8351537