summaryrefslogtreecommitdiffstats
path: root/media/cast/net/rtcp/rtcp_defines.h
blob: 032383a2190724b08b5c89bfbc3255a10c885b79 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// 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_RTCP_RTCP_DEFINES_H_
#define MEDIA_CAST_RTCP_RTCP_DEFINES_H_

#include <list>

#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "media/cast/logging/logging_defines.h"
#include "media/cast/net/cast_transport_defines.h"

namespace media {
namespace cast {

static const size_t kRtcpCastLogHeaderSize = 12;
static const size_t kRtcpReceiverFrameLogSize = 8;
static const size_t kRtcpReceiverEventLogSize = 4;

// The maximum number of Cast receiver events to keep in history for the
// purpose of sending the events through RTCP.
// The number chosen should be more than the number of events that can be
// stored in a RTCP packet.
const size_t kReceiverRtcpEventHistorySize = 512;

enum RtcpPacketFields {
  kPacketTypeLow = 194,  // SMPTE time-code mapping.
  kPacketTypeSenderReport = 200,
  kPacketTypeReceiverReport = 201,
  kPacketTypeApplicationDefined = 204,
  kPacketTypeGenericRtpFeedback = 205,
  kPacketTypePayloadSpecific = 206,
  kPacketTypeXr = 207,
  kPacketTypeHigh = 210,  // Port Mapping.
};

// Handle the per frame ACK and NACK messages.
struct RtcpCastMessage {
  explicit RtcpCastMessage(uint32_t ssrc);
  RtcpCastMessage();
  ~RtcpCastMessage();

  uint32_t media_ssrc;
  uint32_t ack_frame_id;
  uint16_t target_delay_ms;
  MissingFramesAndPacketsMap missing_frames_and_packets;
};

// Log messages from receiver to sender.
struct RtcpReceiverEventLogMessage {
  RtcpReceiverEventLogMessage();
  ~RtcpReceiverEventLogMessage();

  CastLoggingEvent type;
  base::TimeTicks event_timestamp;
  base::TimeDelta delay_delta;
  uint16_t packet_id;
};

typedef std::list<RtcpReceiverEventLogMessage> RtcpReceiverEventLogMessages;

struct RtcpReceiverFrameLogMessage {
  explicit RtcpReceiverFrameLogMessage(uint32_t rtp_timestamp);
  ~RtcpReceiverFrameLogMessage();

  uint32_t rtp_timestamp_;
  RtcpReceiverEventLogMessages event_log_messages_;

  // TODO(mikhal): Investigate what's the best way to allow adding
  // DISALLOW_COPY_AND_ASSIGN, as currently it contradicts the implementation
  // and possible changes have a big impact on design.
};

typedef std::list<RtcpReceiverFrameLogMessage> RtcpReceiverLogMessage;

struct RtcpReceiverReferenceTimeReport {
  RtcpReceiverReferenceTimeReport();
  ~RtcpReceiverReferenceTimeReport();

  uint32_t remote_ssrc;
  uint32_t ntp_seconds;
  uint32_t ntp_fraction;
};

inline bool operator==(RtcpReceiverReferenceTimeReport lhs,
                       RtcpReceiverReferenceTimeReport rhs) {
  return lhs.remote_ssrc == rhs.remote_ssrc &&
         lhs.ntp_seconds == rhs.ntp_seconds &&
         lhs.ntp_fraction == rhs.ntp_fraction;
}

// Struct used by raw event subscribers as an intermediate format before
// sending off to the other side via RTCP.
// (i.e., {Sender,Receiver}RtcpEventSubscriber)
struct RtcpEvent {
  RtcpEvent();
  ~RtcpEvent();

  CastLoggingEvent type;

  // Time of event logged.
  base::TimeTicks timestamp;

  // Render/playout delay. Only set for FRAME_PLAYOUT events.
  base::TimeDelta delay_delta;

  // Only set for packet events.
  uint16_t packet_id;
};

typedef base::Callback<void(const RtcpCastMessage&)> RtcpCastMessageCallback;
typedef base::Callback<void(base::TimeDelta)> RtcpRttCallback;
typedef
base::Callback<void(const RtcpReceiverLogMessage&)> RtcpLogMessageCallback;

// TODO(hubbe): Document members of this struct.
struct RtpReceiverStatistics {
  RtpReceiverStatistics();
  uint8_t fraction_lost;
  uint32_t cumulative_lost;  // 24 bits valid.
  uint32_t extended_high_sequence_number;
  uint32_t jitter;
};

// These are intended to only be created using Rtcp::ConvertToNTPAndSave.
struct RtcpTimeData {
  uint32_t ntp_seconds;
  uint32_t ntp_fraction;
  base::TimeTicks timestamp;
};

// This struct is used to encapsulate all the parameters of the
// SendRtcpFromRtpReceiver for IPC transportation.
struct SendRtcpFromRtpReceiver_Params {
  SendRtcpFromRtpReceiver_Params();
  ~SendRtcpFromRtpReceiver_Params();
  uint32_t ssrc;
  uint32_t sender_ssrc;
  RtcpTimeData time_data;
  scoped_ptr<RtcpCastMessage> cast_message;
  base::TimeDelta target_delay;
  scoped_ptr<std::vector<std::pair<RtpTimestamp, RtcpEvent> > > rtcp_events;
  scoped_ptr<RtpReceiverStatistics> rtp_receiver_statistics;
};


}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_RTCP_RTCP_DEFINES_H_