diff options
34 files changed, 344 insertions, 1297 deletions
diff --git a/modules/audio_conference_mixer/interface/audio_conference_mixer_defines.h b/modules/audio_conference_mixer/interface/audio_conference_mixer_defines.h index ba04b5a4..663be182 100644 --- a/modules/audio_conference_mixer/interface/audio_conference_mixer_defines.h +++ b/modules/audio_conference_mixer/interface/audio_conference_mixer_defines.h @@ -12,7 +12,6 @@ #define WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_INTERFACE_AUDIO_CONFERENCE_MIXER_DEFINES_H_ #include "webrtc/modules/interface/module_common_types.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include "webrtc/typedefs.h" namespace webrtc { @@ -87,19 +86,6 @@ protected: AudioMixerOutputReceiver() {} virtual ~AudioMixerOutputReceiver() {} }; - -class AudioRelayReceiver -{ -public: - // This callback function provides the mix decision for this mix iteration. - // mixerList is a list of elements of the type - // [int,MixerParticipant*] - virtual void NewAudioToRelay(const int32_t id, - const MapWrapper& mixerList) = 0; -protected: - AudioRelayReceiver() {} - virtual ~AudioRelayReceiver() {} -}; } // namespace webrtc #endif // WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_INTERFACE_AUDIO_CONFERENCE_MIXER_DEFINES_H_ diff --git a/modules/audio_conference_mixer/source/audio_conference_mixer_impl.cc b/modules/audio_conference_mixer/source/audio_conference_mixer_impl.cc index ab9d803e..da16814d 100644 --- a/modules/audio_conference_mixer/source/audio_conference_mixer_impl.cc +++ b/modules/audio_conference_mixer/source/audio_conference_mixer_impl.cc @@ -14,7 +14,6 @@ #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/utility/interface/audio_frame_operations.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include "webrtc/system_wrappers/interface/trace.h" namespace webrtc { @@ -240,7 +239,7 @@ int32_t AudioConferenceMixerImpl::Process() ListWrapper mixList; ListWrapper rampOutList; ListWrapper additionalFramesList; - MapWrapper mixedParticipantsMap; + std::map<int, MixerParticipant*> mixedParticipantsMap; { CriticalSectionScoped cs(_cbCrit.get()); @@ -297,19 +296,15 @@ int32_t AudioConferenceMixerImpl::Process() } } - UpdateToMix(mixList, rampOutList, mixedParticipantsMap, + UpdateToMix(mixList, rampOutList, &mixedParticipantsMap, remainingParticipantsAllowedToMix); GetAdditionalAudio(additionalFramesList); UpdateMixedStatus(mixedParticipantsMap); - _scratchParticipantsToMixAmount = mixedParticipantsMap.Size(); + _scratchParticipantsToMixAmount = + static_cast<uint32_t>(mixedParticipantsMap.size()); } - // Clear mixedParticipantsMap to avoid memory leak warning. - // Please note that the mixedParticipantsMap doesn't own any dynamically - // allocated memory. - while(mixedParticipantsMap.Erase(mixedParticipantsMap.First()) == 0) {} - // Get an AudioFrame for mixing from the memory pool. AudioFrame* mixedAudio = NULL; if(_audioFramePool->PopMemory(mixedAudio) == -1) @@ -718,9 +713,8 @@ int32_t AudioConferenceMixerImpl::GetLowestMixingFrequencyFromList( void AudioConferenceMixerImpl::UpdateToMix( ListWrapper& mixList, ListWrapper& rampOutList, - MapWrapper& mixParticipantList, - uint32_t& maxAudioFrameCounter) -{ + std::map<int, MixerParticipant*>* mixParticipantList, + uint32_t& maxAudioFrameCounter) { WEBRTC_TRACE(kTraceStream, kTraceAudioMixerServer, _id, "UpdateToMix(mixList,rampOutList,mixParticipantList,%d)", maxAudioFrameCounter); @@ -811,39 +805,30 @@ void AudioConferenceMixerImpl::UpdateToMix( replaceItem->GetItem()); bool replaceWasMixed = false; - MapItem* replaceParticipant = mixParticipantList.Find( - replaceFrame->id_); + std::map<int, MixerParticipant*>::iterator it = + mixParticipantList->find(replaceFrame->id_); + // When a frame is pushed to |activeList| it is also pushed // to mixParticipantList with the frame's id. This means // that the Find call above should never fail. - if(replaceParticipant == NULL) - { - assert(false); + assert(it != mixParticipantList->end()); + it->second->_mixHistory->WasMixed(replaceWasMixed); + + mixParticipantList->erase(replaceFrame->id_); + activeList.Erase(replaceItem); + + activeList.PushFront(static_cast<void*>(audioFrame)); + (*mixParticipantList)[audioFrame->id_] = participant; + assert(mixParticipantList->size() <= + kMaximumAmountOfMixedParticipants); + + if (replaceWasMixed) { + RampOut(*replaceFrame); + rampOutList.PushBack(static_cast<void*>(replaceFrame)); + assert(rampOutList.GetSize() <= + kMaximumAmountOfMixedParticipants); } else { - static_cast<MixerParticipant*>( - replaceParticipant->GetItem())->_mixHistory-> - WasMixed(replaceWasMixed); - - mixParticipantList.Erase(replaceFrame->id_); - activeList.Erase(replaceItem); - - activeList.PushFront(static_cast<void*>(audioFrame)); - mixParticipantList.Insert( - audioFrame->id_, - static_cast<void*>(participant)); - assert(mixParticipantList.Size() <= - kMaximumAmountOfMixedParticipants); - - if(replaceWasMixed) - { - RampOut(*replaceFrame); - rampOutList.PushBack( - static_cast<void*>(replaceFrame)); - assert(rampOutList.GetSize() <= - kMaximumAmountOfMixedParticipants); - } else { - _audioFramePool->PushMemory(replaceFrame); - } + _audioFramePool->PushMemory(replaceFrame); } } else { if(wasMixed) @@ -858,9 +843,8 @@ void AudioConferenceMixerImpl::UpdateToMix( } } else { activeList.PushFront(static_cast<void*>(audioFrame)); - mixParticipantList.Insert(audioFrame->id_, - static_cast<void*>(participant)); - assert(mixParticipantList.Size() <= + (*mixParticipantList)[audioFrame->id_] = participant; + assert(mixParticipantList->size() <= kMaximumAmountOfMixedParticipants); } } else { @@ -902,9 +886,9 @@ void AudioConferenceMixerImpl::UpdateToMix( if(mixList.GetSize() < maxAudioFrameCounter + mixListStartSize) { mixList.PushBack(pair->audioFrame); - mixParticipantList.Insert(pair->audioFrame->id_, - static_cast<void*>(pair->participant)); - assert(mixParticipantList.Size() <= + (*mixParticipantList)[pair->audioFrame->id_] = + pair->participant; + assert(mixParticipantList->size() <= kMaximumAmountOfMixedParticipants); } else @@ -923,9 +907,8 @@ void AudioConferenceMixerImpl::UpdateToMix( if(mixList.GetSize() < maxAudioFrameCounter + mixListStartSize) { mixList.PushBack(pair->audioFrame); - mixParticipantList.Insert(pair->audioFrame->id_, - static_cast<void*>(pair->participant)); - assert(mixParticipantList.Size() <= + (*mixParticipantList)[pair->audioFrame->id_] = pair->participant; + assert(mixParticipantList->size() <= kMaximumAmountOfMixedParticipants); } else @@ -983,11 +966,11 @@ void AudioConferenceMixerImpl::GetAdditionalAudio( } void AudioConferenceMixerImpl::UpdateMixedStatus( - MapWrapper& mixedParticipantsMap) + std::map<int, MixerParticipant*>& mixedParticipantsMap) { WEBRTC_TRACE(kTraceStream, kTraceAudioMixerServer, _id, "UpdateMixedStatus(mixedParticipantsMap)"); - assert(mixedParticipantsMap.Size() <= kMaximumAmountOfMixedParticipants); + assert(mixedParticipantsMap.size() <= kMaximumAmountOfMixedParticipants); // Loop through all participants. If they are in the mix map they // were mixed. @@ -998,15 +981,14 @@ void AudioConferenceMixerImpl::UpdateMixedStatus( MixerParticipant* participant = static_cast<MixerParticipant*>(participantItem->GetItem()); - MapItem* mixedItem = mixedParticipantsMap.First(); - while(mixedItem) - { - if(participant == mixedItem->GetItem()) - { - isMixed = true; - break; - } - mixedItem = mixedParticipantsMap.Next(mixedItem); + for (std::map<int, MixerParticipant*>::iterator it = + mixedParticipantsMap.begin(); + it != mixedParticipantsMap.end(); + ++it) { + if (it->second == participant) { + isMixed = true; + break; + } } participant->_mixHistory->SetIsMixed(isMixed); participantItem = _participantList.Next(participantItem); diff --git a/modules/audio_conference_mixer/source/audio_conference_mixer_impl.h b/modules/audio_conference_mixer/source/audio_conference_mixer_impl.h index 261cd88d..737acbb0 100644 --- a/modules/audio_conference_mixer/source/audio_conference_mixer_impl.h +++ b/modules/audio_conference_mixer/source/audio_conference_mixer_impl.h @@ -11,6 +11,8 @@ #ifndef WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_AUDIO_CONFERENCE_MIXER_IMPL_H_ #define WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_AUDIO_CONFERENCE_MIXER_IMPL_H_ +#include <map> + #include "webrtc/engine_configurations.h" #include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer.h" #include "webrtc/modules/audio_conference_mixer/source/level_indicator.h" @@ -99,9 +101,11 @@ private: // rampOutList contain AudioFrames corresponding to an audio stream that // used to be mixed but shouldn't be mixed any longer. These AudioFrames // should be ramped out over this AudioFrame to avoid audio discontinuities. - void UpdateToMix(ListWrapper& mixList, ListWrapper& rampOutList, - MapWrapper& mixParticipantList, - uint32_t& maxAudioFrameCounter); + void UpdateToMix( + ListWrapper& mixList, + ListWrapper& rampOutList, + std::map<int, MixerParticipant*>* mixParticipantList, + uint32_t& maxAudioFrameCounter); // Return the lowest mixing frequency that can be used without having to // downsample any audio. @@ -113,7 +117,8 @@ private: // Update the MixHistory of all MixerParticipants. mixedParticipantsList // should contain a map of MixerParticipants that have been mixed. - void UpdateMixedStatus(MapWrapper& mixedParticipantsList); + void UpdateMixedStatus( + std::map<int, MixerParticipant*>& mixedParticipantsList); // Clears audioFrameList and reclaims all memory associated with it. void ClearAudioFrameList(ListWrapper& audioFrameList); diff --git a/modules/video_capture/android/device_info_android.cc b/modules/video_capture/android/device_info_android.cc index b221fd93..3c153af1 100644 --- a/modules/video_capture/android/device_info_android.cc +++ b/modules/video_capture/android/device_info_android.cc @@ -161,11 +161,12 @@ int32_t DeviceInfoAndroid::GetDeviceName( int32_t DeviceInfoAndroid::CreateCapabilityMap( const char* deviceUniqueIdUTF8) { - MapItem* item = NULL; - while ((item = _captureCapabilities.Last())) { - delete (VideoCaptureCapability*) item->GetItem(); - _captureCapabilities.Erase(item); - } + for (std::map<int, VideoCaptureCapability*>::iterator it = + _captureCapabilities.begin(); + it != _captureCapabilities.end(); + ++it) + delete it->second; + _captureCapabilities.clear(); JNIEnv *env; jclass javaCmDevInfoClass; @@ -247,7 +248,7 @@ int32_t DeviceInfoAndroid::CreateCapabilityMap( WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, "%s: Cap width %d, height %d, fps %d", __FUNCTION__, cap->width, cap->height, cap->maxFPS); - _captureCapabilities.Insert(i, cap); + _captureCapabilities[i] = cap; } _lastUsedDeviceNameLength = strlen((char*) deviceUniqueIdUTF8); @@ -259,9 +260,9 @@ int32_t DeviceInfoAndroid::CreateCapabilityMap( VideoCaptureAndroid::ReleaseAndroidDeviceInfoObjects(attached); WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, - "CreateCapabilityMap %d", _captureCapabilities.Size()); + "CreateCapabilityMap %d", _captureCapabilities.size()); - return _captureCapabilities.Size(); + return _captureCapabilities.size(); } int32_t DeviceInfoAndroid::GetOrientation( diff --git a/modules/video_capture/device_info_impl.cc b/modules/video_capture/device_info_impl.cc index c360cf35..1bdaa14f 100644 --- a/modules/video_capture/device_info_impl.cc +++ b/modules/video_capture/device_info_impl.cc @@ -31,13 +31,13 @@ DeviceInfoImpl::DeviceInfoImpl(const int32_t id) DeviceInfoImpl::~DeviceInfoImpl(void) { _apiLock.AcquireLockExclusive(); - // Reset old capability list - MapItem* item = NULL; - while ((item = _captureCapabilities.Last())) - { - delete (VideoCaptureCapability*) item->GetItem(); - _captureCapabilities.Erase(item); + + for (VideoCaptureCapabilityMap::iterator it = _captureCapabilities.begin(); + it != _captureCapabilities.end(); + ++it) { + delete it->second; } + free(_lastUsedDeviceName); _apiLock.ReleaseLockExclusive(); @@ -67,7 +67,7 @@ int32_t DeviceInfoImpl::NumberOfCapabilities( { //yes _apiLock.ReleaseLockShared(); - return _captureCapabilities.Size(); + return static_cast<int32_t>(_captureCapabilities.size()); } } // Need to get exclusive rights to create the new capability map. @@ -116,7 +116,7 @@ int32_t DeviceInfoImpl::GetCapability(const char* deviceUniqueIdUTF8, } // Make sure the number is valid - if (deviceCapabilityNumber >= (unsigned int) _captureCapabilities.Size()) + if (deviceCapabilityNumber >= (unsigned int) _captureCapabilities.size()) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "deviceCapabilityNumber %d is invalid in call to GetCapability", @@ -124,23 +124,23 @@ int32_t DeviceInfoImpl::GetCapability(const char* deviceUniqueIdUTF8, return -1; } - MapItem* item = _captureCapabilities.Find(deviceCapabilityNumber); - if (!item) + VideoCaptureCapabilityMap::iterator item = + _captureCapabilities.find(deviceCapabilityNumber); + + if (item == _captureCapabilities.end()) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "Failed to find capability number %d of %d possible", - deviceCapabilityNumber, _captureCapabilities.Size()); + deviceCapabilityNumber, _captureCapabilities.size()); return -1; } - VideoCaptureCapability* capPointer = static_cast<VideoCaptureCapability*> - (item->GetItem()); - if (!capPointer) + if (item->second == NULL) { return -1; } - capability = *capPointer; + capability = *item->second; return 0; } @@ -183,16 +183,16 @@ int32_t DeviceInfoImpl::GetBestMatchedCapability( RawVideoType bestRawType = kVideoUnknown; webrtc::VideoCodecType bestCodecType = webrtc::kVideoCodecUnknown; - const int32_t numberOfCapabilies = _captureCapabilities.Size(); + const int32_t numberOfCapabilies = + static_cast<int32_t>(_captureCapabilities.size()); for (int32_t tmp = 0; tmp < numberOfCapabilies; ++tmp) // Loop through all capabilities { - MapItem* item = _captureCapabilities.Find(tmp); - if (!item) + VideoCaptureCapabilityMap::iterator item = _captureCapabilities.find(tmp); + if (item == _captureCapabilities.end()) return -1; - VideoCaptureCapability& capability = *static_cast<VideoCaptureCapability*> - (item->GetItem()); + VideoCaptureCapability& capability = *item->second; const int32_t diffWidth = capability.width - requested.width; const int32_t diffHeight = capability.height - requested.height; @@ -298,15 +298,14 @@ int32_t DeviceInfoImpl::GetBestMatchedCapability( bestWidth, bestHeight, bestFrameRate, bestRawType); // Copy the capability - MapItem* item = _captureCapabilities.Find(bestformatIndex); - if (!item) + VideoCaptureCapabilityMap::iterator item = + _captureCapabilities.find(bestformatIndex); + if (item == _captureCapabilities.end()) return -1; - VideoCaptureCapability* capPointer = - static_cast<VideoCaptureCapability*> (item->GetItem()); - if (!capPointer) + if (item->second == NULL) return -1; - resulting = *capPointer; + resulting = *item->second; return bestformatIndex; } diff --git a/modules/video_capture/device_info_impl.h b/modules/video_capture/device_info_impl.h index 79cf5273..dc4c08c6 100644 --- a/modules/video_capture/device_info_impl.h +++ b/modules/video_capture/device_info_impl.h @@ -11,9 +11,10 @@ #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_DEVICE_INFO_IMPL_H_ #define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_DEVICE_INFO_IMPL_H_ +#include <map> + #include "webrtc/modules/video_capture/include/video_capture.h" #include "webrtc/modules/video_capture/video_capture_delay.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" namespace webrtc @@ -57,7 +58,8 @@ protected: protected: // Data members int32_t _id; - MapWrapper _captureCapabilities; + typedef std::map<int, VideoCaptureCapability*> VideoCaptureCapabilityMap; + VideoCaptureCapabilityMap _captureCapabilities; RWLockWrapper& _apiLock; char* _lastUsedDeviceName; uint32_t _lastUsedDeviceNameLength; diff --git a/modules/video_capture/linux/device_info_linux.cc b/modules/video_capture/linux/device_info_linux.cc index 511778d9..0b16ca32 100644 --- a/modules/video_capture/linux/device_info_linux.cc +++ b/modules/video_capture/linux/device_info_linux.cc @@ -219,12 +219,13 @@ int32_t DeviceInfoLinux::CreateCapabilityMap( // now fd will point to the matching device // reset old capability map - MapItem* item = NULL; - while ((item = _captureCapabilities.Last())) - { - delete static_cast<VideoCaptureCapability*> (item->GetItem()); - _captureCapabilities.Erase(item); + for (std::map<int, VideoCaptureCapability*>::iterator it = + _captureCapabilities.begin(); + it != _captureCapabilities.end(); + ++it) { + delete it->second; } + _captureCapabilities.clear(); int size = FillCapabilityMap(fd); close(fd); @@ -235,8 +236,11 @@ int32_t DeviceInfoLinux::CreateCapabilityMap( _lastUsedDeviceNameLength + 1); memcpy(_lastUsedDeviceName, deviceUniqueIdUTF8, _lastUsedDeviceNameLength + 1); - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, "CreateCapabilityMap %d", - _captureCapabilities.Size()); + WEBRTC_TRACE(webrtc::kTraceInfo, + webrtc::kTraceVideoCapture, + _id, + "CreateCapabilityMap %u", + static_cast<unsigned int>(_captureCapabilities.size())); return size; } @@ -314,7 +318,7 @@ int32_t DeviceInfoLinux::FillCapabilityMap(int fd) cap->maxFPS = 30; } - _captureCapabilities.Insert(index, cap); + _captureCapabilities[index] = cap; index++; WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, "Camera capability, width:%d height:%d type:%d fps:%d", @@ -324,9 +328,12 @@ int32_t DeviceInfoLinux::FillCapabilityMap(int fd) } } - WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, "CreateCapabilityMap %d", - _captureCapabilities.Size()); - return _captureCapabilities.Size(); + WEBRTC_TRACE(webrtc::kTraceInfo, + webrtc::kTraceVideoCapture, + _id, + "CreateCapabilityMap %u", + static_cast<unsigned int>(_captureCapabilities.size())); + return _captureCapabilities.size(); } } // namespace videocapturemodule diff --git a/modules/video_capture/mac/qtkit/video_capture_qtkit_info.h b/modules/video_capture/mac/qtkit/video_capture_qtkit_info.h index cae923b4..fd994ad6 100644 --- a/modules/video_capture/mac/qtkit/video_capture_qtkit_info.h +++ b/modules/video_capture/mac/qtkit/video_capture_qtkit_info.h @@ -14,7 +14,6 @@ #include "webrtc/modules/video_capture/device_info_impl.h" #include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_utility.h" #include "webrtc/modules/video_capture/video_capture_impl.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" @class VideoCaptureMacQTKitInfoObjC; diff --git a/modules/video_capture/windows/device_info_ds.cc b/modules/video_capture/windows/device_info_ds.cc index f4598024..11e1f416 100644 --- a/modules/video_capture/windows/device_info_ds.cc +++ b/modules/video_capture/windows/device_info_ds.cc @@ -367,23 +367,18 @@ IBaseFilter * DeviceInfoDS::GetDeviceFilter( } int32_t DeviceInfoDS::GetWindowsCapability( - const int32_t capabilityIndex, - VideoCaptureCapabilityWindows& windowsCapability) - -{ - ReadLockScoped cs(_apiLock); - // Make sure the number is valid - if (capabilityIndex >= _captureCapabilities.Size() || capabilityIndex < 0) - return -1; - - MapItem* item = _captureCapabilities.Find(capabilityIndex); - if (!item) - return -1; - - VideoCaptureCapabilityWindows* capPointer = - static_cast<VideoCaptureCapabilityWindows*> (item->GetItem()); - windowsCapability = *capPointer; - return 0; + const int32_t capabilityIndex, + VideoCaptureCapabilityWindows& windowsCapability) { + ReadLockScoped cs(_apiLock); + + std::map<int, VideoCaptureCapability*>::iterator item = + _captureCapabilities.find(capabilityIndex); + if (item == _captureCapabilities.end()) + return -1; + + windowsCapability = + *static_cast<VideoCaptureCapabilityWindows*>(item->second); + return 0; } int32_t DeviceInfoDS::CreateCapabilityMap( @@ -391,15 +386,15 @@ int32_t DeviceInfoDS::CreateCapabilityMap( { // Reset old capability list - MapItem* item = NULL; - while (item = _captureCapabilities.Last()) - { - VideoCaptureCapabilityWindows* cap = - static_cast<VideoCaptureCapabilityWindows*> (item->GetItem()); - delete cap; - _captureCapabilities.Erase(item); + for (std::map<int, VideoCaptureCapability*>::iterator it = + _captureCapabilities.begin(); + it != _captureCapabilities.end(); + ++it) { + delete it->second; } + _captureCapabilities.clear(); + const int32_t deviceUniqueIdUTF8Length = (int32_t) strlen((char*) deviceUniqueIdUTF8); if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) @@ -678,7 +673,7 @@ int32_t DeviceInfoDS::CreateCapabilityMap( productId, capability->width, capability->height); - _captureCapabilities.Insert(index++, capability); + _captureCapabilities[index++] = capability; WEBRTC_TRACE( webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, "Camera capability, width:%d height:%d type:%d fps:%d", capability->width, capability->height, @@ -699,9 +694,9 @@ int32_t DeviceInfoDS::CreateCapabilityMap( + 1); memcpy(_lastUsedDeviceName, deviceUniqueIdUTF8, _lastUsedDeviceNameLength+ 1); WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, - "CreateCapabilityMap %d", _captureCapabilities.Size()); + "CreateCapabilityMap %d", _captureCapabilities.size()); - return _captureCapabilities.Size(); + return static_cast<int32_t>(_captureCapabilities.size()); } /* Constructs a product ID from the Windows DevicePath. on a USB device the devicePath contains product id and vendor id. diff --git a/modules/video_capture/windows/device_info_ds.h b/modules/video_capture/windows/device_info_ds.h index 19961afc..2230172d 100644 --- a/modules/video_capture/windows/device_info_ds.h +++ b/modules/video_capture/windows/device_info_ds.h @@ -13,7 +13,6 @@ #include "webrtc/modules/video_capture/device_info_impl.h" #include "webrtc/modules/video_capture/video_capture_impl.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include <Dshow.h> diff --git a/modules/video_render/android/video_render_android_impl.cc b/modules/video_render/android/video_render_android_impl.cc index 7bd0919c..27a264ac 100644 --- a/modules/video_render/android/video_render_android_impl.cc +++ b/modules/video_render/android/video_render_android_impl.cc @@ -46,7 +46,6 @@ VideoRenderAndroid::VideoRenderAndroid( _critSect(*CriticalSectionWrapper::CreateCriticalSection()), _renderType(videoRenderType), _ptrWindow((jobject)(window)), - _streamsMap(), _javaShutDownFlag(false), _javaShutdownEvent(*EventWrapper::Create()), _javaRenderEvent(*EventWrapper::Create()), @@ -62,9 +61,10 @@ VideoRenderAndroid::~VideoRenderAndroid() { if (_javaRenderThread) StopRender(); - for (MapItem* item = _streamsMap.First(); item != NULL; item - = _streamsMap.Next(item)) { // Delete streams - delete static_cast<AndroidStream*> (item->GetItem()); + for (AndroidStreamMap::iterator it = _streamsMap.begin(); + it != _streamsMap.end(); + ++it) { + delete it->second; } delete &_javaShutdownEvent; delete &_javaRenderEvent; @@ -91,20 +91,20 @@ VideoRenderAndroid::AddIncomingRenderStream(const uint32_t streamId, CriticalSectionScoped cs(&_critSect); AndroidStream* renderStream = NULL; - MapItem* item = _streamsMap.Find(streamId); - if (item) { - renderStream = (AndroidStream*) (item->GetItem()); - if (NULL != renderStream) { - WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, -1, - "%s: Render stream already exists", __FUNCTION__); - return renderStream; - } + AndroidStreamMap::iterator item = _streamsMap.find(streamId); + if (item != _streamsMap.end() && item->second != NULL) { + WEBRTC_TRACE(kTraceInfo, + kTraceVideoRenderer, + -1, + "%s: Render stream already exists", + __FUNCTION__); + return renderStream; } renderStream = CreateAndroidRenderChannel(streamId, zOrder, left, top, right, bottom, *this); if (renderStream) { - _streamsMap.Insert(streamId, renderStream); + _streamsMap[streamId] = renderStream; } else { WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, @@ -118,16 +118,14 @@ int32_t VideoRenderAndroid::DeleteIncomingRenderStream( const uint32_t streamId) { CriticalSectionScoped cs(&_critSect); - MapItem* item = _streamsMap.Find(streamId); - if (item) { - delete (AndroidStream*) item->GetItem(); - _streamsMap.Erase(streamId); - } - else { + AndroidStreamMap::iterator item = _streamsMap.find(streamId); + if (item == _streamsMap.end()) { WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "(%s:%d): renderStream is NULL", __FUNCTION__, __LINE__); return -1; } + delete item->second; + _streamsMap.erase(item); return 0; } @@ -234,10 +232,10 @@ bool VideoRenderAndroid::JavaRenderThreadProcess() } } - for (MapItem* item = _streamsMap.First(); item != NULL; - item = _streamsMap.Next(item)) { - static_cast<AndroidStream*> (item->GetItem())->DeliverFrame( - _javaRenderJniEnv); + for (AndroidStreamMap::iterator it = _streamsMap.begin(); + it != _streamsMap.end(); + ++it) { + it->second->DeliverFrame(_javaRenderJniEnv); } if (_javaShutDownFlag) { diff --git a/modules/video_render/android/video_render_android_impl.h b/modules/video_render/android/video_render_android_impl.h index eac07d29..1541148a 100644 --- a/modules/video_render/android/video_render_android_impl.h +++ b/modules/video_render/android/video_render_android_impl.h @@ -12,8 +12,10 @@ #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_ANDROID_VIDEO_RENDER_ANDROID_IMPL_H_ #include <jni.h> + +#include <map> + #include "webrtc/modules/video_render/i_video_render.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" namespace webrtc { @@ -136,7 +138,8 @@ class VideoRenderAndroid: IVideoRender { bool JavaRenderThreadProcess(); // Map with streams to render. - MapWrapper _streamsMap; + typedef std::map<int32_t, AndroidStream*> AndroidStreamMap; + AndroidStreamMap _streamsMap; // True if the _javaRenderThread thread shall be detached from the JVM. bool _javaShutDownFlag; EventWrapper& _javaShutdownEvent; diff --git a/modules/video_render/incoming_video_stream.cc b/modules/video_render/incoming_video_stream.cc index 39556d85..71f30c38 100644 --- a/modules/video_render/incoming_video_stream.cc +++ b/modules/video_render/incoming_video_stream.cc @@ -25,7 +25,6 @@ #include "webrtc/modules/video_render//video_render_frames.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/event_wrapper.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include "webrtc/system_wrappers/interface/thread_wrapper.h" #include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/system_wrappers/interface/trace.h" diff --git a/modules/video_render/incoming_video_stream.h b/modules/video_render/incoming_video_stream.h index 500ce260..87fe2de9 100644 --- a/modules/video_render/incoming_video_stream.h +++ b/modules/video_render/incoming_video_stream.h @@ -12,7 +12,6 @@ #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_INCOMING_VIDEO_STREAM_H_ #include "webrtc/modules/video_render/include/video_render.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" namespace webrtc { class CriticalSectionWrapper; diff --git a/modules/video_render/video_render_impl.cc b/modules/video_render/video_render_impl.cc index 7dc0dbf3..64467c1e 100644 --- a/modules/video_render/video_render_impl.cc +++ b/modules/video_render/video_render_impl.cc @@ -96,8 +96,7 @@ ModuleVideoRenderImpl::ModuleVideoRenderImpl( void* window, const bool fullscreen) : _id(id), _moduleCrit(*CriticalSectionWrapper::CreateCriticalSection()), - _ptrWindow(window), _fullScreen(fullscreen), _ptrRenderer(NULL), - _streamRenderMap(*(new MapWrapper())) + _ptrWindow(window), _fullScreen(fullscreen), _ptrRenderer(NULL) { // Create platform specific renderer @@ -222,16 +221,11 @@ ModuleVideoRenderImpl::~ModuleVideoRenderImpl() { delete &_moduleCrit; - while (_streamRenderMap.Size() > 0) - { - MapItem* item = _streamRenderMap.First(); - IncomingVideoStream* ptrIncomingStream = - static_cast<IncomingVideoStream*> (item->GetItem()); - assert(ptrIncomingStream != NULL); - delete ptrIncomingStream; - _streamRenderMap.Erase(item); + for (IncomingVideoStreamMap::iterator it = _streamRenderMap.begin(); + it != _streamRenderMap.end(); + ++it) { + delete it->second; } - delete &_streamRenderMap; // Delete platform specific renderer if (_ptrRenderer) @@ -410,29 +404,22 @@ int32_t ModuleVideoRenderImpl::Id() return _id; } -uint32_t ModuleVideoRenderImpl::GetIncomingFrameRate( - const uint32_t streamId) -{ - CriticalSectionScoped cs(&_moduleCrit); +uint32_t ModuleVideoRenderImpl::GetIncomingFrameRate(const uint32_t streamId) { + CriticalSectionScoped cs(&_moduleCrit); - MapItem* mapItem = _streamRenderMap.Find(streamId); - if (mapItem == NULL) - { - // This stream doesn't exist - WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, - "%s: stream doesn't exist", __FUNCTION__); - return 0; - } - IncomingVideoStream* incomingStream = - static_cast<IncomingVideoStream*> (mapItem->GetItem()); - if (incomingStream == NULL) - { - // This should never happen - assert(false); - _streamRenderMap.Erase(mapItem); - return 0; - } - return incomingStream->IncomingRate(); + IncomingVideoStreamMap::iterator it = _streamRenderMap.find(streamId); + + if (it == _streamRenderMap.end()) { + // This stream doesn't exist + WEBRTC_TRACE(kTraceError, + kTraceVideoRenderer, + _id, + "%s: stream doesn't exist", + __FUNCTION__); + return 0; + } + assert(it->second != NULL); + return it->second->IncomingRate(); } VideoRenderCallback* @@ -452,8 +439,7 @@ ModuleVideoRenderImpl::AddIncomingRenderStream(const uint32_t streamId, return NULL; } - if (_streamRenderMap.Find(streamId) != NULL) - { + if (_streamRenderMap.find(streamId) != _streamRenderMap.end()) { // The stream already exists... WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: stream already exists", __FUNCTION__); @@ -495,7 +481,7 @@ ModuleVideoRenderImpl::AddIncomingRenderStream(const uint32_t streamId, ptrIncomingStream->ModuleCallback(); // Store the stream - _streamRenderMap.Insert(streamId, ptrIncomingStream); + _streamRenderMap[streamId] = ptrIncomingStream; return moduleCallback; } @@ -512,56 +498,52 @@ int32_t ModuleVideoRenderImpl::DeleteIncomingRenderStream( return -1; } - MapItem* mapItem = _streamRenderMap.Find(streamId); - if (!mapItem) + IncomingVideoStreamMap::iterator item = _streamRenderMap.find(streamId); + if (item == _streamRenderMap.end()) { WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: stream doesn't exist", __FUNCTION__); return -1; } - IncomingVideoStream* ptrIncomingStream = - static_cast<IncomingVideoStream*> (mapItem->GetItem()); - delete ptrIncomingStream; - ptrIncomingStream = NULL; + delete item->second; + _ptrRenderer->DeleteIncomingRenderStream(streamId); - _streamRenderMap.Erase(mapItem); + + _streamRenderMap.erase(item); return 0; } int32_t ModuleVideoRenderImpl::AddExternalRenderCallback( - const uint32_t streamId, - VideoRenderCallback* renderObject) -{ + const uint32_t streamId, + VideoRenderCallback* renderObject) { CriticalSectionScoped cs(&_moduleCrit); - MapItem* mapItem = _streamRenderMap.Find(streamId); - if (!mapItem) + IncomingVideoStreamMap::iterator item = _streamRenderMap.find(streamId); + + if (item == _streamRenderMap.end()) { WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: stream doesn't exist", __FUNCTION__); return -1; } - IncomingVideoStream* ptrIncomingStream = - static_cast<IncomingVideoStream*> (mapItem->GetItem()); - if (!ptrIncomingStream) { + if (item->second == NULL) { WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: could not get stream", __FUNCTION__); return -1; } - return ptrIncomingStream->SetExternalCallback(renderObject); + return item->second->SetExternalCallback(renderObject); } int32_t ModuleVideoRenderImpl::GetIncomingRenderStreamProperties( - const uint32_t streamId, - uint32_t& zOrder, - float& left, - float& top, - float& right, - float& bottom) const -{ + const uint32_t streamId, + uint32_t& zOrder, + float& left, + float& top, + float& right, + float& bottom) const { CriticalSectionScoped cs(&_moduleCrit); if (!_ptrRenderer) @@ -580,27 +562,20 @@ uint32_t ModuleVideoRenderImpl::GetNumIncomingRenderStreams() const { CriticalSectionScoped cs(&_moduleCrit); - return (uint32_t) _streamRenderMap.Size(); + return static_cast<uint32_t>(_streamRenderMap.size()); } bool ModuleVideoRenderImpl::HasIncomingRenderStream( - const uint32_t streamId) const -{ - CriticalSectionScoped cs(&_moduleCrit); + const uint32_t streamId) const { + CriticalSectionScoped cs(&_moduleCrit); - bool hasStream = false; - if (_streamRenderMap.Find(streamId) != NULL) - { - hasStream = true; - } - return hasStream; + return _streamRenderMap.find(streamId) != _streamRenderMap.end(); } int32_t ModuleVideoRenderImpl::RegisterRawFrameCallback( - const uint32_t streamId, - VideoRenderCallback* callbackObj) -{ - return -1; + const uint32_t streamId, + VideoRenderCallback* callbackObj) { + return -1; } int32_t ModuleVideoRenderImpl::StartRender(const uint32_t streamId) @@ -615,15 +590,14 @@ int32_t ModuleVideoRenderImpl::StartRender(const uint32_t streamId) } // Start the stream - MapItem* item = _streamRenderMap.Find(streamId); - if (item == NULL) + IncomingVideoStreamMap::iterator item = _streamRenderMap.find(streamId); + + if (item == _streamRenderMap.end()) { return -1; } - IncomingVideoStream* incomingStream = - static_cast<IncomingVideoStream*> (item->GetItem()); - if (incomingStream->Start() == -1) + if (item->second->Start() == -1) { return -1; } @@ -648,15 +622,14 @@ int32_t ModuleVideoRenderImpl::StopRender(const uint32_t streamId) } // Stop the incoming stream - MapItem* item = _streamRenderMap.Find(streamId); - if (item == NULL) + IncomingVideoStreamMap::iterator item = _streamRenderMap.find(streamId); + + if (item == _streamRenderMap.end()) { return -1; } - IncomingVideoStream* incomingStream = - static_cast<IncomingVideoStream*> (item->GetItem()); - if (incomingStream->Stop() == -1) + if (item->second->Stop() == -1) { return -1; } @@ -668,21 +641,15 @@ int32_t ModuleVideoRenderImpl::ResetRender() { CriticalSectionScoped cs(&_moduleCrit); - int32_t error = 0; - - // Loop through all incoming streams and stop them - MapItem* item = _streamRenderMap.First(); - while (item) - { - IncomingVideoStream* incomingStream = - static_cast<IncomingVideoStream*> (item->GetItem()); - if (incomingStream->Reset() == -1) - { - error = -1; - } - item = _streamRenderMap.Next(item); + int32_t ret = 0; + // Loop through all incoming streams and reset them + for (IncomingVideoStreamMap::iterator it = _streamRenderMap.begin(); + it != _streamRenderMap.end(); + ++it) { + if (it->second->Reset() == -1) + ret = -1; } - return error; + return ret; } RawVideoType ModuleVideoRenderImpl::PreferredVideoType() const @@ -830,24 +797,18 @@ int32_t ModuleVideoRenderImpl::GetLastRenderedFrame( return -1; } - MapItem *item = _streamRenderMap.Find(streamId); - if (item == NULL) + IncomingVideoStreamMap::const_iterator item = + _streamRenderMap.find(streamId); + if (item == _streamRenderMap.end()) { // This stream doesn't exist WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: stream doesn't exist", __FUNCTION__); return 0; } - IncomingVideoStream* incomingStream = - static_cast<IncomingVideoStream*> (item->GetItem()); - if (incomingStream == NULL) - { - // This should never happen - assert(false); - _streamRenderMap.Erase(item); - return 0; - } - return incomingStream->GetLastRenderedFrame(frame); + + assert(item->second != NULL); + return item->second->GetLastRenderedFrame(frame); } int32_t ModuleVideoRenderImpl::SetExpectedRenderDelay( @@ -860,8 +821,9 @@ int32_t ModuleVideoRenderImpl::SetExpectedRenderDelay( return false; } - MapItem *item = _streamRenderMap.Find(stream_id); - if (item == NULL) { + IncomingVideoStreamMap::const_iterator item = + _streamRenderMap.find(stream_id); + if (item == _streamRenderMap.end()) { // This stream doesn't exist WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s(%u, %d): stream doesn't exist", __FUNCTION__, stream_id, @@ -869,16 +831,8 @@ int32_t ModuleVideoRenderImpl::SetExpectedRenderDelay( return -1; } - IncomingVideoStream* incoming_stream = - static_cast<IncomingVideoStream*> (item->GetItem()); - if (incoming_stream == NULL) { - // This should never happen - assert(false); - _streamRenderMap.Erase(item); - return 0; - } - - return incoming_stream->SetExpectedRenderDelay(delay_ms); + assert(item->second != NULL); + return item->second->SetExpectedRenderDelay(delay_ms); } int32_t ModuleVideoRenderImpl::ConfigureRenderer( @@ -914,24 +868,17 @@ int32_t ModuleVideoRenderImpl::SetStartImage( return -1; } - MapItem *item = _streamRenderMap.Find(streamId); - if (item == NULL) + IncomingVideoStreamMap::const_iterator item = + _streamRenderMap.find(streamId); + if (item == _streamRenderMap.end()) { // This stream doesn't exist WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: stream doesn't exist", __FUNCTION__); return -1; } - IncomingVideoStream* incomingStream = - static_cast<IncomingVideoStream*> (item->GetItem()); - if (incomingStream == NULL) - { - // This should never happen - assert(false); - _streamRenderMap.Erase(item); - return 0; - } - return incomingStream->SetStartImage(videoFrame); + assert (item->second != NULL); + return item->second->SetStartImage(videoFrame); } @@ -949,24 +896,17 @@ int32_t ModuleVideoRenderImpl::SetTimeoutImage( return -1; } - MapItem *item = _streamRenderMap.Find(streamId); - if (item == NULL) + IncomingVideoStreamMap::const_iterator item = + _streamRenderMap.find(streamId); + if (item == _streamRenderMap.end()) { // This stream doesn't exist WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: stream doesn't exist", __FUNCTION__); return -1; } - IncomingVideoStream* incomingStream = - static_cast<IncomingVideoStream*> (item->GetItem()); - if (incomingStream == NULL) - { - // This should never happen - assert(false); - _streamRenderMap.Erase(item); - return 0; - } - return incomingStream->SetTimeoutImage(videoFrame, timeout); + assert(item->second != NULL); + return item->second->SetTimeoutImage(videoFrame, timeout); } int32_t ModuleVideoRenderImpl::MirrorRenderStream(const int renderId, @@ -983,25 +923,18 @@ int32_t ModuleVideoRenderImpl::MirrorRenderStream(const int renderId, return -1; } - MapItem *item = _streamRenderMap.Find(renderId); - if (item == NULL) + IncomingVideoStreamMap::const_iterator item = + _streamRenderMap.find(renderId); + if (item == _streamRenderMap.end()) { // This stream doesn't exist WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: stream doesn't exist", __FUNCTION__); return 0; } - IncomingVideoStream* incomingStream = - static_cast<IncomingVideoStream*> (item->GetItem()); - if (incomingStream == NULL) - { - // This should never happen - assert(false); - _streamRenderMap.Erase(item); - return 0; - } + assert(item->second != NULL); - return incomingStream->EnableMirroring(enable, mirrorXAxis, mirrorYAxis); + return item->second->EnableMirroring(enable, mirrorXAxis, mirrorYAxis); } } // namespace webrtc diff --git a/modules/video_render/video_render_impl.h b/modules/video_render/video_render_impl.h index c9e69e9f..b8f8d67d 100644 --- a/modules/video_render/video_render_impl.h +++ b/modules/video_render/video_render_impl.h @@ -11,15 +11,15 @@ #ifndef WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_VIDEO_RENDER_IMPL_H_ #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_VIDEO_RENDER_IMPL_H_ +#include <map> + #include "webrtc/engine_configurations.h" #include "webrtc/modules/video_render/include/video_render.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" namespace webrtc { class CriticalSectionWrapper; class IncomingVideoStream; class IVideoRender; -class MapWrapper; // Class definitions class ModuleVideoRenderImpl: public VideoRender @@ -219,7 +219,8 @@ private: bool _fullScreen; IVideoRender* _ptrRenderer; - MapWrapper& _streamRenderMap; + typedef std::map<uint32_t, IncomingVideoStream*> IncomingVideoStreamMap; + IncomingVideoStreamMap _streamRenderMap; }; } // namespace webrtc diff --git a/system_wrappers/interface/map_wrapper.h b/system_wrappers/interface/map_wrapper.h deleted file mode 100644 index 86643e59..00000000 --- a/system_wrappers/interface/map_wrapper.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * 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 - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_MAP_WRAPPER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_MAP_WRAPPER_H_ - -#include <map> - -#include "webrtc/system_wrappers/interface/constructor_magic.h" - -namespace webrtc { - -class MapItem { - public: - MapItem(int id, void* ptr); - virtual ~MapItem(); - void* GetItem(); - int GetId(); - unsigned int GetUnsignedId(); - void SetItem(void* ptr); - - private: - friend class MapWrapper; - - int item_id_; - void* item_pointer_; -}; - -class MapWrapper { - public: - MapWrapper(); - ~MapWrapper(); - - // Puts a pointer to anything in the map and associates it with id. Note, id - // needs to be unique for all items in the map. - int Insert(int id, void* ptr); - - // Removes item from map. - int Erase(MapItem* item); - - // Finds item with associated with id and removes it from the map. - int Erase(int id); - - // Returns the number of elements stored in the map. - int Size() const; - - // Returns a pointer to the first MapItem in the map. - MapItem* First() const; - - // Returns a pointer to the last MapItem in the map. - MapItem* Last() const; - - // Returns a pointer to the MapItem stored after item in the map. - MapItem* Next(MapItem* item) const; - - // Returns a pointer to the MapItem stored before item in the map. - MapItem* Previous(MapItem* item) const; - - // Returns a pointer to the MapItem associated with id from the map. - MapItem* Find(int id) const; - - private: - std::map<int, MapItem*> map_; -}; - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_MAP_WRAPPER_H_ diff --git a/system_wrappers/source/Android.mk b/system_wrappers/source/Android.mk index d8e83503..6cc7a0ba 100644 --- a/system_wrappers/source/Android.mk +++ b/system_wrappers/source/Android.mk @@ -19,7 +19,6 @@ LOCAL_CPP_EXTENSION := .cc LOCAL_SRC_FILES := \ android/cpu-features.c \ cpu_features_android.c \ - map.cc \ sort.cc \ aligned_malloc.cc \ atomic32_posix.cc \ diff --git a/system_wrappers/source/map.cc b/system_wrappers/source/map.cc deleted file mode 100644 index 63ec54fb..00000000 --- a/system_wrappers/source/map.cc +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * 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 - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/system_wrappers/interface/map_wrapper.h" - -#include "webrtc/system_wrappers/interface/trace.h" - -namespace webrtc { - -MapItem::MapItem(int id, void* item) - : item_id_(id), - item_pointer_(item) { -} - -MapItem::~MapItem() { -} - -void* MapItem::GetItem() { - return item_pointer_; -} - -int MapItem::GetId() { - return item_id_; -} - -unsigned int MapItem::GetUnsignedId() { - return static_cast<unsigned int>(item_id_); -} - -void MapItem::SetItem(void* ptr) { - item_pointer_ = ptr; -} - -MapWrapper::MapWrapper() : map_() { -} - -MapWrapper::~MapWrapper() { - if (!map_.empty()) { - WEBRTC_TRACE(kTraceMemory, kTraceUtility, -1, - "Potential memory leak in MapWrapper"); - // Remove all map items. Please note that std::map::clear() can't be - // used because each item has some dynamically allocated memory - // associated with it (i.e. using std::map::clear would introduce a - // memory leak). - while (Erase(First()) == 0) - {} - } -} - -int MapWrapper::Size() const { - return (int)map_.size(); -} - -int MapWrapper::Insert(int id, void* ptr) { - map_[id] = new MapItem(id, ptr); - return 0; -} - -MapItem* MapWrapper::First() const { - std::map<int, MapItem*>::const_iterator it = map_.begin(); - if (it != map_.end()) { - return it->second; - } - return 0; -} - -MapItem* MapWrapper::Last() const { - std::map<int, MapItem*>::const_reverse_iterator it = map_.rbegin(); - if (it != map_.rend()) { - return it->second; - } - return 0; -} - -MapItem* MapWrapper::Next(MapItem* item) const { - if (item == 0) { - return 0; - } - std::map<int, MapItem*>::const_iterator it = map_.find(item->item_id_); - if (it != map_.end()) { - it++; - if (it != map_.end()) { - return it->second; - } - } - return 0; -} - -MapItem* MapWrapper::Previous(MapItem* item) const { - if (item == 0) { - return 0; - } - - std::map<int, MapItem*>::const_iterator it = map_.find(item->item_id_); - if ((it != map_.end()) && - (it != map_.begin())) { - --it; - return it->second; - } - return 0; -} - -MapItem* MapWrapper::Find(int id) const { - std::map<int, MapItem*>::const_iterator it = map_.find(id); - if (it != map_.end()) { - return it->second; - } - return 0; -} - -int MapWrapper::Erase(MapItem* item) { - if (item == 0) { - return -1; - } - std::map<int, MapItem*>::iterator it = map_.find(item->item_id_); - if (it != map_.end()) { - delete it->second; - map_.erase(it); - return 0; - } - return -1; -} - -int MapWrapper::Erase(const int id) { - std::map<int, MapItem*>::iterator it = map_.find(id); - if (it != map_.end()) { - delete it->second; - map_.erase(it); - return 0; - } - return -1; -} - -} // namespace webrtc diff --git a/system_wrappers/source/map_no_stl.cc b/system_wrappers/source/map_no_stl.cc deleted file mode 100644 index 171483e1..00000000 --- a/system_wrappers/source/map_no_stl.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * 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 - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/system_wrappers/source/map_no_stl.h" - -#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" -#include "webrtc/system_wrappers/interface/trace.h" - -namespace webrtc { - -MapNoStlItem::MapNoStlItem(int id, void* item) - : next_(0), - prev_(0), - item_id_(id), - item_ptr_(item) { -} - -MapNoStlItem::~MapNoStlItem() { -} - -void* MapNoStlItem::GetItem() { - return item_ptr_; -} - -int MapNoStlItem::GetId() { - return item_id_; -} - -unsigned int MapNoStlItem::GetUnsignedId() { - return static_cast<unsigned int>(item_id_); -} - -void MapNoStlItem::SetItem(void* ptr) { - item_ptr_ = ptr; -} - -MapNoStl::MapNoStl() - : critical_section_(CriticalSectionWrapper::CreateCriticalSection()), - first_(0), - last_(0), - size_(0) { -} - -MapNoStl::~MapNoStl() { - if (First()) { - WEBRTC_TRACE(kTraceMemory, kTraceUtility, -1, - "Potential memory leak in MapNoStl"); - while (Erase(First()) == 0) - {} - } - delete critical_section_; -} - -int MapNoStl::Size() const { - return size_; -} - -int MapNoStl::Insert(int id, void* ptr) { - MapNoStlItem* new_item = new MapNoStlItem(id, ptr); - - CriticalSectionScoped lock(critical_section_); - MapNoStlItem* item = first_; - size_++; - if (!item) { - first_ = new_item; - last_ = new_item; - return 0; - } - while (item->next_) { - // Three scenarios - // 1. Item should be inserted first. - // 2. Item should be inserted between two items - // 3. Item should be inserted last - if (item->GetId() > id) { - new_item->next_ = item; - item->prev_ = new_item; - if (item == first_) { - first_ = new_item; - } else { - new_item->prev_ = item->prev_; - new_item->prev_->next_ = new_item; - } - return 0; - } - item = item->next_; - } - // 3 - item->next_ = new_item; - new_item->prev_ = item; - last_ = new_item; - return 0; -} - -MapNoStlItem* MapNoStl::First() const { - return first_; -} - -MapNoStlItem* MapNoStl::Last() const { - return last_; -} - -MapNoStlItem* MapNoStl::Next(MapNoStlItem* item) const { - if (!item) { - return 0; - } - return item->next_; -} - -MapNoStlItem* MapNoStl::Previous(MapNoStlItem* item) const { - if (!item) { - return 0; - } - return item->prev_; -} - -MapNoStlItem* MapNoStl::Find(int id) const { - CriticalSectionScoped lock(critical_section_); - MapNoStlItem* item = Locate(id); - return item; -} - -int MapNoStl::Erase(MapNoStlItem* item) { - if (!item) { - return -1; - } - CriticalSectionScoped lock(critical_section_); - return Remove(item); -} - -int MapNoStl::Erase(const int id) { - CriticalSectionScoped lock(critical_section_); - MapNoStlItem* item = Locate(id); - if (!item) { - return -1; - } - return Remove(item); -} - -MapNoStlItem* MapNoStl::Locate(int id) const { - MapNoStlItem* item = first_; - while (item) { - if (item->GetId() == id) { - return item; - } - item = item->next_; - } - return 0; -} - -int MapNoStl::Remove(MapNoStlItem* item) { - if (!item) { - return -1; - } - size_--; - MapNoStlItem* previous_item = item->prev_; - MapNoStlItem* next_item = item->next_; - if (!previous_item) { - next_item->prev_ = 0; - first_ = next_item; - } else { - previous_item->next_ = next_item; - } - if (!next_item) { - previous_item->next_ = 0; - last_ = previous_item; - } else { - next_item->prev_ = previous_item; - } - delete item; - return 0; -} - -} // namespace webrtc diff --git a/system_wrappers/source/map_no_stl.h b/system_wrappers/source/map_no_stl.h deleted file mode 100644 index 23c559d5..00000000 --- a/system_wrappers/source/map_no_stl.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * 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 - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_MAP_NO_STL_H_ -#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_MAP_NO_STL_H_ - -#include "webrtc/system_wrappers/interface/constructor_magic.h" - -namespace webrtc { - -class CriticalSectionWrapper; - -class MapNoStlItem { - friend class Map; - - public: - MapNoStlItem(int id, void* ptr); - virtual ~MapNoStlItem(); - void* GetItem(); - int GetId(); - unsigned int GetUnsignedId(); - void SetItem(void* ptr); - - protected: - MapNoStlItem* next_; - MapNoStlItem* prev_; - - private: - int item_id_; - void* item_ptr_; - DISALLOW_COPY_AND_ASSIGN(MapNoStlItem); -}; - -class MapNoStl { - public: - MapNoStl(); - virtual ~MapNoStl(); - - // MapWrapper functions. - int Insert(int id, void* ptr); - int Erase(MapNoStlItem* item); - int Erase(int id); - int Size() const; - MapNoStlItem* First() const; - MapNoStlItem* Last() const; - MapNoStlItem* Next(MapNoStlItem* item) const; - MapNoStlItem* Previous(MapNoStlItem* item) const; - MapNoStlItem* Find(int id) const; - - private: - MapNoStlItem* Locate(int id) const; - int Remove(MapNoStlItem* item); - - CriticalSection* critical_section_; - MapNoStlItem* first_; - MapNoStlItem* last_; - int size_; - DISALLOW_COPY_AND_ASSIGN(MapNoStl); -}; - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_MAP_NO_STL_H_ diff --git a/system_wrappers/source/map_unittest.cc b/system_wrappers/source/map_unittest.cc deleted file mode 100644 index b82084d7..00000000 --- a/system_wrappers/source/map_unittest.cc +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * 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 - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/system_wrappers/interface/map_wrapper.h" - -#include "testing/gtest/include/gtest/gtest.h" - -using ::webrtc::MapWrapper; -using ::webrtc::MapItem; - -const int kNumberOfElements = 10; - -int* ItemPointer(MapItem* item) { - if (item == NULL) { - return NULL; - } - return reinterpret_cast<int*>(item->GetItem()); -} - -bool DeleteItemContent(MapItem* item) { - if (item == NULL) { - return false; - } - int* value_ptr = ItemPointer(item); - delete value_ptr; - return true; -} - -int ItemValue(MapItem* item) { - if (item == NULL) { - return -1; - } - const int* value_ptr = ItemPointer(item); - if (value_ptr == 0) { - return -1; - } - return *value_ptr; -} - -void PrintToConsole(const char* message, bool supress) { - if (supress) { - return; - } - printf("%s", message); -} - -bool CreateAscendingMap(MapWrapper* ascending_map) { - int* insert_value = NULL; - for (int i = 0; i < kNumberOfElements; ++i) { - insert_value = new int; - if (insert_value == NULL) { - return false; - } - *insert_value = i; - if (0 != ascending_map->Insert( - i, - reinterpret_cast<void*>(insert_value))) { - return false; - } - } - return true; -} - -bool ClearMap(MapWrapper* clear_map) { - bool success = true; - while (clear_map->Size() != 0) { - MapItem* remove_item = clear_map->First(); - if (remove_item == NULL) { - return false; - } - if (!DeleteItemContent(remove_item)) { - success = false; - } - if (clear_map->Erase(remove_item) != 0) { - return false; - } - } - return success; -} - -void PrintMapItem(MapItem* item, bool supress) { - const int id = item->GetId(); - const int value = ItemValue(item); - char print_buffer[16]; - sprintf(print_buffer, "(%3i,%3i) ", id, value); - PrintToConsole(print_buffer, supress); -} - -// Succeeds only if all the items were printed. -bool PrintMap(const MapWrapper& print_map, bool supress) { - const int elements_to_print = print_map.Size(); - int elements_printed = 0; - MapItem* item = print_map.First(); - PrintToConsole("[", supress); - while (item != NULL) { - PrintMapItem(item, supress); - ++elements_printed; - item = print_map.Next(item); - } - PrintToConsole("]\n", supress); - return elements_printed == elements_to_print; -} - -// Succeeds only if all the items were printed. -bool ReversePrintMap(const MapWrapper& print_map, bool supress) { - const int elements_to_print = print_map.Size(); - int elements_printed = 0; - MapItem* item = print_map.Last(); - PrintToConsole("[", supress); - while (item != NULL) { - PrintMapItem(item, supress); - ++elements_printed; - item = print_map.Previous(item); - } - PrintToConsole("]\n", supress); - return elements_printed == elements_to_print; -} - -// Returns true if the map items contain the same item. -bool CompareItems(MapItem* lhs_item, MapItem* rhs_item) { - if ((lhs_item == NULL) || (rhs_item == NULL)) { - return false; - } - if (lhs_item->GetId() != rhs_item->GetId()) { - return false; - } - return lhs_item->GetItem() == rhs_item->GetItem(); -} - -// Returns true if the map contains the same items. -bool CompareMaps(const MapWrapper& lhs, const MapWrapper& rhs) { - const int map_size = lhs.Size(); - if (map_size != rhs.Size()) { - return false; - } - int item_count = 0; - MapItem* lhs_item = lhs.First(); - while (lhs_item != NULL) { - MapItem* rhs_item = rhs.Find(lhs_item->GetId()); - if (rhs_item == NULL) { - return false; - } - if (!CompareItems(lhs_item, rhs_item)) { - return false; - } - ++item_count; - lhs_item = lhs.Next(lhs_item); - } - return item_count == map_size; -} - -class MapWrapperTest : public ::testing::Test { -protected: - virtual void SetUp() { - ASSERT_TRUE(CreateAscendingMap(&ascending_map_)); - } - - virtual void TearDown() { - EXPECT_TRUE(ClearMap(&ascending_map_)); - } - MapWrapper ascending_map_; -}; - -TEST_F(MapWrapperTest, RemoveTest) { - // Erase using int id - { - // Create local scope to avoid accidental re-use - MapItem* item_first = ascending_map_.First(); - ASSERT_FALSE(item_first == NULL); - const int first_value_id = item_first->GetId(); - const int first_value = ItemValue(item_first); - EXPECT_TRUE(first_value == 0); - EXPECT_EQ(first_value_id, first_value); - EXPECT_FALSE(NULL == ascending_map_.Find(first_value_id)); - EXPECT_TRUE(DeleteItemContent(item_first)); - ascending_map_.Erase(first_value_id); - EXPECT_TRUE(NULL == ascending_map_.Find(first_value_id)); - EXPECT_EQ(kNumberOfElements - 1, ascending_map_.Size()); - } - - // Erase using MapItem* item - MapItem* item_last = ascending_map_.Last(); - ASSERT_FALSE(item_last == NULL); - const int last_value_id = item_last->GetId(); - const int last_value = ItemValue(item_last); - EXPECT_TRUE(last_value == kNumberOfElements - 1); - EXPECT_EQ(last_value_id, last_value); - EXPECT_FALSE(NULL == ascending_map_.Find(last_value_id)); - EXPECT_TRUE(DeleteItemContent(item_last)); - ascending_map_.Erase(last_value_id); - EXPECT_TRUE(NULL == ascending_map_.Find(last_value_id)); - EXPECT_EQ(kNumberOfElements - 2, ascending_map_.Size()); -} - -TEST_F(MapWrapperTest, PrintTest) { - const bool supress = true; // Don't spam the console - - EXPECT_TRUE(PrintMap(ascending_map_, supress)); - EXPECT_TRUE(ReversePrintMap(ascending_map_, supress)); -} - -TEST_F(MapWrapperTest, CopyTest) { - MapWrapper compare_map; - ASSERT_TRUE(CreateAscendingMap(&compare_map)); - const int map_size = compare_map.Size(); - ASSERT_EQ(ascending_map_.Size(), map_size); - // CompareMaps compare the pointers not value of the pointers. - // (the values are the same since both are ascending maps). - EXPECT_FALSE(CompareMaps(compare_map, ascending_map_)); - - int copy_count = 0; - MapItem* ascend_item = ascending_map_.First(); - while (ascend_item != NULL) { - MapItem* compare_item = compare_map.Find(ascend_item->GetId()); - ASSERT_FALSE(compare_item == NULL); - DeleteItemContent(compare_item); - compare_item->SetItem(ascend_item->GetItem()); - ascend_item = ascending_map_.Next(ascend_item); - ++copy_count; - } - EXPECT_TRUE(CompareMaps(compare_map, ascending_map_)); - while (compare_map.Erase(compare_map.First()) == 0) { - } - EXPECT_EQ(map_size, copy_count); -} diff --git a/system_wrappers/source/system_wrappers.gyp b/system_wrappers/source/system_wrappers.gyp index 38eceac7..4f6d0833 100644 --- a/system_wrappers/source/system_wrappers.gyp +++ b/system_wrappers/source/system_wrappers.gyp @@ -39,7 +39,6 @@ '../interface/fix_interlocked_exchange_pointer_win.h', '../interface/list_wrapper.h', '../interface/logging.h', - '../interface/map_wrapper.h', '../interface/ref_count.h', '../interface/rw_lock_wrapper.h', '../interface/scoped_ptr.h', @@ -85,7 +84,6 @@ 'list_no_stl.cc', 'logging.cc', 'logging_no_op.cc', - 'map.cc', 'rw_lock.cc', 'rw_lock_generic.cc', 'rw_lock_generic.h', diff --git a/system_wrappers/source/system_wrappers_tests.gyp b/system_wrappers/source/system_wrappers_tests.gyp index e34856fa..a24b8745 100644 --- a/system_wrappers/source/system_wrappers_tests.gyp +++ b/system_wrappers/source/system_wrappers_tests.gyp @@ -26,7 +26,6 @@ 'event_tracer_unittest.cc', 'list_unittest.cc', 'logging_unittest.cc', - 'map_unittest.cc', 'data_log_unittest.cc', 'data_log_unittest_disabled.cc', 'data_log_helpers_unittest.cc', diff --git a/system_wrappers/test/map/map.cc b/system_wrappers/test/map/map.cc deleted file mode 100644 index 58f97291..00000000 --- a/system_wrappers/test/map/map.cc +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * 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 - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include <stdio.h> -#include <stdlib.h> - -#include "webrtc/system_wrappers/interface/map_wrapper.h" - -const int kNumberOfElements = 10; - -void FailTest(bool failed) -{ - if (failed) - { - printf("Test failed!\n"); - printf("Press enter to continue:"); - getchar(); - exit(0); - } -} - -int GetStoredIntegerValue(MapItem* map_item) -{ - void* map_item_pointer = map_item->GetItem(); - if (map_item_pointer != NULL) - { - return *(reinterpret_cast<int*>(map_item_pointer)); - } - return static_cast<int>(map_item->GetUnsignedId()); -} - -void PrintMap(MapWrapper& map) -{ - MapItem* map_item = map.First(); - printf("Map: "); - while (map_item != NULL) - { - int item_value = GetStoredIntegerValue(map_item); - FailTest(item_value < 0); - printf(" %d",item_value); - map_item = map.Next(map_item); - } - printf("\n"); -} - -int main(int /*argc*/, char* /*argv*/[]) -{ - int element_array[kNumberOfElements]; - for (int i = 0; i < kNumberOfElements; i++) - { - element_array[i] = i; - } - // Test insert - MapWrapper test_map; - for (int i = 0; i < kNumberOfElements; i++) - { - test_map.Insert(i,(void*)&element_array[i]); - } - // Test Erase1 - MapItem* remove_item = test_map.Find(2); - FailTest(remove_item == NULL); - FailTest(test_map.Erase(remove_item) != 0); - FailTest(test_map.Find(2) != NULL); - remove_item = NULL; - FailTest(test_map.Erase(remove_item) != -1); - // Test Erase2 - FailTest(test_map.Erase(1) != 0); - FailTest(test_map.Find(1) != NULL); - FailTest(test_map.Erase(1) != -1); - // Test Size - FailTest(test_map.Size() != kNumberOfElements - 2); - PrintMap(test_map); - // Test First - MapItem* first_item = test_map.First(); - FailTest(first_item == NULL); - FailTest(GetStoredIntegerValue(first_item) != 0); - // Test Last - MapItem* last_item = test_map.Last(); - FailTest(last_item == NULL); - FailTest(GetStoredIntegerValue(last_item) != 9); - // Test Next - MapItem* second_item = test_map.Next(first_item); - FailTest(second_item == NULL); - FailTest(GetStoredIntegerValue(second_item) != 3); - FailTest(test_map.Next(last_item) != NULL); - // Test Previous - MapItem* second_to_last_item = test_map.Previous(last_item); - FailTest(second_to_last_item == NULL); - FailTest(GetStoredIntegerValue(second_to_last_item) != 8); - FailTest(test_map.Previous(first_item) != NULL); - // Test Find (only improper usage untested) - FailTest(test_map.Find(kNumberOfElements + 2) != NULL); - // Test GetId - FailTest(*(reinterpret_cast<int*>(second_to_last_item->GetItem())) != - second_to_last_item->GetId()); - FailTest(second_to_last_item->GetUnsignedId() != - static_cast<unsigned int>(second_to_last_item->GetId())); - // Test SetItem - int swapped_item = kNumberOfElements; - last_item->SetItem(reinterpret_cast<void*>(&swapped_item)); - FailTest(GetStoredIntegerValue(last_item) != - swapped_item); - - printf("Tests passed successfully!\n"); -} diff --git a/test/channel_transport/udp_socket_manager_posix.cc b/test/channel_transport/udp_socket_manager_posix.cc index 18f9ae38..5543814b 100644 --- a/test/channel_transport/udp_socket_manager_posix.cc +++ b/test/channel_transport/udp_socket_manager_posix.cc @@ -214,15 +214,13 @@ UdpSocketManagerPosixImpl::~UdpSocketManagerPosixImpl() UpdateSocketMap(); _critSectList->Enter(); - - MapItem* item = _socketMap.First(); - while(item) - { - UdpSocketPosix* s = static_cast<UdpSocketPosix*>(item->GetItem()); - _socketMap.Erase(item); - item = _socketMap.First(); - delete s; + for (std::map<SOCKET, UdpSocketPosix*>::iterator it = + _socketMap.begin(); + it != _socketMap.end(); + ++it) { + delete it->second; } + _socketMap.clear(); _critSectList->Leave(); delete _critSectList; @@ -264,18 +262,19 @@ bool UdpSocketManagerPosixImpl::Process() struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 10000; - MapItem* it; FD_ZERO(&_readFds); UpdateSocketMap(); - unsigned int maxFd = 0; - for (it = _socketMap.First(); it != NULL; it=_socketMap.Next(it)) - { - doSelect = true; - maxFd = maxFd > it->GetUnsignedId() ? maxFd : it->GetUnsignedId(); - FD_SET(it->GetUnsignedId(), &_readFds); + SOCKET maxFd = 0; + for (std::map<SOCKET, UdpSocketPosix*>::iterator it = _socketMap.begin(); + it != _socketMap.end(); + ++it) { + doSelect = true; + if (it->first > maxFd) + maxFd = it->first; + FD_SET(it->first, &_readFds); } int num = 0; @@ -296,16 +295,15 @@ bool UdpSocketManagerPosixImpl::Process() return true; } - for (it = _socketMap.First(); it != NULL && num > 0; - it = _socketMap.Next(it)) - { - UdpSocketPosix* s = static_cast<UdpSocketPosix*>(it->GetItem()); - if (FD_ISSET(it->GetUnsignedId(), &_readFds)) - { - s->HasIncoming(); - num--; - } + for (std::map<SOCKET, UdpSocketPosix*>::iterator it = _socketMap.begin(); + it != _socketMap.end(); + ++it) { + if (FD_ISSET(it->first, &_readFds)) { + it->second->HasIncoming(); + --num; + } } + return true; } @@ -352,11 +350,11 @@ bool UdpSocketManagerPosixImpl::RemoveSocket(UdpSocketWrapper* s) // Checking the socket map is safe since all Erase and Insert calls to this // map are also protected by _critSectList. - if(_socketMap.Find(static_cast<UdpSocketPosix*>(s)->GetFd()) != NULL) - { - _removeList.PushBack(static_cast<UdpSocketPosix*>(s)->GetFd()); - _critSectList->Leave(); - return true; + if (_socketMap.find(static_cast<UdpSocketPosix*>(s)->GetFd()) != + _socketMap.end()) { + _removeList.PushBack(static_cast<UdpSocketPosix*>(s)->GetFd()); + _critSectList->Leave(); + return true; } _critSectList->Leave(); return false; @@ -369,7 +367,7 @@ void UdpSocketManagerPosixImpl::UpdateSocketMap() while(!_removeList.Empty()) { UdpSocketPosix* deleteSocket = NULL; - unsigned int removeFD = _removeList.First()->GetUnsignedItem(); + SOCKET removeFD = _removeList.First()->GetUnsignedItem(); // If the socket is in the add list it hasn't been added to the socket // map yet. Just remove the socket from the add list. @@ -377,7 +375,7 @@ void UdpSocketManagerPosixImpl::UpdateSocketMap() while(addListItem) { UdpSocketPosix* addSocket = (UdpSocketPosix*)addListItem->GetItem(); - unsigned int addFD = addSocket->GetFd(); + SOCKET addFD = addSocket->GetFd(); if(removeFD == addFD) { deleteSocket = addSocket; @@ -388,16 +386,12 @@ void UdpSocketManagerPosixImpl::UpdateSocketMap() } // Find and remove socket from _socketMap. - MapItem* it = _socketMap.Find(removeFD); - if(it != NULL) + std::map<SOCKET, UdpSocketPosix*>::iterator it = + _socketMap.find(removeFD); + if(it != _socketMap.end()) { - UdpSocketPosix* socket = - static_cast<UdpSocketPosix*>(it->GetItem()); - if(socket) - { - deleteSocket = socket; - } - _socketMap.Erase(it); + deleteSocket = it->second; + _socketMap.erase(it); } if(deleteSocket) { @@ -412,9 +406,8 @@ void UdpSocketManagerPosixImpl::UpdateSocketMap() { UdpSocketPosix* s = static_cast<UdpSocketPosix*>(_addList.First()->GetItem()); - if(s) - { - _socketMap.Insert(s->GetFd(), s); + if(s) { + _socketMap[s->GetFd()] = s; } _addList.PopFront(); } diff --git a/test/channel_transport/udp_socket_manager_posix.h b/test/channel_transport/udp_socket_manager_posix.h index 4bfae364..0efd6ffa 100644 --- a/test/channel_transport/udp_socket_manager_posix.h +++ b/test/channel_transport/udp_socket_manager_posix.h @@ -14,9 +14,10 @@ #include <sys/types.h> #include <unistd.h> +#include <map> + #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/list_wrapper.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include "webrtc/system_wrappers/interface/thread_wrapper.h" #include "webrtc/test/channel_transport/udp_socket_manager_wrapper.h" #include "webrtc/test/channel_transport/udp_socket_wrapper.h" @@ -27,6 +28,7 @@ class ConditionVariableWrapper; namespace test { +class UdpSocketPosix; class UdpSocketManagerPosixImpl; #define MAX_NUMBER_OF_SOCKET_MANAGERS_LINUX 8 @@ -77,7 +79,7 @@ private: fd_set _readFds; - MapWrapper _socketMap; + std::map<SOCKET, UdpSocketPosix*> _socketMap; ListWrapper _addList; ListWrapper _removeList; }; diff --git a/video_engine/vie_channel_manager.cc b/video_engine/vie_channel_manager.cc index 3c121fe0..02b991c8 100644 --- a/video_engine/vie_channel_manager.cc +++ b/video_engine/vie_channel_manager.cc @@ -14,7 +14,6 @@ #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" #include "webrtc/modules/utility/interface/process_thread.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include "webrtc/system_wrappers/interface/trace.h" #include "webrtc/video_engine/call_stats.h" #include "webrtc/video_engine/encoder_state_feedback.h" diff --git a/video_engine/vie_channel_manager.h b/video_engine/vie_channel_manager.h index 1a2460bd..5ded9567 100644 --- a/video_engine/vie_channel_manager.h +++ b/video_engine/vie_channel_manager.h @@ -27,7 +27,6 @@ namespace webrtc { class Config; class CriticalSectionWrapper; -class MapWrapper; class ProcessThread; class RtcpRttObserver; class ViEChannel; diff --git a/video_engine/vie_input_manager.cc b/video_engine/vie_input_manager.cc index b1f28aea..f5727c56 100644 --- a/video_engine/vie_input_manager.cc +++ b/video_engine/vie_input_manager.cc @@ -44,19 +44,13 @@ ViEInputManager::ViEInputManager(const int engine_id, const Config& config) ViEInputManager::~ViEInputManager() { WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, ViEId(engine_id_), "%s", __FUNCTION__); - while (vie_frame_provider_map_.Size() != 0) { - MapItem* item = vie_frame_provider_map_.First(); - assert(item); - ViEFrameProviderBase* frame_provider = - static_cast<ViEFrameProviderBase*>(item->GetItem()); - vie_frame_provider_map_.Erase(item); - delete frame_provider; + for (FrameProviderMap::iterator it = vie_frame_provider_map_.begin(); + it != vie_frame_provider_map_.end(); + ++it) { + delete it->second; } - if (capture_device_info_) { - delete capture_device_info_; - capture_device_info_ = NULL; - } + delete capture_device_info_; } void ViEInputManager::SetModuleProcessThread( ProcessThread* module_process_thread) { @@ -191,18 +185,17 @@ int ViEInputManager::CreateCaptureDevice( CriticalSectionScoped cs(map_cs_.get()); // Make sure the device is not already allocated. - for (MapItem* item = vie_frame_provider_map_.First(); item != NULL; - item = vie_frame_provider_map_.Next(item)) { + for (FrameProviderMap::iterator it = vie_frame_provider_map_.begin(); + it != vie_frame_provider_map_.end(); + ++it) { // Make sure this is a capture device. - if (item->GetId() >= kViECaptureIdBase && - item->GetId() <= kViECaptureIdMax) { - ViECapturer* vie_capture = static_cast<ViECapturer*>(item->GetItem()); + if (it->first >= kViECaptureIdBase && it->first <= kViECaptureIdMax) { + ViECapturer* vie_capture = static_cast<ViECapturer*>(it->second); assert(vie_capture); // TODO(mflodman) Can we change input to avoid this cast? const char* device_name = reinterpret_cast<const char*>(vie_capture->CurrentDeviceName()); - if (strncmp(device_name, - reinterpret_cast<const char*>(device_unique_idUTF8), + if (strncmp(device_name, device_unique_idUTF8, strlen(device_name)) == 0) { return kViECaptureDeviceAlreadyAllocated; } @@ -266,13 +259,7 @@ int ViEInputManager::CreateCaptureDevice( return kViECaptureDeviceUnknownError; } - if (vie_frame_provider_map_.Insert(newcapture_id, vie_capture) != 0) { - ReturnCaptureId(newcapture_id); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(engine_id_), - "%s: Could not insert capture module for %s", __FUNCTION__, - device_unique_idUTF8); - return kViECaptureDeviceUnknownError; - } + vie_frame_provider_map_[newcapture_id] = vie_capture; capture_id = newcapture_id; WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_), "%s(device_unique_id: %s, capture_id: %d)", __FUNCTION__, @@ -303,12 +290,7 @@ int ViEInputManager::CreateCaptureDevice(VideoCaptureModule* capture_module, "%s: Could attach capture module.", __FUNCTION__); return kViECaptureDeviceUnknownError; } - if (vie_frame_provider_map_.Insert(newcapture_id, vie_capture) != 0) { - ReturnCaptureId(newcapture_id); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(engine_id_), - "%s: Could not insert capture module", __FUNCTION__); - return kViECaptureDeviceUnknownError; - } + vie_frame_provider_map_[newcapture_id] = vie_capture; capture_id = newcapture_id; WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_), "%s, capture_id: %d", __FUNCTION__, capture_id); @@ -340,7 +322,7 @@ int ViEInputManager::DestroyCaptureDevice(const int capture_id) { "callbacks when destroying capture device", __FUNCTION__, capture_id, num_callbacks); } - vie_frame_provider_map_.Erase(capture_id); + vie_frame_provider_map_.erase(capture_id); ReturnCaptureId(capture_id); // Leave cs before deleting the capture object. This is because deleting the // object might cause deletions of renderers so we prefer to not have a lock @@ -375,13 +357,7 @@ int ViEInputManager::CreateExternalCaptureDevice( return kViECaptureDeviceUnknownError; } - if (vie_frame_provider_map_.Insert(newcapture_id, vie_capture) != 0) { - ReturnCaptureId(newcapture_id); - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(engine_id_), - "%s: Could not insert capture module for external capture.", - __FUNCTION__); - return kViECaptureDeviceUnknownError; - } + vie_frame_provider_map_[newcapture_id] = vie_capture; capture_id = newcapture_id; external_capture = vie_capture; WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_), @@ -421,30 +397,25 @@ ViEFrameProviderBase* ViEInputManager::ViEFrameProvider( assert(capture_observer); CriticalSectionScoped cs(map_cs_.get()); - for (MapItem* provider_item = vie_frame_provider_map_.First(); provider_item - != NULL; provider_item = vie_frame_provider_map_.Next(provider_item)) { - ViEFrameProviderBase* vie_frame_provider = - static_cast<ViEFrameProviderBase*>(provider_item->GetItem()); - assert(vie_frame_provider != NULL); - - if (vie_frame_provider->IsFrameCallbackRegistered(capture_observer)) { - // We found it. - return vie_frame_provider; - } + for (FrameProviderMap::const_iterator it = vie_frame_provider_map_.begin(); + it != vie_frame_provider_map_.end(); + ++it) { + if (it->second->IsFrameCallbackRegistered(capture_observer)) + return it->second; } + // No capture device set for this channel. return NULL; } ViEFrameProviderBase* ViEInputManager::ViEFrameProvider(int provider_id) const { CriticalSectionScoped cs(map_cs_.get()); - MapItem* map_item = vie_frame_provider_map_.Find(provider_id); - if (!map_item) { + + FrameProviderMap::const_iterator it = + vie_frame_provider_map_.find(provider_id); + if (it == vie_frame_provider_map_.end()) return NULL; - } - ViEFrameProviderBase* vie_frame_provider = - static_cast<ViEFrameProviderBase*>(map_item->GetItem()); - return vie_frame_provider; + return it->second; } ViECapturer* ViEInputManager::ViECapturePtr(int capture_id) const { @@ -452,13 +423,7 @@ ViECapturer* ViEInputManager::ViECapturePtr(int capture_id) const { capture_id <= kViECaptureIdBase + kViEMaxCaptureDevices)) return NULL; - CriticalSectionScoped cs(map_cs_.get()); - MapItem* map_item = vie_frame_provider_map_.Find(capture_id); - if (!map_item) { - return NULL; - } - ViECapturer* vie_capture = static_cast<ViECapturer*>(map_item->GetItem()); - return vie_capture; + return static_cast<ViECapturer*>(ViEFrameProvider(capture_id)); } ViEInputManagerScoped::ViEInputManagerScoped( diff --git a/video_engine/vie_input_manager.h b/video_engine/vie_input_manager.h index ed8a908b..a4db9a70 100644 --- a/video_engine/vie_input_manager.h +++ b/video_engine/vie_input_manager.h @@ -11,8 +11,9 @@ #ifndef WEBRTC_VIDEO_ENGINE_VIE_INPUT_MANAGER_H_ #define WEBRTC_VIDEO_ENGINE_VIE_INPUT_MANAGER_H_ +#include <map> + #include "webrtc/modules/video_capture/include/video_capture.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" #include "webrtc/typedefs.h" #include "webrtc/video_engine/include/vie_capture.h" @@ -98,7 +99,9 @@ class ViEInputManager : private ViEManagerBase { int engine_id_; scoped_ptr<CriticalSectionWrapper> map_cs_; scoped_ptr<CriticalSectionWrapper> device_info_cs_; - MapWrapper vie_frame_provider_map_; + + typedef std::map<int, ViEFrameProviderBase*> FrameProviderMap; + FrameProviderMap vie_frame_provider_map_; // Capture devices. VideoCaptureModule::DeviceInfo* capture_device_info_; diff --git a/video_engine/vie_render_manager.cc b/video_engine/vie_render_manager.cc index 79c604bd..2480d90e 100644 --- a/video_engine/vie_render_manager.cc +++ b/video_engine/vie_render_manager.cc @@ -43,14 +43,11 @@ ViERenderManager::ViERenderManager(int32_t engine_id) ViERenderManager::~ViERenderManager() { WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceVideo, ViEId(engine_id_), "ViERenderManager Destructor, engine_id: %d", engine_id_); - - while (stream_to_vie_renderer_.Size() != 0) { - MapItem* item = stream_to_vie_renderer_.First(); - assert(item); - const int32_t render_id = item->GetId(); - // The renderer is delete in RemoveRenderStream. - item = NULL; - RemoveRenderStream(render_id); + for (RendererMap::iterator it = stream_to_vie_renderer_.begin(); + it != stream_to_vie_renderer_.end(); + ++it) { + // The renderer is deleted in RemoveRenderStream. + RemoveRenderStream(it->first); } } @@ -113,7 +110,8 @@ ViERenderer* ViERenderManager::AddRenderStream(const int32_t render_id, const float bottom) { CriticalSectionScoped cs(list_cs_.get()); - if (stream_to_vie_renderer_.Find(render_id) != NULL) { + if (stream_to_vie_renderer_.find(render_id) != + stream_to_vie_renderer_.end()) { // This stream is already added to a renderer, not allowed! WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, ViEId(engine_id_), "Render stream already exists"); @@ -146,7 +144,7 @@ ViERenderer* ViERenderManager::AddRenderStream(const int32_t render_id, "Could not create new render stream"); return NULL; } - stream_to_vie_renderer_.Insert(render_id, vie_renderer); + stream_to_vie_renderer_[render_id] = vie_renderer; return vie_renderer; } @@ -155,28 +153,24 @@ int32_t ViERenderManager::RemoveRenderStream( // We need exclusive right to the items in the render manager to delete a // stream. ViEManagerWriteScoped scope(this); - CriticalSectionScoped cs(list_cs_.get()); - MapItem* map_item = stream_to_vie_renderer_.Find(render_id); - if (!map_item) { + RendererMap::iterator it = stream_to_vie_renderer_.find(render_id); + if (it == stream_to_vie_renderer_.end()) { // No such stream WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideo, ViEId(engine_id_), "No renderer for this stream found, channel_id"); return 0; } - ViERenderer* vie_renderer = static_cast<ViERenderer*>(map_item->GetItem()); - assert(vie_renderer); - // Get the render module pointer for this vie_render object. - VideoRender& renderer = vie_renderer->RenderModule(); + VideoRender& renderer = it->second->RenderModule(); // Delete the vie_render. // This deletes the stream in the render module. - delete vie_renderer; + delete it->second; // Remove from the stream map. - stream_to_vie_renderer_.Erase(map_item); + stream_to_vie_renderer_.erase(it); // Check if there are other streams in the module. if (!use_external_render_module_ && @@ -216,15 +210,11 @@ VideoRender* ViERenderManager::FindRenderModule(void* window) { } ViERenderer* ViERenderManager::ViERenderPtr(int32_t render_id) const { - ViERenderer* renderer = NULL; - MapItem* map_item = stream_to_vie_renderer_.Find(render_id); - if (!map_item) { - // No such stream in any renderer. + RendererMap::const_iterator it = stream_to_vie_renderer_.find(render_id); + if (it == stream_to_vie_renderer_.end()) return NULL; - } - renderer = static_cast<ViERenderer*>(map_item->GetItem()); - return renderer; + return it->second; } } // namespace webrtc diff --git a/video_engine/vie_render_manager.h b/video_engine/vie_render_manager.h index 900fcdc7..bc32893a 100644 --- a/video_engine/vie_render_manager.h +++ b/video_engine/vie_render_manager.h @@ -11,11 +11,11 @@ #ifndef WEBRTC_VIDEO_ENGINE_VIE_RENDER_MANAGER_H_ #define WEBRTC_VIDEO_ENGINE_VIE_RENDER_MANAGER_H_ +#include <map> + #include "webrtc/system_wrappers/interface/list_wrapper.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" #include "webrtc/typedefs.h" - #include "webrtc/video_engine/vie_manager_base.h" namespace webrtc { @@ -55,7 +55,10 @@ class ViERenderManager : private ViEManagerBase { scoped_ptr<CriticalSectionWrapper> list_cs_; int32_t engine_id_; - MapWrapper stream_to_vie_renderer_; // Protected by ViEManagerBase. + // Protected by ViEManagerBase. + typedef std::map<int32_t, ViERenderer*> RendererMap; + RendererMap stream_to_vie_renderer_; + ListWrapper render_list_; bool use_external_render_module_; }; diff --git a/video_engine/vie_renderer.h b/video_engine/vie_renderer.h index 04295f71..4f73e518 100644 --- a/video_engine/vie_renderer.h +++ b/video_engine/vie_renderer.h @@ -12,7 +12,6 @@ #define WEBRTC_VIDEO_ENGINE_VIE_RENDERER_H_ #include "webrtc/modules/video_render/include/video_render_defines.h" -#include "webrtc/system_wrappers/interface/map_wrapper.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" #include "webrtc/video_engine/include/vie_render.h" #include "webrtc/video_engine/vie_frame_provider_base.h" |