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
3 // found in the LICENSE file.
5 #include "remoting/codec/video_decoder_verbatim.h"
7 #include "base/logging.h"
8 #include "remoting/base/util.h"
9 #include "remoting/proto/video.pb.h"
10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
11 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
16 static const int kBytesPerPixel
= 4;
18 VideoDecoderVerbatim::VideoDecoderVerbatim() {}
19 VideoDecoderVerbatim::~VideoDecoderVerbatim() {}
21 bool VideoDecoderVerbatim::DecodePacket(const VideoPacket
& packet
,
22 webrtc::DesktopFrame
* frame
) {
23 webrtc::DesktopRegion
* region
= frame
->mutable_updated_region();
25 const char* current_data_pos
= packet
.data().data();
26 for (int i
= 0; i
< packet
.dirty_rects_size(); ++i
) {
27 Rect proto_rect
= packet
.dirty_rects(i
);
28 webrtc::DesktopRect rect
=
29 webrtc::DesktopRect::MakeXYWH(proto_rect
.x(), proto_rect
.y(),
30 proto_rect
.width(), proto_rect
.height());
31 region
->AddRect(rect
);
33 if (!DoesRectContain(webrtc::DesktopRect::MakeSize(frame
->size()), rect
)) {
34 LOG(ERROR
) << "Invalid packet received.";
38 int rect_row_size
= kBytesPerPixel
* rect
.width();
39 const char* rect_data_end
=
40 current_data_pos
+ rect_row_size
* rect
.height();
41 if (rect_data_end
> packet
.data().data() + packet
.data().size()) {
42 LOG(ERROR
) << "Invalid packet received.";
47 reinterpret_cast<uint8_t*>(const_cast<char*>(current_data_pos
));
48 frame
->CopyPixelsFrom(source
, rect_row_size
, rect
);
49 current_data_pos
= rect_data_end
;
52 if (current_data_pos
!= packet
.data().data() + packet
.data().size()) {
53 LOG(ERROR
) << "Invalid packet received.";
60 } // namespace remoting