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 "content/common/gpu/media/gpu_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "ipc/ipc_message_macros.h" | 11 #include "ipc/ipc_message_macros.h" |
12 #include "ipc/ipc_message_utils.h" | 12 #include "ipc/ipc_message_utils.h" |
13 #include "content/common/gpu/gpu_channel.h" | 13 #include "content/common/gpu/gpu_channel.h" |
14 #include "content/common/gpu/gpu_command_buffer_stub.h" | |
14 #include "content/common/gpu/gpu_messages.h" | 15 #include "content/common/gpu/gpu_messages.h" |
16 #include "content/common/gpu/media/gpu_video_service.h" | |
15 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
16 | 18 |
17 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator( | 19 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator( |
18 IPC::Message::Sender* sender, | 20 IPC::Message::Sender* sender, |
19 int32 host_route_id) | 21 int32 host_route_id, |
22 int32 decoder_route_id, | |
23 GpuCommandBufferStub* stub) | |
20 : sender_(sender), | 24 : sender_(sender), |
21 route_id_(host_route_id), | 25 host_route_id_(host_route_id), |
26 decoder_route_id_(decoder_route_id), | |
27 stub_(stub), | |
22 video_decode_accelerator_(NULL) { | 28 video_decode_accelerator_(NULL) { |
29 stub_->AddSetTokenCallback(base::Bind( | |
30 &GpuVideoDecodeAccelerator::OnSetToken, base::Unretained(this))); | |
scherkus (not reviewing)
2011/06/27 22:54:47
follow-up from previous question...
if the lifeti
Ami GONE FROM CHROMIUM
2011/06/28 00:06:35
Done.
| |
23 } | 31 } |
24 | 32 |
25 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() {} | 33 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() {} |
scherkus (not reviewing)
2011/06/27 22:54:47
is it possible to get deleted w/ deferred_messages
Ami GONE FROM CHROMIUM
2011/06/28 00:06:35
In the glorious future when the BUG is fixed, it w
| |
26 | 34 |
35 // Return true iff |value| is in [min..max), accounting for (up to) one | |
36 // wrap-around. | |
37 static bool CheckInRangeWithWrap(int32 min, int32 max, int32 value) { | |
38 DCHECK_GE(min, 0); | |
39 DCHECK_GE(max, 0); | |
40 if (min <= max) { | |
41 // value should be in [min .. max) | |
42 return (value >= min) && (value < max); | |
43 } else { | |
44 // value should be in [0 .. max) or [min .. wrap value) | |
45 return (value >= min) || (value < max); | |
46 } | |
47 } | |
48 | |
49 void GpuVideoDecodeAccelerator::OnSetToken(int32 token) { | |
50 // Note: this always retries all deferred messages on every token arrival. | |
scherkus (not reviewing)
2011/06/27 22:54:47
s/Note/TODO ?
Ami GONE FROM CHROMIUM
2011/06/28 00:06:35
I'm not sure it's necessary, which is why I didn't
| |
51 // There's an optimization to be done here by only trying messages which are | |
52 // waiting for tokens which are earlier than |token|. | |
53 std::queue<IPC::Message*> deferred_messages_copy; | |
54 std::swap(deferred_messages_copy, deferred_messages_); | |
55 while (!deferred_messages_copy.empty()) { | |
56 scoped_ptr<IPC::Message> message(deferred_messages_copy.front()); | |
57 deferred_messages_copy.pop(); | |
58 OnMessageReceived(*message); | |
59 } | |
60 } | |
61 | |
62 bool GpuVideoDecodeAccelerator::DeferMessageIfNeeded( | |
63 const IPC::Message& msg, bool* deferred) { | |
64 // Only consider deferring for message types that need it. | |
65 switch (msg.type()) { | |
66 case AcceleratedVideoDecoderMsg_GetConfigs::ID: | |
67 case AcceleratedVideoDecoderMsg_Initialize::ID: | |
68 case AcceleratedVideoDecoderMsg_Decode::ID: | |
69 case AcceleratedVideoDecoderMsg_AssignTextures::ID: | |
70 case AcceleratedVideoDecoderMsg_AssignSysmemBuffers::ID: | |
71 case AcceleratedVideoDecoderMsg_ReusePictureBuffer::ID: | |
72 case AcceleratedVideoDecoderMsg_Flush::ID: | |
73 case AcceleratedVideoDecoderMsg_Abort::ID: | |
74 break; | |
75 default: | |
76 return false; | |
77 } | |
78 | |
79 std::pair<int32, int32> tokens; | |
80 void* iter = NULL; | |
81 if (!IPC::ParamTraits<std::pair<int32, int32> >::Read(&msg, &iter, &tokens)) | |
82 return false; | |
83 if (CheckInRangeWithWrap(tokens.first, tokens.second, stub_->token())) { | |
84 deferred_messages_.push(new IPC::Message(msg)); | |
85 *deferred = true; | |
86 } else { | |
87 *deferred = false; | |
88 } | |
89 return true; | |
90 } | |
91 | |
27 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { | 92 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { |
93 bool deferred = false; | |
94 if (!DeferMessageIfNeeded(msg, &deferred)) | |
95 return false; | |
96 if (deferred) | |
97 return true; | |
98 | |
28 bool handled = true; | 99 bool handled = true; |
29 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) | 100 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) |
30 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_GetConfigs, OnGetConfigs) | 101 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_GetConfigs, OnGetConfigs) |
31 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Initialize, OnInitialize) | 102 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Initialize, OnInitialize) |
32 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode) | 103 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode) |
104 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignTextures, | |
105 OnAssignTextures) | |
33 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignSysmemBuffers, | 106 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignSysmemBuffers, |
34 OnAssignSysmemBuffers) | 107 OnAssignSysmemBuffers) |
35 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer, | 108 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer, |
36 OnReusePictureBuffer) | 109 OnReusePictureBuffer) |
37 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush) | 110 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush) |
38 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Abort, OnAbort) | 111 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Abort, OnAbort) |
39 IPC_MESSAGE_UNHANDLED(handled = false) | 112 IPC_MESSAGE_UNHANDLED(handled = false) |
40 IPC_END_MESSAGE_MAP() | 113 IPC_END_MESSAGE_MAP() |
41 return handled; | 114 return handled; |
42 } | 115 } |
43 | 116 |
44 void GpuVideoDecodeAccelerator::OnChannelConnected(int32 peer_pid) { | 117 void GpuVideoDecodeAccelerator::OnChannelConnected(int32 peer_pid) { |
45 // TODO(vmr): Do we have to react on channel connections? | 118 // TODO(vmr): Do we have to react on channel connections? |
46 } | 119 } |
47 | 120 |
48 void GpuVideoDecodeAccelerator::OnChannelError() { | 121 void GpuVideoDecodeAccelerator::OnChannelError() { |
49 // TODO(vmr): Do we have to react on channel errors? | 122 // TODO(vmr): Do we have to react on channel errors? |
50 } | 123 } |
51 | 124 |
52 void GpuVideoDecodeAccelerator::ProvidePictureBuffers( | 125 void GpuVideoDecodeAccelerator::ProvidePictureBuffers( |
53 uint32 requested_num_of_buffers, | 126 uint32 requested_num_of_buffers, |
54 const gfx::Size& dimensions, | 127 const gfx::Size& dimensions, |
55 media::VideoDecodeAccelerator::MemoryType type) { | 128 media::VideoDecodeAccelerator::MemoryType type) { |
56 if (!Send(new AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers( | 129 if (!Send(new AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers( |
57 route_id_, requested_num_of_buffers, dimensions, type))) { | 130 host_route_id_, requested_num_of_buffers, dimensions, type))) { |
58 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers) " | 131 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers) " |
59 << "failed"; | 132 << "failed"; |
60 } | 133 } |
61 } | 134 } |
62 | 135 |
63 void GpuVideoDecodeAccelerator::DismissPictureBuffer( | 136 void GpuVideoDecodeAccelerator::DismissPictureBuffer( |
64 int32 picture_buffer_id) { | 137 int32 picture_buffer_id) { |
65 // Notify client that picture buffer is now unused. | 138 // Notify client that picture buffer is now unused. |
66 if (!Send(new AcceleratedVideoDecoderHostMsg_DismissPictureBuffer( | 139 if (!Send(new AcceleratedVideoDecoderHostMsg_DismissPictureBuffer( |
67 route_id_, picture_buffer_id))) { | 140 host_route_id_, picture_buffer_id))) { |
68 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer) " | 141 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer) " |
69 << "failed"; | 142 << "failed"; |
70 } | 143 } |
71 } | 144 } |
72 | 145 |
73 void GpuVideoDecodeAccelerator::PictureReady( | 146 void GpuVideoDecodeAccelerator::PictureReady( |
74 const media::Picture& picture) { | 147 const media::Picture& picture) { |
75 if (!Send(new AcceleratedVideoDecoderHostMsg_PictureReady( | 148 if (!Send(new AcceleratedVideoDecoderHostMsg_PictureReady( |
76 route_id_, | 149 host_route_id_, |
77 picture.picture_buffer_id(), | 150 picture.picture_buffer_id(), |
78 picture.bitstream_buffer_id(), | 151 picture.bitstream_buffer_id(), |
79 picture.visible_size(), | 152 picture.visible_size(), |
80 picture.decoded_size()))) { | 153 picture.decoded_size()))) { |
81 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_PictureReady) failed"; | 154 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_PictureReady) failed"; |
82 } | 155 } |
83 } | 156 } |
84 | 157 |
85 void GpuVideoDecodeAccelerator::NotifyEndOfStream() { | 158 void GpuVideoDecodeAccelerator::NotifyEndOfStream() { |
86 Send(new AcceleratedVideoDecoderHostMsg_EndOfStream(route_id_)); | 159 Send(new AcceleratedVideoDecoderHostMsg_EndOfStream(host_route_id_)); |
87 } | 160 } |
88 | 161 |
89 void GpuVideoDecodeAccelerator::NotifyError( | 162 void GpuVideoDecodeAccelerator::NotifyError( |
90 media::VideoDecodeAccelerator::Error error) { | 163 media::VideoDecodeAccelerator::Error error) { |
91 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification( | 164 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification( |
92 route_id_, error))) { | 165 host_route_id_, error))) { |
93 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) " | 166 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) " |
94 << "failed"; | 167 << "failed"; |
95 } | 168 } |
96 } | 169 } |
97 | 170 |
98 void GpuVideoDecodeAccelerator::OnGetConfigs( | 171 void GpuVideoDecodeAccelerator::OnGetConfigs( |
172 const std::pair<int32, int32>& /* tokens */, | |
99 const std::vector<uint32>& requested, std::vector<uint32>* matched) { | 173 const std::vector<uint32>& requested, std::vector<uint32>* matched) { |
174 // TODO(fischman,vrk): this is borked; can't have a VDA before calling | |
175 // Initialize, but can't call Initialize until we have some configs! | |
100 if (!video_decode_accelerator_.get()) | 176 if (!video_decode_accelerator_.get()) |
101 return; | 177 return; |
102 video_decode_accelerator_->GetConfigs(requested, matched); | 178 video_decode_accelerator_->GetConfigs(requested, matched); |
103 } | 179 } |
104 | 180 |
105 void GpuVideoDecodeAccelerator::OnInitialize( | 181 void GpuVideoDecodeAccelerator::OnInitialize( |
182 const std::pair<int32, int32>& /* tokens */, | |
106 const std::vector<uint32>& configs) { | 183 const std::vector<uint32>& configs) { |
107 if (!video_decode_accelerator_.get()) | 184 DCHECK(!video_decode_accelerator_.get()); |
108 return; | 185 GpuVideoService::GetInstance()->InitializeVideoDecoder(decoder_route_id_); |
scherkus (not reviewing)
2011/06/27 22:54:47
this call ends up setting video_decode_accelerator
Ami GONE FROM CHROMIUM
2011/06/28 00:06:35
Yes; see the "wonky" comment below.
| |
109 | 186 DCHECK(video_decode_accelerator_.get()); |
110 video_decode_accelerator_->Initialize(configs); | 187 video_decode_accelerator_->Initialize(configs); |
111 } | 188 } |
112 | 189 |
113 void GpuVideoDecodeAccelerator::OnDecode(int32 id, | 190 void GpuVideoDecodeAccelerator::OnDecode( |
114 base::SharedMemoryHandle handle, | 191 const std::pair<int32, int32>&, /* tokens */ |
115 int32 size) { | 192 base::SharedMemoryHandle handle, int32 id, int32 size) { |
116 if (!video_decode_accelerator_.get()) | 193 DCHECK(video_decode_accelerator_.get()); |
scherkus (not reviewing)
2011/06/27 22:54:47
nit: some people are in the camp that DCHECK'ing a
Ami GONE FROM CHROMIUM
2011/06/28 00:06:35
I use it for at least 50% documentation/comment va
| |
117 return; | |
118 video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size)); | 194 video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size)); |
119 } | 195 } |
120 | 196 |
121 void GpuVideoDecodeAccelerator::AssignGLESBuffers( | 197 void GpuVideoDecodeAccelerator::AssignGLESBuffers( |
122 const std::vector<media::GLESBuffer>& buffers) { | 198 const std::vector<media::GLESBuffer>& buffers) { |
123 if (!video_decode_accelerator_.get()) | 199 // TODO(fischman,vrk): it's wonky that we handle the AssignTextures message by |
124 return; | 200 // handing its contents to GpuVideoService which then turns around and calls |
201 // this (public) method. Instead we should make GpuVideoService vend the | |
202 // translation method we need and use it directly. | |
203 DCHECK(video_decode_accelerator_.get()); | |
125 video_decode_accelerator_->AssignGLESBuffers(buffers); | 204 video_decode_accelerator_->AssignGLESBuffers(buffers); |
126 } | 205 } |
127 | 206 |
207 void GpuVideoDecodeAccelerator::OnAssignTextures( | |
208 const std::pair<int32, int32>& /* tokens */, | |
209 const std::vector<int32>& buffer_ids, | |
210 const std::vector<uint32>& texture_ids, | |
211 const std::vector<gfx::Size>& sizes) { | |
212 GpuVideoService* service = GpuVideoService::GetInstance(); | |
213 service->AssignTexturesToDecoder( | |
214 decoder_route_id_, buffer_ids, texture_ids, sizes); | |
215 } | |
216 | |
128 void GpuVideoDecodeAccelerator::OnAssignSysmemBuffers( | 217 void GpuVideoDecodeAccelerator::OnAssignSysmemBuffers( |
129 const std::vector<int32>& buffer_ids, | 218 const std::pair<int32, int32>& /* tokens */, |
130 const std::vector<base::SharedMemoryHandle>& data, | 219 const std::vector<int32> buffer_ids, |
131 const std::vector<gfx::Size>& sizes) { | 220 const std::vector<base::SharedMemoryHandle> data, |
221 const std::vector<gfx::Size> sizes) { | |
132 // TODO(vrk): Implement. | 222 // TODO(vrk): Implement. |
133 NOTIMPLEMENTED(); | 223 NOTIMPLEMENTED(); |
134 } | 224 } |
135 | 225 |
136 void GpuVideoDecodeAccelerator::OnReusePictureBuffer(int32 picture_buffer_id) { | 226 void GpuVideoDecodeAccelerator::OnReusePictureBuffer( |
137 if (!video_decode_accelerator_.get()) | 227 const std::pair<int32, int32>& /* tokens */, |
138 return; | 228 int32 picture_buffer_id) { |
139 | 229 DCHECK(video_decode_accelerator_.get()); |
140 video_decode_accelerator_->ReusePictureBuffer(picture_buffer_id); | 230 video_decode_accelerator_->ReusePictureBuffer(picture_buffer_id); |
141 } | 231 } |
142 | 232 |
143 void GpuVideoDecodeAccelerator::OnFlush() { | 233 void GpuVideoDecodeAccelerator::OnFlush( |
144 if (!video_decode_accelerator_.get()) | 234 const std::pair<int32, int32>& /* tokens */) { |
145 return; | 235 DCHECK(video_decode_accelerator_.get()); |
146 | 236 video_decode_accelerator_->Flush(); |
147 if (!video_decode_accelerator_->Flush()) { | |
148 NotifyError( | |
149 media::VideoDecodeAccelerator::VIDEODECODERERROR_UNEXPECTED_FLUSH); | |
150 } | |
151 } | 237 } |
152 | 238 |
153 void GpuVideoDecodeAccelerator::OnAbort() { | 239 void GpuVideoDecodeAccelerator::OnAbort( |
154 if (!video_decode_accelerator_.get()) | 240 const std::pair<int32, int32>& /* tokens */) { |
155 return; | 241 DCHECK(video_decode_accelerator_.get()); |
156 | |
157 video_decode_accelerator_->Abort(); | 242 video_decode_accelerator_->Abort(); |
158 } | 243 } |
159 | 244 |
160 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer( | 245 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer( |
161 int32 bitstream_buffer_id) { | 246 int32 bitstream_buffer_id) { |
162 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed( | 247 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed( |
163 route_id_, bitstream_buffer_id))) { | 248 host_route_id_, bitstream_buffer_id))) { |
164 DLOG(ERROR) | 249 DLOG(ERROR) |
165 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) " | 250 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) " |
166 << "failed"; | 251 << "failed"; |
167 } | 252 } |
168 } | 253 } |
169 | 254 |
170 void GpuVideoDecodeAccelerator::NotifyInitializeDone() { | 255 void GpuVideoDecodeAccelerator::NotifyInitializeDone() { |
171 if (!Send(new AcceleratedVideoDecoderHostMsg_InitializeDone(route_id_))) | 256 if (!Send(new AcceleratedVideoDecoderHostMsg_InitializeDone(host_route_id_))) |
172 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_InitializeDone) failed"; | 257 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_InitializeDone) failed"; |
173 } | 258 } |
174 | 259 |
175 void GpuVideoDecodeAccelerator::NotifyFlushDone() { | 260 void GpuVideoDecodeAccelerator::NotifyFlushDone() { |
176 if (!Send(new AcceleratedVideoDecoderHostMsg_FlushDone(route_id_))) | 261 if (!Send(new AcceleratedVideoDecoderHostMsg_FlushDone(host_route_id_))) |
177 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed"; | 262 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed"; |
178 } | 263 } |
179 | 264 |
180 void GpuVideoDecodeAccelerator::NotifyAbortDone() { | 265 void GpuVideoDecodeAccelerator::NotifyAbortDone() { |
181 if (!Send(new AcceleratedVideoDecoderHostMsg_AbortDone(route_id_))) | 266 if (!Send(new AcceleratedVideoDecoderHostMsg_AbortDone(host_route_id_))) |
182 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_AbortDone) failed"; | 267 LOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_AbortDone) failed"; |
183 } | 268 } |
184 | 269 |
185 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { | 270 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { |
186 DCHECK(sender_); | 271 DCHECK(sender_); |
187 return sender_->Send(message); | 272 return sender_->Send(message); |
188 } | 273 } |
OLD | NEW |