OLD | NEW |
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_zlib.h" | 5 #include "remoting/base/encoder_zlib.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" | |
10 #include "remoting/base/capture_data.h" | 9 #include "remoting/base/capture_data.h" |
11 #include "remoting/base/compressor_zlib.h" | 10 #include "remoting/base/compressor_zlib.h" |
12 #include "remoting/base/util.h" | 11 #include "remoting/base/util.h" |
| 12 #include "remoting/proto/video.pb.h" |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 | 15 |
16 static const int kPacketSize = 1024 * 1024; | 16 static const int kPacketSize = 1024 * 1024; |
17 | 17 |
18 EncoderZlib::EncoderZlib() : packet_size_(kPacketSize) { | 18 EncoderZlib::EncoderZlib() : packet_size_(kPacketSize) { |
19 } | 19 } |
20 | 20 |
21 EncoderZlib::EncoderZlib(int packet_size) : packet_size_(packet_size) { | 21 EncoderZlib::EncoderZlib(int packet_size) : packet_size_(packet_size) { |
22 } | 22 } |
23 | 23 |
24 EncoderZlib::~EncoderZlib() {} | 24 EncoderZlib::~EncoderZlib() {} |
25 | 25 |
26 void EncoderZlib::Encode(scoped_refptr<CaptureData> capture_data, | 26 void EncoderZlib::Encode(scoped_refptr<CaptureData> capture_data, |
27 bool key_frame, | 27 bool key_frame, |
28 DataAvailableCallback* data_available_callback) { | 28 DataAvailableCallback* data_available_callback) { |
29 CHECK(capture_data->pixel_format() == PIXEL_FORMAT_RGB32) | 29 CHECK(capture_data->pixel_format() == media::VideoFrame::RGB32) |
30 << "Zlib Encoder only works with RGB32. Got " | 30 << "Zlib Encoder only works with RGB32. Got " |
31 << capture_data->pixel_format(); | 31 << capture_data->pixel_format(); |
32 capture_data_ = capture_data; | 32 capture_data_ = capture_data; |
33 callback_.reset(data_available_callback); | 33 callback_.reset(data_available_callback); |
34 | 34 |
35 CompressorZlib compressor; | 35 CompressorZlib compressor; |
36 const InvalidRects& rects = capture_data->dirty_rects(); | 36 const InvalidRects& rects = capture_data->dirty_rects(); |
37 int index = 0; | 37 int index = 0; |
38 for (InvalidRects::const_iterator r = rects.begin(); | 38 for (InvalidRects::const_iterator r = rects.begin(); |
39 r != rects.end(); ++r, ++index) { | 39 r != rects.end(); ++r, ++index) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 void EncoderZlib::PrepareUpdateStart(const gfx::Rect& rect, | 111 void EncoderZlib::PrepareUpdateStart(const gfx::Rect& rect, |
112 VideoPacket* packet) { | 112 VideoPacket* packet) { |
113 packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET); | 113 packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET); |
114 VideoPacketFormat* format = packet->mutable_format(); | 114 VideoPacketFormat* format = packet->mutable_format(); |
115 | 115 |
116 format->set_x(rect.x()); | 116 format->set_x(rect.x()); |
117 format->set_y(rect.y()); | 117 format->set_y(rect.y()); |
118 format->set_width(rect.width()); | 118 format->set_width(rect.width()); |
119 format->set_height(rect.height()); | 119 format->set_height(rect.height()); |
120 format->set_encoding(VideoPacketFormat::ENCODING_ZLIB); | 120 format->set_encoding(VideoPacketFormat::ENCODING_ZLIB); |
121 format->set_pixel_format(capture_data_->pixel_format()); | |
122 } | 121 } |
123 | 122 |
124 uint8* EncoderZlib::GetOutputBuffer(VideoPacket* packet, size_t size) { | 123 uint8* EncoderZlib::GetOutputBuffer(VideoPacket* packet, size_t size) { |
125 packet->mutable_data()->resize(size); | 124 packet->mutable_data()->resize(size); |
126 // TODO(ajwong): Is there a better way to do this at all??? | 125 // TODO(ajwong): Is there a better way to do this at all??? |
127 return const_cast<uint8*>(reinterpret_cast<const uint8*>( | 126 return const_cast<uint8*>(reinterpret_cast<const uint8*>( |
128 packet->mutable_data()->data())); | 127 packet->mutable_data()->data())); |
129 } | 128 } |
130 | 129 |
131 void EncoderZlib::SubmitMessage(VideoPacket* packet, size_t rect_index) { | 130 void EncoderZlib::SubmitMessage(VideoPacket* packet, size_t rect_index) { |
132 callback_->Run(packet); | 131 callback_->Run(packet); |
133 } | 132 } |
134 | 133 |
135 } // namespace remoting | 134 } // namespace remoting |
OLD | NEW |