Home | History | Annotate | Download | only in acm2
      1 /*
      2  *  Copyright (c) 2014 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_ACM2_ACM_SEND_TEST_H_
     12 #define WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_ACM_SEND_TEST_H_
     13 
     14 #include <vector>
     15 
     16 #include "webrtc/base/constructormagic.h"
     17 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
     18 #include "webrtc/modules/audio_coding/neteq/tools/packet_source.h"
     19 #include "webrtc/system_wrappers/interface/clock.h"
     20 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
     21 
     22 namespace webrtc {
     23 
     24 namespace test {
     25 class InputAudioFile;
     26 class Packet;
     27 
     28 class AcmSendTestOldApi : public AudioPacketizationCallback,
     29                           public PacketSource {
     30  public:
     31   AcmSendTestOldApi(InputAudioFile* audio_source,
     32                     int source_rate_hz,
     33                     int test_duration_ms);
     34   virtual ~AcmSendTestOldApi() {}
     35 
     36   // Registers the send codec. Returns true on success, false otherwise.
     37   bool RegisterCodec(const char* payload_name,
     38                      int sampling_freq_hz,
     39                      int channels,
     40                      int payload_type,
     41                      int frame_size_samples);
     42 
     43   // Returns the next encoded packet. Returns NULL if the test duration was
     44   // exceeded. Ownership of the packet is handed over to the caller.
     45   // Inherited from PacketSource.
     46   Packet* NextPacket();
     47 
     48   // Inherited from AudioPacketizationCallback.
     49   virtual int32_t SendData(
     50       FrameType frame_type,
     51       uint8_t payload_type,
     52       uint32_t timestamp,
     53       const uint8_t* payload_data,
     54       uint16_t payload_len_bytes,
     55       const RTPFragmentationHeader* fragmentation) OVERRIDE;
     56 
     57  private:
     58   static const int kBlockSizeMs = 10;
     59 
     60   // Creates a Packet object from the last packet produced by ACM (and received
     61   // through the SendData method as a callback). Ownership of the new Packet
     62   // object is transferred to the caller.
     63   Packet* CreatePacket();
     64 
     65   SimulatedClock clock_;
     66   scoped_ptr<AudioCodingModule> acm_;
     67   InputAudioFile* audio_source_;
     68   int source_rate_hz_;
     69   const int input_block_size_samples_;
     70   AudioFrame input_frame_;
     71   CodecInst codec_;
     72   bool codec_registered_;
     73   int test_duration_ms_;
     74   // The following member variables are set whenever SendData() is called.
     75   FrameType frame_type_;
     76   int payload_type_;
     77   uint32_t timestamp_;
     78   uint16_t sequence_number_;
     79   std::vector<uint8_t> last_payload_vec_;
     80 
     81   DISALLOW_COPY_AND_ASSIGN(AcmSendTestOldApi);
     82 };
     83 
     84 }  // namespace test
     85 }  // namespace webrtc
     86 #endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_ACM_SEND_TEST_H_
     87