2016-04-20 05:25:10 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
|
|
|
|
|
|
|
|
|
|
#include "webrtc/base/checks.h"
|
|
|
|
|
#include "webrtc/base/logging.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
// Absolute send time in RTP streams.
|
|
|
|
|
//
|
|
|
|
|
// The absolute send time is signaled to the receiver in-band using the
|
|
|
|
|
// general mechanism for RTP header extensions [RFC5285]. The payload
|
|
|
|
|
// of this extension (the transmitted value) is a 24-bit unsigned integer
|
|
|
|
|
// containing the sender's current time in seconds as a fixed point number
|
|
|
|
|
// with 18 bits fractional part.
|
|
|
|
|
//
|
|
|
|
|
// The form of the absolute send time extension block:
|
|
|
|
|
//
|
|
|
|
|
// 0 1 2 3
|
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
// | ID | len=2 | absolute send time |
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2016-10-28 07:08:58 -07:00
|
|
|
constexpr RTPExtensionType AbsoluteSendTime::kId;
|
|
|
|
|
constexpr uint8_t AbsoluteSendTime::kValueSizeBytes;
|
2016-11-09 05:46:39 -08:00
|
|
|
constexpr const char* AbsoluteSendTime::kUri;
|
2016-04-20 05:25:10 -07:00
|
|
|
|
2017-04-06 01:03:53 -07:00
|
|
|
bool AbsoluteSendTime::Parse(rtc::ArrayView<const uint8_t> data,
|
|
|
|
|
uint32_t* time_24bits) {
|
|
|
|
|
if (data.size() != 3)
|
|
|
|
|
return false;
|
|
|
|
|
*time_24bits = ByteReader<uint32_t, 3>::ReadBigEndian(data.data());
|
2016-04-20 05:25:10 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AbsoluteSendTime::Write(uint8_t* data, int64_t time_ms) {
|
2016-08-26 05:42:41 -07:00
|
|
|
ByteWriter<uint32_t, 3>::WriteBigEndian(data, MsTo24Bits(time_ms));
|
2016-04-20 05:25:10 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// An RTP Header Extension for Client-to-Mixer Audio Level Indication
|
|
|
|
|
//
|
|
|
|
|
// https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
|
|
|
|
|
//
|
|
|
|
|
// The form of the audio level extension block:
|
|
|
|
|
//
|
|
|
|
|
// 0 1
|
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
// | ID | len=0 |V| level |
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
//
|
2016-10-28 07:08:58 -07:00
|
|
|
constexpr RTPExtensionType AudioLevel::kId;
|
|
|
|
|
constexpr uint8_t AudioLevel::kValueSizeBytes;
|
2016-11-09 05:46:39 -08:00
|
|
|
constexpr const char* AudioLevel::kUri;
|
2016-04-20 05:25:10 -07:00
|
|
|
|
2017-04-06 01:03:53 -07:00
|
|
|
bool AudioLevel::Parse(rtc::ArrayView<const uint8_t> data,
|
2016-04-20 05:25:10 -07:00
|
|
|
bool* voice_activity,
|
|
|
|
|
uint8_t* audio_level) {
|
2017-04-06 01:03:53 -07:00
|
|
|
if (data.size() != 1)
|
|
|
|
|
return false;
|
2016-04-20 05:25:10 -07:00
|
|
|
*voice_activity = (data[0] & 0x80) != 0;
|
|
|
|
|
*audio_level = data[0] & 0x7F;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioLevel::Write(uint8_t* data,
|
|
|
|
|
bool voice_activity,
|
|
|
|
|
uint8_t audio_level) {
|
|
|
|
|
RTC_CHECK_LE(audio_level, 0x7f);
|
|
|
|
|
data[0] = (voice_activity ? 0x80 : 0x00) | audio_level;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// From RFC 5450: Transmission Time Offsets in RTP Streams.
|
|
|
|
|
//
|
|
|
|
|
// The transmission time is signaled to the receiver in-band using the
|
|
|
|
|
// general mechanism for RTP header extensions [RFC5285]. The payload
|
|
|
|
|
// of this extension (the transmitted value) is a 24-bit signed integer.
|
|
|
|
|
// When added to the RTP timestamp of the packet, it represents the
|
|
|
|
|
// "effective" RTP transmission time of the packet, on the RTP
|
|
|
|
|
// timescale.
|
|
|
|
|
//
|
|
|
|
|
// The form of the transmission offset extension block:
|
|
|
|
|
//
|
|
|
|
|
// 0 1 2 3
|
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
// | ID | len=2 | transmission offset |
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2016-10-28 07:08:58 -07:00
|
|
|
constexpr RTPExtensionType TransmissionOffset::kId;
|
|
|
|
|
constexpr uint8_t TransmissionOffset::kValueSizeBytes;
|
2016-11-09 05:46:39 -08:00
|
|
|
constexpr const char* TransmissionOffset::kUri;
|
2016-04-20 05:25:10 -07:00
|
|
|
|
2017-04-06 01:03:53 -07:00
|
|
|
bool TransmissionOffset::Parse(rtc::ArrayView<const uint8_t> data,
|
|
|
|
|
int32_t* rtp_time) {
|
|
|
|
|
if (data.size() != 3)
|
|
|
|
|
return false;
|
|
|
|
|
*rtp_time = ByteReader<int32_t, 3>::ReadBigEndian(data.data());
|
2016-04-20 05:25:10 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 18:27:40 +02:00
|
|
|
bool TransmissionOffset::Write(uint8_t* data, int32_t rtp_time) {
|
|
|
|
|
RTC_DCHECK_LE(rtp_time, 0x00ffffff);
|
|
|
|
|
ByteWriter<int32_t, 3>::WriteBigEndian(data, rtp_time);
|
2016-04-20 05:25:10 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 0 1 2
|
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
// | ID | L=1 |transport wide sequence number |
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2016-10-28 07:08:58 -07:00
|
|
|
constexpr RTPExtensionType TransportSequenceNumber::kId;
|
|
|
|
|
constexpr uint8_t TransportSequenceNumber::kValueSizeBytes;
|
2016-11-09 05:46:39 -08:00
|
|
|
constexpr const char* TransportSequenceNumber::kUri;
|
2016-04-20 05:25:10 -07:00
|
|
|
|
2017-04-06 01:03:53 -07:00
|
|
|
bool TransportSequenceNumber::Parse(rtc::ArrayView<const uint8_t> data,
|
|
|
|
|
uint16_t* value) {
|
|
|
|
|
if (data.size() != 2)
|
|
|
|
|
return false;
|
|
|
|
|
*value = ByteReader<uint16_t>::ReadBigEndian(data.data());
|
2016-04-20 05:25:10 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TransportSequenceNumber::Write(uint8_t* data, uint16_t value) {
|
|
|
|
|
ByteWriter<uint16_t>::WriteBigEndian(data, value);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Coordination of Video Orientation in RTP streams.
|
|
|
|
|
//
|
|
|
|
|
// Coordination of Video Orientation consists in signaling of the current
|
|
|
|
|
// orientation of the image captured on the sender side to the receiver for
|
|
|
|
|
// appropriate rendering and displaying.
|
|
|
|
|
//
|
|
|
|
|
// 0 1
|
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
// | ID | len=0 |0 0 0 0 C F R R|
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2016-10-28 07:08:58 -07:00
|
|
|
constexpr RTPExtensionType VideoOrientation::kId;
|
|
|
|
|
constexpr uint8_t VideoOrientation::kValueSizeBytes;
|
2016-11-09 05:46:39 -08:00
|
|
|
constexpr const char* VideoOrientation::kUri;
|
2016-04-20 05:25:10 -07:00
|
|
|
|
2017-04-06 01:03:53 -07:00
|
|
|
bool VideoOrientation::Parse(rtc::ArrayView<const uint8_t> data,
|
|
|
|
|
VideoRotation* rotation) {
|
|
|
|
|
if (data.size() != 1)
|
|
|
|
|
return false;
|
2016-09-08 03:24:58 -07:00
|
|
|
*rotation = ConvertCVOByteToVideoRotation(data[0]);
|
2016-04-20 05:25:10 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoOrientation::Write(uint8_t* data, VideoRotation rotation) {
|
|
|
|
|
data[0] = ConvertVideoRotationToCVOByte(rotation);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-06 01:03:53 -07:00
|
|
|
bool VideoOrientation::Parse(rtc::ArrayView<const uint8_t> data,
|
|
|
|
|
uint8_t* value) {
|
|
|
|
|
if (data.size() != 1)
|
|
|
|
|
return false;
|
2016-04-20 05:25:10 -07:00
|
|
|
*value = data[0];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoOrientation::Write(uint8_t* data, uint8_t value) {
|
|
|
|
|
data[0] = value;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-09-07 15:08:13 +02:00
|
|
|
|
|
|
|
|
// 0 1 2 3
|
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
// | ID | len=2 | MIN delay | MAX delay |
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
constexpr RTPExtensionType PlayoutDelayLimits::kId;
|
|
|
|
|
constexpr uint8_t PlayoutDelayLimits::kValueSizeBytes;
|
2016-11-09 05:46:39 -08:00
|
|
|
constexpr const char* PlayoutDelayLimits::kUri;
|
2016-09-07 15:08:13 +02:00
|
|
|
|
2017-04-06 01:03:53 -07:00
|
|
|
bool PlayoutDelayLimits::Parse(rtc::ArrayView<const uint8_t> data,
|
2016-09-07 15:08:13 +02:00
|
|
|
PlayoutDelay* playout_delay) {
|
|
|
|
|
RTC_DCHECK(playout_delay);
|
2017-04-06 01:03:53 -07:00
|
|
|
if (data.size() != 3)
|
|
|
|
|
return false;
|
|
|
|
|
uint32_t raw = ByteReader<uint32_t, 3>::ReadBigEndian(data.data());
|
2016-09-07 15:08:13 +02:00
|
|
|
uint16_t min_raw = (raw >> 12);
|
|
|
|
|
uint16_t max_raw = (raw & 0xfff);
|
|
|
|
|
if (min_raw > max_raw)
|
|
|
|
|
return false;
|
|
|
|
|
playout_delay->min_ms = min_raw * kGranularityMs;
|
|
|
|
|
playout_delay->max_ms = max_raw * kGranularityMs;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PlayoutDelayLimits::Write(uint8_t* data,
|
|
|
|
|
const PlayoutDelay& playout_delay) {
|
|
|
|
|
RTC_DCHECK_LE(0, playout_delay.min_ms);
|
|
|
|
|
RTC_DCHECK_LE(playout_delay.min_ms, playout_delay.max_ms);
|
|
|
|
|
RTC_DCHECK_LE(playout_delay.max_ms, kMaxMs);
|
|
|
|
|
// Convert MS to value to be sent on extension header.
|
|
|
|
|
uint32_t min_delay = playout_delay.min_ms / kGranularityMs;
|
|
|
|
|
uint32_t max_delay = playout_delay.max_ms / kGranularityMs;
|
|
|
|
|
ByteWriter<uint32_t, 3>::WriteBigEndian(data, (min_delay << 12) | max_delay);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-11 10:34:31 -07:00
|
|
|
// Video Content Type.
|
|
|
|
|
//
|
|
|
|
|
// E.g. default video or screenshare.
|
|
|
|
|
//
|
|
|
|
|
// 0 1
|
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
// | ID | len=0 | Content type |
|
|
|
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
constexpr RTPExtensionType VideoContentTypeExtension::kId;
|
|
|
|
|
constexpr uint8_t VideoContentTypeExtension::kValueSizeBytes;
|
|
|
|
|
constexpr const char* VideoContentTypeExtension::kUri;
|
|
|
|
|
|
|
|
|
|
bool VideoContentTypeExtension::Parse(rtc::ArrayView<const uint8_t> data,
|
|
|
|
|
VideoContentType* content_type) {
|
|
|
|
|
if (data.size() == 1 &&
|
|
|
|
|
data[0] < static_cast<uint8_t>(VideoContentType::TOTAL_CONTENT_TYPES)) {
|
|
|
|
|
*content_type = static_cast<VideoContentType>(data[0]);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoContentTypeExtension::Write(uint8_t* data,
|
|
|
|
|
VideoContentType content_type) {
|
|
|
|
|
data[0] = static_cast<uint8_t>(content_type);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 02:59:48 -07:00
|
|
|
// RtpStreamId.
|
|
|
|
|
constexpr RTPExtensionType RtpStreamId::kId;
|
|
|
|
|
constexpr uint8_t RtpStreamId::kValueSizeBytes;
|
|
|
|
|
constexpr const char* RtpStreamId::kUri;
|
|
|
|
|
|
|
|
|
|
bool RtpStreamId::Parse(rtc::ArrayView<const uint8_t> data, StreamId* rsid) {
|
|
|
|
|
if (data.empty() || data[0] == 0) // Valid rsid can't be empty.
|
|
|
|
|
return false;
|
|
|
|
|
rsid->Set(data);
|
|
|
|
|
RTC_DCHECK(!rsid->empty());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RtpStreamId::Parse(rtc::ArrayView<const uint8_t> data, std::string* rsid) {
|
|
|
|
|
if (data.empty() || data[0] == 0) // Valid rsid can't be empty.
|
|
|
|
|
return false;
|
|
|
|
|
const char* str = reinterpret_cast<const char*>(data.data());
|
|
|
|
|
// If there is a \0 character in the middle of the |data|, treat it as end of
|
|
|
|
|
// the string. Well-formed rsid shouldn't contain it.
|
|
|
|
|
rsid->assign(str, strnlen(str, data.size()));
|
|
|
|
|
RTC_DCHECK(!rsid->empty());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RepairedRtpStreamId.
|
|
|
|
|
constexpr RTPExtensionType RepairedRtpStreamId::kId;
|
|
|
|
|
constexpr uint8_t RepairedRtpStreamId::kValueSizeBytes;
|
|
|
|
|
constexpr const char* RepairedRtpStreamId::kUri;
|
|
|
|
|
|
|
|
|
|
// RtpStreamId and RepairedRtpStreamId use the same format to store rsid.
|
|
|
|
|
bool RepairedRtpStreamId::Parse(rtc::ArrayView<const uint8_t> data,
|
|
|
|
|
StreamId* rsid) {
|
|
|
|
|
return RtpStreamId::Parse(data, rsid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RepairedRtpStreamId::Parse(rtc::ArrayView<const uint8_t> data,
|
|
|
|
|
std::string* rsid) {
|
|
|
|
|
return RtpStreamId::Parse(data, rsid);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 05:25:10 -07:00
|
|
|
} // namespace webrtc
|