OLD | NEW |
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_encoder_row_based.h" | 5 #include "remoting/codec/video_encoder_row_based.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "remoting/base/capture_data.h" | 8 #include "remoting/base/capture_data.h" |
9 #include "remoting/base/compressor_verbatim.h" | 9 #include "remoting/base/compressor_verbatim.h" |
10 #include "remoting/base/compressor_zlib.h" | 10 #include "remoting/base/compressor_zlib.h" |
11 #include "remoting/base/util.h" | 11 #include "remoting/base/util.h" |
12 #include "remoting/proto/video.pb.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 EncoderRowBased* EncoderRowBased::CreateZlibEncoder() { | 18 VideoEncoderRowBased* VideoEncoderRowBased::CreateZlibEncoder() { |
19 return new EncoderRowBased(new CompressorZlib(), | 19 return new VideoEncoderRowBased(new CompressorZlib(), |
20 VideoPacketFormat::ENCODING_ZLIB); | 20 VideoPacketFormat::ENCODING_ZLIB); |
21 } | 21 } |
22 | 22 |
23 EncoderRowBased* EncoderRowBased::CreateZlibEncoder(int packet_size) { | 23 VideoEncoderRowBased* VideoEncoderRowBased::CreateZlibEncoder(int packet_size) { |
24 return new EncoderRowBased(new CompressorZlib(), | 24 return new VideoEncoderRowBased(new CompressorZlib(), |
25 VideoPacketFormat::ENCODING_ZLIB, | 25 VideoPacketFormat::ENCODING_ZLIB, |
26 packet_size); | 26 packet_size); |
27 } | 27 } |
28 | 28 |
29 EncoderRowBased* EncoderRowBased::CreateVerbatimEncoder() { | 29 VideoEncoderRowBased* VideoEncoderRowBased::CreateVerbatimEncoder() { |
30 return new EncoderRowBased(new CompressorVerbatim(), | 30 return new VideoEncoderRowBased(new CompressorVerbatim(), |
31 VideoPacketFormat::ENCODING_VERBATIM); | 31 VideoPacketFormat::ENCODING_VERBATIM); |
32 } | 32 } |
33 | 33 |
34 EncoderRowBased* EncoderRowBased::CreateVerbatimEncoder(int packet_size) { | 34 VideoEncoderRowBased* VideoEncoderRowBased::CreateVerbatimEncoder( |
35 return new EncoderRowBased(new CompressorVerbatim(), | 35 int packet_size) { |
36 VideoPacketFormat::ENCODING_VERBATIM, | 36 return new VideoEncoderRowBased(new CompressorVerbatim(), |
37 packet_size); | 37 VideoPacketFormat::ENCODING_VERBATIM, |
| 38 packet_size); |
38 } | 39 } |
39 | 40 |
40 EncoderRowBased::EncoderRowBased(Compressor* compressor, | 41 VideoEncoderRowBased::VideoEncoderRowBased(Compressor* compressor, |
41 VideoPacketFormat::Encoding encoding) | 42 VideoPacketFormat::Encoding encoding) |
42 : encoding_(encoding), | 43 : encoding_(encoding), |
43 compressor_(compressor), | 44 compressor_(compressor), |
44 screen_size_(SkISize::Make(0,0)), | 45 screen_size_(SkISize::Make(0,0)), |
45 packet_size_(kPacketSize) { | 46 packet_size_(kPacketSize) { |
46 } | 47 } |
47 | 48 |
48 EncoderRowBased::EncoderRowBased(Compressor* compressor, | 49 VideoEncoderRowBased::VideoEncoderRowBased(Compressor* compressor, |
49 VideoPacketFormat::Encoding encoding, | 50 VideoPacketFormat::Encoding encoding, |
50 int packet_size) | 51 int packet_size) |
51 : encoding_(encoding), | 52 : encoding_(encoding), |
52 compressor_(compressor), | 53 compressor_(compressor), |
53 screen_size_(SkISize::Make(0,0)), | 54 screen_size_(SkISize::Make(0,0)), |
54 packet_size_(packet_size) { | 55 packet_size_(packet_size) { |
55 } | 56 } |
56 | 57 |
57 EncoderRowBased::~EncoderRowBased() {} | 58 VideoEncoderRowBased::~VideoEncoderRowBased() {} |
58 | 59 |
59 void EncoderRowBased::Encode( | 60 void VideoEncoderRowBased::Encode( |
60 scoped_refptr<CaptureData> capture_data, | 61 scoped_refptr<CaptureData> capture_data, |
61 bool key_frame, | 62 bool key_frame, |
62 const DataAvailableCallback& data_available_callback) { | 63 const DataAvailableCallback& data_available_callback) { |
63 CHECK(capture_data->pixel_format() == media::VideoFrame::RGB32) | 64 CHECK(capture_data->pixel_format() == media::VideoFrame::RGB32) |
64 << "RowBased Encoder only works with RGB32. Got " | 65 << "RowBased VideoEncoder only works with RGB32. Got " |
65 << capture_data->pixel_format(); | 66 << capture_data->pixel_format(); |
66 capture_data_ = capture_data; | 67 capture_data_ = capture_data; |
67 callback_ = data_available_callback; | 68 callback_ = data_available_callback; |
68 | 69 |
69 const SkRegion& region = capture_data->dirty_region(); | 70 const SkRegion& region = capture_data->dirty_region(); |
70 SkRegion::Iterator iter(region); | 71 SkRegion::Iterator iter(region); |
71 while (!iter.done()) { | 72 while (!iter.done()) { |
72 SkIRect rect = iter.rect(); | 73 SkIRect rect = iter.rect(); |
73 iter.next(); | 74 iter.next(); |
74 EncodeRect(rect, iter.done()); | 75 EncodeRect(rect, iter.done()); |
75 } | 76 } |
76 | 77 |
77 capture_data_ = NULL; | 78 capture_data_ = NULL; |
78 callback_.Reset(); | 79 callback_.Reset(); |
79 } | 80 } |
80 | 81 |
81 void EncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { | 82 void VideoEncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { |
82 CHECK(capture_data_->data_planes().data[0]); | 83 CHECK(capture_data_->data_planes().data[0]); |
83 CHECK_EQ(capture_data_->pixel_format(), media::VideoFrame::RGB32); | 84 CHECK_EQ(capture_data_->pixel_format(), media::VideoFrame::RGB32); |
84 const int strides = capture_data_->data_planes().strides[0]; | 85 const int strides = capture_data_->data_planes().strides[0]; |
85 const int bytes_per_pixel = 4; | 86 const int bytes_per_pixel = 4; |
86 const int row_size = bytes_per_pixel * rect.width(); | 87 const int row_size = bytes_per_pixel * rect.width(); |
87 | 88 |
88 compressor_->Reset(); | 89 compressor_->Reset(); |
89 | 90 |
90 scoped_ptr<VideoPacket> packet(new VideoPacket()); | 91 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
91 PrepareUpdateStart(rect, packet.get()); | 92 PrepareUpdateStart(rect, packet.get()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 144 |
144 // Reached the end of input row and we're not at the last row. | 145 // Reached the end of input row and we're not at the last row. |
145 if (row_pos == row_size && row_y < rect.height() - 1) { | 146 if (row_pos == row_size && row_y < rect.height() - 1) { |
146 row_pos = 0; | 147 row_pos = 0; |
147 in += strides; | 148 in += strides; |
148 ++row_y; | 149 ++row_y; |
149 } | 150 } |
150 } | 151 } |
151 } | 152 } |
152 | 153 |
153 void EncoderRowBased::PrepareUpdateStart(const SkIRect& rect, | 154 void VideoEncoderRowBased::PrepareUpdateStart(const SkIRect& rect, |
154 VideoPacket* packet) { | 155 VideoPacket* packet) { |
155 packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET); | 156 packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET); |
156 | 157 |
157 VideoPacketFormat* format = packet->mutable_format(); | 158 VideoPacketFormat* format = packet->mutable_format(); |
158 format->set_x(rect.fLeft); | 159 format->set_x(rect.fLeft); |
159 format->set_y(rect.fTop); | 160 format->set_y(rect.fTop); |
160 format->set_width(rect.width()); | 161 format->set_width(rect.width()); |
161 format->set_height(rect.height()); | 162 format->set_height(rect.height()); |
162 format->set_encoding(encoding_); | 163 format->set_encoding(encoding_); |
163 if (capture_data_->size() != screen_size_) { | 164 if (capture_data_->size() != screen_size_) { |
164 screen_size_ = capture_data_->size(); | 165 screen_size_ = capture_data_->size(); |
165 format->set_screen_width(screen_size_.width()); | 166 format->set_screen_width(screen_size_.width()); |
166 format->set_screen_height(screen_size_.height()); | 167 format->set_screen_height(screen_size_.height()); |
167 } | 168 } |
168 } | 169 } |
169 | 170 |
170 uint8* EncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) { | 171 uint8* VideoEncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) { |
171 packet->mutable_data()->resize(size); | 172 packet->mutable_data()->resize(size); |
172 // TODO(ajwong): Is there a better way to do this at all??? | 173 // TODO(ajwong): Is there a better way to do this at all??? |
173 return const_cast<uint8*>(reinterpret_cast<const uint8*>( | 174 return const_cast<uint8*>(reinterpret_cast<const uint8*>( |
174 packet->mutable_data()->data())); | 175 packet->mutable_data()->data())); |
175 } | 176 } |
176 | 177 |
177 } // namespace remoting | 178 } // namespace remoting |
OLD | NEW |