mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] use smart pointer for ReceivedFrame when send it into decoder
This commit is contained in:
@@ -66,10 +66,10 @@ int AomAv1Decoder::Init() {
|
||||
}
|
||||
|
||||
int AomAv1Decoder::Decode(
|
||||
const ReceivedFrame &received_frame,
|
||||
std::unique_ptr<ReceivedFrame> received_frame,
|
||||
std::function<void(const DecodedFrame &)> on_receive_decoded_frame) {
|
||||
const uint8_t *data = received_frame.Buffer();
|
||||
size_t size = received_frame.Size();
|
||||
const uint8_t *data = received_frame->Buffer();
|
||||
size_t size = received_frame->Size();
|
||||
|
||||
#ifdef SAVE_RECEIVED_AV1_STREAM
|
||||
fwrite((unsigned char *)data, 1, size, file_av1_);
|
||||
@@ -138,8 +138,8 @@ int AomAv1Decoder::Decode(
|
||||
DecodedFrame decode_frame(nv12_data.data(), nv12_size, img_->d_w,
|
||||
img_->d_h);
|
||||
|
||||
decode_frame.SetReceivedTimestamp(received_frame.ReceivedTimestamp());
|
||||
decode_frame.SetCapturedTimestamp(received_frame.CapturedTimestamp());
|
||||
decode_frame.SetReceivedTimestamp(received_frame->ReceivedTimestamp());
|
||||
decode_frame.SetCapturedTimestamp(received_frame->CapturedTimestamp());
|
||||
decode_frame.SetDecodedTimestamp(clock_->CurrentTime());
|
||||
|
||||
#ifdef SAVE_DECODED_NV12_STREAM
|
||||
|
||||
@@ -23,7 +23,7 @@ class AomAv1Decoder : public VideoDecoder {
|
||||
int Init();
|
||||
|
||||
int Decode(
|
||||
const ReceivedFrame &received_frame,
|
||||
std::unique_ptr<ReceivedFrame> received_frame,
|
||||
std::function<void(const DecodedFrame &)> on_receive_decoded_frame);
|
||||
|
||||
std::string GetDecoderName() { return "AomAv1"; }
|
||||
|
||||
@@ -107,10 +107,10 @@ int Dav1dAv1Decoder::Init() {
|
||||
}
|
||||
|
||||
int Dav1dAv1Decoder::Decode(
|
||||
const ReceivedFrame &received_frame,
|
||||
std::unique_ptr<ReceivedFrame> received_frame,
|
||||
std::function<void(const DecodedFrame &)> on_receive_decoded_frame) {
|
||||
const uint8_t *data = received_frame.Buffer();
|
||||
size_t size = received_frame.Size();
|
||||
const uint8_t *data = received_frame->Buffer();
|
||||
size_t size = received_frame->Size();
|
||||
|
||||
#ifdef SAVE_RECEIVED_AV1_STREAM
|
||||
fwrite((unsigned char *)data, 1, size, file_av1_);
|
||||
@@ -190,8 +190,8 @@ int Dav1dAv1Decoder::Decode(
|
||||
DecodedFrame decoded_frame(nv12_frame_, nv12_frame_capacity_, frame_width_,
|
||||
frame_height_);
|
||||
|
||||
decoded_frame.SetReceivedTimestamp(received_frame.ReceivedTimestamp());
|
||||
decoded_frame.SetCapturedTimestamp(received_frame.CapturedTimestamp());
|
||||
decoded_frame.SetReceivedTimestamp(received_frame->ReceivedTimestamp());
|
||||
decoded_frame.SetCapturedTimestamp(received_frame->CapturedTimestamp());
|
||||
decoded_frame.SetDecodedTimestamp(clock_->CurrentTime());
|
||||
|
||||
#ifdef SAVE_DECODED_NV12_STREAM
|
||||
|
||||
@@ -21,7 +21,7 @@ class Dav1dAv1Decoder : public VideoDecoder {
|
||||
int Init();
|
||||
|
||||
int Decode(
|
||||
const ReceivedFrame &received_frame,
|
||||
std::unique_ptr<ReceivedFrame> received_frame,
|
||||
std::function<void(const DecodedFrame &)> on_receive_decoded_frame);
|
||||
|
||||
std::string GetDecoderName() { return "Dav1dAv1"; }
|
||||
|
||||
@@ -69,14 +69,14 @@ int NvidiaVideoDecoder::Init() {
|
||||
}
|
||||
|
||||
int NvidiaVideoDecoder::Decode(
|
||||
const ReceivedFrame &received_frame,
|
||||
std::unique_ptr<ReceivedFrame> received_frame,
|
||||
std::function<void(const DecodedFrame &)> on_receive_decoded_frame) {
|
||||
if (!decoder) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const uint8_t *data = received_frame.Buffer();
|
||||
size_t size = received_frame.Size();
|
||||
const uint8_t *data = received_frame->Buffer();
|
||||
size_t size = received_frame->Size();
|
||||
|
||||
#ifdef SAVE_RECEIVED_H264_STREAM
|
||||
fwrite((unsigned char *)data, 1, size, file_h264_);
|
||||
@@ -99,9 +99,9 @@ int NvidiaVideoDecoder::Decode(
|
||||
decoder->GetWidth() * decoder->GetHeight() * 3 / 2,
|
||||
decoder->GetWidth(), decoder->GetHeight());
|
||||
decoded_frame.SetReceivedTimestamp(
|
||||
received_frame.ReceivedTimestamp());
|
||||
received_frame->ReceivedTimestamp());
|
||||
decoded_frame.SetCapturedTimestamp(
|
||||
received_frame.CapturedTimestamp());
|
||||
received_frame->CapturedTimestamp());
|
||||
decoded_frame.SetDecodedTimestamp(clock_->CurrentTime());
|
||||
on_receive_decoded_frame(decoded_frame);
|
||||
#ifdef SAVE_DECODED_NV12_STREAM
|
||||
|
||||
@@ -14,7 +14,7 @@ class NvidiaVideoDecoder : public VideoDecoder {
|
||||
public:
|
||||
int Init();
|
||||
|
||||
int Decode(const ReceivedFrame& received_frame,
|
||||
int Decode(std::unique_ptr<ReceivedFrame> received_frame,
|
||||
std::function<void(const DecodedFrame&)> on_receive_decoded_frame);
|
||||
|
||||
std::string GetDecoderName() { return "NvidiaH264"; }
|
||||
|
||||
@@ -104,14 +104,18 @@ int OpenH264Decoder::Init() {
|
||||
}
|
||||
|
||||
int OpenH264Decoder::Decode(
|
||||
const ReceivedFrame &received_frame,
|
||||
std::unique_ptr<ReceivedFrame> received_frame,
|
||||
std::function<void(const DecodedFrame &)> on_receive_decoded_frame) {
|
||||
if (!openh264_decoder_) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const uint8_t *data = received_frame.Buffer();
|
||||
size_t size = received_frame.Size();
|
||||
const uint8_t *data = received_frame->Buffer();
|
||||
size_t size = received_frame->Size();
|
||||
|
||||
if (data == nullptr) {
|
||||
LOG_WARN("data is nullptr!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
}
|
||||
|
||||
#ifdef SAVE_RECEIVED_H264_STREAM
|
||||
fwrite((unsigned char *)data, 1, size, h264_stream_);
|
||||
@@ -180,8 +184,8 @@ int OpenH264Decoder::Decode(
|
||||
|
||||
DecodedFrame decoded_frame(nv12_frame_, nv12_frame_capacity_,
|
||||
frame_width_, frame_height_);
|
||||
decoded_frame.SetReceivedTimestamp(received_frame.ReceivedTimestamp());
|
||||
decoded_frame.SetCapturedTimestamp(received_frame.CapturedTimestamp());
|
||||
decoded_frame.SetReceivedTimestamp(received_frame->ReceivedTimestamp());
|
||||
decoded_frame.SetCapturedTimestamp(received_frame->CapturedTimestamp());
|
||||
decoded_frame.SetDecodedTimestamp(clock_->CurrentTime());
|
||||
|
||||
#ifdef SAVE_DECODED_NV12_STREAM
|
||||
|
||||
@@ -24,7 +24,7 @@ class OpenH264Decoder : public VideoDecoder {
|
||||
public:
|
||||
int Init();
|
||||
|
||||
int Decode(const ReceivedFrame& received_frame,
|
||||
int Decode(std::unique_ptr<ReceivedFrame> received_frame,
|
||||
std::function<void(const DecodedFrame&)> on_receive_decoded_frame);
|
||||
|
||||
std::string GetDecoderName() { return "OpenH264"; }
|
||||
|
||||
@@ -22,7 +22,7 @@ class VideoDecoder {
|
||||
virtual int Init() = 0;
|
||||
|
||||
virtual int Decode(
|
||||
const ReceivedFrame& received_frame,
|
||||
std::unique_ptr<ReceivedFrame> received_frame,
|
||||
std::function<void(const DecodedFrame&)> on_receive_decoded_frame) = 0;
|
||||
|
||||
virtual std::string GetDecoderName() = 0;
|
||||
|
||||
@@ -733,7 +733,11 @@ bool RtpVideoReceiver::Process() {
|
||||
while (it != pending_frames_.end()) {
|
||||
if (it->second.is_complete) {
|
||||
if (on_receive_complete_frame_) {
|
||||
on_receive_complete_frame_(*(it->second.frame));
|
||||
auto data = it->second.frame->Buffer();
|
||||
if (data == nullptr) {
|
||||
LOG_WARN("data is nullptr!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
}
|
||||
on_receive_complete_frame_(std::move(it->second.frame));
|
||||
}
|
||||
it = pending_frames_.erase(it);
|
||||
} else {
|
||||
|
||||
@@ -44,7 +44,8 @@ class RtpVideoReceiver : public ThreadBase,
|
||||
void SetSendDataFunc(std::function<int(const char*, size_t)> data_send_func);
|
||||
|
||||
void SetOnReceiveCompleteFrame(
|
||||
std::function<void(const ReceivedFrame&)> on_receive_complete_frame) {
|
||||
std::function<void(std::unique_ptr<ReceivedFrame>)>
|
||||
on_receive_complete_frame) {
|
||||
on_receive_complete_frame_ = on_receive_complete_frame;
|
||||
}
|
||||
uint32_t GetSsrc() { return ssrc_; }
|
||||
@@ -99,8 +100,8 @@ class RtpVideoReceiver : public ThreadBase,
|
||||
std::map<uint16_t, RtpPacketAv1> incomplete_av1_frame_list_;
|
||||
std::map<uint16_t, RtpPacket> incomplete_frame_list_;
|
||||
uint8_t* nv12_data_ = nullptr;
|
||||
std::function<void(const ReceivedFrame&)> on_receive_complete_frame_ =
|
||||
nullptr;
|
||||
std::function<void(std::unique_ptr<ReceivedFrame>)>
|
||||
on_receive_complete_frame_ = nullptr;
|
||||
uint32_t last_complete_frame_ts_ = 0;
|
||||
RingBuffer<ReceivedFrame> compelete_video_frame_queue_;
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ VideoChannelReceive::VideoChannelReceive() {}
|
||||
VideoChannelReceive::VideoChannelReceive(
|
||||
std::shared_ptr<SystemClock> clock, std::shared_ptr<IceAgent> ice_agent,
|
||||
std::shared_ptr<IOStatistics> ice_io_statistics,
|
||||
std::function<void(const ReceivedFrame &)> on_receive_complete_frame)
|
||||
std::function<void(std::unique_ptr<ReceivedFrame>)>
|
||||
on_receive_complete_frame)
|
||||
: ice_agent_(ice_agent),
|
||||
ice_io_statistics_(ice_io_statistics),
|
||||
on_receive_complete_frame_(on_receive_complete_frame),
|
||||
@@ -19,8 +20,8 @@ void VideoChannelReceive::Initialize(rtp::PAYLOAD_TYPE payload_type) {
|
||||
rtp_video_receiver_ =
|
||||
std::make_unique<RtpVideoReceiver>(clock_, ice_io_statistics_);
|
||||
rtp_video_receiver_->SetOnReceiveCompleteFrame(
|
||||
[this](const ReceivedFrame &received_frame) -> void {
|
||||
on_receive_complete_frame_(received_frame);
|
||||
[this](std::unique_ptr<ReceivedFrame> received_frame) -> void {
|
||||
on_receive_complete_frame_(std::move(received_frame));
|
||||
});
|
||||
|
||||
rtp_video_receiver_->SetSendDataFunc([this](const char *data,
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
class VideoChannelReceive {
|
||||
public:
|
||||
VideoChannelReceive();
|
||||
VideoChannelReceive(
|
||||
std::shared_ptr<SystemClock> clock, std::shared_ptr<IceAgent> ice_agent,
|
||||
VideoChannelReceive(std::shared_ptr<SystemClock> clock,
|
||||
std::shared_ptr<IceAgent> ice_agent,
|
||||
std::shared_ptr<IOStatistics> ice_io_statistics,
|
||||
std::function<void(const ReceivedFrame &)> on_receive_complete_frame);
|
||||
std::function<void(std::unique_ptr<ReceivedFrame>)>
|
||||
on_receive_complete_frame);
|
||||
|
||||
~VideoChannelReceive();
|
||||
|
||||
@@ -51,8 +52,8 @@ class VideoChannelReceive {
|
||||
std::shared_ptr<IceAgent> ice_agent_ = nullptr;
|
||||
std::shared_ptr<IOStatistics> ice_io_statistics_ = nullptr;
|
||||
std::unique_ptr<RtpVideoReceiver> rtp_video_receiver_ = nullptr;
|
||||
std::function<void(const ReceivedFrame &)> on_receive_complete_frame_ =
|
||||
nullptr;
|
||||
std::function<void(std::unique_ptr<ReceivedFrame>)>
|
||||
on_receive_complete_frame_ = nullptr;
|
||||
|
||||
private:
|
||||
std::shared_ptr<SystemClock> clock_;
|
||||
|
||||
@@ -132,9 +132,9 @@ void IceTransportController::Create(
|
||||
std::weak_ptr<IceTransportController> weak_self = shared_from_this();
|
||||
video_channel_receive_ = std::make_unique<VideoChannelReceive>(
|
||||
clock_, ice_agent, ice_io_statistics,
|
||||
[this, weak_self](const ReceivedFrame& received_frame) {
|
||||
[this, weak_self](std::unique_ptr<ReceivedFrame> received_frame) {
|
||||
if (auto self = weak_self.lock()) {
|
||||
OnReceiveCompleteFrame(received_frame);
|
||||
OnReceiveCompleteFrame(std::move(received_frame));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -314,11 +314,12 @@ int IceTransportController::OnReceiveDataRtpPacket(const char* data,
|
||||
}
|
||||
|
||||
void IceTransportController::OnReceiveCompleteFrame(
|
||||
const ReceivedFrame& received_frame) {
|
||||
task_queue_decode_->PostTask([this, received_frame]() mutable {
|
||||
std::unique_ptr<ReceivedFrame> received_frame) {
|
||||
task_queue_decode_->PostTask(
|
||||
[this, received_frame = std::move(received_frame)]() mutable {
|
||||
if (video_decoder_) {
|
||||
int num_frame_returned = video_decoder_->Decode(
|
||||
received_frame, [this](DecodedFrame decoded_frame) {
|
||||
std::move(received_frame), [this](DecodedFrame decoded_frame) {
|
||||
if (on_receive_video_) {
|
||||
XVideoFrame x_video_frame;
|
||||
x_video_frame.data = (const char*)decoded_frame.Buffer();
|
||||
@@ -331,9 +332,12 @@ void IceTransportController::OnReceiveCompleteFrame(
|
||||
decoded_frame.ReceivedTimestamp();
|
||||
x_video_frame.decoded_timestamp =
|
||||
decoded_frame.DecodedTimestamp();
|
||||
|
||||
if (on_receive_video_) {
|
||||
on_receive_video_(&x_video_frame, remote_user_id_.data(),
|
||||
remote_user_id_.size(), user_data_);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -65,7 +65,7 @@ class IceTransportController
|
||||
int OnReceiveAudioRtpPacket(const char *data, size_t size);
|
||||
int OnReceiveDataRtpPacket(const char *data, size_t size);
|
||||
|
||||
void OnReceiveCompleteFrame(const ReceivedFrame &received_frame);
|
||||
void OnReceiveCompleteFrame(std::unique_ptr<ReceivedFrame> received_frame);
|
||||
void OnReceiveCompleteAudio(const char *data, size_t size);
|
||||
void OnReceiveCompleteData(const char *data, size_t size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user