Skip to content

Commit

Permalink
Initial support for the desktop media pipeline on Android.
Browse files Browse the repository at this point in the history
Add experimental support for the desktop src= media pipeline on Android
behind a compile-time variable. To compile with it
enabled, set the gyp variable media_use_ffmpeg=1.

Currently only H/W accelerated VP8 is supported because that is all that
the existing AndroidVideoDecodeAccelerator supports.

BUG=507834

Review URL: https://codereview.chromium.org/1230793009

Cr-Commit-Position: refs/heads/master@{#339498}
  • Loading branch information
watk authored and Commit bot committed Jul 20, 2015
1 parent 808535c commit 45c3063
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 44 deletions.
6 changes: 3 additions & 3 deletions content/renderer/render_frame_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ CommonNavigationParams MakeCommonNavigationParams(
ui_timestamp, report_type, GURL(), GURL());
}

#if !defined(OS_ANDROID)
#if !defined(OS_ANDROID) || defined(ENABLE_MEDIA_PIPELINE_ON_ANDROID)
media::Context3D GetSharedMainThreadContext3D() {
cc::ContextProvider* provider =
RenderThreadImpl::current()->SharedMainThreadContextProvider().get();
Expand Down Expand Up @@ -2012,7 +2012,7 @@ blink::WebMediaPlayer* RenderFrameImpl::createMediaPlayer(
if (!web_stream.isNull())
return CreateWebMediaPlayerForMediaStream(client);

#if defined(OS_ANDROID)
#if defined(OS_ANDROID) && !defined(ENABLE_MEDIA_PIPELINE_ON_ANDROID)
return CreateAndroidWebMediaPlayer(client, encrypted_client,
GetMediaPermission(), initial_cdm);
#else
Expand Down Expand Up @@ -2047,7 +2047,7 @@ blink::WebMediaPlayer* RenderFrameImpl::createMediaPlayer(
return new media::WebMediaPlayerImpl(
frame, client, encrypted_client, weak_factory_.GetWeakPtr(),
media_renderer_factory.Pass(), GetCdmFactory(), params);
#endif // defined(OS_ANDROID)
#endif // defined(OS_ANDROID) && !defined(ENABLE_MEDIA_PIPELINE_ON_ANDROID)
}

blink::WebApplicationCacheHost* RenderFrameImpl::createApplicationCacheHost(
Expand Down
5 changes: 4 additions & 1 deletion media/blink/media_blink.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# found in the LICENSE file.

{
'includes': [
'../media_variables.gypi'
],
'targets': [
{
# GN version: //media/blink
Expand Down Expand Up @@ -76,7 +79,7 @@
'websourcebuffer_impl.h',
],
'conditions': [
['OS=="android"', {
['OS=="android" and media_use_ffmpeg==0', {
'sources!': [
'encrypted_media_player_support.cc',
'encrypted_media_player_support.h',
Expand Down
9 changes: 9 additions & 0 deletions media/ffmpeg/ffmpeg_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ void AVStreamToVideoDecoderConfig(

VideoPixelFormat format =
PixelFormatToVideoPixelFormat(stream->codec->pix_fmt);
// The format and coded size may be unknown if FFmpeg is compiled without
// video decoders.
#if defined(DISABLE_FFMPEG_VIDEO_DECODERS)
if (format == PIXEL_FORMAT_UNKNOWN)
format = PIXEL_FORMAT_YV12;
if (coded_size == gfx::Size(0, 0))
coded_size = visible_rect.size();
#endif

if (codec == kCodecVP9) {
// TODO(tomfinegan): libavcodec doesn't know about VP9.
format = PIXEL_FORMAT_YV12;
Expand Down
8 changes: 8 additions & 0 deletions media/filters/audio_decoder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,19 @@ TEST_P(FFmpegAudioDecoderBehavioralTest, InitializeWithBadConfig) {
InitializeDecoderWithResult(decoder_config, false);
}

#if defined(OPUS_FIXED_POINT)
const DecodedBufferExpectations kSfxOpusExpectations[] = {
{0, 13500, "-2.70,-1.41,-0.78,-1.27,-2.56,-3.73,"},
{13500, 20000, "5.48,5.93,6.05,5.83,5.54,5.46,"},
{33500, 20000, "-3.44,-3.34,-3.57,-4.11,-4.74,-5.13,"},
};
#else
const DecodedBufferExpectations kSfxOpusExpectations[] = {
{0, 13500, "-2.70,-1.41,-0.78,-1.27,-2.56,-3.73,"},
{13500, 20000, "5.48,5.93,6.04,5.83,5.54,5.45,"},
{33500, 20000, "-3.45,-3.35,-3.57,-4.12,-4.74,-5.14,"},
};
#endif

const DecodedBufferExpectations kBearOpusExpectations[] = {
{500, 3500, "-0.26,0.87,1.36,0.84,-0.30,-1.22,"},
Expand Down
8 changes: 5 additions & 3 deletions media/filters/ffmpeg_glue_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ TEST_F(FFmpegGlueDestructionTest, WithOpenWithOpenStreams) {
ASSERT_TRUE(glue_->OpenContext());
ASSERT_GT(glue_->format_context()->nb_streams, 0u);

AVCodecContext* context = glue_->format_context()->streams[0]->codec;
ASSERT_EQ(avcodec_open2(
context, avcodec_find_decoder(context->codec_id), NULL), 0);
// Pick the audio stream (1) so this works when the ffmpeg video decoders are
// disabled.
AVCodecContext* context = glue_->format_context()->streams[1]->codec;
ASSERT_EQ(0, avcodec_open2(
context, avcodec_find_decoder(context->codec_id), NULL));
}

} // namespace media
65 changes: 44 additions & 21 deletions media/media.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
# detection of ABI mismatches and prevents silent errors.
'linux_link_pulseaudio%': 0,
'conditions': [
['OS=="android" or OS=="ios"', {
# Android and iOS don't use ffmpeg or libvpx.
'media_use_ffmpeg%': 0,
'media_use_libvpx%': 0,
}, { # 'OS!="android" and OS!="ios"'
'media_use_ffmpeg%': 1,
'media_use_libvpx%': 1,
}],
# Enable ALSA and Pulse for runtime selection.
['(OS=="linux" or OS=="freebsd" or OS=="solaris") and (embedded!=1 or (chromecast==1 and target_arch!="arm"))', {
# ALSA is always needed for Web MIDI even if the cras is enabled.
Expand All @@ -45,6 +37,7 @@
},
'includes': [
'media_cdm.gypi',
'media_variables.gypi',
],
'targets': [
{
Expand All @@ -66,6 +59,9 @@
'../url/url.gyp:url_lib',
'shared_memory_support',
],
'export_dependent_settings': [
'../third_party/opus/opus.gyp:opus',
],
'defines': [
'MEDIA_IMPLEMENTATION',
],
Expand Down Expand Up @@ -260,7 +256,7 @@
'base/cdm_factory.cc',
'base/cdm_factory.h',
'base/cdm_initialized_promise.cc',
'base/cdm_initialized_promise.h',
'base/cdm_initialized_promise.h',
'base/cdm_key_information.cc',
'base/cdm_key_information.h',
'base/cdm_promise.cc',
Expand Down Expand Up @@ -706,17 +702,38 @@
'player_android',
'video_capture_android_jni_headers',
],
'sources': [
'base/media.cc',
'base/media.h',
],
'sources!': [
'filters/opus_audio_decoder.cc',
'filters/opus_audio_decoder.h',
'base/audio_video_metadata_extractor.cc',
'base/audio_video_metadata_extractor.h',
'base/media_file_checker.cc',
'base/media_file_checker.h',
'filters/ffmpeg_video_decoder.cc',
'filters/ffmpeg_video_decoder.h',
],
'defines': [
'DISABLE_USER_INPUT_MONITOR',
],
'conditions': [
['media_use_ffmpeg == 1', {
'defines': [
# On Android, FFmpeg is built without video decoders. We only
# support hardware video decoding.
'ENABLE_MEDIA_PIPELINE_ON_ANDROID',
'DISABLE_FFMPEG_VIDEO_DECODERS',
],
'direct_dependent_settings': {
'defines': [
'ENABLE_MEDIA_PIPELINE_ON_ANDROID',
'DISABLE_FFMPEG_VIDEO_DECODERS',
],
},
}, { # media_use_ffmpeg == 0
'sources!': [
'filters/opus_audio_decoder.cc',
'filters/opus_audio_decoder.h',
],
}],
],
}],
# For VaapiVideoEncodeAccelerator.
['target_arch != "arm" and chromeos == 1', {
Expand Down Expand Up @@ -1264,19 +1281,25 @@
'dependencies': [
'../third_party/ffmpeg/ffmpeg.gyp:ffmpeg',
],
}, { # media_use_ffmpeg== 0
}, { # media_use_ffmpeg==0
'sources!': [
'base/audio_video_metadata_extractor_unittest.cc',
'base/container_names_unittest.cc',
'base/media_file_checker_unittest.cc',
'ffmpeg/ffmpeg_common_unittest.cc',
'filters/audio_decoder_unittest.cc',
'filters/audio_file_reader_unittest.cc',
'filters/blocking_url_protocol_unittest.cc',
'filters/ffmpeg_aac_bitstream_converter_unittest.cc',
'filters/ffmpeg_demuxer_unittest.cc',
'filters/ffmpeg_glue_unittest.cc',
'filters/ffmpeg_h264_to_annex_b_bitstream_converter_unittest.cc',
],
}],
# Even if FFmpeg is enabled on Android we don't want these.
# TODO(watk): Refactor tests that could be made to run on Android.
['media_use_ffmpeg==0 or OS=="android"', {
'sources!': [
'base/audio_video_metadata_extractor_unittest.cc',
'base/container_names_unittest.cc',
'base/media_file_checker_unittest.cc',
'filters/audio_file_reader_unittest.cc',
'filters/blocking_url_protocol_unittest.cc',
'filters/ffmpeg_video_decoder_unittest.cc',
'filters/in_memory_url_protocol_unittest.cc',
'test/pipeline_integration_test.cc',
Expand Down
22 changes: 9 additions & 13 deletions media/media_cdm.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
# found in the LICENSE file.

{
'includes': [
'media_variables.gypi',
],
'variables': {
'conditions': [
['OS == "android"', {
# Android doesn't use ffmpeg.
'use_ffmpeg%': 0,
}, { # 'OS != "android"'
'use_ffmpeg%': 1,
}],
],
# Set |use_fake_video_decoder| to 1 to ignore input frames in |clearkeycdm|,
# and produce video frames filled with a solid color instead.
'use_fake_video_decoder%': 0,
# Set |use_libvpx| to 1 to use libvpx for VP8 decoding in |clearkeycdm|.
'use_libvpx%': 0,
# Set |use_libvpx_in_clear_key_cdm| to 1 to use libvpx for VP8 decoding in
# |clearkeycdm|.
'use_libvpx_in_clear_key_cdm%': 0,
},
'conditions': [
['enable_pepper_cdms==1', {
Expand All @@ -39,7 +35,7 @@
'cdm/ppapi/external_clear_key/fake_cdm_video_decoder.h',
],
}],
['use_ffmpeg == 1' , {
['media_use_ffmpeg == 1' , {
'defines': ['CLEAR_KEY_CDM_USE_FFMPEG_DECODER'],
'dependencies': [
'<(DEPTH)/third_party/ffmpeg/ffmpeg.gyp:ffmpeg',
Expand All @@ -49,13 +45,13 @@
'cdm/ppapi/external_clear_key/ffmpeg_cdm_audio_decoder.h',
],
}],
['use_ffmpeg == 1 and use_fake_video_decoder == 0' , {
['media_use_ffmpeg == 1 and use_fake_video_decoder == 0' , {
'sources': [
'cdm/ppapi/external_clear_key/ffmpeg_cdm_video_decoder.cc',
'cdm/ppapi/external_clear_key/ffmpeg_cdm_video_decoder.h',
],
}],
['use_libvpx == 1 and use_fake_video_decoder == 0' , {
['use_libvpx_in_clear_key_cdm == 1 and use_fake_video_decoder == 0' , {
'defines': ['CLEAR_KEY_CDM_USE_LIBVPX_DECODER'],
'dependencies': [
'<(DEPTH)/third_party/libvpx/libvpx.gyp:libvpx',
Expand Down
21 changes: 21 additions & 0 deletions media/media_variables.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Common media variables.
{
'variables': {
'conditions': [
['OS == "android" or OS == "ios"', {
# Android and iOS don't use FFmpeg or libvpx by default.
# Set media_use_ffmpeg=1 for Android builds to compile experimental
# support for FFmpeg and the desktop media pipeline.
'media_use_ffmpeg%': 0,
'media_use_libvpx%': 0,
}, {
'media_use_ffmpeg%': 1,
'media_use_libvpx%': 1,
}],
],
},
}
8 changes: 5 additions & 3 deletions media/renderers/default_renderer_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

#if !defined(MEDIA_DISABLE_FFMPEG)
#include "media/filters/ffmpeg_audio_decoder.h"
#if !defined(DISABLE_FFMPEG_VIDEO_DECODERS)
#include "media/filters/ffmpeg_video_decoder.h"
#endif
#endif

#if !defined(OS_ANDROID)
#if !defined(OS_ANDROID) || defined(ENABLE_MEDIA_PIPELINE_ON_ANDROID)
#include "media/filters/opus_audio_decoder.h"
#endif

Expand Down Expand Up @@ -55,7 +57,7 @@ scoped_ptr<Renderer> DefaultRendererFactory::CreateRenderer(
new FFmpegAudioDecoder(media_task_runner, media_log_));
#endif

#if !defined(OS_ANDROID)
#if !defined(OS_ANDROID) || defined(ENABLE_MEDIA_PIPELINE_ON_ANDROID)
audio_decoders.push_back(new OpusAudioDecoder(media_task_runner));
#endif

Expand All @@ -79,7 +81,7 @@ scoped_ptr<Renderer> DefaultRendererFactory::CreateRenderer(
video_decoders.push_back(new VpxVideoDecoder(media_task_runner));
#endif

#if !defined(MEDIA_DISABLE_FFMPEG)
#if !defined(MEDIA_DISABLE_FFMPEG) && !defined(DISABLE_FFMPEG_VIDEO_DECODERS)
video_decoders.push_back(new FFmpegVideoDecoder(media_task_runner));
#endif

Expand Down
5 changes: 5 additions & 0 deletions third_party/opus/opus.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@
'defines': [
'FIXED_POINT',
],
'direct_dependent_settings': {
'defines': [
'OPUS_FIXED_POINT',
],
},
'include_dirs': [
'src/silk/fixed',
],
Expand Down

0 comments on commit 45c3063

Please sign in to comment.