Remove use of MapWrapper in video_coding.

BUG=
TEST=

Review URL: https://webrtc-codereview.appspot.com/344018

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1498 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
stefan@webrtc.org
2012-01-20 14:04:13 +00:00
parent d798953846
commit f27916a76a
2 changed files with 64 additions and 70 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source
@@ -451,23 +451,24 @@ VCMCodecDataBase::RegisterReceiveCodec(const VideoCodec* receiveCodec,
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
} }
VideoCodec* newReceiveCodec = new VideoCodec(*receiveCodec); VideoCodec* newReceiveCodec = new VideoCodec(*receiveCodec);
_decMap.Insert(receiveCodec->plType, _decMap[receiveCodec->plType] =
new VCMDecoderMapItem(newReceiveCodec, numberOfCores, requireKeyFrame)); new VCMDecoderMapItem(newReceiveCodec, numberOfCores, requireKeyFrame);
return VCM_OK; return VCM_OK;
} }
WebRtc_Word32 VCMCodecDataBase::DeRegisterReceiveCodec(WebRtc_UWord8 payloadType) WebRtc_Word32 VCMCodecDataBase::DeRegisterReceiveCodec(
WebRtc_UWord8 payloadType)
{ {
MapItem* item = _decMap.Find(payloadType); DecoderMap::iterator it = _decMap.find(payloadType);
if (item == NULL) if (it == _decMap.end())
{ {
return VCM_PARAMETER_ERROR; return VCM_PARAMETER_ERROR;
} }
VCMDecoderMapItem* decItem = static_cast<VCMDecoderMapItem*>(item->GetItem()); VCMDecoderMapItem* decItem = (*it).second;
delete decItem->_settings; delete decItem->_settings;
delete decItem; delete decItem;
_decMap.Erase(item); _decMap.erase(it);
if (_receiveCodec.plType == payloadType) if (_receiveCodec.plType == payloadType)
{ {
// This codec is currently in use. // This codec is currently in use.
@@ -483,31 +484,18 @@ VCMCodecDataBase::ResetReceiver()
ReleaseDecoder(_ptrDecoder); ReleaseDecoder(_ptrDecoder);
_ptrDecoder = NULL; _ptrDecoder = NULL;
memset(&_receiveCodec, 0, sizeof(VideoCodec)); memset(&_receiveCodec, 0, sizeof(VideoCodec));
MapItem* item = _decMap.First(); for (DecoderMap::iterator it = _decMap.begin(); it != _decMap.end(); ++it) {
while (item != NULL) if ((*it).second->_settings != NULL)
{ {
VCMDecoderMapItem* decItem = static_cast<VCMDecoderMapItem*>(item->GetItem()); delete (*it).second->_settings;
if (decItem != NULL)
{
if (decItem->_settings != NULL)
{
delete decItem->_settings;
} }
delete decItem; delete (*it).second;
_decMap.erase(it);
} }
_decMap.Erase(item); for (ExternalDecoderMap::iterator it = _decExternalMap.begin();
item = _decMap.First(); it != _decExternalMap.end(); ++it) {
} delete (*it).second;
item = _decExternalMap.First(); _decExternalMap.erase(it);
while (item != NULL)
{
VCMExtDecoderMapItem* decItem = static_cast<VCMExtDecoderMapItem*>(item->GetItem());
if (decItem != NULL)
{
delete decItem;
}
_decExternalMap.Erase(item);
item = _decExternalMap.First();
} }
_currentDecIsExternal = false; _currentDecIsExternal = false;
return VCM_OK; return VCM_OK;
@@ -516,8 +504,8 @@ VCMCodecDataBase::ResetReceiver()
WebRtc_Word32 WebRtc_Word32
VCMCodecDataBase::DeRegisterExternalDecoder(WebRtc_UWord8 payloadType) VCMCodecDataBase::DeRegisterExternalDecoder(WebRtc_UWord8 payloadType)
{ {
MapItem* item = _decExternalMap.Find(payloadType); ExternalDecoderMap::iterator it = _decExternalMap.find(payloadType);
if (item == NULL) if (it == _decExternalMap.end())
{ {
// Not found // Not found
return VCM_PARAMETER_ERROR; return VCM_PARAMETER_ERROR;
@@ -529,9 +517,8 @@ VCMCodecDataBase::DeRegisterExternalDecoder(WebRtc_UWord8 payloadType)
_ptrDecoder = NULL; _ptrDecoder = NULL;
} }
DeRegisterReceiveCodec(payloadType); DeRegisterReceiveCodec(payloadType);
VCMExtDecoderMapItem* decItem = static_cast<VCMExtDecoderMapItem*>(item->GetItem()); delete (*it).second;
delete decItem; _decExternalMap.erase(it);
_decExternalMap.Erase(item);
return VCM_OK; return VCM_OK;
} }
@@ -551,7 +538,7 @@ VCMCodecDataBase::RegisterExternalDecoder(VideoDecoder* externalDecoder,
return VCM_MEMORY; return VCM_MEMORY;
} }
DeRegisterExternalDecoder(payloadType); DeRegisterExternalDecoder(payloadType);
_decExternalMap.Insert(payloadType, extDecoder); _decExternalMap[payloadType] = extDecoder;
return VCM_OK; return VCM_OK;
} }
@@ -559,7 +546,7 @@ VCMCodecDataBase::RegisterExternalDecoder(VideoDecoder* externalDecoder,
bool bool
VCMCodecDataBase::DecoderRegistered() const VCMCodecDataBase::DecoderRegistered() const
{ {
return (_decMap.Size() > 0); return !_decMap.empty();
} }
WebRtc_Word32 WebRtc_Word32
@@ -584,7 +571,8 @@ VCMCodecDataBase::ReceiveCodec() const
} }
VCMGenericDecoder* VCMGenericDecoder*
VCMCodecDataBase::SetDecoder(WebRtc_UWord8 payloadType, VCMDecodedFrameCallback& callback) VCMCodecDataBase::SetDecoder(WebRtc_UWord8 payloadType,
VCMDecodedFrameCallback& callback)
{ {
if (payloadType == _receiveCodec.plType || payloadType == 0) if (payloadType == _receiveCodec.plType || payloadType == 0)
{ {
@@ -597,7 +585,8 @@ VCMCodecDataBase::SetDecoder(WebRtc_UWord8 payloadType, VCMDecodedFrameCallback&
_ptrDecoder = NULL; _ptrDecoder = NULL;
memset(&_receiveCodec, 0, sizeof(VideoCodec)); memset(&_receiveCodec, 0, sizeof(VideoCodec));
} }
_ptrDecoder = CreateAndInitDecoder(payloadType, _receiveCodec, _currentDecIsExternal); _ptrDecoder = CreateAndInitDecoder(payloadType, _receiveCodec,
_currentDecIsExternal);
if (_ptrDecoder == NULL) if (_ptrDecoder == NULL)
{ {
return NULL; return NULL;
@@ -625,11 +614,14 @@ VCMCodecDataBase::CreateAndInitDecoder(WebRtc_UWord8 payloadType,
return NULL; return NULL;
} }
VCMGenericDecoder* ptrDecoder = NULL; VCMGenericDecoder* ptrDecoder = NULL;
VCMExtDecoderMapItem* externalDecItem = FindExternalDecoderItem(payloadType); VCMExtDecoderMapItem* externalDecItem = FindExternalDecoderItem(
payloadType);
if (externalDecItem != NULL) if (externalDecItem != NULL)
{ {
// External codec // External codec
ptrDecoder = new VCMGenericDecoder(*externalDecItem->_externalDecoderInstance, _id, ptrDecoder = new VCMGenericDecoder(
*externalDecItem->_externalDecoderInstance,
_id,
true); true);
external = true; external = true;
} }
@@ -717,10 +709,10 @@ VCMCodecDataBase::ReleaseDecoder(VCMGenericDecoder* decoder) const
VCMDecoderMapItem* VCMDecoderMapItem*
VCMCodecDataBase::FindDecoderItem(WebRtc_UWord8 payloadType) const VCMCodecDataBase::FindDecoderItem(WebRtc_UWord8 payloadType) const
{ {
MapItem* item = _decMap.Find(payloadType); DecoderMap::const_iterator it = _decMap.find(payloadType);
if (item != NULL) if (it != _decMap.end())
{ {
return static_cast<VCMDecoderMapItem*>(item->GetItem()); return (*it).second;
} }
return NULL; return NULL;
} }
@@ -728,10 +720,10 @@ VCMCodecDataBase::FindDecoderItem(WebRtc_UWord8 payloadType) const
VCMExtDecoderMapItem* VCMExtDecoderMapItem*
VCMCodecDataBase::FindExternalDecoderItem(WebRtc_UWord8 payloadType) const VCMCodecDataBase::FindExternalDecoderItem(WebRtc_UWord8 payloadType) const
{ {
MapItem* item = _decExternalMap.Find(payloadType); ExternalDecoderMap::const_iterator it = _decExternalMap.find(payloadType);
if (item != NULL) if (it != _decExternalMap.end())
{ {
return static_cast<VCMExtDecoderMapItem*>(item->GetItem()); return (*it).second;
} }
return NULL; return NULL;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source
@@ -11,12 +11,13 @@
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODEC_DATABASE_H_ #ifndef WEBRTC_MODULES_VIDEO_CODING_CODEC_DATABASE_H_
#define WEBRTC_MODULES_VIDEO_CODING_CODEC_DATABASE_H_ #define WEBRTC_MODULES_VIDEO_CODING_CODEC_DATABASE_H_
#include "video_coding.h" #include <map>
#include "video_codec_interface.h"
#include "generic_decoder.h" #include "modules/video_coding/codecs/interface/video_codec_interface.h"
#include "generic_encoder.h" #include "modules/video_coding/main/interface/video_coding.h"
#include "modules/video_coding/main/source/generic_decoder.h"
#include "modules/video_coding/main/source/generic_encoder.h"
#include "typedefs.h" #include "typedefs.h"
#include "map_wrapper.h"
namespace webrtc namespace webrtc
{ {
@@ -191,6 +192,8 @@ protected:
VCMExtDecoderMapItem* FindExternalDecoderItem(WebRtc_UWord8 payloadType) const; VCMExtDecoderMapItem* FindExternalDecoderItem(WebRtc_UWord8 payloadType) const;
private: private:
typedef std::map<uint8_t, VCMDecoderMapItem*> DecoderMap;
typedef std::map<uint8_t, VCMExtDecoderMapItem*> ExternalDecoderMap;
WebRtc_Word32 _id; WebRtc_Word32 _id;
WebRtc_UWord32 _numberOfCores; WebRtc_UWord32 _numberOfCores;
WebRtc_UWord32 _maxPayloadSize; WebRtc_UWord32 _maxPayloadSize;
@@ -204,9 +207,8 @@ private:
VCMGenericEncoder* _ptrEncoder; VCMGenericEncoder* _ptrEncoder;
VCMGenericDecoder* _ptrDecoder; VCMGenericDecoder* _ptrDecoder;
bool _currentDecIsExternal; bool _currentDecIsExternal;
MapWrapper _decMap; DecoderMap _decMap;
MapWrapper _decExternalMap; ExternalDecoderMap _decExternalMap;
}; // end of VCMCodecDataBase class definition }; // end of VCMCodecDataBase class definition
} // namespace webrtc } // namespace webrtc