2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
10 #ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_RTP_RTCP_OBSERVER_H_
11 #define WEBRTC_VIDEO_ENGINE_TEST_COMMON_RTP_RTCP_OBSERVER_H_
16 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
17 #include "webrtc/typedefs.h"
18 #include "webrtc/video_send_stream.h"
23 class RtpRtcpObserver {
25 virtual ~RtpRtcpObserver() {}
26 newapi::Transport* SendTransport() {
27 return &send_transport_;
30 newapi::Transport* ReceiveTransport() {
31 return &receive_transport_;
34 void SetReceivers(PacketReceiver* send_transport_receiver,
35 PacketReceiver* receive_transport_receiver) {
36 send_transport_.SetReceiver(send_transport_receiver);
37 receive_transport_.SetReceiver(receive_transport_receiver);
41 send_transport_.StopSending();
42 receive_transport_.StopSending();
45 virtual EventTypeWrapper Wait() {
46 EventTypeWrapper result = observation_complete_->Wait(timeout_ms_);
47 observation_complete_->Reset();
52 RtpRtcpObserver(unsigned int event_timeout_ms,
53 const FakeNetworkPipe::Config& configuration)
54 : lock_(CriticalSectionWrapper::CreateCriticalSection()),
55 observation_complete_(EventWrapper::Create()),
56 parser_(RtpHeaderParser::Create()),
57 send_transport_(lock_.get(),
59 &RtpRtcpObserver::OnSendRtp,
60 &RtpRtcpObserver::OnSendRtcp,
62 receive_transport_(lock_.get(),
64 &RtpRtcpObserver::OnReceiveRtp,
65 &RtpRtcpObserver::OnReceiveRtcp,
67 timeout_ms_(event_timeout_ms) {}
69 explicit RtpRtcpObserver(unsigned int event_timeout_ms)
70 : lock_(CriticalSectionWrapper::CreateCriticalSection()),
71 observation_complete_(EventWrapper::Create()),
72 parser_(RtpHeaderParser::Create()),
73 send_transport_(lock_.get(),
75 &RtpRtcpObserver::OnSendRtp,
76 &RtpRtcpObserver::OnSendRtcp,
77 FakeNetworkPipe::Config()),
78 receive_transport_(lock_.get(),
80 &RtpRtcpObserver::OnReceiveRtp,
81 &RtpRtcpObserver::OnReceiveRtcp,
82 FakeNetworkPipe::Config()),
83 timeout_ms_(event_timeout_ms) {}
90 virtual Action OnSendRtp(const uint8_t* packet, size_t length) {
94 virtual Action OnSendRtcp(const uint8_t* packet, size_t length) {
98 virtual Action OnReceiveRtp(const uint8_t* packet, size_t length) {
102 virtual Action OnReceiveRtcp(const uint8_t* packet, size_t length) {
108 class PacketTransport : public test::DirectTransport {
110 typedef Action (RtpRtcpObserver::*PacketTransportAction)(const uint8_t*,
113 PacketTransport(CriticalSectionWrapper* lock,
114 RtpRtcpObserver* observer,
115 PacketTransportAction on_rtp,
116 PacketTransportAction on_rtcp,
117 const FakeNetworkPipe::Config& configuration)
118 : test::DirectTransport(configuration),
125 virtual bool SendRtp(const uint8_t* packet, size_t length) OVERRIDE {
128 CriticalSectionScoped crit_(lock_);
129 action = (observer_->*on_rtp_)(packet, length);
133 // Drop packet silently.
136 return test::DirectTransport::SendRtp(packet, length);
138 return true; // Will never happen, makes compiler happy.
141 virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE {
144 CriticalSectionScoped crit_(lock_);
145 action = (observer_->*on_rtcp_)(packet, length);
149 // Drop packet silently.
152 return test::DirectTransport::SendRtcp(packet, length);
154 return true; // Will never happen, makes compiler happy.
157 // Pointer to shared lock instance protecting on_rtp_/on_rtcp_ calls.
158 CriticalSectionWrapper* lock_;
160 RtpRtcpObserver* observer_;
161 PacketTransportAction on_rtp_, on_rtcp_;
165 scoped_ptr<CriticalSectionWrapper> lock_;
166 scoped_ptr<EventWrapper> observation_complete_;
167 scoped_ptr<RtpHeaderParser> parser_;
170 PacketTransport send_transport_, receive_transport_;
171 unsigned int timeout_ms_;
174 } // namespace webrtc
176 #endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_RTP_RTCP_OBSERVER_H_