Refactored vie_manager_base.*.

The other files are only due to inheritance and will be refactored later. Same goes for pointer, references and function arguments.

Review URL: http://webrtc-codereview.appspot.com/318003

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1178 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2011-12-14 08:18:42 +00:00
parent 6d609b59f3
commit 9a8fa4e65d
5 changed files with 101 additions and 131 deletions

View File

@ -36,19 +36,19 @@ ViEChannelManagerScoped::ViEChannelManagerScoped(
ViEChannel* ViEChannelManagerScoped::Channel(int vieChannelId) const
{
return static_cast<const ViEChannelManager*>
(_vieManager)->ViEChannelPtr(vieChannelId);
return static_cast<const ViEChannelManager*>(vie_manager_)->ViEChannelPtr(
vieChannelId);
}
ViEEncoder* ViEChannelManagerScoped::Encoder(int vieChannelId) const
{
return static_cast<const ViEChannelManager*>
(_vieManager)->ViEEncoderPtr(vieChannelId);
return static_cast<const ViEChannelManager*>(vie_manager_)->ViEEncoderPtr(
vieChannelId);
}
bool ViEChannelManagerScoped::ChannelUsingViEEncoder(int channelId) const
{
return (static_cast<const ViEChannelManager*>
(_vieManager))->ChannelUsingViEEncoder( channelId);
return (static_cast<const ViEChannelManager*>(vie_manager_))->
ChannelUsingViEEncoder(channelId);
}
// ============================================================================

View File

@ -784,24 +784,24 @@ ViEInputManagerScoped::ViEInputManagerScoped(
ViECapturer* ViEInputManagerScoped::Capture(int captureId) const
{
return static_cast<const ViEInputManager*>
(_vieManager)->ViECapturePtr(captureId);
(vie_manager_)->ViECapturePtr(captureId);
}
ViEFrameProviderBase* ViEInputManagerScoped::FrameProvider(
const ViEFrameCallback* captureObserver) const
{
return static_cast<const ViEInputManager*>
(_vieManager)->ViEFrameProvider(captureObserver);
(vie_manager_)->ViEFrameProvider(captureObserver);
}
ViEFrameProviderBase* ViEInputManagerScoped::FrameProvider(int providerId) const
{
return static_cast<const ViEInputManager*>
(_vieManager)->ViEFrameProvider( providerId);
(vie_manager_)->ViEFrameProvider( providerId);
}
ViEFilePlayer* ViEInputManagerScoped::FilePlayer(int fileId) const
{
return static_cast<const ViEInputManager*>
(_vieManager)->ViEFilePlayerPtr(fileId);
(vie_manager_)->ViEFilePlayerPtr(fileId);
}
} // namespace webrtc

View File

@ -8,106 +8,65 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "vie_manager_base.h"
#include "rw_lock_wrapper.h"
#include "assert.h"
#include "system_wrappers/interface/rw_lock_wrapper.h"
#include "video_engine/vie_manager_base.h"
namespace webrtc {
ViEManagerBase::ViEManagerBase() :
_instanceRWLock(*RWLockWrapper::CreateRWLock())
{
}
ViEManagerBase::~ViEManagerBase()
{
delete &_instanceRWLock;
ViEManagerBase::ViEManagerBase()
: instance_rwlock_(*RWLockWrapper::CreateRWLock()) {
}
// ----------------------------------------------------------------------------
// ReadLockManager
//
// Lock count increase. Used by ViEManagerScopedBase
// ----------------------------------------------------------------------------
void ViEManagerBase::ReadLockManager() const
{
_instanceRWLock.AcquireLockShared();
ViEManagerBase::~ViEManagerBase() {
delete &instance_rwlock_;
}
// ----------------------------------------------------------------------------
// ReleaseLockManager
//
// Releases the lock count.
// ----------------------------------------------------------------------------
void ViEManagerBase::ReleaseLockManager() const
{
_instanceRWLock.ReleaseLockShared();
void ViEManagerBase::ReadLockManager() const {
instance_rwlock_.AcquireLockShared();
}
// ----------------------------------------------------------------------------
// WriteLockManager
//
// Lock count increase. Used by ViEManagerWriteScoped
// ----------------------------------------------------------------------------
void ViEManagerBase::WriteLockManager()
{
_instanceRWLock.AcquireLockExclusive();
void ViEManagerBase::ReleaseLockManager() const {
instance_rwlock_.ReleaseLockShared();
}
// ----------------------------------------------------------------------------
// ReleaseLockManager
//
// Releases the lock count.
// ----------------------------------------------------------------------------
void ViEManagerBase::ReleaseWriteLockManager()
{
_instanceRWLock.ReleaseLockExclusive();
void ViEManagerBase::WriteLockManager() {
instance_rwlock_.AcquireLockExclusive();
}
// ----------------------------------------------------------------------------
// ViEManagerScopedBase
//
// ----------------------------------------------------------------------------
ViEManagerScopedBase::ViEManagerScopedBase(const ViEManagerBase& ViEManagerBase) :
_vieManager(&ViEManagerBase), _refCount(0)
{
_vieManager->ReadLockManager();
void ViEManagerBase::ReleaseWriteLockManager() {
instance_rwlock_.ReleaseLockExclusive();
}
ViEManagerScopedBase::~ViEManagerScopedBase()
{
assert(_refCount==0);
_vieManager->ReleaseLockManager();
ViEManagerScopedBase::ViEManagerScopedBase(const ViEManagerBase& ViEManagerBase)
: vie_manager_(&ViEManagerBase),
ref_count_(0) {
vie_manager_->ReadLockManager();
}
// ----------------------------------------------------------------------------
///
// ViEManagerWriteScoped
//
// ----------------------------------------------------------------------------
ViEManagerWriteScoped::ViEManagerWriteScoped(ViEManagerBase& vieManager) :
_vieManager(&vieManager)
{
_vieManager->WriteLockManager();
ViEManagerScopedBase::~ViEManagerScopedBase() {
assert(ref_count_ == 0);
vie_manager_->ReleaseLockManager();
}
ViEManagerWriteScoped::~ViEManagerWriteScoped()
{
_vieManager->ReleaseWriteLockManager();
ViEManagerWriteScoped::ViEManagerWriteScoped(ViEManagerBase& vie_manager)
: vie_manager_(&vie_manager) {
vie_manager_->WriteLockManager();
}
ViEManagerWriteScoped::~ViEManagerWriteScoped() {
vie_manager_->ReleaseWriteLockManager();
}
// ----------------------------------------------------------------------------
// ViEManagedItemScopedBase
//
// ----------------------------------------------------------------------------
ViEManagedItemScopedBase::ViEManagedItemScopedBase(
ViEManagerScopedBase& vieScopedManager) :
_vieScopedManager(vieScopedManager)
{
_vieScopedManager._refCount++;
ViEManagerScopedBase& vie_scoped_manager)
: vie_scoped_manager_(vie_scoped_manager) {
vie_scoped_manager_.ref_count_++;
}
ViEManagedItemScopedBase::~ViEManagedItemScopedBase()
{
_vieScopedManager._refCount--;
ViEManagedItemScopedBase::~ViEManagedItemScopedBase() {
vie_scoped_manager_.ref_count_--;
}
} // namespace webrtc
} // namespace webrtc

View File

@ -8,56 +8,67 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_MANAGER_BASE_H_
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_MANAGER_BASE_H_
#ifndef WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_
#define WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_
namespace webrtc {
class RWLockWrapper;
class ViEManagerBase
{
friend class ViEManagerScopedBase;
friend class ViEManagedItemScopedBase;
friend class ViEManagerWriteScoped;
public:
ViEManagerBase(void);
~ViEManagerBase(void);
private:
void WriteLockManager();
void ReleaseWriteLockManager();
void ReadLockManager() const;
void ReleaseLockManager() const;
RWLockWrapper& _instanceRWLock;
class ViEManagerBase {
friend class ViEManagerScopedBase;
friend class ViEManagedItemScopedBase;
friend class ViEManagerWriteScoped;
public:
ViEManagerBase();
~ViEManagerBase();
private:
// Exclusive lock, used by ViEManagerWriteScoped
void WriteLockManager();
// Releases exclusive lock, used by ViEManagerWriteScoped.
void ReleaseWriteLockManager();
// Increases lock count, used by ViEManagerScopedBase.
void ReadLockManager() const;
// Releases the lock count, used by ViEManagerScopedBase.
void ReleaseLockManager() const;
RWLockWrapper& instance_rwlock_;
};
class ViEManagerWriteScoped
{
public:
ViEManagerWriteScoped(ViEManagerBase& vieManager);
~ViEManagerWriteScoped();
private:
ViEManagerBase* _vieManager;
class ViEManagerWriteScoped {
public:
explicit ViEManagerWriteScoped(ViEManagerBase& vie_manager);
~ViEManagerWriteScoped();
private:
ViEManagerBase* vie_manager_;
};
class ViEManagerScopedBase
{
friend class ViEManagedItemScopedBase;
public:
ViEManagerScopedBase(const ViEManagerBase& vieManager);
~ViEManagerScopedBase();
protected:
const ViEManagerBase* _vieManager;
private:
int _refCount;
class ViEManagerScopedBase {
friend class ViEManagedItemScopedBase;
public:
explicit ViEManagerScopedBase(const ViEManagerBase& vie_manager);
~ViEManagerScopedBase();
protected:
const ViEManagerBase* vie_manager_;
private:
int ref_count_;
};
class ViEManagedItemScopedBase
{
public:
ViEManagedItemScopedBase(ViEManagerScopedBase& vieScopedManager);
~ViEManagedItemScopedBase();
protected:
ViEManagerScopedBase& _vieScopedManager;
class ViEManagedItemScopedBase {
public:
explicit ViEManagedItemScopedBase(ViEManagerScopedBase& vie_scoped_manager);
~ViEManagedItemScopedBase();
protected:
ViEManagerScopedBase& vie_scoped_manager_;
};
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_MANAGER_BASE_H_
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_

View File

@ -46,7 +46,8 @@ ViERenderManagerScoped::ViERenderManagerScoped(const ViERenderManager& vieRender
ViERenderer* ViERenderManagerScoped::Renderer(WebRtc_Word32 renderId) const
{
return static_cast<const ViERenderManager*> (_vieManager)->ViERenderPtr(renderId);
return static_cast<const ViERenderManager*> (vie_manager_)->ViERenderPtr(
renderId);
}
@ -293,4 +294,3 @@ ViERenderer* ViERenderManager::ViERenderPtr(WebRtc_Word32 renderId) const
}
} //namespace webrtc