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

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

Issue 4136010: Cleanups in the video encoding decoding code. Reenable VP8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed arm build Created 10 years, 1 month 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/base/encoder_verbatim.h ('k') | remoting/base/encoder_vp8.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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/base/encoder_verbatim.h" 5 #include "remoting/base/encoder_verbatim.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "gfx/rect.h" 8 #include "gfx/rect.h"
9 #include "media/base/data_buffer.h" 9 #include "media/base/data_buffer.h"
10 #include "remoting/base/capture_data.h" 10 #include "remoting/base/capture_data.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 // TODO(garykac): This assumes that the rect fits into a single packet. 47 // TODO(garykac): This assumes that the rect fits into a single packet.
48 // Fix this by modeling after code in encoder_zlib.cc 48 // Fix this by modeling after code in encoder_zlib.cc
49 void EncoderVerbatim::EncodeRect(const gfx::Rect& rect, size_t rect_index) { 49 void EncoderVerbatim::EncodeRect(const gfx::Rect& rect, size_t rect_index) {
50 CHECK(capture_data_->data_planes().data[0]); 50 CHECK(capture_data_->data_planes().data[0]);
51 const int stride = capture_data_->data_planes().strides[0]; 51 const int stride = capture_data_->data_planes().strides[0];
52 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format()); 52 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format());
53 const int row_size = bytes_per_pixel * rect.width(); 53 const int row_size = bytes_per_pixel * rect.width();
54 54
55 ChromotingHostMessage* message = new ChromotingHostMessage(); 55 VideoPacket* packet = new VideoPacket();
56 RectangleUpdatePacket* update = message->mutable_rectangle_update(); 56 PrepareUpdateStart(rect, packet);
57 PrepareUpdateStart(rect, update);
58 57
59 const uint8* in = capture_data_->data_planes().data[0] + 58 const uint8* in = capture_data_->data_planes().data[0] +
60 rect.y() * stride + 59 rect.y() * stride +
61 rect.x() * bytes_per_pixel; 60 rect.x() * bytes_per_pixel;
62 // TODO(hclam): Fill in the sequence number. 61 // TODO(hclam): Fill in the sequence number.
63 uint8* out = GetOutputBuffer(update, packet_size_); 62 uint8* out = GetOutputBuffer(packet, packet_size_);
64 int total_bytes = 0; 63 int total_bytes = 0;
65 for (int y = 0; y < rect.height(); y++) { 64 for (int y = 0; y < rect.height(); y++) {
66 memcpy(out, in, row_size); 65 memcpy(out, in, row_size);
67 out += row_size; 66 out += row_size;
68 in += stride; 67 in += stride;
69 total_bytes += row_size; 68 total_bytes += row_size;
70 } 69 }
71 70
72 // We have reached the end of stream. 71 // We have reached the end of stream.
73 update->set_flags(update->flags() | RectangleUpdatePacket::LAST_PACKET); 72 packet->set_flags(packet->flags() | VideoPacket::LAST_PACKET);
74 73
75 // If we have filled the message or we have reached the end of stream. 74 // If we have filled the message or we have reached the end of stream.
76 message->mutable_rectangle_update()->mutable_encoded_rect()-> 75 packet->mutable_data()->resize(total_bytes);
77 resize(total_bytes); 76 SubmitMessage(packet, rect_index);
78 SubmitMessage(message, rect_index);
79 } 77 }
80 78
81 void EncoderVerbatim::PrepareUpdateStart(const gfx::Rect& rect, 79 void EncoderVerbatim::PrepareUpdateStart(const gfx::Rect& rect,
82 RectangleUpdatePacket* update) { 80 VideoPacket* packet) {
83 81
84 update->set_flags(update->flags() | RectangleUpdatePacket::FIRST_PACKET); 82 packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET);
85 RectangleFormat* format = update->mutable_format(); 83 VideoPacketFormat* format = packet->mutable_format();
86 84
87 format->set_x(rect.x()); 85 format->set_x(rect.x());
88 format->set_y(rect.y()); 86 format->set_y(rect.y());
89 format->set_width(rect.width()); 87 format->set_width(rect.width());
90 format->set_height(rect.height()); 88 format->set_height(rect.height());
91 format->set_encoding(EncodingNone); 89 format->set_encoding(VideoPacketFormat::ENCODING_VERBATIM);
92 format->set_pixel_format(capture_data_->pixel_format()); 90 format->set_pixel_format(capture_data_->pixel_format());
93 } 91 }
94 92
95 uint8* EncoderVerbatim::GetOutputBuffer(RectangleUpdatePacket* update, 93 uint8* EncoderVerbatim::GetOutputBuffer(VideoPacket* packet, size_t size) {
96 size_t size) { 94 packet->mutable_data()->resize(size);
97 update->mutable_encoded_rect()->resize(size);
98 // TODO(ajwong): Is there a better way to do this at all??? 95 // TODO(ajwong): Is there a better way to do this at all???
99 return const_cast<uint8*>(reinterpret_cast<const uint8*>( 96 return const_cast<uint8*>(reinterpret_cast<const uint8*>(
100 update->mutable_encoded_rect()->data())); 97 packet->mutable_data()->data()));
101 } 98 }
102 99
103 void EncoderVerbatim::SubmitMessage(ChromotingHostMessage* message, 100 void EncoderVerbatim::SubmitMessage(VideoPacket* packet, size_t rect_index) {
104 size_t rect_index) { 101 callback_->Run(packet);
105 EncodingState state = EncodingInProgress;
106 const RectangleUpdatePacket& update = message->rectangle_update();
107 if (rect_index == 0 &&
108 (update.flags() | RectangleUpdatePacket::FIRST_PACKET)) {
109 state |= EncodingStarting;
110 }
111 if (rect_index == capture_data_->dirty_rects().size() - 1 &&
112 (update.flags() | RectangleUpdatePacket::LAST_PACKET)) {
113 state |= EncodingEnded;
114 }
115 callback_->Run(message, state);
116 } 102 }
117 103
118 } // namespace remoting 104 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/encoder_verbatim.h ('k') | remoting/base/encoder_vp8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698