Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: content/common/gpu/media/fake_video_decode_accelerator.cc

Issue 1135943005: Revert of content/common: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "media/base/bitstream_buffer.h" 9 #include "media/base/bitstream_buffer.h"
11 #include "media/base/limits.h" 10 #include "media/base/limits.h"
12 #include "ui/gl/gl_context.h" 11 #include "ui/gl/gl_context.h"
13 #include "ui/gl/gl_implementation.h" 12 #include "ui/gl/gl_implementation.h"
14 #include "ui/gl/gl_surface.h" 13 #include "ui/gl/gl_surface.h"
15 #include "ui/gl/gl_surface_egl.h" 14 #include "ui/gl/gl_surface_egl.h"
16 #include "ui/gl/gl_surface_glx.h" 15 #include "ui/gl/gl_surface_glx.h"
17 16
18 namespace content { 17 namespace content {
19 18
20 static const uint32 kDefaultTextureTarget = GL_TEXTURE_2D; 19 static const uint32 kDefaultTextureTarget = GL_TEXTURE_2D;
21 // Must be at least 2 since the rendering helper will switch between textures 20 // Must be at least 2 since the rendering helper will switch between textures
22 // and if there is only one, it will wait for the next one that will never come. 21 // and if there is only one, it will wait for the next one that will never come.
23 // Must also be an even number as otherwise there won't be the same amount of 22 // Must also be an even number as otherwise there won't be the same amount of
24 // white and black frames. 23 // white and black frames.
25 static const unsigned int kNumBuffers = media::limits::kMaxVideoFrames + 24 static const unsigned int kNumBuffers = media::limits::kMaxVideoFrames +
26 (media::limits::kMaxVideoFrames & 1u); 25 (media::limits::kMaxVideoFrames & 1u);
27 26
28 FakeVideoDecodeAccelerator::FakeVideoDecodeAccelerator( 27 FakeVideoDecodeAccelerator::FakeVideoDecodeAccelerator(
29 gfx::GLContext* gl, 28 gfx::GLContext* gl,
30 gfx::Size size, 29 gfx::Size size,
31 const base::Callback<bool(void)>& make_context_current) 30 const base::Callback<bool(void)>& make_context_current)
32 : child_task_runner_(base::ThreadTaskRunnerHandle::Get()), 31 : child_message_loop_proxy_(base::MessageLoopProxy::current()),
33 client_(NULL), 32 client_(NULL),
34 make_context_current_(make_context_current), 33 make_context_current_(make_context_current),
35 gl_(gl), 34 gl_(gl),
36 frame_buffer_size_(size), 35 frame_buffer_size_(size),
37 flushing_(false), 36 flushing_(false),
38 weak_this_factory_(this) { 37 weak_this_factory_(this) {
39 } 38 }
40 39
41 FakeVideoDecodeAccelerator::~FakeVideoDecodeAccelerator() { 40 FakeVideoDecodeAccelerator::~FakeVideoDecodeAccelerator() {
42 } 41 }
43 42
44 bool FakeVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, 43 bool FakeVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
45 Client* client) { 44 Client* client) {
46 DCHECK(child_task_runner_->BelongsToCurrentThread()); 45 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
47 if (profile == media::VIDEO_CODEC_PROFILE_UNKNOWN) { 46 if (profile == media::VIDEO_CODEC_PROFILE_UNKNOWN) {
48 LOG(ERROR) << "unknown codec profile"; 47 LOG(ERROR) << "unknown codec profile";
49 return false; 48 return false;
50 } 49 }
51 // V4L2VideoDecodeAccelerator waits until first decode call to ask for buffers 50 // V4L2VideoDecodeAccelerator waits until first decode call to ask for buffers
52 // This class asks for it on initialization instead. 51 // This class asks for it on initialization instead.
53 client_ = client; 52 client_ = client;
54 client_->ProvidePictureBuffers(kNumBuffers, 53 client_->ProvidePictureBuffers(kNumBuffers,
55 frame_buffer_size_, 54 frame_buffer_size_,
56 kDefaultTextureTarget); 55 kDefaultTextureTarget);
57 return true; 56 return true;
58 } 57 }
59 58
60 void FakeVideoDecodeAccelerator::Decode( 59 void FakeVideoDecodeAccelerator::Decode(
61 const media::BitstreamBuffer& bitstream_buffer) { 60 const media::BitstreamBuffer& bitstream_buffer) {
62 int bitstream_buffer_id = bitstream_buffer.id(); 61 int bitstream_buffer_id = bitstream_buffer.id();
63 queued_bitstream_ids_.push(bitstream_buffer_id); 62 queued_bitstream_ids_.push(bitstream_buffer_id);
64 child_task_runner_->PostTask( 63 child_message_loop_proxy_->PostTask(
65 FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, 64 FROM_HERE,
66 weak_this_factory_.GetWeakPtr())); 65 base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady,
66 weak_this_factory_.GetWeakPtr()));
67 } 67 }
68 68
69 // Similar to UseOutputBitstreamBuffer for the encode accelerator. 69 // Similar to UseOutputBitstreamBuffer for the encode accelerator.
70 void FakeVideoDecodeAccelerator::AssignPictureBuffers( 70 void FakeVideoDecodeAccelerator::AssignPictureBuffers(
71 const std::vector<media::PictureBuffer>& buffers) { 71 const std::vector<media::PictureBuffer>& buffers) {
72 DCHECK(buffers.size() == kNumBuffers); 72 DCHECK(buffers.size() == kNumBuffers);
73 DCHECK(!(buffers.size()%2)); 73 DCHECK(!(buffers.size()%2));
74 74
75 // Save buffers and mark all buffers as ready for use. 75 // Save buffers and mark all buffers as ready for use.
76 scoped_ptr<uint8[]> white_data( 76 scoped_ptr<uint8[]> white_data(
(...skipping 23 matching lines...) Expand all
100 GL_RGBA, 100 GL_RGBA,
101 GL_UNSIGNED_BYTE, 101 GL_UNSIGNED_BYTE,
102 data); 102 data);
103 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 103 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
104 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 104 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
105 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 105 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
107 glBindTexture(GL_TEXTURE_2D, 0); 107 glBindTexture(GL_TEXTURE_2D, 0);
108 free_output_buffers_.push(buffers[index].id()); 108 free_output_buffers_.push(buffers[index].id());
109 } 109 }
110 child_task_runner_->PostTask( 110 child_message_loop_proxy_->PostTask(
111 FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, 111 FROM_HERE,
112 weak_this_factory_.GetWeakPtr())); 112 base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady,
113 weak_this_factory_.GetWeakPtr()));
113 } 114 }
114 115
115 void FakeVideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { 116 void FakeVideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) {
116 free_output_buffers_.push(picture_buffer_id); 117 free_output_buffers_.push(picture_buffer_id);
117 child_task_runner_->PostTask( 118 child_message_loop_proxy_->PostTask(
118 FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, 119 FROM_HERE,
119 weak_this_factory_.GetWeakPtr())); 120 base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady,
121 weak_this_factory_.GetWeakPtr()));
120 } 122 }
121 123
122 void FakeVideoDecodeAccelerator::Flush() { 124 void FakeVideoDecodeAccelerator::Flush() {
123 flushing_ = true; 125 flushing_ = true;
124 child_task_runner_->PostTask( 126 child_message_loop_proxy_->PostTask(
125 FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, 127 FROM_HERE,
126 weak_this_factory_.GetWeakPtr())); 128 base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady,
129 weak_this_factory_.GetWeakPtr()));
127 } 130 }
128 131
129 void FakeVideoDecodeAccelerator::Reset() { 132 void FakeVideoDecodeAccelerator::Reset() {
130 while (!queued_bitstream_ids_.empty()) { 133 while (!queued_bitstream_ids_.empty()) {
131 client_->NotifyEndOfBitstreamBuffer(queued_bitstream_ids_.front()); 134 client_->NotifyEndOfBitstreamBuffer(queued_bitstream_ids_.front());
132 queued_bitstream_ids_.pop(); 135 queued_bitstream_ids_.pop();
133 } 136 }
134 client_->NotifyResetDone(); 137 client_->NotifyResetDone();
135 } 138 }
136 139
(...skipping 29 matching lines...) Expand all
166 // Bitstream no longer needed. 169 // Bitstream no longer needed.
167 client_->NotifyEndOfBitstreamBuffer(bitstream_id); 170 client_->NotifyEndOfBitstreamBuffer(bitstream_id);
168 if (flushing_ && queued_bitstream_ids_.empty()) { 171 if (flushing_ && queued_bitstream_ids_.empty()) {
169 flushing_ = false; 172 flushing_ = false;
170 client_->NotifyFlushDone(); 173 client_->NotifyFlushDone();
171 } 174 }
172 } 175 }
173 } 176 }
174 177
175 } // namespace content 178 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/fake_video_decode_accelerator.h ('k') | content/common/gpu/media/gpu_video_decode_accelerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698