mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[fix] put resolution converter into task queue
This commit is contained in:
@@ -37,6 +37,8 @@ class AnyInvocable<R(Args...)> {
|
||||
// 移动赋值运算符
|
||||
AnyInvocable& operator=(AnyInvocable&&) = default;
|
||||
|
||||
explicit operator bool() const { return static_cast<bool>(callable_); }
|
||||
|
||||
private:
|
||||
// 抽象基类,允许不同类型的可调用对象
|
||||
struct CallableBase {
|
||||
|
||||
@@ -104,8 +104,6 @@ class TaskQueue {
|
||||
[this]() { return stop_; });
|
||||
}
|
||||
|
||||
if (stop_ && taskQueue_.empty()) return;
|
||||
|
||||
task = std::move(
|
||||
const_cast<AnyInvocable<void()> &>(taskQueue_.top().task));
|
||||
taskQueue_.pop();
|
||||
|
||||
@@ -53,7 +53,7 @@ void RtpVideoSender::Enqueue(
|
||||
|
||||
to_send_rtp_packets.push_back(std::move(rtp_packet_to_send));
|
||||
}
|
||||
enqueue_packets_func_(std::move(to_send_rtp_packets));
|
||||
enqueue_packets_func_(to_send_rtp_packets);
|
||||
}
|
||||
|
||||
void RtpVideoSender::SetSendDataFunc(
|
||||
|
||||
@@ -203,33 +203,33 @@ int IceTransportController::SendVideo(const XVideoFrame* video_frame) {
|
||||
b_force_i_frame_ = false;
|
||||
}
|
||||
|
||||
if (task_queue_encode_ && video_encoder_) {
|
||||
auto video_frame_copy = std::make_shared<XVideoFrame>(*video_frame);
|
||||
task_queue_encode_->PostTask([this, video_frame_copy]() mutable {
|
||||
XVideoFrame new_frame;
|
||||
new_frame.data = nullptr;
|
||||
new_frame.width = video_frame->width;
|
||||
new_frame.height = video_frame->height;
|
||||
new_frame.size = video_frame->size;
|
||||
new_frame.captured_timestamp = video_frame->captured_timestamp;
|
||||
new_frame.width = video_frame_copy->width;
|
||||
new_frame.height = video_frame_copy->height;
|
||||
new_frame.size = video_frame_copy->size;
|
||||
new_frame.captured_timestamp = video_frame_copy->captured_timestamp;
|
||||
if (target_width_.has_value() && target_height_.has_value()) {
|
||||
if (target_width_.value() < video_frame->width &&
|
||||
target_height_.value() < video_frame->height) {
|
||||
if (target_width_.value() < video_frame_copy->width &&
|
||||
target_height_.value() < video_frame_copy->height) {
|
||||
resolution_adapter_->ResolutionDowngrade(
|
||||
video_frame, target_width_.value(), target_height_.value(),
|
||||
&new_frame);
|
||||
video_frame_copy.get(), target_width_.value(),
|
||||
target_height_.value(), &new_frame);
|
||||
} else {
|
||||
new_frame.data = new char[video_frame->size];
|
||||
memcpy((void*)new_frame.data, (void*)video_frame->data,
|
||||
video_frame->size);
|
||||
new_frame.data = new char[video_frame_copy->size];
|
||||
memcpy((void*)new_frame.data, (void*)video_frame_copy->data,
|
||||
video_frame_copy->size);
|
||||
}
|
||||
}
|
||||
|
||||
RawFrame raw_frame((const uint8_t*)new_frame.data, new_frame.size,
|
||||
new_frame.width, new_frame.height);
|
||||
raw_frame.SetCapturedTimestamp(video_frame->captured_timestamp);
|
||||
|
||||
raw_frame.SetCapturedTimestamp(video_frame_copy->captured_timestamp);
|
||||
delete[] new_frame.data;
|
||||
|
||||
if (task_queue_encode_ && video_encoder_) {
|
||||
task_queue_encode_->PostTask([this, raw_frame]() mutable {
|
||||
int ret = video_encoder_->Encode(
|
||||
std::move(raw_frame),
|
||||
[this](const EncodedFrame& encoded_frame) -> int {
|
||||
|
||||
Reference in New Issue
Block a user