summaryrefslogtreecommitdiffstats
path: root/chromium/media/cast/framer/frame_id_map.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/media/cast/framer/frame_id_map.cc')
-rw-r--r--chromium/media/cast/framer/frame_id_map.cc129
1 files changed, 60 insertions, 69 deletions
diff --git a/chromium/media/cast/framer/frame_id_map.cc b/chromium/media/cast/framer/frame_id_map.cc
index bd9b943371c..b4389fd5323 100644
--- a/chromium/media/cast/framer/frame_id_map.cc
+++ b/chromium/media/cast/framer/frame_id_map.cc
@@ -18,28 +18,27 @@ FrameInfo::FrameInfo(uint32 frame_id,
frame_id_(frame_id),
referenced_frame_id_(referenced_frame_id),
max_received_packet_id_(0) {
- if (max_packet_id > 0) {
- // Create the set with all packets missing.
- for (uint16 i = 0; i <= max_packet_id; i++) {
- missing_packets_.insert(i);
- }
+ // Create the set with all packets missing.
+ for (uint16 i = 0; i <= max_packet_id; i++) {
+ missing_packets_.insert(i);
}
}
FrameInfo::~FrameInfo() {}
-bool FrameInfo::InsertPacket(uint16 packet_id) {
+PacketType FrameInfo::InsertPacket(uint16 packet_id) {
+ if (missing_packets_.find(packet_id) == missing_packets_.end()) {
+ return kDuplicatePacket;
+ }
// Update the last received packet id.
if (IsNewerPacketId(packet_id, max_received_packet_id_)) {
max_received_packet_id_ = packet_id;
}
missing_packets_.erase(packet_id);
- return missing_packets_.empty();
+ return missing_packets_.empty() ? kNewPacketCompletingFrame : kNewPacket;
}
-bool FrameInfo::Complete() const {
- return missing_packets_.empty();
-}
+bool FrameInfo::Complete() const { return missing_packets_.empty(); }
void FrameInfo::GetMissingPackets(bool newest_frame,
PacketIdSet* missing_packets) const {
@@ -53,35 +52,29 @@ void FrameInfo::GetMissingPackets(bool newest_frame,
}
}
-
FrameIdMap::FrameIdMap()
: waiting_for_key_(true),
last_released_frame_(kStartFrameId),
- newest_frame_id_(kStartFrameId) {
-}
+ newest_frame_id_(kStartFrameId) {}
FrameIdMap::~FrameIdMap() {}
-bool FrameIdMap::InsertPacket(const RtpCastHeader& rtp_header, bool* complete) {
+PacketType FrameIdMap::InsertPacket(const RtpCastHeader& rtp_header) {
uint32 frame_id = rtp_header.frame_id;
uint32 reference_frame_id;
- if (rtp_header.is_reference) {
- reference_frame_id = rtp_header.reference_frame_id;
- } else {
- reference_frame_id = static_cast<uint32>(frame_id - 1);
- }
+ reference_frame_id = rtp_header.reference_frame_id;
if (rtp_header.is_key_frame && waiting_for_key_) {
last_released_frame_ = static_cast<uint32>(frame_id - 1);
waiting_for_key_ = false;
}
- VLOG(1) << "InsertPacket frame:" << frame_id
+ VLOG(3) << "InsertPacket frame:" << frame_id
<< " packet:" << static_cast<int>(rtp_header.packet_id)
<< " max packet:" << static_cast<int>(rtp_header.max_packet_id);
if (IsOlderFrameId(frame_id, last_released_frame_) && !waiting_for_key_) {
- return false;
+ return kTooOldPacket;
}
// Update the last received frame id.
@@ -91,6 +84,7 @@ bool FrameIdMap::InsertPacket(const RtpCastHeader& rtp_header, bool* complete) {
// Does this packet belong to a new frame?
FrameMap::iterator it = frame_map_.find(frame_id);
+ PacketType packet_type;
if (it == frame_map_.end()) {
// New frame.
linked_ptr<FrameInfo> frame_info(new FrameInfo(frame_id,
@@ -100,12 +94,12 @@ bool FrameIdMap::InsertPacket(const RtpCastHeader& rtp_header, bool* complete) {
std::pair<FrameMap::iterator, bool> retval =
frame_map_.insert(std::make_pair(frame_id, frame_info));
- *complete = retval.first->second->InsertPacket(rtp_header.packet_id);
+ packet_type = retval.first->second->InsertPacket(rtp_header.packet_id);
} else {
// Insert packet to existing frame.
- *complete = it->second->InsertPacket(rtp_header.packet_id);
+ packet_type = it->second->InsertPacket(rtp_header.packet_id);
}
- return true;
+ return packet_type;
}
void FrameIdMap::RemoveOldFrames(uint32 frame_id) {
@@ -129,9 +123,7 @@ void FrameIdMap::Clear() {
newest_frame_id_ = kStartFrameId;
}
-uint32 FrameIdMap::NewestFrameId() const {
- return newest_frame_id_;
-}
+uint32 FrameIdMap::NewestFrameId() const { return newest_frame_id_; }
bool FrameIdMap::NextContinuousFrame(uint32* frame_id) const {
FrameMap::const_iterator it;
@@ -145,6 +137,22 @@ bool FrameIdMap::NextContinuousFrame(uint32* frame_id) const {
return false;
}
+bool FrameIdMap::HaveMultipleDecodableFrames() const {
+ // Find the oldest decodable frame.
+ FrameMap::const_iterator it;
+ bool found_one = false;
+ for (it = frame_map_.begin(); it != frame_map_.end(); ++it) {
+ if (it->second->Complete() && DecodableFrame(it->second.get())) {
+ if (found_one) {
+ return true;
+ } else {
+ found_one = true;
+ }
+ }
+ }
+ return false;
+}
+
uint32 FrameIdMap::LastContinuousFrame() const {
uint32 last_continuous_frame_id = last_released_frame_;
uint32 next_expected_frame = last_released_frame_;
@@ -154,8 +162,10 @@ uint32 FrameIdMap::LastContinuousFrame() const {
do {
next_expected_frame++;
it = frame_map_.find(next_expected_frame);
- if (it == frame_map_.end()) break;
- if (!it->second->Complete()) break;
+ if (it == frame_map_.end())
+ break;
+ if (!it->second->Complete())
+ break;
// We found the next continuous frame.
last_continuous_frame_id = it->first;
@@ -163,52 +173,26 @@ uint32 FrameIdMap::LastContinuousFrame() const {
return last_continuous_frame_id;
}
-bool FrameIdMap::NextAudioFrameAllowingMissingFrames(uint32* frame_id) const {
- // First check if we have continuous frames.
- if (NextContinuousFrame(frame_id)) return true;
-
- // Find the oldest frame.
- FrameMap::const_iterator it_best_match = frame_map_.end();
- FrameMap::const_iterator it;
-
- // Find first complete frame.
- for (it = frame_map_.begin(); it != frame_map_.end(); ++it) {
- if (it->second->Complete()) {
- it_best_match = it;
- break;
- }
- }
- if (it_best_match == frame_map_.end()) return false; // No complete frame.
-
- ++it;
- for (; it != frame_map_.end(); ++it) {
- if (it->second->Complete() &&
- IsOlderFrameId(it->first, it_best_match->first)) {
- it_best_match = it;
- }
- }
- *frame_id = it_best_match->first;
- return true;
-}
-
-bool FrameIdMap::NextVideoFrameAllowingSkippingFrames(uint32* frame_id) const {
+bool FrameIdMap::NextFrameAllowingSkippingFrames(uint32* frame_id) const {
// Find the oldest decodable frame.
FrameMap::const_iterator it_best_match = frame_map_.end();
FrameMap::const_iterator it;
for (it = frame_map_.begin(); it != frame_map_.end(); ++it) {
- if (it->second->Complete() && DecodableVideoFrame(it->second.get())) {
- it_best_match = it;
+ if (it->second->Complete() && DecodableFrame(it->second.get())) {
+ if (it_best_match == frame_map_.end() ||
+ IsOlderFrameId(it->first, it_best_match->first)) {
+ it_best_match = it;
+ }
}
}
- if (it_best_match == frame_map_.end()) return false;
+ if (it_best_match == frame_map_.end())
+ return false;
*frame_id = it_best_match->first;
return true;
}
-bool FrameIdMap::Empty() const {
- return frame_map_.empty();
-}
+bool FrameIdMap::Empty() const { return frame_map_.empty(); }
int FrameIdMap::NumberOfCompleteFrames() const {
int count = 0;
@@ -229,20 +213,27 @@ void FrameIdMap::GetMissingPackets(uint32 frame_id,
bool last_frame,
PacketIdSet* missing_packets) const {
FrameMap::const_iterator it = frame_map_.find(frame_id);
- if (it == frame_map_.end()) return;
+ if (it == frame_map_.end())
+ return;
it->second->GetMissingPackets(last_frame, missing_packets);
}
bool FrameIdMap::ContinuousFrame(FrameInfo* frame) const {
DCHECK(frame);
- if (waiting_for_key_ && !frame->is_key_frame()) return false;
+ if (waiting_for_key_ && !frame->is_key_frame())
+ return false;
return static_cast<uint32>(last_released_frame_ + 1) == frame->frame_id();
}
-bool FrameIdMap::DecodableVideoFrame(FrameInfo* frame) const {
- if (frame->is_key_frame()) return true;
- if (waiting_for_key_ && !frame->is_key_frame()) return false;
+bool FrameIdMap::DecodableFrame(FrameInfo* frame) const {
+ if (frame->is_key_frame())
+ return true;
+ if (waiting_for_key_ && !frame->is_key_frame())
+ return false;
+ // Self-reference?
+ if (frame->referenced_frame_id() == frame->frame_id())
+ return true;
// Current frame is not necessarily referencing the last frame.
// Do we have the reference frame?