| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_PEPPER_VIDEO_DECODER_SHIM_H_ | |
| 6 #define CONTENT_RENDERER_PEPPER_VIDEO_DECODER_SHIM_H_ | |
| 7 | |
| 8 #include <queue> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/containers/hash_tables.h" | |
| 13 #include "base/memory/linked_ptr.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "base/message_loop/message_loop_proxy.h" | |
| 17 #include "gpu/command_buffer/common/mailbox.h" | |
| 18 #include "media/base/video_decoder_config.h" | |
| 19 #include "media/video/video_decode_accelerator.h" | |
| 20 | |
| 21 #include "ppapi/c/pp_codecs.h" | |
| 22 | |
| 23 namespace gpu { | |
| 24 namespace gles2 { | |
| 25 class GLES2Interface; | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 namespace media { | |
| 30 class DecoderBuffer; | |
| 31 } | |
| 32 | |
| 33 namespace webkit { | |
| 34 namespace gpu { | |
| 35 class ContextProviderWebContext; | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 namespace content { | |
| 40 | |
| 41 class PepperVideoDecoderHost; | |
| 42 | |
| 43 // This class is a shim to wrap a media::VideoDecoder so that it can be used | |
| 44 // by PepperVideoDecoderHost in place of a media::VideoDecodeAccelerator. | |
| 45 // This class should be constructed, used, and destructed on the main (render) | |
| 46 // thread. | |
| 47 class VideoDecoderShim : public media::VideoDecodeAccelerator { | |
| 48 public: | |
| 49 explicit VideoDecoderShim(PepperVideoDecoderHost* host); | |
| 50 virtual ~VideoDecoderShim(); | |
| 51 | |
| 52 // media::VideoDecodeAccelerator implementation. | |
| 53 virtual bool Initialize( | |
| 54 media::VideoCodecProfile profile, | |
| 55 media::VideoDecodeAccelerator::Client* client) OVERRIDE; | |
| 56 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | |
| 57 virtual void AssignPictureBuffers( | |
| 58 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; | |
| 59 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | |
| 60 virtual void Flush() OVERRIDE; | |
| 61 virtual void Reset() OVERRIDE; | |
| 62 virtual void Destroy() OVERRIDE; | |
| 63 | |
| 64 private: | |
| 65 enum State { | |
| 66 UNINITIALIZED, | |
| 67 DECODING, | |
| 68 FLUSHING, | |
| 69 RESETTING, | |
| 70 }; | |
| 71 | |
| 72 struct PendingDecode; | |
| 73 struct PendingFrame; | |
| 74 class DecoderImpl; | |
| 75 | |
| 76 void OnInitializeComplete(int32_t result, uint32_t texture_pool_size); | |
| 77 void OnDecodeComplete(int32_t result, uint32_t decode_id); | |
| 78 void OnOutputComplete(scoped_ptr<PendingFrame> frame); | |
| 79 void SendPictures(); | |
| 80 void OnResetComplete(); | |
| 81 void NotifyCompletedDecodes(); | |
| 82 void DismissTexture(uint32_t texture_id); | |
| 83 void DeleteTexture(uint32_t texture_id); | |
| 84 // Call this whenever we change GL state that the plugin relies on, such as | |
| 85 // creating picture textures. | |
| 86 void FlushCommandBuffer(); | |
| 87 | |
| 88 scoped_ptr<DecoderImpl> decoder_impl_; | |
| 89 State state_; | |
| 90 | |
| 91 PepperVideoDecoderHost* host_; | |
| 92 scoped_refptr<base::MessageLoopProxy> media_message_loop_; | |
| 93 scoped_refptr<webkit::gpu::ContextProviderWebContext> context_provider_; | |
| 94 | |
| 95 // The current decoded frame size. | |
| 96 gfx::Size texture_size_; | |
| 97 // Map that takes the plugin's GL texture id to the renderer's GL texture id. | |
| 98 typedef base::hash_map<uint32_t, uint32_t> TextureIdMap; | |
| 99 TextureIdMap texture_id_map_; | |
| 100 // Available textures (these are plugin ids.) | |
| 101 std::vector<uint32_t> available_textures_; | |
| 102 // Track textures that are no longer needed (these are plugin ids.) | |
| 103 typedef base::hash_set<uint32_t> TextureIdSet; | |
| 104 TextureIdSet textures_to_dismiss_; | |
| 105 // Mailboxes for pending texture requests, to write to plugin's textures. | |
| 106 std::vector<gpu::Mailbox> pending_texture_mailboxes_; | |
| 107 | |
| 108 // Queue of completed decode ids, for notifying the host. | |
| 109 typedef std::queue<uint32_t> CompletedDecodeQueue; | |
| 110 CompletedDecodeQueue completed_decodes_; | |
| 111 | |
| 112 // Queue of decoded frames that have been converted to RGB and await upload to | |
| 113 // a GL texture. | |
| 114 typedef std::queue<linked_ptr<PendingFrame> > PendingFrameQueue; | |
| 115 PendingFrameQueue pending_frames_; | |
| 116 | |
| 117 // The optimal number of textures to allocate for decoder_impl_. | |
| 118 uint32_t texture_pool_size_; | |
| 119 | |
| 120 uint32_t num_pending_decodes_; | |
| 121 | |
| 122 base::WeakPtrFactory<VideoDecoderShim> weak_ptr_factory_; | |
| 123 | |
| 124 DISALLOW_COPY_AND_ASSIGN(VideoDecoderShim); | |
| 125 }; | |
| 126 | |
| 127 } // namespace content | |
| 128 | |
| 129 #endif // CONTENT_RENDERER_PEPPER_VIDEO_DECODER_SHIM_H_ | |
| OLD | NEW |