OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/modules/audio_coding/test/Channel.h" | 11 #include "webrtc/modules/audio_coding/test/Channel.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <iostream> | 14 #include <iostream> |
15 | 15 |
16 #include "webrtc/base/format_macros.h" | 16 #include "webrtc/base/format_macros.h" |
17 #include "webrtc/system_wrappers/include/tick_util.h" | 17 #include "webrtc/system_wrappers/include/tick_util.h" |
18 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
19 | 18 |
20 namespace webrtc { | 19 namespace webrtc { |
21 | 20 |
22 int32_t Channel::SendData(FrameType frameType, | 21 int32_t Channel::SendData(FrameType frameType, |
23 uint8_t payloadType, | 22 uint8_t payloadType, |
24 uint32_t timeStamp, | 23 uint32_t timeStamp, |
25 const uint8_t* payloadData, | 24 const uint8_t* payloadData, |
26 size_t payloadSize, | 25 size_t payloadSize, |
27 const RTPFragmentationHeader* fragmentation) { | 26 const RTPFragmentationHeader* fragmentation) { |
28 WebRtcRTPHeader rtpInfo; | 27 WebRtcRTPHeader rtpInfo; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 _leftChannel = false; | 87 _leftChannel = false; |
89 rtpInfo.type.Audio.channel = 1; | 88 rtpInfo.type.Audio.channel = 1; |
90 } else { | 89 } else { |
91 memcpy(&rtpInfo, &_rtpInfo, sizeof(WebRtcRTPHeader)); | 90 memcpy(&rtpInfo, &_rtpInfo, sizeof(WebRtcRTPHeader)); |
92 _leftChannel = true; | 91 _leftChannel = true; |
93 rtpInfo.type.Audio.channel = 2; | 92 rtpInfo.type.Audio.channel = 2; |
94 } | 93 } |
95 } | 94 } |
96 } | 95 } |
97 | 96 |
98 _channelCritSect->Enter(); | 97 _channelCritSect.Enter(); |
99 if (_saveBitStream) { | 98 if (_saveBitStream) { |
100 //fwrite(payloadData, sizeof(uint8_t), payloadSize, _bitStreamFile); | 99 //fwrite(payloadData, sizeof(uint8_t), payloadSize, _bitStreamFile); |
101 } | 100 } |
102 | 101 |
103 if (!_isStereo) { | 102 if (!_isStereo) { |
104 CalcStatistics(rtpInfo, payloadSize); | 103 CalcStatistics(rtpInfo, payloadSize); |
105 } | 104 } |
106 _useLastFrameSize = false; | 105 _useLastFrameSize = false; |
107 _lastInTimestamp = timeStamp; | 106 _lastInTimestamp = timeStamp; |
108 _totalBytes += payloadDataSize; | 107 _totalBytes += payloadDataSize; |
109 _channelCritSect->Leave(); | 108 _channelCritSect.Leave(); |
110 | 109 |
111 if (_useFECTestWithPacketLoss) { | 110 if (_useFECTestWithPacketLoss) { |
112 _packetLoss += 1; | 111 _packetLoss += 1; |
113 if (_packetLoss == 3) { | 112 if (_packetLoss == 3) { |
114 _packetLoss = 0; | 113 _packetLoss = 0; |
115 return 0; | 114 return 0; |
116 } | 115 } |
117 } | 116 } |
118 | 117 |
119 if (num_packets_to_drop_ > 0) { | 118 if (num_packets_to_drop_ > 0) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 _payloadStats[n].lastTimestamp = rtpInfo.header.timestamp; | 217 _payloadStats[n].lastTimestamp = rtpInfo.header.timestamp; |
219 _payloadStats[n].payloadType = rtpInfo.header.payloadType; | 218 _payloadStats[n].payloadType = rtpInfo.header.payloadType; |
220 memset(_payloadStats[n].frameSizeStats, 0, MAX_NUM_FRAMESIZES * | 219 memset(_payloadStats[n].frameSizeStats, 0, MAX_NUM_FRAMESIZES * |
221 sizeof(ACMTestFrameSizeStats)); | 220 sizeof(ACMTestFrameSizeStats)); |
222 } | 221 } |
223 } | 222 } |
224 | 223 |
225 Channel::Channel(int16_t chID) | 224 Channel::Channel(int16_t chID) |
226 : _receiverACM(NULL), | 225 : _receiverACM(NULL), |
227 _seqNo(0), | 226 _seqNo(0), |
228 _channelCritSect(CriticalSectionWrapper::CreateCriticalSection()), | |
229 _bitStreamFile(NULL), | 227 _bitStreamFile(NULL), |
230 _saveBitStream(false), | 228 _saveBitStream(false), |
231 _lastPayloadType(-1), | 229 _lastPayloadType(-1), |
232 _isStereo(false), | 230 _isStereo(false), |
233 _leftChannel(true), | 231 _leftChannel(true), |
234 _lastInTimestamp(0), | 232 _lastInTimestamp(0), |
235 _useLastFrameSize(false), | 233 _useLastFrameSize(false), |
236 _lastFrameSizeSample(0), | 234 _lastFrameSizeSample(0), |
237 _packetLoss(0), | 235 _packetLoss(0), |
238 _useFECTestWithPacketLoss(false), | 236 _useFECTestWithPacketLoss(false), |
(...skipping 19 matching lines...) Expand all Loading... |
258 _saveBitStream = true; | 256 _saveBitStream = true; |
259 char bitStreamFileName[500]; | 257 char bitStreamFileName[500]; |
260 sprintf(bitStreamFileName, "bitStream_%d.dat", chID); | 258 sprintf(bitStreamFileName, "bitStream_%d.dat", chID); |
261 _bitStreamFile = fopen(bitStreamFileName, "wb"); | 259 _bitStreamFile = fopen(bitStreamFileName, "wb"); |
262 } else { | 260 } else { |
263 _saveBitStream = false; | 261 _saveBitStream = false; |
264 } | 262 } |
265 } | 263 } |
266 | 264 |
267 Channel::~Channel() { | 265 Channel::~Channel() { |
268 delete _channelCritSect; | |
269 } | 266 } |
270 | 267 |
271 void Channel::RegisterReceiverACM(AudioCodingModule* acm) { | 268 void Channel::RegisterReceiverACM(AudioCodingModule* acm) { |
272 _receiverACM = acm; | 269 _receiverACM = acm; |
273 return; | 270 return; |
274 } | 271 } |
275 | 272 |
276 void Channel::ResetStats() { | 273 void Channel::ResetStats() { |
277 int n; | 274 int n; |
278 int k; | 275 int k; |
279 _channelCritSect->Enter(); | 276 _channelCritSect.Enter(); |
280 _lastPayloadType = -1; | 277 _lastPayloadType = -1; |
281 for (n = 0; n < MAX_NUM_PAYLOADS; n++) { | 278 for (n = 0; n < MAX_NUM_PAYLOADS; n++) { |
282 _payloadStats[n].payloadType = -1; | 279 _payloadStats[n].payloadType = -1; |
283 _payloadStats[n].newPacket = true; | 280 _payloadStats[n].newPacket = true; |
284 for (k = 0; k < MAX_NUM_FRAMESIZES; k++) { | 281 for (k = 0; k < MAX_NUM_FRAMESIZES; k++) { |
285 _payloadStats[n].frameSizeStats[k].frameSizeSample = 0; | 282 _payloadStats[n].frameSizeStats[k].frameSizeSample = 0; |
286 _payloadStats[n].frameSizeStats[k].maxPayloadLen = 0; | 283 _payloadStats[n].frameSizeStats[k].maxPayloadLen = 0; |
287 _payloadStats[n].frameSizeStats[k].numPackets = 0; | 284 _payloadStats[n].frameSizeStats[k].numPackets = 0; |
288 _payloadStats[n].frameSizeStats[k].totalPayloadLenByte = 0; | 285 _payloadStats[n].frameSizeStats[k].totalPayloadLenByte = 0; |
289 _payloadStats[n].frameSizeStats[k].totalEncodedSamples = 0; | 286 _payloadStats[n].frameSizeStats[k].totalEncodedSamples = 0; |
290 } | 287 } |
291 } | 288 } |
292 _beginTime = TickTime::MillisecondTimestamp(); | 289 _beginTime = TickTime::MillisecondTimestamp(); |
293 _totalBytes = 0; | 290 _totalBytes = 0; |
294 _channelCritSect->Leave(); | 291 _channelCritSect.Leave(); |
295 } | 292 } |
296 | 293 |
297 int16_t Channel::Stats(CodecInst& codecInst, | 294 int16_t Channel::Stats(CodecInst& codecInst, |
298 ACMTestPayloadStats& payloadStats) { | 295 ACMTestPayloadStats& payloadStats) { |
299 _channelCritSect->Enter(); | 296 _channelCritSect.Enter(); |
300 int n; | 297 int n; |
301 payloadStats.payloadType = -1; | 298 payloadStats.payloadType = -1; |
302 for (n = 0; n < MAX_NUM_PAYLOADS; n++) { | 299 for (n = 0; n < MAX_NUM_PAYLOADS; n++) { |
303 if (_payloadStats[n].payloadType == codecInst.pltype) { | 300 if (_payloadStats[n].payloadType == codecInst.pltype) { |
304 memcpy(&payloadStats, &_payloadStats[n], sizeof(ACMTestPayloadStats)); | 301 memcpy(&payloadStats, &_payloadStats[n], sizeof(ACMTestPayloadStats)); |
305 break; | 302 break; |
306 } | 303 } |
307 } | 304 } |
308 if (payloadStats.payloadType == -1) { | 305 if (payloadStats.payloadType == -1) { |
309 _channelCritSect->Leave(); | 306 _channelCritSect.Leave(); |
310 return -1; | 307 return -1; |
311 } | 308 } |
312 for (n = 0; n < MAX_NUM_FRAMESIZES; n++) { | 309 for (n = 0; n < MAX_NUM_FRAMESIZES; n++) { |
313 if (payloadStats.frameSizeStats[n].frameSizeSample == 0) { | 310 if (payloadStats.frameSizeStats[n].frameSizeSample == 0) { |
314 _channelCritSect->Leave(); | 311 _channelCritSect.Leave(); |
315 return 0; | 312 return 0; |
316 } | 313 } |
317 payloadStats.frameSizeStats[n].usageLenSec = (double) payloadStats | 314 payloadStats.frameSizeStats[n].usageLenSec = (double) payloadStats |
318 .frameSizeStats[n].totalEncodedSamples / (double) codecInst.plfreq; | 315 .frameSizeStats[n].totalEncodedSamples / (double) codecInst.plfreq; |
319 | 316 |
320 payloadStats.frameSizeStats[n].rateBitPerSec = | 317 payloadStats.frameSizeStats[n].rateBitPerSec = |
321 payloadStats.frameSizeStats[n].totalPayloadLenByte * 8 | 318 payloadStats.frameSizeStats[n].totalPayloadLenByte * 8 |
322 / payloadStats.frameSizeStats[n].usageLenSec; | 319 / payloadStats.frameSizeStats[n].usageLenSec; |
323 | 320 |
324 } | 321 } |
325 _channelCritSect->Leave(); | 322 _channelCritSect.Leave(); |
326 return 0; | 323 return 0; |
327 } | 324 } |
328 | 325 |
329 void Channel::Stats(uint32_t* numPackets) { | 326 void Channel::Stats(uint32_t* numPackets) { |
330 _channelCritSect->Enter(); | 327 _channelCritSect.Enter(); |
331 int k; | 328 int k; |
332 int n; | 329 int n; |
333 memset(numPackets, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t)); | 330 memset(numPackets, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t)); |
334 for (k = 0; k < MAX_NUM_PAYLOADS; k++) { | 331 for (k = 0; k < MAX_NUM_PAYLOADS; k++) { |
335 if (_payloadStats[k].payloadType == -1) { | 332 if (_payloadStats[k].payloadType == -1) { |
336 break; | 333 break; |
337 } | 334 } |
338 numPackets[k] = 0; | 335 numPackets[k] = 0; |
339 for (n = 0; n < MAX_NUM_FRAMESIZES; n++) { | 336 for (n = 0; n < MAX_NUM_FRAMESIZES; n++) { |
340 if (_payloadStats[k].frameSizeStats[n].frameSizeSample == 0) { | 337 if (_payloadStats[k].frameSizeStats[n].frameSizeSample == 0) { |
341 break; | 338 break; |
342 } | 339 } |
343 numPackets[k] += _payloadStats[k].frameSizeStats[n].numPackets; | 340 numPackets[k] += _payloadStats[k].frameSizeStats[n].numPackets; |
344 } | 341 } |
345 } | 342 } |
346 _channelCritSect->Leave(); | 343 _channelCritSect.Leave(); |
347 } | 344 } |
348 | 345 |
349 void Channel::Stats(uint8_t* payloadType, uint32_t* payloadLenByte) { | 346 void Channel::Stats(uint8_t* payloadType, uint32_t* payloadLenByte) { |
350 _channelCritSect->Enter(); | 347 _channelCritSect.Enter(); |
351 | 348 |
352 int k; | 349 int k; |
353 int n; | 350 int n; |
354 memset(payloadLenByte, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t)); | 351 memset(payloadLenByte, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t)); |
355 for (k = 0; k < MAX_NUM_PAYLOADS; k++) { | 352 for (k = 0; k < MAX_NUM_PAYLOADS; k++) { |
356 if (_payloadStats[k].payloadType == -1) { | 353 if (_payloadStats[k].payloadType == -1) { |
357 break; | 354 break; |
358 } | 355 } |
359 payloadType[k] = (uint8_t) _payloadStats[k].payloadType; | 356 payloadType[k] = (uint8_t) _payloadStats[k].payloadType; |
360 payloadLenByte[k] = 0; | 357 payloadLenByte[k] = 0; |
361 for (n = 0; n < MAX_NUM_FRAMESIZES; n++) { | 358 for (n = 0; n < MAX_NUM_FRAMESIZES; n++) { |
362 if (_payloadStats[k].frameSizeStats[n].frameSizeSample == 0) { | 359 if (_payloadStats[k].frameSizeStats[n].frameSizeSample == 0) { |
363 break; | 360 break; |
364 } | 361 } |
365 payloadLenByte[k] += (uint16_t) _payloadStats[k].frameSizeStats[n] | 362 payloadLenByte[k] += (uint16_t) _payloadStats[k].frameSizeStats[n] |
366 .totalPayloadLenByte; | 363 .totalPayloadLenByte; |
367 } | 364 } |
368 } | 365 } |
369 | 366 |
370 _channelCritSect->Leave(); | 367 _channelCritSect.Leave(); |
371 } | 368 } |
372 | 369 |
373 void Channel::PrintStats(CodecInst& codecInst) { | 370 void Channel::PrintStats(CodecInst& codecInst) { |
374 ACMTestPayloadStats payloadStats; | 371 ACMTestPayloadStats payloadStats; |
375 Stats(codecInst, payloadStats); | 372 Stats(codecInst, payloadStats); |
376 printf("%s %d kHz\n", codecInst.plname, codecInst.plfreq / 1000); | 373 printf("%s %d kHz\n", codecInst.plname, codecInst.plfreq / 1000); |
377 printf("=====================================================\n"); | 374 printf("=====================================================\n"); |
378 if (payloadStats.payloadType == -1) { | 375 if (payloadStats.payloadType == -1) { |
379 printf("No Packets are sent with payload-type %d (%s)\n\n", | 376 printf("No Packets are sent with payload-type %d (%s)\n\n", |
380 codecInst.pltype, codecInst.plname); | 377 codecInst.pltype, codecInst.plname); |
(...skipping 18 matching lines...) Expand all Loading... |
399 (unsigned int) payloadStats.frameSizeStats[k].numPackets); | 396 (unsigned int) payloadStats.frameSizeStats[k].numPackets); |
400 printf("Duration...................... %0.3f sec\n\n", | 397 printf("Duration...................... %0.3f sec\n\n", |
401 payloadStats.frameSizeStats[k].usageLenSec); | 398 payloadStats.frameSizeStats[k].usageLenSec); |
402 | 399 |
403 } | 400 } |
404 | 401 |
405 } | 402 } |
406 | 403 |
407 uint32_t Channel::LastInTimestamp() { | 404 uint32_t Channel::LastInTimestamp() { |
408 uint32_t timestamp; | 405 uint32_t timestamp; |
409 _channelCritSect->Enter(); | 406 _channelCritSect.Enter(); |
410 timestamp = _lastInTimestamp; | 407 timestamp = _lastInTimestamp; |
411 _channelCritSect->Leave(); | 408 _channelCritSect.Leave(); |
412 return timestamp; | 409 return timestamp; |
413 } | 410 } |
414 | 411 |
415 double Channel::BitRate() { | 412 double Channel::BitRate() { |
416 double rate; | 413 double rate; |
417 uint64_t currTime = TickTime::MillisecondTimestamp(); | 414 uint64_t currTime = TickTime::MillisecondTimestamp(); |
418 _channelCritSect->Enter(); | 415 _channelCritSect.Enter(); |
419 rate = ((double) _totalBytes * 8.0) / (double) (currTime - _beginTime); | 416 rate = ((double) _totalBytes * 8.0) / (double) (currTime - _beginTime); |
420 _channelCritSect->Leave(); | 417 _channelCritSect.Leave(); |
421 return rate; | 418 return rate; |
422 } | 419 } |
423 | 420 |
424 } // namespace webrtc | 421 } // namespace webrtc |
OLD | NEW |