Skip to content

Commit

Permalink
Linux: add a tool and code to make use_system_ffmpeg option more comp…
Browse files Browse the repository at this point in the history
…atible

This introduces a compile-time detection of ffmpeg configuration
(which codecs are available).

See https://groups.google.com/a/chromium.org/d/msg/chromium-dev/fm5Oe_AC3Sc/qkbmC7txaSkJ
for more context.

No functional change for Google Chrome.

BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183463 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
phajdan.jr@chromium.org committed Feb 20, 2013
1 parent 1531c30 commit b32da81
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,9 @@
'google_default_client_secret%': '<(google_default_client_secret)',
'enable_managed_users%': '<(enable_managed_users)',

# Use system ffmpeg instead of bundled one.
'use_system_ffmpeg%': 0,

# Use system mesa instead of bundled one.
'use_system_mesa%': 0,

Expand Down
10 changes: 10 additions & 0 deletions media/ffmpeg/ffmpeg_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ AudioCodec CodecIDToAudioCodec(CodecID codec_id) {
return kCodecGSM_MS;
case CODEC_ID_PCM_MULAW:
return kCodecPCM_MULAW;
#ifndef CHROMIUM_OMIT_CODEC_ID_OPUS
case CODEC_ID_OPUS:
return kCodecOpus;
#endif
default:
DVLOG(1) << "Unknown audio CodecID: " << codec_id;
}
Expand Down Expand Up @@ -129,8 +131,10 @@ static CodecID AudioCodecToCodecID(AudioCodec audio_codec,
return CODEC_ID_GSM_MS;
case kCodecPCM_MULAW:
return CODEC_ID_PCM_MULAW;
#ifndef CHROMIUM_OMIT_CODEC_ID_OPUS
case kCodecOpus:
return CODEC_ID_OPUS;
#endif
default:
DVLOG(1) << "Unknown AudioCodec: " << audio_codec;
}
Expand All @@ -147,8 +151,10 @@ VideoCodec CodecIDToVideoCodec(CodecID codec_id) {
return kCodecMPEG4;
case CODEC_ID_VP8:
return kCodecVP8;
#ifndef CHROMIUM_OMIT_AV_CODEC_ID_VP9
case AV_CODEC_ID_VP9:
return kCodecVP9;
#endif
default:
DVLOG(1) << "Unknown video CodecID: " << codec_id;
}
Expand All @@ -165,8 +171,10 @@ static CodecID VideoCodecToCodecID(VideoCodec video_codec) {
return CODEC_ID_MPEG4;
case kCodecVP8:
return CODEC_ID_VP8;
#ifndef CHROMIUM_OMIT_AV_CODEC_ID_VP9
case kCodecVP9:
return AV_CODEC_ID_VP9;
#endif
default:
DVLOG(1) << "Unknown VideoCodec: " << video_codec;
}
Expand Down Expand Up @@ -468,8 +476,10 @@ ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout, int channels) {
return CHANNEL_LAYOUT_6_1_FRONT;
case AV_CH_LAYOUT_7POINT0_FRONT:
return CHANNEL_LAYOUT_7_0_FRONT;
#ifdef AV_CH_LAYOUT_7POINT1_WIDE_BACK
case AV_CH_LAYOUT_7POINT1_WIDE_BACK:
return CHANNEL_LAYOUT_7_1_WIDE_BACK;
#endif
case AV_CH_LAYOUT_OCTAGONAL:
return CHANNEL_LAYOUT_OCTAGONAL;
default:
Expand Down
12 changes: 12 additions & 0 deletions media/media.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@
'filters/vpx_video_decoder.h',
],
}],
['use_system_ffmpeg == 1', {
'defines': [
'<!(python <(DEPTH)/tools/compile_test/compile_test.py '
'--code "#include <libavcodec/avcodec.h>\n'
'int test() { return CODEC_ID_OPUS; }" '
'--on-failure CHROMIUM_OMIT_CODEC_ID_OPUS)',
'<!(python <(DEPTH)/tools/compile_test/compile_test.py '
'--code "#include <libavcodec/avcodec.h>\n'
'int test() { return AV_CODEC_ID_VP9; }" '
'--on-failure CHROMIUM_OMIT_AV_CODEC_ID_VP9)',
],
}],
['OS == "ios"', {
'includes': [
# For shared_memory_support_sources variable.
Expand Down
57 changes: 57 additions & 0 deletions tools/compile_test/compile_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
# Copyright (c) 2013 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.

"""
Tries to compile given code, produces different output depending on success.
This is similar to checks done by ./configure scripts.
"""


import optparse
import os
import shutil
import subprocess
import sys
import tempfile


def DoMain(argv):
parser = optparse.OptionParser()
parser.add_option('--code')
parser.add_option('--on-success', default='')
parser.add_option('--on-failure', default='')

options, args = parser.parse_args(argv)

if not options.code:
parser.error('Missing required --code switch.')

cxx = os.environ.get('CXX', 'g++')

tmpdir = tempfile.mkdtemp()
try:
cxx_path = os.path.join(tmpdir, 'test.cc')
with open(cxx_path, 'w') as f:
f.write(options.code.decode('string-escape'))

o_path = os.path.join(tmpdir, 'test.o')

cxx_popen = subprocess.Popen([cxx, cxx_path, '-o', o_path, '-c'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
cxx_stdout, cxx_stderr = cxx_popen.communicate()
if cxx_popen.returncode == 0:
print options.on_success
else:
print options.on_failure
finally:
shutil.rmtree(tmpdir)

return 0


if __name__ == '__main__':
sys.exit(DoMain(sys.argv[1:]))

0 comments on commit b32da81

Please sign in to comment.