OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/decoder_vp8.h" | 5 #include "remoting/base/decoder_vp8.h" |
6 | 6 |
7 #include "media/base/media.h" | 7 #include "media/base/media.h" |
8 #include "media/base/yuv_convert.h" | 8 #include "media/base/yuv_convert.h" |
9 #include "remoting/base/util.h" | 9 #include "remoting/base/util.h" |
10 | 10 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 // Gets the decoded data. | 83 // Gets the decoded data. |
84 vpx_codec_iter_t iter = NULL; | 84 vpx_codec_iter_t iter = NULL; |
85 vpx_image_t* image = vpx_codec_get_frame(codec_, &iter); | 85 vpx_image_t* image = vpx_codec_get_frame(codec_, &iter); |
86 if (!image) { | 86 if (!image) { |
87 LOG(INFO) << "No video frame decoded"; | 87 LOG(INFO) << "No video frame decoded"; |
88 return DECODE_ERROR; | 88 return DECODE_ERROR; |
89 } | 89 } |
90 last_image_ = image; | 90 last_image_ = image; |
91 | 91 |
92 std::vector<gfx::Rect> rects; | 92 RectVector rects; |
| 93 rects.reserve(packet->dirty_rects_size()); |
93 for (int i = 0; i < packet->dirty_rects_size(); ++i) { | 94 for (int i = 0; i < packet->dirty_rects_size(); ++i) { |
94 gfx::Rect r = gfx::Rect(packet->dirty_rects(i).x(), | 95 Rect remoting_rect = packet->dirty_rects(i); |
95 packet->dirty_rects(i).y(), | 96 rects.push_back(SkIRect::MakeXYWH(remoting_rect.x(), |
96 packet->dirty_rects(i).width(), | 97 remoting_rect.y(), |
97 packet->dirty_rects(i).height()); | 98 remoting_rect.width(), |
98 rects.push_back(r); | 99 remoting_rect.height())); |
99 } | 100 } |
100 | 101 |
101 if (!DoScaling()) | 102 if (!DoScaling()) |
102 ConvertRects(rects, &updated_rects_); | 103 ConvertRects(rects, &updated_rects_); |
103 else | 104 else |
104 ScaleAndConvertRects(rects, &updated_rects_); | 105 ScaleAndConvertRects(rects, &updated_rects_); |
105 return DECODE_DONE; | 106 return DECODE_DONE; |
106 } | 107 } |
107 | 108 |
108 void DecoderVp8::GetUpdatedRects(UpdatedRects* rects) { | 109 void DecoderVp8::GetUpdatedRects(RectVector* rects) { |
109 rects->swap(updated_rects_); | 110 rects->swap(updated_rects_); |
110 } | 111 } |
111 | 112 |
112 void DecoderVp8::Reset() { | 113 void DecoderVp8::Reset() { |
113 frame_ = NULL; | 114 frame_ = NULL; |
114 state_ = kUninitialized; | 115 state_ = kUninitialized; |
115 } | 116 } |
116 | 117 |
117 bool DecoderVp8::IsReadyForData() { | 118 bool DecoderVp8::IsReadyForData() { |
118 return state_ == kReady; | 119 return state_ == kReady; |
(...skipping 10 matching lines...) Expand all Loading... |
129 // is not implemented yet. | 130 // is not implemented yet. |
130 if (horizontal_ratio > 1.0 || horizontal_ratio <= 0.0 || | 131 if (horizontal_ratio > 1.0 || horizontal_ratio <= 0.0 || |
131 vertical_ratio > 1.0 || vertical_ratio <= 0.0) { | 132 vertical_ratio > 1.0 || vertical_ratio <= 0.0) { |
132 return; | 133 return; |
133 } | 134 } |
134 | 135 |
135 horizontal_scale_ratio_ = horizontal_ratio; | 136 horizontal_scale_ratio_ = horizontal_ratio; |
136 vertical_scale_ratio_ = vertical_ratio; | 137 vertical_scale_ratio_ = vertical_ratio; |
137 } | 138 } |
138 | 139 |
139 void DecoderVp8::SetClipRect(const gfx::Rect& clip_rect) { | 140 void DecoderVp8::SetClipRect(const SkIRect& clip_rect) { |
140 clip_rect_ = clip_rect; | 141 clip_rect_ = clip_rect; |
141 } | 142 } |
142 | 143 |
143 void DecoderVp8::RefreshRects(const std::vector<gfx::Rect>& rects) { | 144 void DecoderVp8::RefreshRects(const RectVector& rects) { |
144 if (!DoScaling()) | 145 if (!DoScaling()) |
145 ConvertRects(rects, &updated_rects_); | 146 ConvertRects(rects, &updated_rects_); |
146 else | 147 else |
147 ScaleAndConvertRects(rects, &updated_rects_); | 148 ScaleAndConvertRects(rects, &updated_rects_); |
148 } | 149 } |
149 | 150 |
150 bool DecoderVp8::DoScaling() const { | 151 bool DecoderVp8::DoScaling() const { |
151 return horizontal_scale_ratio_ != 1.0 || vertical_scale_ratio_ != 1.0; | 152 return horizontal_scale_ratio_ != 1.0 || vertical_scale_ratio_ != 1.0; |
152 } | 153 } |
153 | 154 |
154 void DecoderVp8::ConvertRects(const UpdatedRects& rects, | 155 void DecoderVp8::ConvertRects(const RectVector& rects, |
155 UpdatedRects* output_rects) { | 156 RectVector* output_rects) { |
156 if (!last_image_) | 157 if (!last_image_) |
157 return; | 158 return; |
158 | 159 |
159 uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane); | 160 uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane); |
160 const int stride = frame_->stride(media::VideoFrame::kRGBPlane); | 161 const int stride = frame_->stride(media::VideoFrame::kRGBPlane); |
161 | 162 |
162 output_rects->clear(); | 163 output_rects->clear(); |
| 164 output_rects->reserve(rects.size()); |
163 for (size_t i = 0; i < rects.size(); ++i) { | 165 for (size_t i = 0; i < rects.size(); ++i) { |
| 166 // Clip by the clipping rectangle first. |
| 167 SkIRect dest_rect = rects[i]; |
| 168 if (!dest_rect.intersect(clip_rect_)) |
| 169 continue; |
| 170 |
164 // Round down the image width and height. | 171 // Round down the image width and height. |
165 int image_width = RoundToTwosMultiple(last_image_->d_w); | 172 int image_width = RoundToTwosMultiple(last_image_->d_w); |
166 int image_height = RoundToTwosMultiple(last_image_->d_h); | 173 int image_height = RoundToTwosMultiple(last_image_->d_h); |
167 | 174 |
168 // Clip by the clipping rectangle first. | |
169 gfx::Rect dest_rect = rects[i].Intersect(clip_rect_); | |
170 | |
171 // Then clip by the rounded down dimension of the image for safety. | 175 // Then clip by the rounded down dimension of the image for safety. |
172 dest_rect = dest_rect.Intersect( | 176 if (!dest_rect.intersect(SkIRect::MakeWH(image_width, image_height))) |
173 gfx::Rect(0, 0, image_width, image_height)); | 177 continue; |
174 | 178 |
175 // Align the rectangle to avoid artifacts in color space conversion. | 179 // Align the rectangle to avoid artifacts in color space conversion. |
176 dest_rect = AlignRect(dest_rect); | 180 dest_rect = AlignRect(dest_rect); |
177 | 181 |
178 if (dest_rect.IsEmpty()) | |
179 continue; | |
180 | |
181 ConvertYUVToRGB32WithRect(last_image_->planes[0], | 182 ConvertYUVToRGB32WithRect(last_image_->planes[0], |
182 last_image_->planes[1], | 183 last_image_->planes[1], |
183 last_image_->planes[2], | 184 last_image_->planes[2], |
184 data_start, | 185 data_start, |
185 dest_rect, | 186 dest_rect, |
186 last_image_->stride[0], | 187 last_image_->stride[0], |
187 last_image_->stride[1], | 188 last_image_->stride[1], |
188 stride); | 189 stride); |
189 output_rects->push_back(dest_rect); | 190 output_rects->push_back(dest_rect); |
190 } | 191 } |
191 } | 192 } |
192 | 193 |
193 void DecoderVp8::ScaleAndConvertRects(const UpdatedRects& rects, | 194 void DecoderVp8::ScaleAndConvertRects(const RectVector& rects, |
194 UpdatedRects* output_rects) { | 195 RectVector* output_rects) { |
195 if (!last_image_) | 196 if (!last_image_) |
196 return; | 197 return; |
197 | 198 |
198 uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane); | 199 uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane); |
199 const int stride = frame_->stride(media::VideoFrame::kRGBPlane); | 200 const int stride = frame_->stride(media::VideoFrame::kRGBPlane); |
200 | 201 |
201 output_rects->clear(); | 202 output_rects->clear(); |
| 203 output_rects->reserve(rects.size()); |
202 for (size_t i = 0; i < rects.size(); ++i) { | 204 for (size_t i = 0; i < rects.size(); ++i) { |
203 // Round down the image width and height. | 205 // Round down the image width and height. |
204 int image_width = RoundToTwosMultiple(last_image_->d_w); | 206 int image_width = RoundToTwosMultiple(last_image_->d_w); |
205 int image_height = RoundToTwosMultiple(last_image_->d_h); | 207 int image_height = RoundToTwosMultiple(last_image_->d_h); |
206 | 208 |
207 // Clip by the rounded down dimension of the image for safety. | 209 // Clip by the rounded down dimension of the image for safety. |
208 gfx::Rect dest_rect = | 210 SkIRect dest_rect = rects[i]; |
209 rects[i].Intersect(gfx::Rect(0, 0, image_width, image_height)); | 211 if (!dest_rect.intersect(SkIRect::MakeWH(image_width, image_height))) |
| 212 continue; |
210 | 213 |
211 // Align the rectangle to avoid artifacts in color space conversion. | 214 // Align the rectangle to avoid artifacts in color space conversion. |
212 dest_rect = AlignRect(dest_rect); | 215 dest_rect = AlignRect(dest_rect); |
213 | 216 |
214 if (dest_rect.IsEmpty()) | 217 SkIRect scaled_rect = ScaleRect(dest_rect, |
215 continue; | 218 horizontal_scale_ratio_, |
216 | 219 vertical_scale_ratio_); |
217 gfx::Rect scaled_rect = ScaleRect(dest_rect, | |
218 horizontal_scale_ratio_, | |
219 vertical_scale_ratio_); | |
220 | 220 |
221 ScaleYUVToRGB32WithRect(last_image_->planes[0], | 221 ScaleYUVToRGB32WithRect(last_image_->planes[0], |
222 last_image_->planes[1], | 222 last_image_->planes[1], |
223 last_image_->planes[2], | 223 last_image_->planes[2], |
224 data_start, | 224 data_start, |
225 dest_rect, | 225 dest_rect, |
226 scaled_rect, | 226 scaled_rect, |
227 last_image_->stride[0], | 227 last_image_->stride[0], |
228 last_image_->stride[1], | 228 last_image_->stride[1], |
229 stride); | 229 stride); |
230 output_rects->push_back(scaled_rect); | 230 output_rects->push_back(scaled_rect); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 } // namespace remoting | 234 } // namespace remoting |
OLD | NEW |