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

Side by Side Diff: media/filters/ffmpeg_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/ffmpeg_video_decoder.h ('k') | media/filters/gpu_video_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 (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/ffmpeg_video_decoder.h" 5 #include "media/filters/ffmpeg_video_decoder.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (threads.empty() || !base::StringToInt(threads, &decode_threads)) 49 if (threads.empty() || !base::StringToInt(threads, &decode_threads))
50 return decode_threads; 50 return decode_threads;
51 51
52 decode_threads = std::max(decode_threads, 0); 52 decode_threads = std::max(decode_threads, 0);
53 decode_threads = std::min(decode_threads, kMaxDecodeThreads); 53 decode_threads = std::min(decode_threads, kMaxDecodeThreads);
54 return decode_threads; 54 return decode_threads;
55 } 55 }
56 56
57 FFmpegVideoDecoder::FFmpegVideoDecoder( 57 FFmpegVideoDecoder::FFmpegVideoDecoder(
58 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) 58 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
59 : task_runner_(task_runner), 59 : task_runner_(task_runner), state_(kUninitialized) {}
60 weak_factory_(this),
61 state_(kUninitialized) {
62 }
63 60
64 int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, 61 int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context,
65 AVFrame* frame) { 62 AVFrame* frame) {
66 // Don't use |codec_context_| here! With threaded decoding, 63 // Don't use |codec_context_| here! With threaded decoding,
67 // it will contain unsynchronized width/height/pix_fmt values, 64 // it will contain unsynchronized width/height/pix_fmt values,
68 // whereas |codec_context| contains the current threads's 65 // whereas |codec_context| contains the current threads's
69 // updated width/height/pix_fmt, which can change for adaptive 66 // updated width/height/pix_fmt, which can change for adaptive
70 // content. 67 // content.
71 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt); 68 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt);
72 if (format == VideoFrame::UNKNOWN) 69 if (format == VideoFrame::UNKNOWN)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 124 }
128 125
129 void FFmpegVideoDecoder::Initialize(const VideoDecoderConfig& config, 126 void FFmpegVideoDecoder::Initialize(const VideoDecoderConfig& config,
130 const PipelineStatusCB& status_cb) { 127 const PipelineStatusCB& status_cb) {
131 DCHECK(task_runner_->BelongsToCurrentThread()); 128 DCHECK(task_runner_->BelongsToCurrentThread());
132 DCHECK(decode_cb_.is_null()); 129 DCHECK(decode_cb_.is_null());
133 DCHECK(reset_cb_.is_null()); 130 DCHECK(reset_cb_.is_null());
134 DCHECK(!config.is_encrypted()); 131 DCHECK(!config.is_encrypted());
135 132
136 FFmpegGlue::InitializeFFmpeg(); 133 FFmpegGlue::InitializeFFmpeg();
137 weak_this_ = weak_factory_.GetWeakPtr();
138 134
139 config_ = config; 135 config_ = config;
140 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); 136 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb);
141 137
142 if (!config.IsValidConfig() || !ConfigureDecoder()) { 138 if (!config.IsValidConfig() || !ConfigureDecoder()) {
143 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED); 139 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
144 return; 140 return;
145 } 141 }
146 142
147 // Success! 143 // Success!
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { 374 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) {
379 ReleaseFFmpegResources(); 375 ReleaseFFmpegResources();
380 return false; 376 return false;
381 } 377 }
382 378
383 av_frame_.reset(av_frame_alloc()); 379 av_frame_.reset(av_frame_alloc());
384 return true; 380 return true;
385 } 381 }
386 382
387 } // namespace media 383 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_video_decoder.h ('k') | media/filters/gpu_video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698