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

Side by Side Diff: content/renderer/media/rtc_video_decoder.cc

Issue 10918172: Remove VideoDecoder::PrepareForShutdownHack() and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blah Created 8 years, 3 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 | Annotate | Revision Log
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 "content/renderer/media/rtc_video_decoder.h" 5 #include "content/renderer/media/rtc_video_decoder.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 16 matching lines...) Expand all
27 using media::VideoDecoder; 27 using media::VideoDecoder;
28 28
29 RTCVideoDecoder::RTCVideoDecoder(base::TaskRunner* video_decoder_thread, 29 RTCVideoDecoder::RTCVideoDecoder(base::TaskRunner* video_decoder_thread,
30 base::TaskRunner* main_thread, 30 base::TaskRunner* main_thread,
31 webrtc::VideoTrackInterface* video_track) 31 webrtc::VideoTrackInterface* video_track)
32 : video_decoder_thread_(video_decoder_thread), 32 : video_decoder_thread_(video_decoder_thread),
33 main_thread_(main_thread), 33 main_thread_(main_thread),
34 visible_size_(640, 480), 34 visible_size_(640, 480),
35 state_(kUnInitialized), 35 state_(kUnInitialized),
36 got_first_frame_(false), 36 got_first_frame_(false),
37 shutting_down_(false),
38 video_track_(video_track) { 37 video_track_(video_track) {
39 } 38 }
40 39
41 void RTCVideoDecoder::Initialize(const scoped_refptr<DemuxerStream>& stream, 40 void RTCVideoDecoder::Initialize(const scoped_refptr<DemuxerStream>& stream,
42 const PipelineStatusCB& status_cb, 41 const PipelineStatusCB& status_cb,
43 const StatisticsCB& statistics_cb) { 42 const StatisticsCB& statistics_cb) {
44 main_thread_->PostTask( 43 main_thread_->PostTask(
45 FROM_HERE, 44 FROM_HERE,
46 base::Bind(&RTCVideoDecoder::RegisterToVideoTrack, this)); 45 base::Bind(&RTCVideoDecoder::RegisterToVideoTrack, this));
47 if (!video_decoder_thread_->RunsTasksOnCurrentThread()) { 46 if (!video_decoder_thread_->RunsTasksOnCurrentThread()) {
(...skipping 13 matching lines...) Expand all
61 void RTCVideoDecoder::Read(const ReadCB& read_cb) { 60 void RTCVideoDecoder::Read(const ReadCB& read_cb) {
62 if (!video_decoder_thread_->RunsTasksOnCurrentThread()) { 61 if (!video_decoder_thread_->RunsTasksOnCurrentThread()) {
63 video_decoder_thread_->PostTask( 62 video_decoder_thread_->PostTask(
64 FROM_HERE, 63 FROM_HERE,
65 base::Bind(&RTCVideoDecoder::Read, this, read_cb)); 64 base::Bind(&RTCVideoDecoder::Read, this, read_cb));
66 return; 65 return;
67 } 66 }
68 67
69 base::AutoLock auto_lock(lock_); 68 base::AutoLock auto_lock(lock_);
70 CHECK(read_cb_.is_null()); 69 CHECK(read_cb_.is_null());
70
71 if (state_ == kStopped) {
72 read_cb.Run(kOk, NULL);
73 return;
74 }
75
71 read_cb_ = read_cb; 76 read_cb_ = read_cb;
72
73 if (shutting_down_) {
74 video_decoder_thread_->PostTask(FROM_HERE,
75 base::Bind(&RTCVideoDecoder::CancelPendingRead, this));
76 }
77 } 77 }
78 78
79 void RTCVideoDecoder::Reset(const base::Closure& closure) { 79 void RTCVideoDecoder::Reset(const base::Closure& closure) {
80 if (!video_decoder_thread_->RunsTasksOnCurrentThread()) { 80 if (!video_decoder_thread_->RunsTasksOnCurrentThread()) {
81 video_decoder_thread_->PostTask( 81 video_decoder_thread_->PostTask(
82 FROM_HERE, 82 FROM_HERE,
83 base::Bind(&RTCVideoDecoder::Reset, this, closure)); 83 base::Bind(&RTCVideoDecoder::Reset, this, closure));
84 return; 84 return;
85 } 85 }
86 86
87 CancelPendingRead(); 87 CancelPendingRead();
88 closure.Run(); 88 closure.Run();
89 } 89 }
90 90
91 void RTCVideoDecoder::Stop(const base::Closure& closure) { 91 void RTCVideoDecoder::Stop(const base::Closure& closure) {
92 main_thread_->PostTask( 92 main_thread_->PostTask(
93 FROM_HERE, 93 FROM_HERE,
94 base::Bind(&RTCVideoDecoder::DeregisterFromVideoTrack, this)); 94 base::Bind(&RTCVideoDecoder::DeregisterFromVideoTrack, this));
95 if (!video_decoder_thread_->RunsTasksOnCurrentThread()) { 95 if (!video_decoder_thread_->RunsTasksOnCurrentThread()) {
96 video_decoder_thread_->PostTask( 96 video_decoder_thread_->PostTask(
97 FROM_HERE, base::Bind(&RTCVideoDecoder::Stop, this, closure)); 97 FROM_HERE, base::Bind(&RTCVideoDecoder::Stop, this, closure));
98 return; 98 return;
99 } 99 }
100 100
101 state_ = kStopped; 101 state_ = kStopped;
102 CancelPendingRead();
102 closure.Run(); 103 closure.Run();
103 } 104 }
104 105
105 void RTCVideoDecoder::PrepareForShutdownHack() {
106 if (!video_decoder_thread_->RunsTasksOnCurrentThread()) {
107 video_decoder_thread_->PostTask(
108 FROM_HERE, base::Bind(&RTCVideoDecoder::PrepareForShutdownHack,
109 this));
110 return;
111 }
112 shutting_down_ = true;
113 CancelPendingRead();
114 }
115
116 void RTCVideoDecoder::SetSize(int width, int height) { 106 void RTCVideoDecoder::SetSize(int width, int height) {
117 visible_size_.SetSize(width, height); 107 visible_size_.SetSize(width, height);
118 } 108 }
119 109
120 // TODO(wjia): this function can be split into two parts so that the |lock_| 110 // TODO(wjia): this function can be split into two parts so that the |lock_|
121 // can be removed. 111 // can be removed.
122 // First creates media::VideoFrame, then post a task onto |message_loop_| 112 // First creates media::VideoFrame, then post a task onto |message_loop_|
123 // to deliver that frame. 113 // to deliver that frame.
124 void RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) { 114 void RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) {
125 // Called from libjingle thread. 115 // Called from libjingle thread.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 DCHECK(main_thread_->RunsTasksOnCurrentThread()); 185 DCHECK(main_thread_->RunsTasksOnCurrentThread());
196 if (video_track_) { 186 if (video_track_) {
197 video_track_->RemoveRenderer(this); 187 video_track_->RemoveRenderer(this);
198 video_track_ = NULL; 188 video_track_ = NULL;
199 } 189 }
200 } 190 }
201 191
202 RTCVideoDecoder::~RTCVideoDecoder() { 192 RTCVideoDecoder::~RTCVideoDecoder() {
203 DCHECK_NE(kNormal, state_); 193 DCHECK_NE(kNormal, state_);
204 } 194 }
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_video_decoder.h ('k') | content/renderer/media/rtc_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698