blob: 4d72dd6870f8e22b7d9c2f8e06581887cd0c080f [file] [log] [blame]
phoglund@webrtc.orgeb7b0c42013-08-21 12:06:03 +00001/*
2 * Copyright (c) 2013 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#include "webrtc/video_engine/test/common/generate_ssrcs.h"
12
13#include <assert.h>
14#include <stdlib.h>
15
16#include "webrtc/video_engine/new_include/video_send_stream.h"
17
18namespace webrtc {
19namespace test {
20
pbos@webrtc.orgc1797062013-08-23 09:19:30 +000021void GenerateRandomSsrcs(VideoSendStream::Config* config,
phoglund@webrtc.orgeb7b0c42013-08-21 12:06:03 +000022 std::map<uint32_t, bool>* reserved_ssrcs) {
23 size_t num_ssrcs = config->codec.numberOfSimulcastStreams;
24 std::vector<uint32_t>* ssrcs = &config->rtp.ssrcs;
25 assert(ssrcs->size() == 0);
26
27 if (num_ssrcs == 0) {
28 num_ssrcs = 1;
29 }
30
31 while (ssrcs->size() < num_ssrcs) {
32 uint32_t rand_ssrc = static_cast<uint32_t>(rand() + 1); // NOLINT
33
34 // Make sure the ssrc is unique per-call
35 while (true) {
36 if (!(*reserved_ssrcs)[rand_ssrc]) {
37 (*reserved_ssrcs)[rand_ssrc] = true;
38 break;
39 }
40 ++rand_ssrc;
41 }
42
43 ssrcs->push_back(rand_ssrc);
44 }
45}
46
47} // namespace test
48} // namespace webrtc