blob: 1d0ddf840a052155d63e1a04ab170da670dfd59a [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_TEST_RTPFILE_H_
12#define MODULES_AUDIO_CODING_TEST_RTPFILE_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
niklase@google.com470e71d2011-07-07 08:21:25 +000014#include <stdio.h>
15#include <queue>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_coding/include/audio_coding_module.h"
Karl Wiberg2b857922018-03-23 14:53:54 +010018#include "rtc_base/synchronization/rw_lock_wrapper.h"
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000019
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000020namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000021
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000022class RTPStream {
23 public:
Yves Gerey665174f2018-06-19 15:03:05 +020024 virtual ~RTPStream() {}
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000025
Yves Gerey665174f2018-06-19 15:03:05 +020026 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.org975e4a32012-01-17 19:27:33 +000032
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000033 // 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 Gerey665174f2018-06-19 15:03:05 +020035 virtual size_t Read(WebRtcRTPHeader* rtpInfo,
36 uint8_t* payloadData,
37 size_t payloadSize,
38 uint32_t* offset) = 0;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039 virtual bool EndOfFile() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000040
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000041 protected:
Yves Gerey665174f2018-06-19 15:03:05 +020042 void MakeRTPheader(uint8_t* rtpHeader,
43 uint8_t payloadType,
44 int16_t seqNo,
45 uint32_t timeStamp,
46 uint32_t ssrc);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047
48 void ParseRTPHeader(WebRtcRTPHeader* rtpInfo, const uint8_t* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +000049};
50
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000051class RTPPacket {
52 public:
Yves Gerey665174f2018-06-19 15:03:05 +020053 RTPPacket(uint8_t payloadType,
54 uint32_t timeStamp,
55 int16_t seqNo,
56 const uint8_t* payloadData,
57 size_t payloadSize,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000058 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.org4591fbd2014-11-20 22:28:14 +000066 size_t payloadSize;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000067 uint32_t frequency;
niklase@google.com470e71d2011-07-07 08:21:25 +000068};
69
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000070class RTPBuffer : public RTPStream {
71 public:
72 RTPBuffer();
73
74 ~RTPBuffer();
75
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000076 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.orgd5726a12013-05-03 07:34:12 +000082
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000083 size_t Read(WebRtcRTPHeader* rtpInfo,
84 uint8_t* payloadData,
85 size_t payloadSize,
86 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000087
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000088 bool EndOfFile() const override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000089
90 private:
91 RWLockWrapper* _queueRWLock;
Yves Gerey665174f2018-06-19 15:03:05 +020092 std::queue<RTPPacket*> _rtpQueue;
niklase@google.com470e71d2011-07-07 08:21:25 +000093};
94
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000095class RTPFile : public RTPStream {
96 public:
Yves Gerey665174f2018-06-19 15:03:05 +020097 ~RTPFile() {}
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000098
Yves Gerey665174f2018-06-19 15:03:05 +020099 RTPFile() : _rtpFile(NULL), _rtpEOF(false) {}
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000100
Yves Gerey665174f2018-06-19 15:03:05 +0200101 void Open(const char* outFilename, const char* mode);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000102
103 void Close();
104
105 void WriteHeader();
106
107 void ReadHeader();
108
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000109 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.orgd5726a12013-05-03 07:34:12 +0000115
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000116 size_t Read(WebRtcRTPHeader* rtpInfo,
117 uint8_t* payloadData,
118 size_t payloadSize,
119 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000120
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000121 bool EndOfFile() const override { return _rtpEOF; }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000122
123 private:
124 FILE* _rtpFile;
125 bool _rtpEOF;
niklase@google.com470e71d2011-07-07 08:21:25 +0000126};
127
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000128} // namespace webrtc
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000129
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200130#endif // MODULES_AUDIO_CODING_TEST_RTPFILE_H_