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
3 // found in the LICENSE file.
5 #include "media/base/media.h"
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/strings/stringize_macros.h"
12 #include "media/ffmpeg/ffmpeg_common.h"
13 #include "third_party/ffmpeg/ffmpeg_stubs.h"
15 using third_party_ffmpeg::kNumStubModules
;
16 using third_party_ffmpeg::kModuleFfmpegsumo
;
17 using third_party_ffmpeg::InitializeStubs
;
18 using third_party_ffmpeg::StubPathMap
;
23 // Handy to prevent shooting ourselves in the foot with macro wizardry.
24 #if !defined(LIBAVCODEC_VERSION_MAJOR) || \
25 !defined(LIBAVFORMAT_VERSION_MAJOR) || \
26 !defined(LIBAVUTIL_VERSION_MAJOR)
27 #error FFmpeg headers not included!
30 #define AVCODEC_VERSION STRINGIZE(LIBAVCODEC_VERSION_MAJOR)
31 #define AVFORMAT_VERSION STRINGIZE(LIBAVFORMAT_VERSION_MAJOR)
32 #define AVUTIL_VERSION STRINGIZE(LIBAVUTIL_VERSION_MAJOR)
34 #if defined(OS_MACOSX)
35 // TODO(evan): should be using .so like ffmepgsumo here.
36 #define DSO_NAME(MODULE, VERSION) ("lib" MODULE "." VERSION ".dylib")
37 static const base::FilePath::CharType kSumoLib
[] =
38 FILE_PATH_LITERAL("ffmpegsumo.so");
39 #elif defined(OS_POSIX)
40 #define DSO_NAME(MODULE, VERSION) ("lib" MODULE ".so." VERSION)
41 static const base::FilePath::CharType kSumoLib
[] =
42 FILE_PATH_LITERAL("libffmpegsumo.so");
44 #error "Do not know how to construct DSO name for this OS."
47 bool InitializeMediaLibraryInternal(const base::FilePath
& module_dir
) {
50 // First try to initialize with Chrome's sumo library.
51 DCHECK_EQ(kNumStubModules
, 1);
52 paths
[kModuleFfmpegsumo
].push_back(module_dir
.Append(kSumoLib
).value());
54 // If that fails, see if any system libraries are available.
55 paths
[kModuleFfmpegsumo
].push_back(module_dir
.Append(
56 FILE_PATH_LITERAL(DSO_NAME("avutil", AVUTIL_VERSION
))).value());
57 paths
[kModuleFfmpegsumo
].push_back(module_dir
.Append(
58 FILE_PATH_LITERAL(DSO_NAME("avcodec", AVCODEC_VERSION
))).value());
59 paths
[kModuleFfmpegsumo
].push_back(module_dir
.Append(
60 FILE_PATH_LITERAL(DSO_NAME("avformat", AVFORMAT_VERSION
))).value());
62 return InitializeStubs(paths
);
65 } // namespace internal