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