summaryrefslogtreecommitdiffstats
path: root/media/cast/net/cast_transport_defines.h
blob: 9a4d0b2f194995a609e5a5bb43dd2d282e81920a (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
// Copyright 2014 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_NET_CAST_TRANSPORT_DEFINES_H_
#define MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_

#include <stddef.h>
#include <stdint.h>

#include <map>
#include <set>
#include <string>
#include <vector>

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"

namespace media {
namespace cast {

// Enums used to indicate transport readiness state.
enum CastTransportStatus {
  TRANSPORT_AUDIO_UNINITIALIZED = 0,
  TRANSPORT_VIDEO_UNINITIALIZED,
  TRANSPORT_AUDIO_INITIALIZED,
  TRANSPORT_VIDEO_INITIALIZED,
  TRANSPORT_INVALID_CRYPTO_CONFIG,
  TRANSPORT_SOCKET_ERROR,
  CAST_TRANSPORT_STATUS_LAST = TRANSPORT_SOCKET_ERROR
};

// kRtcpCastAllPacketsLost is used in PacketIDSet and
// on the wire to mean that ALL packets for a particular
// frame are lost.
const uint16_t kRtcpCastAllPacketsLost = 0xffff;

// kRtcpCastLastPacket is used in PacketIDSet to ask for
// the last packet of a frame to be retransmitted.
const uint16_t kRtcpCastLastPacket = 0xfffe;

const size_t kMaxIpPacketSize = 1500;

// Each uint16_t represents one packet id within a cast frame.
// Can also contain kRtcpCastAllPacketsLost and kRtcpCastLastPacket.
using PacketIdSet = std::set<uint16_t>;
// Each uint8_t represents one cast frame.
using MissingFramesAndPacketsMap = std::map<uint8_t, PacketIdSet>;

using Packet = std::vector<uint8_t>;
using PacketRef = scoped_refptr<base::RefCountedData<Packet>>;
using PacketList = std::vector<PacketRef>;

class FrameIdWrapHelperTest;

// TODO(miu): UGLY IN-LINE DEFINITION IN HEADER FILE!  Move to appropriate
// location, separated into .h and .cc files.  http://crbug.com/530839
class FrameIdWrapHelper {
 public:
  explicit FrameIdWrapHelper(uint32_t start_frame_id)
      : largest_frame_id_seen_(start_frame_id) {}

  uint32_t MapTo32bitsFrameId(const uint8_t over_the_wire_frame_id) {
    uint32_t ret = (largest_frame_id_seen_ & ~0xff) | over_the_wire_frame_id;
    // Add 1000 to both sides to avoid underflows.
    if (1000 + ret - largest_frame_id_seen_ > 1000 + 127) {
      ret -= 0x100;
    } else if (1000 + ret - largest_frame_id_seen_ < 1000 - 128) {
      ret += 0x100;
    }
    if (1000 + ret - largest_frame_id_seen_ > 1000) {
      largest_frame_id_seen_ = ret;
    }
    return ret;
  }

 private:
  friend class FrameIdWrapHelperTest;

  uint32_t largest_frame_id_seen_;

  DISALLOW_COPY_AND_ASSIGN(FrameIdWrapHelper);
};

}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_