| 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_service.h" | 5 #include "content/common/gpu/media/gpu_video_service.h" |
| 6 | 6 |
| 7 #include "content/common/gpu/gpu_channel.h" | 7 #include "content/common/gpu/gpu_channel.h" |
| 8 #include "content/common/gpu/gpu_messages.h" | 8 #include "content/common/gpu/gpu_messages.h" |
| 9 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" | 9 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
| 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | |
| 11 | 10 |
| 12 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 11 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 13 #include "content/common/gpu/media/omx_video_decode_accelerator.h" | 12 #include "content/common/gpu/media/omx_video_decode_accelerator.h" |
| 14 #include "ui/gfx/gl/gl_surface_egl.h" | 13 #include "ui/gfx/gl/gl_surface_egl.h" |
| 15 #endif // defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | 14 #endif // defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 16 | 15 |
| 17 GpuVideoService::GpuVideoService() { | 16 GpuVideoService::GpuVideoService() { |
| 18 // TODO(jiesun): move this time consuming stuff out of here. | 17 // TODO(jiesun): move this time consuming stuff out of here. |
| 19 IntializeGpuVideoService(); | 18 IntializeGpuVideoService(); |
| 20 } | 19 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 51 |
| 53 bool GpuVideoService::UnintializeGpuVideoService() { | 52 bool GpuVideoService::UnintializeGpuVideoService() { |
| 54 return true; | 53 return true; |
| 55 } | 54 } |
| 56 | 55 |
| 57 bool GpuVideoService::CreateVideoDecoder( | 56 bool GpuVideoService::CreateVideoDecoder( |
| 58 GpuChannel* channel, | 57 GpuChannel* channel, |
| 59 MessageRouter* router, | 58 MessageRouter* router, |
| 60 int32 decoder_host_id, | 59 int32 decoder_host_id, |
| 61 int32 decoder_id, | 60 int32 decoder_id, |
| 62 gpu::gles2::GLES2Decoder* command_decoder, | 61 GpuCommandBufferStub* stub, |
| 63 const std::vector<uint32>& configs) { | 62 const std::vector<uint32>& configs) { |
| 64 // Create GpuVideoDecodeAccelerator and add to map. | 63 // Create GpuVideoDecodeAccelerator and add to map. |
| 65 scoped_refptr<GpuVideoDecodeAccelerator> decoder = | 64 scoped_refptr<GpuVideoDecodeAccelerator> decoder = |
| 66 new GpuVideoDecodeAccelerator(channel, decoder_host_id); | 65 new GpuVideoDecodeAccelerator(channel, decoder_host_id, decoder_id, stub); |
| 67 | |
| 68 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | |
| 69 OmxVideoDecodeAccelerator* omx_decoder = | |
| 70 new OmxVideoDecodeAccelerator(decoder, MessageLoop::current()); | |
| 71 omx_decoder->SetEglState(gfx::GLSurfaceEGL::GetDisplay(), | |
| 72 command_decoder->GetGLContext()->GetHandle()); | |
| 73 decoder->set_video_decode_accelerator(omx_decoder); | |
| 74 #endif // defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | |
| 75 | 66 |
| 76 bool result = decoder_map_.insert(std::make_pair( | 67 bool result = decoder_map_.insert(std::make_pair( |
| 77 decoder_id, VideoDecoderInfo(decoder, command_decoder))).second; | 68 decoder_id, VideoDecoderInfo(decoder, stub))).second; |
| 78 | 69 |
| 79 // Decoder ID is a unique ID determined by GpuVideoServiceHost. | 70 // Decoder ID is a unique ID determined by GpuVideoServiceHost. |
| 80 // We should always be adding entries here. | 71 // We should always be adding entries here. |
| 81 DCHECK(result); | 72 DCHECK(result); |
| 82 | 73 |
| 83 router->AddRoute(decoder_id, decoder); | 74 router->AddRoute(decoder_id, decoder); |
| 84 | 75 |
| 85 // Tell client that initialization is complete. | 76 // Tell client that initialization is complete. |
| 86 channel->Send( | 77 channel->Send( |
| 87 new AcceleratedVideoDecoderHostMsg_CreateDone( | 78 new AcceleratedVideoDecoderHostMsg_CreateDone( |
| 88 decoder_host_id, decoder_id)); | 79 decoder_host_id, decoder_id)); |
| 89 | 80 |
| 90 return true; | 81 return true; |
| 91 } | 82 } |
| 92 | 83 |
| 84 void GpuVideoService::InitializeVideoDecoder(int32 decoder_id) { |
| 85 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 86 DecoderMap::iterator it = decoder_map_.find(decoder_id); |
| 87 DCHECK(it != decoder_map_.end()); |
| 88 GpuVideoDecodeAccelerator* decoder = it->second.video_decoder.get(); |
| 89 GpuCommandBufferStub* stub = it->second.stub; |
| 90 DCHECK(stub->scheduler()); |
| 91 OmxVideoDecodeAccelerator* omx_decoder = |
| 92 new OmxVideoDecodeAccelerator(decoder, MessageLoop::current()); |
| 93 omx_decoder->SetEglState( |
| 94 gfx::GLSurfaceEGL::GetDisplay(), |
| 95 stub->scheduler()->decoder()->GetGLContext()->GetHandle()); |
| 96 decoder->set_video_decode_accelerator(omx_decoder); |
| 97 #else |
| 98 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| 99 #endif // defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 100 } |
| 101 |
| 93 void GpuVideoService::DestroyVideoDecoder( | 102 void GpuVideoService::DestroyVideoDecoder( |
| 94 MessageRouter* router, | 103 MessageRouter* router, |
| 95 int32 decoder_id) { | 104 int32 decoder_id) { |
| 96 router->RemoveRoute(decoder_id); | 105 router->RemoveRoute(decoder_id); |
| 97 decoder_map_.erase(decoder_id); | 106 decoder_map_.erase(decoder_id); |
| 98 } | 107 } |
| 99 | 108 |
| 100 void GpuVideoService::AssignTexturesToDecoder( | 109 void GpuVideoService::AssignTexturesToDecoder( |
| 101 int32 decoder_id, | 110 int32 decoder_id, |
| 102 const std::vector<int32>& buffer_ids, | 111 const std::vector<int32>& buffer_ids, |
| 103 const std::vector<uint32>& texture_ids, | 112 const std::vector<uint32>& texture_ids, |
| 104 const std::vector<gfx::Size>& sizes) { | 113 const std::vector<gfx::Size>& sizes) { |
| 105 DecoderMap::iterator it = decoder_map_.find(decoder_id); | 114 DecoderMap::iterator it = decoder_map_.find(decoder_id); |
| 106 DCHECK(it != decoder_map_.end()); | 115 DCHECK(it != decoder_map_.end()); |
| 107 DCHECK_EQ(it->first, decoder_id); | 116 DCHECK_EQ(it->first, decoder_id); |
| 108 GpuVideoDecodeAccelerator* video_decoder = it->second.video_decoder; | 117 GpuVideoDecodeAccelerator* video_decoder = it->second.video_decoder; |
| 109 gpu::gles2::GLES2Decoder* command_decoder = it->second.command_decoder; | 118 DCHECK(it->second.stub->scheduler()); // Ensure already Initialize()'d. |
| 119 gpu::gles2::GLES2Decoder* command_decoder = |
| 120 it->second.stub->scheduler()->decoder(); |
| 110 | 121 |
| 111 std::vector<media::GLESBuffer> buffers; | 122 std::vector<media::GLESBuffer> buffers; |
| 112 for (uint32 i = 0; i < buffer_ids.size(); ++i) { | 123 for (uint32 i = 0; i < buffer_ids.size(); ++i) { |
| 113 uint32 service_texture_id; | 124 uint32 service_texture_id; |
| 114 if (!command_decoder->GetServiceTextureId( | 125 if (!command_decoder->GetServiceTextureId( |
| 115 texture_ids[i], &service_texture_id)) { | 126 texture_ids[i], &service_texture_id)) { |
| 116 // TODO(vrk): Send an error for invalid GLES buffers. | 127 // TODO(vrk): Send an error for invalid GLES buffers. |
| 117 LOG(DFATAL) << "Failed to translate texture!"; | 128 LOG(DFATAL) << "Failed to translate texture!"; |
| 118 return; | 129 return; |
| 119 } | 130 } |
| 120 buffers.push_back(media::GLESBuffer( | 131 buffers.push_back(media::GLESBuffer( |
| 121 buffer_ids[i], sizes[i], service_texture_id)); | 132 buffer_ids[i], sizes[i], service_texture_id)); |
| 122 } | 133 } |
| 123 video_decoder->AssignGLESBuffers(buffers); | 134 video_decoder->AssignGLESBuffers(buffers); |
| 124 } | 135 } |
| OLD | NEW |