Skip to content

Commit

Permalink
[M84][InsertableStreams] Send transformed frames on worker queue.
Browse files Browse the repository at this point in the history
When video frame encoding is done on an external thread (for example in
the case of hardware encoders), the WebRTC TaskQueueBase::Current() is
null; in this case use the worker queue instead to send transformed
frames.

(cherry picked from commit 2e69660)

Bug: chromium:1086373
Change-Id: I903ddc52ad6832557fc5b5f76396fe26cf5a88f3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176303
Reviewed-by: Magnus Flodman <mflodman@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Marina Ciocea <marinaciocea@webrtc.org>
Cr-Original-Commit-Position: refs/heads/master@{#31388}
TBR: marinaciocea@webrtc.org
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176844
Commit-Queue: Guido Urdaneta <guidou@webrtc.org>
Reviewed-by: Guido Urdaneta <guidou@webrtc.org>
Cr-Commit-Position: refs/branch-heads/4147@{#6}
Cr-Branched-From: 2b7d969-refs/heads/master@{#31262}
  • Loading branch information
Marina Ciocea authored and Commit Bot committed Jun 10, 2020
1 parent 0ddafe3 commit 1b649a8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions call/rtp_video_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/location.h"
#include "rtc_base/logging.h"
#include "rtc_base/task_queue.h"

namespace webrtc {

Expand Down Expand Up @@ -281,6 +282,7 @@ std::vector<RtpStreamSender> CreateRtpStreamSenders(
video_config.fec_overhead_bytes = fec_generator->MaxPacketOverhead();
}
video_config.frame_transformer = frame_transformer;
video_config.worker_queue = transport->GetWorkerQueue()->Get();
auto sender_video = std::make_unique<RTPSenderVideo>(video_config);
rtp_streams.emplace_back(std::move(rtp_rtcp), std::move(sender_video),
std::move(fec_generator));
Expand Down
3 changes: 2 additions & 1 deletion modules/rtp_rtcp/source/rtp_sender_video.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ RTPSenderVideo::RTPSenderVideo(const Config& config)
RTPSenderVideoFrameTransformerDelegate>(
this,
config.frame_transformer,
rtp_sender_->SSRC())
rtp_sender_->SSRC(),
config.worker_queue)
: nullptr) {
if (frame_transformer_delegate_)
frame_transformer_delegate_->Init();
Expand Down
2 changes: 2 additions & 0 deletions modules/rtp_rtcp/source/rtp_sender_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "api/array_view.h"
#include "api/frame_transformer_interface.h"
#include "api/scoped_refptr.h"
#include "api/task_queue/task_queue_base.h"
#include "api/transport/rtp/dependency_descriptor.h"
#include "api/video/video_codec_type.h"
#include "api/video/video_frame_type.h"
Expand Down Expand Up @@ -81,6 +82,7 @@ class RTPSenderVideo {
absl::optional<int> red_payload_type;
const WebRtcKeyValueConfig* field_trials = nullptr;
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer;
TaskQueueBase* worker_queue = nullptr;
};

explicit RTPSenderVideo(const Config& config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ class TransformableVideoSenderFrame : public TransformableVideoFrameInterface {
RTPSenderVideoFrameTransformerDelegate::RTPSenderVideoFrameTransformerDelegate(
RTPSenderVideo* sender,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
uint32_t ssrc)
uint32_t ssrc,
TaskQueueBase* worker_queue)
: sender_(sender),
frame_transformer_(std::move(frame_transformer)),
ssrc_(ssrc) {}
ssrc_(ssrc),
worker_queue_(worker_queue) {}

void RTPSenderVideoFrameTransformerDelegate::Init() {
frame_transformer_->RegisterTransformedFrameSinkCallback(
Expand All @@ -123,8 +125,14 @@ bool RTPSenderVideoFrameTransformerDelegate::TransformFrame(
const RTPFragmentationHeader* fragmentation,
RTPVideoHeader video_header,
absl::optional<int64_t> expected_retransmission_time_ms) {
if (!encoder_queue_)
encoder_queue_ = TaskQueueBase::Current();
if (!encoder_queue_) {
// Save the current task queue to post the transformed frame for sending
// once it is transformed. When there is no current task queue, i.e.
// encoding is done on an external thread (for example in the case of
// hardware encoders), use the worker queue instead.
TaskQueueBase* current = TaskQueueBase::Current();
encoder_queue_ = current ? current : worker_queue_;
}
frame_transformer_->Transform(std::make_unique<TransformableVideoSenderFrame>(
encoded_image, video_header, payload_type, codec_type, rtp_timestamp,
fragmentation, expected_retransmission_time_ms, ssrc_));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class RTPSenderVideoFrameTransformerDelegate : public TransformedFrameCallback {
RTPSenderVideoFrameTransformerDelegate(
RTPSenderVideo* sender,
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
uint32_t ssrc);
uint32_t ssrc,
TaskQueueBase* worker_queue);

void Init();

Expand Down Expand Up @@ -69,6 +70,7 @@ class RTPSenderVideoFrameTransformerDelegate : public TransformedFrameCallback {
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_;
const uint32_t ssrc_;
TaskQueueBase* encoder_queue_ = nullptr;
TaskQueueBase* worker_queue_;
};

} // namespace webrtc
Expand Down

0 comments on commit 1b649a8

Please sign in to comment.