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_TEST_PCMFILE_H_
     12 #define WEBRTC_MODULES_AUDIO_CODING_TEST_PCMFILE_H_
     13 
     14 #include <stdio.h>
     15 #include <stdlib.h>
     16 
     17 #include <string>
     18 
     19 #include "webrtc/base/optional.h"
     20 #include "webrtc/modules/include/module_common_types.h"
     21 #include "webrtc/typedefs.h"
     22 
     23 namespace webrtc {
     24 
     25 class PCMFile {
     26  public:
     27   PCMFile();
     28   PCMFile(uint32_t timestamp);
     29   ~PCMFile() {
     30     if (pcm_file_ != NULL) {
     31       fclose(pcm_file_);
     32     }
     33   }
     34 
     35   void Open(const std::string& filename, uint16_t frequency, const char* mode,
     36             bool auto_rewind = false);
     37 
     38   int32_t Read10MsData(AudioFrame& audio_frame);
     39 
     40   void Write10MsData(int16_t *playout_buffer, size_t length_smpls);
     41   void Write10MsData(AudioFrame& audio_frame);
     42 
     43   uint16_t PayloadLength10Ms() const;
     44   int32_t SamplingFrequency() const;
     45   void Close();
     46   bool EndOfFile() const {
     47     return end_of_file_;
     48   }
     49   // Moves forward the specified number of 10 ms blocks. If a limit has been set
     50   // with SetNum10MsBlocksToRead, fast-forwarding does not count towards this
     51   // limit.
     52   void FastForward(int num_10ms_blocks);
     53   void Rewind();
     54   static int16_t ChooseFile(std::string* file_name, int16_t max_len,
     55                             uint16_t* frequency_hz);
     56   bool Rewinded();
     57   void SaveStereo(bool is_stereo = true);
     58   void ReadStereo(bool is_stereo = true);
     59   // If set, the reading will stop after the specified number of blocks have
     60   // been read. When that has happened, EndOfFile() will return true. Calling
     61   // Rewind() will reset the counter and start over.
     62   void SetNum10MsBlocksToRead(int value);
     63 
     64  private:
     65   FILE* pcm_file_;
     66   uint16_t samples_10ms_;
     67   int32_t frequency_;
     68   bool end_of_file_;
     69   bool auto_rewind_;
     70   bool rewinded_;
     71   uint32_t timestamp_;
     72   bool read_stereo_;
     73   bool save_stereo_;
     74   rtc::Optional<int> num_10ms_blocks_to_read_;
     75   int blocks_read_ = 0;
     76 };
     77 
     78 }  // namespace webrtc
     79 
     80 #endif  // WEBRTC_MODULES_AUDIO_CODING_TEST_PCMFILE_H_
     81