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