1 /*
2  *  Copyright (c) 2015 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 #ifndef TEST_LAYER_FILTERING_TRANSPORT_H_
11 #define TEST_LAYER_FILTERING_TRANSPORT_H_
12 
13 #include <stddef.h>
14 #include <stdint.h>
15 
16 #include <map>
17 #include <memory>
18 
19 #include "api/call/transport.h"
20 #include "api/media_types.h"
21 #include "call/call.h"
22 #include "call/simulated_packet_receiver.h"
23 #include "modules/rtp_rtcp/source/video_rtp_depacketizer.h"
24 #include "test/direct_transport.h"
25 
26 namespace webrtc {
27 
28 namespace test {
29 
30 class LayerFilteringTransport : public test::DirectTransport {
31  public:
32   LayerFilteringTransport(
33       TaskQueueBase* task_queue,
34       std::unique_ptr<SimulatedPacketReceiverInterface> pipe,
35       Call* send_call,
36       uint8_t vp8_video_payload_type,
37       uint8_t vp9_video_payload_type,
38       int selected_tl,
39       int selected_sl,
40       const std::map<uint8_t, MediaType>& payload_type_map,
41       uint32_t ssrc_to_filter_min,
42       uint32_t ssrc_to_filter_max);
43   LayerFilteringTransport(
44       TaskQueueBase* task_queue,
45       std::unique_ptr<SimulatedPacketReceiverInterface> pipe,
46       Call* send_call,
47       uint8_t vp8_video_payload_type,
48       uint8_t vp9_video_payload_type,
49       int selected_tl,
50       int selected_sl,
51       const std::map<uint8_t, MediaType>& payload_type_map);
52   bool DiscardedLastPacket() const;
53   bool SendRtp(const uint8_t* data,
54                size_t length,
55                const PacketOptions& options) override;
56 
57  private:
58   // Used to distinguish between VP8 and VP9.
59   const uint8_t vp8_video_payload_type_;
60   const uint8_t vp9_video_payload_type_;
61   const std::unique_ptr<VideoRtpDepacketizer> vp8_depacketizer_;
62   const std::unique_ptr<VideoRtpDepacketizer> vp9_depacketizer_;
63   // Discard or invalidate all temporal/spatial layers with id greater than the
64   // selected one. -1 to disable filtering.
65   const int selected_tl_;
66   const int selected_sl_;
67   bool discarded_last_packet_;
68   int num_active_spatial_layers_;
69   const uint32_t ssrc_to_filter_min_;
70   const uint32_t ssrc_to_filter_max_;
71 };
72 
73 }  // namespace test
74 }  // namespace webrtc
75 
76 #endif  // TEST_LAYER_FILTERING_TRANSPORT_H_
77