OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/host/video_frame_recorder.h" | 5 #include "remoting/host/video_frame_recorder.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/location.h" | 10 #include "base/location.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
11 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
12 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
13 #include "remoting/codec/video_encoder.h" | 15 #include "remoting/codec/video_encoder.h" |
14 #include "remoting/proto/video.pb.h" | 16 #include "remoting/proto/video.pb.h" |
15 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 17 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
16 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 18 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 55 |
54 base::WeakPtrFactory<RecordingVideoEncoder> weak_factory_; | 56 base::WeakPtrFactory<RecordingVideoEncoder> weak_factory_; |
55 | 57 |
56 DISALLOW_COPY_AND_ASSIGN(RecordingVideoEncoder); | 58 DISALLOW_COPY_AND_ASSIGN(RecordingVideoEncoder); |
57 }; | 59 }; |
58 | 60 |
59 VideoFrameRecorder::RecordingVideoEncoder::RecordingVideoEncoder( | 61 VideoFrameRecorder::RecordingVideoEncoder::RecordingVideoEncoder( |
60 scoped_ptr<VideoEncoder> encoder, | 62 scoped_ptr<VideoEncoder> encoder, |
61 scoped_refptr<base::TaskRunner> recorder_task_runner, | 63 scoped_refptr<base::TaskRunner> recorder_task_runner, |
62 base::WeakPtr<VideoFrameRecorder> recorder) | 64 base::WeakPtr<VideoFrameRecorder> recorder) |
63 : encoder_(encoder.Pass()), | 65 : encoder_(std::move(encoder)), |
64 recorder_task_runner_(recorder_task_runner), | 66 recorder_task_runner_(recorder_task_runner), |
65 recorder_(recorder), | 67 recorder_(recorder), |
66 enable_recording_(false), | 68 enable_recording_(false), |
67 weak_factory_(this) { | 69 weak_factory_(this) { |
68 DCHECK(encoder_); | 70 DCHECK(encoder_); |
69 DCHECK(recorder_task_runner_.get()); | 71 DCHECK(recorder_task_runner_.get()); |
70 } | 72 } |
71 | 73 |
72 base::WeakPtr<VideoFrameRecorder::RecordingVideoEncoder> | 74 base::WeakPtr<VideoFrameRecorder::RecordingVideoEncoder> |
73 VideoFrameRecorder::RecordingVideoEncoder::AsWeakPtr() { | 75 VideoFrameRecorder::RecordingVideoEncoder::AsWeakPtr() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 DetachVideoEncoderWrapper(); | 129 DetachVideoEncoderWrapper(); |
128 } | 130 } |
129 | 131 |
130 scoped_ptr<VideoEncoder> VideoFrameRecorder::WrapVideoEncoder( | 132 scoped_ptr<VideoEncoder> VideoFrameRecorder::WrapVideoEncoder( |
131 scoped_ptr<VideoEncoder> encoder) { | 133 scoped_ptr<VideoEncoder> encoder) { |
132 DCHECK(!encoder_task_runner_.get()); | 134 DCHECK(!encoder_task_runner_.get()); |
133 DCHECK(!caller_task_runner_.get()); | 135 DCHECK(!caller_task_runner_.get()); |
134 caller_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 136 caller_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
135 | 137 |
136 scoped_ptr<RecordingVideoEncoder> recording_encoder( | 138 scoped_ptr<RecordingVideoEncoder> recording_encoder( |
137 new RecordingVideoEncoder(encoder.Pass(), | 139 new RecordingVideoEncoder(std::move(encoder), |
138 caller_task_runner_, | 140 caller_task_runner_, |
139 weak_factory_.GetWeakPtr())); | 141 weak_factory_.GetWeakPtr())); |
140 recording_encoder_ = recording_encoder->AsWeakPtr(); | 142 recording_encoder_ = recording_encoder->AsWeakPtr(); |
141 | 143 |
142 return recording_encoder.Pass(); | 144 return std::move(recording_encoder); |
143 } | 145 } |
144 | 146 |
145 void VideoFrameRecorder::DetachVideoEncoderWrapper() { | 147 void VideoFrameRecorder::DetachVideoEncoderWrapper() { |
146 DCHECK(!caller_task_runner_.get() || | 148 DCHECK(!caller_task_runner_.get() || |
147 caller_task_runner_->BelongsToCurrentThread()); | 149 caller_task_runner_->BelongsToCurrentThread()); |
148 | 150 |
149 // Immediately detach the wrapper from this recorder. | 151 // Immediately detach the wrapper from this recorder. |
150 weak_factory_.InvalidateWeakPtrs(); | 152 weak_factory_.InvalidateWeakPtrs(); |
151 | 153 |
152 // Clean up any pending recorded frames. | 154 // Clean up any pending recorded frames. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 196 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
195 | 197 |
196 scoped_ptr<webrtc::DesktopFrame> frame; | 198 scoped_ptr<webrtc::DesktopFrame> frame; |
197 if (!recorded_frames_.empty()) { | 199 if (!recorded_frames_.empty()) { |
198 frame.reset(recorded_frames_.front()); | 200 frame.reset(recorded_frames_.front()); |
199 recorded_frames_.pop_front(); | 201 recorded_frames_.pop_front(); |
200 content_bytes_ -= FrameContentSize(frame.get()); | 202 content_bytes_ -= FrameContentSize(frame.get()); |
201 DCHECK_GE(content_bytes_, 0); | 203 DCHECK_GE(content_bytes_, 0); |
202 } | 204 } |
203 | 205 |
204 return frame.Pass(); | 206 return frame; |
205 } | 207 } |
206 | 208 |
207 void VideoFrameRecorder::SetEncoderTaskRunner( | 209 void VideoFrameRecorder::SetEncoderTaskRunner( |
208 scoped_refptr<base::TaskRunner> task_runner) { | 210 scoped_refptr<base::TaskRunner> task_runner) { |
209 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 211 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
210 DCHECK(!encoder_task_runner_.get()); | 212 DCHECK(!encoder_task_runner_.get()); |
211 DCHECK(task_runner.get()); | 213 DCHECK(task_runner.get()); |
212 | 214 |
213 encoder_task_runner_ = task_runner; | 215 encoder_task_runner_ = task_runner; |
214 | 216 |
(...skipping 25 matching lines...) Expand all Loading... |
240 if (content_bytes_ + frame_bytes > max_content_bytes_) { | 242 if (content_bytes_ + frame_bytes > max_content_bytes_) { |
241 return; | 243 return; |
242 } | 244 } |
243 | 245 |
244 // Store the frame and update the content byte count. | 246 // Store the frame and update the content byte count. |
245 recorded_frames_.push_back(frame.release()); | 247 recorded_frames_.push_back(frame.release()); |
246 content_bytes_ += frame_bytes; | 248 content_bytes_ += frame_bytes; |
247 } | 249 } |
248 | 250 |
249 } // namespace remoting | 251 } // namespace remoting |
OLD | NEW |