| 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 void set_enable_recording(bool enable_recording) { | 37 void set_enable_recording(bool enable_recording) { |
| 38 DCHECK(!encoder_task_runner_.get() || | 38 DCHECK(!encoder_task_runner_.get() || |
| 39 encoder_task_runner_->BelongsToCurrentThread()); | 39 encoder_task_runner_->BelongsToCurrentThread()); |
| 40 enable_recording_ = enable_recording; | 40 enable_recording_ = enable_recording; |
| 41 } | 41 } |
| 42 | 42 |
| 43 // remoting::VideoEncoder interface. | 43 // remoting::VideoEncoder interface. |
| 44 void SetLosslessEncode(bool want_lossless) override; | 44 void SetLosslessEncode(bool want_lossless) override; |
| 45 void SetLosslessColor(bool want_lossless) override; | 45 void SetLosslessColor(bool want_lossless) override; |
| 46 scoped_ptr<VideoPacket> Encode(const webrtc::DesktopFrame& frame) override; | 46 scoped_ptr<VideoPacket> Encode(const webrtc::DesktopFrame& frame, |
| 47 uint32_t flags = 0) override; |
| 47 | 48 |
| 48 private: | 49 private: |
| 49 scoped_ptr<VideoEncoder> encoder_; | 50 scoped_ptr<VideoEncoder> encoder_; |
| 50 scoped_refptr<base::TaskRunner> recorder_task_runner_; | 51 scoped_refptr<base::TaskRunner> recorder_task_runner_; |
| 51 base::WeakPtr<VideoFrameRecorder> recorder_; | 52 base::WeakPtr<VideoFrameRecorder> recorder_; |
| 52 | 53 |
| 53 bool enable_recording_; | 54 bool enable_recording_; |
| 54 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_; | 55 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_; |
| 55 | 56 |
| 56 base::WeakPtrFactory<RecordingVideoEncoder> weak_factory_; | 57 base::WeakPtrFactory<RecordingVideoEncoder> weak_factory_; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 80 bool want_lossless) { | 81 bool want_lossless) { |
| 81 encoder_->SetLosslessEncode(want_lossless); | 82 encoder_->SetLosslessEncode(want_lossless); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void VideoFrameRecorder::RecordingVideoEncoder::SetLosslessColor( | 85 void VideoFrameRecorder::RecordingVideoEncoder::SetLosslessColor( |
| 85 bool want_lossless) { | 86 bool want_lossless) { |
| 86 encoder_->SetLosslessColor(want_lossless); | 87 encoder_->SetLosslessColor(want_lossless); |
| 87 } | 88 } |
| 88 | 89 |
| 89 scoped_ptr<VideoPacket> VideoFrameRecorder::RecordingVideoEncoder::Encode( | 90 scoped_ptr<VideoPacket> VideoFrameRecorder::RecordingVideoEncoder::Encode( |
| 90 const webrtc::DesktopFrame& frame) { | 91 const webrtc::DesktopFrame& frame, |
| 92 uint32_t flags) { |
| 91 // If this is the first Encode() then store the TaskRunner and inform the | 93 // If this is the first Encode() then store the TaskRunner and inform the |
| 92 // VideoFrameRecorder so it can post set_enable_recording() on it. | 94 // VideoFrameRecorder so it can post set_enable_recording() on it. |
| 93 if (!encoder_task_runner_.get()) { | 95 if (!encoder_task_runner_.get()) { |
| 94 encoder_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 96 encoder_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 95 recorder_task_runner_->PostTask(FROM_HERE, | 97 recorder_task_runner_->PostTask(FROM_HERE, |
| 96 base::Bind(&VideoFrameRecorder::SetEncoderTaskRunner, | 98 base::Bind(&VideoFrameRecorder::SetEncoderTaskRunner, |
| 97 recorder_, | 99 recorder_, |
| 98 encoder_task_runner_)); | 100 encoder_task_runner_)); |
| 99 } | 101 } |
| 100 | 102 |
| 101 DCHECK(encoder_task_runner_->BelongsToCurrentThread()); | 103 DCHECK(encoder_task_runner_->BelongsToCurrentThread()); |
| 102 | 104 |
| 103 if (enable_recording_) { | 105 if (enable_recording_) { |
| 104 // Copy the frame and post it to the VideoFrameRecorder to store. | 106 // Copy the frame and post it to the VideoFrameRecorder to store. |
| 105 scoped_ptr<webrtc::DesktopFrame> frame_copy( | 107 scoped_ptr<webrtc::DesktopFrame> frame_copy( |
| 106 new webrtc::BasicDesktopFrame(frame.size())); | 108 new webrtc::BasicDesktopFrame(frame.size())); |
| 107 *frame_copy->mutable_updated_region() = frame.updated_region(); | 109 *frame_copy->mutable_updated_region() = frame.updated_region(); |
| 108 frame_copy->set_dpi(frame.dpi()); | 110 frame_copy->set_dpi(frame.dpi()); |
| 109 frame_copy->CopyPixelsFrom(frame.data(), | 111 frame_copy->CopyPixelsFrom(frame.data(), |
| 110 frame.stride(), | 112 frame.stride(), |
| 111 webrtc::DesktopRect::MakeSize(frame.size())); | 113 webrtc::DesktopRect::MakeSize(frame.size())); |
| 112 recorder_task_runner_->PostTask(FROM_HERE, | 114 recorder_task_runner_->PostTask(FROM_HERE, |
| 113 base::Bind(&VideoFrameRecorder::RecordFrame, | 115 base::Bind(&VideoFrameRecorder::RecordFrame, |
| 114 recorder_, | 116 recorder_, |
| 115 base::Passed(&frame_copy))); | 117 base::Passed(&frame_copy))); |
| 116 } | 118 } |
| 117 | 119 |
| 118 return encoder_->Encode(frame); | 120 return encoder_->Encode(frame, flags); |
| 119 } | 121 } |
| 120 | 122 |
| 121 VideoFrameRecorder::VideoFrameRecorder() | 123 VideoFrameRecorder::VideoFrameRecorder() |
| 122 : content_bytes_(0), | 124 : content_bytes_(0), |
| 123 max_content_bytes_(0), | 125 max_content_bytes_(0), |
| 124 enable_recording_(false), | 126 enable_recording_(false), |
| 125 weak_factory_(this) { | 127 weak_factory_(this) { |
| 126 } | 128 } |
| 127 | 129 |
| 128 VideoFrameRecorder::~VideoFrameRecorder() { | 130 VideoFrameRecorder::~VideoFrameRecorder() { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (content_bytes_ + frame_bytes > max_content_bytes_) { | 244 if (content_bytes_ + frame_bytes > max_content_bytes_) { |
| 243 return; | 245 return; |
| 244 } | 246 } |
| 245 | 247 |
| 246 // Store the frame and update the content byte count. | 248 // Store the frame and update the content byte count. |
| 247 recorded_frames_.push_back(frame.release()); | 249 recorded_frames_.push_back(frame.release()); |
| 248 content_bytes_ += frame_bytes; | 250 content_bytes_ += frame_bytes; |
| 249 } | 251 } |
| 250 | 252 |
| 251 } // namespace remoting | 253 } // namespace remoting |
| OLD | NEW |