Skip to content

Commit

Permalink
Generate stubs for OpenMAX IL
Browse files Browse the repository at this point in the history
Generate stubs for OpenMAX IL so we don't need a real OpenMAX library for
building. The actual library is loaded during runtime.

TEST=Build is green
TEST=Running omx_test works on hardware with OpenMAX support

Review URL: http://codereview.chromium.org/661135

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40418 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hclam@chromium.org committed Mar 2, 2010
1 parent de945c8 commit 2ac1e7c
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 26 deletions.
9 changes: 8 additions & 1 deletion chrome/renderer/render_process.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 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.

Expand Down Expand Up @@ -31,6 +31,7 @@
#include "ipc/ipc_channel.h"
#include "ipc/ipc_message_utils.h"
#include "media/base/media.h"
#include "media/base/media_switches.h"
#include "native_client/src/trusted/plugin/nacl_entry_points.h"
#include "webkit/glue/webkit_glue.h"

Expand Down Expand Up @@ -105,6 +106,12 @@ RenderProcess::RenderProcess()
initialized_media_library_ =
PathService::Get(base::DIR_MODULE, &module_path) &&
media::InitializeMediaLibrary(module_path);

// TODO(hclam): Add more checks here. Currently this is not used.
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableOpenMax)) {
media::InitializeOpenMaxLibrary(module_path);
}
#endif
}

Expand Down
8 changes: 6 additions & 2 deletions media/base/media.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 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.

Expand All @@ -20,7 +20,11 @@ namespace media {
// Returns true if everything was successfully initialized, false otherwise.
bool InitializeMediaLibrary(const FilePath& module_dir);

// Attempts to initialize OpenMAX library.
//
// Returns true if OpenMAX was successfully initialized and loaded.
bool InitializeOpenMaxLibrary(const FilePath& module_dir);

} // namespace media

#endif // MEDIA_BASE_MEDIA_H_

33 changes: 32 additions & 1 deletion media/base/media_posix.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2010 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.

Expand All @@ -12,6 +12,10 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "third_party/ffmpeg/ffmpeg_stubs.h"
#if defined(OS_LINUX)
// OpenMAX IL stub is generated only on Linux.
#include "third_party/openmax/il_stubs.h"
#endif

namespace tp_ffmpeg = third_party_ffmpeg;

Expand All @@ -29,6 +33,7 @@ const FilePath::CharType sumo_name[] = FILE_PATH_LITERAL("libffmpegsumo.so");
#else
#error "Do not know how to construct DSO name for this OS."
#endif
const FilePath::CharType openmax_name[] = FILE_PATH_LITERAL("libOmxCore.so");

// Retrieves the DSOName for the given key.
std::string GetDSOName(tp_ffmpeg::StubModules stub_key) {
Expand Down Expand Up @@ -68,4 +73,30 @@ bool InitializeMediaLibrary(const FilePath& module_dir) {
return tp_ffmpeg::InitializeStubs(paths);
}

#if defined(OS_LINUX)
namespace tp_openmax = third_party_openmax;
bool InitializeOpenMaxLibrary(const FilePath& module_dir) {
// TODO(ajwong): We need error resolution.
tp_openmax::StubPathMap paths;
for (int i = 0; i < static_cast<int>(tp_openmax::kNumStubModules); ++i) {
tp_openmax::StubModules module = static_cast<tp_openmax::StubModules>(i);

// Add the OpenMAX library first so it takes precedence.
paths[module].push_back(module_dir.Append(openmax_name).value());
}

bool result = tp_openmax::InitializeStubs(paths);
if (!result) {
LOG(FATAL) << "Cannot load " << openmax_name << "."
<< " Make sure it exists for OpenMAX.";
}
return result;
}
#else
bool InitializeOpenMaxLibrary(const FilePath& module_dir) {
NOTIMPLEMENTED() << "OpenMAX is only used in Linux.";
return false;
}
#endif

} // namespace media
5 changes: 5 additions & 0 deletions media/base/media_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ bool InitializeMediaLibrary(const FilePath& base_path) {
return false;
}

