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

Side by Side Diff: media/filters/vpx_video_decoder.cc

Issue 65803002: Replace MessageLoopProxy with SingleThreadTaskRunner for media/filters/ + associated code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « media/filters/vpx_video_decoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/filters/vpx_video_decoder.h" 5 #include "media/filters/vpx_video_decoder.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/sys_byteorder.h" 17 #include "base/sys_byteorder.h"
18 #include "media/base/bind_to_loop.h" 18 #include "media/base/bind_to_loop.h"
19 #include "media/base/decoder_buffer.h" 19 #include "media/base/decoder_buffer.h"
20 #include "media/base/demuxer_stream.h" 20 #include "media/base/demuxer_stream.h"
21 #include "media/base/media_switches.h" 21 #include "media/base/media_switches.h"
22 #include "media/base/pipeline.h" 22 #include "media/base/pipeline.h"
23 #include "media/base/video_decoder_config.h" 23 #include "media/base/video_decoder_config.h"
24 #include "media/base/video_frame.h" 24 #include "media/base/video_frame.h"
25 #include "media/base/video_util.h" 25 #include "media/base/video_util.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 return decode_threads; 62 return decode_threads;
63 } 63 }
64 64
65 decode_threads = std::max(decode_threads, 0); 65 decode_threads = std::max(decode_threads, 0);
66 decode_threads = std::min(decode_threads, kMaxDecodeThreads); 66 decode_threads = std::min(decode_threads, kMaxDecodeThreads);
67 return decode_threads; 67 return decode_threads;
68 } 68 }
69 69
70 VpxVideoDecoder::VpxVideoDecoder( 70 VpxVideoDecoder::VpxVideoDecoder(
71 const scoped_refptr<base::MessageLoopProxy>& message_loop) 71 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
72 : message_loop_(message_loop), 72 : task_runner_(task_runner),
73 weak_factory_(this), 73 weak_factory_(this),
74 state_(kUninitialized), 74 state_(kUninitialized),
75 vpx_codec_(NULL), 75 vpx_codec_(NULL),
76 vpx_codec_alpha_(NULL) { 76 vpx_codec_alpha_(NULL) {
77 } 77 }
78 78
79 VpxVideoDecoder::~VpxVideoDecoder() { 79 VpxVideoDecoder::~VpxVideoDecoder() {
80 DCHECK_EQ(kUninitialized, state_); 80 DCHECK_EQ(kUninitialized, state_);
81 CloseDecoder(); 81 CloseDecoder();
82 } 82 }
83 83
84 void VpxVideoDecoder::Initialize(const VideoDecoderConfig& config, 84 void VpxVideoDecoder::Initialize(const VideoDecoderConfig& config,
85 const PipelineStatusCB& status_cb) { 85 const PipelineStatusCB& status_cb) {
86 DCHECK(message_loop_->BelongsToCurrentThread()); 86 DCHECK(task_runner_->BelongsToCurrentThread());
87 DCHECK(config.IsValidConfig()); 87 DCHECK(config.IsValidConfig());
88 DCHECK(!config.is_encrypted()); 88 DCHECK(!config.is_encrypted());
89 DCHECK(decode_cb_.is_null()); 89 DCHECK(decode_cb_.is_null());
90 DCHECK(reset_cb_.is_null()); 90 DCHECK(reset_cb_.is_null());
91 91
92 weak_this_ = weak_factory_.GetWeakPtr(); 92 weak_this_ = weak_factory_.GetWeakPtr();
93 93
94 if (!ConfigureDecoder(config)) { 94 if (!ConfigureDecoder(config)) {
95 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); 95 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
96 return; 96 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 159 }
160 if (vpx_codec_alpha_) { 160 if (vpx_codec_alpha_) {
161 vpx_codec_destroy(vpx_codec_alpha_); 161 vpx_codec_destroy(vpx_codec_alpha_);
162 delete vpx_codec_alpha_; 162 delete vpx_codec_alpha_;
163 vpx_codec_alpha_ = NULL; 163 vpx_codec_alpha_ = NULL;
164 } 164 }
165 } 165 }
166 166
167 void VpxVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 167 void VpxVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
168 const DecodeCB& decode_cb) { 168 const DecodeCB& decode_cb) {
169 DCHECK(message_loop_->BelongsToCurrentThread()); 169 DCHECK(task_runner_->BelongsToCurrentThread());
170 DCHECK(!decode_cb.is_null()); 170 DCHECK(!decode_cb.is_null());
171 CHECK_NE(state_, kUninitialized); 171 CHECK_NE(state_, kUninitialized);
172 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; 172 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported.";
173 173
174 decode_cb_ = BindToCurrentLoop(decode_cb); 174 decode_cb_ = BindToCurrentLoop(decode_cb);
175 175
176 if (state_ == kError) { 176 if (state_ == kError) {
177 base::ResetAndReturn(&decode_cb_).Run(kDecodeError, NULL); 177 base::ResetAndReturn(&decode_cb_).Run(kDecodeError, NULL);
178 return; 178 return;
179 } 179 }
180 180
181 // Return empty frames if decoding has finished. 181 // Return empty frames if decoding has finished.
182 if (state_ == kDecodeFinished) { 182 if (state_ == kDecodeFinished) {
183 base::ResetAndReturn(&decode_cb_).Run(kOk, VideoFrame::CreateEOSFrame()); 183 base::ResetAndReturn(&decode_cb_).Run(kOk, VideoFrame::CreateEOSFrame());
184 return; 184 return;
185 } 185 }
186 186
187 DecodeBuffer(buffer); 187 DecodeBuffer(buffer);
188 } 188 }
189 189
190 void VpxVideoDecoder::Reset(const base::Closure& closure) { 190 void VpxVideoDecoder::Reset(const base::Closure& closure) {
191 DCHECK(message_loop_->BelongsToCurrentThread()); 191 DCHECK(task_runner_->BelongsToCurrentThread());
192 DCHECK(reset_cb_.is_null()); 192 DCHECK(reset_cb_.is_null());
193 reset_cb_ = BindToCurrentLoop(closure); 193 reset_cb_ = BindToCurrentLoop(closure);
194 194
195 // Defer the reset if a decode is pending. 195 // Defer the reset if a decode is pending.
196 if (!decode_cb_.is_null()) 196 if (!decode_cb_.is_null())
197 return; 197 return;
198 198
199 DoReset(); 199 DoReset();
200 } 200 }
201 201
202 void VpxVideoDecoder::Stop(const base::Closure& closure) { 202 void VpxVideoDecoder::Stop(const base::Closure& closure) {
203 DCHECK(message_loop_->BelongsToCurrentThread()); 203 DCHECK(task_runner_->BelongsToCurrentThread());
204 base::ScopedClosureRunner runner(BindToCurrentLoop(closure)); 204 base::ScopedClosureRunner runner(BindToCurrentLoop(closure));
205 205
206 if (state_ == kUninitialized) 206 if (state_ == kUninitialized)
207 return; 207 return;
208 208
209 if (!decode_cb_.is_null()) { 209 if (!decode_cb_.is_null()) {
210 base::ResetAndReturn(&decode_cb_).Run(kOk, NULL); 210 base::ResetAndReturn(&decode_cb_).Run(kOk, NULL);
211 // Reset is pending only when decode is pending. 211 // Reset is pending only when decode is pending.
212 if (!reset_cb_.is_null()) 212 if (!reset_cb_.is_null())
213 base::ResetAndReturn(&reset_cb_).Run(); 213 base::ResetAndReturn(&reset_cb_).Run();
214 } 214 }
215 215
216 state_ = kUninitialized; 216 state_ = kUninitialized;
217 } 217 }
218 218
219 bool VpxVideoDecoder::HasAlpha() const { 219 bool VpxVideoDecoder::HasAlpha() const {
220 return vpx_codec_alpha_ != NULL; 220 return vpx_codec_alpha_ != NULL;
221 } 221 }
222 222
223 void VpxVideoDecoder::DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer) { 223 void VpxVideoDecoder::DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer) {
224 DCHECK(message_loop_->BelongsToCurrentThread()); 224 DCHECK(task_runner_->BelongsToCurrentThread());
225 DCHECK_NE(state_, kUninitialized); 225 DCHECK_NE(state_, kUninitialized);
226 DCHECK_NE(state_, kDecodeFinished); 226 DCHECK_NE(state_, kDecodeFinished);
227 DCHECK_NE(state_, kError); 227 DCHECK_NE(state_, kError);
228 DCHECK(reset_cb_.is_null()); 228 DCHECK(reset_cb_.is_null());
229 DCHECK(!decode_cb_.is_null()); 229 DCHECK(!decode_cb_.is_null());
230 DCHECK(buffer); 230 DCHECK(buffer);
231 231
232 // Transition to kDecodeFinished on the first end of stream buffer. 232 // Transition to kDecodeFinished on the first end of stream buffer.
233 if (state_ == kNormal && buffer->end_of_stream()) { 233 if (state_ == kNormal && buffer->end_of_stream()) {
234 state_ = kDecodeFinished; 234 state_ = kDecodeFinished;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); 368 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get());
369 return; 369 return;
370 } 370 }
371 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], 371 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y],
372 vpx_image->stride[VPX_PLANE_Y], 372 vpx_image->stride[VPX_PLANE_Y],
373 vpx_image->d_h, 373 vpx_image->d_h,
374 video_frame->get()); 374 video_frame->get());
375 } 375 }
376 376
377 } // namespace media 377 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/vpx_video_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698