Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to M118 #26

Merged
merged 12 commits into from
Mar 26, 2024
Merged
4 changes: 4 additions & 0 deletions api/media_stream_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const char* const MediaStreamTrackInterface::kVideoKind =
const char* const MediaStreamTrackInterface::kAudioKind =
cricket::kMediaTypeAudio;

bool VideoTrackInterface::should_receive() const {
return true;
}

VideoTrackInterface::ContentHint VideoTrackInterface::content_hint() const {
return ContentHint::kNone;
}
Expand Down
2 changes: 2 additions & 0 deletions api/media_stream_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ class RTC_EXPORT VideoTrackInterface

virtual VideoTrackSourceInterface* GetSource() const = 0;

virtual void set_should_receive(bool should_receive) {}
virtual bool should_receive() const;
virtual ContentHint content_hint() const;
virtual void set_content_hint(ContentHint hint) {}

Expand Down
2 changes: 2 additions & 0 deletions media/base/media_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,8 @@ class VideoMediaReceiveChannelInterface : public MediaReceiveChannelInterface {
webrtc::RtcpMode rtcp_mode,
absl::optional<int> rtx_time) = 0;
virtual bool AddDefaultRecvStreamForTesting(const StreamParams& sp) = 0;
virtual void StartReceive(uint32_t ssrc) {}
virtual void StopReceive(uint32_t ssrc) {}
};

} // namespace cricket
Expand Down
29 changes: 29 additions & 0 deletions media/engine/webrtc_video_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,24 @@ WebRtcVideoReceiveChannel::~WebRtcVideoReceiveChannel() {
delete kv.second;
}

void WebRtcVideoReceiveChannel::StartReceive(uint32_t ssrc) {
RTC_DCHECK_RUN_ON(&thread_checker_);
WebRtcVideoReceiveStream* stream = FindReceiveStream(ssrc);
if(!stream) {
return;
}
stream->StartStream();
}

void WebRtcVideoReceiveChannel::StopReceive(uint32_t ssrc) {
RTC_DCHECK_RUN_ON(&thread_checker_);
WebRtcVideoReceiveStream* stream = FindReceiveStream(ssrc);
if(!stream) {
return;
}
stream->StopStream();
}

void WebRtcVideoReceiveChannel::SetReceiverFeedbackParameters(
bool lntf_enabled,
bool nack_enabled,
Expand Down Expand Up @@ -3478,6 +3496,17 @@ void WebRtcVideoReceiveChannel::WebRtcVideoReceiveStream::SetReceiverParameters(
}
}

void WebRtcVideoReceiveChannel::WebRtcVideoReceiveStream::StartStream(){
if (stream_) {
stream_->Start();
}
}
void WebRtcVideoReceiveChannel::WebRtcVideoReceiveStream::StopStream(){
if (stream_) {
stream_->Stop();
}
}

void WebRtcVideoReceiveChannel::WebRtcVideoReceiveStream::
RecreateReceiveStream() {
RTC_DCHECK_RUN_ON(&thread_checker_);
Expand Down
6 changes: 5 additions & 1 deletion media/engine/webrtc_video_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ class WebRtcVideoSendChannel : public MediaChannelUtil,
}
return send_codec()->rtx_time;
}

private:
struct ChangedSenderParameters {
// These optionals are unset if not changed.
Expand Down Expand Up @@ -643,6 +642,8 @@ class WebRtcVideoReceiveChannel : public MediaChannelUtil,
webrtc::RtcpMode rtcp_mode,
absl::optional<int> rtx_time) override;

void StartReceive(uint32_t ssrc) override;
void StopReceive(uint32_t ssrc) override;
private:
class WebRtcVideoReceiveStream;
struct ChangedReceiverParameters {
Expand Down Expand Up @@ -744,6 +745,9 @@ class WebRtcVideoReceiveChannel : public MediaChannelUtil,
rtc::scoped_refptr<webrtc::FrameTransformerInterface>
frame_transformer);

void StartStream();
void StopStream();

