1 /* 2 * Copyright (c) 2013 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 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" 11 12 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" 13 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 14 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" 15 #include "webrtc/system_wrappers/interface/scoped_ptr.h" 16 17 namespace webrtc { 18 19 class RtpHeaderParserImpl : public RtpHeaderParser { 20 public: 21 RtpHeaderParserImpl(); 22 virtual ~RtpHeaderParserImpl() {} 23 24 virtual bool Parse(const uint8_t* packet, int length, 25 RTPHeader* header) const OVERRIDE; 26 27 virtual bool RegisterRtpHeaderExtension(RTPExtensionType type, 28 uint8_t id) OVERRIDE; 29 30 virtual bool DeregisterRtpHeaderExtension(RTPExtensionType type) OVERRIDE; 31 32 private: 33 scoped_ptr<CriticalSectionWrapper> critical_section_; 34 RtpHeaderExtensionMap rtp_header_extension_map_; 35 }; 36 37 RtpHeaderParser* RtpHeaderParser::Create() { 38 return new RtpHeaderParserImpl; 39 } 40 41 RtpHeaderParserImpl::RtpHeaderParserImpl() 42 : critical_section_(CriticalSectionWrapper::CreateCriticalSection()) {} 43 44 bool RtpHeaderParser::IsRtcp(const uint8_t* packet, int length) { 45 ModuleRTPUtility::RTPHeaderParser rtp_parser(packet, length); 46 return rtp_parser.RTCP(); 47 } 48 49 bool RtpHeaderParserImpl::Parse(const uint8_t* packet, int length, 50 RTPHeader* header) const { 51 ModuleRTPUtility::RTPHeaderParser rtp_parser(packet, length); 52 memset(header, 0, sizeof(*header)); 53 54 RtpHeaderExtensionMap map; 55 { 56 CriticalSectionScoped cs(critical_section_.get()); 57 rtp_header_extension_map_.GetCopy(&map); 58 } 59 60 const bool valid_rtpheader = rtp_parser.Parse(*header, &map); 61 if (!valid_rtpheader) { 62 return false; 63 } 64 return true; 65 } 66 67 bool RtpHeaderParserImpl::RegisterRtpHeaderExtension(RTPExtensionType type, 68 uint8_t id) { 69 CriticalSectionScoped cs(critical_section_.get()); 70 return rtp_header_extension_map_.Register(type, id) == 0; 71 } 72 73 bool RtpHeaderParserImpl::DeregisterRtpHeaderExtension(RTPExtensionType type) { 74 CriticalSectionScoped cs(critical_section_.get()); 75 return rtp_header_extension_map_.Deregister(type) == 0; 76 } 77 } // namespace webrtc 78