Skip to content

Commit d30f1df

Browse files
committed
fix codegate issues/readability
1 parent a37b309 commit d30f1df

File tree

4 files changed

+76
-87
lines changed

4 files changed

+76
-87
lines changed

src/nvhttp.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,39 @@ namespace nvhttp {
680680
return true;
681681
}
682682

683+
uint32_t get_codec_mode_flags() {
684+
uint32_t codec_mode_flags = SCM_H264;
685+
if (video::last_encoder_probe_supported_yuv444_for_codec[0]) {
686+
codec_mode_flags |= SCM_H264_HIGH8_444;
687+
}
688+
if (video::active_hevc_mode >= 2) {
689+
codec_mode_flags |= SCM_HEVC;
690+
if (video::last_encoder_probe_supported_yuv444_for_codec[1]) {
691+
codec_mode_flags |= SCM_HEVC_REXT8_444;
692+
}
693+
}
694+
if (video::active_hevc_mode == 3 || video::active_hevc_mode == 5) {
695+
codec_mode_flags |= SCM_HEVC_MAIN10;
696+
}
697+
if ((video::active_hevc_mode == 4 || video::active_hevc_mode == 5) && video::last_encoder_probe_supported_yuv444_for_codec[1]) {
698+
codec_mode_flags |= SCM_HEVC_REXT10_444;
699+
}
700+
701+
if (video::active_av1_mode >= 2) {
702+
codec_mode_flags |= SCM_AV1_MAIN8;
703+
if (video::last_encoder_probe_supported_yuv444_for_codec[2]) {
704+
codec_mode_flags |= SCM_AV1_HIGH8_444;
705+
}
706+
}
707+
if (video::active_av1_mode == 3 || video::active_av1_mode == 5) {
708+
codec_mode_flags |= SCM_AV1_MAIN10;
709+
}
710+
if ((video::active_av1_mode == 4 || video::active_av1_mode == 5) && video::last_encoder_probe_supported_yuv444_for_codec[2]) {
711+
codec_mode_flags |= SCM_AV1_HIGH10_444;
712+
}
713+
return codec_mode_flags;
714+
}
715+
683716
template<class T>
684717
void serverinfo(std::shared_ptr<typename SimpleWeb::ServerBase<T>::Response> response, std::shared_ptr<typename SimpleWeb::ServerBase<T>::Request> request) {
685718
print_req<T>(request);
@@ -731,36 +764,7 @@ namespace nvhttp {
731764
tree.put("root.LocalIP", net::addr_to_normalized_string(local_endpoint.address()));
732765
}
733766

734-
uint32_t codec_mode_flags = SCM_H264;
735-
if (video::last_encoder_probe_supported_yuv444_for_codec[0]) {
736-
codec_mode_flags |= SCM_H264_HIGH8_444;
737-
}
738-
if (video::active_hevc_mode >= 2) {
739-
codec_mode_flags |= SCM_HEVC;
740-
if (video::last_encoder_probe_supported_yuv444_for_codec[1]) {
741-
codec_mode_flags |= SCM_HEVC_REXT8_444;
742-
}
743-
}
744-
if (video::active_hevc_mode == 3 || video::active_hevc_mode == 5) {
745-
codec_mode_flags |= SCM_HEVC_MAIN10;
746-
}
747-
if (video::active_hevc_mode == 4 || video::active_hevc_mode == 5) {
748-
if (video::last_encoder_probe_supported_yuv444_for_codec[1]) {
749-
codec_mode_flags |= SCM_HEVC_REXT10_444;
750-
}
751-
}
752-
if (video::active_av1_mode >= 2) {
753-
codec_mode_flags |= SCM_AV1_MAIN8;
754-
if (video::last_encoder_probe_supported_yuv444_for_codec[2]) {
755-
codec_mode_flags |= SCM_AV1_HIGH8_444;
756-
}
757-
}
758-
if (video::active_av1_mode >= 3) {
759-
codec_mode_flags |= SCM_AV1_MAIN10;
760-
if (video::last_encoder_probe_supported_yuv444_for_codec[2]) {
761-
codec_mode_flags |= SCM_AV1_HIGH10_444;
762-
}
763-
}
767+
const uint32_t codec_mode_flags = get_codec_mode_flags();
764768
tree.put("root.ServerCodecModeSupport", codec_mode_flags);
765769

766770
auto current_appid = proc::proc.running();

src/platform/linux/graphics.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,10 @@ namespace egl {
651651
return rgb;
652652
}
653653

654+
//constants for clear black color Y, U, V. U & V are same so:
655+
const float y_black[] = {0.0f, 0.0f, 0.0f, 0.0f};
656+
const float uv_black[] = {0.5f, 0.5f, 0.5f, 0.5f};
657+
654658
std::optional<nv12_t> import_target(display_t::pointer egl_display, std::array<file_t, nv12_img_t::num_fds> &&fds, const surface_descriptor_t &y, const surface_descriptor_t &uv) {
655659
auto y_attribs = surface_descriptor_to_egl_attribs(y);
656660
auto uv_attribs = surface_descriptor_to_egl_attribs(uv);
@@ -690,9 +694,6 @@ namespace egl {
690694
for (int x = 0; x < sizeof(attachments) / sizeof(decltype(attachments[0])); ++x) {
691695
gl::ctx.BindFramebuffer(GL_FRAMEBUFFER, nv12->buf[x]);
692696
gl::ctx.DrawBuffers(1, &attachments[x]);
693-
694-
const float y_black[] = {0.0f, 0.0f, 0.0f, 0.0f};
695-
const float uv_black[] = {0.5f, 0.5f, 0.5f, 0.5f};
696697
gl::ctx.ClearBufferfv(GL_COLOR, 0, x == 0 ? y_black : uv_black);
697698
}
698699

@@ -752,9 +753,6 @@ namespace egl {
752753
for (int x = 0; x < sizeof(attachments) / sizeof(decltype(attachments[0])); ++x) {
753754
gl::ctx.BindFramebuffer(GL_FRAMEBUFFER, yuv444->buf[x]);
754755
gl::ctx.DrawBuffers(1, &attachments[x]);
755-
756-
const float y_black[] = {0.0f, 0.0f, 0.0f, 0.0f};
757-
const float uv_black[] = {0.5f, 0.5f, 0.5f, 0.5f};
758756
gl::ctx.ClearBufferfv(GL_COLOR, 0, x == 0 ? y_black : uv_black);
759757
}
760758

@@ -813,9 +811,6 @@ namespace egl {
813811
for (int x = 0; x < sizeof(attachments) / sizeof(decltype(attachments[0])); ++x) {
814812
gl::ctx.BindFramebuffer(GL_FRAMEBUFFER, nv12->buf[x]);
815813
gl::ctx.DrawBuffers(1, &attachments[x]);
816-
817-
const float y_black[] = {0.0f, 0.0f, 0.0f, 0.0f};
818-
const float uv_black[] = {0.5f, 0.5f, 0.5f, 0.5f};
819814
gl::ctx.ClearBufferfv(GL_COLOR, 0, x == 0 ? y_black : uv_black);
820815
}
821816

@@ -876,9 +871,6 @@ namespace egl {
876871
for (int x = 0; x < sizeof(attachments) / sizeof(decltype(attachments[0])); ++x) {
877872
gl::ctx.BindFramebuffer(GL_FRAMEBUFFER, yuv444->buf[x]);
878873
gl::ctx.DrawBuffers(1, &attachments[x]);
879-
880-
const float y_black[] = {0.0f, 0.0f, 0.0f, 0.0f};
881-
const float uv_black[] = {0.5f, 0.5f, 0.5f, 0.5f};
882874
gl::ctx.ClearBufferfv(GL_COLOR, 0, x == 0 ? y_black : uv_black);
883875
}
884876

@@ -1163,10 +1155,10 @@ namespace egl {
11631155
return sws;
11641156
}
11651157

1166-
int sws_t::blank(gl::frame_buf_t &fb, int offsetX, int offsetY, int width, int height, AVPixelFormat format) {
1158+
int sws_t::blank(gl::frame_buf_t &fb, int offsetX_, int offsetY_, int width, int height, AVPixelFormat format) {
11671159
auto f = [&]() {
1168-
std::swap(offsetX, this->offsetX);
1169-
std::swap(offsetY, this->offsetY);
1160+
std::swap(offsetX_, this->offsetX);
1161+
std::swap(offsetY_, this->offsetY);
11701162
std::swap(width, this->out_width);
11711163
std::swap(height, this->out_height);
11721164
};

src/platform/linux/graphics.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ namespace egl {
219219
gl::tex_t tex;
220220
gl::frame_buf_t buf;
221221

222-
// sizeof(va::DRMPRIMESurfaceDescriptor::objects) / sizeof(va::DRMPRIMESurfaceDescriptor::objects[0]);
223222
static constexpr std::size_t num_fds = 4;
224223

225224
std::array<file_t, num_fds> fds;
@@ -367,7 +366,7 @@ namespace egl {
367366
int convert_yuv444(gl::frame_buf_t &fb);
368367

369368
// Make an area of the image black
370-
int blank(gl::frame_buf_t &fb, int offsetX, int offsetY, int width, int height, AVPixelFormat format);
369+
int blank(gl::frame_buf_t &fb, int offsetX_, int offsetY_, int width, int height, AVPixelFormat format);
371370

372371
void load_nv12_ram(platf::img_t &img);
373372
void load_nv12_vram(img_descriptor_t &img, int offset_x, int offset_y, int texture);

src/video.cpp

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,36 +2735,19 @@ namespace video {
27352735

27362736
// Test HDR and YUV444 support
27372737
{
2738-
// H.264 is special because encoders may support YUV 4:4:4 without supporting 10-bit color depth
2739-
if (encoder.flags & YUV444_SUPPORT) {
2740-
config_t config_h264_yuv444 {1920, 1080, 60, 6000, 1000, 1, 0, 1, 0, 0, 1};
2741-
encoder.h264[encoder_t::YUV444] = disp->is_codec_supported(encoder.h264.name, config_h264_yuv444) &&
2742-
validate_config(disp, encoder, config_h264_yuv444) >= 0;
2743-
} else {
2744-
encoder.h264[encoder_t::YUV444] = false;
2745-
}
2746-
27472738
auto test_yuv444 = [&](auto &flag_map, auto video_format) {
2748-
const config_t sdr_yuv444_config = {1920, 1080, 60, 6000, 1000, 1, 0, 1, 1, 0, 1};
2749-
2750-
auto config = sdr_yuv444_config;
2739+
const config_t config = {1920, 1080, 60, 6000, 1000, 1, 0, 1, video_format, 0, 1};
27512740

2752-
// Reset the display
27532741
reset_display(disp, encoder.platform_formats->dev_type, output_name, config);
27542742
if (!disp) {
27552743
return;
27562744
}
2757-
2758-
config.videoFormat = video_format;
2759-
27602745
if (!flag_map[encoder_t::PASSED]) {
27612746
return;
27622747
}
27632748

27642749
auto encoder_codec_name = encoder.codec_from_config(config).name;
27652750

2766-
// Test 4:4:4 SDR first
2767-
config.chromaSamplingType = 1;
27682751
if ((encoder.flags & YUV444_SUPPORT) &&
27692752
disp->is_codec_supported(encoder_codec_name, config) &&
27702753
validate_config(disp, encoder, config) >= 0) {
@@ -2774,53 +2757,59 @@ namespace video {
27742757
}
27752758
};
27762759

2777-
auto test_hdr = [&](auto &flag_map, auto video_format) {
2778-
2779-
const config_t generic_hdr_config = {1920, 1080, 60, 6000, 1000, 1, 0, 3, 1, 1, 0};
2780-
2781-
auto config = generic_hdr_config;
2760+
auto test_yuv420_hdr = [&](auto &flag_map, auto video_format) {
2761+
const config_t config = {1920, 1080, 60, 6000, 1000, 1, 0, 3, video_format, 1, 0};
27822762

2783-
// Reset the display
27842763
reset_display(disp, encoder.platform_formats->dev_type, output_name, config);
27852764
if (!disp) {
27862765
return;
27872766
}
2767+
if (!flag_map[encoder_t::PASSED]) {
2768+
return;
2769+
}
2770+
2771+
auto encoder_codec_name = encoder.codec_from_config(config).name;
2772+
2773+
if (disp->is_codec_supported(encoder_codec_name, config) && validate_config(disp, encoder, config) >= 0) {
2774+
flag_map[encoder_t::DYNAMIC_RANGE] = true;
2775+
} else {
2776+
flag_map[encoder_t::DYNAMIC_RANGE] = false;
2777+
}
2778+
};
27882779

2789-
config.videoFormat = video_format;
2780+
auto test_yuv444_hdr = [&](auto &flag_map, auto video_format) {
2781+
const config_t config = {1920, 1080, 60, 6000, 1000, 1, 0, 3, video_format, 1, 1};
27902782

2783+
reset_display(disp, encoder.platform_formats->dev_type, output_name, config);
2784+
if (!disp) {
2785+
return;
2786+
}
27912787
if (!flag_map[encoder_t::PASSED]) {
27922788
return;
27932789
}
27942790

27952791
auto encoder_codec_name = encoder.codec_from_config(config).name;
27962792

2797-
// Test 4:4:4 HDR first.
2798-
config.chromaSamplingType = 1;
27992793
if ((encoder.flags & YUV444_SUPPORT) &&
28002794
disp->is_codec_supported(encoder_codec_name, config) &&
28012795
validate_config(disp, encoder, config) >= 0) {
28022796
flag_map[encoder_t::DYNAMIC_RANGE_YUV444] = true;
28032797
} else {
28042798
flag_map[encoder_t::DYNAMIC_RANGE_YUV444] = false;
28052799
}
2806-
2807-
// Test 4:2:0 HDR
2808-
config.chromaSamplingType = 0;
2809-
if (disp->is_codec_supported(encoder_codec_name, config) && validate_config(disp, encoder, config) >= 0) {
2810-
flag_map[encoder_t::DYNAMIC_RANGE] = true;
2811-
} else {
2812-
flag_map[encoder_t::DYNAMIC_RANGE] = false;
2813-
}
28142800
};
28152801

2802+
test_yuv444(encoder.h264, 0);
28162803
// HDR is not supported with H.264. Don't bother even trying it.
28172804
encoder.h264[encoder_t::DYNAMIC_RANGE] = false;
28182805
encoder.h264[encoder_t::DYNAMIC_RANGE_YUV444] = false;
28192806

28202807
test_yuv444(encoder.hevc, 1);
2821-
test_hdr(encoder.hevc, 1);
2808+
test_yuv420_hdr(encoder.hevc, 1);
2809+
test_yuv444_hdr(encoder.hevc, 1);
28222810
test_yuv444(encoder.av1, 2);
2823-
test_hdr(encoder.av1, 2);
2811+
test_yuv420_hdr(encoder.av1, 2);
2812+
test_yuv444_hdr(encoder.av1, 2);
28242813
}
28252814

28262815
encoder.h264[encoder_t::VUI_PARAMETERS] = encoder.h264[encoder_t::VUI_PARAMETERS] && !config::sunshine.flags[config::flag::FORCE_VIDEO_HEADER_REPLACE];
@@ -2857,7 +2846,7 @@ namespace video {
28572846
active_av1_mode = config::video.av1_mode;
28582847
last_encoder_probe_supported_ref_frames_invalidation = false;
28592848

2860-
auto adjust_encoder_constraints = [&](encoder_t *encoder) {
2849+
auto adjust_encoder_constraints_hevc = [&](encoder_t *encoder) {
28612850
// If we can't satisfy both the encoder and codec requirement, prefer the encoder over codec support
28622851
if (active_hevc_mode == 5 && !encoder->hevc[encoder_t::DYNAMIC_RANGE] && !encoder->hevc[encoder_t::DYNAMIC_RANGE_YUV444]) {
28632852
BOOST_LOG(warning) << "Encoder ["sv << encoder->name << "] does not support HEVC Main10 Rext10_444 on this system"sv;
@@ -2872,7 +2861,10 @@ namespace video {
28722861
BOOST_LOG(warning) << "Encoder ["sv << encoder->name << "] does not support HEVC on this system"sv;
28732862
active_hevc_mode = 0;
28742863
}
2864+
};
28752865

2866+
auto adjust_encoder_constraints_av1 = [&](encoder_t *encoder) {
2867+
// If we can't satisfy both the encoder and codec requirement, prefer the encoder over codec support
28762868
if (active_av1_mode == 5 && !encoder->av1[encoder_t::DYNAMIC_RANGE] && !encoder->av1[encoder_t::DYNAMIC_RANGE_YUV444]) {
28772869
BOOST_LOG(warning) << "Encoder ["sv << encoder->name << "] does not support AV1 Main10 Rext10_444 on this system"sv;
28782870
active_av1_mode = 0;
@@ -2901,7 +2893,8 @@ namespace video {
29012893
}
29022894

29032895
// We will return an encoder here even if it fails one of the codec requirements specified by the user
2904-
adjust_encoder_constraints(encoder);
2896+
adjust_encoder_constraints_hevc(encoder);
2897+
adjust_encoder_constraints_av1(encoder);
29052898

29062899
chosen_encoder = encoder;
29072900
break;
@@ -2980,7 +2973,8 @@ namespace video {
29802973
}
29812974

29822975
// We will return an encoder here even if it fails one of the codec requirements specified by the user
2983-
adjust_encoder_constraints(encoder);
2976+
adjust_encoder_constraints_hevc(encoder);
2977+
adjust_encoder_constraints_av1(encoder);
29842978

29852979
chosen_encoder = encoder;
29862980
break;

0 commit comments

Comments
 (0)