• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_TEST_CHANNEL_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_TEST_CHANNEL_H_
13 
14 #include <stdio.h>
15 
16 #include "webrtc/modules/audio_coding/include/audio_coding_module.h"
17 #include "webrtc/modules/include/module_common_types.h"
18 #include "webrtc/typedefs.h"
19 
20 namespace webrtc {
21 
22 class CriticalSectionWrapper;
23 
24 #define MAX_NUM_PAYLOADS   50
25 #define MAX_NUM_FRAMESIZES  6
26 
27 // TODO(turajs): Write constructor for this structure.
28 struct ACMTestFrameSizeStats {
29   uint16_t frameSizeSample;
30   size_t maxPayloadLen;
31   uint32_t numPackets;
32   uint64_t totalPayloadLenByte;
33   uint64_t totalEncodedSamples;
34   double rateBitPerSec;
35   double usageLenSec;
36 };
37 
38 // TODO(turajs): Write constructor for this structure.
39 struct ACMTestPayloadStats {
40   bool newPacket;
41   int16_t payloadType;
42   size_t lastPayloadLenByte;
43   uint32_t lastTimestamp;
44   ACMTestFrameSizeStats frameSizeStats[MAX_NUM_FRAMESIZES];
45 };
46 
47 class Channel : public AudioPacketizationCallback {
48  public:
49 
50   Channel(int16_t chID = -1);
51   ~Channel();
52 
53   int32_t SendData(FrameType frameType,
54                    uint8_t payloadType,
55                    uint32_t timeStamp,
56                    const uint8_t* payloadData,
57                    size_t payloadSize,
58                    const RTPFragmentationHeader* fragmentation) override;
59 
60   void RegisterReceiverACM(AudioCodingModule *acm);
61 
62   void ResetStats();
63 
64   int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats);
65 
66   void Stats(uint32_t* numPackets);
67 
68   void Stats(uint8_t* payloadType, uint32_t* payloadLenByte);
69 
70   void PrintStats(CodecInst& codecInst);
71 
SetIsStereo(bool isStereo)72   void SetIsStereo(bool isStereo) {
73     _isStereo = isStereo;
74   }
75 
76   uint32_t LastInTimestamp();
77 
SetFECTestWithPacketLoss(bool usePacketLoss)78   void SetFECTestWithPacketLoss(bool usePacketLoss) {
79     _useFECTestWithPacketLoss = usePacketLoss;
80   }
81 
82   double BitRate();
83 
set_send_timestamp(uint32_t new_send_ts)84   void set_send_timestamp(uint32_t new_send_ts) {
85     external_send_timestamp_ = new_send_ts;
86   }
87 
set_sequence_number(uint16_t new_sequence_number)88   void set_sequence_number(uint16_t new_sequence_number) {
89     external_sequence_number_ = new_sequence_number;
90   }
91 
set_num_packets_to_drop(int new_num_packets_to_drop)92   void set_num_packets_to_drop(int new_num_packets_to_drop) {
93     num_packets_to_drop_ = new_num_packets_to_drop;
94   }
95 
96  private:
97   void CalcStatistics(WebRtcRTPHeader& rtpInfo, size_t payloadSize);
98 
99   AudioCodingModule* _receiverACM;
100   uint16_t _seqNo;
101   // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
102   uint8_t _payloadData[60 * 32 * 2 * 2];
103 
104   CriticalSectionWrapper* _channelCritSect;
105   FILE* _bitStreamFile;
106   bool _saveBitStream;
107   int16_t _lastPayloadType;
108   ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
109   bool _isStereo;
110   WebRtcRTPHeader _rtpInfo;
111   bool _leftChannel;
112   uint32_t _lastInTimestamp;
113   bool _useLastFrameSize;
114   uint32_t _lastFrameSizeSample;
115   // FEC Test variables
116   int16_t _packetLoss;
117   bool _useFECTestWithPacketLoss;
118   uint64_t _beginTime;
119   uint64_t _totalBytes;
120 
121   // External timing info, defaulted to -1. Only used if they are
122   // non-negative.
123   int64_t external_send_timestamp_;
124   int32_t external_sequence_number_;
125   int num_packets_to_drop_;
126 };
127 
128 }  // namespace webrtc
129 
130 #endif  // WEBRTC_MODULES_AUDIO_CODING_TEST_CHANNEL_H_
131