| 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 <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 virtual void Graphics3DContextLost() { | 51 virtual void Graphics3DContextLost() { |
| 52 // TODO(vrk/fischman): Properly reset after a lost graphics context. In | 52 // TODO(vrk/fischman): Properly reset after a lost graphics context. In |
| 53 // particular need to delete context_ & surface_ and re-create textures. | 53 // particular need to delete context_ & surface_ and re-create textures. |
| 54 // Probably have to recreate the decoder from scratch, because old textures | 54 // Probably have to recreate the decoder from scratch, because old textures |
| 55 // can still be outstanding in the decoder! | 55 // can still be outstanding in the decoder! |
| 56 assert(!"Unexpectedly lost graphics context"); | 56 assert(!"Unexpectedly lost graphics context"); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // pp::VideoDecoderClient_Dev implementation. | 59 // pp::VideoDecoderClient_Dev implementation. |
| 60 virtual void ProvidePictureBuffers( | 60 virtual void ProvidePictureBuffers( |
| 61 uint32_t req_num_of_bufs, PP_Size dimensions, | 61 uint32_t req_num_of_bufs, PP_Size dimensions); |
| 62 PP_PictureBufferType_Dev type); | |
| 63 virtual void DismissPictureBuffer(int32_t picture_buffer_id); | 62 virtual void DismissPictureBuffer(int32_t picture_buffer_id); |
| 64 virtual void PictureReady(const PP_Picture_Dev& picture); | 63 virtual void PictureReady(const PP_Picture_Dev& picture); |
| 65 virtual void EndOfStream(); | 64 virtual void EndOfStream(); |
| 66 virtual void NotifyError(PP_VideoDecodeError_Dev error); | 65 virtual void NotifyError(PP_VideoDecodeError_Dev error); |
| 67 | 66 |
| 68 private: | 67 private: |
| 69 enum { kNumConcurrentDecodes = 7 }; | 68 enum { kNumConcurrentDecodes = 7 }; |
| 70 | 69 |
| 71 // Initialize Video Decoder. | 70 // Initialize Video Decoder. |
| 72 void InitializeDecoder(); | 71 void InitializeDecoder(); |
| 73 | 72 |
| 74 // Callbacks passed into pp:VideoDecoder_Dev functions. | 73 // Callbacks passed into pp:VideoDecoder_Dev functions. |
| 75 void DecoderInitDone(int32_t result); | 74 void DecoderInitDone(int32_t result); |
| 76 void DecoderBitstreamDone(int32_t result, int bitstream_buffer_id); | 75 void DecoderBitstreamDone(int32_t result, int bitstream_buffer_id); |
| 77 void DecoderFlushDone(int32_t result); | 76 void DecoderFlushDone(int32_t result); |
| 78 | 77 |
| 79 // Decode helpers. | 78 // Decode helpers. |
| 80 void DecodeNextNALUs(); | 79 void DecodeNextNALUs(); |
| 81 void DecodeNextNALU(); | 80 void DecodeNextNALU(); |
| 82 void GetNextNALUBoundary(size_t start_pos, size_t* end_pos); | 81 void GetNextNALUBoundary(size_t start_pos, size_t* end_pos); |
| 83 void Render(const PP_GLESBuffer_Dev& buffer); | 82 void Render(const PP_PictureBuffer_Dev& buffer); |
| 84 | 83 |
| 85 // GL-related functions. | 84 // GL-related functions. |
| 86 void InitGL(); | 85 void InitGL(); |
| 87 GLuint CreateTexture(int32_t width, int32_t height); | 86 GLuint CreateTexture(int32_t width, int32_t height); |
| 88 void CreateGLObjects(); | 87 void CreateGLObjects(); |
| 89 void CreateShader(GLuint program, GLenum type, const char* source, int size); | 88 void CreateShader(GLuint program, GLenum type, const char* source, int size); |
| 90 void DeleteTexture(GLuint id); | 89 void DeleteTexture(GLuint id); |
| 91 void PaintFinished(int32_t result, int picture_buffer_id); | 90 void PaintFinished(int32_t result, int picture_buffer_id); |
| 92 | 91 |
| 93 pp::Size position_size_; | 92 pp::Size position_size_; |
| 94 int next_picture_buffer_id_; | 93 int next_picture_buffer_id_; |
| 95 int next_bitstream_buffer_id_; | 94 int next_bitstream_buffer_id_; |
| 96 bool is_painting_; | 95 bool is_painting_; |
| 97 pp::CompletionCallbackFactory<GLES2DemoInstance> callback_factory_; | 96 pp::CompletionCallbackFactory<GLES2DemoInstance> callback_factory_; |
| 98 size_t encoded_data_next_pos_to_decode_; | 97 size_t encoded_data_next_pos_to_decode_; |
| 99 std::set<int> bitstream_ids_at_decoder_; | 98 std::set<int> bitstream_ids_at_decoder_; |
| 100 // When decode outpaces render, we queue up decoded pictures for later | 99 // When decode outpaces render, we queue up decoded pictures for later |
| 101 // painting. | 100 // painting. |
| 102 std::list<PP_Picture_Dev> pictures_pending_paint_; | 101 std::list<PP_Picture_Dev> pictures_pending_paint_; |
| 103 int num_frames_rendered_; | 102 int num_frames_rendered_; |
| 104 | 103 |
| 105 // Map of texture buffers indexed by buffer id. | 104 // Map of texture buffers indexed by buffer id. |
| 106 typedef std::map<int, PP_GLESBuffer_Dev> PictureBufferMap; | 105 typedef std::map<int, PP_PictureBuffer_Dev> PictureBufferMap; |
| 107 PictureBufferMap buffers_by_id_; | 106 PictureBufferMap buffers_by_id_; |
| 108 // Map of bitstream buffers indexed by id. | 107 // Map of bitstream buffers indexed by id. |
| 109 typedef std::map<int, pp::Buffer_Dev*> BitstreamBufferMap; | 108 typedef std::map<int, pp::Buffer_Dev*> BitstreamBufferMap; |
| 110 BitstreamBufferMap bitstream_buffers_by_id_; | 109 BitstreamBufferMap bitstream_buffers_by_id_; |
| 111 PP_TimeTicks first_frame_delivered_ticks_; | 110 PP_TimeTicks first_frame_delivered_ticks_; |
| 112 PP_TimeTicks last_swap_request_ticks_; | 111 PP_TimeTicks last_swap_request_ticks_; |
| 113 PP_TimeTicks swap_ticks_; | 112 PP_TimeTicks swap_ticks_; |
| 114 | 113 |
| 115 // Unowned pointers. | 114 // Unowned pointers. |
| 116 const struct PPB_Core* core_if_; | 115 const struct PPB_Core* core_if_; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 243 |
| 245 pp::CompletionCallback cb = | 244 pp::CompletionCallback cb = |
| 246 callback_factory_.NewCallback( | 245 callback_factory_.NewCallback( |
| 247 &GLES2DemoInstance::DecoderBitstreamDone, id); | 246 &GLES2DemoInstance::DecoderBitstreamDone, id); |
| 248 assert(bitstream_ids_at_decoder_.insert(id).second); | 247 assert(bitstream_ids_at_decoder_.insert(id).second); |
| 249 video_decoder_->Decode(bitstream_buffer, cb); | 248 video_decoder_->Decode(bitstream_buffer, cb); |
| 250 encoded_data_next_pos_to_decode_ = end_pos; | 249 encoded_data_next_pos_to_decode_ = end_pos; |
| 251 } | 250 } |
| 252 | 251 |
| 253 void GLES2DemoInstance::ProvidePictureBuffers( | 252 void GLES2DemoInstance::ProvidePictureBuffers( |
| 254 uint32_t req_num_of_bufs, PP_Size dimensions, | 253 uint32_t req_num_of_bufs, PP_Size dimensions) { |
| 255 PP_PictureBufferType_Dev type) { | 254 std::vector<PP_PictureBuffer_Dev> buffers; |
| 256 std::vector<PP_GLESBuffer_Dev> buffers; | |
| 257 for (uint32_t i = 0; i < req_num_of_bufs; i++) { | 255 for (uint32_t i = 0; i < req_num_of_bufs; i++) { |
| 258 PP_GLESBuffer_Dev buffer; | 256 PP_PictureBuffer_Dev buffer; |
| 259 buffer.texture_id = CreateTexture(dimensions.width, dimensions.height); | 257 buffer.texture_id = CreateTexture(dimensions.width, dimensions.height); |
| 260 int id = ++next_picture_buffer_id_; | 258 int id = ++next_picture_buffer_id_; |
| 261 buffer.info.id= id; | 259 buffer.id = id; |
| 262 buffers.push_back(buffer); | 260 buffers.push_back(buffer); |
| 263 assert(buffers_by_id_.insert(std::make_pair(id, buffer)).second); | 261 assert(buffers_by_id_.insert(std::make_pair(id, buffer)).second); |
| 264 } | 262 } |
| 265 video_decoder_->AssignGLESBuffers(buffers); | 263 video_decoder_->AssignPictureBuffers(buffers); |
| 266 } | 264 } |
| 267 | 265 |
| 268 void GLES2DemoInstance::DismissPictureBuffer(int32_t picture_buffer_id) { | 266 void GLES2DemoInstance::DismissPictureBuffer(int32_t picture_buffer_id) { |
| 269 PictureBufferMap::iterator it = buffers_by_id_.find(picture_buffer_id); | 267 PictureBufferMap::iterator it = buffers_by_id_.find(picture_buffer_id); |
| 270 assert(it != buffers_by_id_.end()); | 268 assert(it != buffers_by_id_.end()); |
| 271 DeleteTexture(it->second.texture_id); | 269 DeleteTexture(it->second.texture_id); |
| 272 buffers_by_id_.erase(it); | 270 buffers_by_id_.erase(it); |
| 273 } | 271 } |
| 274 | 272 |
| 275 void GLES2DemoInstance::PictureReady(const PP_Picture_Dev& picture) { | 273 void GLES2DemoInstance::PictureReady(const PP_Picture_Dev& picture) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 gles2_if_->Clear(context_->pp_resource(), GL_COLOR_BUFFER_BIT); | 323 gles2_if_->Clear(context_->pp_resource(), GL_COLOR_BUFFER_BIT); |
| 326 gles2_if_->Viewport(context_->pp_resource(), 0, 0, | 324 gles2_if_->Viewport(context_->pp_resource(), 0, 0, |
| 327 position_size_.width(), position_size_.height()); | 325 position_size_.width(), position_size_.height()); |
| 328 | 326 |
| 329 assert(BindGraphics(*surface_)); | 327 assert(BindGraphics(*surface_)); |
| 330 assertNoGLError(); | 328 assertNoGLError(); |
| 331 | 329 |
| 332 CreateGLObjects(); | 330 CreateGLObjects(); |
| 333 } | 331 } |
| 334 | 332 |
| 335 void GLES2DemoInstance::Render(const PP_GLESBuffer_Dev& buffer) { | 333 void GLES2DemoInstance::Render(const PP_PictureBuffer_Dev& buffer) { |
| 336 assert(!is_painting_); | 334 assert(!is_painting_); |
| 337 is_painting_ = true; | 335 is_painting_ = true; |
| 338 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); | 336 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); |
| 339 gles2_if_->BindTexture( | 337 gles2_if_->BindTexture( |
| 340 context_->pp_resource(), GL_TEXTURE_2D, buffer.texture_id); | 338 context_->pp_resource(), GL_TEXTURE_2D, buffer.texture_id); |
| 341 gles2_if_->DrawArrays(context_->pp_resource(), GL_TRIANGLE_STRIP, 0, 4); | 339 gles2_if_->DrawArrays(context_->pp_resource(), GL_TRIANGLE_STRIP, 0, 4); |
| 342 pp::CompletionCallback cb = | 340 pp::CompletionCallback cb = |
| 343 callback_factory_.NewCallback( | 341 callback_factory_.NewCallback( |
| 344 &GLES2DemoInstance::PaintFinished, buffer.info.id); | 342 &GLES2DemoInstance::PaintFinished, buffer.id); |
| 345 last_swap_request_ticks_ = core_if_->GetTimeTicks(); | 343 last_swap_request_ticks_ = core_if_->GetTimeTicks(); |
| 346 assert(surface_->SwapBuffers(cb) == PP_OK_COMPLETIONPENDING); | 344 assert(surface_->SwapBuffers(cb) == PP_OK_COMPLETIONPENDING); |
| 347 } | 345 } |
| 348 | 346 |
| 349 void GLES2DemoInstance::PaintFinished(int32_t result, int picture_buffer_id) { | 347 void GLES2DemoInstance::PaintFinished(int32_t result, int picture_buffer_id) { |
| 350 swap_ticks_ += core_if_->GetTimeTicks() - last_swap_request_ticks_; | 348 swap_ticks_ += core_if_->GetTimeTicks() - last_swap_request_ticks_; |
| 351 is_painting_ = false; | 349 is_painting_ = false; |
| 352 ++num_frames_rendered_; | 350 ++num_frames_rendered_; |
| 353 if (num_frames_rendered_ % 50 == 0) { | 351 if (num_frames_rendered_ % 50 == 0) { |
| 354 double elapsed = core_if_->GetTimeTicks() - first_frame_delivered_ticks_; | 352 double elapsed = core_if_->GetTimeTicks() - first_frame_delivered_ticks_; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 gles2_if_->DeleteShader(context_->pp_resource(), shader); | 470 gles2_if_->DeleteShader(context_->pp_resource(), shader); |
| 473 } | 471 } |
| 474 } // anonymous namespace | 472 } // anonymous namespace |
| 475 | 473 |
| 476 namespace pp { | 474 namespace pp { |
| 477 // Factory function for your specialization of the Module object. | 475 // Factory function for your specialization of the Module object. |
| 478 Module* CreateModule() { | 476 Module* CreateModule() { |
| 479 return new GLES2DemoModule(); | 477 return new GLES2DemoModule(); |
| 480 } | 478 } |
| 481 } // namespace pp | 479 } // namespace pp |
| OLD | NEW |