Chromium Code Reviews| Index: remoting/codec/video_encoder_verbatim.cc |
| diff --git a/remoting/codec/video_encoder_row_based.cc b/remoting/codec/video_encoder_verbatim.cc |
| similarity index 52% |
| rename from remoting/codec/video_encoder_row_based.cc |
| rename to remoting/codec/video_encoder_verbatim.cc |
| index b2454aa18c1f822efb602cbae5cf4263577488c4..bcac5ded21a6beb3d769ecf9700d456bb2dff707 100644 |
| --- a/remoting/codec/video_encoder_row_based.cc |
| +++ b/remoting/codec/video_encoder_verbatim.cc |
| @@ -2,12 +2,10 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "remoting/codec/video_encoder_row_based.h" |
| +#include "remoting/codec/video_encoder_verbatim.h" |
| #include "base/logging.h" |
| #include "remoting/base/capture_data.h" |
| -#include "remoting/base/compressor_verbatim.h" |
| -#include "remoting/base/compressor_zlib.h" |
| #include "remoting/base/util.h" |
| #include "remoting/proto/video.pb.h" |
| @@ -15,49 +13,19 @@ namespace remoting { |
| static const int kPacketSize = 1024 * 1024; |
| -VideoEncoderRowBased* VideoEncoderRowBased::CreateZlibEncoder() { |
| - return new VideoEncoderRowBased(new CompressorZlib(), |
| - VideoPacketFormat::ENCODING_ZLIB); |
| -} |
| - |
| -VideoEncoderRowBased* VideoEncoderRowBased::CreateZlibEncoder(int packet_size) { |
| - return new VideoEncoderRowBased(new CompressorZlib(), |
| - VideoPacketFormat::ENCODING_ZLIB, |
| - packet_size); |
| -} |
| - |
| -VideoEncoderRowBased* VideoEncoderRowBased::CreateVerbatimEncoder() { |
| - return new VideoEncoderRowBased(new CompressorVerbatim(), |
| - VideoPacketFormat::ENCODING_VERBATIM); |
| -} |
| - |
| -VideoEncoderRowBased* VideoEncoderRowBased::CreateVerbatimEncoder( |
| - int packet_size) { |
| - return new VideoEncoderRowBased(new CompressorVerbatim(), |
| - VideoPacketFormat::ENCODING_VERBATIM, |
| - packet_size); |
| -} |
| - |
| -VideoEncoderRowBased::VideoEncoderRowBased(Compressor* compressor, |
| - VideoPacketFormat::Encoding encoding) |
| - : encoding_(encoding), |
| - compressor_(compressor), |
| - screen_size_(SkISize::Make(0,0)), |
| +VideoEncoderVerbatim::VideoEncoderVerbatim() |
| + : screen_size_(SkISize::Make(0,0)), |
| packet_size_(kPacketSize) { |
| } |
| -VideoEncoderRowBased::VideoEncoderRowBased(Compressor* compressor, |
| - VideoPacketFormat::Encoding encoding, |
| - int packet_size) |
| - : encoding_(encoding), |
| - compressor_(compressor), |
| - screen_size_(SkISize::Make(0,0)), |
| - packet_size_(packet_size) { |
| +void VideoEncoderVerbatim::SetMaxPacketSize(int size) { |
| + packet_size_ = size; |
| } |
| -VideoEncoderRowBased::~VideoEncoderRowBased() {} |
| +VideoEncoderVerbatim::~VideoEncoderVerbatim() { |
| +} |
| -void VideoEncoderRowBased::Encode( |
| +void VideoEncoderVerbatim::Encode( |
| scoped_refptr<CaptureData> capture_data, |
| bool key_frame, |
| const DataAvailableCallback& data_available_callback) { |
| @@ -79,15 +47,13 @@ void VideoEncoderRowBased::Encode( |
| callback_.Reset(); |
| } |
| -void VideoEncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { |
| +void VideoEncoderVerbatim::EncodeRect(const SkIRect& rect, bool last) { |
| CHECK(capture_data_->data_planes().data[0]); |
| CHECK_EQ(capture_data_->pixel_format(), media::VideoFrame::RGB32); |
| const int strides = capture_data_->data_planes().strides[0]; |
| const int bytes_per_pixel = 4; |
| const int row_size = bytes_per_pixel * rect.width(); |
| - compressor_->Reset(); |
| - |
| scoped_ptr<VideoPacket> packet(new VideoPacket()); |
| PrepareUpdateStart(rect, packet.get()); |
| const uint8* in = capture_data_->data_planes().data[0] + |
| @@ -97,8 +63,7 @@ void VideoEncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { |
| int filled = 0; |
| int row_pos = 0; // Position in the current row in bytes. |
| int row_y = 0; // Current row. |
| - bool compress_again = true; |
| - while (compress_again) { |
| + while (row_y < rect.height()) { |
| // Prepare a message for sending out. |
| if (!packet.get()) { |
| packet.reset(new VideoPacket()); |
| @@ -106,21 +71,24 @@ void VideoEncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { |
| filled = 0; |
| } |
| - Compressor::CompressorFlush flush = Compressor::CompressorNoFlush; |
| - if (row_y == rect.height() - 1) { |
| - flush = Compressor::CompressorFinish; |
| + if (row_y < rect.height()) { |
| + int bytes_to_copy = std::min(row_size - row_pos, packet_size_ - filled); |
| + memcpy(out + filled, in + row_pos, bytes_to_copy); |
| + row_pos += bytes_to_copy; |
| + filled += bytes_to_copy; |
| + |
| + // Just to the next row when we've reached the end of the current row. |
|
Wez
2012/10/17 22:25:16
nit: Just -> Move
Sergey Ulanov
2012/10/18 01:09:52
Changed to "Jump"
|
| + if (row_pos == row_size) { |
| + row_pos = 0; |
| + in += strides; |
| + ++row_y; |
| + } |
| } |
| - int consumed = 0; |
| - int written = 0; |
| - compress_again = compressor_->Process(in + row_pos, row_size - row_pos, |
| - out + filled, packet_size_ - filled, |
| - flush, &consumed, &written); |
| - row_pos += consumed; |
| - filled += written; |
| + if (row_y == rect.height()) { |
| + DCHECK_EQ(row_pos, 0); |
| - // We have reached the end of stream. |
| - if (!compress_again) { |
| + packet->mutable_data()->resize(filled); |
| packet->set_flags(packet->flags() | VideoPacket::LAST_PACKET); |
| packet->set_capture_time_ms(capture_data_->capture_time_ms()); |
| packet->set_client_sequence_number( |
| @@ -132,26 +100,17 @@ void VideoEncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { |
| packet->mutable_format()->set_y_dpi(dpi.y()); |
| if (last) |
| packet->set_flags(packet->flags() | VideoPacket::LAST_PARTITION); |
| - DCHECK(row_pos == row_size); |
| - DCHECK(row_y == rect.height() - 1); |
| } |
| - // If we have filled the message or we have reached the end of stream. |
| - if (filled == packet_size_ || !compress_again) { |
| + // If we have filled the current packet, then send it. |
| + if (filled == packet_size_ || row_y == rect.height()) { |
| packet->mutable_data()->resize(filled); |
| callback_.Run(packet.Pass()); |
| } |
| - |
| - // Reached the end of input row and we're not at the last row. |
| - if (row_pos == row_size && row_y < rect.height() - 1) { |
| - row_pos = 0; |
| - in += strides; |
| - ++row_y; |
| - } |
| } |
| } |
| -void VideoEncoderRowBased::PrepareUpdateStart(const SkIRect& rect, |
| +void VideoEncoderVerbatim::PrepareUpdateStart(const SkIRect& rect, |
| VideoPacket* packet) { |
| packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET); |
| @@ -160,7 +119,7 @@ void VideoEncoderRowBased::PrepareUpdateStart(const SkIRect& rect, |
| format->set_y(rect.fTop); |
| format->set_width(rect.width()); |
| format->set_height(rect.height()); |
| - format->set_encoding(encoding_); |
| + format->set_encoding(VideoPacketFormat::ENCODING_VERBATIM); |
| if (capture_data_->size() != screen_size_) { |
| screen_size_ = capture_data_->size(); |
| format->set_screen_width(screen_size_.width()); |
| @@ -168,7 +127,7 @@ void VideoEncoderRowBased::PrepareUpdateStart(const SkIRect& rect, |
| } |
| } |
| -uint8* VideoEncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) { |
| +uint8* VideoEncoderVerbatim::GetOutputBuffer(VideoPacket* packet, size_t size) { |
| packet->mutable_data()->resize(size); |
| // TODO(ajwong): Is there a better way to do this at all??? |
| return const_cast<uint8*>(reinterpret_cast<const uint8*>( |