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

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

Issue 2643733002: Allow to use {FFmpeg/Vpx}VideoDecoder from a UtilityProcess (Closed)
Patch Set: Rebase Created 3 years, 10 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/ffmpeg_video_decoder.h ('k') | media/filters/vpx_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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <string> 11 #include <string>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/sys_info.h" 19 #include "base/sys_info.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "media/base/bind_to_current_loop.h" 21 #include "media/base/bind_to_current_loop.h"
22 #include "media/base/decoder_buffer.h" 22 #include "media/base/decoder_buffer.h"
23 #include "media/base/limits.h" 23 #include "media/base/limits.h"
24 #include "media/base/media_switches.h" 24 #include "media/base/media_switches.h"
25 #include "media/base/timestamp_constants.h" 25 #include "media/base/timestamp_constants.h"
26 #include "media/base/video_frame.h" 26 #include "media/base/video_frame.h"
27 #include "media/base/video_frame_provider.h"
27 #include "media/base/video_util.h" 28 #include "media/base/video_util.h"
28 #include "media/ffmpeg/ffmpeg_common.h" 29 #include "media/ffmpeg/ffmpeg_common.h"
29 #include "media/filters/ffmpeg_glue.h" 30 #include "media/filters/ffmpeg_glue.h"
30 31
31 namespace media { 32 namespace media {
32 33
33 // Always use 2 or more threads for video decoding. Most machines today will 34 // Always use 2 or more threads for video decoding. Most machines today will
34 // have 2-8 execution contexts. Using more cores generally doesn't seem to 35 // have 2-8 execution contexts. Using more cores generally doesn't seem to
35 // increase power usage and allows us to decode video faster. 36 // increase power usage and allows us to decode video faster.
36 // 37 //
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 bool FFmpegVideoDecoder::IsCodecSupported(VideoCodec codec) { 110 bool FFmpegVideoDecoder::IsCodecSupported(VideoCodec codec) {
110 FFmpegGlue::InitializeFFmpeg(); 111 FFmpegGlue::InitializeFFmpeg();
111 return avcodec_find_decoder(VideoCodecToCodecID(codec)) != nullptr; 112 return avcodec_find_decoder(VideoCodecToCodecID(codec)) != nullptr;
112 } 113 }
113 114
114 FFmpegVideoDecoder::FFmpegVideoDecoder() 115 FFmpegVideoDecoder::FFmpegVideoDecoder()
115 : state_(kUninitialized), decode_nalus_(false) { 116 : state_(kUninitialized), decode_nalus_(false) {
116 thread_checker_.DetachFromThread(); 117 thread_checker_.DetachFromThread();
117 } 118 }
118 119
120 FFmpegVideoDecoder::FFmpegVideoDecoder(
121 std::unique_ptr<VideoFrameProvider> video_frame_provider)
122 : state_(kUninitialized),
123 frame_pool_(std::move(video_frame_provider)),
124 decode_nalus_(false) {
125 thread_checker_.DetachFromThread();
126 }
127
119 int FFmpegVideoDecoder::GetVideoBuffer(struct AVCodecContext* codec_context, 128 int FFmpegVideoDecoder::GetVideoBuffer(struct AVCodecContext* codec_context,
120 AVFrame* frame, 129 AVFrame* frame,
121 int flags) { 130 int flags) {
122 // Don't use |codec_context_| here! With threaded decoding, 131 // Don't use |codec_context_| here! With threaded decoding,
123 // it will contain unsynchronized width/height/pix_fmt values, 132 // it will contain unsynchronized width/height/pix_fmt values,
124 // whereas |codec_context| contains the current threads's 133 // whereas |codec_context| contains the current threads's
125 // updated width/height/pix_fmt, which can change for adaptive 134 // updated width/height/pix_fmt, which can change for adaptive
126 // content. 135 // content.
127 const VideoPixelFormat format = 136 const VideoPixelFormat format =
128 AVPixelFormatToVideoPixelFormat(codec_context->pix_fmt); 137 AVPixelFormatToVideoPixelFormat(codec_context->pix_fmt);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { 436 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) {
428 ReleaseFFmpegResources(); 437 ReleaseFFmpegResources();
429 return false; 438 return false;
430 } 439 }
431 440
432 av_frame_.reset(av_frame_alloc()); 441 av_frame_.reset(av_frame_alloc());
433 return true; 442 return true;
434 } 443 }
435 444
436 } // namespace media 445 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_video_decoder.h ('k') | media/filters/vpx_video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698