• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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.
4 
5 #ifndef MEDIA_CAST_NET_RTP_SENDER_PACKET_STORAGE_PACKET_STORAGE_H_
6 #define MEDIA_CAST_NET_RTP_SENDER_PACKET_STORAGE_PACKET_STORAGE_H_
7 
8 #include <list>
9 #include <map>
10 #include <vector>
11 
12 #include "base/basictypes.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/time/tick_clock.h"
16 #include "base/time/time.h"
17 #include "media/cast/cast_config.h"
18 
19 namespace media {
20 namespace cast {
21 
22 class StoredPacket;
23 typedef std::map<uint32, linked_ptr<StoredPacket> > PacketMap;
24 typedef std::multimap<base::TimeTicks, uint32> TimeToPacketMap;
25 
26 class PacketStorage {
27  public:
28   static const int kMaxStoredPackets = 1000;
29 
30   PacketStorage(base::TickClock* clock, int max_time_stored_ms);
31   virtual ~PacketStorage();
32 
33   void StorePacket(uint32 frame_id, uint16 packet_id, const Packet* packet);
34 
35   // Copies all missing packets into the packet list.
36   PacketList GetPackets(
37       const MissingFramesAndPacketsMap& missing_frames_and_packets);
38 
39   // Copies packet into the packet list.
40   bool GetPacket(uint8 frame_id, uint16 packet_id, PacketList* packets);
41 
42  private:
43   void CleanupOldPackets(base::TimeTicks now);
44 
45   base::TickClock* const clock_;  // Not owned by this class.
46   base::TimeDelta max_time_stored_;
47   PacketMap stored_packets_;
48   TimeToPacketMap time_to_packet_map_;
49   std::list<linked_ptr<StoredPacket> > free_packets_;
50 };
51 
52 }  // namespace cast
53 }  // namespace media
54 
55 #endif  // MEDIA_CAST_NET_RTP_SENDER_PACKET_STORAGE_PACKET_STORAGE_H_
56