实现前后Camera 480P 720P 1080P高清视频录像(MTK平台)

Camera AP有定义了低,中,高,精细几种quality。每个quality都有对应的MediaProfile,
MediaProfile里面包涵当前quality的mCameraId, mFileFormat,mVideoCodec,mFrameWidth,mFrameHeight,mFrameRate等信息。
camera启动后会针对每一个quality去加载对应的MediaProfile

流程如下:

Camera线程启动后会去initializeCameraPreferences(),在initializeCameraPreferences()中会根据前后mCameraId去判断每个quality是否有对应的mediaProfile

 if(CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_MTK_LOW)) {
           supported.add(Integer.toString(CamcorderProfile.QUALITY_MTK_LOW));
       }
     if(CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_MTK_HIGH)) {
           supported.add(Integer.toString(CamcorderProfile.QUALITY_MTK_HIGH));
      ...

如果quality有对应的MediaProfile,那么在Camera AP里就会显示这个quality,否则就不会显示出来。
代码路径:packages\apps\Camera\src\com\android\camera\Camera.java
packages\apps\Camera\src\com\android\camera\CameraSettings.java

第二部分:

既然每个quality都有对应的mediaProfile 那怎样才能得到这个Profile呢?

流程如下:

系统调用JNI_OnLoad时会去注册register_android_media_MediaProfiles(), 在register_android_media_MediaProfiles()里会去创建MediaProfiles类的一个具体实例 MediaProfiles::getInstance(), 在得到具体profile对像后,会为这个profile对像添加相关的音视频编码解码属性设定如:createDefaultCamcorderProfiles(profiles),createDefaultVideoEncoders(profiles), createDefaultAudioEncoders(profiles)等.
其中createDefaultCamcorderProfiles(profiles)就是针对不同的Camera AP里的quality添加对应的profile设定.
例如添加前置1080P profile

 // day mode
       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);
       // night mode
       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);

代码路径:frameworks\base\media\jni\android_media_MediaPlayer.cpp
frameworks\base\media\jni\android_media_MediaProfiles.cpp
frameworks\av\media\libmedia\MediaProfiles.cpp

第三部分:

在Video Size里面添加对应quality的resolution

//例如:
        //  Video Size
           FTABLE_CONFIG_AS_TYPE_OF_DEFAULT_VALUES(
           KEY_AS_(MtkCameraParameters::KEY_VIDEO_SIZE),
           SCENE_AS_DEFAULT_SCENE(
           ITEM_AS_DEFAULT_("640x480"),
           ITEM_AS_VALUES_(
              "176x144",       "640x480",
               "1280x720",     "1920x1080",

代码路径:mediatek\custom\common\hal\imgsensor$sensor_mipi_raw\config.ftbl……

你可能感兴趣的:(Android,Camera)