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_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_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 "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
14 #include "media/video/video_decode_accelerator.h" | 14 #include "media/video/video_decode_accelerator.h" |
15 | 15 |
16 namespace gpu { | 16 namespace gpu { |
17 class ReadWriteTokens; | 17 class ReadWriteTokens; |
18 } | 18 } |
19 | 19 |
20 class GpuCommandBufferStub; | 20 class GpuCommandBufferStub; |
21 | 21 |
22 class GpuVideoDecodeAccelerator | 22 class GpuVideoDecodeAccelerator |
23 : public base::RefCountedThreadSafe<GpuVideoDecodeAccelerator>, | 23 : public IPC::Channel::Listener, |
24 public IPC::Channel::Listener, | |
25 public IPC::Message::Sender, | 24 public IPC::Message::Sender, |
26 public media::VideoDecodeAccelerator::Client { | 25 public media::VideoDecodeAccelerator::Client { |
27 public: | 26 public: |
28 GpuVideoDecodeAccelerator(IPC::Message::Sender* sender, | 27 GpuVideoDecodeAccelerator(IPC::Message::Sender* sender, |
29 int32 host_route_id, | 28 int32 host_route_id, |
30 int32 decoder_route_id, | |
31 GpuCommandBufferStub* stub); | 29 GpuCommandBufferStub* stub); |
32 virtual ~GpuVideoDecodeAccelerator(); | 30 virtual ~GpuVideoDecodeAccelerator(); |
33 | 31 |
34 // IPC::Channel::Listener implementation. | 32 // IPC::Channel::Listener implementation. |
35 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 33 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
36 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 34 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
37 virtual void OnChannelError() OVERRIDE; | 35 virtual void OnChannelError() OVERRIDE; |
38 | 36 |
39 // media::VideoDecodeAccelerator::Client implementation. | 37 // media::VideoDecodeAccelerator::Client implementation. |
40 virtual void ProvidePictureBuffers( | 38 virtual void ProvidePictureBuffers( |
41 uint32 requested_num_of_buffers, | 39 uint32 requested_num_of_buffers, |
42 const gfx::Size& dimensions, | 40 const gfx::Size& dimensions, |
43 media::VideoDecodeAccelerator::MemoryType type) OVERRIDE; | 41 media::VideoDecodeAccelerator::MemoryType type) OVERRIDE; |
44 virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE; | 42 virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE; |
45 virtual void PictureReady(const media::Picture& picture) OVERRIDE; | 43 virtual void PictureReady(const media::Picture& picture) OVERRIDE; |
46 virtual void NotifyInitializeDone() OVERRIDE; | 44 virtual void NotifyInitializeDone() OVERRIDE; |
47 virtual void NotifyEndOfStream() OVERRIDE; | 45 virtual void NotifyEndOfStream() OVERRIDE; |
48 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; | 46 virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; |
49 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE; | 47 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE; |
50 virtual void NotifyFlushDone() OVERRIDE; | 48 virtual void NotifyFlushDone() OVERRIDE; |
51 virtual void NotifyAbortDone() OVERRIDE; | 49 virtual void NotifyAbortDone() OVERRIDE; |
52 | 50 |
53 // Function to delegate sending to actual sender. | 51 // Function to delegate sending to actual sender. |
54 virtual bool Send(IPC::Message* message); | 52 virtual bool Send(IPC::Message* message); |
55 | 53 |
56 void set_video_decode_accelerator( | |
57 media::VideoDecodeAccelerator* accelerator) { | |
58 DCHECK(!video_decode_accelerator_.get()); | |
59 video_decode_accelerator_.reset(accelerator); | |
60 } | |
61 | |
62 void AssignGLESBuffers(const std::vector<media::GLESBuffer>& buffers); | |
63 | |
64 // Callback to be fired when the underlying stub receives a new token. | 54 // Callback to be fired when the underlying stub receives a new token. |
65 void OnSetToken(int32 token); | 55 void OnSetToken(int32 token); |
66 | 56 |
| 57 // Initialize the accelerator with the given configuration. |
| 58 void Initialize(const std::vector<uint32>& configs); |
| 59 |
67 private: | 60 private: |
68 // Defers |msg| for later processing if it specifies a write token that hasn't | 61 // Defers |msg| for later processing if it specifies a write token that hasn't |
69 // come to pass yet, and set |*deferred| to true. Return false if the message | 62 // come to pass yet, and set |*deferred| to true. Return false if the message |
70 // failed to parse. | 63 // failed to parse. |
71 bool DeferMessageIfNeeded(const IPC::Message& msg, bool* deferred); | 64 bool DeferMessageIfNeeded(const IPC::Message& msg, bool* deferred); |
72 | 65 |
73 // Handlers for IPC messages. | 66 // Handlers for IPC messages. |
74 void OnGetConfigs( | 67 void OnGetConfigs( |
75 const gpu::ReadWriteTokens& /* tokens */, | 68 const gpu::ReadWriteTokens& /* tokens */, |
76 const std::vector<uint32>& config, | 69 const std::vector<uint32>& config, |
77 std::vector<uint32>* configs); | 70 std::vector<uint32>* configs); |
78 void OnInitialize( | |
79 const gpu::ReadWriteTokens& /* tokens */, | |
80 const std::vector<uint32>& configs); | |
81 void OnDecode( | 71 void OnDecode( |
82 const gpu::ReadWriteTokens& /* tokens */, | 72 const gpu::ReadWriteTokens& /* tokens */, |
83 base::SharedMemoryHandle handle, int32 id, int32 size); | 73 base::SharedMemoryHandle handle, int32 id, int32 size); |
84 void OnAssignTextures( | 74 void OnAssignGLESBuffers( |
85 const gpu::ReadWriteTokens& /* tokens */, | 75 const gpu::ReadWriteTokens& /* tokens */, |
86 const std::vector<int32>& buffer_ids, | 76 const std::vector<int32>& buffer_ids, |
87 const std::vector<uint32>& texture_ids, | 77 const std::vector<uint32>& texture_ids, |
88 const std::vector<gfx::Size>& sizes); | 78 const std::vector<gfx::Size>& sizes); |
89 void OnAssignSysmemBuffers( | 79 void OnAssignSysmemBuffers( |
90 const gpu::ReadWriteTokens& /* tokens */, | 80 const gpu::ReadWriteTokens& /* tokens */, |
91 const std::vector<int32> buffer_ids, | 81 const std::vector<int32> buffer_ids, |
92 const std::vector<base::SharedMemoryHandle> data, | 82 const std::vector<base::SharedMemoryHandle> data, |
93 const std::vector<gfx::Size> sizes); | 83 const std::vector<gfx::Size> sizes); |
94 void OnReusePictureBuffer( | 84 void OnReusePictureBuffer( |
95 const gpu::ReadWriteTokens& /* tokens */, | 85 const gpu::ReadWriteTokens& /* tokens */, |
96 int32 picture_buffer_id); | 86 int32 picture_buffer_id); |
97 void OnFlush(const gpu::ReadWriteTokens& /* tokens */); | 87 void OnFlush(const gpu::ReadWriteTokens& /* tokens */); |
98 void OnAbort(const gpu::ReadWriteTokens& /* tokens */); | 88 void OnAbort(const gpu::ReadWriteTokens& /* tokens */); |
99 | 89 |
100 // Pointer to the IPC message sender. | 90 // Pointer to the IPC message sender. |
101 IPC::Message::Sender* sender_; | 91 IPC::Message::Sender* sender_; |
102 | 92 |
103 // Route ID to communicate with the host. | 93 // Route ID to communicate with the host. |
104 int32 host_route_id_; | 94 int32 host_route_id_; |
105 | 95 |
106 // Route ID of the decoder. | |
107 int32 decoder_route_id_; | |
108 | |
109 // Messages deferred for later processing when their tokens have come to pass. | 96 // Messages deferred for later processing when their tokens have come to pass. |
110 std::vector<IPC::Message*> deferred_messages_; | 97 std::vector<IPC::Message*> deferred_messages_; |
111 | 98 |
112 // Unowned pointer to the underlying GpuCommandBufferStub. | 99 // Unowned pointer to the underlying GpuCommandBufferStub. |
113 GpuCommandBufferStub* stub_; | 100 GpuCommandBufferStub* stub_; |
114 | 101 |
115 // Pointer to the underlying VideoDecodeAccelerator. | 102 // Pointer to the underlying VideoDecodeAccelerator. |
116 scoped_ptr<media::VideoDecodeAccelerator> video_decode_accelerator_; | 103 scoped_ptr<media::VideoDecodeAccelerator> video_decode_accelerator_; |
117 | 104 |
118 DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecodeAccelerator); | 105 DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecodeAccelerator); |
119 }; | 106 }; |
120 | 107 |
121 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_ | 108 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_DECODE_ACCELERATOR_H_ |
OLD | NEW |