OLD | NEW |
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/vpx_video_decoder.h" | 5 #include "media/filters/vpx_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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 return decode_threads; | 51 return decode_threads; |
52 | 52 |
53 decode_threads = std::max(decode_threads, 0); | 53 decode_threads = std::max(decode_threads, 0); |
54 decode_threads = std::min(decode_threads, kMaxDecodeThreads); | 54 decode_threads = std::min(decode_threads, kMaxDecodeThreads); |
55 return decode_threads; | 55 return decode_threads; |
56 } | 56 } |
57 | 57 |
58 VpxVideoDecoder::VpxVideoDecoder( | 58 VpxVideoDecoder::VpxVideoDecoder( |
59 const scoped_refptr<base::MessageLoopProxy>& message_loop) | 59 const scoped_refptr<base::MessageLoopProxy>& message_loop) |
60 : message_loop_(message_loop), | 60 : message_loop_(message_loop), |
| 61 weak_factory_(this), |
61 state_(kUninitialized), | 62 state_(kUninitialized), |
62 vpx_codec_(NULL) { | 63 vpx_codec_(NULL) { |
63 } | 64 } |
64 | 65 |
65 VpxVideoDecoder::~VpxVideoDecoder() { | 66 VpxVideoDecoder::~VpxVideoDecoder() { |
66 DCHECK_EQ(kUninitialized, state_); | 67 DCHECK_EQ(kUninitialized, state_); |
67 CloseDecoder(); | 68 CloseDecoder(); |
68 } | 69 } |
69 | 70 |
70 void VpxVideoDecoder::Initialize( | 71 void VpxVideoDecoder::Initialize( |
71 const scoped_refptr<DemuxerStream>& stream, | 72 const scoped_refptr<DemuxerStream>& stream, |
72 const PipelineStatusCB& status_cb, | 73 const PipelineStatusCB& status_cb, |
73 const StatisticsCB& statistics_cb) { | 74 const StatisticsCB& statistics_cb) { |
74 DCHECK(message_loop_->BelongsToCurrentThread()); | 75 DCHECK(message_loop_->BelongsToCurrentThread()); |
75 DCHECK(!demuxer_stream_) << "Already initialized."; | 76 DCHECK(!demuxer_stream_) << "Already initialized."; |
| 77 weak_this_ = weak_factory_.GetWeakPtr(); |
76 | 78 |
77 if (!stream) { | 79 if (!stream) { |
78 status_cb.Run(PIPELINE_ERROR_DECODE); | 80 status_cb.Run(PIPELINE_ERROR_DECODE); |
79 return; | 81 return; |
80 } | 82 } |
81 | 83 |
82 demuxer_stream_ = stream; | 84 demuxer_stream_ = stream; |
83 statistics_cb_ = statistics_cb; | 85 statistics_cb_ = statistics_cb; |
84 | 86 |
85 if (!ConfigureDecoder()) { | 87 if (!ConfigureDecoder()) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 state_ = kUninitialized; | 177 state_ = kUninitialized; |
176 closure.Run(); | 178 closure.Run(); |
177 } | 179 } |
178 | 180 |
179 void VpxVideoDecoder::ReadFromDemuxerStream() { | 181 void VpxVideoDecoder::ReadFromDemuxerStream() { |
180 DCHECK_NE(state_, kUninitialized); | 182 DCHECK_NE(state_, kUninitialized); |
181 DCHECK_NE(state_, kDecodeFinished); | 183 DCHECK_NE(state_, kDecodeFinished); |
182 DCHECK(!read_cb_.is_null()); | 184 DCHECK(!read_cb_.is_null()); |
183 | 185 |
184 demuxer_stream_->Read(base::Bind( | 186 demuxer_stream_->Read(base::Bind( |
185 &VpxVideoDecoder::DoDecryptOrDecodeBuffer, this)); | 187 &VpxVideoDecoder::DoDecryptOrDecodeBuffer, weak_this_)); |
186 } | 188 } |
187 | 189 |
188 void VpxVideoDecoder::DoDecryptOrDecodeBuffer( | 190 void VpxVideoDecoder::DoDecryptOrDecodeBuffer( |
189 DemuxerStream::Status status, | 191 DemuxerStream::Status status, |
190 const scoped_refptr<DecoderBuffer>& buffer) { | 192 const scoped_refptr<DecoderBuffer>& buffer) { |
191 DCHECK(message_loop_->BelongsToCurrentThread()); | 193 DCHECK(message_loop_->BelongsToCurrentThread()); |
192 DCHECK_NE(state_, kDecodeFinished); | 194 DCHECK_NE(state_, kDecodeFinished); |
193 DCHECK_EQ(status != DemuxerStream::kOk, !buffer) << status; | 195 DCHECK_EQ(status != DemuxerStream::kOk, !buffer) << status; |
194 | 196 |
195 if (state_ == kUninitialized) | 197 if (state_ == kUninitialized) |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 vpx_image->stride[VPX_PLANE_U], | 334 vpx_image->stride[VPX_PLANE_U], |
333 vpx_image->d_h / 2, | 335 vpx_image->d_h / 2, |
334 *video_frame); | 336 *video_frame); |
335 CopyVPlane(vpx_image->planes[VPX_PLANE_V], | 337 CopyVPlane(vpx_image->planes[VPX_PLANE_V], |
336 vpx_image->stride[VPX_PLANE_V], | 338 vpx_image->stride[VPX_PLANE_V], |
337 vpx_image->d_h / 2, | 339 vpx_image->d_h / 2, |
338 *video_frame); | 340 *video_frame); |
339 } | 341 } |
340 | 342 |
341 } // namespace media | 343 } // namespace media |
OLD | NEW |