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 #ifndef CONTENT_RENDERER_GPU_GPU_VIDEO_DECODE_ACCELERATOR_HOST_H_ | 5 #ifndef CONTENT_RENDERER_GPU_GPU_VIDEO_DECODE_ACCELERATOR_HOST_H_ |
6 #define CONTENT_RENDERER_GPU_GPU_VIDEO_DECODE_ACCELERATOR_HOST_H_ | 6 #define CONTENT_RENDERER_GPU_GPU_VIDEO_DECODE_ACCELERATOR_HOST_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
12 #include "ipc/ipc_channel.h" | 12 #include "ipc/ipc_channel.h" |
13 #include "media/video/video_decode_accelerator.h" | 13 #include "media/video/video_decode_accelerator.h" |
14 | 14 |
15 class MessageLoop; | 15 class MessageLoop; |
16 class MessageRouter; | 16 class MessageRouter; |
| 17 namespace gpu { |
| 18 class CommandBufferHelper; |
| 19 class ReadWriteTokens; |
| 20 } |
17 | 21 |
18 // This class is used to talk to VideoDecodeAccelerator in the Gpu process | 22 // This class is used to talk to VideoDecodeAccelerator in the Gpu process |
19 // through IPC messages. | 23 // through IPC messages. |
20 class GpuVideoDecodeAcceleratorHost : public IPC::Channel::Listener, | 24 class GpuVideoDecodeAcceleratorHost |
21 public media::VideoDecodeAccelerator { | 25 : public IPC::Channel::Listener, |
| 26 public media::VideoDecodeAccelerator { |
22 public: | 27 public: |
23 // |router| is used to dispatch IPC messages to this object. | 28 // |router| is used to dispatch IPC messages to this object. |
24 // |ipc_sender| is used to send IPC messages to Gpu process. | 29 // |ipc_sender| is used to send IPC messages to Gpu process. |
25 GpuVideoDecodeAcceleratorHost(MessageRouter* router, | 30 GpuVideoDecodeAcceleratorHost(MessageRouter* router, |
26 IPC::Message::Sender* ipc_sender, | 31 IPC::Message::Sender* ipc_sender, |
27 int32 decoder_host_id, | 32 int32 decoder_host_id, |
28 uint32 command_buffer_route_id, | 33 int32 command_buffer_route_id, |
| 34 gpu::CommandBufferHelper* cmd_buffer_helper, |
29 media::VideoDecodeAccelerator::Client* client); | 35 media::VideoDecodeAccelerator::Client* client); |
30 virtual ~GpuVideoDecodeAcceleratorHost(); | 36 virtual ~GpuVideoDecodeAcceleratorHost(); |
31 | 37 |
32 // IPC::Channel::Listener implementation. | 38 // IPC::Channel::Listener implementation. |
33 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 39 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
34 virtual void OnChannelError() OVERRIDE; | 40 virtual void OnChannelError() OVERRIDE; |
35 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 41 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
36 | 42 |
37 // media::VideoDecodeAccelerator implementation. | 43 // media::VideoDecodeAccelerator implementation. |
38 virtual bool GetConfigs( | 44 virtual bool GetConfigs( |
39 const std::vector<uint32>& requested_configs, | 45 const std::vector<uint32>& requested_configs, |
40 std::vector<uint32>* matched_configs) OVERRIDE; | 46 std::vector<uint32>* matched_configs) OVERRIDE; |
41 virtual bool Initialize(const std::vector<uint32>& configs) OVERRIDE; | 47 virtual bool Initialize(const std::vector<uint32>& configs) OVERRIDE; |
42 virtual bool Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | 48 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; |
43 virtual void AssignGLESBuffers( | 49 virtual void AssignGLESBuffers( |
44 const std::vector<media::GLESBuffer>& buffers) OVERRIDE; | 50 const std::vector<media::GLESBuffer>& buffers) OVERRIDE; |
45 virtual void AssignSysmemBuffers( | 51 virtual void AssignSysmemBuffers( |
46 const std::vector<media::SysmemBuffer>& buffers) OVERRIDE; | 52 const std::vector<media::SysmemBuffer>& buffers) OVERRIDE; |
47 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | 53 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; |
48 virtual bool Flush() OVERRIDE; | 54 virtual void Flush() OVERRIDE; |
49 virtual bool Abort() OVERRIDE; | 55 virtual void Abort() OVERRIDE; |
50 | 56 |
51 private: | 57 private: |
| 58 // Insert a token into the command buffer and return a token-pair suitable for |
| 59 // sending over IPC for synchronization with the command buffer. |
| 60 gpu::ReadWriteTokens SyncTokens(); |
| 61 |
52 void OnBitstreamBufferProcessed(int32 bitstream_buffer_id); | 62 void OnBitstreamBufferProcessed(int32 bitstream_buffer_id); |
53 void OnProvidePictureBuffer( | 63 void OnProvidePictureBuffer( |
54 uint32 num_requested_buffers, const gfx::Size& buffer_size, int32 mem_type); | 64 uint32 num_requested_buffers, const gfx::Size& buffer_size, int32 mem_type); |
55 void OnDismissPictureBuffer(int32 picture_buffer_id); | 65 void OnDismissPictureBuffer(int32 picture_buffer_id); |
56 void OnCreateDone(int32 decoder_id); | 66 void OnCreateDone(int32 decoder_id); |
57 void OnInitializeDone(); | 67 void OnInitializeDone(); |
58 void OnPictureReady(int32 picture_buffer_id, | 68 void OnPictureReady(int32 picture_buffer_id, |
59 int32 bitstream_buffer_id, | 69 int32 bitstream_buffer_id, |
60 const gfx::Size& visible_size, | 70 const gfx::Size& visible_size, |
61 const gfx::Size& decoded_size); | 71 const gfx::Size& decoded_size); |
62 void OnFlushDone(); | 72 void OnFlushDone(); |
63 void OnAbortDone(); | 73 void OnAbortDone(); |
64 void OnEndOfStream(); | 74 void OnEndOfStream(); |
65 void OnErrorNotification(uint32 error); | 75 void OnErrorNotification(uint32 error); |
66 | 76 |
67 // A router used to send us IPC messages. | 77 // A router used to send us IPC messages. |
68 MessageRouter* router_; | 78 MessageRouter* router_; |
69 | 79 |
70 // Sends IPC messages to the Gpu process. | 80 // Sends IPC messages to the Gpu process. |
71 IPC::Message::Sender* ipc_sender_; | 81 IPC::Message::Sender* ipc_sender_; |
72 | 82 |
73 // ID of this GpuVideoDecodeAcceleratorHost. | 83 // ID of this GpuVideoDecodeAcceleratorHost. |
74 int32 decoder_host_id_; | 84 int32 decoder_host_id_; |
75 | 85 |
76 // ID of VideoDecodeAccelerator in the Gpu process. | 86 // ID of VideoDecodeAccelerator in the Gpu process. |
77 int32 decoder_id_; | 87 int32 decoder_id_; |
78 | 88 |
79 // Route ID for the command buffer associated with the context the GPU Video | 89 // Route ID for the command buffer associated with the context the GPU Video |
80 // Decoder uses. | 90 // Decoder uses. |
81 uint32 command_buffer_route_id_; | 91 // TODO(fischman): storing route_id's for GPU process entities in the renderer |
| 92 // process is vulnerable to GPU process crashing & being respawned, and |
| 93 // attempting to use an outdated or reused route id. |
| 94 int32 command_buffer_route_id_; |
| 95 |
| 96 // Helper for the command buffer associated with the context the GPU Video |
| 97 // Decoder uses. |
| 98 // TODO(fischman): in the out-of-process case, this won't work |
| 99 // (context3d->gles2_impl() will be NULL), and will have to be replaced with a |
| 100 // dedicated message such as WaitForToken, which will serialize subsequent |
| 101 // message processing behind it. |
| 102 gpu::CommandBufferHelper* cmd_buffer_helper_; |
82 | 103 |
83 // Temporarily store configs here in between Create and Initialize phase. | 104 // Temporarily store configs here in between Create and Initialize phase. |
84 std::vector<uint32> configs_; | 105 std::vector<uint32> configs_; |
85 | 106 |
86 // Reference to the client that will receive callbacks from the decoder. | 107 // Reference to the client that will receive callbacks from the decoder. |
87 media::VideoDecodeAccelerator::Client* client_; | 108 media::VideoDecodeAccelerator::Client* client_; |
88 | 109 |
89 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecodeAcceleratorHost); | 110 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecodeAcceleratorHost); |
90 }; | 111 }; |
91 | 112 |
92 #endif // CONTENT_RENDERER_GPU_GPU_VIDEO_DECODE_ACCELERATOR_HOST_H_ | 113 #endif // CONTENT_RENDERER_GPU_GPU_VIDEO_DECODE_ACCELERATOR_HOST_H_ |
OLD | NEW |