blob: cdf1e28f95e987f14e2643a8e0ac23e303aebac7 [file] [log] [blame]
Patrik Höglund3e113432017-12-15 14:40:10 +01001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef API_RTP_HEADERS_H_
12#define API_RTP_HEADERS_H_
13
14#include <stddef.h>
Yves Gerey988cc082018-10-23 12:03:01 +020015#include <stdint.h>
Niels Möllerd57efc12019-03-22 14:02:11 +010016#include <string>
Patrik Höglund3e113432017-12-15 14:40:10 +010017
Johannes Kronad1d9f02018-11-09 11:12:36 +010018#include "absl/types/optional.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010019#include "api/array_view.h"
Sebastian Jansson3d61ab12019-06-14 13:35:51 +020020#include "api/units/timestamp.h"
Johannes Kron09d65882018-11-27 14:36:41 +010021#include "api/video/color_space.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010022#include "api/video/video_content_type.h"
Johnny Leee0c8b232018-09-11 16:50:49 -040023#include "api/video/video_frame_marking.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010024#include "api/video/video_rotation.h"
25#include "api/video/video_timing.h"
Yves Gerey665174f2018-06-19 15:03:05 +020026#include "common_types.h" // NOLINT(build/include)
Patrik Höglund3e113432017-12-15 14:40:10 +010027
28namespace webrtc {
29
Johannes Kron075f6872019-02-14 14:41:05 +010030struct FeedbackRequest {
31 // Determines whether the recv delta as specified in
32 // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
33 // should be included.
34 bool include_timestamps;
35 // Include feedback of received packets in the range [sequence_number -
Johannes Kron0da25a12019-03-06 09:34:13 +010036 // sequence_count + 1, sequence_number]. That is, no feedback will be sent if
37 // sequence_count is zero.
Johannes Kron075f6872019-02-14 14:41:05 +010038 int sequence_count;
39};
40
Patrik Höglund3e113432017-12-15 14:40:10 +010041struct RTPHeaderExtension {
42 RTPHeaderExtension();
43 RTPHeaderExtension(const RTPHeaderExtension& other);
44 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
45
Sebastian Jansson3d61ab12019-06-14 13:35:51 +020046 static constexpr int kAbsSendTimeFraction = 18;
47
48 Timestamp GetAbsoluteSendTimestamp() const {
49 RTC_DCHECK(hasAbsoluteSendTime);
50 RTC_DCHECK(absoluteSendTime < (1ul << 24));
51 return Timestamp::us((absoluteSendTime * 1000000L) /
52 (1 << kAbsSendTimeFraction));
53 }
54
Patrik Höglund3e113432017-12-15 14:40:10 +010055 bool hasTransmissionTimeOffset;
56 int32_t transmissionTimeOffset;
57 bool hasAbsoluteSendTime;
58 uint32_t absoluteSendTime;
59 bool hasTransportSequenceNumber;
60 uint16_t transportSequenceNumber;
Johannes Kron075f6872019-02-14 14:41:05 +010061 absl::optional<FeedbackRequest> feedback_request;
Patrik Höglund3e113432017-12-15 14:40:10 +010062
63 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
Chen Xingd2a66862019-06-03 14:53:42 +020064 // https://tools.ietf.org/html/rfc6464#section-3
Patrik Höglund3e113432017-12-15 14:40:10 +010065 bool hasAudioLevel;
66 bool voiceActivity;
67 uint8_t audioLevel;
68
69 // For Coordination of Video Orientation. See
70 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
71 // ts_126114v120700p.pdf
72 bool hasVideoRotation;
73 VideoRotation videoRotation;
74
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020075 // TODO(ilnik): Refactor this and one above to be absl::optional() and remove
Patrik Höglund3e113432017-12-15 14:40:10 +010076 // a corresponding bool flag.
77 bool hasVideoContentType;
78 VideoContentType videoContentType;
79
80 bool has_video_timing;
81 VideoSendTiming video_timing;
82
Johnny Leee0c8b232018-09-11 16:50:49 -040083 bool has_frame_marking;
84 FrameMarking frame_marking;
85
Patrik Höglund3e113432017-12-15 14:40:10 +010086 PlayoutDelay playout_delay = {-1, -1};
87
88 // For identification of a stream when ssrc is not signaled. See
89 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
90 // TODO(danilchap): Update url from draft to release version.
Niels Möllerd57efc12019-03-22 14:02:11 +010091 std::string stream_id;
92 std::string repaired_stream_id;
Patrik Höglund3e113432017-12-15 14:40:10 +010093
94 // For identifying the media section used to interpret this RTP packet. See
95 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
Niels Möllerd57efc12019-03-22 14:02:11 +010096 std::string mid;
Johannes Kronad1d9f02018-11-09 11:12:36 +010097
Johannes Kron09d65882018-11-27 14:36:41 +010098 absl::optional<ColorSpace> color_space;
Patrik Höglund3e113432017-12-15 14:40:10 +010099};
100
Niels Möller418f5802019-05-08 14:24:15 +0200101enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
102
Patrik Höglund3e113432017-12-15 14:40:10 +0100103struct RTPHeader {
104 RTPHeader();
105 RTPHeader(const RTPHeader& other);
106 RTPHeader& operator=(const RTPHeader& other);
107
108 bool markerBit;
109 uint8_t payloadType;
110 uint16_t sequenceNumber;
111 uint32_t timestamp;
112 uint32_t ssrc;
113 uint8_t numCSRCs;
114 uint32_t arrOfCSRCs[kRtpCsrcSize];
115 size_t paddingLength;
116 size_t headerLength;
117 int payload_type_frequency;
118 RTPHeaderExtension extension;
119};
120
121// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
122// RTCP mode is described by RFC 5506.
123enum class RtcpMode { kOff, kCompound, kReducedSize };
124
125enum NetworkState {
126 kNetworkUp,
127 kNetworkDown,
128};
129
Patrik Höglund3e113432017-12-15 14:40:10 +0100130} // namespace webrtc
131
132#endif // API_RTP_HEADERS_H_