blob: b9afe2f1c4dfd0332b481e953c28a7b376329bc3 [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"
Mirko Bonadei71207422017-09-15 13:58:09 +020019#include "typedefs.h" // NOLINT(build/include)
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000020
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000023class RTPStream {
24 public:
25 virtual ~RTPStream() {
26 }
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000027
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000028 virtual void Write(const uint8_t payloadType, const uint32_t timeStamp,
29 const int16_t seqNo, const uint8_t* payloadData,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000030 const size_t payloadSize, uint32_t frequency) = 0;
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000031
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000032 // 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.org4591fbd2014-11-20 22:28:14 +000034 virtual size_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
35 size_t payloadSize, uint32_t* offset) = 0;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000036 virtual bool EndOfFile() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000038 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.com470e71d2011-07-07 08:21:25 +000043};
44
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000045class RTPPacket {
46 public:
47 RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000048 const uint8_t* payloadData, size_t payloadSize,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000049 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.org4591fbd2014-11-20 22:28:14 +000057 size_t payloadSize;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000058 uint32_t frequency;
niklase@google.com470e71d2011-07-07 08:21:25 +000059};
60
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000061class RTPBuffer : public RTPStream {
62 public:
63 RTPBuffer();
64
65 ~RTPBuffer();
66
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000067 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.orgd5726a12013-05-03 07:34:12 +000073
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000074 size_t Read(WebRtcRTPHeader* rtpInfo,
75 uint8_t* payloadData,
76 size_t payloadSize,
77 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000078
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000079 bool EndOfFile() const override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000080
81 private:
82 RWLockWrapper* _queueRWLock;
83 std::queue<RTPPacket *> _rtpQueue;
niklase@google.com470e71d2011-07-07 08:21:25 +000084};
85
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000086class 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.org14665ff2015-03-04 12:58:35 +0000104 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.orgd5726a12013-05-03 07:34:12 +0000110
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000111 size_t Read(WebRtcRTPHeader* rtpInfo,
112 uint8_t* payloadData,
113 size_t payloadSize,
114 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000115
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000116 bool EndOfFile() const override { return _rtpEOF; }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000117
118 private:
119 FILE* _rtpFile;
120 bool _rtpEOF;
niklase@google.com470e71d2011-07-07 08:21:25 +0000121};
122
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000123} // namespace webrtc
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000124
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200125#endif // MODULES_AUDIO_CODING_TEST_RTPFILE_H_