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

Side by Side Diff: remoting/codec/video_decoder_row_based.cc

Issue 10873047: Renamed Decoder -> VideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
OLDNEW
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_decoder_row_based.h" 5 #include "remoting/codec/video_decoder_row_based.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "remoting/base/decompressor.h" 8 #include "remoting/base/decompressor.h"
9 #include "remoting/base/decompressor_zlib.h" 9 #include "remoting/base/decompressor_zlib.h"
10 #include "remoting/base/decompressor_verbatim.h" 10 #include "remoting/base/decompressor_verbatim.h"
11 #include "remoting/base/util.h" 11 #include "remoting/base/util.h"
12 12
13 namespace remoting { 13 namespace remoting {
14 14
15 namespace { 15 namespace {
16 // Both input and output data are assumed to be RGBA32. 16 // Both input and output data are assumed to be RGBA32.
17 const int kBytesPerPixel = 4; 17 const int kBytesPerPixel = 4;
18 } 18 }
19 19
20 DecoderRowBased* DecoderRowBased::CreateZlibDecoder() { 20 VideoDecoderRowBased* VideoDecoderRowBased::CreateZlibDecoder() {
21 return new DecoderRowBased(new DecompressorZlib(), 21 return new VideoDecoderRowBased(new DecompressorZlib(),
22 VideoPacketFormat::ENCODING_ZLIB); 22 VideoPacketFormat::ENCODING_ZLIB);
23 } 23 }
24 24
25 DecoderRowBased* DecoderRowBased::CreateVerbatimDecoder() { 25 VideoDecoderRowBased* VideoDecoderRowBased::CreateVerbatimDecoder() {
26 return new DecoderRowBased(new DecompressorVerbatim(), 26 return new VideoDecoderRowBased(new DecompressorVerbatim(),
27 VideoPacketFormat::ENCODING_VERBATIM); 27 VideoPacketFormat::ENCODING_VERBATIM);
28 } 28 }
29 29
30 DecoderRowBased::DecoderRowBased(Decompressor* decompressor, 30 VideoDecoderRowBased::VideoDecoderRowBased(Decompressor* decompressor,
31 VideoPacketFormat::Encoding encoding) 31 VideoPacketFormat::Encoding encoding)
32 : state_(kUninitialized), 32 : state_(kUninitialized),
33 clip_(SkIRect::MakeEmpty()), 33 clip_(SkIRect::MakeEmpty()),
34 decompressor_(decompressor), 34 decompressor_(decompressor),
35 encoding_(encoding), 35 encoding_(encoding),
36 row_pos_(0), 36 row_pos_(0),
37 row_y_(0), 37 row_y_(0),
38 screen_size_(SkISize::Make(0, 0)) { 38 screen_size_(SkISize::Make(0, 0)) {
39 } 39 }
40 40
41 DecoderRowBased::~DecoderRowBased() { 41 VideoDecoderRowBased::~VideoDecoderRowBased() {
42 } 42 }
43 43
44 bool DecoderRowBased::IsReadyForData() { 44 bool VideoDecoderRowBased::IsReadyForData() {
45 switch (state_) { 45 switch (state_) {
46 case kUninitialized: 46 case kUninitialized:
47 case kError: 47 case kError:
48 return false; 48 return false;
49 case kReady: 49 case kReady:
50 case kProcessing: 50 case kProcessing:
51 case kPartitionDone: 51 case kPartitionDone:
52 case kDone: 52 case kDone:
53 return true; 53 return true;
54 } 54 }
55 NOTREACHED(); 55 NOTREACHED();
56 return false; 56 return false;
57 } 57 }
58 58
59 void DecoderRowBased::Initialize(const SkISize& screen_size) { 59 void VideoDecoderRowBased::Initialize(const SkISize& screen_size) {
60 decompressor_->Reset(); 60 decompressor_->Reset();
61 updated_region_.setEmpty(); 61 updated_region_.setEmpty();
62 screen_buffer_.reset(NULL); 62 screen_buffer_.reset(NULL);
63 63
64 screen_size_ = screen_size; 64 screen_size_ = screen_size;
65 // Allocate the screen buffer, if necessary. 65 // Allocate the screen buffer, if necessary.
66 if (!screen_size_.isEmpty()) { 66 if (!screen_size_.isEmpty()) {
67 screen_buffer_.reset(new uint8[ 67 screen_buffer_.reset(new uint8[
68 screen_size_.width() * screen_size_.height() * kBytesPerPixel]); 68 screen_size_.width() * screen_size_.height() * kBytesPerPixel]);
69 } 69 }
70 70
71 state_ = kReady; 71 state_ = kReady;
72 } 72 }
73 73
74 Decoder::DecodeResult DecoderRowBased::DecodePacket(const VideoPacket* packet) { 74 VideoDecoder::DecodeResult VideoDecoderRowBased::DecodePacket(
75 const VideoPacket* packet) {
75 UpdateStateForPacket(packet); 76 UpdateStateForPacket(packet);
76 77
77 if (state_ == kError) { 78 if (state_ == kError) {
78 return DECODE_ERROR; 79 return DECODE_ERROR;
79 } 80 }
80 81
81 const uint8* in = reinterpret_cast<const uint8*>(packet->data().data()); 82 const uint8* in = reinterpret_cast<const uint8*>(packet->data().data());
82 const int in_size = packet->data().size(); 83 const int in_size = packet->data().size();
83 const int row_size = clip_.width() * kBytesPerPixel; 84 const int row_size = clip_.width() * kBytesPerPixel;
84 85
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 decompressor_->Reset(); 124 decompressor_->Reset();
124 } 125 }
125 126
126 if (state_ == kDone) { 127 if (state_ == kDone) {
127 return DECODE_DONE; 128 return DECODE_DONE;
128 } else { 129 } else {
129 return DECODE_IN_PROGRESS; 130 return DECODE_IN_PROGRESS;
130 } 131 }
131 } 132 }
132 133
133 void DecoderRowBased::UpdateStateForPacket(const VideoPacket* packet) { 134 void VideoDecoderRowBased::UpdateStateForPacket(const VideoPacket* packet) {
134 if (state_ == kError) { 135 if (state_ == kError) {
135 return; 136 return;
136 } 137 }
137 138
138 if (packet->flags() & VideoPacket::FIRST_PACKET) { 139 if (packet->flags() & VideoPacket::FIRST_PACKET) {
139 if (state_ != kReady && state_ != kDone && state_ != kPartitionDone) { 140 if (state_ != kReady && state_ != kDone && state_ != kPartitionDone) {
140 state_ = kError; 141 state_ = kError;
141 LOG(WARNING) << "Received unexpected FIRST_PACKET."; 142 LOG(WARNING) << "Received unexpected FIRST_PACKET.";
142 return; 143 return;
143 } 144 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 state_ = kError; 177 state_ = kError;
177 LOG(WARNING) << "Received unexpected LAST_PARTITION."; 178 LOG(WARNING) << "Received unexpected LAST_PARTITION.";
178 return; 179 return;
179 } 180 }
180 state_ = kDone; 181 state_ = kDone;
181 } 182 }
182 183
183 return; 184 return;
184 } 185 }
185 186
186 VideoPacketFormat::Encoding DecoderRowBased::Encoding() { 187 VideoPacketFormat::Encoding VideoDecoderRowBased::Encoding() {
187 return encoding_; 188 return encoding_;
188 } 189 }
189 190
190 void DecoderRowBased::Invalidate(const SkISize& view_size, 191 void VideoDecoderRowBased::Invalidate(const SkISize& view_size,
191 const SkRegion& region) { 192 const SkRegion& region) {
192 updated_region_.op(region, SkRegion::kUnion_Op); 193 updated_region_.op(region, SkRegion::kUnion_Op);
193 } 194 }
194 195
195 void DecoderRowBased::RenderFrame(const SkISize& view_size, 196 void VideoDecoderRowBased::RenderFrame(const SkISize& view_size,
196 const SkIRect& clip_area, 197 const SkIRect& clip_area,
197 uint8* image_buffer, 198 uint8* image_buffer,
198 int image_stride, 199 int image_stride,
199 SkRegion* output_region) { 200 SkRegion* output_region) {
200 output_region->setEmpty(); 201 output_region->setEmpty();
201 202
202 // TODO(alexeypa): scaling is not implemented. 203 // TODO(alexeypa): scaling is not implemented.
203 SkIRect clip_rect = SkIRect::MakeSize(screen_size_); 204 SkIRect clip_rect = SkIRect::MakeSize(screen_size_);
204 if (!clip_rect.intersect(clip_area)) 205 if (!clip_rect.intersect(clip_area))
205 return; 206 return;
206 207
207 int screen_stride = screen_size_.width() * kBytesPerPixel; 208 int screen_stride = screen_size_.width() * kBytesPerPixel;
208 209
209 for (SkRegion::Iterator i(updated_region_); !i.done(); i.next()) { 210 for (SkRegion::Iterator i(updated_region_); !i.done(); i.next()) {
210 SkIRect rect(i.rect()); 211 SkIRect rect(i.rect());
211 if (!rect.intersect(clip_rect)) 212 if (!rect.intersect(clip_rect))
212 continue; 213 continue;
213 214
214 CopyRGB32Rect(screen_buffer_.get(), screen_stride, 215 CopyRGB32Rect(screen_buffer_.get(), screen_stride,
215 clip_rect, 216 clip_rect,
216 image_buffer, image_stride, 217 image_buffer, image_stride,
217 clip_area, 218 clip_area,
218 rect); 219 rect);
219 output_region->op(rect, SkRegion::kUnion_Op); 220 output_region->op(rect, SkRegion::kUnion_Op);
220 } 221 }
221 222
222 updated_region_.setEmpty(); 223 updated_region_.setEmpty();
223 } 224 }
224 225
225 } // namespace remoting 226 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698