Home | History | Annotate | Download | only in test
      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_MAIN_TEST_CHANNEL_H_
     12 #define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_CHANNEL_H_
     13 
     14 #include <stdio.h>
     15 
     16 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
     17 #include "webrtc/modules/interface/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   int16_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   int16_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   virtual int32_t SendData(
     54       const FrameType frameType, const uint8_t payloadType,
     55       const uint32_t timeStamp, const uint8_t* payloadData,
     56       const uint16_t payloadSize,
     57       const RTPFragmentationHeader* fragmentation) OVERRIDE;
     58 
     59   void RegisterReceiverACM(AudioCodingModule *acm);
     60 
     61   void ResetStats();
     62 
     63   int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats);
     64 
     65   void Stats(uint32_t* numPackets);
     66 
     67   void Stats(uint8_t* payloadLenByte, uint32_t* payloadType);
     68 
     69   void PrintStats(CodecInst& codecInst);
     70 
     71   void SetIsStereo(bool isStereo) {
     72     _isStereo = isStereo;
     73   }
     74 
     75   uint32_t LastInTimestamp();
     76 
     77   void SetFECTestWithPacketLoss(bool usePacketLoss) {
     78     _useFECTestWithPacketLoss = usePacketLoss;
     79   }
     80 
     81   double BitRate();
     82 
     83   void set_send_timestamp(uint32_t new_send_ts) {
     84     external_send_timestamp_ = new_send_ts;
     85   }
     86 
     87   void set_sequence_number(uint16_t new_sequence_number) {
     88     external_sequence_number_ = new_sequence_number;
     89   }
     90 
     91   void set_num_packets_to_drop(int new_num_packets_to_drop) {
     92     num_packets_to_drop_ = new_num_packets_to_drop;
     93   }
     94 
     95  private:
     96   void CalcStatistics(WebRtcRTPHeader& rtpInfo, uint16_t payloadSize);
     97 
     98   AudioCodingModule* _receiverACM;
     99   uint16_t _seqNo;
    100   // 60msec * 32 sample(max)/msec * 2 description (maybe) * 2 bytes/sample
    101   uint8_t _payloadData[60 * 32 * 2 * 2];
    102 
    103   CriticalSectionWrapper* _channelCritSect;
    104   FILE* _bitStreamFile;
    105   bool _saveBitStream;
    106   int16_t _lastPayloadType;
    107   ACMTestPayloadStats _payloadStats[MAX_NUM_PAYLOADS];
    108   bool _isStereo;
    109   WebRtcRTPHeader _rtpInfo;
    110   bool _leftChannel;
    111   uint32_t _lastInTimestamp;
    112   // FEC Test variables
    113   int16_t _packetLoss;
    114   bool _useFECTestWithPacketLoss;
    115   uint64_t _beginTime;
    116   uint64_t _totalBytes;
    117 
    118   // External timing info, defaulted to -1. Only used if they are
    119   // non-negative.
    120   int64_t external_send_timestamp_;
    121   int32_t external_sequence_number_;
    122   int num_packets_to_drop_;
    123 };
    124 
    125 }  // namespace webrtc
    126 
    127 #endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_CHANNEL_H_
    128