blob: b796491da96f037bf7614919aa82250719b74193 [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
Ali Tofigh714e3cb2022-07-20 12:53:07 +020018#include "absl/strings/string_view.h"
Niels Möller834a5542019-09-23 10:31:16 +020019#include "api/rtp_headers.h"
Niels Möller84d36072020-10-28 14:05:07 +010020#include "rtc_base/synchronization/mutex.h"
21#include "rtc_base/thread_annotations.h"
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000022
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000023namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000025class RTPStream {
26 public:
Yves Gerey665174f2018-06-19 15:03:05 +020027 virtual ~RTPStream() {}
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000028
Ali Tofigh62238092022-01-25 13:27:19 +010029 virtual void Write(uint8_t payloadType,
30 uint32_t timeStamp,
31 int16_t seqNo,
Yves Gerey665174f2018-06-19 15:03:05 +020032 const uint8_t* payloadData,
Ali Tofigh62238092022-01-25 13:27:19 +010033 size_t payloadSize,
Yves Gerey665174f2018-06-19 15:03:05 +020034 uint32_t frequency) = 0;
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000035
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000036 // Returns the packet's payload size. Zero should be treated as an
37 // end-of-stream (in the case that EndOfFile() is true) or an error.
Niels Möllerbf474952019-02-18 12:00:06 +010038 virtual size_t Read(RTPHeader* rtp_Header,
Yves Gerey665174f2018-06-19 15:03:05 +020039 uint8_t* payloadData,
40 size_t payloadSize,
41 uint32_t* offset) = 0;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000042 virtual bool EndOfFile() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000043
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000044 protected:
Yves Gerey665174f2018-06-19 15:03:05 +020045 void MakeRTPheader(uint8_t* rtpHeader,
46 uint8_t payloadType,
47 int16_t seqNo,
48 uint32_t timeStamp,
49 uint32_t ssrc);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000050
Niels Möllerbf474952019-02-18 12:00:06 +010051 void ParseRTPHeader(RTPHeader* rtp_header, const uint8_t* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +000052};
53
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000054class RTPPacket {
55 public:
Yves Gerey665174f2018-06-19 15:03:05 +020056 RTPPacket(uint8_t payloadType,
57 uint32_t timeStamp,
58 int16_t seqNo,
59 const uint8_t* payloadData,
60 size_t payloadSize,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000061 uint32_t frequency);
62
63 ~RTPPacket();
64
65 uint8_t payloadType;
66 uint32_t timeStamp;
67 int16_t seqNo;
68 uint8_t* payloadData;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000069 size_t payloadSize;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000070 uint32_t frequency;
niklase@google.com470e71d2011-07-07 08:21:25 +000071};
72
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000073class RTPBuffer : public RTPStream {
74 public:
Niels Möller84d36072020-10-28 14:05:07 +010075 RTPBuffer() = default;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000076
Niels Möller84d36072020-10-28 14:05:07 +010077 ~RTPBuffer() = default;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000078
Ali Tofigh62238092022-01-25 13:27:19 +010079 void Write(uint8_t payloadType,
80 uint32_t timeStamp,
81 int16_t seqNo,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000082 const uint8_t* payloadData,
Ali Tofigh62238092022-01-25 13:27:19 +010083 size_t payloadSize,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000084 uint32_t frequency) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000085
Niels Möllerbf474952019-02-18 12:00:06 +010086 size_t Read(RTPHeader* rtp_header,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000087 uint8_t* payloadData,
88 size_t payloadSize,
89 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000090
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000091 bool EndOfFile() const override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000092
93 private:
Niels Möller84d36072020-10-28 14:05:07 +010094 mutable Mutex mutex_;
95 std::queue<RTPPacket*> _rtpQueue RTC_GUARDED_BY(&mutex_);
niklase@google.com470e71d2011-07-07 08:21:25 +000096};
97
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000098class RTPFile : public RTPStream {
99 public:
Yves Gerey665174f2018-06-19 15:03:05 +0200100 ~RTPFile() {}
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000101
Yves Gerey665174f2018-06-19 15:03:05 +0200102 RTPFile() : _rtpFile(NULL), _rtpEOF(false) {}
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000103
Ali Tofigh714e3cb2022-07-20 12:53:07 +0200104 void Open(absl::string_view outFilename, absl::string_view mode);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000105
106 void Close();
107
108 void WriteHeader();
109
110 void ReadHeader();
111
Ali Tofigh62238092022-01-25 13:27:19 +0100112 void Write(uint8_t payloadType,
113 uint32_t timeStamp,
114 int16_t seqNo,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000115 const uint8_t* payloadData,
Ali Tofigh62238092022-01-25 13:27:19 +0100116 size_t payloadSize,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000117 uint32_t frequency) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000118
Niels Möllerbf474952019-02-18 12:00:06 +0100119 size_t Read(RTPHeader* rtp_header,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000120 uint8_t* payloadData,
121 size_t payloadSize,
122 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000123
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000124 bool EndOfFile() const override { return _rtpEOF; }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000125
126 private:
127 FILE* _rtpFile;
128 bool _rtpEOF;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129};
130
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000131} // namespace webrtc
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000132
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200133#endif // MODULES_AUDIO_CODING_TEST_RTPFILE_H_