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

Side by Side Diff: remoting/client/rectangle_update_decoder.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/client/rectangle_update_decoder.h ('k') | remoting/host/capturer.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/client/rectangle_update_decoder.h" 5 #include "remoting/client/rectangle_update_decoder.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "media/base/callback.h" 9 #include "media/base/callback.h"
10 #include "remoting/base/decoder.h" 10 #include "remoting/base/decoder.h"
11 #include "remoting/base/decoder_row_based.h" 11 #include "remoting/base/decoder_row_based.h"
12 #include "remoting/base/decoder_vp8.h"
12 #include "remoting/base/tracer.h" 13 #include "remoting/base/tracer.h"
13 #include "remoting/base/util.h" 14 #include "remoting/base/util.h"
14 #include "remoting/client/frame_consumer.h" 15 #include "remoting/client/frame_consumer.h"
15 16
16 using media::AutoTaskRunner; 17 using media::AutoTaskRunner;
17 18
18 namespace remoting { 19 namespace remoting {
19 20
20 namespace { 21 namespace {
21 22
(...skipping 17 matching lines...) Expand all
39 40
40 RectangleUpdateDecoder::RectangleUpdateDecoder(MessageLoop* message_loop, 41 RectangleUpdateDecoder::RectangleUpdateDecoder(MessageLoop* message_loop,
41 FrameConsumer* consumer) 42 FrameConsumer* consumer)
42 : message_loop_(message_loop), 43 : message_loop_(message_loop),
43 consumer_(consumer) { 44 consumer_(consumer) {
44 } 45 }
45 46
46 RectangleUpdateDecoder::~RectangleUpdateDecoder() { 47 RectangleUpdateDecoder::~RectangleUpdateDecoder() {
47 } 48 }
48 49
49 void RectangleUpdateDecoder::DecodePacket(const RectangleUpdatePacket& packet, 50 void RectangleUpdateDecoder::DecodePacket(const VideoPacket& packet,
50 Task* done) { 51 Task* done) {
51 if (message_loop_ != MessageLoop::current()) { 52 if (message_loop_ != MessageLoop::current()) {
52 message_loop_->PostTask( 53 message_loop_->PostTask(
53 FROM_HERE, 54 FROM_HERE,
54 NewTracedMethod(this, 55 NewTracedMethod(this,
55 &RectangleUpdateDecoder::DecodePacket, packet, 56 &RectangleUpdateDecoder::DecodePacket, packet,
56 done)); 57 done));
57 return; 58 return;
58 } 59 }
59 AutoTaskRunner done_runner(done); 60 AutoTaskRunner done_runner(done);
60 61
61 TraceContext::tracer()->PrintString("Decode Packet called."); 62 TraceContext::tracer()->PrintString("Decode Packet called.");
62 63
63 if (!IsValidPacket(packet)) { 64 if (!IsValidPacket(packet)) {
64 LOG(ERROR) << "Received invalid packet."; 65 LOG(ERROR) << "Received invalid packet.";
65 return; 66 return;
66 } 67 }
67 68
68 Task* process_packet_data = 69 Task* process_packet_data =
69 NewTracedMethod(this, 70 NewTracedMethod(this,
70 &RectangleUpdateDecoder::ProcessPacketData, 71 &RectangleUpdateDecoder::ProcessPacketData,
71 packet, done_runner.release()); 72 packet, done_runner.release());
72 73
73 if (packet.flags() | RectangleUpdatePacket::FIRST_PACKET) { 74 if (packet.flags() | VideoPacket::FIRST_PACKET) {
74 const RectangleFormat& format = packet.format(); 75 const VideoPacketFormat& format = packet.format();
75 76
76 InitializeDecoder(format, process_packet_data); 77 InitializeDecoder(format, process_packet_data);
77 } else { 78 } else {
78 process_packet_data->Run(); 79 process_packet_data->Run();
79 delete process_packet_data; 80 delete process_packet_data;
80 } 81 }
81 } 82 }
82 83
83 void RectangleUpdateDecoder::ProcessPacketData( 84 void RectangleUpdateDecoder::ProcessPacketData(
84 const RectangleUpdatePacket& packet, 85 const VideoPacket& packet, Task* done) {
85 Task* done) {
86 AutoTaskRunner done_runner(done); 86 AutoTaskRunner done_runner(done);
87 87
88 if (!decoder_->IsReadyForData()) { 88 if (!decoder_->IsReadyForData()) {
89 // TODO(ajwong): This whole thing should move into an invalid state. 89 // TODO(ajwong): This whole thing should move into an invalid state.
90 LOG(ERROR) << "Decoder is unable to process data. Dropping packet."; 90 LOG(ERROR) << "Decoder is unable to process data. Dropping packet.";
91 return; 91 return;
92 } 92 }
93 93
94 TraceContext::tracer()->PrintString("Executing Decode."); 94 TraceContext::tracer()->PrintString("Executing Decode.");
95 decoder_->DecodeBytes(packet.encoded_rect()); 95 decoder_->DecodeBytes(packet.data());
96 96
97 if (packet.flags() | RectangleUpdatePacket::LAST_PACKET) { 97 if (packet.flags() | VideoPacket::LAST_PACKET) {
98 decoder_->Reset(); 98 decoder_->Reset();
99 99
100 UpdatedRects* rects = new UpdatedRects(); 100 UpdatedRects* rects = new UpdatedRects();
101 101
102 // Empty out the list of current updated rects so the decoder can keep 102 // Empty out the list of current updated rects so the decoder can keep
103 // writing new ones while these are processed. 103 // writing new ones while these are processed.
104 rects->swap(updated_rects_); 104 rects->swap(updated_rects_);
105 105
106 consumer_->OnPartialFrameOutput(frame_, rects, 106 consumer_->OnPartialFrameOutput(frame_, rects,
107 new PartialFrameCleanup(frame_, rects)); 107 new PartialFrameCleanup(frame_, rects));
108 } 108 }
109 } 109 }
110 110
111 // static 111 // static
112 bool RectangleUpdateDecoder::IsValidPacket( 112 bool RectangleUpdateDecoder::IsValidPacket(const VideoPacket& packet) {
113 const RectangleUpdatePacket& packet) {
114 if (!packet.IsInitialized()) { 113 if (!packet.IsInitialized()) {
115 LOG(WARNING) << "Protobuf consistency checks fail."; 114 LOG(WARNING) << "Protobuf consistency checks fail.";
116 return false; 115 return false;
117 } 116 }
118 117
119 // First packet must have a format. 118 // First packet must have a format.
120 if (packet.flags() | RectangleUpdatePacket::FIRST_PACKET) { 119 if (packet.flags() | VideoPacket::FIRST_PACKET) {
121 if (!packet.has_format()) { 120 if (!packet.has_format()) {
122 LOG(WARNING) << "First packet must have format."; 121 LOG(WARNING) << "First packet must have format.";
123 return false; 122 return false;
124 } 123 }
125 124
126 // TODO(ajwong): Verify that we don't need to whitelist encodings. 125 // TODO(ajwong): Verify that we don't need to whitelist encodings.
127 const RectangleFormat& format = packet.format(); 126 const VideoPacketFormat& format = packet.format();
128 if (!format.has_encoding() || 127 if (!format.has_encoding() ||
129 format.encoding() == EncodingInvalid) { 128 format.encoding() == VideoPacketFormat::ENCODING_INVALID) {
130 LOG(WARNING) << "Invalid encoding specified."; 129 LOG(WARNING) << "Invalid encoding specified.";
131 return false; 130 return false;
132 } 131 }
133 } 132 }
134 133
135 // We shouldn't generate null packets. 134 // We shouldn't generate null packets.
136 if (!packet.has_encoded_rect()) { 135 if (!packet.has_data()) {
137 LOG(WARNING) << "Packet w/o an encoded rectangle received."; 136 LOG(WARNING) << "Packet w/o data received.";
138 return false; 137 return false;
139 } 138 }
140 139
141 return true; 140 return true;
142 } 141 }
143 142
144 void RectangleUpdateDecoder::InitializeDecoder(const RectangleFormat& format, 143 void RectangleUpdateDecoder::InitializeDecoder(const VideoPacketFormat& format,
145 Task* done) { 144 Task* done) {
146 if (message_loop_ != MessageLoop::current()) { 145 if (message_loop_ != MessageLoop::current()) {
147 message_loop_->PostTask( 146 message_loop_->PostTask(
148 FROM_HERE, 147 FROM_HERE,
149 NewTracedMethod(this, 148 NewTracedMethod(this,
150 &RectangleUpdateDecoder::InitializeDecoder, 149 &RectangleUpdateDecoder::InitializeDecoder,
151 format, done)); 150 format, done));
152 return; 151 return;
153 } 152 }
154 AutoTaskRunner done_runner(done); 153 AutoTaskRunner done_runner(done);
(...skipping 30 matching lines...) Expand all
185 // stream that changes decoders. At the very leask, we should not 184 // stream that changes decoders. At the very leask, we should not
186 // crash the process. 185 // crash the process.
187 // 186 //
188 // For now though, assume that only one encoding is used throughout. 187 // For now though, assume that only one encoding is used throughout.
189 // 188 //
190 // Note, this may be as simple as just deleting the current decoder. 189 // Note, this may be as simple as just deleting the current decoder.
191 // However, we need to verify the flushing semantics of the decoder first. 190 // However, we need to verify the flushing semantics of the decoder first.
192 CHECK(decoder_->Encoding() == format.encoding()); 191 CHECK(decoder_->Encoding() == format.encoding());
193 } else { 192 } else {
194 // Initialize a new decoder based on this message encoding. 193 // Initialize a new decoder based on this message encoding.
195 if (format.encoding() == EncodingNone) { 194 if (format.encoding() == VideoPacketFormat::ENCODING_VERBATIM) {
196 TraceContext::tracer()->PrintString("Creating Verbatim decoder."); 195 TraceContext::tracer()->PrintString("Creating Verbatim decoder.");
197 decoder_.reset(DecoderRowBased::CreateVerbatimDecoder()); 196 decoder_.reset(DecoderRowBased::CreateVerbatimDecoder());
198 } else if (format.encoding() == EncodingZlib) { 197 } else if (format.encoding() == VideoPacketFormat::ENCODING_ZLIB) {
199 TraceContext::tracer()->PrintString("Creating Zlib decoder"); 198 TraceContext::tracer()->PrintString("Creating Zlib decoder");
200 decoder_.reset(DecoderRowBased::CreateZlibDecoder()); 199 decoder_.reset(DecoderRowBased::CreateZlibDecoder());
200 } else if (format.encoding() == VideoPacketFormat::ENCODING_VP8) {
201 TraceContext::tracer()->PrintString("Creating VP8 decoder");
202 decoder_.reset(new DecoderVp8());
201 } else { 203 } else {
202 NOTREACHED() << "Invalid Encoding found: " << format.encoding(); 204 NOTREACHED() << "Invalid Encoding found: " << format.encoding();
203 } 205 }
204 } 206 }
205 207
206 // TODO(ajwong): This can happen in the face of corrupt input data. Figure 208 // TODO(ajwong): This can happen in the face of corrupt input data. Figure
207 // out the right behavior and make this more resilient. 209 // out the right behavior and make this more resilient.
208 CHECK(updated_rects_.empty()); 210 CHECK(updated_rects_.empty());
209 211
210 gfx::Rect rectangle_size(format.x(), format.y(), 212 gfx::Rect rectangle_size(format.x(), format.y(),
211 format.width(), format.height()); 213 format.width(), format.height());
212 updated_rects_.push_back(rectangle_size); 214 updated_rects_.push_back(rectangle_size);
213 decoder_->Initialize(frame_, rectangle_size, 215 decoder_->Initialize(frame_, rectangle_size,
214 GetBytesPerPixel(format.pixel_format())); 216 GetBytesPerPixel(format.pixel_format()));
215 TraceContext::tracer()->PrintString("Decoder is Initialized"); 217 TraceContext::tracer()->PrintString("Decoder is Initialized");
216 } 218 }
217 219
218 } // namespace remoting 220 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/rectangle_update_decoder.h ('k') | remoting/host/capturer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698