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/renderer/gpu/gpu_video_decode_accelerator_host.h" | 5 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
11 #include "content/common/gpu/gpu_messages.h" | 11 #include "content/common/gpu/gpu_messages.h" |
12 #include "content/common/view_messages.h" | 12 #include "content/common/view_messages.h" |
| 13 #include "content/renderer/gpu/gpu_channel_host.h" |
13 #include "content/renderer/render_thread.h" | 14 #include "content/renderer/render_thread.h" |
14 #include "ipc/ipc_message_macros.h" | 15 #include "ipc/ipc_message_macros.h" |
15 #include "ipc/ipc_message_utils.h" | 16 #include "ipc/ipc_message_utils.h" |
16 | 17 |
17 using media::VideoDecodeAccelerator; | 18 using media::VideoDecodeAccelerator; |
18 | 19 |
19 GpuVideoDecodeAcceleratorHost::GpuVideoDecodeAcceleratorHost( | 20 GpuVideoDecodeAcceleratorHost::GpuVideoDecodeAcceleratorHost( |
20 IPC::Message::Sender* ipc_sender, | 21 GpuChannelHost* channel, |
21 int32 command_buffer_route_id, | 22 int32 decoder_route_id, |
22 VideoDecodeAccelerator::Client* client) | 23 VideoDecodeAccelerator::Client* client) |
23 : ipc_sender_(ipc_sender), | 24 : channel_(channel), |
24 command_buffer_route_id_(command_buffer_route_id), | 25 decoder_route_id_(decoder_route_id), |
25 client_(client) { | 26 client_(client) { |
26 DCHECK(ipc_sender_); | 27 DCHECK(channel_); |
27 DCHECK(client_); | 28 DCHECK(client_); |
28 DCHECK(RenderThread::current()); | 29 DCHECK(RenderThread::current()); |
29 DCHECK_EQ(RenderThread::current()->message_loop(), MessageLoop::current()); | 30 DCHECK_EQ(RenderThread::current()->message_loop(), MessageLoop::current()); |
30 } | 31 } |
31 | 32 |
32 GpuVideoDecodeAcceleratorHost::~GpuVideoDecodeAcceleratorHost() {} | 33 GpuVideoDecodeAcceleratorHost::~GpuVideoDecodeAcceleratorHost() {} |
33 | 34 |
34 void GpuVideoDecodeAcceleratorHost::OnChannelError() { | 35 void GpuVideoDecodeAcceleratorHost::OnChannelError() { |
35 ipc_sender_ = NULL; | 36 channel_ = NULL; |
36 } | 37 } |
37 | 38 |
38 bool GpuVideoDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { | 39 bool GpuVideoDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { |
39 DCHECK(CalledOnValidThread()); | 40 DCHECK(CalledOnValidThread()); |
40 bool handled = true; | 41 bool handled = true; |
41 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAcceleratorHost, msg) | 42 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAcceleratorHost, msg) |
42 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed, | 43 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed, |
43 OnBitstreamBufferProcessed) | 44 OnBitstreamBufferProcessed) |
44 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers, | 45 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers, |
45 OnProvidePictureBuffer) | 46 OnProvidePictureBuffer) |
(...skipping 16 matching lines...) Expand all Loading... |
62 bool GpuVideoDecodeAcceleratorHost::Initialize( | 63 bool GpuVideoDecodeAcceleratorHost::Initialize( |
63 const std::vector<int32>& configs) { | 64 const std::vector<int32>& configs) { |
64 NOTREACHED(); | 65 NOTREACHED(); |
65 return true; | 66 return true; |
66 } | 67 } |
67 | 68 |
68 void GpuVideoDecodeAcceleratorHost::Decode( | 69 void GpuVideoDecodeAcceleratorHost::Decode( |
69 const media::BitstreamBuffer& bitstream_buffer) { | 70 const media::BitstreamBuffer& bitstream_buffer) { |
70 DCHECK(CalledOnValidThread()); | 71 DCHECK(CalledOnValidThread()); |
71 Send(new AcceleratedVideoDecoderMsg_Decode( | 72 Send(new AcceleratedVideoDecoderMsg_Decode( |
72 command_buffer_route_id_, bitstream_buffer.handle(), | 73 decoder_route_id_, bitstream_buffer.handle(), |
73 bitstream_buffer.id(), bitstream_buffer.size())); | 74 bitstream_buffer.id(), bitstream_buffer.size())); |
74 } | 75 } |
75 | 76 |
76 void GpuVideoDecodeAcceleratorHost::AssignPictureBuffers( | 77 void GpuVideoDecodeAcceleratorHost::AssignPictureBuffers( |
77 const std::vector<media::PictureBuffer>& buffers) { | 78 const std::vector<media::PictureBuffer>& buffers) { |
78 DCHECK(CalledOnValidThread()); | 79 DCHECK(CalledOnValidThread()); |
79 // Rearrange data for IPC command. | 80 // Rearrange data for IPC command. |
80 std::vector<int32> buffer_ids; | 81 std::vector<int32> buffer_ids; |
81 std::vector<uint32> texture_ids; | 82 std::vector<uint32> texture_ids; |
82 std::vector<gfx::Size> sizes; | 83 std::vector<gfx::Size> sizes; |
83 for (uint32 i = 0; i < buffers.size(); i++) { | 84 for (uint32 i = 0; i < buffers.size(); i++) { |
84 const media::PictureBuffer& buffer = buffers[i]; | 85 const media::PictureBuffer& buffer = buffers[i]; |
85 texture_ids.push_back(buffer.texture_id()); | 86 texture_ids.push_back(buffer.texture_id()); |
86 buffer_ids.push_back(buffer.id()); | 87 buffer_ids.push_back(buffer.id()); |
87 sizes.push_back(buffer.size()); | 88 sizes.push_back(buffer.size()); |
88 } | 89 } |
89 Send(new AcceleratedVideoDecoderMsg_AssignPictureBuffers( | 90 Send(new AcceleratedVideoDecoderMsg_AssignPictureBuffers( |
90 command_buffer_route_id_, buffer_ids, texture_ids, sizes)); | 91 decoder_route_id_, buffer_ids, texture_ids, sizes)); |
91 } | 92 } |
92 | 93 |
93 void GpuVideoDecodeAcceleratorHost::ReusePictureBuffer( | 94 void GpuVideoDecodeAcceleratorHost::ReusePictureBuffer( |
94 int32 picture_buffer_id) { | 95 int32 picture_buffer_id) { |
95 DCHECK(CalledOnValidThread()); | 96 DCHECK(CalledOnValidThread()); |
96 Send(new AcceleratedVideoDecoderMsg_ReusePictureBuffer( | 97 Send(new AcceleratedVideoDecoderMsg_ReusePictureBuffer( |
97 command_buffer_route_id_, picture_buffer_id)); | 98 decoder_route_id_, picture_buffer_id)); |
98 } | 99 } |
99 | 100 |
100 void GpuVideoDecodeAcceleratorHost::Flush() { | 101 void GpuVideoDecodeAcceleratorHost::Flush() { |
101 DCHECK(CalledOnValidThread()); | 102 DCHECK(CalledOnValidThread()); |
102 Send(new AcceleratedVideoDecoderMsg_Flush(command_buffer_route_id_)); | 103 Send(new AcceleratedVideoDecoderMsg_Flush(decoder_route_id_)); |
103 } | 104 } |
104 | 105 |
105 void GpuVideoDecodeAcceleratorHost::Reset() { | 106 void GpuVideoDecodeAcceleratorHost::Reset() { |
106 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
107 Send(new AcceleratedVideoDecoderMsg_Reset(command_buffer_route_id_)); | 108 Send(new AcceleratedVideoDecoderMsg_Reset(decoder_route_id_)); |
108 } | 109 } |
109 | 110 |
110 void GpuVideoDecodeAcceleratorHost::Destroy() { | 111 void GpuVideoDecodeAcceleratorHost::Destroy() { |
111 DCHECK(CalledOnValidThread()); | 112 DCHECK(CalledOnValidThread()); |
112 Send(new AcceleratedVideoDecoderMsg_Destroy(command_buffer_route_id_)); | 113 channel_->RemoveRoute(decoder_route_id_); |
113 client_ = NULL; | 114 client_ = NULL; |
| 115 Send(new AcceleratedVideoDecoderMsg_Destroy(decoder_route_id_)); |
114 } | 116 } |
115 | 117 |
116 void GpuVideoDecodeAcceleratorHost::Send(IPC::Message* message) { | 118 void GpuVideoDecodeAcceleratorHost::Send(IPC::Message* message) { |
117 // After OnChannelError is called, the client should no longer send | 119 // After OnChannelError is called, the client should no longer send |
118 // messages to the gpu channel through this object. | 120 // messages to the gpu channel through this object. |
119 DCHECK(ipc_sender_); | 121 DCHECK(channel_); |
120 if (!ipc_sender_ || !ipc_sender_->Send(message)) { | 122 if (!channel_ || !channel_->Send(message)) { |
121 DLOG(ERROR) << "Send(" << message->type() << ") failed"; | 123 DLOG(ERROR) << "Send(" << message->type() << ") failed"; |
122 OnErrorNotification(PLATFORM_FAILURE); | 124 OnErrorNotification(PLATFORM_FAILURE); |
123 } | 125 } |
124 } | 126 } |
125 | 127 |
126 void GpuVideoDecodeAcceleratorHost::OnBitstreamBufferProcessed( | 128 void GpuVideoDecodeAcceleratorHost::OnBitstreamBufferProcessed( |
127 int32 bitstream_buffer_id) { | 129 int32 bitstream_buffer_id) { |
128 DCHECK(CalledOnValidThread()); | 130 DCHECK(CalledOnValidThread()); |
129 if (client_) | 131 if (client_) |
130 client_->NotifyEndOfBitstreamBuffer(bitstream_buffer_id); | 132 client_->NotifyEndOfBitstreamBuffer(bitstream_buffer_id); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 client_->NotifyEndOfStream(); | 174 client_->NotifyEndOfStream(); |
173 } | 175 } |
174 | 176 |
175 void GpuVideoDecodeAcceleratorHost::OnErrorNotification(uint32 error) { | 177 void GpuVideoDecodeAcceleratorHost::OnErrorNotification(uint32 error) { |
176 DCHECK(CalledOnValidThread()); | 178 DCHECK(CalledOnValidThread()); |
177 if (!client_) | 179 if (!client_) |
178 return; | 180 return; |
179 client_->NotifyError( | 181 client_->NotifyError( |
180 static_cast<media::VideoDecodeAccelerator::Error>(error)); | 182 static_cast<media::VideoDecodeAccelerator::Error>(error)); |
181 } | 183 } |
OLD | NEW |