Commit 2b070ce1 authored by Byron Campen's avatar Byron Campen
Browse files

Bug 1822194 - Vendor libwebrtc from 893c0e449d

Upstream commit: https://webrtc.googlesource.com/src/+/893c0e449dcbe4804edf42fb17031015c2601292
    Allow Video Sender OnTransformedFrame() before TransformFrame()

    Lazily initialize the RTPSenderVideoFrameTransformerDelegate's
    encoder_queue_ on either OnTransformedFrame() or TransformFrame(), to
    allow apps to write to an encoded insertable stream's writable before
    reading from its readable.

    Bug: chromium:1393373
    Change-Id: I08f11682fa142884b575bb207d7d7044e80bbb9c
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/284921


    Reviewed-by: default avatarHarald Alvestrand <hta@webrtc.org>
    Commit-Queue: Tony Herre <herre@google.com>
    Auto-Submit: Tony Herre <herre@google.com>
    Commit-Queue: Harald Alvestrand <hta@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#38728}
parent 79d58605
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -19785,3 +19785,6 @@ a7013ee650
# MOZ_LIBWEBRTC_SRC=/home/bcampen/checkouts/moz-libwebrtc MOZ_LIBWEBRTC_BRANCH=mozpatches bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh
# base of lastest vendoring
d6b330ea77
# MOZ_LIBWEBRTC_SRC=/home/bcampen/checkouts/moz-libwebrtc MOZ_LIBWEBRTC_BRANCH=mozpatches bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh
# base of lastest vendoring
893c0e449d
+2 −0
Original line number Diff line number Diff line
@@ -13212,3 +13212,5 @@ libwebrtc updated from /home/bcampen/checkouts/moz-libwebrtc commit mozpatches o
libwebrtc updated from /home/bcampen/checkouts/moz-libwebrtc commit mozpatches on 2023-04-01T00:12:50.725985.
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/bcampen/checkouts/moz-libwebrtc --commit mozpatches libwebrtc
libwebrtc updated from /home/bcampen/checkouts/moz-libwebrtc commit mozpatches on 2023-04-01T00:14:12.197553.
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/bcampen/checkouts/moz-libwebrtc --commit mozpatches libwebrtc
libwebrtc updated from /home/bcampen/checkouts/moz-libwebrtc commit mozpatches on 2023-04-01T00:15:36.738269.
+17 −11
Original line number Diff line number Diff line
@@ -112,14 +112,9 @@ void RTPSenderVideoFrameTransformerDelegate::Init() {
      rtc::scoped_refptr<TransformedFrameCallback>(this), ssrc_);
}

bool RTPSenderVideoFrameTransformerDelegate::TransformFrame(
    int payload_type,
    absl::optional<VideoCodecType> codec_type,
    uint32_t rtp_timestamp,
    const EncodedImage& encoded_image,
    RTPVideoHeader video_header,
    absl::optional<int64_t> expected_retransmission_time_ms) {
void RTPSenderVideoFrameTransformerDelegate::EnsureEncoderQueueCreated() {
  TaskQueueBase* current = 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.
@@ -133,6 +128,18 @@ bool RTPSenderVideoFrameTransformerDelegate::TransformFrame(
      encoder_queue_ = owned_encoder_queue_.get();
    }
  }
}

bool RTPSenderVideoFrameTransformerDelegate::TransformFrame(
    int payload_type,
    absl::optional<VideoCodecType> codec_type,
    uint32_t rtp_timestamp,
    const EncodedImage& encoded_image,
    RTPVideoHeader video_header,
    absl::optional<int64_t> expected_retransmission_time_ms) {
  EnsureEncoderQueueCreated();

  TaskQueueBase* current = TaskQueueBase::Current();
  // DCHECK that the current queue does not change, or if does then it was due
  // to a hardware encoder fallback and thus there is an owned queue.
  RTC_DCHECK(!current || current == encoder_queue_ || owned_encoder_queue_)
@@ -152,10 +159,9 @@ void RTPSenderVideoFrameTransformerDelegate::OnTransformedFrame(
    std::unique_ptr<TransformableFrameInterface> frame) {
  MutexLock lock(&sender_lock_);

  // The encoder queue normally gets destroyed after the sender;
  // however, it might still be null by the time a previously queued frame
  // arrives.
  if (!sender_ || !encoder_queue_)
  EnsureEncoderQueueCreated();

  if (!sender_)
    return;
  rtc::scoped_refptr<RTPSenderVideoFrameTransformerDelegate> delegate(this);
  encoder_queue_->PostTask(
+2 −0
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ class RTPSenderVideoFrameTransformerDelegate : public TransformedFrameCallback {
  ~RTPSenderVideoFrameTransformerDelegate() override = default;

 private:
  void EnsureEncoderQueueCreated();

  mutable Mutex sender_lock_;
  RTPSenderVideo* sender_ RTC_GUARDED_BY(sender_lock_);
  rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_;