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