phoglund@webrtc.org | eb7b0c4 | 2013-08-21 12:06:03 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | namespace webrtc { |
| 19 | namespace test { |
| 20 | |
pbos@webrtc.org | c179706 | 2013-08-23 09:19:30 +0000 | [diff] [blame^] | 21 | void GenerateRandomSsrcs(VideoSendStream::Config* config, |
phoglund@webrtc.org | eb7b0c4 | 2013-08-21 12:06:03 +0000 | [diff] [blame] | 22 | 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 |