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

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

Issue 395703002: Fold {Audio|Video}Decoder::Stop() into the dtor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor fixes Created 6 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/fake_video_decoder.h" 5 #include "media/filters/fake_video_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "media/base/bind_to_current_loop.h" 11 #include "media/base/bind_to_current_loop.h"
12 #include "media/base/test_helpers.h" 12 #include "media/base/test_helpers.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 FakeVideoDecoder::FakeVideoDecoder(int decoding_delay, 16 FakeVideoDecoder::FakeVideoDecoder(int decoding_delay,
17 int max_parallel_decoding_requests) 17 int max_parallel_decoding_requests)
18 : decoding_delay_(decoding_delay), 18 : decoding_delay_(decoding_delay),
19 max_parallel_decoding_requests_(max_parallel_decoding_requests), 19 max_parallel_decoding_requests_(max_parallel_decoding_requests),
20 state_(STATE_UNINITIALIZED), 20 state_(STATE_UNINITIALIZED),
21 hold_decode_(false), 21 hold_decode_(false),
22 total_bytes_decoded_(0), 22 total_bytes_decoded_(0),
23 weak_factory_(this) { 23 weak_factory_(this) {
24 DCHECK_GE(decoding_delay, 0); 24 DCHECK_GE(decoding_delay, 0);
25 } 25 }
26 26
27 FakeVideoDecoder::~FakeVideoDecoder() { 27 FakeVideoDecoder::~FakeVideoDecoder() {
28 DCHECK_EQ(state_, STATE_UNINITIALIZED); 28 DCHECK(thread_checker_.CalledOnValidThread());
29
30 if (state_ == STATE_UNINITIALIZED)
31 return;
32
33 if (!init_cb_.IsNull())
34 SatisfyInit();
35 if (!held_decode_callbacks_.empty())
36 SatisfyDecode();
37 if (!reset_cb_.IsNull())
38 SatisfyReset();
39
40 decoded_frames_.clear();
41 state_ = STATE_UNINITIALIZED;
29 } 42 }
30 43
31 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config, 44 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config,
32 bool low_delay, 45 bool low_delay,
33 const PipelineStatusCB& status_cb, 46 const PipelineStatusCB& status_cb,
34 const OutputCB& output_cb) { 47 const OutputCB& output_cb) {
35 DCHECK(thread_checker_.CalledOnValidThread()); 48 DCHECK(thread_checker_.CalledOnValidThread());
36 DCHECK(config.IsValidConfig()); 49 DCHECK(config.IsValidConfig());
37 DCHECK(held_decode_callbacks_.empty()) 50 DCHECK(held_decode_callbacks_.empty())
38 << "No reinitialization during pending decode."; 51 << "No reinitialization during pending decode.";
(...skipping 18 matching lines...) Expand all
57 void FakeVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 70 void FakeVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
58 const DecodeCB& decode_cb) { 71 const DecodeCB& decode_cb) {
59 DCHECK(thread_checker_.CalledOnValidThread()); 72 DCHECK(thread_checker_.CalledOnValidThread());
60 DCHECK(reset_cb_.IsNull()); 73 DCHECK(reset_cb_.IsNull());
61 DCHECK_LE(decoded_frames_.size(), 74 DCHECK_LE(decoded_frames_.size(),
62 decoding_delay_ + held_decode_callbacks_.size()); 75 decoding_delay_ + held_decode_callbacks_.size());
63 DCHECK_LT(static_cast<int>(held_decode_callbacks_.size()), 76 DCHECK_LT(static_cast<int>(held_decode_callbacks_.size()),
64 max_parallel_decoding_requests_); 77 max_parallel_decoding_requests_);
65 78
66 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size(); 79 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size();
67 DecodeCB wrapped_decode_cb = 80 DecodeCB wrapped_decode_cb = base::Bind(&FakeVideoDecoder::OnFrameDecoded,
68 BindToCurrentLoop(base::Bind(&FakeVideoDecoder::OnFrameDecoded, 81 weak_factory_.GetWeakPtr(),
69 weak_factory_.GetWeakPtr(), 82 buffer_size,
70 buffer_size, decode_cb)); 83 BindToCurrentLoop(decode_cb));
71 84
72 if (state_ == STATE_ERROR) { 85 if (state_ == STATE_ERROR) {
73 wrapped_decode_cb.Run(kDecodeError); 86 wrapped_decode_cb.Run(kDecodeError);
74 return; 87 return;
75 } 88 }
76 89
77 if (buffer->end_of_stream()) { 90 if (buffer->end_of_stream()) {
78 state_ = STATE_END_OF_STREAM; 91 state_ = STATE_END_OF_STREAM;
79 } else { 92 } else {
80 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_)); 93 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_));
(...skipping 12 matching lines...) Expand all
93 reset_cb_.SetCallback(BindToCurrentLoop(closure)); 106 reset_cb_.SetCallback(BindToCurrentLoop(closure));
94 decoded_frames_.clear(); 107 decoded_frames_.clear();
95 108
96 // Defer the reset if a decode is pending. 109 // Defer the reset if a decode is pending.
97 if (!held_decode_callbacks_.empty()) 110 if (!held_decode_callbacks_.empty())
98 return; 111 return;
99 112
100 DoReset(); 113 DoReset();
101 } 114 }
102 115
103 void FakeVideoDecoder::Stop() {
104 DCHECK(thread_checker_.CalledOnValidThread());
105
106 if (!init_cb_.IsNull())
107 SatisfyInit();
108 if (!held_decode_callbacks_.empty())
109 SatisfyDecode();
110 if (!reset_cb_.IsNull())
111 SatisfyReset();
112
113 decoded_frames_.clear();
114 state_ = STATE_UNINITIALIZED;
115 }
116
117 void FakeVideoDecoder::HoldNextInit() { 116 void FakeVideoDecoder::HoldNextInit() {
118 DCHECK(thread_checker_.CalledOnValidThread()); 117 DCHECK(thread_checker_.CalledOnValidThread());
119 init_cb_.HoldCallback(); 118 init_cb_.HoldCallback();
120 } 119 }
121 120
122 void FakeVideoDecoder::HoldDecode() { 121 void FakeVideoDecoder::HoldDecode() {
123 DCHECK(thread_checker_.CalledOnValidThread()); 122 DCHECK(thread_checker_.CalledOnValidThread());
124 hold_decode_ = true; 123 hold_decode_ = true;
125 } 124 }
126 125
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 235
237 void FakeVideoDecoder::DoReset() { 236 void FakeVideoDecoder::DoReset() {
238 DCHECK(thread_checker_.CalledOnValidThread()); 237 DCHECK(thread_checker_.CalledOnValidThread());
239 DCHECK(held_decode_callbacks_.empty()); 238 DCHECK(held_decode_callbacks_.empty());
240 DCHECK(!reset_cb_.IsNull()); 239 DCHECK(!reset_cb_.IsNull());
241 240
242 reset_cb_.RunOrHold(); 241 reset_cb_.RunOrHold();
243 } 242 }
244 243
245 } // namespace media 244 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698