blob: eda576d4cf2eeedd8ad57f5ae82dd255d1b86fea [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
niklase@google.com470e71d2011-07-07 08:21:25 +000016#include <queue>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/include/audio_coding_module.h"
Niels Möllerafb5dbb2019-02-15 15:21:47 +010019#include "modules/include/module_common_types.h"
Karl Wiberg2b857922018-03-23 14:53:54 +010020#include "rtc_base/synchronization/rw_lock_wrapper.h"
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000021
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000022namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000023
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000024class RTPStream {
25 public:
Yves Gerey665174f2018-06-19 15:03:05 +020026 virtual ~RTPStream() {}
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000027
Yves Gerey665174f2018-06-19 15:03:05 +020028 virtual void Write(const uint8_t payloadType,
29 const uint32_t timeStamp,
30 const int16_t seqNo,
31 const uint8_t* payloadData,
32 const size_t payloadSize,
33 uint32_t frequency) = 0;
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000034
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000035 // Returns the packet's payload size. Zero should be treated as an
36 // end-of-stream (in the case that EndOfFile() is true) or an error.
Niels Möllerbf474952019-02-18 12:00:06 +010037 virtual size_t Read(RTPHeader* rtp_Header,
Yves Gerey665174f2018-06-19 15:03:05 +020038 uint8_t* payloadData,
39 size_t payloadSize,
40 uint32_t* offset) = 0;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000041 virtual bool EndOfFile() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000042
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000043 protected:
Yves Gerey665174f2018-06-19 15:03:05 +020044 void MakeRTPheader(uint8_t* rtpHeader,
45 uint8_t payloadType,
46 int16_t seqNo,
47 uint32_t timeStamp,
48 uint32_t ssrc);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000049
Niels Möllerbf474952019-02-18 12:00:06 +010050 void ParseRTPHeader(RTPHeader* rtp_header, const uint8_t* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +000051};
52
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000053class RTPPacket {
54 public:
Yves Gerey665174f2018-06-19 15:03:05 +020055 RTPPacket(uint8_t payloadType,
56 uint32_t timeStamp,
57 int16_t seqNo,
58 const uint8_t* payloadData,
59 size_t payloadSize,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000060 uint32_t frequency);
61
62 ~RTPPacket();
63
64 uint8_t payloadType;
65 uint32_t timeStamp;
66 int16_t seqNo;
67 uint8_t* payloadData;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000068 size_t payloadSize;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000069 uint32_t frequency;
niklase@google.com470e71d2011-07-07 08:21:25 +000070};
71
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000072class RTPBuffer : public RTPStream {
73 public:
74 RTPBuffer();
75
76 ~RTPBuffer();
77
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000078 void Write(const uint8_t payloadType,
79 const uint32_t timeStamp,
80 const int16_t seqNo,
81 const uint8_t* payloadData,
82 const size_t payloadSize,
83 uint32_t frequency) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000084
Niels Möllerbf474952019-02-18 12:00:06 +010085 size_t Read(RTPHeader* rtp_header,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000086 uint8_t* payloadData,
87 size_t payloadSize,
88 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000089
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000090 bool EndOfFile() const override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000091
92 private:
93 RWLockWrapper* _queueRWLock;
Yves Gerey665174f2018-06-19 15:03:05 +020094 std::queue<RTPPacket*> _rtpQueue;
niklase@google.com470e71d2011-07-07 08:21:25 +000095};
96
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000097class RTPFile : public RTPStream {
98 public:
Yves Gerey665174f2018-06-19 15:03:05 +020099 ~RTPFile() {}
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000100
Yves Gerey665174f2018-06-19 15:03:05 +0200101 RTPFile() : _rtpFile(NULL), _rtpEOF(false) {}
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000102
Yves Gerey665174f2018-06-19 15:03:05 +0200103 void Open(const char* outFilename, const char* mode);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000104
105 void Close();
106
107 void WriteHeader();
108
109 void ReadHeader();
110
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000111 void Write(const uint8_t payloadType,
112 const uint32_t timeStamp,
113 const int16_t seqNo,
114 const uint8_t* payloadData,
115 const size_t payloadSize,
116 uint32_t frequency) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000117
Niels Möllerbf474952019-02-18 12:00:06 +0100118 size_t Read(RTPHeader* rtp_header,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000119 uint8_t* payloadData,
120 size_t payloadSize,
121 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000122
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000123 bool EndOfFile() const override { return _rtpEOF; }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000124
125 private:
126 FILE* _rtpFile;
127 bool _rtpEOF;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128};
129
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000130} // namespace webrtc
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000131
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200132#endif // MODULES_AUDIO_CODING_TEST_RTPFILE_H_