| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 10 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
| 11 | 11 |
| 12 #include "webrtc/base/scoped_ptr.h" | 12 #include "webrtc/base/criticalsection.h" |
| 13 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 13 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
| 14 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 14 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
| 15 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
| 16 | 15 |
| 17 namespace webrtc { | 16 namespace webrtc { |
| 18 | 17 |
| 19 class RtpHeaderParserImpl : public RtpHeaderParser { | 18 class RtpHeaderParserImpl : public RtpHeaderParser { |
| 20 public: | 19 public: |
| 21 RtpHeaderParserImpl(); | 20 RtpHeaderParserImpl(); |
| 22 virtual ~RtpHeaderParserImpl() {} | 21 virtual ~RtpHeaderParserImpl() {} |
| 23 | 22 |
| 24 bool Parse(const uint8_t* packet, | 23 bool Parse(const uint8_t* packet, |
| 25 size_t length, | 24 size_t length, |
| 26 RTPHeader* header) const override; | 25 RTPHeader* header) const override; |
| 27 | 26 |
| 28 bool RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id) override; | 27 bool RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id) override; |
| 29 | 28 |
| 30 bool DeregisterRtpHeaderExtension(RTPExtensionType type) override; | 29 bool DeregisterRtpHeaderExtension(RTPExtensionType type) override; |
| 31 | 30 |
| 32 private: | 31 private: |
| 33 rtc::scoped_ptr<CriticalSectionWrapper> critical_section_; | 32 rtc::CriticalSection critical_section_; |
| 34 RtpHeaderExtensionMap rtp_header_extension_map_ GUARDED_BY(critical_section_); | 33 RtpHeaderExtensionMap rtp_header_extension_map_ GUARDED_BY(critical_section_); |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 RtpHeaderParser* RtpHeaderParser::Create() { | 36 RtpHeaderParser* RtpHeaderParser::Create() { |
| 38 return new RtpHeaderParserImpl; | 37 return new RtpHeaderParserImpl; |
| 39 } | 38 } |
| 40 | 39 |
| 41 RtpHeaderParserImpl::RtpHeaderParserImpl() | 40 RtpHeaderParserImpl::RtpHeaderParserImpl() {} |
| 42 : critical_section_(CriticalSectionWrapper::CreateCriticalSection()) {} | |
| 43 | 41 |
| 44 bool RtpHeaderParser::IsRtcp(const uint8_t* packet, size_t length) { | 42 bool RtpHeaderParser::IsRtcp(const uint8_t* packet, size_t length) { |
| 45 RtpUtility::RtpHeaderParser rtp_parser(packet, length); | 43 RtpUtility::RtpHeaderParser rtp_parser(packet, length); |
| 46 return rtp_parser.RTCP(); | 44 return rtp_parser.RTCP(); |
| 47 } | 45 } |
| 48 | 46 |
| 49 bool RtpHeaderParserImpl::Parse(const uint8_t* packet, | 47 bool RtpHeaderParserImpl::Parse(const uint8_t* packet, |
| 50 size_t length, | 48 size_t length, |
| 51 RTPHeader* header) const { | 49 RTPHeader* header) const { |
| 52 RtpUtility::RtpHeaderParser rtp_parser(packet, length); | 50 RtpUtility::RtpHeaderParser rtp_parser(packet, length); |
| 53 memset(header, 0, sizeof(*header)); | 51 memset(header, 0, sizeof(*header)); |
| 54 | 52 |
| 55 RtpHeaderExtensionMap map; | 53 RtpHeaderExtensionMap map; |
| 56 { | 54 { |
| 57 CriticalSectionScoped cs(critical_section_.get()); | 55 rtc::CritScope cs(&critical_section_); |
| 58 rtp_header_extension_map_.GetCopy(&map); | 56 rtp_header_extension_map_.GetCopy(&map); |
| 59 } | 57 } |
| 60 | 58 |
| 61 const bool valid_rtpheader = rtp_parser.Parse(header, &map); | 59 const bool valid_rtpheader = rtp_parser.Parse(header, &map); |
| 62 if (!valid_rtpheader) { | 60 if (!valid_rtpheader) { |
| 63 return false; | 61 return false; |
| 64 } | 62 } |
| 65 return true; | 63 return true; |
| 66 } | 64 } |
| 67 | 65 |
| 68 bool RtpHeaderParserImpl::RegisterRtpHeaderExtension(RTPExtensionType type, | 66 bool RtpHeaderParserImpl::RegisterRtpHeaderExtension(RTPExtensionType type, |
| 69 uint8_t id) { | 67 uint8_t id) { |
| 70 CriticalSectionScoped cs(critical_section_.get()); | 68 rtc::CritScope cs(&critical_section_); |
| 71 return rtp_header_extension_map_.Register(type, id) == 0; | 69 return rtp_header_extension_map_.Register(type, id) == 0; |
| 72 } | 70 } |
| 73 | 71 |
| 74 bool RtpHeaderParserImpl::DeregisterRtpHeaderExtension(RTPExtensionType type) { | 72 bool RtpHeaderParserImpl::DeregisterRtpHeaderExtension(RTPExtensionType type) { |
| 75 CriticalSectionScoped cs(critical_section_.get()); | 73 rtc::CritScope cs(&critical_section_); |
| 76 return rtp_header_extension_map_.Deregister(type) == 0; | 74 return rtp_header_extension_map_.Deregister(type) == 0; |
| 77 } | 75 } |
| 78 } // namespace webrtc | 76 } // namespace webrtc |
| OLD | NEW |