OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/client/plugin/pepper_video_renderer_3d.h" | 5 #include "remoting/client/plugin/pepper_video_renderer_3d.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
| 9 #include <utility> |
| 10 |
9 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
11 #include "ppapi/c/pp_codecs.h" | 13 #include "ppapi/c/pp_codecs.h" |
12 #include "ppapi/c/ppb_opengles2.h" | 14 #include "ppapi/c/ppb_opengles2.h" |
13 #include "ppapi/c/ppb_video_decoder.h" | 15 #include "ppapi/c/ppb_video_decoder.h" |
14 #include "ppapi/cpp/instance.h" | 16 #include "ppapi/cpp/instance.h" |
15 #include "ppapi/lib/gl/include/GLES2/gl2.h" | 17 #include "ppapi/lib/gl/include/GLES2/gl2.h" |
16 #include "ppapi/lib/gl/include/GLES2/gl2ext.h" | 18 #include "ppapi/lib/gl/include/GLES2/gl2ext.h" |
17 #include "remoting/proto/video.pb.h" | 19 #include "remoting/proto/video.pb.h" |
18 #include "remoting/protocol/performance_tracker.h" | 20 #include "remoting/protocol/performance_tracker.h" |
19 #include "remoting/protocol/session_config.h" | 21 #include "remoting/protocol/session_config.h" |
20 | 22 |
21 namespace remoting { | 23 namespace remoting { |
22 | 24 |
23 // The implementation here requires that the decoder allocates at least 3 | 25 // The implementation here requires that the decoder allocates at least 3 |
24 // pictures. PPB_VideoDecoder didn't support this parameter prior to | 26 // pictures. PPB_VideoDecoder didn't support this parameter prior to |
25 // 1.1, so we have to pass 0 for backwards compatibility with older versions of | 27 // 1.1, so we have to pass 0 for backwards compatibility with older versions of |
26 // the browser. Currently all API implementations allocate more than 3 buffers | 28 // the browser. Currently all API implementations allocate more than 3 buffers |
27 // by default. | 29 // by default. |
28 // | 30 // |
29 // TODO(sergeyu): Change this to 3 once PPB_VideoDecoder v1.1 is enabled on | 31 // TODO(sergeyu): Change this to 3 once PPB_VideoDecoder v1.1 is enabled on |
30 // stable channel (crbug.com/520323). | 32 // stable channel (crbug.com/520323). |
31 const uint32_t kMinimumPictureCount = 0; // 3 | 33 const uint32_t kMinimumPictureCount = 0; // 3 |
32 | 34 |
33 class PepperVideoRenderer3D::PendingPacket { | 35 class PepperVideoRenderer3D::PendingPacket { |
34 public: | 36 public: |
35 PendingPacket(scoped_ptr<VideoPacket> packet, const base::Closure& done) | 37 PendingPacket(scoped_ptr<VideoPacket> packet, const base::Closure& done) |
36 : packet_(packet.Pass()), | 38 : packet_(std::move(packet)), done_runner_(done) {} |
37 done_runner_(done) { | |
38 } | |
39 | 39 |
40 ~PendingPacket() {} | 40 ~PendingPacket() {} |
41 | 41 |
42 const VideoPacket* packet() const { return packet_.get(); } | 42 const VideoPacket* packet() const { return packet_.get(); } |
43 | 43 |
44 private: | 44 private: |
45 scoped_ptr<VideoPacket> packet_; | 45 scoped_ptr<VideoPacket> packet_; |
46 base::ScopedClosureRunner done_runner_; | 46 base::ScopedClosureRunner done_runner_; |
47 }; | 47 }; |
48 | 48 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if (packet->has_use_desktop_shape()) { | 217 if (packet->has_use_desktop_shape()) { |
218 if (packet->use_desktop_shape()) { | 218 if (packet->use_desktop_shape()) { |
219 scoped_ptr<webrtc::DesktopRegion> shape(new webrtc::DesktopRegion); | 219 scoped_ptr<webrtc::DesktopRegion> shape(new webrtc::DesktopRegion); |
220 for (int i = 0; i < packet->desktop_shape_rects_size(); ++i) { | 220 for (int i = 0; i < packet->desktop_shape_rects_size(); ++i) { |
221 Rect remoting_rect = packet->desktop_shape_rects(i); | 221 Rect remoting_rect = packet->desktop_shape_rects(i); |
222 shape->AddRect(webrtc::DesktopRect::MakeXYWH( | 222 shape->AddRect(webrtc::DesktopRect::MakeXYWH( |
223 remoting_rect.x(), remoting_rect.y(), remoting_rect.width(), | 223 remoting_rect.x(), remoting_rect.y(), remoting_rect.width(), |
224 remoting_rect.height())); | 224 remoting_rect.height())); |
225 } | 225 } |
226 if (!frame_shape_ || !frame_shape_->Equals(*shape)) { | 226 if (!frame_shape_ || !frame_shape_->Equals(*shape)) { |
227 frame_shape_ = shape.Pass(); | 227 frame_shape_ = std::move(shape); |
228 event_handler_->OnVideoShape(frame_shape_.get()); | 228 event_handler_->OnVideoShape(frame_shape_.get()); |
229 } | 229 } |
230 } else if (frame_shape_) { | 230 } else if (frame_shape_) { |
231 frame_shape_ = nullptr; | 231 frame_shape_ = nullptr; |
232 event_handler_->OnVideoShape(nullptr); | 232 event_handler_->OnVideoShape(nullptr); |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 // Report the dirty region, for debugging, if requested. | 236 // Report the dirty region, for debugging, if requested. |
237 if (debug_dirty_region_) { | 237 if (debug_dirty_region_) { |
238 webrtc::DesktopRegion dirty_region; | 238 webrtc::DesktopRegion dirty_region; |
239 for (int i = 0; i < packet->dirty_rects_size(); ++i) { | 239 for (int i = 0; i < packet->dirty_rects_size(); ++i) { |
240 Rect remoting_rect = packet->dirty_rects(i); | 240 Rect remoting_rect = packet->dirty_rects(i); |
241 dirty_region.AddRect(webrtc::DesktopRect::MakeXYWH( | 241 dirty_region.AddRect(webrtc::DesktopRect::MakeXYWH( |
242 remoting_rect.x(), remoting_rect.y(), | 242 remoting_rect.x(), remoting_rect.y(), |
243 remoting_rect.width(), remoting_rect.height())); | 243 remoting_rect.width(), remoting_rect.height())); |
244 } | 244 } |
245 event_handler_->OnVideoFrameDirtyRegion(dirty_region); | 245 event_handler_->OnVideoFrameDirtyRegion(dirty_region); |
246 } | 246 } |
247 | 247 |
248 pending_packets_.push_back( | 248 pending_packets_.push_back( |
249 new PendingPacket(packet.Pass(), done_runner.Release())); | 249 new PendingPacket(std::move(packet), done_runner.Release())); |
250 DecodeNextPacket(); | 250 DecodeNextPacket(); |
251 } | 251 } |
252 | 252 |
253 void PepperVideoRenderer3D::OnInitialized(int32_t result) { | 253 void PepperVideoRenderer3D::OnInitialized(int32_t result) { |
254 // Assume that VP8 and VP9 codecs are always supported by the browser. | 254 // Assume that VP8 and VP9 codecs are always supported by the browser. |
255 CHECK_EQ(result, PP_OK) << "VideoDecoder::Initialize() failed: " << result; | 255 CHECK_EQ(result, PP_OK) << "VideoDecoder::Initialize() failed: " << result; |
256 initialization_finished_ = true; | 256 initialization_finished_ = true; |
257 | 257 |
258 // Start decoding in case a frame was received during decoder initialization. | 258 // Start decoding in case a frame was received during decoder initialization. |
259 DecodeNextPacket(); | 259 DecodeNextPacket(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 PaintIfNeeded(); | 333 PaintIfNeeded(); |
334 GetNextPicture(); | 334 GetNextPicture(); |
335 } | 335 } |
336 | 336 |
337 void PepperVideoRenderer3D::PaintIfNeeded() { | 337 void PepperVideoRenderer3D::PaintIfNeeded() { |
338 bool need_repaint = next_picture_ || (force_repaint_ && current_picture_); | 338 bool need_repaint = next_picture_ || (force_repaint_ && current_picture_); |
339 if (paint_pending_ || !need_repaint) | 339 if (paint_pending_ || !need_repaint) |
340 return; | 340 return; |
341 | 341 |
342 if (next_picture_) | 342 if (next_picture_) |
343 current_picture_ = next_picture_.Pass(); | 343 current_picture_ = std::move(next_picture_); |
344 | 344 |
345 force_repaint_ = false; | 345 force_repaint_ = false; |
346 | 346 |
347 const PP_VideoPicture& picture = current_picture_->picture(); | 347 const PP_VideoPicture& picture = current_picture_->picture(); |
348 PP_Resource graphics_3d = graphics_.pp_resource(); | 348 PP_Resource graphics_3d = graphics_.pp_resource(); |
349 | 349 |
350 EnsureProgramForTexture(picture.texture_target); | 350 EnsureProgramForTexture(picture.texture_target); |
351 | 351 |
352 gles2_if_->UseProgram(graphics_3d, shader_program_); | 352 gles2_if_->UseProgram(graphics_3d, shader_program_); |
353 | 353 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader); | 517 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader); |
518 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); | 518 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); |
519 } | 519 } |
520 | 520 |
521 void PepperVideoRenderer3D::CheckGLError() { | 521 void PepperVideoRenderer3D::CheckGLError() { |
522 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); | 522 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); |
523 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; | 523 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; |
524 } | 524 } |
525 | 525 |
526 } // namespace remoting | 526 } // namespace remoting |
OLD | NEW |