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

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

Issue 12741012: base: Support setting thread priorities generically. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove static initializers. Created 7 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
« no previous file with comments | « media/audio/cross_process_notification_win.cc ('k') | remoting/base/auto_thread.cc » ('j') | 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/video_renderer_base.h" 5 #include "media/filters/video_renderer_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 17 matching lines...) Expand all
28 const PaintCB& paint_cb, 28 const PaintCB& paint_cb,
29 const SetOpaqueCB& set_opaque_cb, 29 const SetOpaqueCB& set_opaque_cb,
30 bool drop_frames) 30 bool drop_frames)
31 : message_loop_(message_loop), 31 : message_loop_(message_loop),
32 weak_factory_(this), 32 weak_factory_(this),
33 video_frame_stream_( 33 video_frame_stream_(
34 message_loop, decoders.Pass(), set_decryptor_ready_cb), 34 message_loop, decoders.Pass(), set_decryptor_ready_cb),
35 received_end_of_stream_(false), 35 received_end_of_stream_(false),
36 frame_available_(&lock_), 36 frame_available_(&lock_),
37 state_(kUninitialized), 37 state_(kUninitialized),
38 thread_(base::kNullThreadHandle), 38 thread_(),
39 pending_read_(false), 39 pending_read_(false),
40 drop_frames_(drop_frames), 40 drop_frames_(drop_frames),
41 playback_rate_(0), 41 playback_rate_(0),
42 paint_cb_(paint_cb), 42 paint_cb_(paint_cb),
43 set_opaque_cb_(set_opaque_cb), 43 set_opaque_cb_(set_opaque_cb),
44 last_timestamp_(kNoTimestamp()) { 44 last_timestamp_(kNoTimestamp()) {
45 DCHECK(!paint_cb_.is_null()); 45 DCHECK(!paint_cb_.is_null());
46 } 46 }
47 47
48 VideoRendererBase::~VideoRendererBase() { 48 VideoRendererBase::~VideoRendererBase() {
49 base::AutoLock auto_lock(lock_); 49 base::AutoLock auto_lock(lock_);
50 CHECK(state_ == kStopped || state_ == kUninitialized) << state_; 50 CHECK(state_ == kStopped || state_ == kUninitialized) << state_;
51 CHECK_EQ(thread_, base::kNullThreadHandle); 51 CHECK(thread_.is_null());
52 } 52 }
53 53
54 void VideoRendererBase::Play(const base::Closure& callback) { 54 void VideoRendererBase::Play(const base::Closure& callback) {
55 DCHECK(message_loop_->BelongsToCurrentThread()); 55 DCHECK(message_loop_->BelongsToCurrentThread());
56 base::AutoLock auto_lock(lock_); 56 base::AutoLock auto_lock(lock_);
57 DCHECK_EQ(kPrerolled, state_); 57 DCHECK_EQ(kPrerolled, state_);
58 state_ = kPlaying; 58 state_ = kPlaying;
59 callback.Run(); 59 callback.Run();
60 } 60 }
61 61
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing 93 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing
94 // task-running guards that check |state_| with DCHECK(). 94 // task-running guards that check |state_| with DCHECK().
95 95
96 state_ = kStopped; 96 state_ = kStopped;
97 97
98 statistics_cb_.Reset(); 98 statistics_cb_.Reset();
99 max_time_cb_.Reset(); 99 max_time_cb_.Reset();
100 DoStopOrError_Locked(); 100 DoStopOrError_Locked();
101 101
102 // Clean up our thread if present. 102 // Clean up our thread if present.
103 base::PlatformThreadHandle thread_to_join = base::kNullThreadHandle; 103 base::PlatformThreadHandle thread_to_join = base::PlatformThreadHandle();
104 if (thread_ != base::kNullThreadHandle) { 104 if (!thread_.is_null()) {
105 // Signal the thread since it's possible to get stopped with the video 105 // Signal the thread since it's possible to get stopped with the video
106 // thread waiting for a read to complete. 106 // thread waiting for a read to complete.
107 frame_available_.Signal(); 107 frame_available_.Signal();
108 std::swap(thread_, thread_to_join); 108 std::swap(thread_, thread_to_join);
109 } 109 }
110 110
111 if (thread_to_join != base::kNullThreadHandle) { 111 if (!thread_to_join.is_null()) {
112 base::AutoUnlock auto_unlock(lock_); 112 base::AutoUnlock auto_unlock(lock_);
113 base::PlatformThread::Join(thread_to_join); 113 base::PlatformThread::Join(thread_to_join);
114 } 114 }
115 115
116 video_frame_stream_.Stop(callback); 116 video_frame_stream_.Stop(callback);
117 } 117 }
118 118
119 void VideoRendererBase::SetPlaybackRate(float playback_rate) { 119 void VideoRendererBase::SetPlaybackRate(float playback_rate) {
120 DCHECK(message_loop_->BelongsToCurrentThread()); 120 DCHECK(message_loop_->BelongsToCurrentThread());
121 base::AutoLock auto_lock(lock_); 121 base::AutoLock auto_lock(lock_);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (!base::PlatformThread::Create(0, this, &thread_)) { 205 if (!base::PlatformThread::Create(0, this, &thread_)) {
206 NOTREACHED() << "Video thread creation failed"; 206 NOTREACHED() << "Video thread creation failed";
207 state_ = kError; 207 state_ = kError;
208 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); 208 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED);
209 return; 209 return;
210 } 210 }
211 211
212 #if defined(OS_WIN) 212 #if defined(OS_WIN)
213 // Bump up our priority so our sleeping is more accurate. 213 // Bump up our priority so our sleeping is more accurate.
214 // TODO(scherkus): find out if this is necessary, but it seems to help. 214 // TODO(scherkus): find out if this is necessary, but it seems to help.
215 ::SetThreadPriority(thread_, THREAD_PRIORITY_ABOVE_NORMAL); 215 ::SetThreadPriority(thread_.platform_handle(), THREAD_PRIORITY_ABOVE_NORMAL);
216 #endif // defined(OS_WIN) 216 #endif // defined(OS_WIN)
217 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); 217 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK);
218 } 218 }
219 219
220 // PlatformThread::Delegate implementation. 220 // PlatformThread::Delegate implementation.
221 void VideoRendererBase::ThreadMain() { 221 void VideoRendererBase::ThreadMain() {
222 base::PlatformThread::SetName("CrVideoRenderer"); 222 base::PlatformThread::SetName("CrVideoRenderer");
223 223
224 // The number of milliseconds to idle when we do not have anything to do. 224 // The number of milliseconds to idle when we do not have anything to do.
225 // Nothing special about the value, other than we're being more OS-friendly 225 // Nothing special about the value, other than we're being more OS-friendly
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // Because we might remain in the prerolled state for an undetermined amount 530 // Because we might remain in the prerolled state for an undetermined amount
531 // of time (e.g., we seeked while paused), we'll paint the first prerolled 531 // of time (e.g., we seeked while paused), we'll paint the first prerolled
532 // frame. 532 // frame.
533 if (!ready_frames_.empty()) 533 if (!ready_frames_.empty())
534 PaintNextReadyFrame_Locked(); 534 PaintNextReadyFrame_Locked();
535 535
536 base::ResetAndReturn(&preroll_cb_).Run(PIPELINE_OK); 536 base::ResetAndReturn(&preroll_cb_).Run(PIPELINE_OK);
537 } 537 }
538 538
539 } // namespace media 539 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/cross_process_notification_win.cc ('k') | remoting/base/auto_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698