| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/gpu/media/gpu_video_service.h" | |
| 6 | |
| 7 #include "content/common/gpu/gpu_channel.h" | |
| 8 #include "content/common/gpu/gpu_messages.h" | |
| 9 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" | |
| 10 | |
| 11 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | |
| 12 #include "content/common/gpu/media/omx_video_decode_accelerator.h" | |
| 13 #include "ui/gfx/gl/gl_surface_egl.h" | |
| 14 #endif // defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | |
| 15 | |
| 16 GpuVideoService::GpuVideoService() { | |
| 17 // TODO(jiesun): move this time consuming stuff out of here. | |
| 18 IntializeGpuVideoService(); | |
| 19 } | |
| 20 | |
| 21 GpuVideoService::~GpuVideoService() { | |
| 22 // TODO(jiesun): move this time consuming stuff out of here. | |
| 23 UnintializeGpuVideoService(); | |
| 24 } | |
| 25 | |
| 26 // static | |
| 27 GpuVideoService* GpuVideoService::GetInstance() { | |
| 28 return Singleton<GpuVideoService>::get(); | |
| 29 } | |
| 30 | |
| 31 void GpuVideoService::OnChannelConnected(int32 peer_pid) { | |
| 32 LOG(ERROR) << "GpuVideoService::OnChannelConnected"; | |
| 33 } | |
| 34 | |
| 35 void GpuVideoService::OnChannelError() { | |
| 36 LOG(ERROR) << "GpuVideoService::OnChannelError"; | |
| 37 } | |
| 38 | |
| 39 bool GpuVideoService::OnMessageReceived(const IPC::Message& msg) { | |
| 40 #if 0 | |
| 41 IPC_BEGIN_MESSAGE_MAP(GpuVideoService, msg) | |
| 42 IPC_MESSAGE_UNHANDLED_ERROR() | |
| 43 IPC_END_MESSAGE_MAP() | |
| 44 #endif | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 bool GpuVideoService::IntializeGpuVideoService() { | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 bool GpuVideoService::UnintializeGpuVideoService() { | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 56 bool GpuVideoService::CreateVideoDecoder( | |
| 57 GpuChannel* channel, | |
| 58 MessageRouter* router, | |
| 59 int32 decoder_host_id, | |
| 60 int32 decoder_id, | |
| 61 GpuCommandBufferStub* stub, | |
| 62 const std::vector<uint32>& configs) { | |
| 63 // Create GpuVideoDecodeAccelerator and add to map. | |
| 64 scoped_refptr<GpuVideoDecodeAccelerator> decoder = | |
| 65 new GpuVideoDecodeAccelerator(channel, decoder_host_id, decoder_id, stub); | |
| 66 | |
| 67 bool result = decoder_map_.insert(std::make_pair( | |
| 68 decoder_id, VideoDecoderInfo(decoder, stub))).second; | |
| 69 | |
| 70 // Decoder ID is a unique ID determined by GpuVideoServiceHost. | |
| 71 // We should always be adding entries here. | |
| 72 DCHECK(result); | |
| 73 | |
| 74 router->AddRoute(decoder_id, decoder); | |
| 75 | |
| 76 // Tell client that initialization is complete. | |
| 77 channel->Send( | |
| 78 new AcceleratedVideoDecoderHostMsg_CreateDone( | |
| 79 decoder_host_id, decoder_id)); | |
| 80 | |
| 81 return true; | |
| 82 } | |
| 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 | |
| 102 void GpuVideoService::DestroyVideoDecoder( | |
| 103 MessageRouter* router, | |
| 104 int32 decoder_id) { | |
| 105 router->RemoveRoute(decoder_id); | |
| 106 decoder_map_.erase(decoder_id); | |
| 107 } | |
| 108 | |
| 109 void GpuVideoService::AssignTexturesToDecoder( | |
| 110 int32 decoder_id, | |
| 111 const std::vector<int32>& buffer_ids, | |
| 112 const std::vector<uint32>& texture_ids, | |
| 113 const std::vector<gfx::Size>& sizes) { | |
| 114 DecoderMap::iterator it = decoder_map_.find(decoder_id); | |
| 115 DCHECK(it != decoder_map_.end()); | |
| 116 DCHECK_EQ(it->first, decoder_id); | |
| 117 GpuVideoDecodeAccelerator* video_decoder = it->second.video_decoder; | |
| 118 DCHECK(it->second.stub->scheduler()); // Ensure already Initialize()'d. | |
| 119 gpu::gles2::GLES2Decoder* command_decoder = | |
| 120 it->second.stub->scheduler()->decoder(); | |
| 121 | |
| 122 std::vector<media::GLESBuffer> buffers; | |
| 123 for (uint32 i = 0; i < buffer_ids.size(); ++i) { | |
| 124 uint32 service_texture_id; | |
| 125 if (!command_decoder->GetServiceTextureId( | |
| 126 texture_ids[i], &service_texture_id)) { | |
| 127 // TODO(vrk): Send an error for invalid GLES buffers. | |
| 128 LOG(DFATAL) << "Failed to translate texture!"; | |
| 129 return; | |
| 130 } | |
| 131 buffers.push_back(media::GLESBuffer( | |
| 132 buffer_ids[i], sizes[i], service_texture_id)); | |
| 133 } | |
| 134 video_decoder->AssignGLESBuffers(buffers); | |
| 135 } | |
| OLD | NEW |