OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/fake_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/fake_video_decode_accelerator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 static const uint32_t kDefaultTextureTarget = GL_TEXTURE_2D; | 23 static const uint32_t kDefaultTextureTarget = GL_TEXTURE_2D; |
24 // Must be at least 2 since the rendering helper will switch between textures | 24 // Must be at least 2 since the rendering helper will switch between textures |
25 // and if there is only one, it will wait for the next one that will never come. | 25 // and if there is only one, it will wait for the next one that will never come. |
26 // Must also be an even number as otherwise there won't be the same amount of | 26 // Must also be an even number as otherwise there won't be the same amount of |
27 // white and black frames. | 27 // white and black frames. |
28 static const unsigned int kNumBuffers = media::limits::kMaxVideoFrames + | 28 static const unsigned int kNumBuffers = media::limits::kMaxVideoFrames + |
29 (media::limits::kMaxVideoFrames & 1u); | 29 (media::limits::kMaxVideoFrames & 1u); |
30 | 30 |
31 FakeVideoDecodeAccelerator::FakeVideoDecodeAccelerator( | 31 FakeVideoDecodeAccelerator::FakeVideoDecodeAccelerator( |
32 const gfx::Size& size, | 32 gfx::GLContext* gl, |
33 const MakeGLContextCurrentCallback& make_context_current_cb) | 33 gfx::Size size, |
| 34 const base::Callback<bool(void)>& make_context_current) |
34 : child_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 35 : child_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
35 client_(NULL), | 36 client_(NULL), |
36 make_context_current_cb_(make_context_current_cb), | 37 make_context_current_(make_context_current), |
| 38 gl_(gl), |
37 frame_buffer_size_(size), | 39 frame_buffer_size_(size), |
38 flushing_(false), | 40 flushing_(false), |
39 weak_this_factory_(this) {} | 41 weak_this_factory_(this) { |
| 42 } |
40 | 43 |
41 FakeVideoDecodeAccelerator::~FakeVideoDecodeAccelerator() { | 44 FakeVideoDecodeAccelerator::~FakeVideoDecodeAccelerator() { |
42 } | 45 } |
43 | 46 |
44 bool FakeVideoDecodeAccelerator::Initialize(const Config& config, | 47 bool FakeVideoDecodeAccelerator::Initialize(const Config& config, |
45 Client* client) { | 48 Client* client) { |
46 DCHECK(child_task_runner_->BelongsToCurrentThread()); | 49 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
47 if (config.profile == media::VIDEO_CODEC_PROFILE_UNKNOWN) { | 50 if (config.profile == media::VIDEO_CODEC_PROFILE_UNKNOWN) { |
48 LOG(ERROR) << "unknown codec profile"; | 51 LOG(ERROR) << "unknown codec profile"; |
49 return false; | 52 return false; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 4]); | 96 4]); |
94 memset(white_data.get(), | 97 memset(white_data.get(), |
95 UINT8_MAX, | 98 UINT8_MAX, |
96 frame_buffer_size_.width() * frame_buffer_size_.height() * 4); | 99 frame_buffer_size_.width() * frame_buffer_size_.height() * 4); |
97 scoped_ptr<uint8_t[]> black_data( | 100 scoped_ptr<uint8_t[]> black_data( |
98 new uint8_t[frame_buffer_size_.width() * frame_buffer_size_.height() * | 101 new uint8_t[frame_buffer_size_.width() * frame_buffer_size_.height() * |
99 4]); | 102 4]); |
100 memset(black_data.get(), | 103 memset(black_data.get(), |
101 0, | 104 0, |
102 frame_buffer_size_.width() * frame_buffer_size_.height() * 4); | 105 frame_buffer_size_.width() * frame_buffer_size_.height() * 4); |
103 if (!make_context_current_cb_.Run()) { | 106 if (!make_context_current_.Run()) { |
104 LOG(ERROR) << "ReusePictureBuffer(): could not make context current"; | 107 LOG(ERROR) << "ReusePictureBuffer(): could not make context current"; |
105 return; | 108 return; |
106 } | 109 } |
107 for (size_t index = 0; index < buffers.size(); ++index) { | 110 for (size_t index = 0; index < buffers.size(); ++index) { |
108 glBindTexture(GL_TEXTURE_2D, buffers[index].texture_id()); | 111 glBindTexture(GL_TEXTURE_2D, buffers[index].texture_id()); |
109 // Every other frame white and the rest black. | 112 // Every other frame white and the rest black. |
110 uint8_t* data = index % 2 ? white_data.get() : black_data.get(); | 113 uint8_t* data = index % 2 ? white_data.get() : black_data.get(); |
111 glTexImage2D(GL_TEXTURE_2D, | 114 glTexImage2D(GL_TEXTURE_2D, |
112 0, | 115 0, |
113 GL_RGBA, | 116 GL_RGBA, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 155 } |
153 | 156 |
154 void FakeVideoDecodeAccelerator::Destroy() { | 157 void FakeVideoDecodeAccelerator::Destroy() { |
155 while (!queued_bitstream_ids_.empty()) { | 158 while (!queued_bitstream_ids_.empty()) { |
156 client_->NotifyEndOfBitstreamBuffer(queued_bitstream_ids_.front()); | 159 client_->NotifyEndOfBitstreamBuffer(queued_bitstream_ids_.front()); |
157 queued_bitstream_ids_.pop(); | 160 queued_bitstream_ids_.pop(); |
158 } | 161 } |
159 delete this; | 162 delete this; |
160 } | 163 } |
161 | 164 |
162 bool FakeVideoDecodeAccelerator::TryToSetupDecodeOnSeparateThread( | 165 bool FakeVideoDecodeAccelerator::CanDecodeOnIOThread() { |
163 const base::WeakPtr<Client>& decode_client, | 166 return true; |
164 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) { | |
165 return false; | |
166 } | 167 } |
167 | 168 |
168 void FakeVideoDecodeAccelerator::DoPictureReady() { | 169 void FakeVideoDecodeAccelerator::DoPictureReady() { |
169 if (flushing_ && queued_bitstream_ids_.empty()) { | 170 if (flushing_ && queued_bitstream_ids_.empty()) { |
170 flushing_ = false; | 171 flushing_ = false; |
171 client_->NotifyFlushDone(); | 172 client_->NotifyFlushDone(); |
172 } | 173 } |
173 while (!free_output_buffers_.empty() && !queued_bitstream_ids_.empty()) { | 174 while (!free_output_buffers_.empty() && !queued_bitstream_ids_.empty()) { |
174 int bitstream_id = queued_bitstream_ids_.front(); | 175 int bitstream_id = queued_bitstream_ids_.front(); |
175 queued_bitstream_ids_.pop(); | 176 queued_bitstream_ids_.pop(); |
176 int buffer_id = free_output_buffers_.front(); | 177 int buffer_id = free_output_buffers_.front(); |
177 free_output_buffers_.pop(); | 178 free_output_buffers_.pop(); |
178 | 179 |
179 const media::Picture picture = | 180 const media::Picture picture = |
180 media::Picture(buffer_id, | 181 media::Picture(buffer_id, |
181 bitstream_id, | 182 bitstream_id, |
182 gfx::Rect(frame_buffer_size_), | 183 gfx::Rect(frame_buffer_size_), |
183 false); | 184 false); |
184 client_->PictureReady(picture); | 185 client_->PictureReady(picture); |
185 // Bitstream no longer needed. | 186 // Bitstream no longer needed. |
186 client_->NotifyEndOfBitstreamBuffer(bitstream_id); | 187 client_->NotifyEndOfBitstreamBuffer(bitstream_id); |
187 if (flushing_ && queued_bitstream_ids_.empty()) { | 188 if (flushing_ && queued_bitstream_ids_.empty()) { |
188 flushing_ = false; | 189 flushing_ = false; |
189 client_->NotifyFlushDone(); | 190 client_->NotifyFlushDone(); |
190 } | 191 } |
191 } | 192 } |
192 } | 193 } |
193 | 194 |
194 } // namespace content | 195 } // namespace content |
OLD | NEW |