OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/rtc_peer_connection_handler.h" | 5 #include "content/renderer/media/rtc_peer_connection_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 #include "content/renderer/media/media_stream.h" | 19 #include "content/renderer/media/media_stream.h" |
20 #include "content/renderer/media/media_stream_audio_source.h" | 20 #include "content/renderer/media/media_stream_audio_source.h" |
21 #include "content/renderer/media/media_stream_dependency_factory.h" | 21 #include "content/renderer/media/media_stream_dependency_factory.h" |
22 #include "content/renderer/media/media_stream_track.h" | 22 #include "content/renderer/media/media_stream_track.h" |
23 #include "content/renderer/media/peer_connection_tracker.h" | 23 #include "content/renderer/media/peer_connection_tracker.h" |
24 #include "content/renderer/media/remote_media_stream_impl.h" | 24 #include "content/renderer/media/remote_media_stream_impl.h" |
25 #include "content/renderer/media/rtc_data_channel_handler.h" | 25 #include "content/renderer/media/rtc_data_channel_handler.h" |
26 #include "content/renderer/media/rtc_dtmf_sender_handler.h" | 26 #include "content/renderer/media/rtc_dtmf_sender_handler.h" |
27 #include "content/renderer/media/rtc_media_constraints.h" | 27 #include "content/renderer/media/rtc_media_constraints.h" |
28 #include "content/renderer/media/webrtc_audio_capturer.h" | 28 #include "content/renderer/media/webrtc_audio_capturer.h" |
29 #include "content/renderer/media/webrtc_audio_device_impl.h" | 29 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 30 #include "content/renderer/media/webrtc_uma_histograms.h" |
30 #include "content/renderer/render_thread_impl.h" | 31 #include "content/renderer/render_thread_impl.h" |
31 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 32 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
32 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 33 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
33 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h" | 34 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h" |
34 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 35 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
35 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" | 36 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" |
36 #include "third_party/WebKit/public/platform/WebRTCSessionDescription.h" | 37 #include "third_party/WebKit/public/platform/WebRTCSessionDescription.h" |
37 #include "third_party/WebKit/public/platform/WebRTCSessionDescriptionRequest.h" | 38 #include "third_party/WebKit/public/platform/WebRTCSessionDescriptionRequest.h" |
38 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | 39 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
39 #include "third_party/WebKit/public/platform/WebURL.h" | 40 #include "third_party/WebKit/public/platform/WebURL.h" |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 | 547 |
547 bool RTCPeerConnectionHandler::addStream( | 548 bool RTCPeerConnectionHandler::addStream( |
548 const blink::WebMediaStream& stream, | 549 const blink::WebMediaStream& stream, |
549 const blink::WebMediaConstraints& options) { | 550 const blink::WebMediaConstraints& options) { |
550 RTCMediaConstraints constraints(options); | 551 RTCMediaConstraints constraints(options); |
551 | 552 |
552 if (peer_connection_tracker_) | 553 if (peer_connection_tracker_) |
553 peer_connection_tracker_->TrackAddStream( | 554 peer_connection_tracker_->TrackAddStream( |
554 this, stream, PeerConnectionTracker::SOURCE_LOCAL); | 555 this, stream, PeerConnectionTracker::SOURCE_LOCAL); |
555 | 556 |
| 557 PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter(); |
| 558 |
556 track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM, | 559 track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM, |
557 MediaStream::GetAdapter(stream)); | 560 MediaStream::GetAdapter(stream)); |
558 | 561 |
559 // A media stream is connected to a peer connection, enable the | 562 // A media stream is connected to a peer connection, enable the |
560 // peer connection mode for the sources. | 563 // peer connection mode for the sources. |
561 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; | 564 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; |
562 stream.audioTracks(audio_tracks); | 565 stream.audioTracks(audio_tracks); |
563 for (size_t i = 0; i < audio_tracks.size(); ++i) { | 566 for (size_t i = 0; i < audio_tracks.size(); ++i) { |
564 MediaStreamTrack* native_track = | 567 MediaStreamTrack* native_track = |
565 MediaStreamTrack::GetTrack(audio_tracks[i]); | 568 MediaStreamTrack::GetTrack(audio_tracks[i]); |
(...skipping 18 matching lines...) Expand all Loading... |
584 | 587 |
585 return AddStream(stream, &constraints); | 588 return AddStream(stream, &constraints); |
586 } | 589 } |
587 | 590 |
588 void RTCPeerConnectionHandler::removeStream( | 591 void RTCPeerConnectionHandler::removeStream( |
589 const blink::WebMediaStream& stream) { | 592 const blink::WebMediaStream& stream) { |
590 RemoveStream(stream); | 593 RemoveStream(stream); |
591 if (peer_connection_tracker_) | 594 if (peer_connection_tracker_) |
592 peer_connection_tracker_->TrackRemoveStream( | 595 peer_connection_tracker_->TrackRemoveStream( |
593 this, stream, PeerConnectionTracker::SOURCE_LOCAL); | 596 this, stream, PeerConnectionTracker::SOURCE_LOCAL); |
| 597 PerSessionWebRTCAPIMetrics::GetInstance()->DecrementStreamCounter(); |
594 track_metrics_.RemoveStream(MediaStreamTrackMetrics::SENT_STREAM, | 598 track_metrics_.RemoveStream(MediaStreamTrackMetrics::SENT_STREAM, |
595 MediaStream::GetAdapter(stream)); | 599 MediaStream::GetAdapter(stream)); |
596 } | 600 } |
597 | 601 |
598 void RTCPeerConnectionHandler::getStats( | 602 void RTCPeerConnectionHandler::getStats( |
599 const blink::WebRTCStatsRequest& request) { | 603 const blink::WebRTCStatsRequest& request) { |
600 scoped_refptr<LocalRTCStatsRequest> inner_request( | 604 scoped_refptr<LocalRTCStatsRequest> inner_request( |
601 new talk_base::RefCountedObject<LocalRTCStatsRequest>(request)); | 605 new talk_base::RefCountedObject<LocalRTCStatsRequest>(request)); |
602 getStats(inner_request.get()); | 606 getStats(inner_request.get()); |
603 } | 607 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 new RemoteMediaStreamImpl(stream_interface); | 764 new RemoteMediaStreamImpl(stream_interface); |
761 remote_streams_.insert( | 765 remote_streams_.insert( |
762 std::pair<webrtc::MediaStreamInterface*, RemoteMediaStreamImpl*> ( | 766 std::pair<webrtc::MediaStreamInterface*, RemoteMediaStreamImpl*> ( |
763 stream_interface, remote_stream)); | 767 stream_interface, remote_stream)); |
764 | 768 |
765 if (peer_connection_tracker_) | 769 if (peer_connection_tracker_) |
766 peer_connection_tracker_->TrackAddStream( | 770 peer_connection_tracker_->TrackAddStream( |
767 this, remote_stream->webkit_stream(), | 771 this, remote_stream->webkit_stream(), |
768 PeerConnectionTracker::SOURCE_REMOTE); | 772 PeerConnectionTracker::SOURCE_REMOTE); |
769 | 773 |
| 774 PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter(); |
| 775 |
770 track_metrics_.AddStream(MediaStreamTrackMetrics::RECEIVED_STREAM, | 776 track_metrics_.AddStream(MediaStreamTrackMetrics::RECEIVED_STREAM, |
771 stream_interface); | 777 stream_interface); |
772 | 778 |
773 client_->didAddRemoteStream(remote_stream->webkit_stream()); | 779 client_->didAddRemoteStream(remote_stream->webkit_stream()); |
774 } | 780 } |
775 | 781 |
776 void RTCPeerConnectionHandler::OnRemoveStream( | 782 void RTCPeerConnectionHandler::OnRemoveStream( |
777 webrtc::MediaStreamInterface* stream_interface) { | 783 webrtc::MediaStreamInterface* stream_interface) { |
778 DCHECK(stream_interface); | 784 DCHECK(stream_interface); |
779 RemoteStreamMap::iterator it = remote_streams_.find(stream_interface); | 785 RemoteStreamMap::iterator it = remote_streams_.find(stream_interface); |
780 if (it == remote_streams_.end()) { | 786 if (it == remote_streams_.end()) { |
781 NOTREACHED() << "Stream not found"; | 787 NOTREACHED() << "Stream not found"; |
782 return; | 788 return; |
783 } | 789 } |
784 | 790 |
785 track_metrics_.RemoveStream(MediaStreamTrackMetrics::RECEIVED_STREAM, | 791 track_metrics_.RemoveStream(MediaStreamTrackMetrics::RECEIVED_STREAM, |
786 stream_interface); | 792 stream_interface); |
| 793 PerSessionWebRTCAPIMetrics::GetInstance()->DecrementStreamCounter(); |
787 | 794 |
788 scoped_ptr<RemoteMediaStreamImpl> remote_stream(it->second); | 795 scoped_ptr<RemoteMediaStreamImpl> remote_stream(it->second); |
789 const blink::WebMediaStream& webkit_stream = remote_stream->webkit_stream(); | 796 const blink::WebMediaStream& webkit_stream = remote_stream->webkit_stream(); |
790 DCHECK(!webkit_stream.isNull()); | 797 DCHECK(!webkit_stream.isNull()); |
791 remote_streams_.erase(it); | 798 remote_streams_.erase(it); |
792 | 799 |
793 if (peer_connection_tracker_) | 800 if (peer_connection_tracker_) |
794 peer_connection_tracker_->TrackRemoveStream( | 801 peer_connection_tracker_->TrackRemoveStream( |
795 this, webkit_stream, PeerConnectionTracker::SOURCE_REMOTE); | 802 this, webkit_stream, PeerConnectionTracker::SOURCE_REMOTE); |
796 | 803 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 webrtc::SessionDescriptionInterface* native_desc = | 853 webrtc::SessionDescriptionInterface* native_desc = |
847 dependency_factory_->CreateSessionDescription(type, sdp, error); | 854 dependency_factory_->CreateSessionDescription(type, sdp, error); |
848 | 855 |
849 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." | 856 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." |
850 << " Type: " << type << " SDP: " << sdp; | 857 << " Type: " << type << " SDP: " << sdp; |
851 | 858 |
852 return native_desc; | 859 return native_desc; |
853 } | 860 } |
854 | 861 |
855 } // namespace content | 862 } // namespace content |
OLD | NEW |