niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_CODING_TEST_RTPFILE_H_ |
| 12 | #define MODULES_AUDIO_CODING_TEST_RTPFILE_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <queue> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/audio_coding/include/audio_coding_module.h" |
Karl Wiberg | 2b85792 | 2018-03-23 14:53:54 +0100 | [diff] [blame] | 18 | #include "rtc_base/synchronization/rw_lock_wrapper.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 19 | #include "typedefs.h" // NOLINT(build/include) |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 20 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 23 | class RTPStream { |
| 24 | public: |
| 25 | virtual ~RTPStream() { |
| 26 | } |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 27 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 28 | virtual void Write(const uint8_t payloadType, const uint32_t timeStamp, |
| 29 | const int16_t seqNo, const uint8_t* payloadData, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 30 | const size_t payloadSize, uint32_t frequency) = 0; |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 31 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 32 | // Returns the packet's payload size. Zero should be treated as an |
| 33 | // end-of-stream (in the case that EndOfFile() is true) or an error. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 34 | virtual size_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData, |
| 35 | size_t payloadSize, uint32_t* offset) = 0; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 36 | virtual bool EndOfFile() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 38 | protected: |
| 39 | void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType, int16_t seqNo, |
| 40 | uint32_t timeStamp, uint32_t ssrc); |
| 41 | |
| 42 | void ParseRTPHeader(WebRtcRTPHeader* rtpInfo, const uint8_t* rtpHeader); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 45 | class RTPPacket { |
| 46 | public: |
| 47 | RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 48 | const uint8_t* payloadData, size_t payloadSize, |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 49 | uint32_t frequency); |
| 50 | |
| 51 | ~RTPPacket(); |
| 52 | |
| 53 | uint8_t payloadType; |
| 54 | uint32_t timeStamp; |
| 55 | int16_t seqNo; |
| 56 | uint8_t* payloadData; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 57 | size_t payloadSize; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 58 | uint32_t frequency; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 61 | class RTPBuffer : public RTPStream { |
| 62 | public: |
| 63 | RTPBuffer(); |
| 64 | |
| 65 | ~RTPBuffer(); |
| 66 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 67 | void Write(const uint8_t payloadType, |
| 68 | const uint32_t timeStamp, |
| 69 | const int16_t seqNo, |
| 70 | const uint8_t* payloadData, |
| 71 | const size_t payloadSize, |
| 72 | uint32_t frequency) override; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 73 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 74 | size_t Read(WebRtcRTPHeader* rtpInfo, |
| 75 | uint8_t* payloadData, |
| 76 | size_t payloadSize, |
| 77 | uint32_t* offset) override; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 78 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 79 | bool EndOfFile() const override; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 80 | |
| 81 | private: |
| 82 | RWLockWrapper* _queueRWLock; |
| 83 | std::queue<RTPPacket *> _rtpQueue; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 86 | class RTPFile : public RTPStream { |
| 87 | public: |
| 88 | ~RTPFile() { |
| 89 | } |
| 90 | |
| 91 | RTPFile() |
| 92 | : _rtpFile(NULL), |
| 93 | _rtpEOF(false) { |
| 94 | } |
| 95 | |
| 96 | void Open(const char *outFilename, const char *mode); |
| 97 | |
| 98 | void Close(); |
| 99 | |
| 100 | void WriteHeader(); |
| 101 | |
| 102 | void ReadHeader(); |
| 103 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 104 | void Write(const uint8_t payloadType, |
| 105 | const uint32_t timeStamp, |
| 106 | const int16_t seqNo, |
| 107 | const uint8_t* payloadData, |
| 108 | const size_t payloadSize, |
| 109 | uint32_t frequency) override; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 110 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 111 | size_t Read(WebRtcRTPHeader* rtpInfo, |
| 112 | uint8_t* payloadData, |
| 113 | size_t payloadSize, |
| 114 | uint32_t* offset) override; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 115 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 116 | bool EndOfFile() const override { return _rtpEOF; } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 117 | |
| 118 | private: |
| 119 | FILE* _rtpFile; |
| 120 | bool _rtpEOF; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 123 | } // namespace webrtc |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 124 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 125 | #endif // MODULES_AUDIO_CODING_TEST_RTPFILE_H_ |