OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 template <class T> inline std::vector<T> MakeVector(const T a[], size_t s) { | 54 template <class T> inline std::vector<T> MakeVector(const T a[], size_t s) { |
55 return std::vector<T>(a, a + s); | 55 return std::vector<T>(a, a + s); |
56 } | 56 } |
57 #define MAKE_VECTOR(a) cricket::MakeVector(a, ARRAY_SIZE(a)) | 57 #define MAKE_VECTOR(a) cricket::MakeVector(a, ARRAY_SIZE(a)) |
58 | 58 |
59 struct RtpDumpPacket; | 59 struct RtpDumpPacket; |
60 class RtpDumpWriter; | 60 class RtpDumpWriter; |
61 class VideoFrame; | 61 class VideoFrame; |
62 | 62 |
63 struct RawRtpPacket { | 63 struct RawRtpPacket { |
64 void WriteToByteBuffer(uint32 in_ssrc, rtc::ByteBuffer* buf) const; | 64 void WriteToByteBuffer(uint32_t in_ssrc, rtc::ByteBuffer* buf) const; |
65 bool ReadFromByteBuffer(rtc::ByteBuffer* buf); | 65 bool ReadFromByteBuffer(rtc::ByteBuffer* buf); |
66 // Check if this packet is the same as the specified packet except the | 66 // Check if this packet is the same as the specified packet except the |
67 // sequence number and timestamp, which should be the same as the specified | 67 // sequence number and timestamp, which should be the same as the specified |
68 // parameters. | 68 // parameters. |
69 bool SameExceptSeqNumTimestampSsrc( | 69 bool SameExceptSeqNumTimestampSsrc(const RawRtpPacket& packet, |
70 const RawRtpPacket& packet, uint16 seq, uint32 ts, uint32 ssc) const; | 70 uint16_t seq, |
| 71 uint32_t ts, |
| 72 uint32_t ssc) const; |
71 int size() const { return 28; } | 73 int size() const { return 28; } |
72 | 74 |
73 uint8 ver_to_cc; | 75 uint8_t ver_to_cc; |
74 uint8 m_to_pt; | 76 uint8_t m_to_pt; |
75 uint16 sequence_number; | 77 uint16_t sequence_number; |
76 uint32 timestamp; | 78 uint32_t timestamp; |
77 uint32 ssrc; | 79 uint32_t ssrc; |
78 char payload[16]; | 80 char payload[16]; |
79 }; | 81 }; |
80 | 82 |
81 struct RawRtcpPacket { | 83 struct RawRtcpPacket { |
82 void WriteToByteBuffer(rtc::ByteBuffer* buf) const; | 84 void WriteToByteBuffer(rtc::ByteBuffer* buf) const; |
83 bool ReadFromByteBuffer(rtc::ByteBuffer* buf); | 85 bool ReadFromByteBuffer(rtc::ByteBuffer* buf); |
84 bool EqualsTo(const RawRtcpPacket& packet) const; | 86 bool EqualsTo(const RawRtcpPacket& packet) const; |
85 | 87 |
86 uint8 ver_to_count; | 88 uint8_t ver_to_count; |
87 uint8 type; | 89 uint8_t type; |
88 uint16 length; | 90 uint16_t length; |
89 char payload[16]; | 91 char payload[16]; |
90 }; | 92 }; |
91 | 93 |
92 class RtpTestUtility { | 94 class RtpTestUtility { |
93 public: | 95 public: |
94 static size_t GetTestPacketCount(); | 96 static size_t GetTestPacketCount(); |
95 | 97 |
96 // Write the first count number of kTestRawRtcpPackets or kTestRawRtpPackets, | 98 // Write the first count number of kTestRawRtcpPackets or kTestRawRtpPackets, |
97 // depending on the flag rtcp. If it is RTP, use the specified SSRC. Return | 99 // depending on the flag rtcp. If it is RTP, use the specified SSRC. Return |
98 // true if successful. | 100 // true if successful. |
99 static bool WriteTestPackets( | 101 static bool WriteTestPackets(size_t count, |
100 size_t count, bool rtcp, uint32 rtp_ssrc, RtpDumpWriter* writer); | 102 bool rtcp, |
| 103 uint32_t rtp_ssrc, |
| 104 RtpDumpWriter* writer); |
101 | 105 |
102 // Loop read the first count number of packets from the specified stream. | 106 // Loop read the first count number of packets from the specified stream. |
103 // Verify the elapsed time of the dump packets increase monotonically. If the | 107 // Verify the elapsed time of the dump packets increase monotonically. If the |
104 // stream is a RTP stream, verify the RTP sequence number, timestamp, and | 108 // stream is a RTP stream, verify the RTP sequence number, timestamp, and |
105 // payload. If the stream is a RTCP stream, verify the RTCP header and | 109 // payload. If the stream is a RTCP stream, verify the RTCP header and |
106 // payload. | 110 // payload. |
107 static bool VerifyTestPacketsFromStream( | 111 static bool VerifyTestPacketsFromStream(size_t count, |
108 size_t count, rtc::StreamInterface* stream, uint32 ssrc); | 112 rtc::StreamInterface* stream, |
| 113 uint32_t ssrc); |
109 | 114 |
110 // Verify the dump packet is the same as the raw RTP packet. | 115 // Verify the dump packet is the same as the raw RTP packet. |
111 static bool VerifyPacket(const RtpDumpPacket* dump, | 116 static bool VerifyPacket(const RtpDumpPacket* dump, |
112 const RawRtpPacket* raw, | 117 const RawRtpPacket* raw, |
113 bool header_only); | 118 bool header_only); |
114 | 119 |
115 static const uint32 kDefaultSsrc = 1; | 120 static const uint32_t kDefaultSsrc = 1; |
116 static const uint32 kRtpTimestampIncrease = 90; | 121 static const uint32_t kRtpTimestampIncrease = 90; |
117 static const uint32 kDefaultTimeIncrease = 30; | 122 static const uint32_t kDefaultTimeIncrease = 30; |
118 static const uint32 kElapsedTimeInterval = 10; | 123 static const uint32_t kElapsedTimeInterval = 10; |
119 static const RawRtpPacket kTestRawRtpPackets[]; | 124 static const RawRtpPacket kTestRawRtpPackets[]; |
120 static const RawRtcpPacket kTestRawRtcpPackets[]; | 125 static const RawRtcpPacket kTestRawRtcpPackets[]; |
121 | 126 |
122 private: | 127 private: |
123 RtpTestUtility() {} | 128 RtpTestUtility() {} |
124 }; | 129 }; |
125 | 130 |
126 // Test helper for testing VideoCapturer implementations. | 131 // Test helper for testing VideoCapturer implementations. |
127 class VideoCapturerListener : public sigslot::has_slots<> { | 132 class VideoCapturerListener : public sigslot::has_slots<> { |
128 public: | 133 public: |
129 explicit VideoCapturerListener(VideoCapturer* cap); | 134 explicit VideoCapturerListener(VideoCapturer* cap); |
130 | 135 |
131 CaptureState last_capture_state() const { return last_capture_state_; } | 136 CaptureState last_capture_state() const { return last_capture_state_; } |
132 int frame_count() const { return frame_count_; } | 137 int frame_count() const { return frame_count_; } |
133 uint32 frame_fourcc() const { return frame_fourcc_; } | 138 uint32_t frame_fourcc() const { return frame_fourcc_; } |
134 int frame_width() const { return frame_width_; } | 139 int frame_width() const { return frame_width_; } |
135 int frame_height() const { return frame_height_; } | 140 int frame_height() const { return frame_height_; } |
136 uint32 frame_size() const { return frame_size_; } | 141 uint32_t frame_size() const { return frame_size_; } |
137 bool resolution_changed() const { return resolution_changed_; } | 142 bool resolution_changed() const { return resolution_changed_; } |
138 | 143 |
139 void OnStateChange(VideoCapturer* capturer, CaptureState state); | 144 void OnStateChange(VideoCapturer* capturer, CaptureState state); |
140 void OnFrameCaptured(VideoCapturer* capturer, const CapturedFrame* frame); | 145 void OnFrameCaptured(VideoCapturer* capturer, const CapturedFrame* frame); |
141 | 146 |
142 private: | 147 private: |
143 CaptureState last_capture_state_; | 148 CaptureState last_capture_state_; |
144 int frame_count_; | 149 int frame_count_; |
145 uint32 frame_fourcc_; | 150 uint32_t frame_fourcc_; |
146 int frame_width_; | 151 int frame_width_; |
147 int frame_height_; | 152 int frame_height_; |
148 uint32 frame_size_; | 153 uint32_t frame_size_; |
149 bool resolution_changed_; | 154 bool resolution_changed_; |
150 }; | 155 }; |
151 | 156 |
152 class ScreencastEventCatcher : public sigslot::has_slots<> { | 157 class ScreencastEventCatcher : public sigslot::has_slots<> { |
153 public: | 158 public: |
154 ScreencastEventCatcher() : ssrc_(0), ev_(rtc::WE_RESIZE) { } | 159 ScreencastEventCatcher() : ssrc_(0), ev_(rtc::WE_RESIZE) { } |
155 uint32 ssrc() const { return ssrc_; } | 160 uint32_t ssrc() const { return ssrc_; } |
156 rtc::WindowEvent event() const { return ev_; } | 161 rtc::WindowEvent event() const { return ev_; } |
157 void OnEvent(uint32 ssrc, rtc::WindowEvent ev) { | 162 void OnEvent(uint32_t ssrc, rtc::WindowEvent ev) { |
158 ssrc_ = ssrc; | 163 ssrc_ = ssrc; |
159 ev_ = ev; | 164 ev_ = ev; |
160 } | 165 } |
161 private: | 166 private: |
162 uint32 ssrc_; | 167 uint32_t ssrc_; |
163 rtc::WindowEvent ev_; | 168 rtc::WindowEvent ev_; |
164 }; | 169 }; |
165 | 170 |
166 class VideoMediaErrorCatcher : public sigslot::has_slots<> { | 171 class VideoMediaErrorCatcher : public sigslot::has_slots<> { |
167 public: | 172 public: |
168 VideoMediaErrorCatcher() : ssrc_(0), error_(VideoMediaChannel::ERROR_NONE) { } | 173 VideoMediaErrorCatcher() : ssrc_(0), error_(VideoMediaChannel::ERROR_NONE) { } |
169 uint32 ssrc() const { return ssrc_; } | 174 uint32_t ssrc() const { return ssrc_; } |
170 VideoMediaChannel::Error error() const { return error_; } | 175 VideoMediaChannel::Error error() const { return error_; } |
171 void OnError(uint32 ssrc, VideoMediaChannel::Error error) { | 176 void OnError(uint32_t ssrc, VideoMediaChannel::Error error) { |
172 ssrc_ = ssrc; | 177 ssrc_ = ssrc; |
173 error_ = error; | 178 error_ = error; |
174 } | 179 } |
175 private: | 180 private: |
176 uint32 ssrc_; | 181 uint32_t ssrc_; |
177 VideoMediaChannel::Error error_; | 182 VideoMediaChannel::Error error_; |
178 }; | 183 }; |
179 | 184 |
180 // Returns the absolute path to a file in the testdata/ directory. | 185 // Returns the absolute path to a file in the testdata/ directory. |
181 std::string GetTestFilePath(const std::string& filename); | 186 std::string GetTestFilePath(const std::string& filename); |
182 | 187 |
183 // PSNR formula: psnr = 10 * log10 (Peak Signal^2 / mse) | 188 // PSNR formula: psnr = 10 * log10 (Peak Signal^2 / mse) |
184 // sse is set to a small number for identical frames or sse == 0 | 189 // sse is set to a small number for identical frames or sse == 0 |
185 static inline double ComputePSNR(double sse, double count) { | 190 static inline double ComputePSNR(double sse, double count) { |
186 return libyuv::SumSquareErrorToPsnr(static_cast<uint64>(sse), | 191 return libyuv::SumSquareErrorToPsnr(static_cast<uint64_t>(sse), |
187 static_cast<uint64>(count)); | 192 static_cast<uint64_t>(count)); |
188 } | 193 } |
189 | 194 |
190 static inline double ComputeSumSquareError(const uint8 *org, const uint8 *rec, | 195 static inline double ComputeSumSquareError(const uint8_t* org, |
| 196 const uint8_t* rec, |
191 int size) { | 197 int size) { |
192 return static_cast<double>(libyuv::ComputeSumSquareError(org, rec, size)); | 198 return static_cast<double>(libyuv::ComputeSumSquareError(org, rec, size)); |
193 } | 199 } |
194 | 200 |
195 // Loads the image with the specified prefix and size into |out|. | 201 // Loads the image with the specified prefix and size into |out|. |
196 bool LoadPlanarYuvTestImage(const std::string& prefix, | 202 bool LoadPlanarYuvTestImage(const std::string& prefix, |
197 int width, int height, uint8* out); | 203 int width, |
| 204 int height, |
| 205 uint8_t* out); |
198 | 206 |
199 // Dumps the YUV image out to a file, for visual inspection. | 207 // Dumps the YUV image out to a file, for visual inspection. |
200 // PYUV tool can be used to view dump files. | 208 // PYUV tool can be used to view dump files. |
201 void DumpPlanarYuvTestImage(const std::string& prefix, const uint8* img, | 209 void DumpPlanarYuvTestImage(const std::string& prefix, |
202 int w, int h); | 210 const uint8_t* img, |
| 211 int w, |
| 212 int h); |
203 | 213 |
204 // Dumps the ARGB image out to a file, for visual inspection. | 214 // Dumps the ARGB image out to a file, for visual inspection. |
205 // ffplay tool can be used to view dump files. | 215 // ffplay tool can be used to view dump files. |
206 void DumpPlanarArgbTestImage(const std::string& prefix, const uint8* img, | 216 void DumpPlanarArgbTestImage(const std::string& prefix, |
207 int w, int h); | 217 const uint8_t* img, |
| 218 int w, |
| 219 int h); |
208 | 220 |
209 // Compare two I420 frames. | 221 // Compare two I420 frames. |
210 bool VideoFrameEqual(const VideoFrame* frame0, const VideoFrame* frame1); | 222 bool VideoFrameEqual(const VideoFrame* frame0, const VideoFrame* frame1); |
211 | 223 |
212 // Checks whether |codecs| contains |codec|; checks using Codec::Matches(). | 224 // Checks whether |codecs| contains |codec|; checks using Codec::Matches(). |
213 template <class C> | 225 template <class C> |
214 bool ContainsMatchingCodec(const std::vector<C>& codecs, const C& codec) { | 226 bool ContainsMatchingCodec(const std::vector<C>& codecs, const C& codec) { |
215 typename std::vector<C>::const_iterator it; | 227 typename std::vector<C>::const_iterator it; |
216 for (it = codecs.begin(); it != codecs.end(); ++it) { | 228 for (it = codecs.begin(); it != codecs.end(); ++it) { |
217 if (it->Matches(codec)) { | 229 if (it->Matches(codec)) { |
218 return true; | 230 return true; |
219 } | 231 } |
220 } | 232 } |
221 return false; | 233 return false; |
222 } | 234 } |
223 | 235 |
224 // Create Simulcast StreamParams with given |ssrcs| and |cname|. | 236 // Create Simulcast StreamParams with given |ssrcs| and |cname|. |
225 cricket::StreamParams CreateSimStreamParams( | 237 cricket::StreamParams CreateSimStreamParams(const std::string& cname, |
226 const std::string& cname, const std::vector<uint32>& ssrcs); | 238 const std::vector<uint32_t>& ssrcs); |
227 // Create Simulcast stream with given |ssrcs| and |rtx_ssrcs|. | 239 // Create Simulcast stream with given |ssrcs| and |rtx_ssrcs|. |
228 // The number of |rtx_ssrcs| must match number of |ssrcs|. | 240 // The number of |rtx_ssrcs| must match number of |ssrcs|. |
229 cricket::StreamParams CreateSimWithRtxStreamParams( | 241 cricket::StreamParams CreateSimWithRtxStreamParams( |
230 const std::string& cname, const std::vector<uint32>& ssrcs, | 242 const std::string& cname, |
231 const std::vector<uint32>& rtx_ssrcs); | 243 const std::vector<uint32_t>& ssrcs, |
| 244 const std::vector<uint32_t>& rtx_ssrcs); |
232 | 245 |
233 } // namespace cricket | 246 } // namespace cricket |
234 | 247 |
235 #endif // TALK_MEDIA_BASE_TESTUTILS_H_ | 248 #endif // TALK_MEDIA_BASE_TESTUTILS_H_ |
OLD | NEW |