OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/gl_surface_encoder.h" | 5 #include "content/common/gpu/gl_surface_encoder.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "content/common/gpu/gpu_channel.h" | 10 #include "content/common/gpu/gpu_channel.h" |
11 #include "content/common/gpu/gpu_messages.h" | 11 #include "content/common/gpu/gpu_messages.h" |
12 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
13 #include "ui/gl/gl_surface.h" | 13 #include "ui/gl/gl_surface.h" |
14 | 14 |
| 15 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 16 #include "content/common/gpu/media/exynos_video_encode_accelerator.h" |
| 17 #include "ui/gl/gl_surface_egl.h" |
| 18 #endif |
| 19 |
15 namespace content { | 20 namespace content { |
16 | 21 |
17 namespace { | 22 static bool MakeEncoderContextCurrent( |
| 23 const base::WeakPtr<GpuCommandBufferStub> stub) { |
| 24 if (!stub) { |
| 25 DLOG(ERROR) << "Stub is gone; won't MakeCurrent()."; |
| 26 return false; |
| 27 } |
18 | 28 |
19 void DoNothingWithSurface(gfx::GLSurface* surface) { | 29 if (!stub->decoder()->MakeCurrent()) { |
| 30 DLOG(ERROR) << "Failed to MakeCurrent()"; |
| 31 return false; |
| 32 } |
| 33 |
| 34 return true; |
20 } | 35 } |
21 | 36 |
22 } // anonymous namespace | 37 static void DoNothingWithSurface(gfx::GLSurface* surface) { |
| 38 } |
23 | 39 |
24 GLSurfaceEncoder::GLSurfaceEncoder(int32 host_route_id, | 40 GLSurfaceEncoder::GLSurfaceEncoder(int32 host_route_id, |
25 GpuCommandBufferStub* stub) | 41 GpuCommandBufferStub* stub) |
26 : host_route_id_(host_route_id), | 42 : host_route_id_(host_route_id), |
27 stub_(stub) { | 43 stub_(stub) { |
28 DCHECK(stub_); | 44 DCHECK(stub_); |
29 stub_->AddDestructionObserver(this); | 45 stub_->AddDestructionObserver(this); |
30 stub_->channel()->AddRoute(host_route_id_, this); | 46 stub_->channel()->AddRoute(host_route_id_, this); |
31 encoder_ = CreateEncoder(stub_, this).Pass(); | 47 encoder_ = CreateEncoder(stub_, this).Pass(); |
32 } | 48 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 DCHECK(stub_); | 126 DCHECK(stub_); |
111 return stub_->channel()->Send(message); | 127 return stub_->channel()->Send(message); |
112 } | 128 } |
113 | 129 |
114 // static | 130 // static |
115 scoped_ptr<media::VideoEncodeAccelerator> GLSurfaceEncoder::CreateEncoder( | 131 scoped_ptr<media::VideoEncodeAccelerator> GLSurfaceEncoder::CreateEncoder( |
116 GpuCommandBufferStub* stub, | 132 GpuCommandBufferStub* stub, |
117 media::VideoEncodeAccelerator::Client* client) { | 133 media::VideoEncodeAccelerator::Client* client) { |
118 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 134 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
119 | 135 |
120 // TODO(sheu): actually create an encoder. | 136 base::Callback<bool(void)> make_current = |
| 137 base::Bind(&MakeEncoderContextCurrent, stub->AsWeakPtr()); |
| 138 |
| 139 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 140 encoder.reset(new ExynosVideoEncodeAccelerator( |
| 141 gfx::GLSurfaceEGL::GetHardwareDisplay(), |
| 142 client, |
| 143 make_current, |
| 144 true)); |
| 145 #endif |
| 146 |
121 return encoder.Pass(); | 147 return encoder.Pass(); |
122 } | 148 } |
123 | 149 |
124 void GLSurfaceEncoder::OnEncodeCurrentContents(bool force_keyframe) { | 150 void GLSurfaceEncoder::OnEncodeCurrentContents(bool force_keyframe) { |
125 gfx::GLSurface* surface = stub_->surface(); | 151 gfx::GLSurface* surface = stub_->surface(); |
126 scoped_refptr<media::VideoFrame> frame(media::VideoFrame::WrapNativeSurface( | 152 scoped_refptr<media::VideoFrame> frame(media::VideoFrame::WrapNativeSurface( |
127 surface->GetHandle(), | 153 surface->GetHandle(), |
128 surface->GetSize(), | 154 surface->GetSize(), |
129 base::Time::Now() - start_time_, | 155 base::Time::Now() - start_time_, |
130 base::Bind(&DoNothingWithSurface, make_scoped_refptr(surface)))); | 156 base::Bind(&DoNothingWithSurface, make_scoped_refptr(surface)))); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 void GLSurfaceEncoder::OnRequestEncodingParameterChange( | 190 void GLSurfaceEncoder::OnRequestEncodingParameterChange( |
165 int32 bitrate) { | 191 int32 bitrate) { |
166 encoder_->RequestEncodingParameterChange(bitrate); | 192 encoder_->RequestEncodingParameterChange(bitrate); |
167 } | 193 } |
168 | 194 |
169 void GLSurfaceEncoder::OnDestroy() { | 195 void GLSurfaceEncoder::OnDestroy() { |
170 delete this; | 196 delete this; |
171 } | 197 } |
172 | 198 |
173 } // namespace content | 199 } // namespace content |
OLD | NEW |