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

Side by Side Diff: remoting/host/encoder_verbatim.cc

Issue 2690003: Copy the (early prototype of) remoting in Chrome into the public tree.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/encoder_verbatim.h ('k') | remoting/host/encoder_vp8.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
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/host/encoder_verbatim.h"
6
7 #include "gfx/rect.h"
8 #include "media/base/data_buffer.h"
9 #include "remoting/base/protocol/chromotocol.pb.h"
10
11 namespace remoting {
12
13 using chromotocol_pb::UpdateStreamPacketHeader;
14 using media::DataBuffer;
15
16 void EncoderVerbatim::Encode(const DirtyRects& dirty_rects,
17 const uint8** input_data,
18 const int* strides,
19 bool key_frame,
20 UpdateStreamPacketHeader* header,
21 scoped_refptr<DataBuffer>* output_data,
22 bool* encode_done,
23 Task* data_available_task) {
24 int num_rects = dirty_rects.size();
25 for (int i = 0; i < num_rects; i++) {
26 if (EncodeRect(dirty_rects[i], input_data, strides, header, output_data)) {
27 *encode_done = (i == num_rects - 1); // Set for last rect.
28 data_available_task->Run();
29 }
30 }
31
32 delete data_available_task;
33 }
34
35 void EncoderVerbatim::SetSize(int width, int height) {
36 width_ = width;
37 height_ = height;
38 }
39
40 void EncoderVerbatim::SetPixelFormat(chromotocol_pb::PixelFormat pixel_format) {
41 // These are sorted so that the most common formats are checked first.
42 if (pixel_format == chromotocol_pb::PixelFormatRgb24) {
43 bytes_per_pixel_ = 3;
44 } else if (pixel_format == chromotocol_pb::PixelFormatRgb565) {
45 bytes_per_pixel_ = 2;
46 } else if (pixel_format == chromotocol_pb::PixelFormatRgb32) {
47 bytes_per_pixel_ = 4;
48 } else if (pixel_format != chromotocol_pb::PixelFormatAscii) {
49 bytes_per_pixel_ = 1;
50 } else {
51 NOTREACHED() << "Pixel format not supported";
52 }
53 }
54
55 bool EncoderVerbatim::EncodeRect(const gfx::Rect& dirty,
56 const uint8** input_data,
57 const int* strides,
58 UpdateStreamPacketHeader* header,
59 scoped_refptr<DataBuffer>* output_data) {
60 const int kPlanes = 3;
61
62 // Calculate the size of output.
63 int output_size = 0;
64 for (int i = 0; i < kPlanes; ++i) {
65 // TODO(hclam): Handle YUV since the height would be different.
66 output_size += strides[i] * height_;
67 }
68
69 header->set_x(dirty.x());
70 header->set_y(dirty.y());
71 header->set_width(dirty.width());
72 header->set_height(dirty.height());
73 header->set_encoding(chromotocol_pb::EncodingNone);
74
75 *output_data = new DataBuffer(output_size);
76 (*output_data)->SetDataSize(output_size);
77
78 uint8* out = (*output_data)->GetWritableData();
79 for (int i = 0; i < kPlanes; ++i) {
80 const uint8* in = input_data[i];
81 // Skip over planes that don't have data.
82 if (!in)
83 continue;
84
85 // TODO(hclam): Handle YUV since the height would be different.
86 for (int j = 0; j < height_; ++j) {
87 int row_size = width_ * bytes_per_pixel_;
88 DCHECK_LE(row_size, strides[i]);
89 memcpy(out, in, row_size);
90 in += strides[i];
91 out += row_size;
92 }
93 }
94 return true;
95 }
96
97 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/encoder_verbatim.h ('k') | remoting/host/encoder_vp8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698