Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: media/cast/net/rtp/packet_storage.cc

Issue 560223002: [Cast] Limit frames in flight by duration, and not by number of frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaks. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cast/net/rtp/packet_storage.h ('k') | media/cast/net/rtp/packet_storage_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cast/net/rtp/packet_storage.h" 5 #include "media/cast/net/rtp/packet_storage.h"
6 6
7 #include <string>
8
9 #include "base/logging.h" 7 #include "base/logging.h"
10 #include "media/cast/cast_defines.h" 8 #include "media/cast/cast_defines.h"
11 9
12 namespace media { 10 namespace media {
13 namespace cast { 11 namespace cast {
14 12
15 PacketStorage::PacketStorage(size_t stored_frames) 13 PacketStorage::PacketStorage()
16 : max_stored_frames_(stored_frames), 14 : first_frame_id_in_list_(0),
17 first_frame_id_in_list_(0), 15 zombie_count_(0) {
18 last_frame_id_in_list_(0) {
19 } 16 }
20 17
21 PacketStorage::~PacketStorage() { 18 PacketStorage::~PacketStorage() {
22 } 19 }
23 20
24 bool PacketStorage::IsValid() const {
25 return max_stored_frames_ > 0 &&
26 static_cast<int>(max_stored_frames_) <= kMaxUnackedFrames;
27 }
28
29 size_t PacketStorage::GetNumberOfStoredFrames() const { 21 size_t PacketStorage::GetNumberOfStoredFrames() const {
30 return frames_.size(); 22 return frames_.size() - zombie_count_;
31 } 23 }
32 24
33 void PacketStorage::StoreFrame(uint32 frame_id, 25 void PacketStorage::StoreFrame(uint32 frame_id,
34 const SendPacketVector& packets) { 26 const SendPacketVector& packets) {
27 if (packets.empty()) {
28 NOTREACHED();
29 return;
30 }
31
35 if (frames_.empty()) { 32 if (frames_.empty()) {
36 first_frame_id_in_list_ = frame_id; 33 first_frame_id_in_list_ = frame_id;
37 } else { 34 } else {
38 // Make sure frame IDs are consecutive. 35 // Make sure frame IDs are consecutive.
39 DCHECK_EQ(last_frame_id_in_list_ + 1, frame_id); 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));
40 } 41 }
41 42
42 // Save new frame to the end of the list. 43 // Save new frame to the end of the list.
43 last_frame_id_in_list_ = frame_id;
44 frames_.push_back(packets); 44 frames_.push_back(packets);
45 }
45 46
46 // Evict the oldest frame if the list is too long. 47 void PacketStorage::ReleaseFrame(uint32 frame_id) {
47 if (frames_.size() > max_stored_frames_) { 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;
52 }
53
54 frames_[offset].clear();
55 ++zombie_count_;
56
57 while (!frames_.empty() && frames_.front().empty()) {
58 DCHECK_GT(zombie_count_, 0u);
59 --zombie_count_;
48 frames_.pop_front(); 60 frames_.pop_front();
49 ++first_frame_id_in_list_; 61 ++first_frame_id_in_list_;
50 } 62 }
51 } 63 }
52 64
53 const SendPacketVector* PacketStorage::GetFrame8(uint8 frame_id_8bits) const { 65 const SendPacketVector* PacketStorage::GetFrame8(uint8 frame_id_8bits) const {
54 // The requested frame ID has only 8-bits so convert the first frame ID 66 // The requested frame ID has only 8-bits so convert the first frame ID
55 // in list to match. 67 // in list to match.
56 uint8 index_8bits = first_frame_id_in_list_ & 0xFF; 68 uint8 index_8bits = first_frame_id_in_list_ & 0xFF;
57 index_8bits = frame_id_8bits - index_8bits; 69 index_8bits = frame_id_8bits - index_8bits;
58 if (index_8bits >= frames_.size()) 70 if (index_8bits >= frames_.size())
59 return NULL; 71 return NULL;
60 return &(frames_[index_8bits]); 72 const SendPacketVector& packets = frames_[index_8bits];
73 return packets.empty() ? NULL : &packets;
61 } 74 }
62 75
63 } // namespace cast 76 } // namespace cast
64 } // namespace media 77 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/net/rtp/packet_storage.h ('k') | media/cast/net/rtp/packet_storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698