DreamCamera2 common preview questions modification scheme
Like collection
FAQ number
FAQ202072398
creator
tianfu.qiu
Release time
2021-08-09 09:53:39
Product:
SPCSS_SC9863A,SPCSS_SC9863A_ZTE,SPCSS_UMS312,SPCSS_UMS512
Component:
02-Camera-APP
Chip:
SC7731E,SC9820E,SC9863A,UMS312,UMS512
keyword
Camera App
[QUESTION]
DreamCamera2 common preview questions
[ANSWER]
DreamCamera2 app FAQ modification scheme
DreamCamera2 APP layer preview common problems include preview stretch, unclear preview, preview black edge, etc. This paper mainly summarizes the modification schemes for common customer problems.
1.1 introduction to common dimensions
DreamCamera2 preview related dimensions include picture size, preview size and preview box size.
1.1.1 picture size / video size
Picture size and video size are the formats set in DreamCamera2 APP, as shown in Figure 1.1 and Figure 1.2.
Figure 1.1 picture size Figure 1.2 video size
1.1.2 preview dimensions
Preview size PreviewSize. Incorrect PreviewSize setting will cause preview stretching problems. In Android 10, the preview size settings of video and photography are implemented in PhotoModule.java and VideoModule.java respectively.
File reference path:
① Photo: sprdroid10_trunk_19c/vendor/sprd/platform/packages/apps/DreamCamera2/src/com/android/camera/PhotoModule.java
// Set a preview size that is closest to the viewfinder height and has // the right aspect ratio. List<Size> sizes = Size.convert(mCameraCapabilities .getSupportedPreviewSizes()); Size optimalSize = CameraUtil.getOptimalPreviewSize(sizes, (double) pictureSize.width() / pictureSize.height()); //Find the appropriate preview size based on the photo size and screen size Size original = new Size(mCameraSettings.getCurrentPreviewSize());//Current pre
// int currentModuleId = mActivity.getCurrentModuleIndex();
// Log.d(TAG,"qtf_currentModuleId: " + currentModuleId);
if (optimalSize != null && !optimalSize.equals(original)) { Log.i(TAG, "setting preview size. optimal: " + optimalSize + "original: " + original); mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize()); //Set Photo preview size }
Figure 1.3 photo preview size setting position
② Video: sprdroid10_trunk_19c/vendor/sprd/platform/packages/apps/DreamCamera2/src/com/android/camera/VideoModule.java
protected void updateDesiredPreviewSize() {
if (mCameraDevice == null) {
return;
}
mCameraSettings = mCameraDevice.getSettings(); desiredPreviewSize = getDesiredPreviewSize(mCameraCapabilities, //Get the right video size mProfile, mUI.getPreviewScreenSize()); mDesiredPreviewWidth = desiredPreviewSize.x; mDesiredPreviewHeight = desiredPreviewSize.y; mUI.setPreviewSize(mDesiredPreviewWidth, mDesiredPreviewHeight); //Set video preview size if (isSlowMotionOn() && mActivity.getCameraAppUI().getSurfaceHolder() != null) { mActivity.getCameraAppUI().getSurfaceHolder().setFixedSize(mDesiredPreviewWidth, mDesiredPreviewHeight); } Log.v(TAG, "Updated DesiredPreview=" + mDesiredPreviewWidth + "x" + mDesiredPreviewHeight);
}
Figure 1.4 video preview size setting
It is worth noting that the preview size of each photo or video is calculated. The photo preview size is calculated by getOptimalPreviewSize. The obtained preview size can be compatible with the screen size and photo size to ensure that the screen is covered as much as possible without stretching the photo; Similarly, the final calculation method of video size is also calculated by getOptimalPreviewSize.
1.1.2.1 photo preview size setting
The following is an example of a photo preview size modification scheme. In order to improve the definition of preview, different preview sizes are set for different photo sizes taken before and after.
— a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -4996,7 +4996,28 @@ public class PhotoModule extends CameraModule implements PhotoController,
if (optimalSize != null && !optimalSize.equals(original)) { Log.i(TAG, "setting preview size. optimal: " + optimalSize + "original: " + original);
-
mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize());
-
//mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize());
-
float pictureRatio = (float)pictureSize.width() / (float)pictureSize.height();
-
if(DreamUtil.getRightCamera(mCameraId) == DreamUtil.BACK_CAMERA){
-
if(pictureRatio == (4f/3f)){
-
optimalSize = new Size(1280, 960);
-
mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize());
-
}else if(pictureRatio == (1280f / 720f)){
-
optimalSize = new Size(1280, 720);
-
mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize());
-
}else if(pictureRatio == (1920f / 1088f)){
-
optimalSize = new Size(1920, 1088);
-
mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize());
-
}else if(pictureRatio == (864f / 480f)){
-
mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize());
-
}
-
}else if(DreamUtil.getRightCamera(mCameraId) == DreamUtil.FRONT_CAMERA){
-
if(pictureRatio == (4f/3f)){
-
optimalSize = new Size(960, 720);
-
mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize());
-
}else if(pictureRatio == (1280f / 720f) || pictureRatio == (640f / 360f)){
-
optimalSize = new Size(1280, 720);
-
mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize());
-
}else if(pictureRatio == (720f / 544f) || pictureRatio == (864f / 480f)){
-
mCameraSettings.setPreviewSize(optimalSize.toPortabilitySize());
-
}
-
} }
1.1.2.2 video preview size setting
The following is an example of video preview size modification scheme. In order to improve the definition of preview, different preview sizes are set for different video sizes.
— a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -1694,8 +1694,19 @@ public class VideoModule extends CameraModule implements
desiredPreviewSize = getDesiredPreviewSize(mCameraCapabilities, mProfile, mUI.getPreviewScreenSize());
-
mDesiredPreviewWidth = desiredPreviewSize.x;
-
mDesiredPreviewHeight = desiredPreviewSize.y;
-
// mDesiredPreviewWidth = desiredPreviewSize.x;
-
// mDesiredPreviewHeight = desiredPreviewSize.y;
-
int videoFrameResolution = mProfile.videoFrameWidth * mProfile.videoFrameHeight;
-
if(videoFrameResolution == (1280 * 720)){
-
mDesiredPreviewWidth = 1280;
-
mDesiredPreviewHeight = 720;
-
}else if (videoFrameResolution == (720 * 480)){
-
mDesiredPreviewWidth = 720;
-
mDesiredPreviewHeight = 480;
-
}else if (videoFrameResolution == (352 * 288)){
-
mDesiredPreviewWidth = 352;
-
mDesiredPreviewHeight = 288;
-
} mUI.setPreviewSize(mDesiredPreviewWidth, mDesiredPreviewHeight); Log.v(TAG, "Updated DesiredPreview=" + mDesiredPreviewWidth + "x"
1.1.2.3 bottom hal size
It is worth noting that:
① The preview size set in 1.1.2.1 and 1.1.2.2 must be supported by the bottom hal. That is, the preview size must exist in the bottom layer (hal layer) before the preview size can be set in the upper layer, otherwise an error that cannot be previewed will appear;
② In general, it is not recommended to modify the preview size without problems such as preview stretching and unclear.
The bottom layer (HAL layer) sets the preview size file (Android8, 9, 10) to SprdCamera3Setting.cpp (reference path: sprdroid10_trunk_19c/vendor/sprd/modules/libcamera/hal3_2v6/SprdCamera3Setting.cpp)
Modify location: stream_info [] array
// initStaticParametersforScalerInfo may be change min_duration and
// stall_duration
const cam_stream_info_t stream_info[] = {
{{9216, 6912}, 41666666L, 41666666L}, /* 64M */
{{6528, 4896}, 41666666L, 41666666L},
...
{{2560, 1440}, 33331760L, 33331760L},
{{2448, 2448}, 33331760L, 33331760L},
{{2320, 1740}, 33331760L, 33331760L},
{{2304, 1728}, 33331760L, 33331760L}, // L5Pro,4in1 binning size
...
{{1920, HEIGHT_2M}, 33331760L, 33331760L},
{{1920, 896}, 33331760L, 33331760L},
...
{{176, 144}, 33331760L, 33331760L}};
Figure 1.5 stream_info [] array
The preview size and picture size of the upper layer are from stream_ Read from info [] array
1.1.3 preview box size
The preview box size is also called preview area size (PreviewRect). Incorrect setting of the preview box will lead to preview black edges and stretching problems. The size of the preview box in DreamCamera2 is calculated based on, and the aspect ratio of the two is basically the same.
In Android 8, 9 and 10, the file for setting the preview box size in the app layer of DreamCamera2 is dreamcapturelayouthelper.java (reference path: sprdrid10_trunk_19c / vendor / SPRD / platform / packages / apps / DreamCamera2 / SRC / COM / dream / camera / UI / dreamcapturelayouthelper. Java)
The preview area in DreamCaptureLayoutHelper.java contains the settings of the preview area in Photo and Video modes. The size setting of the camera preview area is essentially distinguished by the aspect ratio and screen aspect ratio of the picture / Video. For simple description, the aspect ratio of a picture / Video is uniformly abbreviated as the aspect ratio of a picture. The setting idea is shown in Figure 1.6.
Figure 1.6 idea of preview area setting
In DreamCaptureLayoutHelper.java, the specific preview area settings are shown in Figure 1.7.
@Override protected PositionConfiguration getPositionConfiguration(int width, int height, float previewAspectRatio, int rotation) { ................. /***Preview scale = = 0, during initialization***/ if (previewAspectRatio == TextureViewHelper.MATCH_SCREEN) { config.mPreviewRect.set(0, 0, width, height);/***Set preview box size***/ } else { .................. /***Preview proportion > Screen proportion (generally screen aspect ratio < 16 / 9)***/ if (remainingSpaceAlongLongerEdge <= 0) { if (landscape) { /***Apply the horizontal screen to set the preview box size***/ config.mPreviewRect.set(0, height / 2 - previewShorterEdge / 2, previewLongerEdge,height / 2 + previewShorterEdge / 2); } else { /***Apply the vertical screen and set the preview box size***/ config.mPreviewRect.set(width / 2 - previewShorterEdge / 2, 0, width / 2 + previewShorterEdge / 2, previewLongerEdge); } /******Preview ratio > 14:9 (16:9 photos, 720p, 1080p videos, etc.) * * * ******/ } else if (previewAspectRatio > 14f / 9f) { // If the preview aspect ratio is large enough, simply offset the // preview to the bottom/right. barSize = bottomHeight - slideHeight; previewShorterEdge = shorterEdge; previewLongerEdge = shorterEdge * previewAspectRatio; config.mBottomBarOverlay = true; if (landscape) {/*****Apply the horizontal screen to set the preview box size***/ config.mPreviewRect.set(0, topHeight, previewLongerEdge, previewShorterEdge + topHeight); } else {/***Apply the vertical screen and set the preview box size***/ config.mPreviewRect.set(0, topHeight, previewShorterEdge, previewLongerEdge + topHeight); } /***Preview ratio is less than 14:9 (generally 4:3,CIF video format and other picture sizes)***/ } else { .................. if (landscape) { /*****Apply the horizontal screen to set the preview box size***/ config.mPreviewRect.set(topHeight, 0, topHeight + previewLongerEdge, previewShorterEdge); } else { /***Apply the vertical screen and set the preview box size***/ config.mPreviewRect.set(0, topHeight, previewShorterEdge, topHeight + previewLongerEdge); } } } round(config.mBottomBarRect); round(config.mPreviewRect); return config; }
Figure 1.7 modification position of preview area
Preview locale resolution:
As shown in Figure 1.6 and 1.7:
① When the aspect ratio of preview = 0, set the preview size to the screen size;
② When the preview aspect ratio ≠ screen aspect ratio, it is divided into picture or video aspect ratio > screen aspect ratio and picture or video aspect ratio less than screen aspect ratio;
③ When the preview aspect ratio > screen aspect ratio, take the long side of the screen as the long side of the preview box, and the preview short side = the long side of the screen × Proportion of pictures or videos;
④ When the preview aspect ratio is less than the screen aspect ratio, the short side of the screen is the long side of the preview box, and the preview long side = the short side of the screen / picture or video ratio;
⑤ When the preview aspect ratio is less than the screen aspect ratio, the preview box size setting under different picture or video proportion is distinguished by 14f / 9f. For example, the picture or video format of 16:9 is set when the preview scale is > 14f / 9f; 4: The picture or video format of 3 is set when the preview scale is less than 14f / 9f.
1.2 solutions to common problems
Common preview problems include preview stretch, unclear preview, preview black edge, etc. The size of the preview box is calculated from the preview size. For stretching and black edge problems, you can modify both the preview size and the preview box size. For a specific format screen, you can also modify the picture size to solve this problem.
1.2.1 preview stretch issues
The essence of preview stretching is that the picture scale is inconsistent with the preview / preview box scale. Generally, the picture scale cannot be modified. The solution is to modify the preview / preview box scale to solve this problem. For specific pictures, please refer to sections 1.1.2 and 1.1.3 of this document for modifying the preview / preview box size.
1.2.2 unclear Preview
The preview is not clear. On the premise that the tuning effect parameters are set correctly, the app layer can consider increasing the preview size and appropriately increasing the preview frame rate to solve this problem. For the modification of preview size, refer to chapter 1.1.2 of this document.
1.2.3 preview black edge problem
The black edge here refers to the left and right black edges of the preview box. The essence of the preview black edge is that the height width ratio of the preview area is greater than the height width ratio of the screen size, resulting in the screen and the preview box do not coincide, and the left and right of the preview area can not fill the screen. At this time, the black edge problem will occur. Preview the black edge phenomenon as shown in Figure 1.8.
Figure 1.8 Preview black edge phenomenon
The black edge problem can be solved by modifying the preview / preview box size. Refer to chapters 1.1.2 and 1.1.3 of this article.
1.2.4 modify picture / video size
For a specific scale screen, sometimes it is necessary to add a picture size, such as for a screen with an aspect ratio of 8:5; In order to improve the video quality, it is sometimes necessary to increase the video size. This chapter mainly introduces the modification of picture size and video size in DreamCamera2.
1.2.4.1 modify picture size
To modify the picture size, you need to modify the hal layer and the application layer respectively. The following is the operation of increasing the picture size of 8:5.
1.2.4.1.1 bottom layer (hal) modification
For Android 8, 9, 10, the picture size of hal layer is modified in SprdCamera3Setting.cpp file. The picture size, preview size and thumbnail size need to be added in hal layer.
File reference path: sprdroid10_trunk_19c/vendor/sprd/modules/libcamera/hal3_2v6/SprdCamera3Setting.cpp
Add the modification scheme of 8:5 picture size:
const cam_stream_info_t stream_info[] = {
...
{{3264, 2448}, 33331760L, 33331760L},
{{3264, 1836}, 33331760L, 33331760L},
{{2592, 1944}, 33331760L, 33331760L},
-
{{2592, 1620}, 33331760L, 33331760L}, //for capture (picture size)
{{2560, 1920}, 33331760L, 33331760L},
{{1920, HEIGHT_2M}, 33331760L, 33331760L},
{{1600, 1200}, 33331760L, 33331760L},
{{1280, 960}, 33331760L, 33331760L},
-
{{1280, 800}, 33331760L, 33331760L}, ///for capture /for preview
{{1280, 720}, 33331760L, 33331760L},
{{960, 720}, 33331760L, 33331760L},
...
{{480, 480}, 33331760L, 33331760L},
{{352, 288}, 33331760L, 33331760L},
{{320, 240}, 33331760L, 33331760L},
-
{{320, 200}, 33331760L, 33331760L}, //for thumbnail
{{288, 352}, 33331760L, 33331760L},
{{240, 320}, 33331760L, 33331760L},
{{176, 144}, 33331760L, 33331760L}};
As shown in the above modification, when adding a picture size, a small size picture is selected in the thumbnail app, so it is necessary to set an 8:5 small size {320, 200}; In the preview app, the medium size is generally selected. Here, {1280, 800} is set as the preview size; When {1280, 800} and {2592, 1620} are selected in the capture app, two groups of 8:5 picture sizes of {1280, 800} and {2592, 1620} will appear in the app application interface, as shown in Figure 1.9.
Figure 1.9 add 8:5 preview size
1.2.4.1.2 application layer (app) modification
The picture size modification of DreamCamera2 is completed in the ResolutionUtil.java file
Resolutionutil.java file reference path: sprdroid10_trunk_19c/vendor/sprd/platform/packages/apps/DreamCamera2/src/com/android/camera/settings/ResolutionUtil.java)
Add 8:5 picture size and delete the modification scheme of 4:3 picture size:
— a/src/com/android/camera/settings/ResolutionUtil.java
+++ b/src/com/android/camera/settings/ResolutionUtil.java
@@ -67,11 +67,12 @@ public class ResolutionUtil {
* We will also take the maximum supported resolution for full sensor image. */ private static Float[] sDesiredAspectRatios = {
-
16.0f / 9.0f, 4.0f / 3.0f
-
16.0f / 9.0f, 8.0f / 5.0f
};
private static Size[] sDesiredAspectRatioSizes = {
-
new Size(16, 9), new Size(4, 3)
-
new Size(16, 9), new Size(8, 5)
};
@@ -241,6 +241,7 @@ public class ResolutionUtil {
for (Size size : sizes) { Float aspectRatio = (float) size.getWidth() / (float) size.getHeight();
-
if (aspectRatio < 1.6) continue; //4: 3. The aspect ratio of the picture format = = 1.33 < 1.6, so it is removed here // If this aspect ratio is close to a desired Aspect Ratio, // fuzz it so that they are bucketed together aspectRatio = fuzzAspectRatio(aspectRatio);
1.2.4.2 modify video size
The picture size of DreamCamera2 is modified in media_profiles.xml file (file reference path: sprdroid10_trunk_19c/device/sprd/sharkl5Pro/common/media_profiles.xml)
The following is the modification scheme for adding h264 video format 480p video.
<EncoderProfile quality="timelapsecif" fileFormat="mp4" duration="60"> <Video codec="m4v" bitRate="512000" width="352" height="288" frameRate="30" /> <!-- audio setting is ignored --> <Audio codec="amrnb" bitRate="12200" sampleRate="8000" channels="1" /> </EncoderProfile>
-
<EncoderProfile quality="480p" fileFormat="mp4" duration="60">
-
<Video codec="h264"
-
bitRate="4000000"
-
width="640"
-
height="480"
-
frameRate="30" />
-
<Audio codec="aac"
-
bitRate="64000"
-
sampleRate="44100"
-
channels="1" />
-
</EncoderProfile>
-
<EncoderProfile quality="timelapse480p" fileFormat="mp4" duration="60">
-
<Video codec="h264"
-
bitRate="4000000"
-
width="640"
-
height="480"
-
frameRate="30" />
-
<!-- audio setting is ignored -->
-
<Audio codec="aac"
-
bitRate="64000"
-
sampleRate="44100"
-
channels="1" /> </EncoderProfile> <ImageEncoding quality="95" /> <ImageEncoding quality="80" /> <ImageEncoding quality="70" /> <ImageDecoding memCap="20000000" />
It should be noted that:
① The set video size must be supported by the sprdcamera3setting.cpp file of Hal layer. The reference path of sprdcamera3setting.cpp is sprdroid10_trunk_19c/vendor/sprd/modules/libcamera/hal3_2v6/SprdCamera3Setting.cpp
② The sensor must support the set video size. For example, the sensor size is 2 million (12 million) × 1600), set 1080p (1920 × 1080) will go wrong because 1200 × 1600 = 1920000 < 1920 × 1080 = 2073600
③ At present, the video format settings supported by the platform include 1080p (1920) × 1080),720p(1080 × 720),480p(720 × 480),CIF(352 × 288).
④ Modified adaptation