Removed MapWrapper from ViEFrameProviderBase.
BUG=C-10189 Review URL: https://webrtc-codereview.appspot.com/356002 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1560 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
194a93ac66
commit
832adebca2
@ -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
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
@ -10,6 +10,9 @@
|
||||
|
||||
#include "video_engine/vie_frame_provider_base.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "modules/interface/module_common_types.h"
|
||||
#include "system_wrappers/interface/critical_section_wrapper.h"
|
||||
#include "system_wrappers/interface/tick_util.h"
|
||||
#include "system_wrappers/interface/trace.h"
|
||||
@ -20,27 +23,22 @@ namespace webrtc {
|
||||
ViEFrameProviderBase::ViEFrameProviderBase(int Id, int engine_id)
|
||||
: id_(Id),
|
||||
engine_id_(engine_id),
|
||||
frame_callbacks_(),
|
||||
provider_cs_(CriticalSectionWrapper::CreateCriticalSection()),
|
||||
extra_frame_(NULL),
|
||||
frame_delay_(0) {
|
||||
}
|
||||
|
||||
ViEFrameProviderBase::~ViEFrameProviderBase() {
|
||||
if (frame_callbacks_.Size() > 0) {
|
||||
if (frame_callbacks_.size() > 0) {
|
||||
WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"FrameCallbacks still exist when Provider deleted %d",
|
||||
frame_callbacks_.Size());
|
||||
}
|
||||
for (MapItem* item = frame_callbacks_.First(); item != NULL;
|
||||
item = frame_callbacks_.Next(item)) {
|
||||
static_cast<ViEFrameCallback*>(item->GetItem())->ProviderDestroyed(id_);
|
||||
frame_callbacks_.size());
|
||||
}
|
||||
|
||||
while (frame_callbacks_.Erase(frame_callbacks_.First()) == 0) {
|
||||
for (FrameCallbacks::iterator it = frame_callbacks_.begin();
|
||||
it != frame_callbacks_.end(); ++it) {
|
||||
(*it)->ProviderDestroyed(id_);
|
||||
}
|
||||
|
||||
delete extra_frame_;
|
||||
frame_callbacks_.clear();
|
||||
}
|
||||
|
||||
int ViEFrameProviderBase::Id() {
|
||||
@ -57,29 +55,19 @@ void ViEFrameProviderBase::DeliverFrame(
|
||||
CriticalSectionScoped cs(provider_cs_.get());
|
||||
|
||||
// Deliver the frame to all registered callbacks.
|
||||
if (frame_callbacks_.Size() > 0) {
|
||||
if (frame_callbacks_.Size() == 1) {
|
||||
if (frame_callbacks_.size() > 0) {
|
||||
if (frame_callbacks_.size() == 1) {
|
||||
// We don't have to copy the frame.
|
||||
ViEFrameCallback* frame_observer =
|
||||
static_cast<ViEFrameCallback*>(frame_callbacks_.First()->GetItem());
|
||||
frame_observer->DeliverFrame(id_, video_frame, num_csrcs, CSRC);
|
||||
frame_callbacks_.front()->DeliverFrame(id_, video_frame, num_csrcs, CSRC);
|
||||
} else {
|
||||
// Make a copy of the frame for all callbacks.
|
||||
for (MapItem* map_item = frame_callbacks_.First(); map_item != NULL;
|
||||
map_item = frame_callbacks_.Next(map_item)) {
|
||||
if (extra_frame_ == NULL) {
|
||||
extra_frame_ = new VideoFrame();
|
||||
}
|
||||
if (map_item != NULL) {
|
||||
ViEFrameCallback* frame_observer =
|
||||
static_cast<ViEFrameCallback*>(map_item->GetItem());
|
||||
if (frame_observer != NULL) {
|
||||
// We must copy the frame each time since the previous receiver
|
||||
// might swap it to avoid a copy.
|
||||
extra_frame_->CopyFrame(video_frame);
|
||||
frame_observer->DeliverFrame(id_, *extra_frame_, num_csrcs, CSRC);
|
||||
}
|
||||
// Make a copy of the frame for all callbacks.callback
|
||||
for (FrameCallbacks::iterator it = frame_callbacks_.begin();
|
||||
it != frame_callbacks_.end(); ++it) {
|
||||
if (!extra_frame_.get()) {
|
||||
extra_frame_.reset(new VideoFrame());
|
||||
}
|
||||
extra_frame_->CopyFrame(video_frame);
|
||||
(*it)->DeliverFrame(id_, *(extra_frame_.get()), num_csrcs, CSRC);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,12 +86,9 @@ void ViEFrameProviderBase::SetFrameDelay(int frame_delay) {
|
||||
CriticalSectionScoped cs(provider_cs_.get());
|
||||
frame_delay_ = frame_delay;
|
||||
|
||||
for (MapItem* map_item = frame_callbacks_.First(); map_item != NULL;
|
||||
map_item = frame_callbacks_.Next(map_item)) {
|
||||
ViEFrameCallback* frame_observer =
|
||||
static_cast<ViEFrameCallback*>(map_item->GetItem());
|
||||
assert(frame_observer);
|
||||
frame_observer->DelayChanged(id_, frame_delay);
|
||||
for (FrameCallbacks::iterator it = frame_callbacks_.begin();
|
||||
it != frame_callbacks_.end(); ++it) {
|
||||
(*it)->DelayChanged(id_, frame_delay);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,20 +104,13 @@ int ViEFrameProviderBase::GetBestFormat(int& best_width,
|
||||
int highest_frame_rate = 0;
|
||||
|
||||
CriticalSectionScoped cs(provider_cs_.get());
|
||||
|
||||
// Check if this one already exists.
|
||||
for (MapItem* map_item = frame_callbacks_.First(); map_item != NULL;
|
||||
map_item = frame_callbacks_.Next(map_item)) {
|
||||
for (FrameCallbacks::iterator it = frame_callbacks_.begin();
|
||||
it != frame_callbacks_.end(); ++it) {
|
||||
int prefered_width = 0;
|
||||
int prefered_height = 0;
|
||||
int prefered_frame_rate = 0;
|
||||
|
||||
ViEFrameCallback* callback_object =
|
||||
static_cast<ViEFrameCallback*>(map_item->GetItem());
|
||||
assert(callback_object);
|
||||
if (callback_object->GetPreferedFrameSettings(prefered_width,
|
||||
prefered_height,
|
||||
prefered_frame_rate) == 0) {
|
||||
if ((*it)->GetPreferedFrameSettings(prefered_width, prefered_height,
|
||||
prefered_frame_rate) == 0) {
|
||||
if (prefered_width > largest_width) {
|
||||
largest_width = prefered_width;
|
||||
}
|
||||
@ -144,51 +122,31 @@ int ViEFrameProviderBase::GetBestFormat(int& best_width,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
best_width = largest_width;
|
||||
best_height = largest_height;
|
||||
best_frame_rate = highest_frame_rate;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ViEFrameProviderBase::RegisterFrameCallback(
|
||||
int observer_id, ViEFrameCallback* callback_object) {
|
||||
if (callback_object == NULL) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s: No argument", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
assert(callback_object);
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, id_), "%s(0x%p)",
|
||||
__FUNCTION__, callback_object);
|
||||
|
||||
{
|
||||
CriticalSectionScoped cs(provider_cs_.get());
|
||||
|
||||
// Check if the callback already exists.
|
||||
for (MapItem* map_item = frame_callbacks_.First();
|
||||
map_item != NULL;
|
||||
map_item = frame_callbacks_.Next(map_item)) {
|
||||
const ViEFrameCallback* observer =
|
||||
static_cast<ViEFrameCallback*>(map_item->GetItem());
|
||||
if (observer == callback_object) {
|
||||
// This callback is already registered.
|
||||
WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s 0x%p already registered", __FUNCTION__,
|
||||
callback_object);
|
||||
assert("!frameObserver already registered");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (frame_callbacks_.Insert(observer_id, callback_object) != 0) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s: Could not add 0x%p to list", __FUNCTION__,
|
||||
if (std::find(frame_callbacks_.begin(), frame_callbacks_.end(),
|
||||
callback_object) != frame_callbacks_.end()) {
|
||||
// This object is already registered.
|
||||
WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s 0x%p already registered", __FUNCTION__,
|
||||
callback_object);
|
||||
assert("!frameObserver already registered");
|
||||
return -1;
|
||||
}
|
||||
frame_callbacks_.push_back(callback_object);
|
||||
}
|
||||
// Report current capture delay
|
||||
// Report current capture delay.
|
||||
callback_object->DelayChanged(id_, frame_delay_);
|
||||
|
||||
// Notify implementer of this class that the callback list have changed.
|
||||
@ -198,38 +156,23 @@ int ViEFrameProviderBase::RegisterFrameCallback(
|
||||
|
||||
int ViEFrameProviderBase::DeregisterFrameCallback(
|
||||
const ViEFrameCallback* callback_object) {
|
||||
if (!callback_object) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s: No argument", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
assert(callback_object);
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, id_), "%s(0x%p)",
|
||||
__FUNCTION__, callback_object);
|
||||
CriticalSectionScoped cs(provider_cs_.get());
|
||||
|
||||
{
|
||||
CriticalSectionScoped cs(provider_cs_.get());
|
||||
bool item_found = false;
|
||||
|
||||
// Try to find the callback in our list.
|
||||
for (MapItem* map_item = frame_callbacks_.First(); map_item != NULL;
|
||||
map_item = frame_callbacks_.Next(map_item)) {
|
||||
const ViEFrameCallback* observer =
|
||||
static_cast<ViEFrameCallback*>(map_item->GetItem());
|
||||
if (observer == callback_object) {
|
||||
// We found it, remove it!
|
||||
frame_callbacks_.Erase(map_item);
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s 0x%p deregistered", __FUNCTION__, callback_object);
|
||||
item_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!item_found) {
|
||||
WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s 0x%p not found", __FUNCTION__, callback_object);
|
||||
return -1;
|
||||
}
|
||||
FrameCallbacks::iterator it = std::find(frame_callbacks_.begin(),
|
||||
frame_callbacks_.end(),
|
||||
callback_object);
|
||||
if (it == frame_callbacks_.end()) {
|
||||
WEBRTC_TRACE(kTraceWarning, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s 0x%p not found", __FUNCTION__, callback_object);
|
||||
return -1;
|
||||
}
|
||||
frame_callbacks_.erase(it);
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s 0x%p deregistered", __FUNCTION__, callback_object);
|
||||
|
||||
// Notify implementer of this class that the callback list have changed.
|
||||
FrameCallbackChanged();
|
||||
return 0;
|
||||
@ -237,30 +180,18 @@ int ViEFrameProviderBase::DeregisterFrameCallback(
|
||||
|
||||
bool ViEFrameProviderBase::IsFrameCallbackRegistered(
|
||||
const ViEFrameCallback* callback_object) {
|
||||
if (!callback_object) {
|
||||
WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s: No argument", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
assert(callback_object);
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s(0x%p)", __FUNCTION__, callback_object);
|
||||
|
||||
for (MapItem* map_item = frame_callbacks_.First(); map_item != NULL;
|
||||
map_item = frame_callbacks_.Next(map_item)) {
|
||||
if (callback_object == map_item->GetItem()) {
|
||||
// We found the callback.
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s 0x%p is registered", __FUNCTION__, callback_object);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(engine_id_, id_),
|
||||
"%s 0x%p not registered", __FUNCTION__, callback_object);
|
||||
return false;
|
||||
CriticalSectionScoped cs(provider_cs_.get());
|
||||
return std::find(frame_callbacks_.begin(), frame_callbacks_.end(),
|
||||
callback_object) != frame_callbacks_.end();
|
||||
}
|
||||
|
||||
int ViEFrameProviderBase::NumberOfRegisteredFrameCallbacks() {
|
||||
CriticalSectionScoped cs(provider_cs_.get());
|
||||
return frame_callbacks_.Size();
|
||||
return frame_callbacks_.size();
|
||||
}
|
||||
|
||||
} // namespac webrtc
|
||||
|
@ -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
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
@ -11,8 +11,9 @@
|
||||
#ifndef WEBRTC_VIDEO_ENGINE_VIE_FRAME_PROVIDER_BASE_H_
|
||||
#define WEBRTC_VIDEO_ENGINE_VIE_FRAME_PROVIDER_BASE_H_
|
||||
|
||||
#include "modules/interface/module_common_types.h"
|
||||
#include "system_wrappers/interface/map_wrapper.h"
|
||||
#include <vector>
|
||||
|
||||
#include "common_types.h"
|
||||
#include "system_wrappers/interface/scoped_ptr.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
@ -20,6 +21,7 @@ namespace webrtc {
|
||||
|
||||
class CriticalSectionWrapper;
|
||||
class VideoEncoder;
|
||||
class VideoFrame;
|
||||
|
||||
// ViEFrameCallback shall be implemented by all classes receiving frames from a
|
||||
// frame provider.
|
||||
@ -86,11 +88,12 @@ class ViEFrameProviderBase {
|
||||
int engine_id_;
|
||||
|
||||
// Frame callbacks.
|
||||
MapWrapper frame_callbacks_;
|
||||
typedef std::vector<ViEFrameCallback*> FrameCallbacks;
|
||||
FrameCallbacks frame_callbacks_;
|
||||
scoped_ptr<CriticalSectionWrapper> provider_cs_;
|
||||
|
||||
private:
|
||||
VideoFrame* extra_frame_;
|
||||
scoped_ptr<VideoFrame> extra_frame_;
|
||||
int frame_delay_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user