henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MEDIA_BASE_TESTUTILS_H_ |
| 12 | #define MEDIA_BASE_TESTUTILS_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "media/base/mediachannel.h" |
| 18 | #include "media/base/videocapturer.h" |
| 19 | #include "media/base/videocommon.h" |
| 20 | #include "rtc_base/arraysize.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame^] | 21 | #include "rtc_base/third_party/sigslot/sigslot.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 23 | namespace rtc { |
jbauch | f1f8720 | 2016-03-30 06:43:37 -0700 | [diff] [blame] | 24 | class ByteBufferReader; |
| 25 | class ByteBufferWriter; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 26 | class StreamInterface; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 27 | } // namespace rtc |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 28 | |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 29 | namespace webrtc { |
| 30 | class VideoFrame; |
| 31 | } |
| 32 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | namespace cricket { |
| 34 | |
| 35 | // Returns size of 420 image with rounding on chroma for odd sizes. |
| 36 | #define I420_SIZE(w, h) (w * h + (((w + 1) / 2) * ((h + 1) / 2)) * 2) |
| 37 | // Returns size of ARGB image. |
| 38 | #define ARGB_SIZE(w, h) (w * h * 4) |
| 39 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 40 | template <class T> |
| 41 | inline std::vector<T> MakeVector(const T a[], size_t s) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | return std::vector<T>(a, a + s); |
| 43 | } |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 44 | #define MAKE_VECTOR(a) cricket::MakeVector(a, arraysize(a)) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | |
| 46 | struct RtpDumpPacket; |
| 47 | class RtpDumpWriter; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | |
| 49 | struct RawRtpPacket { |
jbauch | f1f8720 | 2016-03-30 06:43:37 -0700 | [diff] [blame] | 50 | void WriteToByteBuffer(uint32_t in_ssrc, rtc::ByteBufferWriter* buf) const; |
| 51 | bool ReadFromByteBuffer(rtc::ByteBufferReader* buf); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | // Check if this packet is the same as the specified packet except the |
| 53 | // sequence number and timestamp, which should be the same as the specified |
| 54 | // parameters. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 55 | bool SameExceptSeqNumTimestampSsrc(const RawRtpPacket& packet, |
| 56 | uint16_t seq, |
| 57 | uint32_t ts, |
| 58 | uint32_t ssc) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | int size() const { return 28; } |
| 60 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 61 | uint8_t ver_to_cc; |
| 62 | uint8_t m_to_pt; |
| 63 | uint16_t sequence_number; |
| 64 | uint32_t timestamp; |
| 65 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | char payload[16]; |
| 67 | }; |
| 68 | |
| 69 | struct RawRtcpPacket { |
jbauch | f1f8720 | 2016-03-30 06:43:37 -0700 | [diff] [blame] | 70 | void WriteToByteBuffer(rtc::ByteBufferWriter* buf) const; |
| 71 | bool ReadFromByteBuffer(rtc::ByteBufferReader* buf); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | bool EqualsTo(const RawRtcpPacket& packet) const; |
| 73 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 74 | uint8_t ver_to_count; |
| 75 | uint8_t type; |
| 76 | uint16_t length; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 77 | char payload[16]; |
| 78 | }; |
| 79 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | // Test helper for testing VideoCapturer implementations. |
nisse | 7924697 | 2016-08-23 05:50:09 -0700 | [diff] [blame] | 81 | class VideoCapturerListener |
| 82 | : public sigslot::has_slots<>, |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 83 | public rtc::VideoSinkInterface<webrtc::VideoFrame> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | public: |
| 85 | explicit VideoCapturerListener(VideoCapturer* cap); |
nisse | 7924697 | 2016-08-23 05:50:09 -0700 | [diff] [blame] | 86 | ~VideoCapturerListener(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | |
| 88 | CaptureState last_capture_state() const { return last_capture_state_; } |
| 89 | int frame_count() const { return frame_count_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | int frame_width() const { return frame_width_; } |
| 91 | int frame_height() const { return frame_height_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | bool resolution_changed() const { return resolution_changed_; } |
| 93 | |
| 94 | void OnStateChange(VideoCapturer* capturer, CaptureState state); |
nisse | acd935b | 2016-11-11 03:55:13 -0800 | [diff] [blame] | 95 | void OnFrame(const webrtc::VideoFrame& frame) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | |
| 97 | private: |
nisse | 7924697 | 2016-08-23 05:50:09 -0700 | [diff] [blame] | 98 | VideoCapturer* capturer_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | CaptureState last_capture_state_; |
| 100 | int frame_count_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | int frame_width_; |
| 102 | int frame_height_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | bool resolution_changed_; |
| 104 | }; |
| 105 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 106 | // Checks whether |codecs| contains |codec|; checks using Codec::Matches(). |
| 107 | template <class C> |
| 108 | bool ContainsMatchingCodec(const std::vector<C>& codecs, const C& codec) { |
| 109 | typename std::vector<C>::const_iterator it; |
| 110 | for (it = codecs.begin(); it != codecs.end(); ++it) { |
| 111 | if (it->Matches(codec)) { |
| 112 | return true; |
| 113 | } |
| 114 | } |
| 115 | return false; |
| 116 | } |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 117 | |
| 118 | // Create Simulcast StreamParams with given |ssrcs| and |cname|. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 119 | cricket::StreamParams CreateSimStreamParams(const std::string& cname, |
| 120 | const std::vector<uint32_t>& ssrcs); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 121 | // Create Simulcast stream with given |ssrcs| and |rtx_ssrcs|. |
| 122 | // The number of |rtx_ssrcs| must match number of |ssrcs|. |
| 123 | cricket::StreamParams CreateSimWithRtxStreamParams( |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 124 | const std::string& cname, |
| 125 | const std::vector<uint32_t>& ssrcs, |
| 126 | const std::vector<uint32_t>& rtx_ssrcs); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 127 | |
brandtr | 9688e38 | 2016-11-22 00:59:48 -0800 | [diff] [blame] | 128 | // Create StreamParams with single primary SSRC and corresponding FlexFEC SSRC. |
| 129 | cricket::StreamParams CreatePrimaryWithFecFrStreamParams( |
| 130 | const std::string& cname, |
| 131 | uint32_t primary_ssrc, |
| 132 | uint32_t flexfec_ssrc); |
| 133 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 134 | } // namespace cricket |
| 135 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 136 | #endif // MEDIA_BASE_TESTUTILS_H_ |