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

Side by Side Diff: remoting/client/rectangle_update_decoder.cc

Issue 4255001: Revert 64672 - Cleanups in the video encoding decoding code. Reenable VP8.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
13 #include "remoting/base/tracer.h" 12 #include "remoting/base/tracer.h"
14 #include "remoting/base/util.h" 13 #include "remoting/base/util.h"
15 #include "remoting/client/frame_consumer.h" 14 #include "remoting/client/frame_consumer.h"
16 15
17 using media::AutoTaskRunner; 16 using media::AutoTaskRunner;
18 17
19 namespace remoting { 18 namespace remoting {
20 19
21 namespace { 20 namespace {
22 21
(...skipping 17 matching lines...) Expand all
40 39
41 RectangleUpdateDecoder::RectangleUpdateDecoder(MessageLoop* message_loop, 40 RectangleUpdateDecoder::RectangleUpdateDecoder(MessageLoop* message_loop,
42 FrameConsumer* consumer) 41 FrameConsumer* consumer)
43 : message_loop_(message_loop), 42 : message_loop_(message_loop),
44 consumer_(consumer) { 43 consumer_(consumer) {
45 } 44 }
46 45
47 RectangleUpdateDecoder::~RectangleUpdateDecoder() { 46 RectangleUpdateDecoder::~RectangleUpdateDecoder() {
48 } 47 }
49 48
50 void RectangleUpdateDecoder::DecodePacket(const VideoPacket& packet, 49 void RectangleUpdateDecoder::DecodePacket(const RectangleUpdatePacket& packet,
51 Task* done) { 50 Task* done) {
52 if (message_loop_ != MessageLoop::current()) { 51 if (message_loop_ != MessageLoop::current()) {
53 message_loop_->PostTask( 52 message_loop_->PostTask(
54 FROM_HERE, 53 FROM_HERE,
55 NewTracedMethod(this, 54 NewTracedMethod(this,
56 &RectangleUpdateDecoder::DecodePacket, packet, 55 &RectangleUpdateDecoder::DecodePacket, packet,
57 done)); 56 done));
58 return; 57 return;
59 } 58 }
60 AutoTaskRunner done_runner(done); 59 AutoTaskRunner done_runner(done);
61 60
62 TraceContext::tracer()->PrintString("Decode Packet called."); 61 TraceContext::tracer()->PrintString("Decode Packet called.");
63 62
64 if (!IsValidPacket(packet)) { 63 if (!IsValidPacket(packet)) {
65 LOG(ERROR) << "Received invalid packet."; 64 LOG(ERROR) << "Received invalid packet.";
66 return; 65 return;
67 } 66 }
68 67
69 Task* process_packet_data = 68 Task* process_packet_data =
70 NewTracedMethod(this, 69 NewTracedMethod(this,
71 &RectangleUpdateDecoder::ProcessPacketData, 70 &RectangleUpdateDecoder::ProcessPacketData,
72 packet, done_runner.release()); 71 packet, done_runner.release());
73 72
74 if (packet.flags() | VideoPacket::FIRST_PACKET) { 73 if (packet.flags() | RectangleUpdatePacket::FIRST_PACKET) {
75 const VideoPacketFormat& format = packet.format(); 74 const RectangleFormat& format = packet.format();
76 75
77 InitializeDecoder(format, process_packet_data); 76 InitializeDecoder(format, process_packet_data);
78 } else { 77 } else {
79 process_packet_data->Run(); 78 process_packet_data->Run();
80 delete process_packet_data; 79 delete process_packet_data;
81 } 80 }
82 } 81 }
83 82
84 void RectangleUpdateDecoder::ProcessPacketData( 83 void RectangleUpdateDecoder::ProcessPacketData(
85 const VideoPacket& packet, Task* done) { 84 const RectangleUpdatePacket& packet,
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.data()); 95 decoder_->DecodeBytes(packet.encoded_rect());
96 96
97 if (packet.flags() | VideoPacket::LAST_PACKET) { 97 if (packet.flags() | RectangleUpdatePacket::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(const VideoPacket& packet) { 112 bool RectangleUpdateDecoder::IsValidPacket(
113 const RectangleUpdatePacket& packet) {
113 if (!packet.IsInitialized()) { 114 if (!packet.IsInitialized()) {
114 LOG(WARNING) << "Protobuf consistency checks fail."; 115 LOG(WARNING) << "Protobuf consistency checks fail.";
115 return false; 116 return false;
116 } 117 }
117 118
118 // First packet must have a format. 119 // First packet must have a format.
119 if (packet.flags() | VideoPacket::FIRST_PACKET) { 120 if (packet.flags() | RectangleUpdatePacket::FIRST_PACKET) {
120 if (!packet.has_format()) { 121 if (!packet.has_format()) {
121 LOG(WARNING) << "First packet must have format."; 122 LOG(WARNING) << "First packet must have format.";
122 return false; 123 return false;
123 } 124 }
124 125
125 // TODO(ajwong): Verify that we don't need to whitelist encodings. 126 // TODO(ajwong): Verify that we don't need to whitelist encodings.
126 const VideoPacketFormat& format = packet.format(); 127 const RectangleFormat& format = packet.format();
127 if (!format.has_encoding() || 128 if (!format.has_encoding() ||
128 format.encoding() == VideoPacketFormat::ENCODING_INVALID) { 129 format.encoding() == EncodingInvalid) {
129 LOG(WARNING) << "Invalid encoding specified."; 130 LOG(WARNING) << "Invalid encoding specified.";
130 return false; 131 return false;
131 } 132 }
132 } 133 }
133 134
134 // We shouldn't generate null packets. 135 // We shouldn't generate null packets.
135 if (!packet.has_data()) { 136 if (!packet.has_encoded_rect()) {
136 LOG(WARNING) << "Packet w/o data received."; 137 LOG(WARNING) << "Packet w/o an encoded rectangle received.";
137 return false; 138 return false;
138 } 139 }
139 140
140 return true; 141 return true;
141 } 142 }
142 143
143 void RectangleUpdateDecoder::InitializeDecoder(const VideoPacketFormat& format, 144 void RectangleUpdateDecoder::InitializeDecoder(const RectangleFormat& format,
144 Task* done) { 145 Task* done) {
145 if (message_loop_ != MessageLoop::current()) { 146 if (message_loop_ != MessageLoop::current()) {
146 message_loop_->PostTask( 147 message_loop_->PostTask(
147 FROM_HERE, 148 FROM_HERE,
148 NewTracedMethod(this, 149 NewTracedMethod(this,
149 &RectangleUpdateDecoder::InitializeDecoder, 150 &RectangleUpdateDecoder::InitializeDecoder,
150 format, done)); 151 format, done));
151 return; 152 return;
152 } 153 }
153 AutoTaskRunner done_runner(done); 154 AutoTaskRunner done_runner(done);
(...skipping 30 matching lines...) Expand all
184 // stream that changes decoders. At the very leask, we should not 185 // stream that changes decoders. At the very leask, we should not
185 // crash the process. 186 // crash the process.
186 // 187 //
187 // For now though, assume that only one encoding is used throughout. 188 // For now though, assume that only one encoding is used throughout.
188 // 189 //
189 // Note, this may be as simple as just deleting the current decoder. 190 // Note, this may be as simple as just deleting the current decoder.
190 // However, we need to verify the flushing semantics of the decoder first. 191 // However, we need to verify the flushing semantics of the decoder first.
191 CHECK(decoder_->Encoding() == format.encoding()); 192 CHECK(decoder_->Encoding() == format.encoding());
192 } else { 193 } else {
193 // Initialize a new decoder based on this message encoding. 194 // Initialize a new decoder based on this message encoding.
194 if (format.encoding() == VideoPacketFormat::ENCODING_VERBATIM) { 195 if (format.encoding() == EncodingNone) {
195 TraceContext::tracer()->PrintString("Creating Verbatim decoder."); 196 TraceContext::tracer()->PrintString("Creating Verbatim decoder.");
196 decoder_.reset(DecoderRowBased::CreateVerbatimDecoder()); 197 decoder_.reset(DecoderRowBased::CreateVerbatimDecoder());
197 } else if (format.encoding() == VideoPacketFormat::ENCODING_ZLIB) { 198 } else if (format.encoding() == EncodingZlib) {
198 TraceContext::tracer()->PrintString("Creating Zlib decoder"); 199 TraceContext::tracer()->PrintString("Creating Zlib decoder");
199 decoder_.reset(DecoderRowBased::CreateZlibDecoder()); 200 decoder_.reset(DecoderRowBased::CreateZlibDecoder());
200 } else if (format.encoding() == VideoPacketFormat::ENCODING_VP8) {
201 TraceContext::tracer()->PrintString("Creating VP8 decoder");
202 decoder_.reset(new DecoderVp8());
203 } else { 201 } else {
204 NOTREACHED() << "Invalid Encoding found: " << format.encoding(); 202 NOTREACHED() << "Invalid Encoding found: " << format.encoding();
205 } 203 }
206 } 204 }
207 205
208 // TODO(ajwong): This can happen in the face of corrupt input data. Figure 206 // TODO(ajwong): This can happen in the face of corrupt input data. Figure
209 // out the right behavior and make this more resilient. 207 // out the right behavior and make this more resilient.
210 CHECK(updated_rects_.empty()); 208 CHECK(updated_rects_.empty());
211 209
212 gfx::Rect rectangle_size(format.x(), format.y(), 210 gfx::Rect rectangle_size(format.x(), format.y(),
213 format.width(), format.height()); 211 format.width(), format.height());
214 updated_rects_.push_back(rectangle_size); 212 updated_rects_.push_back(rectangle_size);
215 decoder_->Initialize(frame_, rectangle_size, 213 decoder_->Initialize(frame_, rectangle_size,
216 GetBytesPerPixel(format.pixel_format())); 214 GetBytesPerPixel(format.pixel_format()));
217 TraceContext::tracer()->PrintString("Decoder is Initialized"); 215 TraceContext::tracer()->PrintString("Decoder is Initialized");
218 } 216 }
219 217
220 } // namespace remoting 218 } // 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