use of net.sourceforge.opencamera.Preview.VideoProfile in project OpenCamera by ageback.
the class MainActivityTest method testPreviewSizeWYSIWYG.
/* Ensures that preview resolution is set as expected in WYSIWYG mode
*/
public void testPreviewSizeWYSIWYG() {
Log.d(TAG, "testPreviewSizeWYSIWYG");
setToDefault();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mActivity);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PreferenceKeys.PreviewSizePreferenceKey, "preference_preview_size_wysiwyg");
editor.apply();
updateForSettings();
Point display_size = new Point();
{
Display display = mActivity.getWindowManager().getDefaultDisplay();
display.getSize(display_size);
Log.d(TAG, "display_size: " + display_size.x + " x " + display_size.y);
}
CameraController.Size picture_size = mPreview.getCameraController().getPictureSize();
CameraController.Size preview_size = mPreview.getCameraController().getPreviewSize();
// double targetRatio = mPreview.getTargetRatioForPreview(display_size);
double targetRatio = mPreview.getTargetRatio();
double expTargetRatio = ((double) picture_size.width) / (double) picture_size.height;
double previewRatio = ((double) preview_size.width) / (double) preview_size.height;
assertTrue(Math.abs(targetRatio - expTargetRatio) <= 1.0e-5);
assertTrue(Math.abs(previewRatio - expTargetRatio) <= 1.0e-5);
checkOptimalPreviewSize();
checkSquareAspectRatio();
Log.d(TAG, "switch to video");
View switchVideoButton = mActivity.findViewById(net.sourceforge.opencamera.R.id.switch_video);
clickView(switchVideoButton);
waitUntilCameraOpened();
assertTrue(mPreview.isVideo());
VideoProfile profile = mPreview.getVideoProfile();
CameraController.Size video_preview_size = mPreview.getCameraController().getPreviewSize();
// targetRatio = mPreview.getTargetRatioForPreview(display_size);
targetRatio = mPreview.getTargetRatio();
expTargetRatio = ((double) profile.videoFrameWidth) / (double) profile.videoFrameHeight;
previewRatio = ((double) video_preview_size.width) / (double) video_preview_size.height;
assertTrue(Math.abs(targetRatio - expTargetRatio) <= 1.0e-5);
assertTrue(Math.abs(previewRatio - expTargetRatio) <= 1.0e-5);
checkOptimalPreviewSize();
checkSquareAspectRatio();
checkOptimalVideoPictureSize(expTargetRatio);
clickView(switchVideoButton);
waitUntilCameraOpened();
assertTrue(!mPreview.isVideo());
CameraController.Size new_picture_size = mPreview.getCameraController().getPictureSize();
CameraController.Size new_preview_size = mPreview.getCameraController().getPreviewSize();
Log.d(TAG, "picture_size: " + picture_size.width + " x " + picture_size.height);
Log.d(TAG, "new_picture_size: " + new_picture_size.width + " x " + new_picture_size.height);
Log.d(TAG, "preview_size: " + preview_size.width + " x " + preview_size.height);
Log.d(TAG, "new_preview_size: " + new_preview_size.width + " x " + new_preview_size.height);
assertTrue(new_picture_size.equals(picture_size));
assertTrue(new_preview_size.equals(preview_size));
if (mPreview.getCameraControllerManager().getNumberOfCameras() > 1) {
Log.d(TAG, "switch camera");
View switchCameraButton = mActivity.findViewById(net.sourceforge.opencamera.R.id.switch_camera);
clickView(switchCameraButton);
waitUntilCameraOpened();
picture_size = mPreview.getCameraController().getPictureSize();
preview_size = mPreview.getCameraController().getPreviewSize();
// targetRatio = mPreview.getTargetRatioForPreview(display_size);
targetRatio = mPreview.getTargetRatio();
expTargetRatio = ((double) picture_size.width) / (double) picture_size.height;
previewRatio = ((double) preview_size.width) / (double) preview_size.height;
assertTrue(Math.abs(targetRatio - expTargetRatio) <= 1.0e-5);
assertTrue(Math.abs(previewRatio - expTargetRatio) <= 1.0e-5);
checkOptimalPreviewSize();
checkSquareAspectRatio();
Log.d(TAG, "switch to video again");
clickView(switchVideoButton);
waitUntilCameraOpened();
assertTrue(mPreview.isVideo());
profile = mPreview.getVideoProfile();
video_preview_size = mPreview.getCameraController().getPreviewSize();
// targetRatio = mPreview.getTargetRatioForPreview(display_size);
targetRatio = mPreview.getTargetRatio();
expTargetRatio = ((double) profile.videoFrameWidth) / (double) profile.videoFrameHeight;
previewRatio = ((double) video_preview_size.width) / (double) video_preview_size.height;
assertTrue(Math.abs(targetRatio - expTargetRatio) <= 1.0e-5);
assertTrue(Math.abs(previewRatio - expTargetRatio) <= 1.0e-5);
checkOptimalPreviewSize();
checkSquareAspectRatio();
checkOptimalVideoPictureSize(expTargetRatio);
clickView(switchVideoButton);
waitUntilCameraOpened();
assertTrue(!mPreview.isVideo());
new_picture_size = mPreview.getCameraController().getPictureSize();
new_preview_size = mPreview.getCameraController().getPreviewSize();
assertTrue(new_picture_size.equals(picture_size));
assertTrue(new_preview_size.equals(preview_size));
}
}
use of net.sourceforge.opencamera.Preview.VideoProfile in project OpenCamera by ageback.
the class MainActivity method showPhotoVideoToast.
/**
* Displays a toast with information about the current preferences.
* If always_show is true, the toast is always displayed; otherwise, we only display
* a toast if it's important to notify the user (i.e., unusual non-default settings are
* set). We want a balance between not pestering the user too much, whilst also reminding
* them if certain settings are on.
*/
private void showPhotoVideoToast(boolean always_show) {
if (MyDebug.LOG) {
Log.d(TAG, "showPhotoVideoToast");
Log.d(TAG, "always_show? " + always_show);
}
CameraController camera_controller = preview.getCameraController();
if (camera_controller == null || this.camera_in_background) {
if (MyDebug.LOG)
Log.d(TAG, "camera not open or in background");
return;
}
String toast_string;
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean simple = true;
boolean video_high_speed = preview.isVideoHighSpeed();
if (preview.isVideo()) {
VideoProfile profile = preview.getVideoProfile();
String bitrate_string;
if (profile.videoBitRate >= 10000000)
bitrate_string = profile.videoBitRate / 1000000 + "Mbps";
else if (profile.videoBitRate >= 10000)
bitrate_string = profile.videoBitRate / 1000 + "Kbps";
else
bitrate_string = profile.videoBitRate + "bps";
toast_string = getResources().getString(R.string.video) + ": " + profile.videoFrameWidth + "x" + profile.videoFrameHeight + ", " + profile.videoFrameRate + getResources().getString(R.string.fps) + (video_high_speed ? " [" + getResources().getString(R.string.high_speed) + "]" : "") + ", " + bitrate_string;
String fps_value = applicationInterface.getVideoFPSPref();
if (!fps_value.equals("default") || video_high_speed) {
simple = false;
}
boolean record_audio = applicationInterface.getRecordAudioPref();
if (!record_audio) {
toast_string += "\n" + getResources().getString(R.string.audio_disabled);
simple = false;
}
String max_duration_value = sharedPreferences.getString(PreferenceKeys.getVideoMaxDurationPreferenceKey(), "0");
if (max_duration_value.length() > 0 && !max_duration_value.equals("0")) {
String[] entries_array = getResources().getStringArray(R.array.preference_video_max_duration_entries);
String[] values_array = getResources().getStringArray(R.array.preference_video_max_duration_values);
int index = Arrays.asList(values_array).indexOf(max_duration_value);
if (index != -1) {
// just in case!
String entry = entries_array[index];
toast_string += "\n" + getResources().getString(R.string.max_duration) + ": " + entry;
simple = false;
}
}
long max_filesize = applicationInterface.getVideoMaxFileSizeUserPref();
if (max_filesize != 0) {
long max_filesize_mb = max_filesize / (1024 * 1024);
toast_string += "\n" + getResources().getString(R.string.max_filesize) + ": " + max_filesize_mb + getResources().getString(R.string.mb_abbreviation);
simple = false;
}
if (applicationInterface.getVideoFlashPref() && preview.supportsFlash()) {
toast_string += "\n" + getResources().getString(R.string.preference_video_flash);
simple = false;
}
} else {
toast_string = getResources().getString(R.string.photo);
CameraController.Size current_size = preview.getCurrentPictureSize();
toast_string += " " + current_size.width + "x" + current_size.height;
if (preview.supportsFocus() && preview.getSupportedFocusValues().size() > 1) {
String focus_value = preview.getCurrentFocusValue();
if (focus_value != null && !focus_value.equals("focus_mode_auto") && !focus_value.equals("focus_mode_continuous_picture")) {
String focus_entry = preview.findFocusEntryForValue(focus_value);
if (focus_entry != null) {
toast_string += "\n" + focus_entry;
}
}
}
if (applicationInterface.getAutoStabilisePref()) {
// important as users are sometimes confused at the behaviour if they don't realise the option is on
toast_string += "\n" + getResources().getString(R.string.preference_auto_stabilise);
simple = false;
}
String photo_mode_string = null;
MyApplicationInterface.PhotoMode photo_mode = applicationInterface.getPhotoMode();
if (photo_mode == MyApplicationInterface.PhotoMode.DRO) {
photo_mode_string = getResources().getString(R.string.photo_mode_dro);
} else if (photo_mode == MyApplicationInterface.PhotoMode.HDR) {
photo_mode_string = getResources().getString(R.string.photo_mode_hdr);
} else if (photo_mode == MyApplicationInterface.PhotoMode.ExpoBracketing) {
photo_mode_string = getResources().getString(R.string.photo_mode_expo_bracketing_full);
} else if (photo_mode == MyApplicationInterface.PhotoMode.FastBurst) {
photo_mode_string = getResources().getString(R.string.photo_mode_fast_burst_full);
int n_images = applicationInterface.getBurstNImages();
photo_mode_string += " (" + n_images + ")";
} else if (photo_mode == MyApplicationInterface.PhotoMode.NoiseReduction) {
photo_mode_string = getResources().getString(R.string.photo_mode_noise_reduction_full);
}
if (photo_mode_string != null) {
toast_string += "\n" + getResources().getString(R.string.photo_mode) + ": " + photo_mode_string;
simple = false;
}
}
if (applicationInterface.getFaceDetectionPref()) {
// important so that the user realises why touching for focus/metering areas won't work - easy to forget that face detection has been turned on!
toast_string += "\n" + getResources().getString(R.string.preference_face_detection);
simple = false;
}
if (!video_high_speed) {
// manual ISO only supported for high speed video
String iso_value = applicationInterface.getISOPref();
if (!iso_value.equals(CameraController.ISO_DEFAULT)) {
toast_string += "\nISO: " + iso_value;
if (preview.supportsExposureTime()) {
long exposure_time_value = applicationInterface.getExposureTimePref();
toast_string += " " + preview.getExposureTimeString(exposure_time_value);
}
simple = false;
}
int current_exposure = camera_controller.getExposureCompensation();
if (current_exposure != 0) {
toast_string += "\n" + preview.getExposureCompensationString(current_exposure);
simple = false;
}
}
String scene_mode = camera_controller.getSceneMode();
if (scene_mode != null && !scene_mode.equals(CameraController.SCENE_MODE_DEFAULT)) {
toast_string += "\n" + getResources().getString(R.string.scene_mode) + ": " + mainUI.getEntryForSceneMode(scene_mode);
simple = false;
}
String white_balance = camera_controller.getWhiteBalance();
if (white_balance != null && !white_balance.equals(CameraController.WHITE_BALANCE_DEFAULT)) {
toast_string += "\n" + getResources().getString(R.string.white_balance) + ": " + mainUI.getEntryForWhiteBalance(white_balance);
if (white_balance.equals("manual") && preview.supportsWhiteBalanceTemperature()) {
toast_string += " " + camera_controller.getWhiteBalanceTemperature();
}
simple = false;
}
String color_effect = camera_controller.getColorEffect();
if (color_effect != null && !color_effect.equals(CameraController.COLOR_EFFECT_DEFAULT)) {
toast_string += "\n" + getResources().getString(R.string.color_effect) + ": " + mainUI.getEntryForColorEffect(color_effect);
simple = false;
}
String lock_orientation = applicationInterface.getLockOrientationPref();
if (!lock_orientation.equals("none")) {
String[] entries_array = getResources().getStringArray(R.array.preference_lock_orientation_entries);
String[] values_array = getResources().getStringArray(R.array.preference_lock_orientation_values);
int index = Arrays.asList(values_array).indexOf(lock_orientation);
if (index != -1) {
// just in case!
String entry = entries_array[index];
toast_string += "\n" + entry;
simple = false;
}
}
String timer = sharedPreferences.getString(PreferenceKeys.getTimerPreferenceKey(), "0");
if (!timer.equals("0")) {
String[] entries_array = getResources().getStringArray(R.array.preference_timer_entries);
String[] values_array = getResources().getStringArray(R.array.preference_timer_values);
int index = Arrays.asList(values_array).indexOf(timer);
if (index != -1) {
// just in case!
String entry = entries_array[index];
toast_string += "\n" + getResources().getString(R.string.preference_timer) + ": " + entry;
simple = false;
}
}
String repeat = applicationInterface.getRepeatPref();
if (!repeat.equals("1")) {
String[] entries_array = getResources().getStringArray(R.array.preference_burst_mode_entries);
String[] values_array = getResources().getStringArray(R.array.preference_burst_mode_values);
int index = Arrays.asList(values_array).indexOf(repeat);
if (index != -1) {
// just in case!
String entry = entries_array[index];
toast_string += "\n" + getResources().getString(R.string.preference_burst_mode) + ": " + entry;
simple = false;
}
}
if (MyDebug.LOG) {
Log.d(TAG, "toast_string: " + toast_string);
Log.d(TAG, "simple?: " + simple);
}
if (!simple || always_show)
preview.showToast(switch_video_toast, toast_string);
}
use of net.sourceforge.opencamera.Preview.VideoProfile in project OpenCamera by ageback.
the class MainActivity method openSettings.
public void openSettings() {
if (MyDebug.LOG)
Log.d(TAG, "openSettings");
// in theory not needed as we could continue running in the background, but best to be safe
waitUntilImageQueueEmpty();
closePopup();
// best to cancel any timer, in case we take a photo while settings window is open, or when changing settings
preview.cancelTimer();
// similarly cancel the auto-repeat mode!
preview.cancelRepeat();
// important to stop video, as we'll be changing camera parameters when the settings window closes
preview.stopVideo(false);
stopAudioListeners();
Bundle bundle = new Bundle();
bundle.putInt("cameraId", this.preview.getCameraId());
bundle.putInt("nCameras", preview.getCameraControllerManager().getNumberOfCameras());
bundle.putString("camera_api", this.preview.getCameraAPI());
bundle.putBoolean("using_android_l", this.preview.usingCamera2API());
bundle.putBoolean("supports_auto_stabilise", this.supports_auto_stabilise);
bundle.putBoolean("supports_force_video_4k", this.supports_force_video_4k);
bundle.putBoolean("supports_camera2", this.supports_camera2);
bundle.putBoolean("supports_face_detection", this.preview.supportsFaceDetection());
bundle.putBoolean("supports_raw", this.preview.supportsRaw());
bundle.putBoolean("supports_hdr", this.supportsHDR());
bundle.putBoolean("supports_nr", this.supportsNoiseReduction());
bundle.putBoolean("supports_expo_bracketing", this.supportsExpoBracketing());
bundle.putInt("max_expo_bracketing_n_images", this.maxExpoBracketingNImages());
bundle.putBoolean("supports_exposure_compensation", this.preview.supportsExposures());
bundle.putInt("exposure_compensation_min", this.preview.getMinimumExposure());
bundle.putInt("exposure_compensation_max", this.preview.getMaximumExposure());
bundle.putBoolean("supports_iso_range", this.preview.supportsISORange());
bundle.putInt("iso_range_min", this.preview.getMinimumISO());
bundle.putInt("iso_range_max", this.preview.getMaximumISO());
bundle.putBoolean("supports_exposure_time", this.preview.supportsExposureTime());
bundle.putLong("exposure_time_min", this.preview.getMinimumExposureTime());
bundle.putLong("exposure_time_max", this.preview.getMaximumExposureTime());
bundle.putBoolean("supports_white_balance_temperature", this.preview.supportsWhiteBalanceTemperature());
bundle.putInt("white_balance_temperature_min", this.preview.getMinimumWhiteBalanceTemperature());
bundle.putInt("white_balance_temperature_max", this.preview.getMaximumWhiteBalanceTemperature());
bundle.putBoolean("supports_video_stabilization", this.preview.supportsVideoStabilization());
bundle.putBoolean("can_disable_shutter_sound", this.preview.canDisableShutterSound());
putBundleExtra(bundle, "color_effects", this.preview.getSupportedColorEffects());
putBundleExtra(bundle, "scene_modes", this.preview.getSupportedSceneModes());
putBundleExtra(bundle, "white_balances", this.preview.getSupportedWhiteBalances());
putBundleExtra(bundle, "isos", this.preview.getSupportedISOs());
bundle.putString("iso_key", this.preview.getISOKey());
if (this.preview.getCameraController() != null) {
bundle.putString("parameters_string", preview.getCameraController().getParametersString());
}
List<CameraController.Size> preview_sizes = this.preview.getSupportedPreviewSizes();
if (preview_sizes != null) {
int[] widths = new int[preview_sizes.size()];
int[] heights = new int[preview_sizes.size()];
int i = 0;
for (CameraController.Size size : preview_sizes) {
widths[i] = size.width;
heights[i] = size.height;
i++;
}
bundle.putIntArray("preview_widths", widths);
bundle.putIntArray("preview_heights", heights);
}
bundle.putInt("preview_width", preview.getCurrentPreviewSize().width);
bundle.putInt("preview_height", preview.getCurrentPreviewSize().height);
List<CameraController.Size> sizes = this.preview.getSupportedPictureSizes();
if (sizes != null) {
int[] widths = new int[sizes.size()];
int[] heights = new int[sizes.size()];
int i = 0;
for (CameraController.Size size : sizes) {
widths[i] = size.width;
heights[i] = size.height;
i++;
}
bundle.putIntArray("resolution_widths", widths);
bundle.putIntArray("resolution_heights", heights);
}
if (preview.getCurrentPictureSize() != null) {
bundle.putInt("resolution_width", preview.getCurrentPictureSize().width);
bundle.putInt("resolution_height", preview.getCurrentPictureSize().height);
}
if (preview.getVideoQualityHander().getCurrentVideoQuality() != null) {
bundle.putString("current_video_quality", preview.getVideoQualityHander().getCurrentVideoQuality());
}
VideoProfile camcorder_profile = preview.getVideoProfile();
bundle.putInt("video_frame_width", camcorder_profile.videoFrameWidth);
bundle.putInt("video_frame_height", camcorder_profile.videoFrameHeight);
bundle.putInt("video_bit_rate", camcorder_profile.videoBitRate);
bundle.putInt("video_frame_rate", camcorder_profile.videoFrameRate);
List<CameraController.Size> video_sizes = this.preview.getVideoQualityHander().getSupportedVideoSizes();
if (video_sizes != null) {
int[] widths = new int[video_sizes.size()];
int[] heights = new int[video_sizes.size()];
int i = 0;
for (CameraController.Size size : video_sizes) {
widths[i] = size.width;
heights[i] = size.height;
i++;
}
bundle.putIntArray("video_widths", widths);
bundle.putIntArray("video_heights", heights);
}
// set up supported fps values
if (preview.usingCamera2API()) {
// with Camera2, we know what frame rates are supported
int[] candidate_fps = { 15, 24, 25, 30, 60, 96, 100, 120, 240 };
List<Integer> video_fps = new ArrayList<>();
for (int fps : candidate_fps) {
if (this.preview.getVideoQualityHander().videoSupportsFrameRateHighSpeed(fps) || this.preview.getVideoQualityHander().videoSupportsFrameRate(fps)) {
video_fps.add(fps);
}
}
int[] video_fps_array = new int[video_fps.size()];
int i = 0;
for (Integer fps : video_fps) {
video_fps_array[i++] = fps;
}
bundle.putIntArray("video_fps", video_fps_array);
} else {
// with old API, we don't know what frame rates are supported, so we make it up and let the user try
// probably shouldn't allow 120fps, but we did in the past, and there may be some devices where this did work?
int[] video_fps = { 15, 24, 25, 30, 60, 96, 100, 120 };
bundle.putIntArray("video_fps", video_fps);
}
putBundleExtra(bundle, "flash_values", this.preview.getSupportedFlashValues());
putBundleExtra(bundle, "focus_values", this.preview.getSupportedFocusValues());
preferencesListener.startListening();
showPreview(false);
setWindowFlagsForSettings();
MyPreferenceFragment fragment = new MyPreferenceFragment();
fragment.setArguments(bundle);
// use commitAllowingStateLoss() instead of commit(), does to "java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState" crash seen on Google Play
// see http://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-wit
getFragmentManager().beginTransaction().add(android.R.id.content, fragment, "PREFERENCE_FRAGMENT").addToBackStack(null).commitAllowingStateLoss();
}
Aggregations