Skip to content

Commit

Permalink
Merge pull request #660 from OpenHD/consti-dev
Browse files Browse the repository at this point in the history
update default resolution(s)
  • Loading branch information
Consti10 authored Feb 16, 2024
2 parents f8c6b95 + 53655e1 commit c04802f
Showing 1 changed file with 109 additions and 55 deletions.
164 changes: 109 additions & 55 deletions app/telemetry/models/openhd_core/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#ifndef OPENHD_CAMERA_HPP
#define OPENHD_CAMERA_HPP

#include <iostream>
#include <optional>
#include <regex>
#include <sstream>
#include <string>
#include <vector>
#include <optional>

/**
* NOTE: This file is copied into QOpenHD to populate the UI.
Expand Down Expand Up @@ -51,8 +52,8 @@ static constexpr int X_CAM_TYPE_RPI_LIBCAMERA_RPIF_V3_IMX708 = 32;
static constexpr int X_CAM_TYPE_RPI_LIBCAMERA_RPIF_HQ_IMX477 = 33;
// .... 5 reserved for future use
// Now to all the rpi libcamera arducam cameras
static constexpr int X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYMASTERHDR = 40;
static constexpr int X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYVISIONPRO = 41;
static constexpr int X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYMASTERHDR_IMX708 = 40;
static constexpr int X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYVISIONPRO_IMX519 = 41;
static constexpr int X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_IMX477M = 42;
static constexpr int X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_IMX462 = 43;
static constexpr int X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_IMX327 = 44;
Expand All @@ -77,7 +78,7 @@ static constexpr int X_CAM_TYPE_ROCK_HDMI_IN = 80;
static constexpr int X_CAM_TYPE_ROCK_IMX219 = 81;
//
// OpenIPC specific starts here
static constexpr int X_CAM_TYPE_OPENIPC_SOMETHING=90;
static constexpr int X_CAM_TYPE_OPENIPC_SOMETHING = 90;
//

// ... rest is reserved for future use
Expand Down Expand Up @@ -110,9 +111,9 @@ static std::string x_cam_type_to_string(int camera_type) {
return "RPIF_V3_IMX708";
case X_CAM_TYPE_RPI_LIBCAMERA_RPIF_HQ_IMX477:
return "RPIF_HQ_IMX477";
case X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYMASTERHDR:
case X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYMASTERHDR_IMX708:
return "ARDUCAM_SKYMASTERHDR";
case X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYVISIONPRO:
case X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYVISIONPRO_IMX519:
return "ARDUCAM_SKYVISIONPRO";
case X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_IMX477M:
return "ARDUCAM_IMX477M";
Expand Down Expand Up @@ -156,9 +157,9 @@ struct ResolutionFramerate {
int width_px;
int height_px;
int fps;
std::string as_string()const{
std::string as_string() const {
std::stringstream ss;
ss<<width_px<<"x"<<height_px<<"@"<<fps;
ss << width_px << "x" << height_px << "@" << fps;
return ss.str();
}
};
Expand Down Expand Up @@ -200,21 +201,69 @@ struct XCamera {
// anything he likes)
std::vector<ResolutionFramerate> get_supported_resolutions() const {
if (requires_rpi_veye_pipeline()) {
// Veye camera(s) only do 1080p30
// Except one, all veye camera(s) only do 1080p30 -
// Urghs but not via v4l2. So we only expose 1080p30
/*if(camera_type==X_CAM_TYPE_RPI_V4L2_VEYE_CSIMX307){
std::vector<ResolutionFramerate> ret;
ret.push_back(ResolutionFramerate{640, 480, 90});
ret.push_back(ResolutionFramerate{1280, 720, 50});
ret.push_back(ResolutionFramerate{1280, 720, 60});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
}else{
return {ResolutionFramerate{1920, 1080, 30}};
}*/
return {ResolutionFramerate{1920, 1080, 30}};
} else if (requires_x20_cedar_pipeline()) {
// also easy, 720p60 only (for now)
return {ResolutionFramerate{1280, 720, 60}};
} else if (camera_type == X_CAM_TYPE_USB_INFIRAY) {
return {ResolutionFramerate{384,292,25}};
} else if(camera_type==X_CAM_TYPE_USB_GENERIC){
return {ResolutionFramerate{384, 292, 25}};
} else if (camera_type == X_CAM_TYPE_USB_GENERIC) {
// Return what's most likely going to work
return {ResolutionFramerate{640, 480, 30}};
} else if (requires_rpi_libcamera_pipeline()) {
std::vector<ResolutionFramerate> ret;
ret.push_back(ResolutionFramerate{640, 480, 60});
ret.push_back(ResolutionFramerate{1280, 720, 60});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
if(camera_type==X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_IMX462 ||
camera_type==X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_IMX462_LOWLIGHT_MINI){
ret.push_back(ResolutionFramerate{640, 480, 60});
ret.push_back(ResolutionFramerate{896, 504, 60});
ret.push_back(ResolutionFramerate{1280, 720, 60});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
}else if(camera_type==X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_IMX477M ||
camera_type==X_CAM_TYPE_RPI_LIBCAMERA_RPIF_HQ_IMX477) {
ret.push_back(ResolutionFramerate{640, 480, 50});
ret.push_back(ResolutionFramerate{896, 504, 50});
ret.push_back(ResolutionFramerate{1280, 720, 50});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
}else if(camera_type==X_CAM_TYPE_RPI_LIBCAMERA_RPIF_V2_IMX219){
ret.push_back(ResolutionFramerate{640, 480, 47});
ret.push_back(ResolutionFramerate{896, 504, 47});
ret.push_back(ResolutionFramerate{1280, 720, 47});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
}else if(camera_type==X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYVISIONPRO_IMX519){
ret.push_back(ResolutionFramerate{640, 480, 60});
ret.push_back(ResolutionFramerate{896, 504, 60});
ret.push_back(ResolutionFramerate{1280, 720, 60});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
}else if(camera_type==X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_SKYMASTERHDR_IMX708 ||
camera_type==X_CAM_TYPE_RPI_LIBCAMERA_RPIF_V3_IMX708){
ret.push_back(ResolutionFramerate{640, 480, 60});
ret.push_back(ResolutionFramerate{896, 504, 60});
ret.push_back(ResolutionFramerate{1280, 720, 60});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
}else if(camera_type==X_CAM_TYPE_RPI_LIBCAMERA_ARDUCAM_IMX327) {
ret.push_back(ResolutionFramerate{640, 480, 60});
ret.push_back(ResolutionFramerate{896, 504, 60});
ret.push_back(ResolutionFramerate{1280, 720, 60});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
}else if(camera_type==X_CAM_TYPE_RPI_LIBCAMERA_RPIF_V1_OV5647){
ret.push_back(ResolutionFramerate{1280, 720, 30});
ret.push_back(ResolutionFramerate{1920, 1080, 30});
}
else{
std::cerr<<"Not yet mapped:"<<camera_type<<std::endl;
ret.push_back(ResolutionFramerate{1920, 1080, 30});
}
return ret;
} else if (camera_type == X_CAM_TYPE_RPI_MMAL_HDMI_TO_CSI) {
std::vector<ResolutionFramerate> ret;
Expand All @@ -223,17 +272,17 @@ struct XCamera {
ret.push_back(ResolutionFramerate{1920, 1080, 25});
ret.push_back(ResolutionFramerate{1280, 720, 60});
return ret;
}else if(camera_type==X_CAM_TYPE_DUMMY_SW){
} else if (camera_type == X_CAM_TYPE_DUMMY_SW) {
std::vector<ResolutionFramerate> ret;
ret.push_back(ResolutionFramerate{640,480,30});
ret.push_back(ResolutionFramerate{1280,720,30});
ret.push_back(ResolutionFramerate{1280,720,60});
ret.push_back(ResolutionFramerate{640, 480, 30});
ret.push_back(ResolutionFramerate{1280, 720, 30});
ret.push_back(ResolutionFramerate{1280, 720, 60});
return ret;
}else if(camera_type==X_CAM_TYPE_DEVELOPMENT_FILESRC){
} else if (camera_type == X_CAM_TYPE_DEVELOPMENT_FILESRC) {
std::vector<ResolutionFramerate> ret;
ret.push_back(ResolutionFramerate{848,480,60});
ret.push_back(ResolutionFramerate{1280,720,60});
ret.push_back(ResolutionFramerate{1920,1080,60});
ret.push_back(ResolutionFramerate{848, 480, 60});
ret.push_back(ResolutionFramerate{1280, 720, 60});
ret.push_back(ResolutionFramerate{1920, 1080, 60});
return ret;
}
// Not mapped yet
Expand All @@ -242,8 +291,8 @@ struct XCamera {
}
// We default to the last supported resolution
[[nodiscard]] ResolutionFramerate get_default_resolution_fps() const {
auto supported_resolutions=get_supported_resolutions();
return supported_resolutions.at(supported_resolutions.size()-1);
auto supported_resolutions = get_supported_resolutions();
return supported_resolutions.at(supported_resolutions.size() - 1);
}
};

