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

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

Issue 1083883003: Move BindToCurrentLoop from media/base/ to base/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix media/base/callback_holder.h compile Created 5 years, 8 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/filters/fake_demuxer_stream.cc ('k') | media/filters/ffmpeg_audio_decoder.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 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/bind_to_current_loop.h"
8 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
9 #include "base/location.h" 10 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.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 const BytesDecodedCB& bytes_decoded_cb) 18 const BytesDecodedCB& bytes_decoded_cb)
19 : decoding_delay_(decoding_delay), 19 : decoding_delay_(decoding_delay),
20 max_parallel_decoding_requests_(max_parallel_decoding_requests), 20 max_parallel_decoding_requests_(max_parallel_decoding_requests),
21 bytes_decoded_cb_(bytes_decoded_cb), 21 bytes_decoded_cb_(bytes_decoded_cb),
(...skipping 29 matching lines...) Expand all
51 bool low_delay, 51 bool low_delay,
52 const PipelineStatusCB& status_cb, 52 const PipelineStatusCB& status_cb,
53 const OutputCB& output_cb) { 53 const OutputCB& output_cb) {
54 DCHECK(thread_checker_.CalledOnValidThread()); 54 DCHECK(thread_checker_.CalledOnValidThread());
55 DCHECK(config.IsValidConfig()); 55 DCHECK(config.IsValidConfig());
56 DCHECK(held_decode_callbacks_.empty()) 56 DCHECK(held_decode_callbacks_.empty())
57 << "No reinitialization during pending decode."; 57 << "No reinitialization during pending decode.";
58 DCHECK(reset_cb_.IsNull()) << "No reinitialization during pending reset."; 58 DCHECK(reset_cb_.IsNull()) << "No reinitialization during pending reset.";
59 59
60 current_config_ = config; 60 current_config_ = config;
61 init_cb_.SetCallback(BindToCurrentLoop(status_cb)); 61 init_cb_.SetCallback(base::BindToCurrentLoop(status_cb));
62 62
63 // Don't need BindToCurrentLoop() because |output_cb_| is only called from 63 // Don't need base::BindToCurrentLoop() because |output_cb_| is only called
64 // RunDecodeCallback() which is posted from Decode(). 64 // from RunDecodeCallback() which is posted from Decode().
65 output_cb_ = output_cb; 65 output_cb_ = output_cb;
66 66
67 if (!decoded_frames_.empty()) { 67 if (!decoded_frames_.empty()) {
68 DVLOG(1) << "Decoded frames dropped during reinitialization."; 68 DVLOG(1) << "Decoded frames dropped during reinitialization.";
69 decoded_frames_.clear(); 69 decoded_frames_.clear();
70 } 70 }
71 71
72 if (fail_to_initialize_) { 72 if (fail_to_initialize_) {
73 state_ = STATE_ERROR; 73 state_ = STATE_ERROR;
74 init_cb_.RunOrHold(DECODER_ERROR_NOT_SUPPORTED); 74 init_cb_.RunOrHold(DECODER_ERROR_NOT_SUPPORTED);
(...skipping 10 matching lines...) Expand all
85 DCHECK_LE(decoded_frames_.size(), 85 DCHECK_LE(decoded_frames_.size(),
86 decoding_delay_ + held_decode_callbacks_.size()); 86 decoding_delay_ + held_decode_callbacks_.size());
87 DCHECK_LT(static_cast<int>(held_decode_callbacks_.size()), 87 DCHECK_LT(static_cast<int>(held_decode_callbacks_.size()),
88 max_parallel_decoding_requests_); 88 max_parallel_decoding_requests_);
89 DCHECK_NE(state_, STATE_END_OF_STREAM); 89 DCHECK_NE(state_, STATE_END_OF_STREAM);
90 90
91 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size(); 91 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size();
92 DecodeCB wrapped_decode_cb = base::Bind(&FakeVideoDecoder::OnFrameDecoded, 92 DecodeCB wrapped_decode_cb = base::Bind(&FakeVideoDecoder::OnFrameDecoded,
93 weak_factory_.GetWeakPtr(), 93 weak_factory_.GetWeakPtr(),
94 buffer_size, 94 buffer_size,
95 BindToCurrentLoop(decode_cb)); 95 base::BindToCurrentLoop(decode_cb));
96 96
97 if (state_ == STATE_ERROR) { 97 if (state_ == STATE_ERROR) {
98 wrapped_decode_cb.Run(kDecodeError); 98 wrapped_decode_cb.Run(kDecodeError);
99 return; 99 return;
100 } 100 }
101 101
102 if (buffer->end_of_stream()) { 102 if (buffer->end_of_stream()) {
103 state_ = STATE_END_OF_STREAM; 103 state_ = STATE_END_OF_STREAM;
104 } else { 104 } else {
105 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_)); 105 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_));
106 scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateColorFrame( 106 scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateColorFrame(
107 current_config_.coded_size(), 0, 0, 0, buffer->timestamp()); 107 current_config_.coded_size(), 0, 0, 0, buffer->timestamp());
108 decoded_frames_.push_back(video_frame); 108 decoded_frames_.push_back(video_frame);
109 } 109 }
110 110
111 RunOrHoldDecode(wrapped_decode_cb); 111 RunOrHoldDecode(wrapped_decode_cb);
112 } 112 }
113 113
114 void FakeVideoDecoder::Reset(const base::Closure& closure) { 114 void FakeVideoDecoder::Reset(const base::Closure& closure) {
115 DCHECK(thread_checker_.CalledOnValidThread()); 115 DCHECK(thread_checker_.CalledOnValidThread());
116 DCHECK(reset_cb_.IsNull()); 116 DCHECK(reset_cb_.IsNull());
117 117
118 reset_cb_.SetCallback(BindToCurrentLoop(closure)); 118 reset_cb_.SetCallback(base::BindToCurrentLoop(closure));
119 decoded_frames_.clear(); 119 decoded_frames_.clear();
120 120
121 // Defer the reset if a decode is pending. 121 // Defer the reset if a decode is pending.
122 if (!held_decode_callbacks_.empty()) 122 if (!held_decode_callbacks_.empty())
123 return; 123 return;
124 124
125 DoReset(); 125 DoReset();
126 } 126 }
127 127
128 void FakeVideoDecoder::HoldNextInit() { 128 void FakeVideoDecoder::HoldNextInit() {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 void FakeVideoDecoder::DoReset() { 255 void FakeVideoDecoder::DoReset() {
256 DCHECK(thread_checker_.CalledOnValidThread()); 256 DCHECK(thread_checker_.CalledOnValidThread());
257 DCHECK(held_decode_callbacks_.empty()); 257 DCHECK(held_decode_callbacks_.empty());
258 DCHECK(!reset_cb_.IsNull()); 258 DCHECK(!reset_cb_.IsNull());
259 259
260 reset_cb_.RunOrHold(); 260 reset_cb_.RunOrHold();
261 } 261 }
262 262
263 } // namespace media 263 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/fake_demuxer_stream.cc ('k') | media/filters/ffmpeg_audio_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698