[feat] save thumbnail as black picture if have not received a full frame

This commit is contained in:
dijunkun
2025-04-16 16:47:30 +08:00
parent 22aed6ea53
commit 9705374b9a
2 changed files with 27 additions and 21 deletions

View File

@@ -999,12 +999,10 @@ void Render::ProcessSdlEvent() {
DestroyStreamWindowContext(); DestroyStreamWindowContext();
for (auto& [host_name, props] : client_properties_) { for (auto& [host_name, props] : client_properties_) {
if (props->dst_buffer_) { thumbnail_->SaveToThumbnail(
thumbnail_->SaveToThumbnail( (char*)props->dst_buffer_, props->video_width_,
(char*)props->dst_buffer_, props->video_width_, props->video_height_, host_name, props->remote_host_name_,
props->video_height_, host_name, props->remote_host_name_, props->remember_password_ ? props->remote_password_ : "");
props->remember_password_ ? props->remote_password_ : "");
}
if (props->peer_) { if (props->peer_) {
std::string client_id = (host_name == client_id_) std::string client_id = (host_name == client_id_)

View File

@@ -143,23 +143,31 @@ int Thumbnail::SaveToThumbnail(const char* yuv420p, int width, int height,
if (yuv420p) { if (yuv420p) {
ScaleYUV420pToABGR((char*)yuv420p, width, height, thumbnail_width_, ScaleYUV420pToABGR((char*)yuv420p, width, height, thumbnail_width_,
thumbnail_height_, rgba_buffer_); thumbnail_height_, rgba_buffer_);
} else {
std::string image_name; // If yuv420p is null, fill the buffer with black pixels
if (password.empty()) { memset(rgba_buffer_, 0x00, thumbnail_width_ * thumbnail_height_ * 4);
return 0; for (int i = 0; i < thumbnail_width_ * thumbnail_height_; ++i) {
} else { // Set alpha channel to opaque
// delete the file which has no password in its name rgba_buffer_[i * 4 + 3] = 0xFF;
std::string filename_without_password = remote_id + "N" + host_name;
DeleteThumbnail(filename_without_password);
image_name = remote_id + 'Y' + password + host_name;
} }
std::string ciphertext = AES_encrypt(image_name, aes128_key_, aes128_iv_);
std::string file_path = image_path_ + ciphertext;
stbi_write_png(file_path.data(), thumbnail_width_, thumbnail_height_, 4,
rgba_buffer_, thumbnail_width_ * 4);
} }
std::string image_name;
if (password.empty()) {
return 0;
} else {
// delete the file which has no password in its name
std::string filename_without_password = remote_id + "N" + host_name;
DeleteThumbnail(filename_without_password);
image_name = remote_id + 'Y' + password + host_name;
}
std::string ciphertext = AES_encrypt(image_name, aes128_key_, aes128_iv_);
std::string file_path = image_path_ + ciphertext;
stbi_write_png(file_path.data(), thumbnail_width_, thumbnail_height_, 4,
rgba_buffer_, thumbnail_width_ * 4);
return 0; return 0;
} }