summaryrefslogtreecommitdiff
path: root/chromium/media/cast/framer/frame_id_map.h
blob: 6bf72a0d692cab506772a774d896f94ca8875ac1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CAST_FRAMER_FRAME_ID_MAP_H_
#define MEDIA_CAST_FRAMER_FRAME_ID_MAP_H_

#include <map>
#include <set>

#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "media/cast/cast_config.h"
#include "media/cast/rtcp/rtcp_defines.h"
#include "media/cast/rtp_common/rtp_defines.h"

namespace media {
namespace cast {

class FrameInfo {
 public:
  FrameInfo(uint8 frame_id,
            uint8 referenced_frame_id,
            uint16 max_packet_id,
            bool key_frame);
  ~FrameInfo();

  // Returns true if frame is complete after the insert.
  bool InsertPacket(uint16 packet_id);
  bool Complete() const;
  void GetMissingPackets(bool newest_frame,
                         PacketIdSet* missing_packets) const;

  bool is_key_frame() const { return is_key_frame_; }
  uint8 frame_id() const { return frame_id_; }
  uint8 referenced_frame_id() const { return referenced_frame_id_; }

 private:
  const bool is_key_frame_;
  const uint8 frame_id_;
  const uint8 referenced_frame_id_;

  uint16 max_received_packet_id_;
  PacketIdSet missing_packets_;

  DISALLOW_COPY_AND_ASSIGN(FrameInfo);
};

typedef std::map<uint8, linked_ptr<FrameInfo> > FrameMap;

class FrameIdMap {
 public:
  FrameIdMap();
  ~FrameIdMap();

  // Returns false if not a valid (old) packet, otherwise returns true.
  bool InsertPacket(const RtpCastHeader& rtp_header, bool* complete);

  bool Empty() const;
  bool FrameExists(uint8 frame_id) const;
  uint8 NewestFrameId() const;

  void RemoveOldFrames(uint8 frame_id);
  void Clear();

  // Identifies the next frame to be released (rendered).
  bool NextContinuousFrame(uint8* frame_id) const;
  uint8 LastContinuousFrame() const;

  bool NextAudioFrameAllowingMissingFrames(uint8* frame_id) const;
  bool NextVideoFrameAllowingSkippingFrames(uint8* frame_id) const;

  int NumberOfCompleteFrames() const;
  void GetMissingPackets(uint8 frame_id,
                         bool last_frame,
                         PacketIdSet* missing_packets) const;

 private:
  bool ContinuousFrame(FrameInfo* frame) const;
  bool DecodableVideoFrame(FrameInfo* frame) const;

  FrameMap frame_map_;
  bool waiting_for_key_;
  uint8 last_released_frame_;
  uint8 newest_frame_id_;

  DISALLOW_COPY_AND_ASSIGN(FrameIdMap);
};

}  //  namespace cast
}  //  namespace media

#endif  // MEDIA_CAST_FRAMER_FRAME_ID_MAP_H_