summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--media/DEPS2
-rw-r--r--media/base/media_posix.cc290
-rw-r--r--third_party/ffmpeg/avcodec-52.sigs18
-rw-r--r--third_party/ffmpeg/avformat-52.sigs12
-rw-r--r--third_party/ffmpeg/avutil-50.sigs9
-rwxr-xr-xthird_party/ffmpeg/ffmpeg.gyp139
-rw-r--r--third_party/ffmpeg/ffmpeg_stub_headers.fragment9
-rwxr-xr-xthird_party/ffmpeg/generate_stubs.py34
-rwxr-xr-xthird_party/ffmpeg/generate_stubs_unittest.py5
9 files changed, 195 insertions, 323 deletions
diff --git a/media/DEPS b/media/DEPS
index 2b2d7d8..3d2daa9 100644
--- a/media/DEPS
+++ b/media/DEPS
@@ -1,3 +1,3 @@
include_rules = [
- "+third_party/ffmpeg/include",
+ "+third_party/ffmpeg",
]
diff --git a/media/base/media_posix.cc b/media/base/media_posix.cc
index 9a964dd..51efbca 100644
--- a/media/base/media_posix.cc
+++ b/media/base/media_posix.cc
@@ -11,304 +11,46 @@
#include "base/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
-#include "media/filters/ffmpeg_common.h"
-
-// We create stub references to dynamically loaded functions in FFmpeg
-// for ease of linking.
-//
-// TODO(ajwong): We need to find a more maintainable way to have this work.
-// Also, this code should really be in the FFmpeg wrapper, and not here
-// in the media level. The concept of "weak symbols" looks like it might
-// be promising, but I don't quite understand it yet.
-//
-// TODO(scherkus): I am *this close* to writing the world's coolest macro to
-// make modifying this file easier.
-extern "C" {
-
-// libavcodec functions.
-void (*av_free_packet_ptr)(AVPacket* pkt) = NULL;
-void av_free_packet(AVPacket* pkt) {
- av_free_packet_ptr(pkt);
-}
-
-int (*av_get_bits_per_sample_format_ptr)(enum SampleFormat sample_fmt) = NULL;
-int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
- return av_get_bits_per_sample_format_ptr(sample_fmt);
-}
-
-void (*av_init_packet_ptr)(AVPacket* pkt) = NULL;
-void av_init_packet(AVPacket* pkt) {
- av_init_packet_ptr(pkt);
-}
-
-int (*av_new_packet_ptr)(AVPacket* pkt, int size) = NULL;
-int av_new_packet(AVPacket* pkt, int size) {
- return av_new_packet_ptr(pkt, size);
-}
-
-AVFrame* (*avcodec_alloc_frame_ptr)(void) = NULL;
-AVFrame* avcodec_alloc_frame(void) {
- return avcodec_alloc_frame_ptr();
-}
-
-int (*avcodec_decode_audio3_ptr)(AVCodecContext* avctx, int16_t* samples,
- int* frame_size_ptr, AVPacket* avpkt) = NULL;
-int avcodec_decode_audio3(AVCodecContext* avctx, int16_t* samples,
- int* frame_size_ptr, AVPacket* avpkt) {
- return avcodec_decode_audio3_ptr(avctx, samples, frame_size_ptr, avpkt);
-}
-
-int (*avcodec_decode_video2_ptr)(AVCodecContext* avctx, AVFrame* picture,
- int* got_picture_ptr, AVPacket* avpkt) = NULL;
-int avcodec_decode_video2(AVCodecContext* avctx, AVFrame* picture,
- int* got_picture_ptr, AVPacket* avpkt) {
- return avcodec_decode_video2_ptr(avctx, picture, got_picture_ptr, avpkt);
-}
-
-AVCodec* (*avcodec_find_decoder_ptr)(enum CodecID id) = NULL;
-AVCodec* avcodec_find_decoder(enum CodecID id) {
- return avcodec_find_decoder_ptr(id);
-}
-
-void (*avcodec_flush_buffers_ptr)(AVCodecContext *avctx) = NULL;
-void avcodec_flush_buffers(AVCodecContext *avctx) {
- avcodec_flush_buffers_ptr(avctx);
-}
-
-void (*avcodec_init_ptr)(void) = NULL;
-void avcodec_init(void) {
- avcodec_init_ptr();
-}
-
-int (*avcodec_open_ptr)(AVCodecContext* avctx, AVCodec* codec) = NULL;
-int avcodec_open(AVCodecContext* avctx, AVCodec* codec) {
- return avcodec_open_ptr(avctx, codec);
-}
-
-int (*avcodec_thread_init_ptr)(AVCodecContext* s, int thread_count) = NULL;
-int avcodec_thread_init(AVCodecContext* s, int thread_count) {
- return avcodec_thread_init_ptr(s, thread_count);
-}
-
-
-// libavformat functions.
-int (*av_find_stream_info_ptr)(AVFormatContext* ic) = NULL;
-int av_find_stream_info(AVFormatContext* ic) {
- return av_find_stream_info_ptr(ic);
-}
-
-int (*av_open_input_file_ptr)(AVFormatContext** ic_ptr, const char* filename,
- AVInputFormat* fmt, int buf_size,
- AVFormatParameters* ap) = NULL;
-int av_open_input_file(AVFormatContext** ic_ptr, const char* filename,
- AVInputFormat* fmt, int buf_size,
- AVFormatParameters* ap) {
- return av_open_input_file_ptr(ic_ptr, filename, fmt, buf_size, ap);
-}
-
-int (*av_read_frame_ptr)(AVFormatContext* s, AVPacket* pkt) = NULL;
-int av_read_frame(AVFormatContext* s, AVPacket* pkt) {
- return av_read_frame_ptr(s, pkt);
-}
-
-void (*av_register_all_ptr)(void) = NULL;
-void av_register_all(void) {
- av_register_all_ptr();
-}
-
-int (*av_register_protocol_ptr)(URLProtocol* protocol) = NULL;
-int av_register_protocol(URLProtocol* protocol) {
- return av_register_protocol_ptr(protocol);
-}
-
-int (*av_seek_frame_ptr)(AVFormatContext* s, int stream_index,
- int64_t timestamp, int flags) = NULL;
-int av_seek_frame(AVFormatContext* s, int stream_index,
- int64_t timestamp, int flags) {
- return av_seek_frame_ptr(s, stream_index, timestamp, flags);
-}
-
-
-// libavutil functions.
-void (*av_free_ptr)(void* ptr) = NULL;
-void av_free(void* ptr) {
- return av_free_ptr(ptr);
-}
-
-void* (*av_malloc_ptr)(unsigned int size) = NULL;
-void* av_malloc(unsigned int size) {
- return av_malloc_ptr(size);
-}
-
-int64_t (*av_rescale_q_ptr)(int64_t a, AVRational bq, AVRational cq) = NULL;
-int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) {
- return av_rescale_q_ptr(a, bq, cq);
-}
-
-} // extern "C"
+#include "third_party/ffmpeg/ffmpeg_stubs.h"
+namespace tp_ffmpeg = third_party_ffmpeg;
namespace media {
namespace {
-enum FFmpegDSOKeys {
- FILE_LIBAVCODEC, // full path to libavcodec media decoding library.
- FILE_LIBAVFORMAT, // full path to libavformat media parsing library.
- FILE_LIBAVUTIL, // full path to libavutil media utility library.
-};
-
-// Retrieves the DLLName for the given key.
-std::string GetDSOName(FFmpegDSOKeys dso_key) {
+// Retrieves the DSOName for the given key.
+std::string GetDSOName(tp_ffmpeg::StubModules stub_key) {
// TODO(ajwong): Do we want to lock to a specific ffmpeg version?
// TODO(port): These library names are incorrect for mac. We need .dynlib
// suffixes.
- switch (dso_key) {
- case FILE_LIBAVCODEC:
+ switch (stub_key) {
+ case tp_ffmpeg::kModuleAvcodec52:
return FILE_PATH_LITERAL("libavcodec.so.52");
- case FILE_LIBAVFORMAT:
+ case tp_ffmpeg::kModuleAvformat52:
return FILE_PATH_LITERAL("libavformat.so.52");
- case FILE_LIBAVUTIL:
+ case tp_ffmpeg::kModuleAvutil50:
return FILE_PATH_LITERAL("libavutil.so.50");
default:
- LOG(DFATAL) << "Invalid DSO key requested: " << dso_key;
+ LOG(DFATAL) << "Invalid stub module requested: " << stub_key;
return FILE_PATH_LITERAL("");
}
}
} // namespace
-// Attempts to initialize the media library (loading DLLs, DSOs, etc.).
+// Attempts to initialize the media library (loading DSOs, etc.).
// Returns true if everything was successfully initialized, false otherwise.
bool InitializeMediaLibrary(const FilePath& module_dir) {
// TODO(ajwong): We need error resolution.
- FFmpegDSOKeys path_keys[] = {
- FILE_LIBAVCODEC,
- FILE_LIBAVFORMAT,
- FILE_LIBAVUTIL
- };
- void* libs[arraysize(path_keys)] = {};
- for (size_t i = 0; i < arraysize(path_keys); ++i) {
- FilePath path = module_dir.Append(GetDSOName(path_keys[i]));
- libs[i] = dlopen(path.value().c_str(), RTLD_LAZY);
- if (!libs[i])
- break;
- }
-
- // Check that we loaded all libraries successfully. We only need to check the
- // last array element because the loop above breaks on any failure.
- if (libs[arraysize(libs)-1] == NULL) {
- // Free any loaded libraries if we weren't successful.
- for (size_t i = 0; i < arraysize(libs) && libs[i] != NULL; ++i) {
- dlclose(libs[i]);
- libs[i] = NULL; // Just to be safe.
- }
- return false;
- }
-
- // TODO(ajwong): Extract this to somewhere saner, and hopefully
- // autogenerate the bindings from the .def files. Having all this
- // code here is incredibly ugly.
-
- // libavcodec functions.
- av_free_packet_ptr =
- reinterpret_cast<void (*)(AVPacket*)>(
- dlsym(libs[FILE_LIBAVCODEC], "av_free_packet"));
- av_get_bits_per_sample_format_ptr =
- reinterpret_cast<int (*)(enum SampleFormat)>(
- dlsym(libs[FILE_LIBAVCODEC], "av_get_bits_per_sample_format"));
- av_init_packet_ptr =
- reinterpret_cast<void (*)(AVPacket*)>(
- dlsym(libs[FILE_LIBAVCODEC], "av_init_packet"));
- av_new_packet_ptr =
- reinterpret_cast<int (*)(AVPacket*, int)>(
- dlsym(libs[FILE_LIBAVCODEC], "av_new_packet"));
- avcodec_alloc_frame_ptr =
- reinterpret_cast<AVFrame* (*)(void)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_alloc_frame"));
- avcodec_decode_audio3_ptr =
- reinterpret_cast<int (*)(AVCodecContext*, int16_t*, int*, AVPacket*)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_decode_audio3"));
- avcodec_decode_video2_ptr =
- reinterpret_cast<int (*)(AVCodecContext*, AVFrame*, int*, AVPacket*)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_decode_video2"));
- avcodec_find_decoder_ptr =
- reinterpret_cast<AVCodec* (*)(enum CodecID)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_find_decoder"));
- avcodec_flush_buffers_ptr =
- reinterpret_cast<void (*)(AVCodecContext*)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_flush_buffers"));
- avcodec_init_ptr =
- reinterpret_cast<void (*)(void)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_init"));
- avcodec_open_ptr =
- reinterpret_cast<int (*)(AVCodecContext*, AVCodec*)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_open"));
- avcodec_thread_init_ptr =
- reinterpret_cast<int (*)(AVCodecContext*, int)>(
- dlsym(libs[FILE_LIBAVCODEC], "avcodec_thread_init"));
-
- // libavformat functions.
- av_find_stream_info_ptr =
- reinterpret_cast<int (*)(AVFormatContext*)>(
- dlsym(libs[FILE_LIBAVFORMAT], "av_find_stream_info"));
- av_open_input_file_ptr =
- reinterpret_cast<int (*)(AVFormatContext**, const char*,
- AVInputFormat*, int,
- AVFormatParameters*)>(
- dlsym(libs[FILE_LIBAVFORMAT], "av_open_input_file"));
- av_read_frame_ptr =
- reinterpret_cast<int (*)(AVFormatContext*, AVPacket*)>(
- dlsym(libs[FILE_LIBAVFORMAT], "av_read_frame"));
- av_register_all_ptr =
- reinterpret_cast<void (*)(void)>(
- dlsym(libs[FILE_LIBAVFORMAT], "av_register_all"));
- av_register_protocol_ptr =
- reinterpret_cast<int (*)(URLProtocol*)>(
- dlsym(libs[FILE_LIBAVFORMAT], "av_register_protocol"));
- av_seek_frame_ptr =
- reinterpret_cast<int (*)(AVFormatContext*, int, int64_t, int)>(
- dlsym(libs[FILE_LIBAVFORMAT], "av_seek_frame"));
-
- // libavutil functions.
- av_free_ptr =
- reinterpret_cast<void (*)(void*)>(
- dlsym(libs[FILE_LIBAVUTIL], "av_free"));
- av_malloc_ptr =
- reinterpret_cast<void* (*)(unsigned int)>(
- dlsym(libs[FILE_LIBAVUTIL], "av_malloc"));
- av_rescale_q_ptr =
- reinterpret_cast<int64_t (*)(int64_t, AVRational, AVRational)>(
- dlsym(libs[FILE_LIBAVUTIL], "av_rescale_q"));
-
- // Check that all the symbols were loaded correctly before returning true.
- if (av_free_packet_ptr &&
- av_get_bits_per_sample_format_ptr &&
- av_init_packet_ptr &&
- av_new_packet_ptr &&
- avcodec_alloc_frame_ptr &&
- avcodec_decode_audio3_ptr &&
- avcodec_decode_video2_ptr &&
- avcodec_find_decoder_ptr &&
- avcodec_flush_buffers_ptr &&
- avcodec_init_ptr &&
- avcodec_open_ptr &&
- avcodec_thread_init_ptr &&
-
- av_find_stream_info_ptr &&
- av_open_input_file_ptr &&
- av_read_frame_ptr &&
- av_register_all_ptr &&
- av_register_protocol_ptr &&
- av_seek_frame_ptr &&
-
- av_free_ptr &&
- av_malloc_ptr &&
- av_rescale_q_ptr) {
- return true;
+ tp_ffmpeg::StubPathMap paths;
+ for (int i = 0; i < static_cast<int>(tp_ffmpeg::kNumStubModules); ++i) {
+ tp_ffmpeg::StubModules module = static_cast<tp_ffmpeg::StubModules>(i);
+ FilePath path = module_dir.Append(GetDSOName(module));
+ paths[module].push_back(path.value());
}
- return false;
+ return tp_ffmpeg::InitializeStubs(paths);
}
} // namespace media
diff --git a/third_party/ffmpeg/avcodec-52.sigs b/third_party/ffmpeg/avcodec-52.sigs
new file mode 100644
index 0000000..27b8ef9
--- /dev/null
+++ b/third_party/ffmpeg/avcodec-52.sigs
@@ -0,0 +1,18 @@
+# Copyright (c) 2009 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.
+#
+# Functions from avcodec used in chromium code.
+
+AVCodec *avcodec_find_decoder(enum CodecID id);
+AVFrame *avcodec_alloc_frame(void);
+int av_get_bits_per_sample_format(enum SampleFormat sample_fmt);
+int av_new_packet(AVPacket *pkt, int size);
+int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, AVPacket *avpkt);
+int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt);
+int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
+int avcodec_thread_init(AVCodecContext *s, int thread_count);
+void av_free_packet(AVPacket *pkt);
+void av_init_packet(AVPacket *pkt);
+void avcodec_flush_buffers(AVCodecContext *avctx);
+void avcodec_init(void);
diff --git a/third_party/ffmpeg/avformat-52.sigs b/third_party/ffmpeg/avformat-52.sigs
new file mode 100644
index 0000000..5f7b193
--- /dev/null
+++ b/third_party/ffmpeg/avformat-52.sigs
@@ -0,0 +1,12 @@
+# Copyright (c) 2009 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.
+#
+# Functions from avformat used in chromium code.
+
+int av_find_stream_info(AVFormatContext *ic);
+int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap);
+int av_read_frame(AVFormatContext *s, AVPacket *pkt);
+int av_register_protocol(URLProtocol *protocol);
+int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
+void av_register_all(void);
diff --git a/third_party/ffmpeg/avutil-50.sigs b/third_party/ffmpeg/avutil-50.sigs
new file mode 100644
index 0000000..c83f6fa
--- /dev/null
+++ b/third_party/ffmpeg/avutil-50.sigs
@@ -0,0 +1,9 @@
+# Copyright (c) 2009 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.
+#
+# Functions from avutil used in chromium code.
+
+int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq);
+void *av_malloc(unsigned int size);
+void av_free(void *ptr);
diff --git a/third_party/ffmpeg/ffmpeg.gyp b/third_party/ffmpeg/ffmpeg.gyp
index 5a3d706..427e541 100755
--- a/third_party/ffmpeg/ffmpeg.gyp
+++ b/third_party/ffmpeg/ffmpeg.gyp
@@ -15,8 +15,16 @@
},
'targets': [
{
+ 'variables': {
+ 'generate_stubs_script': 'generate_stubs.py',
+ 'sig_files': [
+ 'avcodec-52.sigs',
+ 'avformat-52.sigs',
+ 'avutil-50.sigs',
+ ],
+ 'extra_header': 'ffmpeg_stub_headers.fragment',
+ },
'target_name': 'ffmpeg',
- 'type': 'none',
'msvs_guid': 'D7A94F58-576A-45D9-A45F-EB87C63ABBB0',
'sources': [
'include/libavcodec/avcodec.h',
@@ -43,57 +51,110 @@
'include/libavutil/sha1.h',
'include/win/inttypes.h',
'include/win/stdint.h',
+ '<@(sig_files)',
+ '<(extra_header)'
],
+ 'hard_dependency': 1,
'direct_dependent_settings': {
'include_dirs': [
'include',
],
},
'conditions': [
- ['OS=="win"', {
- 'sources': [
- 'avcodec-52.def',
- 'avformat-52.def',
- 'avutil-50.def',
- ],
- 'direct_dependent_settings': {
- 'include_dirs': [
- 'include/win',
+ ['OS=="win"',
+ {
+ 'variables': {
+ 'outfile_type': 'windows_lib',
+ 'output_dir': '<(PRODUCT_DIR)/lib',
+ 'intermediate_dir': '<(INTERMEDIATE_DIR)',
+ },
+ 'type': 'none',
+ 'dependencies': [
+ 'ffmpeg_binaries',
+ ],
+ 'sources!': [
+ '<(extra_header)',
],
- 'link_settings': {
- 'libraries': [
- '<(PRODUCT_DIR)/lib/avcodec-52.lib',
- '<(PRODUCT_DIR)/lib/avformat-52.lib',
- '<(PRODUCT_DIR)/lib/avutil-50.lib',
+ 'direct_dependent_settings': {
+ 'include_dirs': [
+ 'include/win',
],
+ 'link_settings': {
+ 'libraries': [
+ '<(output_dir)/avcodec-52.lib',
+ '<(output_dir)/avformat-52.lib',
+ '<(output_dir)/avutil-50.lib',
+ ],
+ },
},
- },
- 'dependencies': [
- 'ffmpeg_binaries',
- '../../build/win/system.gyp:cygwin',
- ],
- 'rules': [
- {
- 'rule_name': 'generate_libs',
- 'extension': 'def',
- 'inputs': [
- 'generate_libs.py',
- ],
- 'outputs': [
- '<(PRODUCT_DIR)/lib/<(RULE_INPUT_ROOT).lib',
- ],
- 'variables': {
- 'def_files': [
- 'avcodec-52.def',
- 'avformat-52.def',
- 'avutil-50.def',
+ 'rules': [
+ {
+ 'rule_name': 'generate_libs',
+ 'extension': 'sigs',
+ 'inputs': [
+ '<(generate_stubs_script)',
+ '<@(sig_files)',
+ ],
+ 'outputs': [
+ '<(output_dir)/<(RULE_INPUT_ROOT).lib',
],
+ 'action': ['python', '<(generate_stubs_script)',
+ '-i', '<(intermediate_dir)',
+ '-o', '<(output_dir)',
+ '-t', '<(outfile_type)',
+ '<@(RULE_INPUT_PATH)',
+ ],
+ 'message': 'Generating FFmpeg import libraries.',
},
- 'action': ['python', '<@(_inputs)', '-o', '<(PRODUCT_DIR)/lib', '<@(RULE_INPUT_PATH)'],
- 'message': 'Generating import libraries',
+ ],
+ }, { # else OS!="win"
+ 'variables': {
+ 'outfile_type': 'posix_stubs',
+ 'stubs_filename_root': 'ffmpeg_stubs',
+ 'project_path': 'third_party/ffmpeg',
+ 'intermediate_dir': '<(INTERMEDIATE_DIR)',
+ 'output_root': '<(SHARED_INTERMEDIATE_DIR)/ffmpeg',
},
- ],
- }],
+ 'type': '<(library)',
+ 'include_dirs': [
+ 'include',
+ '<(output_root)',
+ '../..', # The chromium 'src' directory.
+ ],
+ 'direct_dependent_settings': {
+ 'include_dirs': [
+ '<(output_root)',
+ '../..', # The chromium 'src' directory.
+ ],
+ },
+ 'actions': [
+ {
+ 'action_name': 'generate_stubs',
+ 'inputs': [
+ '<(generate_stubs_script)',
+ '<(extra_header)',
+ '<@(sig_files)',
+ ],
+ 'outputs': [
+ '<(intermediate_dir)/<(stubs_filename_root).cc',
+ '<(output_root)/<(project_path)/<(stubs_filename_root).h',
+ ],
+ 'action': ['python',
+ '<(generate_stubs_script)',
+ '-i', '<(intermediate_dir)',
+ '-o', '<(output_root)/<(project_path)',
+ '-t', '<(outfile_type)',
+ '-e', '<(extra_header)',
+ '-s', '<(stubs_filename_root)',
+ '-p', '<(project_path)',
+ '<@(_inputs)',
+ ],
+ 'message': 'Generating FFmpeg stubs for dynamic loading.',
+ 'process_outputs_as_sources': 1,
+ },
+ ],
+ }
+ ],
],
},
{
diff --git a/third_party/ffmpeg/ffmpeg_stub_headers.fragment b/third_party/ffmpeg/ffmpeg_stub_headers.fragment
new file mode 100644
index 0000000..99abcf7
--- /dev/null
+++ b/third_party/ffmpeg/ffmpeg_stub_headers.fragment
@@ -0,0 +1,9 @@
+// These are some extra includes needed in the generated stub file for defining
+// various FFmpeg types.
+
+extern "C" {
+
+#include "third_party/ffmpeg/include/libavcodec/avcodec.h"
+#include "third_party/ffmpeg/include/libavformat/avformat.h"
+
+}
diff --git a/third_party/ffmpeg/generate_stubs.py b/third_party/ffmpeg/generate_stubs.py
index 1288697..b1a6385 100755
--- a/third_party/ffmpeg/generate_stubs.py
+++ b/third_party/ffmpeg/generate_stubs.py
@@ -144,16 +144,18 @@ class WindowsLibCreator(object):
logic.
"""
- def __init__(self, module_name, signatures, outdir_path):
+ def __init__(self, module_name, signatures, intermediate_dir, outdir_path):
"""Initializes the WindowsLibCreator for creating a library stub.
Args:
module_name: The name of the module we are writing a stub for.
signatures: The list of signatures to create stubs for.
- outdir_path: The directory that generated files should go into.
+ intermediate_dir: The directory where the generated .def files should go.
+ outdir_path: The directory where generated .lib files should go.
"""
self.module_name = module_name
self.signatures = signatures
+ self.intermediate_dir = intermediate_dir
self.outdir_path = outdir_path
def DefFilePath(self):
@@ -163,7 +165,7 @@ class WindowsLibCreator(object):
A string with the path to the def file.
"""
# Output file name is in the form "module_name.def".
- return '%s/%s.def' % (self.outdir_path, self.module_name)
+ return '%s/%s.def' % (self.intermediate_dir, self.module_name)
def LibFilePath(self):
"""Generates the path of the lib file for the given module_name.
@@ -575,6 +577,7 @@ void %s();
// Umbrella initializer for all the modules in this stub file.
bool InitializeStubs(const StubPathMap& path_map);
+
} // namespace %s
#endif // %s
@@ -588,15 +591,17 @@ bool InitializeStubs(const StubPathMap& path_map);
outfile: The file handle to populate.
"""
outfile.write('extern "C" {\n')
+ outfile.write('\n')
self.WriteFunctionPointers(outfile)
self.WriteStubFunctions(outfile)
+ outfile.write('\n')
outfile.write('} // extern "C"\n')
outfile.write('\n')
outfile.write('namespace %s {\n' % namespace)
outfile.write('\n')
self.WriteModuleInitializeFunctions(outfile)
- outfile.write('} // namespace %s\n' % namespace)
+ outfile.write('} // namespace %s\n\n' % namespace)
def WriteFunctionPointers(self, outfile):
"""Write the function pointer declarations needed by the stubs.
@@ -704,6 +709,11 @@ def main():
dest='out_dir',
default=None,
help='Output location.')
+ parser.add_option('-i',
+ '--intermediate_dir',
+ dest='intermediate_dir',
+ default=None,
+ help='Locaiton of intermediate files.')
parser.add_option('-t',
'--type',
dest='type',
@@ -738,7 +748,7 @@ def main():
if options.out_dir is None:
parser.error('Output location not specified')
- if args:
+ if len(args) == 0:
parser.error('No inputs specified')
if options.type not in [FILE_TYPE_WIN, FILE_TYPE_POSIX_STUB]:
@@ -750,10 +760,17 @@ def main():
if options.path_from_source is None:
parser.error('Path from source needed for %s' % FILE_TYPE_POSIX_STUB)
- # Make sure output directory exists.
+ # Get the names for the output directory and intermdiate directory.
out_dir = RemoveTrailingSlashes(options.out_dir)
+ intermediate_dir = RemoveTrailingSlashes(options.intermediate_dir)
+ if intermediate_dir is None:
+ intermediate_dir = out_dir
+
+ # Make sure the directories exists.
if not os.path.exists(out_dir):
os.makedirs(out_dir)
+ if not os.path.exists(intermediate_dir):
+ os.makedirs(intermediate_dir)
if options.type == FILE_TYPE_WIN:
for input_path in args:
@@ -761,7 +778,7 @@ def main():
infile = open(input_path, 'r')
signatures = ParseSignatures(infile)
module_name = ExtractModuleName(os.path.basename(input_path))
- WindowsLibCreator(module_name, signatures, out_dir).CreateLib()
+ WindowsLibCreator(module_name, signatures, intermediate_dir, out_dir).CreateLib()
finally:
if infile is not None:
infile.close()
@@ -770,7 +787,7 @@ def main():
header_path = PosixStubWriter.HeaderFilePath(options.stubfile_name,
out_dir)
impl_path = PosixStubWriter.ImplementationFilePath(options.stubfile_name,
- out_dir)
+ intermediate_dir)
# Generate some convenience variables for bits of data needed below.
module_names = [ExtractModuleName(path) for path in args]
@@ -788,6 +805,7 @@ def main():
impl_file)
if options.extra_stub_header is not None:
try:
+ impl_file.write('\n')
extra_header_file = open(options.extra_stub_header, 'r')
for line in extra_header_file:
impl_file.write(line)
diff --git a/third_party/ffmpeg/generate_stubs_unittest.py b/third_party/ffmpeg/generate_stubs_unittest.py
index ccaa35b..b68175e 100755
--- a/third_party/ffmpeg/generate_stubs_unittest.py
+++ b/third_party/ffmpeg/generate_stubs_unittest.py
@@ -136,12 +136,15 @@ class WindowsLibCreatorUnittest(unittest.TestCase):
self.module_name = 'my_module-1'
self.signatures = [sig[1] for sig in SIMPLE_SIGNATURES]
self.out_dir = 'out_dir'
+ self.intermediate_dir = 'intermediate_dir'
self.creator = gs.WindowsLibCreator(self.module_name,
self.signatures,
+ self.intermediate_dir,
self.out_dir)
def testDefFilePath(self):
- self.assertEqual('out_dir/my_module-1.def', self.creator.DefFilePath())
+ self.assertEqual('intermediate_dir/my_module-1.def',
+ self.creator.DefFilePath())
def testLibFilePath(self):
self.assertEqual('out_dir/my_module-1.lib', self.creator.LibFilePath())