Expand All @@ -252,32 +301,29 @@ static bool is_valid_primary_cam_type(int cam_type) {
return false;
}
static bool is_valid_secondary_cam_type(int cam_type) {
if (cam_type == X_CAM_TYPE_DUMMY_SW ||
cam_type == X_CAM_TYPE_USB_INFIRAY ||
cam_type==X_CAM_TYPE_USB_GENERIC ||
cam_type == X_CAM_TYPE_EXTERNAL ||
cam_type == X_CAM_TYPE_EXTERNAL_IP ||
cam_type == X_CAM_TYPE_DISABLED) {
if (cam_type == X_CAM_TYPE_DUMMY_SW || cam_type == X_CAM_TYPE_USB_INFIRAY ||
cam_type == X_CAM_TYPE_USB_GENERIC || cam_type == X_CAM_TYPE_EXTERNAL ||
cam_type == X_CAM_TYPE_EXTERNAL_IP || cam_type == X_CAM_TYPE_DISABLED) {
return true;
}
return false;
}

static bool is_rpi_csi_camera(int cam_type) {
return cam_type >= 10 && cam_type <= 59;
return cam_type >= 20 && cam_type <= 69;
}

static bool supports_rotation(int cam_type){
return is_rpi_csi_camera(cam_type);
static bool is_rock_csi_camera(int cam_type) {
return cam_type == X_CAM_TYPE_ROCK_IMX219;
}

static bool is_usb_camera(int cam_type){
return cam_type>=10 && cam_type<19;
static bool is_usb_camera(int cam_type) {
return cam_type >= 10 && cam_type < 19;
}

// Takes a string in the from {width}x{height}@{framerate}
// e.g. 1280x720@30
static std::optional<ResolutionFramerate> parse_video_format(const std::string& videoFormat){
static std::optional<ResolutionFramerate> parse_video_format(
const std::string& videoFormat) {
if (videoFormat.size() <= 5) {
return std::nullopt;
}
Expand All @@ -299,29 +345,37 @@ static std::optional<ResolutionFramerate> parse_video_format(const std::string&
//
// Used in QOpenHD UI
//
static std::string get_verbose_string_of_resolution(const ResolutionFramerate& resolution_framerate){
if(resolution_framerate.width_px==0 && resolution_framerate.height_px==0 && resolution_framerate.fps==0){
static std::string get_verbose_string_of_resolution(
const ResolutionFramerate& resolution_framerate) {
if (resolution_framerate.width_px == 0 &&
resolution_framerate.height_px == 0 && resolution_framerate.fps == 0) {
return "AUTO";
}
std::stringstream ss;
if(resolution_framerate.width_px==640 && resolution_framerate.height_px==480){
ss<<"VGA 4:3";
}else if(resolution_framerate.width_px==848 && resolution_framerate.height_px==480){
ss<<"VGA 16:9";
}else if(resolution_framerate.width_px==896 && resolution_framerate.height_px== 504){
ss<<"SD 16:9";
}else if(resolution_framerate.width_px==1280 && resolution_framerate.height_px==720){
ss<<"HD 16:9";
}else if(resolution_framerate.width_px==1920 && resolution_framerate.height_px==1080){
ss<<"FHD 16:9";
}else if(resolution_framerate.width_px==2560 && resolution_framerate.height_px==1440){
ss<<"2K 16:9";
}else{
ss<<resolution_framerate.width_px<<"x"<<resolution_framerate.height_px<<"\n";
if (resolution_framerate.width_px == 640 &&
resolution_framerate.height_px == 480) {
ss << "VGA 4:3";
} else if (resolution_framerate.width_px == 848 &&
resolution_framerate.height_px == 480) {
ss << "VGA 16:9";
} else if (resolution_framerate.width_px == 896 &&
resolution_framerate.height_px == 504) {
ss << "SD 16:9";
} else if (resolution_framerate.width_px == 1280 &&
resolution_framerate.height_px == 720) {
ss << "HD 16:9";
} else if (resolution_framerate.width_px == 1920 &&
resolution_framerate.height_px == 1080) {
ss << "FHD 16:9";
} else if (resolution_framerate.width_px == 2560 &&
resolution_framerate.height_px == 1440) {
ss << "2K 16:9";
} else {
ss << resolution_framerate.width_px << "x" << resolution_framerate.height_px
<< "\n";
}
ss<<"\n"<<resolution_framerate.fps<<"fps";
ss << "\n" << resolution_framerate.fps << "fps";
return ss.str();
}


#endif // OPENHD_CAMERA_HPP

0 comments on commit c04802f

Please sign in to comment.