2013-05-29 12:12:51 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 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.
|
|
|
|
|
*/
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_header_parser.h"
|
2013-05-29 12:12:51 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_utility.h"
|
|
|
|
|
#include "rtc_base/criticalsection.h"
|
2013-05-29 12:12:51 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class RtpHeaderParserImpl : public RtpHeaderParser {
|
|
|
|
|
public:
|
|
|
|
|
RtpHeaderParserImpl();
|
|
|
|
|
virtual ~RtpHeaderParserImpl() {}
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
bool Parse(const uint8_t* packet,
|
|
|
|
|
size_t length,
|
|
|
|
|
RTPHeader* header) const override;
|
2013-05-29 12:12:51 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
bool RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id) override;
|
2013-05-29 12:12:51 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
bool DeregisterRtpHeaderExtension(RTPExtensionType type) override;
|
2013-05-29 12:12:51 +00:00
|
|
|
|
|
|
|
|
private:
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CriticalSection critical_section_;
|
2017-09-07 07:53:45 -07:00
|
|
|
RtpHeaderExtensionMap rtp_header_extension_map_
|
|
|
|
|
RTC_GUARDED_BY(critical_section_);
|
2013-05-29 12:12:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RtpHeaderParser* RtpHeaderParser::Create() {
|
|
|
|
|
return new RtpHeaderParserImpl;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-14 03:05:31 -07:00
|
|
|
RtpHeaderParserImpl::RtpHeaderParserImpl() {}
|
2013-05-29 12:12:51 +00:00
|
|
|
|
2014-07-08 12:10:51 +00:00
|
|
|
bool RtpHeaderParser::IsRtcp(const uint8_t* packet, size_t length) {
|
|
|
|
|
RtpUtility::RtpHeaderParser rtp_parser(packet, length);
|
2013-05-29 12:12:51 +00:00
|
|
|
return rtp_parser.RTCP();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 12:10:51 +00:00
|
|
|
bool RtpHeaderParserImpl::Parse(const uint8_t* packet,
|
|
|
|
|
size_t length,
|
|
|
|
|
RTPHeader* header) const {
|
|
|
|
|
RtpUtility::RtpHeaderParser rtp_parser(packet, length);
|
2013-05-29 12:12:51 +00:00
|
|
|
memset(header, 0, sizeof(*header));
|
|
|
|
|
|
|
|
|
|
RtpHeaderExtensionMap map;
|
|
|
|
|
{
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&critical_section_);
|
2016-12-01 08:39:35 -08:00
|
|
|
map = rtp_header_extension_map_;
|
2013-05-29 12:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-28 10:18:46 -08:00
|
|
|
const bool valid_rtpheader = rtp_parser.Parse(header, &map);
|
2013-05-29 12:12:51 +00:00
|
|
|
if (!valid_rtpheader) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RtpHeaderParserImpl::RegisterRtpHeaderExtension(RTPExtensionType type,
|
|
|
|
|
uint8_t id) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&critical_section_);
|
2016-12-01 08:39:35 -08:00
|
|
|
return rtp_header_extension_map_.RegisterByType(id, type);
|
2013-05-29 12:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RtpHeaderParserImpl::DeregisterRtpHeaderExtension(RTPExtensionType type) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&critical_section_);
|
2013-05-29 12:12:51 +00:00
|
|
|
return rtp_header_extension_map_.Deregister(type) == 0;
|
|
|
|
|
}
|
|
|
|
|
} // namespace webrtc
|