Chromium Code Reviews| Index: webrtc/video/call.cc |
| diff --git a/webrtc/video/call.cc b/webrtc/video/call.cc |
| index cde41bc77a69d589c2cdb18620fbb981371ef9db..539a0d97520e4e981025418791b834b9b64bd69b 100644 |
| --- a/webrtc/video/call.cc |
| +++ b/webrtc/video/call.cc |
| @@ -109,6 +109,16 @@ class Call : public webrtc::Call, public PacketReceiver { |
| void SetBitrateControllerConfig( |
| const webrtc::Call::Config::BitrateConfig& bitrate_config); |
| + void AddAudioReceiveStreamSync(AudioReceiveStream* stream) |
| + EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| + void RemoveAudioReceiveStreamSync(AudioReceiveStream* stream) |
| + EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| + |
| + void AddVideoReceiveStreamSync(VideoReceiveStream* stream) |
| + EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| + void RemoveVideoReceiveStreamSync(VideoReceiveStream* stream) |
| + EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| + |
| const int num_cpu_cores_; |
| const rtc::scoped_ptr<ProcessThread> module_process_thread_; |
| const rtc::scoped_ptr<ChannelGroup> channel_group_; |
| @@ -130,6 +140,8 @@ class Call : public webrtc::Call, public PacketReceiver { |
| GUARDED_BY(receive_crit_); |
| std::set<VideoReceiveStream*> video_receive_streams_ |
| GUARDED_BY(receive_crit_); |
| + std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
| + GUARDED_BY(receive_crit_); |
| rtc::scoped_ptr<RWLockWrapper> send_crit_; |
| std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); |
| @@ -219,6 +231,7 @@ webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
| DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| audio_receive_ssrcs_.end()); |
| audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| + AddAudioReceiveStreamSync(receive_stream); |
| } |
| return receive_stream; |
| } |
| @@ -234,6 +247,7 @@ void Call::DestroyAudioReceiveStream( |
| size_t num_deleted = audio_receive_ssrcs_.erase( |
| audio_receive_stream->config().rtp.remote_ssrc); |
| DCHECK(num_deleted == 1); |
| + RemoveAudioReceiveStreamSync(audio_receive_stream); |
| } |
| delete audio_receive_stream; |
| } |
| @@ -324,8 +338,11 @@ webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
| video_receive_ssrcs_[it->second.ssrc] = receive_stream; |
| video_receive_streams_.insert(receive_stream); |
| + AddVideoReceiveStreamSync(receive_stream); |
| + |
| if (!network_enabled_) |
| receive_stream->SignalNetworkState(kNetworkDown); |
| + |
| return receive_stream; |
| } |
| @@ -333,7 +350,6 @@ void Call::DestroyVideoReceiveStream( |
| webrtc::VideoReceiveStream* receive_stream) { |
| TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
| DCHECK(receive_stream != nullptr); |
| - |
| VideoReceiveStream* receive_stream_impl = nullptr; |
| { |
| WriteLockScoped write_lock(*receive_crit_); |
| @@ -351,8 +367,9 @@ void Call::DestroyVideoReceiveStream( |
| } |
| } |
| video_receive_streams_.erase(receive_stream_impl); |
| + CHECK(receive_stream_impl != nullptr); |
| + RemoveVideoReceiveStreamSync(receive_stream_impl); |
| } |
| - CHECK(receive_stream_impl != nullptr); |
| delete receive_stream_impl; |
| } |
| @@ -428,6 +445,56 @@ void Call::SignalNetworkState(NetworkState state) { |
| } |
| } |
| +void Call::AddAudioReceiveStreamSync(AudioReceiveStream* stream) { |
|
the sun
2015/06/11 15:38:48
I'd like you to spend a few minutes to see if this
pbos-webrtc
2015/06/12 15:53:14
Done.
|
| + // Set sync only if there was no previous one. |
| + if (stream->config().sync_group.empty() || |
| + sync_stream_mapping_[stream->config().sync_group] != nullptr) { |
| + return; |
| + } |
| + |
| + sync_stream_mapping_[stream->config().sync_group] = stream; |
| + for (VideoReceiveStream* video_stream : video_receive_streams_) { |
| + video_stream->SetSyncChannel(config_.voice_engine, |
| + stream->config().voe_channel_id); |
| + } |
| +} |
| + |
| +void Call::RemoveAudioReceiveStreamSync(AudioReceiveStream* stream) { |
| + // Try to replace sync only if this stream was previously used. |
| + if (stream->config().sync_group.empty() || |
| + sync_stream_mapping_[stream->config().sync_group] != stream) { |
| + return; |
| + } |
| + sync_stream_mapping_[stream->config().sync_group] = nullptr; |
| + int voe_channel_id = -1; |
| + for (auto& kv : audio_receive_ssrcs_) { |
| + if (kv.second->config().sync_group == stream->config().sync_group) { |
| + sync_stream_mapping_[stream->config().sync_group] = kv.second; |
| + voe_channel_id = kv.second->config().voe_channel_id; |
| + break; |
| + } |
| + } |
| + |
| + for (VideoReceiveStream* video_stream : video_receive_streams_) |
| + video_stream->SetSyncChannel(config_.voice_engine, voe_channel_id); |
| +} |
| + |
| +void Call::AddVideoReceiveStreamSync(VideoReceiveStream* stream) { |
| + // Configure sync only if there's an audio stream to sync to. |
| + if (stream->config().sync_group.empty() || |
| + sync_stream_mapping_[stream->config().sync_group] == nullptr) { |
| + return; |
| + } |
| + stream->SetSyncChannel(config_.voice_engine, |
| + sync_stream_mapping_[stream->config().sync_group] |
| + ->config() |
| + .voe_channel_id); |
| +} |
| + |
| +void Call::RemoveVideoReceiveStreamSync(VideoReceiveStream* stream) { |
| + stream->SetSyncChannel(nullptr, -1); |
| +} |
| + |
| PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type, |
| const uint8_t* packet, |
| size_t length) { |