1 /*
2 * Copyright (c) 2004 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
11 #ifndef MEDIA_BASE_TEST_UTILS_H_
12 #define MEDIA_BASE_TEST_UTILS_H_
13
14 #include <string>
15 #include <vector>
16
17 #include "media/base/media_channel.h"
18 #include "media/base/video_common.h"
19 #include "rtc_base/arraysize.h"
20
21 namespace webrtc {
22 class VideoFrame;
23 }
24
25 namespace cricket {
26
27 // Returns size of 420 image with rounding on chroma for odd sizes.
28 #define I420_SIZE(w, h) (w * h + (((w + 1) / 2) * ((h + 1) / 2)) * 2)
29 // Returns size of ARGB image.
30 #define ARGB_SIZE(w, h) (w * h * 4)
31
32 template <class T>
MakeVector(const T a[],size_t s)33 inline std::vector<T> MakeVector(const T a[], size_t s) {
34 return std::vector<T>(a, a + s);
35 }
36 #define MAKE_VECTOR(a) cricket::MakeVector(a, arraysize(a))
37
38 // Checks whether `codecs` contains `codec`; checks using Codec::Matches().
39 template <class C>
ContainsMatchingCodec(const std::vector<C> & codecs,const C & codec,const webrtc::FieldTrialsView * field_trials)40 bool ContainsMatchingCodec(const std::vector<C>& codecs,
41 const C& codec,
42 const webrtc::FieldTrialsView* field_trials) {
43 typename std::vector<C>::const_iterator it;
44 for (it = codecs.begin(); it != codecs.end(); ++it) {
45 if (it->Matches(codec, field_trials)) {
46 return true;
47 }
48 }
49 return false;
50 }
51
52 // Create Simulcast StreamParams with given `ssrcs` and `cname`.
53 cricket::StreamParams CreateSimStreamParams(const std::string& cname,
54 const std::vector<uint32_t>& ssrcs);
55 // Create Simulcast stream with given `ssrcs` and `rtx_ssrcs`.
56 // The number of `rtx_ssrcs` must match number of `ssrcs`.
57 cricket::StreamParams CreateSimWithRtxStreamParams(
58 const std::string& cname,
59 const std::vector<uint32_t>& ssrcs,
60 const std::vector<uint32_t>& rtx_ssrcs);
61
62 // Create StreamParams with single primary SSRC and corresponding FlexFEC SSRC.
63 cricket::StreamParams CreatePrimaryWithFecFrStreamParams(
64 const std::string& cname,
65 uint32_t primary_ssrc,
66 uint32_t flexfec_ssrc);
67
68 } // namespace cricket
69
70 #endif // MEDIA_BASE_TEST_UTILS_H_
71