bool InitializeOpenMaxLibrary(const FilePath& module_dir) {
NOTIMPLEMENTED() << "OpenMAX is not used in Windows.";
return false;
}

} // namespace media
6 changes: 6 additions & 0 deletions media/tools/omx_test/omx_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ int main(int argc, char** argv) {
loop_count = 1;
DCHECK_GE(loop_count, 1);

// Initialize OpenMAX.
if (!media::InitializeOpenMaxLibrary(FilePath())) {
LOG(ERROR) << "Unable to initialize OpenMAX library.";
return false;
}

// If FFmpeg should be used for demuxing load the library here and do
// the initialization.
if (use_ffmpeg && !InitFFmpeg()) {
Expand Down
8 changes: 8 additions & 0 deletions media/tools/player_x11/player_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ bool InitX11() {
bool InitPipeline(MessageLoop* message_loop,
const char* filename, bool enable_audio,
scoped_refptr<media::PipelineImpl>* pipeline) {
// Initialize OpenMAX.
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableOpenMax) &&
!media::InitializeOpenMaxLibrary(FilePath())) {
std::cout << "Unable to initialize OpenMAX library."<< std::endl;
return false;
}

// Load media libraries.
if (!media::InitializeMediaLibrary(FilePath())) {
std::cout << "Unable to initialize the media library." << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion third_party/ffmpeg/ffmpeg.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@
'targets': [
{
'variables': {
'generate_stubs_script': 'generate_stubs.py',
'generate_stubs_script': '../../tools/generate_stubs/generate_stubs.py',
'sig_files': [
# Note that these must be listed in dependency order.
# (i.e. if A depends on B, then B must be listed before A.)
Expand Down
11 changes: 11 additions & 0 deletions third_party/openmax/il.sigs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2010 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 OpenMAX IL used in Chromium code.

OMX_ERRORTYPE OMX_Init(void);
OMX_ERRORTYPE OMX_Deinit(void);
OMX_ERRORTYPE OMX_GetHandle(OMX_HANDLETYPE* pHandle, OMX_STRING cComponentName, OMX_PTR pAppData, OMX_CALLBACKTYPE* pCallBacks);
OMX_ERRORTYPE OMX_FreeHandle(OMX_HANDLETYPE hComponent);
OMX_ERRORTYPE OMX_GetComponentsOfRole (OMX_STRING role, OMX_U32* pNumComps, OMX_U8** compNames);
8 changes: 8 additions & 0 deletions third_party/openmax/il_stub_headers.fragment
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// These are some extra includes needed in the generated stub file for defining
// various OpenMAX types.

extern "C" {

#include "third_party/openmax/il/OMX_Core.h"

}
78 changes: 57 additions & 21 deletions third_party/openmax/openmax.gyp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Copyright (c) 2010 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.

Expand Down Expand Up @@ -26,9 +26,12 @@
'include_dirs': [
'il',
],
'defines': [
'__OMX_EXPORTS',
],
},
'conditions': [
['openmax_type=="stub"', {
['OS!="linux"', {
'type': '<(library)',
'dependencies': [
'../../base/base.gyp:base',
Expand All @@ -42,31 +45,64 @@
'defines': [
'__OMX_EXPORTS',
],
}],
['OS=="linux"', {
'variables': {
'generate_stubs_script': '../../tools/generate_stubs/generate_stubs.py',
'sig_files': [
'il.sigs',
],
'extra_header': 'il_stub_headers.fragment',
'outfile_type': 'posix_stubs',
'stubs_filename_root': 'il_stubs',
'project_path': 'third_party/openmax',
'intermediate_dir': '<(INTERMEDIATE_DIR)',
'output_root': '<(SHARED_INTERMEDIATE_DIR)/openmax',
},
'type': '<(library)',
'dependencies': [
'../../base/base.gyp:base',
],
'defines': [
'__OMX_EXPORTS',
],
'include_dirs': [
'il',
'<(output_root)',
'../..', # The chromium 'src' directory.
],
'direct_dependent_settings': {
'defines': [
'__OMX_EXPORTS',
'include_dirs': [
'<(output_root)',
'../..', # The chromium 'src' directory.
],
},
}],
['openmax_type=="bellagio"', {
'type': 'none',
'direct_dependent_settings': {
'link_settings': {
'libraries': [
'-lomxil-bellagio',
'actions': [
{
'action_name': 'generate_stubs',
'inputs': [
'<(generate_stubs_script)',
'<(extra_header)',
'<@(sig_files)',
],
},
},
}],
['openmax_type=="omxcore"', {
'type': 'none',
'direct_dependent_settings': {
'link_settings': {
'libraries': [
'-lOmxCore',
'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)',
],
'process_outputs_as_sources': 1,
'message': 'Generating OpenMAX IL stubs for dynamic loading.',
},
},
],
}],
],
},
Expand Down
File renamed without changes.

0 comments on commit 2ac1e7c

Please sign in to comment.