void SetLocalSsrc(uint32_t local_ssrc);
void UpdateRtxSsrc(uint32_t ssrc);
void StartReceiveStream();
Expand Down
2 changes: 2 additions & 0 deletions pc/media_stream_track_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ PROXY_SECONDARY_METHOD2(void,
PROXY_SECONDARY_METHOD1(void, RemoveSink, rtc::VideoSinkInterface<VideoFrame>*)
PROXY_SECONDARY_METHOD0(void, RequestRefreshFrame)
BYPASS_PROXY_CONSTMETHOD0(VideoTrackSourceInterface*, GetSource)
PROXY_CONSTMETHOD0(bool, should_receive)
PROXY_METHOD1(void, set_should_receive, bool)

PROXY_METHOD1(void, RegisterObserver, ObserverInterface*)
PROXY_METHOD1(void, UnregisterObserver, ObserverInterface*)
Expand Down
41 changes: 40 additions & 1 deletion pc/video_rtp_receiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ VideoRtpReceiver::VideoRtpReceiver(
rtc::Thread::Current(),
worker_thread,
VideoTrack::Create(receiver_id, source_, worker_thread))),
attachment_id_(GenerateUniqueId()) {
cached_track_should_receive_(track_->should_receive()),
attachment_id_(GenerateUniqueId()),
worker_thread_safety_(PendingTaskSafetyFlag::CreateDetachedInactive()) {
RTC_DCHECK(worker_thread_);
SetStreams(streams);
track_->RegisterObserver(this);
RTC_DCHECK_EQ(source_->state(), MediaSourceInterface::kInitializing);
}

VideoRtpReceiver::~VideoRtpReceiver() {
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
RTC_DCHECK(!media_channel_);

track_->UnregisterObserver(this);
}

std::vector<std::string> VideoRtpReceiver::stream_ids() const {
Expand Down Expand Up @@ -114,6 +119,39 @@ void VideoRtpReceiver::Stop() {
track_->internal()->set_ended();
}

void VideoRtpReceiver::OnChanged() {
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
if (cached_track_should_receive_ != track_->should_receive()) {
cached_track_should_receive_ = track_->should_receive();
worker_thread_->PostTask(
[this, receive = cached_track_should_receive_]() {
RTC_DCHECK_RUN_ON(worker_thread_);
if(receive) {
StartMediaChannel();
} else {
StopMediaChannel();
}
});
}
}

void VideoRtpReceiver::StartMediaChannel() {
RTC_DCHECK_RUN_ON(worker_thread_);
if (!media_channel_) {
return;
}
media_channel_->StartReceive(signaled_ssrc_.value_or(0));
OnGenerateKeyFrame();
}

void VideoRtpReceiver::StopMediaChannel() {
RTC_DCHECK_RUN_ON(worker_thread_);
if (!media_channel_) {
return;
}
media_channel_->StopReceive(signaled_ssrc_.value_or(0));
}

void VideoRtpReceiver::RestartMediaChannel(absl::optional<uint32_t> ssrc) {
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
MediaSourceInterface::SourceState state = source_->state();
Expand Down Expand Up @@ -209,6 +247,7 @@ void VideoRtpReceiver::set_transport(
void VideoRtpReceiver::SetStreams(
const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);

// Remove remote track from any streams that are going away.
for (const auto& existing_stream : streams_) {
bool removed = true;
Expand Down
11 changes: 10 additions & 1 deletion pc/video_rtp_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@

namespace webrtc {

class VideoRtpReceiver : public RtpReceiverInternal {
class VideoRtpReceiver : public RtpReceiverInternal,
public ObserverInterface {
public:
// An SSRC of 0 will create a receiver that will match the first SSRC it
// sees. Must be called on signaling thread.
Expand All @@ -60,6 +61,9 @@ class VideoRtpReceiver : public RtpReceiverInternal {

rtc::scoped_refptr<VideoTrackInterface> video_track() const { return track_; }

// ObserverInterface implementation
void OnChanged() override;

// RtpReceiverInterface implementation
rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
return track_;
Expand Down Expand Up @@ -115,6 +119,8 @@ class VideoRtpReceiver : public RtpReceiverInternal {
cricket::MediaReceiveChannelInterface* media_channel);

private:
void StartMediaChannel();
void StopMediaChannel();
void RestartMediaChannel(absl::optional<uint32_t> ssrc)
RTC_RUN_ON(&signaling_thread_checker_);
void RestartMediaChannel_w(absl::optional<uint32_t> ssrc,
Expand Down Expand Up @@ -162,6 +168,8 @@ class VideoRtpReceiver : public RtpReceiverInternal {
RTC_GUARDED_BY(&signaling_thread_checker_) = nullptr;
bool received_first_packet_ RTC_GUARDED_BY(&signaling_thread_checker_) =
false;

bool cached_track_should_receive_ RTC_GUARDED_BY(&signaling_thread_checker_);
const int attachment_id_;
rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor_
RTC_GUARDED_BY(worker_thread_);
Expand All @@ -177,6 +185,7 @@ class VideoRtpReceiver : public RtpReceiverInternal {
// or switched.
bool saved_generate_keyframe_ RTC_GUARDED_BY(worker_thread_) = false;
bool saved_encoded_sink_enabled_ RTC_GUARDED_BY(worker_thread_) = false;
const rtc::scoped_refptr<PendingTaskSafetyFlag> worker_thread_safety_;
};

} // namespace webrtc
Expand Down
13 changes: 13 additions & 0 deletions pc/video_track.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ VideoTrackSourceInterface* VideoTrack::GetSourceInternal() const {
return video_source_->internal();
}

void VideoTrack::set_should_receive(bool receive) {
RTC_DCHECK_RUN_ON(&signaling_thread_);
if (should_receive_ == receive)
return;
should_receive_ = receive;
Notifier<VideoTrackInterface>::FireOnChanged();
}

bool VideoTrack::should_receive() const {
RTC_DCHECK_RUN_ON(&signaling_thread_);
return should_receive_;
}

VideoTrackInterface::ContentHint VideoTrack::content_hint() const {
RTC_DCHECK_RUN_ON(&signaling_thread_);
return content_hint_;
Expand Down
4 changes: 4 additions & 0 deletions pc/video_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class VideoTrack : public MediaStreamTrack<VideoTrackInterface>,
void RequestRefreshFrame() override;
VideoTrackSourceInterface* GetSource() const override;

void set_should_receive(bool should_receive) override;
bool should_receive() const override;

ContentHint content_hint() const override;
void set_content_hint(ContentHint hint) override;
bool set_enabled(bool enable) override;
Expand Down Expand Up @@ -81,6 +84,7 @@ class VideoTrack : public MediaStreamTrack<VideoTrackInterface>,
// be queried without blocking on the worker thread by callers that don't
// use an api proxy to call the `enabled()` method.
bool enabled_w_ RTC_GUARDED_BY(worker_thread_) = true;
bool should_receive_ RTC_GUARDED_BY(signaling_thread_) = true;
};

} // namespace webrtc
Expand Down
23 changes: 23 additions & 0 deletions sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ if (is_ios || is_mac) {
]

deps = [
":simulcast",
":base_objc",
":native_video",
":videocodec_objc",
Expand Down Expand Up @@ -807,6 +808,22 @@ if (is_ios || is_mac) {
]
}

rtc_library("simulcast") {
sources = [
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.h",
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.mm",
"objc/api/video_codec/RTCVideoEncoderSimulcast.h",
"objc/api/video_codec/RTCVideoEncoderSimulcast.mm",
]

deps = [
":base_objc",
":wrapped_native_codec_objc",
"../media:rtc_media_base",
"../media:rtc_simulcast_encoder_adapter",
]
}

rtc_library("libaom_av1_encoder") {
visibility = [ "*" ]
allow_poison = [ "software_video_codecs" ]
Expand Down Expand Up @@ -1334,6 +1351,9 @@ if (is_ios || is_mac) {
"objc/api/video_codec/RTCVideoEncoderAV1.h",
"objc/api/video_frame_buffer/RTCNativeI420Buffer.h",
"objc/api/video_frame_buffer/RTCNativeMutableI420Buffer.h",
# Added for Simulcast support
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.h",
"objc/api/video_codec/RTCVideoEncoderSimulcast.h",
]

if (!build_with_chromium) {
Expand Down Expand Up @@ -1478,6 +1498,9 @@ if (is_ios || is_mac) {
"objc/components/video_codec/RTCVideoEncoderH264.h",
"objc/components/video_frame_buffer/RTCCVPixelBuffer.h",
"objc/helpers/RTCDispatcher.h",
# Added for Simulcast support
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.h",
"objc/api/video_codec/RTCVideoEncoderSimulcast.h",
]
if (!build_with_chromium) {
sources += [
Expand Down
27 changes: 27 additions & 0 deletions sdk/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ if (is_android) {
"api/org/webrtc/WrappedNativeVideoEncoder.java",
"api/org/webrtc/YuvConverter.java",
"api/org/webrtc/YuvHelper.java",
"api/org/webrtc/ResolutionAdjustment.java",
"src/java/org/webrtc/EglBase10Impl.java",
"src/java/org/webrtc/EglBase14Impl.java",
"src/java/org/webrtc/GlGenericDrawer.java",
Expand Down Expand Up @@ -362,6 +363,9 @@ if (is_android) {
sources = [
"api/org/webrtc/DefaultVideoDecoderFactory.java",
"api/org/webrtc/DefaultVideoEncoderFactory.java",
"api/org/webrtc/WrappedVideoDecoderFactory.java",
"api/org/webrtc/DefaultAlignedVideoEncoderFactory.java",
"api/org/webrtc/SimulcastAlignedVideoEncoderFactory.java",
]

deps = [
Expand Down Expand Up @@ -393,6 +397,8 @@ if (is_android) {
sources = [
"api/org/webrtc/HardwareVideoDecoderFactory.java",
"api/org/webrtc/HardwareVideoEncoderFactory.java",
"api/org/webrtc/HardwareVideoEncoderWrapper.java",
"api/org/webrtc/HardwareVideoEncoderWrapperFactory.java",
"api/org/webrtc/PlatformSoftwareVideoDecoderFactory.java",
"src/java/org/webrtc/AndroidVideoDecoder.java",
"src/java/org/webrtc/BaseBitrateAdjuster.java",
Expand Down Expand Up @@ -428,6 +434,7 @@ if (is_android) {
"src/java/org/webrtc/audio/WebRtcAudioRecord.java",
"src/java/org/webrtc/audio/WebRtcAudioTrack.java",
"src/java/org/webrtc/audio/WebRtcAudioUtils.java",
"src/java/org/webrtc/audio/AudioRecordDataCallback.java",
]

deps = [
Expand Down Expand Up @@ -525,6 +532,8 @@ if (is_android) {
sources = [
"api/org/webrtc/SoftwareVideoDecoderFactory.java",
"api/org/webrtc/SoftwareVideoEncoderFactory.java",
"api/org/webrtc/SimulcastVideoEncoder.java",
"api/org/webrtc/SimulcastVideoEncoderFactory.java",
]

deps = [
Expand Down Expand Up @@ -864,6 +873,23 @@ if (current_os == "linux" || is_android) {
]
}

rtc_library("simulcast_jni") {
visibility = [ "*" ]
allow_poison = [ "software_video_codecs" ]
sources = [
"src/jni/simulcast_video_encoder.cc",
"src/jni/simulcast_video_encoder.h",
"src/jni/simulcast_video_encoder_factory.cc",
"src/jni/simulcast_video_encoder_factory.h"
]
deps = [
":base_jni",
":video_jni",
":native_api_codecs",
"../../media:rtc_simulcast_encoder_adapter"
]
}

rtc_library("libaom_av1_encoder_jni") {
visibility = [ "*" ]
allow_poison = [ "software_video_codecs" ]
Expand Down Expand Up @@ -900,6 +926,7 @@ if (current_os == "linux" || is_android) {
":generated_swcodecs_jni",
":libvpx_vp8_jni",
":libvpx_vp9_jni",
":simulcast_jni",
":native_api_jni",
":video_jni",
"../../api/video_codecs:builtin_video_decoder_factory",
Expand Down
Loading