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 "remoting/codec/video_encoder_verbatim.h" | 5 #include "remoting/codec/video_encoder_verbatim.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/time/time.h" | |
10 #include "remoting/base/util.h" | 9 #include "remoting/base/util.h" |
11 #include "remoting/proto/video.pb.h" | 10 #include "remoting/proto/video.pb.h" |
12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
13 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 12 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
14 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" | 13 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
15 | 14 |
16 namespace remoting { | 15 namespace remoting { |
17 | 16 |
18 static uint8_t* GetPacketOutputBuffer(VideoPacket* packet, size_t size) { | 17 static uint8_t* GetPacketOutputBuffer(VideoPacket* packet, size_t size) { |
19 packet->mutable_data()->resize(size); | 18 packet->mutable_data()->resize(size); |
20 return reinterpret_cast<uint8_t*>(string_as_array(packet->mutable_data())); | 19 return reinterpret_cast<uint8_t*>(string_as_array(packet->mutable_data())); |
21 } | 20 } |
22 | 21 |
23 VideoEncoderVerbatim::VideoEncoderVerbatim() {} | 22 VideoEncoderVerbatim::VideoEncoderVerbatim() {} |
24 VideoEncoderVerbatim::~VideoEncoderVerbatim() {} | 23 VideoEncoderVerbatim::~VideoEncoderVerbatim() {} |
25 | 24 |
26 scoped_ptr<VideoPacket> VideoEncoderVerbatim::Encode( | 25 scoped_ptr<VideoPacket> VideoEncoderVerbatim::Encode( |
27 const webrtc::DesktopFrame& frame) { | 26 const webrtc::DesktopFrame& frame) { |
28 DCHECK(frame.data()); | 27 DCHECK(frame.data()); |
29 | 28 |
30 // If nothing has changed in the frame then return NULL to indicate that | 29 // If nothing has changed in the frame then return NULL to indicate that |
31 // we don't need to actually send anything (e.g. nothing to top-off). | 30 // we don't need to actually send anything (e.g. nothing to top-off). |
32 if (frame.updated_region().is_empty()) | 31 if (frame.updated_region().is_empty()) |
33 return nullptr; | 32 return nullptr; |
34 | 33 |
35 base::Time encode_start_time = base::Time::Now(); | |
36 | |
37 // Create a VideoPacket with common fields (e.g. DPI, rects, shape) set. | 34 // Create a VideoPacket with common fields (e.g. DPI, rects, shape) set. |
38 scoped_ptr<VideoPacket> packet(helper_.CreateVideoPacket(frame)); | 35 scoped_ptr<VideoPacket> packet(helper_.CreateVideoPacket(frame)); |
39 packet->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VERBATIM); | 36 packet->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VERBATIM); |
40 | 37 |
41 // Calculate output size. | 38 // Calculate output size. |
42 size_t output_size = 0; | 39 size_t output_size = 0; |
43 for (webrtc::DesktopRegion::Iterator iter(frame.updated_region()); | 40 for (webrtc::DesktopRegion::Iterator iter(frame.updated_region()); |
44 !iter.IsAtEnd(); iter.Advance()) { | 41 !iter.IsAtEnd(); iter.Advance()) { |
45 const webrtc::DesktopRect& rect = iter.rect(); | 42 const webrtc::DesktopRect& rect = iter.rect(); |
46 output_size += rect.width() * rect.height() * | 43 output_size += rect.width() * rect.height() * |
(...skipping 10 matching lines...) Expand all Loading... |
57 const int row_size = webrtc::DesktopFrame::kBytesPerPixel * rect.width(); | 54 const int row_size = webrtc::DesktopFrame::kBytesPerPixel * rect.width(); |
58 const uint8_t* in = frame.data() + rect.top() * in_stride + | 55 const uint8_t* in = frame.data() + rect.top() * in_stride + |
59 rect.left() * webrtc::DesktopFrame::kBytesPerPixel; | 56 rect.left() * webrtc::DesktopFrame::kBytesPerPixel; |
60 for (int y = rect.top(); y < rect.top() + rect.height(); ++y) { | 57 for (int y = rect.top(); y < rect.top() + rect.height(); ++y) { |
61 memcpy(out, in, row_size); | 58 memcpy(out, in, row_size); |
62 out += row_size; | 59 out += row_size; |
63 in += in_stride; | 60 in += in_stride; |
64 } | 61 } |
65 } | 62 } |
66 | 63 |
67 // Note the time taken to encode the pixel data. | |
68 packet->set_encode_time_ms( | |
69 (base::Time::Now() - encode_start_time).InMillisecondsRoundedUp()); | |
70 | |
71 return packet.Pass(); | 64 return packet.Pass(); |
72 } | 65 } |
73 | 66 |
74 } // namespace remoting | 67 } // namespace remoting |
OLD | NEW |