This source file includes following definitions.
- OnReceiveFrameEvent
- OnReceivePacketEvent
- OnReceiveGenericEvent
- GetRtcpEventsAndReset
- TruncateMapIfNeeded
#include "media/cast/rtcp/sender_rtcp_event_subscriber.h"
#include <utility>
#include "base/logging.h"
#include "media/cast/rtcp/rtcp_defines.h"
namespace media {
namespace cast {
SenderRtcpEventSubscriber::SenderRtcpEventSubscriber(
const size_t max_size_to_retain)
: max_size_to_retain_(max_size_to_retain) {
DCHECK(max_size_to_retain_ > 0u);
}
SenderRtcpEventSubscriber::~SenderRtcpEventSubscriber() {
DCHECK(thread_checker_.CalledOnValidThread());
}
void SenderRtcpEventSubscriber::OnReceiveFrameEvent(
const FrameEvent& frame_event) {
DCHECK(thread_checker_.CalledOnValidThread());
if (frame_event.type != kVideoFrameCaptured &&
frame_event.type != kVideoFrameSentToEncoder &&
frame_event.type != kVideoFrameEncoded) {
return;
}
RtcpEventMap::iterator it = rtcp_events_.find(frame_event.rtp_timestamp);
if (it == rtcp_events_.end()) {
RtcpEvent rtcp_event;
rtcp_event.type = frame_event.type;
rtcp_event.timestamp = frame_event.timestamp;
rtcp_events_.insert(std::make_pair(frame_event.rtp_timestamp, rtcp_event));
TruncateMapIfNeeded();
} else {
if (frame_event.type == kVideoFrameCaptured) {
return;
}
if (it->second.type == kVideoFrameEncoded) {
return;
}
it->second.type = frame_event.type;
}
DCHECK(rtcp_events_.size() <= max_size_to_retain_);
}
void SenderRtcpEventSubscriber::OnReceivePacketEvent(
const PacketEvent& packet_event) {
DCHECK(thread_checker_.CalledOnValidThread());
}
void SenderRtcpEventSubscriber::OnReceiveGenericEvent(
const GenericEvent& generic_event) {
DCHECK(thread_checker_.CalledOnValidThread());
}
void SenderRtcpEventSubscriber::GetRtcpEventsAndReset(
RtcpEventMap* rtcp_events) {
DCHECK(thread_checker_.CalledOnValidThread());
rtcp_events->swap(rtcp_events_);
rtcp_events_.clear();
}
void SenderRtcpEventSubscriber::TruncateMapIfNeeded() {
if (rtcp_events_.size() > max_size_to_retain_) {
DVLOG(2) << "RTCP event map exceeded size limit; "
<< "removing oldest entry";
rtcp_events_.erase(rtcp_events_.begin());
}
}
}
}