This source file includes following definitions.
- GetCategoryGroupEnabled
- AddTraceEvent
- InitializeWebRtcModule
- GetLibPeerConnectionPath
- InitializeWebRtcModule
- CreateWebRtcMediaEngine
- DestroyWebRtcMediaEngine
#include "init_webrtc.h"
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/native_library.h"
#include "base/path_service.h"
#include "talk/base/basictypes.h"
#include "third_party/libjingle/overrides/talk/base/logging.h"
const unsigned char* GetCategoryGroupEnabled(const char* category_group) {
return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group);
}
void AddTraceEvent(char phase,
const unsigned char* category_group_enabled,
const char* name,
unsigned long long id,
int num_args,
const char** arg_names,
const unsigned char* arg_types,
const unsigned long long* arg_values,
unsigned char flags) {
TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, id,
num_args, arg_names, arg_types, arg_values,
NULL, flags);
}
#if defined(LIBPEERCONNECTION_LIB)
bool InitializeWebRtcModule() {
webrtc::SetupEventTracer(&GetCategoryGroupEnabled, &AddTraceEvent);
return true;
}
#else
CreateWebRtcMediaEngineFunction g_create_webrtc_media_engine = NULL;
DestroyWebRtcMediaEngineFunction g_destroy_webrtc_media_engine = NULL;
static base::FilePath GetLibPeerConnectionPath() {
base::FilePath path;
CHECK(PathService::Get(base::DIR_MODULE, &path));
#if defined(OS_WIN)
path = path.Append(FILE_PATH_LITERAL("libpeerconnection.dll"));
#elif defined(OS_MACOSX)
path = path.Append(FILE_PATH_LITERAL("Libraries"))
.Append(FILE_PATH_LITERAL("libpeerconnection.so"));
#elif defined(OS_ANDROID)
path = path.Append(FILE_PATH_LITERAL("libpeerconnection.so"));
#else
path = path.Append(FILE_PATH_LITERAL("lib"))
.Append(FILE_PATH_LITERAL("libpeerconnection.so"));
#endif
return path;
}
bool InitializeWebRtcModule() {
TRACE_EVENT0("webrtc", "InitializeWebRtcModule");
if (g_create_webrtc_media_engine)
return true;
base::FilePath path(GetLibPeerConnectionPath());
DVLOG(1) << "Loading WebRTC module: " << path.value();
base::NativeLibraryLoadError error;
static base::NativeLibrary lib = base::LoadNativeLibrary(path, &error);
#if defined(OS_WIN)
if (error.code == ERROR_MOD_NOT_FOUND) {
CHECK(base::PathExists(path));
CHECK(lib);
} else if (error.code == ERROR_ACCESS_DENIED) {
CHECK(lib);
}
#endif
CHECK(lib) << error.ToString();
InitializeModuleFunction initialize_module =
reinterpret_cast<InitializeModuleFunction>(
base::GetFunctionPointerFromNativeLibrary(
lib, "InitializeModule"));
InitDiagnosticLoggingDelegateFunctionFunction init_diagnostic_logging = NULL;
bool init_ok = initialize_module(*CommandLine::ForCurrentProcess(),
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
&Allocate, &Dellocate,
#endif
logging::GetLogMessageHandler(),
&GetCategoryGroupEnabled, &AddTraceEvent,
&g_create_webrtc_media_engine, &g_destroy_webrtc_media_engine,
&init_diagnostic_logging);
if (init_ok)
talk_base::SetExtraLoggingInit(init_diagnostic_logging);
return init_ok;
}
cricket::MediaEngineInterface* CreateWebRtcMediaEngine(
webrtc::AudioDeviceModule* adm,
webrtc::AudioDeviceModule* adm_sc,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory) {
InitializeWebRtcModule();
return g_create_webrtc_media_engine(adm, adm_sc, encoder_factory,
decoder_factory);
}
void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine) {
g_destroy_webrtc_media_engine(media_engine);
}
#endif