OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/media/base/testutils.h" | 11 #include "webrtc/media/base/testutils.h" |
12 | 12 |
13 #include <math.h> | 13 #include <math.h> |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "webrtc/base/bytebuffer.h" | 17 #include "webrtc/base/bytebuffer.h" |
18 #include "webrtc/base/fileutils.h" | 18 #include "webrtc/base/fileutils.h" |
19 #include "webrtc/base/gunit.h" | 19 #include "webrtc/base/gunit.h" |
20 #include "webrtc/base/pathutils.h" | 20 #include "webrtc/base/pathutils.h" |
21 #include "webrtc/base/stream.h" | 21 #include "webrtc/base/stream.h" |
22 #include "webrtc/base/stringutils.h" | 22 #include "webrtc/base/stringutils.h" |
23 #include "webrtc/base/testutils.h" | 23 #include "webrtc/base/testutils.h" |
24 #include "webrtc/media/base/executablehelpers.h" | |
25 #include "webrtc/media/base/rtpdump.h" | 24 #include "webrtc/media/base/rtpdump.h" |
26 #include "webrtc/media/base/videocapturer.h" | 25 #include "webrtc/media/base/videocapturer.h" |
27 #include "webrtc/media/base/videoframe.h" | 26 #include "webrtc/media/base/videoframe.h" |
28 | 27 |
29 namespace cricket { | 28 namespace cricket { |
30 | 29 |
31 ///////////////////////////////////////////////////////////////////////// | 30 ///////////////////////////////////////////////////////////////////////// |
32 // Implementation of RawRtpPacket | 31 // Implementation of RawRtpPacket |
33 ///////////////////////////////////////////////////////////////////////// | 32 ///////////////////////////////////////////////////////////////////////// |
34 void RawRtpPacket::WriteToByteBuffer(uint32_t in_ssrc, | 33 void RawRtpPacket::WriteToByteBuffer(uint32_t in_ssrc, |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 if (1 == frame_count_) { | 234 if (1 == frame_count_) { |
236 frame_fourcc_ = frame->fourcc; | 235 frame_fourcc_ = frame->fourcc; |
237 frame_width_ = frame->width; | 236 frame_width_ = frame->width; |
238 frame_height_ = frame->height; | 237 frame_height_ = frame->height; |
239 frame_size_ = frame->data_size; | 238 frame_size_ = frame->data_size; |
240 } else if (frame_width_ != frame->width || frame_height_ != frame->height) { | 239 } else if (frame_width_ != frame->width || frame_height_ != frame->height) { |
241 resolution_changed_ = true; | 240 resolution_changed_ = true; |
242 } | 241 } |
243 } | 242 } |
244 | 243 |
245 // Returns the absolute path to a file in the resources/ directory. | |
246 std::string GetTestFilePath(const std::string& filename) { | |
247 // Locate test data directory. | |
248 #ifdef ENABLE_WEBRTC | |
249 rtc::Pathname path = rtc::GetExecutablePath(); | |
250 EXPECT_FALSE(path.empty()); | |
251 path.AppendPathname("../../resources/"); | |
252 #else | |
253 rtc::Pathname path = testing::GetTalkDirectory(); | |
254 EXPECT_FALSE(path.empty()); // must be run from inside "talk" | |
255 #endif | |
256 path.AppendFolder("media/"); | |
257 path.SetFilename(filename); | |
258 return path.pathname(); | |
259 } | |
260 | |
261 // Loads the image with the specified prefix and size into |out|. | |
262 bool LoadPlanarYuvTestImage(const std::string& prefix, | |
263 int width, | |
264 int height, | |
265 uint8_t* out) { | |
266 std::stringstream ss; | |
267 ss << prefix << "." << width << "x" << height << "_P420.yuv"; | |
268 | |
269 std::unique_ptr<rtc::FileStream> stream( | |
270 rtc::Filesystem::OpenFile(rtc::Pathname( | |
271 GetTestFilePath(ss.str())), "rb")); | |
272 if (!stream) { | |
273 return false; | |
274 } | |
275 | |
276 rtc::StreamResult res = | |
277 stream->ReadAll(out, I420_SIZE(width, height), NULL, NULL); | |
278 return (res == rtc::SR_SUCCESS); | |
279 } | |
280 | |
281 // Dumps the YUV image out to a file, for visual inspection. | |
282 // PYUV tool can be used to view dump files. | |
283 void DumpPlanarYuvTestImage(const std::string& prefix, | |
284 const uint8_t* img, | |
285 int w, | |
286 int h) { | |
287 rtc::FileStream fs; | |
288 char filename[256]; | |
289 rtc::sprintfn(filename, sizeof(filename), "%s.%dx%d_P420.yuv", | |
290 prefix.c_str(), w, h); | |
291 fs.Open(filename, "wb", NULL); | |
292 fs.Write(img, I420_SIZE(w, h), NULL, NULL); | |
293 } | |
294 | |
295 // Dumps the ARGB image out to a file, for visual inspection. | |
296 // ffplay tool can be used to view dump files. | |
297 void DumpPlanarArgbTestImage(const std::string& prefix, | |
298 const uint8_t* img, | |
299 int w, | |
300 int h) { | |
301 rtc::FileStream fs; | |
302 char filename[256]; | |
303 rtc::sprintfn(filename, sizeof(filename), "%s.%dx%d_ARGB.raw", | |
304 prefix.c_str(), w, h); | |
305 fs.Open(filename, "wb", NULL); | |
306 fs.Write(img, ARGB_SIZE(w, h), NULL, NULL); | |
307 } | |
308 | |
309 cricket::StreamParams CreateSimStreamParams( | 244 cricket::StreamParams CreateSimStreamParams( |
310 const std::string& cname, | 245 const std::string& cname, |
311 const std::vector<uint32_t>& ssrcs) { | 246 const std::vector<uint32_t>& ssrcs) { |
312 cricket::StreamParams sp; | 247 cricket::StreamParams sp; |
313 cricket::SsrcGroup sg(cricket::kSimSsrcGroupSemantics, ssrcs); | 248 cricket::SsrcGroup sg(cricket::kSimSsrcGroupSemantics, ssrcs); |
314 sp.ssrcs = ssrcs; | 249 sp.ssrcs = ssrcs; |
315 sp.ssrc_groups.push_back(sg); | 250 sp.ssrc_groups.push_back(sg); |
316 sp.cname = cname; | 251 sp.cname = cname; |
317 return sp; | 252 return sp; |
318 } | 253 } |
319 | 254 |
320 // There should be an rtx_ssrc per ssrc. | 255 // There should be an rtx_ssrc per ssrc. |
321 cricket::StreamParams CreateSimWithRtxStreamParams( | 256 cricket::StreamParams CreateSimWithRtxStreamParams( |
322 const std::string& cname, | 257 const std::string& cname, |
323 const std::vector<uint32_t>& ssrcs, | 258 const std::vector<uint32_t>& ssrcs, |
324 const std::vector<uint32_t>& rtx_ssrcs) { | 259 const std::vector<uint32_t>& rtx_ssrcs) { |
325 cricket::StreamParams sp = CreateSimStreamParams(cname, ssrcs); | 260 cricket::StreamParams sp = CreateSimStreamParams(cname, ssrcs); |
326 for (size_t i = 0; i < ssrcs.size(); ++i) { | 261 for (size_t i = 0; i < ssrcs.size(); ++i) { |
327 sp.ssrcs.push_back(rtx_ssrcs[i]); | 262 sp.ssrcs.push_back(rtx_ssrcs[i]); |
328 std::vector<uint32_t> fid_ssrcs; | 263 std::vector<uint32_t> fid_ssrcs; |
329 fid_ssrcs.push_back(ssrcs[i]); | 264 fid_ssrcs.push_back(ssrcs[i]); |
330 fid_ssrcs.push_back(rtx_ssrcs[i]); | 265 fid_ssrcs.push_back(rtx_ssrcs[i]); |
331 cricket::SsrcGroup fid_group(cricket::kFidSsrcGroupSemantics, fid_ssrcs); | 266 cricket::SsrcGroup fid_group(cricket::kFidSsrcGroupSemantics, fid_ssrcs); |
332 sp.ssrc_groups.push_back(fid_group); | 267 sp.ssrc_groups.push_back(fid_group); |
333 } | 268 } |
334 return sp; | 269 return sp; |
335 } | 270 } |
336 | 271 |
337 } // namespace cricket | 272 } // namespace cricket |
OLD | NEW |