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/base/decoder_vp8.h" | 5 #include "remoting/base/decoder_vp8.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/base/media.h" | 10 #include "media/base/media.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 // Gets the decoded data. | 86 // Gets the decoded data. |
87 vpx_codec_iter_t iter = NULL; | 87 vpx_codec_iter_t iter = NULL; |
88 vpx_image_t* image = vpx_codec_get_frame(codec_, &iter); | 88 vpx_image_t* image = vpx_codec_get_frame(codec_, &iter); |
89 if (!image) { | 89 if (!image) { |
90 LOG(INFO) << "No video frame decoded"; | 90 LOG(INFO) << "No video frame decoded"; |
91 return DECODE_ERROR; | 91 return DECODE_ERROR; |
92 } | 92 } |
93 last_image_ = image; | 93 last_image_ = image; |
94 | 94 |
95 SkRegion region; | 95 RectVector rects; |
| 96 rects.reserve(packet->dirty_rects_size()); |
96 for (int i = 0; i < packet->dirty_rects_size(); ++i) { | 97 for (int i = 0; i < packet->dirty_rects_size(); ++i) { |
97 Rect remoting_rect = packet->dirty_rects(i); | 98 Rect remoting_rect = packet->dirty_rects(i); |
98 SkIRect rect = SkIRect::MakeXYWH(remoting_rect.x(), | 99 rects.push_back(SkIRect::MakeXYWH(remoting_rect.x(), |
99 remoting_rect.y(), | 100 remoting_rect.y(), |
100 remoting_rect.width(), | 101 remoting_rect.width(), |
101 remoting_rect.height()); | 102 remoting_rect.height())); |
102 region.op(rect, SkRegion::kUnion_Op); | |
103 } | 103 } |
104 | 104 |
105 RefreshRegion(region); | 105 RefreshRects(rects); |
106 return DECODE_DONE; | 106 return DECODE_DONE; |
107 } | 107 } |
108 | 108 |
109 void DecoderVp8::GetUpdatedRegion(SkRegion* region) { | 109 void DecoderVp8::GetUpdatedRects(RectVector* rects) { |
110 region->swap(updated_region_); | 110 rects->swap(updated_rects_); |
111 } | 111 } |
112 | 112 |
113 void DecoderVp8::Reset() { | 113 void DecoderVp8::Reset() { |
114 frame_ = NULL; | 114 frame_ = NULL; |
115 state_ = kUninitialized; | 115 state_ = kUninitialized; |
116 } | 116 } |
117 | 117 |
118 bool DecoderVp8::IsReadyForData() { | 118 bool DecoderVp8::IsReadyForData() { |
119 return state_ == kReady; | 119 return state_ == kReady; |
120 } | 120 } |
121 | 121 |
122 VideoPacketFormat::Encoding DecoderVp8::Encoding() { | 122 VideoPacketFormat::Encoding DecoderVp8::Encoding() { |
123 return VideoPacketFormat::ENCODING_VP8; | 123 return VideoPacketFormat::ENCODING_VP8; |
124 } | 124 } |
125 | 125 |
126 void DecoderVp8::SetOutputSize(const SkISize& size) { | 126 void DecoderVp8::SetOutputSize(const SkISize& size) { |
127 output_size_ = size; | 127 output_size_ = size; |
128 } | 128 } |
129 | 129 |
130 void DecoderVp8::SetClipRect(const SkIRect& clip_rect) { | 130 void DecoderVp8::SetClipRect(const SkIRect& clip_rect) { |
131 clip_rect_ = clip_rect; | 131 clip_rect_ = clip_rect; |
132 } | 132 } |
133 | 133 |
134 void DecoderVp8::RefreshRegion(const SkRegion& region) { | 134 void DecoderVp8::RefreshRects(const RectVector& rects) { |
135 // TODO(wez): Fix the rest of the decode pipeline not to assume the frame | 135 // TODO(wez): Fix the rest of the decode pipeline not to assume the frame |
136 // size is the host dimensions, since it's not when scaling. If the host | 136 // size is the host dimensions, since it's not when scaling. If the host |
137 // gets smaller, then the output size will be too big and we'll overrun the | 137 // gets smaller, then the output size will be too big and we'll overrun the |
138 // frame, so currently we render 1:1 in that case; the app will see the | 138 // frame, so currently we render 1:1 in that case; the app will see the |
139 // host size change and resize us if need be. | 139 // host size change and resize us if need be. |
140 if (output_size_.width() > static_cast<int>(frame_->width())) | 140 if (output_size_.width() > static_cast<int>(frame_->width())) |
141 output_size_.set(frame_->width(), output_size_.height()); | 141 output_size_.set(frame_->width(), output_size_.height()); |
142 if (output_size_.height() > static_cast<int>(frame_->height())) | 142 if (output_size_.height() > static_cast<int>(frame_->height())) |
143 output_size_.set(output_size_.width(), frame_->height()); | 143 output_size_.set(output_size_.width(), frame_->height()); |
144 | 144 |
145 if (!DoScaling()) { | 145 if (!DoScaling()) |
146 ConvertRegion(region, &updated_region_); | 146 ConvertRects(rects, &updated_rects_); |
147 } else { | 147 else |
148 ScaleAndConvertRegion(region, &updated_region_); | 148 ScaleAndConvertRects(rects, &updated_rects_); |
149 } | |
150 } | 149 } |
151 | 150 |
152 bool DecoderVp8::DoScaling() const { | 151 bool DecoderVp8::DoScaling() const { |
153 DCHECK(last_image_); | 152 DCHECK(last_image_); |
154 return !output_size_.equals(last_image_->d_w, last_image_->d_h); | 153 return !output_size_.equals(last_image_->d_w, last_image_->d_h); |
155 } | 154 } |
156 | 155 |
157 void DecoderVp8::ConvertRegion(const SkRegion& input_region, | 156 void DecoderVp8::ConvertRects(const RectVector& input_rects, |
158 SkRegion* output_region) { | 157 RectVector* output_rects) { |
159 if (!last_image_) | 158 if (!last_image_) |
160 return; | 159 return; |
161 | 160 |
162 output_region->setEmpty(); | 161 output_rects->clear(); |
163 | 162 |
164 // Clip based on both the output dimensions and Pepper clip rect. | 163 // Clip based on both the output dimensions and Pepper clip rect. |
165 // ConvertYUVToRGB32WithRect() requires even X and Y coordinates, so we align | 164 // ConvertYUVToRGB32WithRect() requires even X and Y coordinates, so we align |
166 // |clip_rect| to prevent clipping from breaking alignment. We then clamp it | 165 // |clip_rect| to prevent clipping from breaking alignment. We then clamp it |
167 // to the image dimensions, which may lead to odd width & height, which we | 166 // to the image dimensions, which may lead to odd width & height, which we |
168 // can cope with. | 167 // can cope with. |
169 SkIRect clip_rect = AlignRect(clip_rect_); | 168 SkIRect clip_rect = AlignRect(clip_rect_); |
170 if (!clip_rect.intersect(SkIRect::MakeWH(last_image_->d_w, last_image_->d_h))) | 169 if (!clip_rect.intersect(SkIRect::MakeWH(last_image_->d_w, last_image_->d_h))) |
171 return; | 170 return; |
172 | 171 |
173 uint8* output_rgb_buf = frame_->data(media::VideoFrame::kRGBPlane); | 172 uint8* output_rgb_buf = frame_->data(media::VideoFrame::kRGBPlane); |
174 const int output_stride = frame_->stride(media::VideoFrame::kRGBPlane); | 173 const int output_stride = frame_->stride(media::VideoFrame::kRGBPlane); |
| 174 output_rects->reserve(input_rects.size()); |
175 | 175 |
176 for (SkRegion::Iterator i(input_region); !i.done(); i.next()) { | 176 for (size_t i = 0; i < input_rects.size(); ++i) { |
177 // Align the rectangle so the top-left coordinates are even, for | 177 // Align the rectangle so the top-left coordinates are even, for |
178 // ConvertYUVToRGB32WithRect(). | 178 // ConvertYUVToRGB32WithRect(). |
179 SkIRect dest_rect(AlignRect(i.rect())); | 179 SkIRect dest_rect(AlignRect(input_rects[i])); |
180 | 180 |
181 // Clip the rectangle, preserving alignment since |clip_rect| is aligned. | 181 // Clip the rectangle, preserving alignment since |clip_rect| is aligned. |
182 if (!dest_rect.intersect(clip_rect)) | 182 if (!dest_rect.intersect(clip_rect)) |
183 continue; | 183 continue; |
184 | 184 |
185 ConvertYUVToRGB32WithRect(last_image_->planes[0], | 185 ConvertYUVToRGB32WithRect(last_image_->planes[0], |
186 last_image_->planes[1], | 186 last_image_->planes[1], |
187 last_image_->planes[2], | 187 last_image_->planes[2], |
188 output_rgb_buf, | 188 output_rgb_buf, |
189 dest_rect, | 189 dest_rect, |
190 last_image_->stride[0], | 190 last_image_->stride[0], |
191 last_image_->stride[1], | 191 last_image_->stride[1], |
192 output_stride); | 192 output_stride); |
193 | 193 |
194 output_region->op(dest_rect, SkRegion::kUnion_Op); | 194 output_rects->push_back(dest_rect); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 void DecoderVp8::ScaleAndConvertRegion(const SkRegion& input_region, | 198 void DecoderVp8::ScaleAndConvertRects(const RectVector& input_rects, |
199 SkRegion* output_region) { | 199 RectVector* output_rects) { |
200 if (!last_image_) | 200 if (!last_image_) |
201 return; | 201 return; |
202 | 202 |
203 DCHECK(output_size_.width() <= static_cast<int>(frame_->width())); | 203 DCHECK(output_size_.width() <= static_cast<int>(frame_->width())); |
204 DCHECK(output_size_.height() <= static_cast<int>(frame_->height())); | 204 DCHECK(output_size_.height() <= static_cast<int>(frame_->height())); |
205 | 205 |
206 output_region->setEmpty(); | 206 output_rects->clear(); |
207 | 207 |
208 // Clip based on both the output dimensions and Pepper clip rect. | 208 // Clip based on both the output dimensions and Pepper clip rect. |
209 SkIRect clip_rect = clip_rect_; | 209 SkIRect clip_rect = clip_rect_; |
210 if (!clip_rect.intersect(SkIRect::MakeSize(output_size_))) | 210 if (!clip_rect.intersect(SkIRect::MakeSize(output_size_))) |
211 return; | 211 return; |
212 | 212 |
213 SkISize image_size = SkISize::Make(last_image_->d_w, last_image_->d_h); | 213 SkISize image_size = SkISize::Make(last_image_->d_w, last_image_->d_h); |
214 uint8* output_rgb_buf = frame_->data(media::VideoFrame::kRGBPlane); | 214 uint8* output_rgb_buf = frame_->data(media::VideoFrame::kRGBPlane); |
215 const int output_stride = frame_->stride(media::VideoFrame::kRGBPlane); | 215 const int output_stride = frame_->stride(media::VideoFrame::kRGBPlane); |
216 | 216 |
217 for (SkRegion::Iterator i(input_region); !i.done(); i.next()) { | 217 output_rects->reserve(input_rects.size()); |
| 218 |
| 219 for (size_t i = 0; i < input_rects.size(); ++i) { |
218 // Determine the scaled area affected by this rectangle changing. | 220 // Determine the scaled area affected by this rectangle changing. |
219 SkIRect output_rect = ScaleRect(i.rect(), image_size, output_size_); | 221 SkIRect output_rect = ScaleRect(input_rects[i], image_size, output_size_); |
220 if (!output_rect.intersect(clip_rect)) | 222 if (!output_rect.intersect(clip_rect)) |
221 continue; | 223 continue; |
222 | 224 |
223 // The scaler will not to read outside the input dimensions. | 225 // The scaler will not to read outside the input dimensions. |
224 media::ScaleYUVToRGB32WithRect(last_image_->planes[0], | 226 media::ScaleYUVToRGB32WithRect(last_image_->planes[0], |
225 last_image_->planes[1], | 227 last_image_->planes[1], |
226 last_image_->planes[2], | 228 last_image_->planes[2], |
227 output_rgb_buf, | 229 output_rgb_buf, |
228 image_size.width(), | 230 image_size.width(), |
229 image_size.height(), | 231 image_size.height(), |
230 output_size_.width(), | 232 output_size_.width(), |
231 output_size_.height(), | 233 output_size_.height(), |
232 output_rect.x(), | 234 output_rect.x(), |
233 output_rect.y(), | 235 output_rect.y(), |
234 output_rect.right(), | 236 output_rect.right(), |
235 output_rect.bottom(), | 237 output_rect.bottom(), |
236 last_image_->stride[0], | 238 last_image_->stride[0], |
237 last_image_->stride[1], | 239 last_image_->stride[1], |
238 output_stride); | 240 output_stride); |
239 | 241 output_rects->push_back(output_rect); |
240 output_region->op(output_rect, SkRegion::kUnion_Op); | |
241 } | 242 } |
242 } | 243 } |
243 | 244 |
244 } // namespace remoting | 245 } // namespace remoting |
OLD | NEW |