Chromium Code Reviews| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "ppapi/c/pp_codecs.h" | 12 #include "ppapi/c/pp_codecs.h" |
| 13 #include "ppapi/c/ppb_opengles2.h" | 13 #include "ppapi/c/ppb_opengles2.h" |
| 14 #include "ppapi/c/ppb_video_decoder.h" | 14 #include "ppapi/c/ppb_video_decoder.h" |
| 15 #include "ppapi/cpp/instance.h" | 15 #include "ppapi/cpp/instance.h" |
| 16 #include "ppapi/lib/gl/include/GLES2/gl2.h" | 16 #include "ppapi/lib/gl/include/GLES2/gl2.h" |
| 17 #include "ppapi/lib/gl/include/GLES2/gl2ext.h" | 17 #include "ppapi/lib/gl/include/GLES2/gl2ext.h" |
| 18 #include "remoting/proto/video.pb.h" | 18 #include "remoting/proto/video.pb.h" |
| 19 #include "remoting/protocol/frame_stats.h" | 19 #include "remoting/protocol/frame_stats.h" |
| 20 #include "remoting/protocol/performance_tracker.h" | 20 #include "remoting/protocol/performance_tracker.h" |
| 21 #include "remoting/protocol/session_config.h" | 21 #include "remoting/protocol/session_config.h" |
| 22 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" | 22 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
| 23 | 23 |
| 24 namespace remoting { | 24 namespace remoting { |
| 25 | 25 |
| 26 namespace { | |
| 26 // The implementation here requires that the decoder allocates at least 3 | 27 // The implementation here requires that the decoder allocates at least 3 |
| 27 // pictures. PPB_VideoDecoder didn't support this parameter prior to | 28 // pictures. PPB_VideoDecoder didn't support this parameter prior to |
| 28 // 1.1, so we have to pass 0 for backwards compatibility with older versions of | 29 // 1.1, so we have to pass 0 for backwards compatibility with older versions of |
| 29 // the browser. Currently all API implementations allocate more than 3 buffers | 30 // the browser. Currently all API implementations allocate more than 3 buffers |
| 30 // by default. | 31 // by default. |
| 31 const uint32_t kMinimumPictureCount = 3; | 32 const uint32_t kMinimumPictureCount = 3; |
| 33 } // namespace | |
|
joedow
2017/02/14 00:24:47
This felt like it should be in an anonymous namesp
| |
| 32 | 34 |
| 33 class PepperVideoRenderer3D::FrameTracker { | 35 class PepperVideoRenderer3D::FrameTracker { |
| 34 public: | 36 public: |
| 35 FrameTracker(std::unique_ptr<VideoPacket> packet, | 37 FrameTracker(std::unique_ptr<VideoPacket> packet, |
| 36 protocol::FrameStatsConsumer* stats_consumer, | 38 protocol::FrameStatsConsumer* stats_consumer, |
| 37 const base::Closure& done) | 39 const base::Closure& done) |
| 38 : packet_(std::move(packet)), | 40 : packet_(std::move(packet)), |
| 39 stats_consumer_(stats_consumer), | 41 stats_consumer_(stats_consumer), |
| 40 done_(done) { | 42 done_(done) { |
| 41 stats_.host_stats = protocol::HostFrameStats::GetForVideoPacket(*packet_); | 43 stats_.host_stats = protocol::HostFrameStats::GetForVideoPacket(*packet_); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 event_handler_->OnVideoDecodeError(); | 324 event_handler_->OnVideoDecodeError(); |
| 323 return; | 325 return; |
| 324 } | 326 } |
| 325 | 327 |
| 326 pending_frames_.front()->OnDecoded(); | 328 pending_frames_.front()->OnDecoded(); |
| 327 // Move the frame from |pending_frames_| to |decoded_frames_|. | 329 // Move the frame from |pending_frames_| to |decoded_frames_|. |
| 328 decoded_frames_.splice(decoded_frames_.end(), pending_frames_, | 330 decoded_frames_.splice(decoded_frames_.end(), pending_frames_, |
| 329 pending_frames_.begin()); | 331 pending_frames_.begin()); |
| 330 | 332 |
| 331 DecodeNextPacket(); | 333 DecodeNextPacket(); |
| 332 GetNextPicture(); | 334 GetNextPictureIfReady(); |
| 333 } | 335 } |
| 334 | 336 |
| 335 void PepperVideoRenderer3D::GetNextPicture() { | 337 void PepperVideoRenderer3D::GetNextPictureIfReady() { |
|
joedow
2017/02/14 00:24:47
Wez's comment about only needing the |decoded_fram
Wez
2017/02/14 00:33:00
The alternative would be to DCHECK(!decoded_frames
joedow
2017/02/14 16:01:34
The unit test is a fair point (as was the suggeste
| |
| 336 // Return early if |decoded_frames_| is empty or the decoder is already | 338 // Return early if |decoded_frames_| is empty or the decoder is already |
| 337 // preparing a picture. If we call GetPicture() before a new frame has been | 339 // preparing a picture. If we call GetPicture() before a new frame has been |
| 338 // prepared (i.e. |decoded_frames_| is populated), the OnPictureReady callback | 340 // prepared (i.e. |decoded_frames_| is populated), the OnPictureReady callback |
| 339 // could be called before OnDecodeDone() is called which will cause a crash. | 341 // could be called before OnDecodeDone() is called which will cause a crash. |
| 340 // See crbug.com/689229 for more details. | 342 // See crbug.com/689229 for more details. |
| 341 if (get_picture_pending_ || decoded_frames_.empty()) { | 343 if (get_picture_pending_ || decoded_frames_.empty()) { |
| 342 return; | 344 return; |
| 343 } | 345 } |
| 344 | 346 |
| 345 int32_t result = | 347 int32_t result = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 DCHECK_EQ(static_cast<int32_t>(picture.decode_id), | 380 DCHECK_EQ(static_cast<int32_t>(picture.decode_id), |
| 379 decoded_frames_.front()->packet()->frame_id()); | 381 decoded_frames_.front()->packet()->frame_id()); |
| 380 | 382 |
| 381 // Move the frame from |decoded_frames_| to |next_picture_frames_|. | 383 // Move the frame from |decoded_frames_| to |next_picture_frames_|. |
| 382 next_picture_frames_.splice(next_picture_frames_.end(), decoded_frames_, | 384 next_picture_frames_.splice(next_picture_frames_.end(), decoded_frames_, |
| 383 decoded_frames_.begin()); | 385 decoded_frames_.begin()); |
| 384 | 386 |
| 385 next_picture_.reset(new Picture(&video_decoder_, picture)); | 387 next_picture_.reset(new Picture(&video_decoder_, picture)); |
| 386 | 388 |
| 387 PaintIfNeeded(); | 389 PaintIfNeeded(); |
| 388 GetNextPicture(); | 390 GetNextPictureIfReady(); |
| 389 } | 391 } |
| 390 | 392 |
| 391 void PepperVideoRenderer3D::PaintIfNeeded() { | 393 void PepperVideoRenderer3D::PaintIfNeeded() { |
| 392 bool need_repaint = next_picture_ || (force_repaint_ && current_picture_); | 394 bool need_repaint = next_picture_ || (force_repaint_ && current_picture_); |
| 393 if (paint_pending_ || !need_repaint) | 395 if (paint_pending_ || !need_repaint) |
| 394 return; | 396 return; |
| 395 | 397 |
| 396 if (next_picture_) { | 398 if (next_picture_) { |
| 397 current_picture_ = std::move(next_picture_); | 399 current_picture_ = std::move(next_picture_); |
| 398 current_picture_frames_.splice(current_picture_frames_.end(), | 400 current_picture_frames_.splice(current_picture_frames_.end(), |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader); | 581 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader); |
| 580 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); | 582 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); |
| 581 } | 583 } |
| 582 | 584 |
| 583 void PepperVideoRenderer3D::CheckGLError() { | 585 void PepperVideoRenderer3D::CheckGLError() { |
| 584 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); | 586 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); |
| 585 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; | 587 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; |
| 586 } | 588 } |
| 587 | 589 |
| 588 } // namespace remoting | 590 } // namespace remoting |
| OLD | NEW |