Revert "Omit calls to set composing region when pasting image."
[chromium-blink-merge.git] / media / cast / net / rtp / packet_storage.cc
blob0408eb1823239326525d3a22a8561a2eea730249
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/cast/net/rtp/packet_storage.h"
7 #include "base/logging.h"
8 #include "media/cast/cast_defines.h"
10 namespace media {
11 namespace cast {
13 PacketStorage::PacketStorage()
14 : first_frame_id_in_list_(0),
15 zombie_count_(0) {
18 PacketStorage::~PacketStorage() {
21 size_t PacketStorage::GetNumberOfStoredFrames() const {
22 return frames_.size() - zombie_count_;
25 void PacketStorage::StoreFrame(uint32 frame_id,
26 const SendPacketVector& packets) {
27 if (packets.empty()) {
28 NOTREACHED();
29 return;
32 if (frames_.empty()) {
33 first_frame_id_in_list_ = frame_id;
34 } else {
35 // Make sure frame IDs are consecutive.
36 DCHECK_EQ(first_frame_id_in_list_ + static_cast<uint32>(frames_.size()),
37 frame_id);
38 // Make sure we aren't being asked to store more frames than the system's
39 // design limit.
40 DCHECK_LT(frames_.size(), static_cast<size_t>(kMaxUnackedFrames));
43 // Save new frame to the end of the list.
44 frames_.push_back(packets);
47 void PacketStorage::ReleaseFrame(uint32 frame_id) {
48 const uint32 offset = frame_id - first_frame_id_in_list_;
49 if (static_cast<int32>(offset) < 0 || offset >= frames_.size() ||
50 frames_[offset].empty()) {
51 return;
54 frames_[offset].clear();
55 ++zombie_count_;
57 while (!frames_.empty() && frames_.front().empty()) {
58 DCHECK_GT(zombie_count_, 0u);
59 --zombie_count_;
60 frames_.pop_front();
61 ++first_frame_id_in_list_;
65 const SendPacketVector* PacketStorage::GetFrame8(uint8 frame_id_8bits) const {
66 // The requested frame ID has only 8-bits so convert the first frame ID
67 // in list to match.
68 uint8 index_8bits = first_frame_id_in_list_ & 0xFF;
69 index_8bits = frame_id_8bits - index_8bits;
70 if (index_8bits >= frames_.size())
71 return NULL;
72 const SendPacketVector& packets = frames_[index_8bits];
73 return packets.empty() ? NULL : &packets;
76 } // namespace cast
77 } // namespace media