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

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

Issue 193303002: WeakPtr destruction order cleanup: media edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 9 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
« no previous file with comments | « media/filters/fake_video_decoder.h ('k') | media/filters/ffmpeg_audio_decoder.h » ('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/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 bool supports_get_decode_output) 17 bool supports_get_decode_output)
18 : task_runner_(base::MessageLoopProxy::current()), 18 : task_runner_(base::MessageLoopProxy::current()),
19 weak_factory_(this),
20 decoding_delay_(decoding_delay), 19 decoding_delay_(decoding_delay),
21 supports_get_decode_output_(supports_get_decode_output), 20 supports_get_decode_output_(supports_get_decode_output),
22 state_(UNINITIALIZED), 21 state_(UNINITIALIZED),
23 total_bytes_decoded_(0) { 22 total_bytes_decoded_(0),
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_, UNINITIALIZED); 28 DCHECK_EQ(state_, UNINITIALIZED);
29 } 29 }
30 30
31 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config, 31 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config,
32 const PipelineStatusCB& status_cb) { 32 const PipelineStatusCB& status_cb) {
33 DCHECK(task_runner_->BelongsToCurrentThread()); 33 DCHECK(task_runner_->BelongsToCurrentThread());
34 DCHECK(config.IsValidConfig()); 34 DCHECK(config.IsValidConfig());
35 DCHECK(decode_cb_.IsNull()) << "No reinitialization during pending decode."; 35 DCHECK(decode_cb_.IsNull()) << "No reinitialization during pending decode.";
36 DCHECK(reset_cb_.IsNull()) << "No reinitialization during pending reset."; 36 DCHECK(reset_cb_.IsNull()) << "No reinitialization during pending reset.";
37 37
38 weak_this_ = weak_factory_.GetWeakPtr();
39
40 current_config_ = config; 38 current_config_ = config;
41 init_cb_.SetCallback(BindToCurrentLoop(status_cb)); 39 init_cb_.SetCallback(BindToCurrentLoop(status_cb));
42 40
43 if (!decoded_frames_.empty()) { 41 if (!decoded_frames_.empty()) {
44 DVLOG(1) << "Decoded frames dropped during reinitialization."; 42 DVLOG(1) << "Decoded frames dropped during reinitialization.";
45 decoded_frames_.clear(); 43 decoded_frames_.clear();
46 } 44 }
47 45
48 state_ = NORMAL; 46 state_ = NORMAL;
49 init_cb_.RunOrHold(PIPELINE_OK); 47 init_cb_.RunOrHold(PIPELINE_OK);
50 } 48 }
51 49
52 void FakeVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 50 void FakeVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
53 const DecodeCB& decode_cb) { 51 const DecodeCB& decode_cb) {
54 DCHECK(task_runner_->BelongsToCurrentThread()); 52 DCHECK(task_runner_->BelongsToCurrentThread());
55 DCHECK(decode_cb_.IsNull()) << "Overlapping decodes are not supported."; 53 DCHECK(decode_cb_.IsNull()) << "Overlapping decodes are not supported.";
56 DCHECK(reset_cb_.IsNull()); 54 DCHECK(reset_cb_.IsNull());
57 DCHECK_LE(decoded_frames_.size(), static_cast<size_t>(decoding_delay_)); 55 DCHECK_LE(decoded_frames_.size(), static_cast<size_t>(decoding_delay_));
58 56
59 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size(); 57 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size();
60 decode_cb_.SetCallback(BindToCurrentLoop(base::Bind( 58 decode_cb_.SetCallback(
61 &FakeVideoDecoder::OnFrameDecoded, weak_this_, buffer_size, decode_cb))); 59 BindToCurrentLoop(base::Bind(&FakeVideoDecoder::OnFrameDecoded,
60 weak_factory_.GetWeakPtr(),
61 buffer_size,
62 decode_cb)));
62 63
63 if (buffer->end_of_stream() && decoded_frames_.empty()) { 64 if (buffer->end_of_stream() && decoded_frames_.empty()) {
64 decode_cb_.RunOrHold(kOk, VideoFrame::CreateEOSFrame()); 65 decode_cb_.RunOrHold(kOk, VideoFrame::CreateEOSFrame());
65 return; 66 return;
66 } 67 }
67 68
68 if (!buffer->end_of_stream()) { 69 if (!buffer->end_of_stream()) {
69 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_)); 70 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_));
70 scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateColorFrame( 71 scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateColorFrame(
71 current_config_.coded_size(), 0, 0, 0, buffer->timestamp()); 72 current_config_.coded_size(), 0, 0, 0, buffer->timestamp());
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 int buffer_size, 197 int buffer_size,
197 const DecodeCB& decode_cb, 198 const DecodeCB& decode_cb,
198 Status status, 199 Status status,
199 const scoped_refptr<VideoFrame>& video_frame) { 200 const scoped_refptr<VideoFrame>& video_frame) {
200 if (status == kOk || status == kNotEnoughData) 201 if (status == kOk || status == kNotEnoughData)
201 total_bytes_decoded_ += buffer_size; 202 total_bytes_decoded_ += buffer_size;
202 decode_cb.Run(status, video_frame); 203 decode_cb.Run(status, video_frame);
203 } 204 }
204 205
205 } // namespace media 206 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/fake_video_decoder.h ('k') | media/filters/ffmpeg_audio_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698