OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <iostream> | 8 #include <iostream> |
9 #include <queue> | 9 #include <queue> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 ~Shader() {} | 47 ~Shader() {} |
48 | 48 |
49 GLuint program; | 49 GLuint program; |
50 GLint texcoord_scale_location; | 50 GLint texcoord_scale_location; |
51 }; | 51 }; |
52 | 52 |
53 class Decoder; | 53 class Decoder; |
54 class MyInstance; | 54 class MyInstance; |
55 | 55 |
56 struct PendingPicture { | 56 struct PendingPicture { |
57 PendingPicture(Decoder* decoder, const PP_VideoPicture& picture) | 57 PendingPicture(Decoder* decoder, |
58 : decoder(decoder), picture(picture) {} | 58 const PP_VideoPicture& picture, |
| 59 const PP_Rect& visible_rect) |
| 60 : decoder(decoder), picture(picture), visible_rect(visible_rect) {} |
59 ~PendingPicture() {} | 61 ~PendingPicture() {} |
60 | 62 |
61 Decoder* decoder; | 63 Decoder* decoder; |
62 PP_VideoPicture picture; | 64 PP_VideoPicture picture; |
| 65 PP_Rect visible_rect; |
63 }; | 66 }; |
64 | 67 |
65 class MyInstance : public pp::Instance, public pp::Graphics3DClient { | 68 class MyInstance : public pp::Instance, public pp::Graphics3DClient { |
66 public: | 69 public: |
67 MyInstance(PP_Instance instance, pp::Module* module); | 70 MyInstance(PP_Instance instance, pp::Module* module); |
68 virtual ~MyInstance(); | 71 virtual ~MyInstance(); |
69 | 72 |
70 // pp::Instance implementation. | 73 // pp::Instance implementation. |
71 virtual void DidChangeView(const pp::Rect& position, | 74 virtual void DidChangeView(const pp::Rect& position, |
72 const pp::Rect& clip_ignored); | 75 const pp::Rect& clip_ignored); |
73 virtual bool HandleInputEvent(const pp::InputEvent& event); | 76 virtual bool HandleInputEvent(const pp::InputEvent& event); |
74 | 77 |
75 // pp::Graphics3DClient implementation. | 78 // pp::Graphics3DClient implementation. |
76 virtual void Graphics3DContextLost() { | 79 virtual void Graphics3DContextLost() { |
77 // TODO(vrk/fischman): Properly reset after a lost graphics context. In | 80 // TODO(vrk/fischman): Properly reset after a lost graphics context. In |
78 // particular need to delete context_ and re-create textures. | 81 // particular need to delete context_ and re-create textures. |
79 // Probably have to recreate the decoder from scratch, because old textures | 82 // Probably have to recreate the decoder from scratch, because old textures |
80 // can still be outstanding in the decoder! | 83 // can still be outstanding in the decoder! |
81 assert(false && "Unexpectedly lost graphics context"); | 84 assert(false && "Unexpectedly lost graphics context"); |
82 } | 85 } |
83 | 86 |
84 void PaintPicture(Decoder* decoder, const PP_VideoPicture& picture); | 87 void PaintPicture(Decoder* decoder, |
| 88 const PP_VideoPicture& picture, |
| 89 const PP_Rect& visible_rect); |
85 | 90 |
86 private: | 91 private: |
87 // Log an error to the developer console and stderr by creating a temporary | 92 // Log an error to the developer console and stderr by creating a temporary |
88 // object of this type and streaming to it. Example usage: | 93 // object of this type and streaming to it. Example usage: |
89 // LogError(this).s() << "Hello world: " << 42; | 94 // LogError(this).s() << "Hello world: " << 42; |
90 class LogError { | 95 class LogError { |
91 public: | 96 public: |
92 LogError(MyInstance* instance) : instance_(instance) {} | 97 LogError(MyInstance* instance) : instance_(instance) {} |
93 ~LogError() { | 98 ~LogError() { |
94 const std::string& msg = stream_.str(); | 99 const std::string& msg = stream_.str(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 void DecodeDone(int32_t result); | 178 void DecodeDone(int32_t result); |
174 void PictureReady(int32_t result, PP_VideoPicture picture); | 179 void PictureReady(int32_t result, PP_VideoPicture picture); |
175 void FlushDone(int32_t result); | 180 void FlushDone(int32_t result); |
176 void ResetDone(int32_t result); | 181 void ResetDone(int32_t result); |
177 | 182 |
178 MyInstance* instance_; | 183 MyInstance* instance_; |
179 int id_; | 184 int id_; |
180 | 185 |
181 pp::VideoDecoder* decoder_; | 186 pp::VideoDecoder* decoder_; |
182 pp::CompletionCallbackFactory<Decoder> callback_factory_; | 187 pp::CompletionCallbackFactory<Decoder> callback_factory_; |
| 188 PP_Rect picture_visible_rect_; |
183 | 189 |
184 size_t encoded_data_next_pos_to_decode_; | 190 size_t encoded_data_next_pos_to_decode_; |
185 int next_picture_id_; | 191 int next_picture_id_; |
186 bool flushing_; | 192 bool flushing_; |
187 bool resetting_; | 193 bool resetting_; |
188 | 194 |
189 const PPB_Core* core_if_; | 195 const PPB_Core* core_if_; |
190 static const int kMaxDecodeDelay = 128; | 196 static const int kMaxDecodeDelay = 128; |
191 PP_TimeTicks decode_time_[kMaxDecodeDelay]; | 197 PP_TimeTicks decode_time_[kMaxDecodeDelay]; |
192 PP_TimeTicks total_latency_; | 198 PP_TimeTicks total_latency_; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 276 } |
271 | 277 |
272 void Decoder::Start() { | 278 void Decoder::Start() { |
273 assert(decoder_); | 279 assert(decoder_); |
274 | 280 |
275 encoded_data_next_pos_to_decode_ = 0; | 281 encoded_data_next_pos_to_decode_ = 0; |
276 | 282 |
277 // Register callback to get the first picture. We call GetPicture again in | 283 // Register callback to get the first picture. We call GetPicture again in |
278 // PictureReady to continuously receive pictures as they're decoded. | 284 // PictureReady to continuously receive pictures as they're decoded. |
279 decoder_->GetPicture( | 285 decoder_->GetPicture( |
| 286 &picture_visible_rect_, |
280 callback_factory_.NewCallbackWithOutput(&Decoder::PictureReady)); | 287 callback_factory_.NewCallbackWithOutput(&Decoder::PictureReady)); |
281 | 288 |
282 // Start the decode loop. | 289 // Start the decode loop. |
283 DecodeNextFrame(); | 290 DecodeNextFrame(); |
284 } | 291 } |
285 | 292 |
286 void Decoder::Reset() { | 293 void Decoder::Reset() { |
287 assert(decoder_); | 294 assert(decoder_); |
288 assert(!resetting_); | 295 assert(!resetting_); |
289 resetting_ = true; | 296 resetting_ = true; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // Break out of the get picture loop on abort. | 343 // Break out of the get picture loop on abort. |
337 if (result == PP_ERROR_ABORTED) | 344 if (result == PP_ERROR_ABORTED) |
338 return; | 345 return; |
339 assert(result == PP_OK); | 346 assert(result == PP_OK); |
340 | 347 |
341 num_pictures_++; | 348 num_pictures_++; |
342 PP_TimeTicks latency = core_if_->GetTimeTicks() - | 349 PP_TimeTicks latency = core_if_->GetTimeTicks() - |
343 decode_time_[picture.decode_id % kMaxDecodeDelay]; | 350 decode_time_[picture.decode_id % kMaxDecodeDelay]; |
344 total_latency_ += latency; | 351 total_latency_ += latency; |
345 | 352 |
| 353 PP_Rect visible_rect = picture_visible_rect_; |
346 decoder_->GetPicture( | 354 decoder_->GetPicture( |
| 355 &picture_visible_rect_, |
347 callback_factory_.NewCallbackWithOutput(&Decoder::PictureReady)); | 356 callback_factory_.NewCallbackWithOutput(&Decoder::PictureReady)); |
348 instance_->PaintPicture(this, picture); | 357 instance_->PaintPicture(this, picture, visible_rect); |
349 } | 358 } |
350 | 359 |
351 void Decoder::FlushDone(int32_t result) { | 360 void Decoder::FlushDone(int32_t result) { |
352 assert(decoder_); | 361 assert(decoder_); |
353 assert(result == PP_OK || result == PP_ERROR_ABORTED); | 362 assert(result == PP_OK || result == PP_ERROR_ABORTED); |
354 assert(flushing_); | 363 assert(flushing_); |
355 flushing_ = false; | 364 flushing_ = false; |
356 } | 365 } |
357 | 366 |
358 void Decoder::ResetDone(int32_t result) { | 367 void Decoder::ResetDone(int32_t result) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 } | 449 } |
441 | 450 |
442 void MyInstance::InitializeDecoders() { | 451 void MyInstance::InitializeDecoders() { |
443 assert(video_decoders_.empty()); | 452 assert(video_decoders_.empty()); |
444 // Create two decoders with ids 0 and 1. | 453 // Create two decoders with ids 0 and 1. |
445 video_decoders_.push_back(new Decoder(this, 0, *context_)); | 454 video_decoders_.push_back(new Decoder(this, 0, *context_)); |
446 video_decoders_.push_back(new Decoder(this, 1, *context_)); | 455 video_decoders_.push_back(new Decoder(this, 1, *context_)); |
447 } | 456 } |
448 | 457 |
449 void MyInstance::PaintPicture(Decoder* decoder, | 458 void MyInstance::PaintPicture(Decoder* decoder, |
450 const PP_VideoPicture& picture) { | 459 const PP_VideoPicture& picture, |
| 460 const PP_Rect& visible_rect) { |
451 if (first_frame_delivered_ticks_ == -1) | 461 if (first_frame_delivered_ticks_ == -1) |
452 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); | 462 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); |
453 | 463 |
454 pending_pictures_.push(PendingPicture(decoder, picture)); | 464 pending_pictures_.push(PendingPicture(decoder, picture, visible_rect)); |
455 if (!is_painting_) | 465 if (!is_painting_) |
456 PaintNextPicture(); | 466 PaintNextPicture(); |
457 } | 467 } |
458 | 468 |
459 void MyInstance::PaintNextPicture() { | 469 void MyInstance::PaintNextPicture() { |
460 assert(!is_painting_); | 470 assert(!is_painting_); |
461 is_painting_ = true; | 471 is_painting_ = true; |
462 | 472 |
463 const PendingPicture& next = pending_pictures_.front(); | 473 const PendingPicture& next = pending_pictures_.front(); |
464 Decoder* decoder = next.decoder; | 474 Decoder* decoder = next.decoder; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 }; | 737 }; |
728 | 738 |
729 } // anonymous namespace | 739 } // anonymous namespace |
730 | 740 |
731 namespace pp { | 741 namespace pp { |
732 // Factory function for your specialization of the Module object. | 742 // Factory function for your specialization of the Module object. |
733 Module* CreateModule() { | 743 Module* CreateModule() { |
734 return new MyModule(); | 744 return new MyModule(); |
735 } | 745 } |
736 } // namespace pp | 746 } // namespace pp |
OLD | NEW |