OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/protocol/webrtc_video_stream.h" | 5 #include "remoting/protocol/webrtc_video_stream.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "remoting/protocol/webrtc_video_capturer_adapter.h" | 8 #include "remoting/protocol/webrtc_dummy_video_capturer.h" |
9 #include "third_party/webrtc/api/mediastreaminterface.h" | 9 #include "third_party/webrtc/api/mediastreaminterface.h" |
10 #include "third_party/webrtc/api/peerconnectioninterface.h" | 10 #include "third_party/webrtc/api/peerconnectioninterface.h" |
11 #include "third_party/webrtc/api/test/fakeconstraints.h" | 11 #include "third_party/webrtc/api/test/fakeconstraints.h" |
12 #include "third_party/webrtc/media/base/videocapturer.h" | |
12 | 13 |
13 namespace remoting { | 14 namespace remoting { |
14 namespace protocol { | 15 namespace protocol { |
15 | 16 |
16 const char kStreamLabel[] = "screen_stream"; | 17 const char kStreamLabel[] = "screen_stream"; |
17 const char kVideoLabel[] = "screen_video"; | 18 const char kVideoLabel[] = "screen_video"; |
18 | 19 |
19 WebrtcVideoStream::WebrtcVideoStream() {} | 20 WebrtcVideoStream::WebrtcVideoStream() {} |
20 | 21 |
21 WebrtcVideoStream::~WebrtcVideoStream() { | 22 WebrtcVideoStream::~WebrtcVideoStream() { |
22 if (stream_) { | 23 if (stream_) { |
23 for (const auto& track : stream_->GetVideoTracks()) { | 24 for (const auto& track : stream_->GetVideoTracks()) { |
24 track->GetSource()->Stop(); | 25 track->GetSource()->Stop(); |
25 stream_->RemoveTrack(track.get()); | 26 stream_->RemoveTrack(track.get()); |
26 } | 27 } |
27 connection_->RemoveStream(stream_.get()); | 28 connection_->RemoveStream(stream_.get()); |
28 } | 29 } |
29 | |
30 // MediaStream may still outlive WebrtcVideoStream because it's | |
31 // ref-counted. Reset SizeCallback to make sure it won't be called again. | |
32 if (capturer_adapter_) | |
33 capturer_adapter_->SetSizeCallback(SizeCallback()); | |
34 } | 30 } |
35 | 31 |
36 bool WebrtcVideoStream::Start( | 32 bool WebrtcVideoStream::Start( |
37 scoped_ptr<webrtc::DesktopCapturer> desktop_capturer, | 33 scoped_ptr<webrtc::DesktopCapturer> desktop_capturer, |
38 scoped_refptr<webrtc::PeerConnectionInterface> connection, | 34 WebrtcTransport* webrtc_transport, |
39 scoped_refptr<webrtc::PeerConnectionFactoryInterface> | 35 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, |
40 peer_connection_factory) { | 36 scoped_ptr<VideoEncoder> video_encoder) { |
41 scoped_ptr<WebrtcVideoCapturerAdapter> capturer_adapter( | 37 DCHECK(webrtc_transport); |
Sergey Ulanov
2016/04/07 21:05:39
WebrtcVideoCapturerAdapter is not used anywhere be
Irfan
2016/04/12 21:13:11
Done.
| |
42 new WebrtcVideoCapturerAdapter(std::move(desktop_capturer))); | 38 DCHECK(desktop_capturer); |
43 capturer_adapter_ = capturer_adapter->GetWeakPtr(); | 39 DCHECK(video_encode_task_runner); |
40 DCHECK(video_encoder); | |
44 | 41 |
45 connection_ = connection; | 42 scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory( |
43 webrtc_transport->peer_connection_factory()); | |
44 connection_ = webrtc_transport->peer_connection(); | |
45 DCHECK(peer_connection_factory); | |
46 DCHECK(connection_); | |
47 | |
48 scoped_ptr<WebRtcFrameScheduler> frame_scheduler(new WebRtcFrameScheduler( | |
49 video_encode_task_runner, std::move(desktop_capturer), webrtc_transport, | |
50 std::move(video_encoder))); | |
51 webrtc_frame_scheduler_ = frame_scheduler.get(); | |
46 | 52 |
47 // Set video stream constraints. | 53 // Set video stream constraints. |
48 webrtc::FakeConstraints video_constraints; | 54 webrtc::FakeConstraints video_constraints; |
49 video_constraints.AddMandatory( | 55 video_constraints.AddMandatory( |
50 webrtc::MediaConstraintsInterface::kMinFrameRate, 5); | 56 webrtc::MediaConstraintsInterface::kMinFrameRate, 5); |
51 | 57 |
58 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> src = | |
59 peer_connection_factory->CreateVideoSource( | |
60 new WebRtcDummyVideoCapturer(std::move(frame_scheduler)), | |
61 &video_constraints); | |
52 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track = | 62 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track = |
53 peer_connection_factory->CreateVideoTrack( | 63 peer_connection_factory->CreateVideoTrack(kVideoLabel, src); |
54 kVideoLabel, peer_connection_factory->CreateVideoSource( | |
55 capturer_adapter.release(), &video_constraints)); | |
56 | 64 |
57 stream_ = peer_connection_factory->CreateLocalMediaStream(kStreamLabel); | 65 stream_ = peer_connection_factory->CreateLocalMediaStream(kStreamLabel); |
58 | 66 |
59 if (!stream_->AddTrack(video_track.get()) || | 67 if (!stream_->AddTrack(video_track.get()) || |
60 !connection_->AddStream(stream_.get())) { | 68 !connection_->AddStream(stream_.get())) { |
61 stream_ = nullptr; | 69 stream_ = nullptr; |
62 connection_ = nullptr; | 70 connection_ = nullptr; |
63 return false; | 71 return false; |
64 } | 72 } |
65 | |
66 return true; | 73 return true; |
67 } | 74 } |
68 | 75 |
69 void WebrtcVideoStream::Pause(bool pause) { | 76 void WebrtcVideoStream::Pause(bool pause) { |
70 if (capturer_adapter_) | 77 if (webrtc_frame_scheduler_) |
71 capturer_adapter_->PauseCapturer(pause); | 78 webrtc_frame_scheduler_->Pause(pause); |
72 } | 79 } |
73 | 80 |
74 void WebrtcVideoStream::OnInputEventReceived(int64_t event_timestamp) { | 81 void WebrtcVideoStream::OnInputEventReceived(int64_t event_timestamp) { |
75 NOTIMPLEMENTED(); | 82 NOTIMPLEMENTED(); |
76 } | 83 } |
77 | 84 |
78 void WebrtcVideoStream::SetLosslessEncode(bool want_lossless) { | 85 void WebrtcVideoStream::SetLosslessEncode(bool want_lossless) { |
79 NOTIMPLEMENTED(); | 86 NOTIMPLEMENTED(); |
80 } | 87 } |
81 | 88 |
82 void WebrtcVideoStream::SetLosslessColor(bool want_lossless) { | 89 void WebrtcVideoStream::SetLosslessColor(bool want_lossless) { |
83 NOTIMPLEMENTED(); | 90 NOTIMPLEMENTED(); |
84 } | 91 } |
85 | 92 |
86 void WebrtcVideoStream::SetSizeCallback(const SizeCallback& size_callback) { | 93 void WebrtcVideoStream::SetSizeCallback(const SizeCallback& size_callback) { |
87 if (capturer_adapter_) | 94 if (webrtc_frame_scheduler_) |
88 capturer_adapter_->SetSizeCallback(size_callback); | 95 webrtc_frame_scheduler_->SetSizeCallback(size_callback); |
89 } | 96 } |
90 | 97 |
91 } // namespace protocol | 98 } // namespace protocol |
92 } // namespace remoting | 99 } // namespace remoting |
OLD | NEW |