Clean creation of VideoEngine:
- clean a static variable just used to debug and not so necessary IMO. - clean a really ugly reinterpret cast - clean a extern "C" code and loading of dlls which is no longer in use. Review URL: https://webrtc-codereview.appspot.com/1385006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3986 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
6155be2c61
commit
44272739c2
@ -9,12 +9,6 @@
|
||||
*/
|
||||
|
||||
#include "video_engine/vie_impl.h"
|
||||
|
||||
#if (defined(WIN32_) || defined(WIN64_))
|
||||
#include <Windows.h> // For LoadLibrary.
|
||||
#include <tchar.h> // For T_.
|
||||
#endif
|
||||
|
||||
#include "system_wrappers/interface/trace.h"
|
||||
|
||||
#ifdef WEBRTC_ANDROID
|
||||
@ -22,66 +16,35 @@
|
||||
#include "webrtc/modules/video_render/include/video_render.h"
|
||||
#endif
|
||||
|
||||
// Global counter to get an id for each new ViE instance.
|
||||
static int32_t g_vie_active_instance_counter = 0;
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// extern "C" ensures that GetProcAddress() can find the function address.
|
||||
extern "C" {
|
||||
VideoEngine* GetVideoEngine() {
|
||||
VideoEngineImpl* self = new VideoEngineImpl();
|
||||
if (!self) {
|
||||
return NULL;
|
||||
}
|
||||
g_vie_active_instance_counter++;
|
||||
VideoEngine* vie = reinterpret_cast<VideoEngine*>(self);
|
||||
return vie;
|
||||
}
|
||||
}
|
||||
enum { kModuleId = 0 };
|
||||
|
||||
VideoEngine* VideoEngine::Create() {
|
||||
#if (defined(WIN32_) || defined(WIN64_))
|
||||
// Load a debug dll, if there is one.
|
||||
HMODULE hmod_ = LoadLibrary(TEXT("VideoEngineTestingDLL.dll"));
|
||||
if (hmod_) {
|
||||
typedef VideoEngine* (*PFNGetVideoEngineLib)(void);
|
||||
PFNGetVideoEngineLib pfn =
|
||||
(PFNGetVideoEngineLib)GetProcAddress(hmod_, "GetVideoEngine");
|
||||
if (pfn) {
|
||||
VideoEngine* self = pfn();
|
||||
return self;
|
||||
} else {
|
||||
assert(false && "Failed to open test dll VideoEngineTestingDLL.dll");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return GetVideoEngine();
|
||||
return new VideoEngineImpl();
|
||||
}
|
||||
|
||||
bool VideoEngine::Delete(VideoEngine*& video_engine) {
|
||||
if (!video_engine) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"VideoEngine::Delete - No argument");
|
||||
return false;
|
||||
}
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
|
||||
"VideoEngine::Delete(vie = 0x%p)", video_engine);
|
||||
VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine);
|
||||
|
||||
// Check all reference counters.
|
||||
ViEBaseImpl* vie_base = vie_impl;
|
||||
if (vie_base->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViEBase ref count: %d", vie_base->GetCount());
|
||||
return false;
|
||||
}
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API
|
||||
ViECaptureImpl* vie_capture = vie_impl;
|
||||
if (vie_capture->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViECapture ref count: %d", vie_capture->GetCount());
|
||||
return false;
|
||||
}
|
||||
@ -89,7 +52,7 @@ bool VideoEngine::Delete(VideoEngine*& video_engine) {
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_CODEC_API
|
||||
ViECodecImpl* vie_codec = vie_impl;
|
||||
if (vie_codec->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViECodec ref count: %d", vie_codec->GetCount());
|
||||
return false;
|
||||
}
|
||||
@ -97,7 +60,7 @@ bool VideoEngine::Delete(VideoEngine*& video_engine) {
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_ENCRYPTION_API
|
||||
ViEEncryptionImpl* vie_encryption = vie_impl;
|
||||
if (vie_encryption->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViEEncryption ref count: %d", vie_encryption->GetCount());
|
||||
return false;
|
||||
}
|
||||
@ -105,7 +68,7 @@ bool VideoEngine::Delete(VideoEngine*& video_engine) {
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API
|
||||
ViEExternalCodecImpl* vie_external_codec = vie_impl;
|
||||
if (vie_external_codec->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViEEncryption ref count: %d", vie_encryption->GetCount());
|
||||
return false;
|
||||
}
|
||||
@ -113,7 +76,7 @@ bool VideoEngine::Delete(VideoEngine*& video_engine) {
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_FILE_API
|
||||
ViEFileImpl* vie_file = vie_impl;
|
||||
if (vie_file->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViEFile ref count: %d", vie_file->GetCount());
|
||||
return false;
|
||||
}
|
||||
@ -121,7 +84,7 @@ bool VideoEngine::Delete(VideoEngine*& video_engine) {
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_IMAGE_PROCESS_API
|
||||
ViEImageProcessImpl* vie_image_process = vie_impl;
|
||||
if (vie_image_process->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViEImageProcess ref count: %d",
|
||||
vie_image_process->GetCount());
|
||||
return false;
|
||||
@ -129,14 +92,14 @@ bool VideoEngine::Delete(VideoEngine*& video_engine) {
|
||||
#endif
|
||||
ViENetworkImpl* vie_network = vie_impl;
|
||||
if (vie_network->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViENetwork ref count: %d", vie_network->GetCount());
|
||||
return false;
|
||||
}
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_RENDER_API
|
||||
ViERenderImpl* vie_render = vie_impl;
|
||||
if (vie_render->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViERender ref count: %d", vie_render->GetCount());
|
||||
return false;
|
||||
}
|
||||
@ -144,7 +107,7 @@ bool VideoEngine::Delete(VideoEngine*& video_engine) {
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_RTP_RTCP_API
|
||||
ViERTP_RTCPImpl* vie_rtp_rtcp = vie_impl;
|
||||
if (vie_rtp_rtcp->GetCount() > 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"ViERTP_RTCP ref count: %d", vie_rtp_rtcp->GetCount());
|
||||
return false;
|
||||
}
|
||||
@ -154,12 +117,8 @@ bool VideoEngine::Delete(VideoEngine*& video_engine) {
|
||||
vie_impl = NULL;
|
||||
video_engine = NULL;
|
||||
|
||||
// Decrease the number of instances.
|
||||
g_vie_active_instance_counter--;
|
||||
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVideo, g_vie_active_instance_counter,
|
||||
"%s: instance deleted. Remaining instances: %d", __FUNCTION__,
|
||||
g_vie_active_instance_counter);
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVideo, kModuleId,
|
||||
"%s: instance deleted.", __FUNCTION__);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -171,7 +130,7 @@ int VideoEngine::SetTraceFile(const char* file_nameUTF8,
|
||||
if (Trace::SetTraceFile(file_nameUTF8, add_file_counter) == -1) {
|
||||
return -1;
|
||||
}
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
|
||||
"SetTraceFileName(file_nameUTF8 = %s, add_file_counter = %d",
|
||||
file_nameUTF8, add_file_counter);
|
||||
return 0;
|
||||
@ -183,15 +142,15 @@ int VideoEngine::SetTraceFilter(const unsigned int filter) {
|
||||
|
||||
if (filter == kTraceNone && old_filter != kTraceNone) {
|
||||
// Do the logging before turning it off.
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
|
||||
"SetTraceFilter(filter = 0x%x)", filter);
|
||||
}
|
||||
|
||||
int32_t error = Trace::SetLevelFilter(filter);
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
|
||||
"SetTraceFilter(filter = 0x%x)", filter);
|
||||
if (error != 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"SetTraceFilter error: %d", error);
|
||||
return -1;
|
||||
}
|
||||
@ -199,29 +158,29 @@ int VideoEngine::SetTraceFilter(const unsigned int filter) {
|
||||
}
|
||||
|
||||
int VideoEngine::SetTraceCallback(TraceCallback* callback) {
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
|
||||
"SetTraceCallback(TraceCallback = 0x%p)", callback);
|
||||
return Trace::SetTraceCallback(callback);
|
||||
}
|
||||
|
||||
int VideoEngine::SetAndroidObjects(void* javaVM, void* javaContext) {
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
|
||||
"SetAndroidObjects()");
|
||||
|
||||
#if defined(WEBRTC_ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
|
||||
if (SetCaptureAndroidVM(javaVM, javaContext) != 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"Could not set capture Android VM");
|
||||
return -1;
|
||||
}
|
||||
if (SetRenderAndroidVM(javaVM) != 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"Could not set render Android VM");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, g_vie_active_instance_counter,
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
|
||||
"WEBRTC_ANDROID not defined for VideoEngine::SetAndroidObjects");
|
||||
return -1;
|
||||
#endif
|
||||
|
@ -45,32 +45,33 @@
|
||||
namespace webrtc {
|
||||
|
||||
class VideoEngineImpl
|
||||
: public ViEBaseImpl
|
||||
: public ViEBaseImpl,
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_CODEC_API
|
||||
, public ViECodecImpl
|
||||
public ViECodecImpl,
|
||||
#endif
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API
|
||||
, public ViECaptureImpl
|
||||
public ViECaptureImpl,
|
||||
#endif
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_ENCRYPTION_API
|
||||
, public ViEEncryptionImpl
|
||||
public ViEEncryptionImpl,
|
||||
#endif
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_FILE_API
|
||||
, public ViEFileImpl
|
||||
public ViEFileImpl,
|
||||
#endif
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_IMAGE_PROCESS_API
|
||||
, public ViEImageProcessImpl
|
||||
public ViEImageProcessImpl,
|
||||
#endif
|
||||
, public ViENetworkImpl
|
||||
public ViENetworkImpl,
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_RENDER_API
|
||||
, public ViERenderImpl
|
||||
public ViERenderImpl,
|
||||
#endif
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_RTP_RTCP_API
|
||||
, public ViERTP_RTCPImpl
|
||||
public ViERTP_RTCPImpl,
|
||||
#endif
|
||||
#ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API
|
||||
, public ViEExternalCodecImpl
|
||||
public ViEExternalCodecImpl,
|
||||
#endif
|
||||
public VideoEngine
|
||||
{ // NOLINT
|
||||
public:
|
||||
VideoEngineImpl()
|
||||
|
Loading…
Reference in New Issue
Block a user