Skip to content

Commit

Permalink
RtpReceiverInterface::stream_ids() added.
Browse files Browse the repository at this point in the history
This is the first step to removing streams from third_party/webrtc.
RtpReceiverInterface::streams() will have to be removed separately.
See https://crbug.com/webrtc/9480 for more information.

Bug: webrtc:9480
Change-Id: I6f9e6ddcda5e2245cc601d2cc6205b7b363f73ef
Reviewed-on: https://webrtc-review.googlesource.com/86840
Reviewed-by: Seth Hampson <[email protected]>
Reviewed-by: Steve Anton <[email protected]>
Commit-Queue: Henrik Boström <[email protected]>
Cr-Commit-Position: refs/heads/master@{#23929}
  • Loading branch information
henbos authored and Commit Bot committed Jul 11, 2018
1 parent f957dd9 commit 199e27b
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 12 deletions.
4 changes: 4 additions & 0 deletions api/rtpreceiverinterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ RtpSource::RtpSource(const RtpSource&) = default;
RtpSource& RtpSource::operator=(const RtpSource&) = default;
RtpSource::~RtpSource() = default;

std::vector<std::string> RtpReceiverInterface::stream_ids() const {
return {};
}

std::vector<rtc::scoped_refptr<MediaStreamInterface>>
RtpReceiverInterface::streams() const {
return {};
Expand Down
6 changes: 5 additions & 1 deletion api/rtpreceiverinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ class RtpReceiverInterface : public rtc::RefCountInterface {
virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
// The list of streams that |track| is associated with. This is the same as
// the [[AssociatedRemoteMediaStreams]] internal slot in the spec.
// https://w3c.github.io/webrtc-pc/#dfn-x%5B%5Bassociatedremotemediastreams%5D%5D
// https://w3c.github.io/webrtc-pc/#dfn-associatedremotemediastreams
// TODO(hbos): Make pure virtual as soon as Chromium's mock implements this.
// TODO(https://crbug.com/webrtc/9480): Remove streams() in favor of
// stream_ids() as soon as downstream projects are no longer dependent on
// stream objects.
virtual std::vector<std::string> stream_ids() const;
virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() const;

// Audio or video receiver?
Expand Down
14 changes: 8 additions & 6 deletions ortc/ortcrtpreceiveradapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#include "ortc/ortcrtpreceiveradapter.h"

#include <string>
#include <utility>
#include <vector>

#include "media/base/mediaconstants.h"
#include "ortc/rtptransportadapter.h"
Expand Down Expand Up @@ -151,19 +153,19 @@ void OrtcRtpReceiverAdapter::MaybeRecreateInternalReceiver() {
internal_receiver_ = nullptr;
switch (kind_) {
case cricket::MEDIA_TYPE_AUDIO: {
auto* audio_receiver =
new AudioRtpReceiver(rtp_transport_controller_->worker_thread(),
rtc::CreateRandomUuid(), {});
auto* audio_receiver = new AudioRtpReceiver(
rtp_transport_controller_->worker_thread(), rtc::CreateRandomUuid(),
std::vector<std::string>({}));
auto* voice_channel = rtp_transport_controller_->voice_channel();
RTC_DCHECK(voice_channel);
audio_receiver->SetVoiceMediaChannel(voice_channel->media_channel());
internal_receiver_ = audio_receiver;
break;
}
case cricket::MEDIA_TYPE_VIDEO: {
auto* video_receiver =
new VideoRtpReceiver(rtp_transport_controller_->worker_thread(),
rtc::CreateRandomUuid(), {});
auto* video_receiver = new VideoRtpReceiver(
rtp_transport_controller_->worker_thread(), rtc::CreateRandomUuid(),
std::vector<std::string>({}));
auto* video_channel = rtp_transport_controller_->video_channel();
RTC_DCHECK(video_channel);
video_receiver->SetVideoMediaChannel(video_channel->media_channel());
Expand Down
19 changes: 14 additions & 5 deletions pc/peerconnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1478,14 +1478,14 @@ PeerConnection::CreateReceiver(cricket::MediaType media_type,
receiver;
if (media_type == cricket::MEDIA_TYPE_AUDIO) {
receiver = RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
signaling_thread(),
new AudioRtpReceiver(worker_thread(), receiver_id, {}));
signaling_thread(), new AudioRtpReceiver(worker_thread(), receiver_id,
std::vector<std::string>({})));
NoteUsageEvent(UsageEvent::AUDIO_ADDED);
} else {
RTC_DCHECK_EQ(media_type, cricket::MEDIA_TYPE_VIDEO);
receiver = RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
signaling_thread(),
new VideoRtpReceiver(worker_thread(), receiver_id, {}));
signaling_thread(), new VideoRtpReceiver(worker_thread(), receiver_id,
std::vector<std::string>({})));
NoteUsageEvent(UsageEvent::VIDEO_ADDED);
}
return receiver;
Expand Down Expand Up @@ -2442,6 +2442,8 @@ RTCError PeerConnection::ApplyRemoteDescription(
media_streams.push_back(stream);
}
// This will add the remote track to the streams.
// TODO(hbos): When we remove remote_streams(), use set_stream_ids()
// instead. https://crbug.com/webrtc/9480
transceiver->internal()->receiver_internal()->SetStreams(media_streams);
now_receiving_transceivers.push_back(transceiver);
}
Expand All @@ -2456,9 +2458,12 @@ RTCError PeerConnection::ApplyRemoteDescription(
std::vector<rtc::scoped_refptr<MediaStreamInterface>> media_streams =
transceiver->internal()->receiver_internal()->streams();
// This will remove the remote track from the streams.
transceiver->internal()->receiver_internal()->SetStreams({});
transceiver->internal()->receiver_internal()->set_stream_ids({});
no_longer_receiving_transceivers.push_back(transceiver);
// Remove any streams that no longer have tracks.
// TODO(https://crbug.com/webrtc/9480): When we use stream IDs instead
// of streams, see if the stream was removed by checking if this was the
// last receiver with that stream ID.
for (auto stream : media_streams) {
if (stream->GetAudioTracks().empty() &&
stream->GetVideoTracks().empty()) {
Expand Down Expand Up @@ -3370,6 +3375,8 @@ void PeerConnection::CreateAudioReceiver(
const RtpSenderInfo& remote_sender_info) {
std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams;
streams.push_back(rtc::scoped_refptr<MediaStreamInterface>(stream));
// TODO(https://crbug.com/webrtc/9480): When we remove remote_streams(), use
// the constructor taking stream IDs instead.
auto* audio_receiver = new AudioRtpReceiver(
worker_thread(), remote_sender_info.sender_id, streams);
audio_receiver->SetVoiceMediaChannel(voice_media_channel());
Expand All @@ -3386,6 +3393,8 @@ void PeerConnection::CreateVideoReceiver(
const RtpSenderInfo& remote_sender_info) {
std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams;
streams.push_back(rtc::scoped_refptr<MediaStreamInterface>(stream));
// TODO(https://crbug.com/webrtc/9480): When we remove remote_streams(), use
// the constructor taking stream IDs instead.
auto* video_receiver = new VideoRtpReceiver(
worker_thread(), remote_sender_info.sender_id, streams);
video_receiver->SetVideoMediaChannel(video_media_channel());
Expand Down
49 changes: 49 additions & 0 deletions pc/rtpreceiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#include <utility>
#include <vector>

#include "api/mediastreamproxy.h"
#include "api/mediastreamtrackproxy.h"
#include "api/videosourceproxy.h"
#include "pc/audiotrack.h"
#include "pc/mediastream.h"
#include "pc/videotrack.h"
#include "rtc_base/trace_event.h"

Expand All @@ -30,8 +32,26 @@ int GenerateUniqueId() {
return ++g_unique_id;
}

std::vector<rtc::scoped_refptr<MediaStreamInterface>> CreateStreamsFromIds(
std::vector<std::string> stream_ids) {
std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams(
stream_ids.size());
for (size_t i = 0; i < stream_ids.size(); ++i) {
streams[i] = MediaStreamProxy::Create(
rtc::Thread::Current(), MediaStream::Create(std::move(stream_ids[i])));
}
return streams;
}

} // namespace

AudioRtpReceiver::AudioRtpReceiver(rtc::Thread* worker_thread,
std::string receiver_id,
std::vector<std::string> stream_ids)
: AudioRtpReceiver(worker_thread,
receiver_id,
CreateStreamsFromIds(std::move(stream_ids))) {}

AudioRtpReceiver::AudioRtpReceiver(
rtc::Thread* worker_thread,
const std::string& receiver_id,
Expand Down Expand Up @@ -92,6 +112,13 @@ void AudioRtpReceiver::OnSetVolume(double volume) {
}
}

std::vector<std::string> AudioRtpReceiver::stream_ids() const {
std::vector<std::string> stream_ids(streams_.size());
for (size_t i = 0; i < streams_.size(); ++i)
stream_ids[i] = streams_[i]->id();
return stream_ids;
}

RtpParameters AudioRtpReceiver::GetParameters() const {
if (!media_channel_ || !ssrc_ || stopped_) {
return RtpParameters();
Expand Down Expand Up @@ -141,6 +168,10 @@ void AudioRtpReceiver::SetupMediaChannel(uint32_t ssrc) {
Reconfigure();
}

void AudioRtpReceiver::set_stream_ids(std::vector<std::string> stream_ids) {
SetStreams(CreateStreamsFromIds(std::move(stream_ids)));
}

void AudioRtpReceiver::SetStreams(
const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {
// Remove remote track from any streams that are going away.
Expand Down Expand Up @@ -209,6 +240,13 @@ void AudioRtpReceiver::NotifyFirstPacketReceived() {
received_first_packet_ = true;
}

VideoRtpReceiver::VideoRtpReceiver(rtc::Thread* worker_thread,
std::string receiver_id,
std::vector<std::string> stream_ids)
: VideoRtpReceiver(worker_thread,
receiver_id,
CreateStreamsFromIds(std::move(stream_ids))) {}

VideoRtpReceiver::VideoRtpReceiver(
rtc::Thread* worker_thread,
const std::string& receiver_id,
Expand Down Expand Up @@ -237,6 +275,13 @@ VideoRtpReceiver::~VideoRtpReceiver() {
Stop();
}

std::vector<std::string> VideoRtpReceiver::stream_ids() const {
std::vector<std::string> stream_ids(streams_.size());
for (size_t i = 0; i < streams_.size(); ++i)
stream_ids[i] = streams_[i]->id();
return stream_ids;
}

bool VideoRtpReceiver::SetSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
RTC_DCHECK(media_channel_);
RTC_DCHECK(ssrc_);
Expand Down Expand Up @@ -294,6 +339,10 @@ void VideoRtpReceiver::SetupMediaChannel(uint32_t ssrc) {
SetSink(source_->sink());
}

void VideoRtpReceiver::set_stream_ids(std::vector<std::string> stream_ids) {
SetStreams(CreateStreamsFromIds(std::move(stream_ids)));
}

void VideoRtpReceiver::SetStreams(
const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {
// Remove remote track from any streams that are going away.
Expand Down
17 changes: 17 additions & 0 deletions pc/rtpreceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class RtpReceiverInternal : public RtpReceiverInterface {
// Set the associated remote media streams for this receiver. The remote track
// will be removed from any streams that are no longer present and added to
// any new streams.
virtual void set_stream_ids(std::vector<std::string> stream_ids) = 0;
// TODO(https://crbug.com/webrtc/9480): Remove SetStreams() in favor of
// set_stream_ids() as soon as downstream projects are no longer dependent on
// stream objects.
virtual void SetStreams(
const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) = 0;

Expand All @@ -72,6 +76,10 @@ class AudioRtpReceiver : public ObserverInterface,
public AudioSourceInterface::AudioObserver,
public rtc::RefCountedObject<RtpReceiverInternal> {
public:
AudioRtpReceiver(rtc::Thread* worker_thread,
std::string receiver_id,
std::vector<std::string> stream_ids);
// TODO(https://crbug.com/webrtc/9480): Remove this when streams() is removed.
AudioRtpReceiver(
rtc::Thread* worker_thread,
const std::string& receiver_id,
Expand All @@ -92,6 +100,7 @@ class AudioRtpReceiver : public ObserverInterface,
rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
return track_.get();
}
std::vector<std::string> stream_ids() const override;
std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams()
const override {
return streams_;
Expand All @@ -111,6 +120,7 @@ class AudioRtpReceiver : public ObserverInterface,
void SetupMediaChannel(uint32_t ssrc) override;
uint32_t ssrc() const override { return ssrc_.value_or(0); }
void NotifyFirstPacketReceived() override;
void set_stream_ids(std::vector<std::string> stream_ids) override;
void SetStreams(const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&
streams) override;

Expand Down Expand Up @@ -151,6 +161,11 @@ class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInternal> {
public:
// An SSRC of 0 will create a receiver that will match the first SSRC it
// sees.
VideoRtpReceiver(rtc::Thread* worker_thread,
std::string receiver_id,
std::vector<std::string> streams_ids);
// TODO(hbos): Remove this when streams() is removed.
// https://crbug.com/webrtc/9480
VideoRtpReceiver(
rtc::Thread* worker_thread,
const std::string& receiver_id,
Expand All @@ -166,6 +181,7 @@ class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInternal> {
rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
return track_.get();
}
std::vector<std::string> stream_ids() const override;
std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams()
const override {
return streams_;
Expand All @@ -185,6 +201,7 @@ class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInternal> {
void SetupMediaChannel(uint32_t ssrc) override;
uint32_t ssrc() const override { return ssrc_.value_or(0); }
void NotifyFirstPacketReceived() override;
void set_stream_ids(std::vector<std::string> stream_ids) override;
void SetStreams(const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&
streams) override;

Expand Down
2 changes: 2 additions & 0 deletions pc/test/mock_rtpreceiverinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MockRtpReceiverInternal : public RtpReceiverInternal {
// RtpReceiverInterface methods.
MOCK_METHOD1(SetTrack, void(MediaStreamTrackInterface*));
MOCK_CONST_METHOD0(track, rtc::scoped_refptr<MediaStreamTrackInterface>());
MOCK_CONST_METHOD0(stream_ids, std::vector<std::string>());
MOCK_CONST_METHOD0(streams,
std::vector<rtc::scoped_refptr<MediaStreamInterface>>());
MOCK_CONST_METHOD0(media_type, cricket::MediaType());
Expand All @@ -41,6 +42,7 @@ class MockRtpReceiverInternal : public RtpReceiverInternal {
MOCK_METHOD1(SetupMediaChannel, void(uint32_t));
MOCK_CONST_METHOD0(ssrc, uint32_t());
MOCK_METHOD0(NotifyFirstPacketReceived, void());
MOCK_METHOD1(set_stream_ids, void(std::vector<std::string>));
MOCK_METHOD1(
SetStreams,
void(const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&));
Expand Down

0 comments on commit 199e27b

Please sign in to comment.