tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

EncodeDecodeTest.h (3241B)


      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 MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_
     12 #define MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_
     13 
     14 #include <stdio.h>
     15 #include <string.h>
     16 
     17 #include <cstdint>
     18 
     19 #include "absl/strings/string_view.h"
     20 #include "api/audio_codecs/audio_format.h"
     21 #include "api/environment/environment.h"
     22 #include "api/neteq/neteq.h"
     23 #include "modules/audio_coding/acm2/acm_resampler.h"
     24 #include "modules/audio_coding/include/audio_coding_module.h"
     25 #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
     26 #include "modules/audio_coding/test/PCMFile.h"
     27 #include "modules/audio_coding/test/RTPFile.h"
     28 
     29 namespace webrtc {
     30 
     31 #define MAX_INCOMING_PAYLOAD 8096
     32 
     33 // TestPacketization callback which writes the encoded payloads to file
     34 class TestPacketization : public AudioPacketizationCallback {
     35 public:
     36  TestPacketization(RTPStream* rtpStream, uint16_t frequency);
     37  ~TestPacketization();
     38  int32_t SendData(AudioFrameType frameType,
     39                   uint8_t payloadType,
     40                   uint32_t timeStamp,
     41                   const uint8_t* payloadData,
     42                   size_t payloadSize,
     43                   int64_t absolute_capture_timestamp_ms) override;
     44 
     45 private:
     46  static void MakeRTPheader(uint8_t* rtpHeader,
     47                            uint8_t payloadType,
     48                            int16_t seqNo,
     49                            uint32_t timeStamp,
     50                            uint32_t ssrc);
     51  RTPStream* _rtpStream;
     52  int32_t _frequency;
     53  int16_t _seqNo;
     54 };
     55 
     56 class Sender {
     57 public:
     58  Sender();
     59  void Setup(const Environment& env,
     60             AudioCodingModule* acm,
     61             RTPStream* rtpStream,
     62             absl::string_view in_file_name,
     63             int in_sample_rate,
     64             int payload_type,
     65             SdpAudioFormat format);
     66  void Teardown();
     67  void Run();
     68  bool Add10MsData();
     69 
     70 protected:
     71  AudioCodingModule* _acm;
     72 
     73 private:
     74  PCMFile _pcmFile;
     75  AudioFrame _audioFrame;
     76  TestPacketization* _packetization;
     77 };
     78 
     79 class Receiver {
     80 public:
     81  Receiver();
     82  virtual ~Receiver() {}
     83  void Setup(NetEq* neteq,
     84             RTPStream* rtpStream,
     85             absl::string_view out_file_name,
     86             size_t channels,
     87             int file_num);
     88  void Teardown();
     89  void Run();
     90  virtual bool IncomingPacket();
     91  bool PlayoutData();
     92 
     93 private:
     94  PCMFile _pcmFile;
     95  int16_t* _playoutBuffer;
     96  uint16_t _playoutLengthSmpls;
     97  int32_t _frequency;
     98  bool _firstTime;
     99 
    100 protected:
    101  NetEq* _neteq;
    102  acm2::ResamplerHelper _resampler_helper;
    103  uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
    104  RTPStream* _rtpStream;
    105  RTPHeader _rtpHeader;
    106  size_t _realPayloadSizeBytes;
    107  size_t _payloadSizeBytes;
    108  uint32_t _nextTime;
    109 };
    110 
    111 class EncodeDecodeTest {
    112 public:
    113  EncodeDecodeTest();
    114  void Perform();
    115 };
    116 
    117 }  // namespace webrtc
    118 
    119 #endif  // MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_