2013-08-19 16:09:34 +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
|
|
|
#ifndef TEST_RTP_RTCP_OBSERVER_H_
|
|
|
|
|
#define TEST_RTP_RTCP_OBSERVER_H_
|
2013-08-19 16:09:34 +00:00
|
|
|
|
|
|
|
|
#include <map>
|
2016-05-01 14:53:46 -07:00
|
|
|
#include <memory>
|
Reland "Delete test/constants.h"
This reverts commit 4f36b7a478c2763463c7a9ea970548ec68bc3ea6.
Reason for revert: Failing tests fixed.
Original change's description:
> Revert "Delete test/constants.h"
>
> This reverts commit 389b1672a32f2dd49af6c6ed40e8ddf394b986de.
>
> Reason for revert: Causes failure (and empty result list) in CallPerfTest.PadsToMinTransmitBitrate
>
> Original change's description:
> > Delete test/constants.h
> >
> > It's not possible to use constants.h for all RTP extensions
> > after the number of extensions exceeds 14, which is the maximum
> > number of one-byte RTP extensions. This is because some extensions
> > would have to be assigned a number greater than 14, even if the
> > test only involves 14 extensions or less.
> >
> > For uniformity's sake, this CL also edits some files to use an
> > enum as the files involved in this CL, rather than free-floating
> > const-ints.
> >
> > Bug: webrtc:10288
> > Change-Id: Ib5e58ad72c4d3756f4c4f6521f140ec59617f3f5
> > Reviewed-on: https://webrtc-review.googlesource.com/c/123048
> > Commit-Queue: Elad Alon <eladalon@webrtc.org>
> > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> > Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> > Reviewed-by: Erik Språng <sprang@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#26728}
>
> TBR=danilchap@webrtc.org,kwiberg@webrtc.org,eladalon@webrtc.org,sprang@webrtc.org
>
> Bug: webrtc:10288, chromium:933127
> Change-Id: If1de0bd8992137c52bf0b877b3cb0a2bafc809d4
> Reviewed-on: https://webrtc-review.googlesource.com/c/123381
> Commit-Queue: Oleh Prypin <oprypin@webrtc.org>
> Reviewed-by: Oleh Prypin <oprypin@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#26744}
TBR=danilchap@webrtc.org,oprypin@webrtc.org,kwiberg@webrtc.org,eladalon@webrtc.org,sprang@webrtc.org
Change-Id: I65e391325d3a6df6db3c0739185e2002e70fb954
Bug: webrtc:10288, chromium:933127
Reviewed-on: https://webrtc-review.googlesource.com/c/123384
Reviewed-by: Elad Alon <eladalon@webrtc.org>
Commit-Queue: Elad Alon <eladalon@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26750}
2019-02-18 23:45:57 +01:00
|
|
|
#include <utility>
|
2013-08-19 16:09:34 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2018-08-17 14:26:54 +02:00
|
|
|
#include "api/test/simulated_network.h"
|
|
|
|
|
#include "call/simulated_packet_receiver.h"
|
2018-06-19 15:03:05 +02:00
|
|
|
#include "call/video_send_stream.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/critical_section.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/event.h"
|
|
|
|
|
#include "system_wrappers/include/field_trial.h"
|
|
|
|
|
#include "test/direct_transport.h"
|
|
|
|
|
#include "test/gtest.h"
|
2019-08-29 16:39:05 +02:00
|
|
|
#include "test/rtp_header_parser.h"
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2017-02-21 05:20:28 -08:00
|
|
|
namespace {
|
|
|
|
|
const int kShortTimeoutMs = 500;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-19 16:09:34 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
class PacketTransport;
|
|
|
|
|
|
2013-08-19 16:09:34 +00:00
|
|
|
class RtpRtcpObserver {
|
|
|
|
|
public:
|
2015-10-27 08:29:42 -07:00
|
|
|
enum Action {
|
|
|
|
|
SEND_PACKET,
|
|
|
|
|
DROP_PACKET,
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-21 11:42:02 +00:00
|
|
|
virtual ~RtpRtcpObserver() {}
|
2015-10-27 08:29:42 -07:00
|
|
|
|
2017-02-21 05:20:28 -08:00
|
|
|
virtual bool Wait() {
|
2017-02-28 08:50:47 -08:00
|
|
|
if (field_trial::IsEnabled("WebRTC-QuickPerfTest")) {
|
2017-02-21 05:20:28 -08:00
|
|
|
observation_complete_.Wait(kShortTimeoutMs);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return observation_complete_.Wait(timeout_ms_);
|
|
|
|
|
}
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
virtual Action OnSendRtp(const uint8_t* packet, size_t length) {
|
|
|
|
|
return SEND_PACKET;
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
virtual Action OnSendRtcp(const uint8_t* packet, size_t length) {
|
|
|
|
|
return SEND_PACKET;
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
virtual Action OnReceiveRtp(const uint8_t* packet, size_t length) {
|
|
|
|
|
return SEND_PACKET;
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
virtual Action OnReceiveRtcp(const uint8_t* packet, size_t length) {
|
|
|
|
|
return SEND_PACKET;
|
2013-11-15 12:32:15 +00:00
|
|
|
}
|
2013-09-19 14:22:12 +00:00
|
|
|
|
2013-08-19 16:09:34 +00:00
|
|
|
protected:
|
2017-03-21 03:24:27 -07:00
|
|
|
RtpRtcpObserver() : RtpRtcpObserver(0) {}
|
2015-12-10 13:02:50 +01:00
|
|
|
explicit RtpRtcpObserver(int event_timeout_ms)
|
2019-08-29 16:39:05 +02:00
|
|
|
: parser_(RtpHeaderParser::CreateForTest()),
|
|
|
|
|
timeout_ms_(event_timeout_ms) {}
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-12-10 13:02:50 +01:00
|
|
|
rtc::Event observation_complete_;
|
2016-05-01 14:53:46 -07:00
|
|
|
const std::unique_ptr<RtpHeaderParser> parser_;
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
private:
|
2015-12-10 13:02:50 +01:00
|
|
|
const int timeout_ms_;
|
2015-10-27 08:29:42 -07:00
|
|
|
};
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
class PacketTransport : public test::DirectTransport {
|
|
|
|
|
public:
|
|
|
|
|
enum TransportType { kReceiver, kSender };
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2019-09-30 04:16:28 +02:00
|
|
|
PacketTransport(TaskQueueBase* task_queue,
|
2018-04-24 14:41:22 +02:00
|
|
|
Call* send_call,
|
|
|
|
|
RtpRtcpObserver* observer,
|
2017-10-24 16:26:49 +02:00
|
|
|
TransportType transport_type,
|
2018-04-24 14:41:22 +02:00
|
|
|
const std::map<uint8_t, MediaType>& payload_type_map,
|
2018-08-17 14:26:54 +02:00
|
|
|
std::unique_ptr<SimulatedPacketReceiverInterface> nw_pipe)
|
2018-04-24 14:41:22 +02:00
|
|
|
: test::DirectTransport(task_queue,
|
|
|
|
|
std::move(nw_pipe),
|
|
|
|
|
send_call,
|
|
|
|
|
payload_type_map),
|
2017-10-24 16:26:49 +02:00
|
|
|
observer_(observer),
|
|
|
|
|
transport_type_(transport_type) {}
|
|
|
|
|
|
2013-08-19 16:09:34 +00:00
|
|
|
private:
|
2015-10-27 08:29:42 -07:00
|
|
|
bool SendRtp(const uint8_t* packet,
|
|
|
|
|
size_t length,
|
|
|
|
|
const PacketOptions& options) override {
|
|
|
|
|
EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, length));
|
|
|
|
|
RtpRtcpObserver::Action action;
|
|
|
|
|
{
|
|
|
|
|
if (transport_type_ == kSender) {
|
|
|
|
|
action = observer_->OnSendRtp(packet, length);
|
|
|
|
|
} else {
|
|
|
|
|
action = observer_->OnReceiveRtp(packet, length);
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-27 08:29:42 -07:00
|
|
|
switch (action) {
|
|
|
|
|
case RtpRtcpObserver::DROP_PACKET:
|
|
|
|
|
// Drop packet silently.
|
|
|
|
|
return true;
|
|
|
|
|
case RtpRtcpObserver::SEND_PACKET:
|
|
|
|
|
return test::DirectTransport::SendRtp(packet, length, options);
|
|
|
|
|
}
|
|
|
|
|
return true; // Will never happen, makes compiler happy.
|
|
|
|
|
}
|
2013-08-19 16:35:36 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
bool SendRtcp(const uint8_t* packet, size_t length) override {
|
|
|
|
|
EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, length));
|
|
|
|
|
RtpRtcpObserver::Action action;
|
|
|
|
|
{
|
|
|
|
|
if (transport_type_ == kSender) {
|
|
|
|
|
action = observer_->OnSendRtcp(packet, length);
|
|
|
|
|
} else {
|
|
|
|
|
action = observer_->OnReceiveRtcp(packet, length);
|
2013-08-19 16:09:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-27 08:29:42 -07:00
|
|
|
switch (action) {
|
|
|
|
|
case RtpRtcpObserver::DROP_PACKET:
|
|
|
|
|
// Drop packet silently.
|
|
|
|
|
return true;
|
|
|
|
|
case RtpRtcpObserver::SEND_PACKET:
|
|
|
|
|
return test::DirectTransport::SendRtcp(packet, length);
|
|
|
|
|
}
|
|
|
|
|
return true; // Will never happen, makes compiler happy.
|
|
|
|
|
}
|
2013-08-19 16:09:34 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
RtpRtcpObserver* const observer_;
|
|
|
|
|
TransportType transport_type_;
|
2013-08-19 16:09:34 +00:00
|
|
|
};
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // TEST_RTP_RTCP_OBSERVER_H_
|