Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / media / cast / transport / rtp_sender / packet_storage / packet_storage.h
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_TRANSPORT_RTP_SENDER_PACKET_STORAGE_PACKET_STORAGE_H_
6 #define MEDIA_CAST_TRANSPORT_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/transport/cast_transport_config.h"
18 #include "media/cast/transport/cast_transport_defines.h"
19 #include "media/cast/transport/pacing/paced_sender.h"
20
21 namespace media {
22 namespace cast {
23 namespace transport {
24
25 class StoredPacket;
26
27 // StorageIndex contains {frame_id, packet_id}.
28 typedef std::pair<uint32, uint16> StorageIndex;
29 typedef std::map<StorageIndex, std::pair<PacketKey, PacketRef> > PacketMap;
30
31 // Frame IDs are generally stored as 8-bit values when sent over the
32 // wire. This means that having a history longer than 255 frames makes
33 // no sense.
34 const int kMaxStoredFrames = 255;
35
36 class PacketStorage {
37  public:
38   PacketStorage(int stored_frames);
39   virtual ~PacketStorage();
40
41   // Returns true if this class is configured correctly.
42   // (stored frames > 0 && stored_frames < kMaxStoredFrames)
43   bool IsValid() const;
44
45   void StorePacket(uint32 frame_id,
46                    uint16 packet_id,
47                    const PacketKey& key,
48                    PacketRef packet);
49
50   // Copies all missing packets into the packet list.
51   void GetPackets(
52       const MissingFramesAndPacketsMap& missing_frames_and_packets,
53       SendPacketVector* packets_to_resend);
54
55   // Copies packet into the packet list.
56   bool GetPacket(uint8 frame_id_8bit,
57                  uint16 packet_id,
58                  SendPacketVector* packets);
59  private:
60   FRIEND_TEST_ALL_PREFIXES(PacketStorageTest, PacketContent);
61
62   // Same as GetPacket, but takes a 32-bit frame id.
63   bool GetPacket32(uint32 frame_id,
64                    uint16 packet_id,
65                    SendPacketVector* packets);
66   void CleanupOldPackets(uint32 current_frame_id);
67
68   PacketMap stored_packets_;
69   int stored_frames_;
70
71   DISALLOW_COPY_AND_ASSIGN(PacketStorage);
72 };
73
74 }  // namespace transport
75 }  // namespace cast
76 }  // namespace media
77
78 #endif  // MEDIA_CAST_TRANSPORT_RTP_SENDER_PACKET_STORAGE_PACKET_STORAGE_H_