Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: remoting/base/decoder_verbatim.cc

Issue 3305001: Move decoder into separate thread, clean up API layering, and redo update protocl (Closed)
Patch Set: Fix compile error. Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/base/decoder_verbatim.h ('k') | remoting/base/decoder_verbatim_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "remoting/base/decoder_verbatim.h"
6
7 #include "remoting/base/protocol_util.h"
8
9 namespace remoting {
10
11 DecoderVerbatim::DecoderVerbatim()
12 : state_(kWaitingForBeginRect),
13 rect_x_(0),
14 rect_y_(0),
15 rect_width_(0),
16 rect_height_(0),
17 bytes_per_pixel_(0),
18 updated_rects_(NULL),
19 reverse_rows_(true) {
20 encoding_ = EncodingNone;
21 }
22
23 bool DecoderVerbatim::BeginDecode(scoped_refptr<media::VideoFrame> frame,
24 UpdatedRects* updated_rects,
25 Task* partial_decode_done,
26 Task* decode_done) {
27 DCHECK(!partial_decode_done_.get());
28 DCHECK(!decode_done_.get());
29 DCHECK(!updated_rects_);
30 DCHECK_EQ(kWaitingForBeginRect, state_);
31 DCHECK(!started_);
32
33 partial_decode_done_.reset(partial_decode_done);
34 decode_done_.reset(decode_done);
35 updated_rects_ = updated_rects;
36
37 // TODO(hclam): Check if we can accept the color format of the video frame
38 // and the codec.
39 frame_ = frame;
40
41 started_ = true;
42 return true;
43 }
44
45 bool DecoderVerbatim::PartialDecode(ChromotingHostMessage* message) {
46 scoped_ptr<ChromotingHostMessage> msg_deleter(message);
47 DCHECK(message->has_update_stream_packet());
48 DCHECK(started_);
49
50 bool ret = true;
51 if (message->update_stream_packet().has_begin_rect())
52 ret = HandleBeginRect(message);
53 if (ret && message->update_stream_packet().has_rect_data())
54 ret = HandleRectData(message);
55 if (ret && message->update_stream_packet().has_end_rect())
56 ret = HandleEndRect(message);
57 return ret;
58 }
59
60 void DecoderVerbatim::EndDecode() {
61 DCHECK_EQ(kWaitingForBeginRect, state_);
62 DCHECK(started_);
63
64 decode_done_->Run();
65
66 partial_decode_done_.reset();
67 decode_done_.reset();
68 frame_ = NULL;
69 updated_rects_ = NULL;
70 started_ = false;
71 }
72
73 bool DecoderVerbatim::HandleBeginRect(ChromotingHostMessage* message) {
74 DCHECK_EQ(kWaitingForBeginRect, state_);
75 state_ = kWaitingForRectData;
76
77 rect_width_ = message->update_stream_packet().begin_rect().width();
78 rect_height_ = message->update_stream_packet().begin_rect().height();
79 rect_x_ = message->update_stream_packet().begin_rect().x();
80 rect_y_ = message->update_stream_packet().begin_rect().y();
81
82 PixelFormat pixel_format =
83 message->update_stream_packet().begin_rect().pixel_format();
84
85 if (static_cast<PixelFormat>(frame_->format()) != pixel_format) {
86 NOTREACHED() << "Pixel format of message doesn't match the video frame. "
87 "Expected vs received = "
88 << frame_->format() << " vs " << pixel_format
89 << " Color space conversion required.";
90 return false;
91 }
92
93 bytes_per_pixel_ = GetBytesPerPixel(pixel_format);
94 return true;
95 }
96
97 bool DecoderVerbatim::HandleRectData(ChromotingHostMessage* message) {
98 DCHECK_EQ(kWaitingForRectData, state_);
99 DCHECK_EQ(0,
100 message->update_stream_packet().rect_data().sequence_number());
101
102 // Copy the data line by line.
103 const int src_stride = bytes_per_pixel_ * rect_width_;
104 const char* src =
105 message->update_stream_packet().rect_data().data().data();
106
107 // Make sure there's enough data in |message|.
108 const int src_size =
109 message->update_stream_packet().rect_data().data().length();
110 if (src_size != src_stride * rect_height_)
111 return false;
112
113 // Make sure there's enough space for us to write to.
114 if (frame_->height() < static_cast<size_t>(rect_height_) ||
115 frame_->stride(media::VideoFrame::kRGBPlane) < src_stride) {
116 return false;
117 }
118
119 int src_stride_dir = src_stride;
120 if (reverse_rows_) {
121 // Copy rows from bottom to top to flip the image vertically.
122 src += (rect_height_ - 1) * src_stride;
123 // Change the direction of the stride to work bottom to top.
124 src_stride_dir *= -1;
125 }
126 const int dest_stride = frame_->stride(media::VideoFrame::kRGBPlane);
127 uint8* dest = frame_->data(media::VideoFrame::kRGBPlane) +
128 dest_stride * rect_y_ + bytes_per_pixel_ * rect_x_;
129 for (int i = 0; i < rect_height_; ++i) {
130 memcpy(dest, src, src_stride);
131 dest += dest_stride;
132 src += src_stride_dir;
133 }
134
135 updated_rects_->clear();
136 updated_rects_->push_back(gfx::Rect(rect_x_, rect_y_,
137 rect_width_, rect_height_));
138 partial_decode_done_->Run();
139 return true;
140 }
141
142 bool DecoderVerbatim::HandleEndRect(ChromotingHostMessage* message) {
143 DCHECK_EQ(kWaitingForRectData, state_);
144 state_ = kWaitingForBeginRect;
145 return true;
146 }
147
148 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/decoder_verbatim.h ('k') | remoting/base/decoder_verbatim_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698