Channel.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2012 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. #ifndef MODULES_AUDIO_CODING_TEST_CHANNEL_H_
  11. #define MODULES_AUDIO_CODING_TEST_CHANNEL_H_
  12. #include <stdio.h>
  13. #include "modules/audio_coding/include/audio_coding_module.h"
  14. #include "modules/include/module_common_types.h"
  15. #include "rtc_base/synchronization/mutex.h"
  16. namespace webrtc {
  17. #define MAX_NUM_PAYLOADS 50
  18. #define MAX_NUM_FRAMESIZES 6
  19. // TODO(turajs): Write constructor for this structure.
  20. struct ACMTestFrameSizeStats {
  21. uint16_t frameSizeSample;
  22. size_t maxPayloadLen;
  23. uint32_t numPackets;
  24. uint64_t totalPayloadLenByte;
  25. uint64_t totalEncodedSamples;
  26. double rateBitPerSec;
  27. double usageLenSec;
  28. };
  29. // TODO(turajs): Write constructor for this structure.
  30. struct ACMTestPayloadStats {
  31. bool newPacket;
  32. int16_t payloadType;
  33. size_t lastPayloadLenByte;
  34. uint32_t lastTimestamp;
  35. ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
  36. };
  37. class Channel : public AudioPacketizationCallback {
  38. public:
  39. Channel(int16_t chID = -1);
  40. ~Channel() override;
  41. int32_t SendData(AudioFrameType frameType,
  42. uint8_t payloadType,
  43. uint32_t timeStamp,
  44. const uint8_t* payloadData,
  45. size_t payloadSize,
  46. int64_t absolute_capture_timestamp_ms) override;
  47. void RegisterReceiverACM(AudioCodingModule* acm);
  48. void ResetStats();
  49. void SetIsStereo(bool isStereo) { _isStereo = isStereo; }
  50. uint32_t LastInTimestamp();
  51. void SetFECTestWithPacketLoss(bool usePacketLoss) {
  52. _useFECTestWithPacketLoss = usePacketLoss;
  53. }
  54. double BitRate();
  55. void set_send_timestamp(uint32_t new_send_ts) {
  56. external_send_timestamp_ = new_send_ts;
  57. }
  58. void set_sequence_number(uint16_t new_sequence_number) {
  59. external_sequence_number_ = new_sequence_number;
  60. }
  61. void set_num_packets_to_drop(int new_num_packets_to_drop) {
  62. num_packets_to_drop_ = new_num_packets_to_drop;
  63. }
  64. private:
  65. void CalcStatistics(const RTPHeader& rtp_header, size_t payloadSize);
  66. AudioCodingModule* _receiverACM;
  67. uint16_t _seqNo;
  68. // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
  69. uint8_t _payloadData[60 * 32 * 2 * 2];
  70. Mutex _channelCritSect;
  71. FILE* _bitStreamFile;
  72. bool _saveBitStream;
  73. int16_t _lastPayloadType;
  74. ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
  75. bool _isStereo;
  76. RTPHeader _rtp_header;
  77. bool _leftChannel;
  78. uint32_t _lastInTimestamp;
  79. bool _useLastFrameSize;
  80. uint32_t _lastFrameSizeSample;
  81. // FEC Test variables
  82. int16_t _packetLoss;
  83. bool _useFECTestWithPacketLoss;
  84. uint64_t _beginTime;
  85. uint64_t _totalBytes;
  86. // External timing info, defaulted to -1. Only used if they are
  87. // non-negative.
  88. int64_t external_send_timestamp_;
  89. int32_t external_sequence_number_;
  90. int num_packets_to_drop_;
  91. };
  92. } // namespace webrtc
  93. #endif // MODULES_AUDIO_CODING_TEST_CHANNEL_H_