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