blob: 73e97dd5262404ec5033aaf55a7ecead8ac2e389 [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:
Yves Gerey665174f2018-06-19 15:03:05 +020025 virtual ~RTPStream() {}
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000026
Yves Gerey665174f2018-06-19 15:03:05 +020027 virtual void Write(const uint8_t payloadType,
28 const uint32_t timeStamp,
29 const int16_t seqNo,
30 const uint8_t* payloadData,
31 const size_t payloadSize,
32 uint32_t frequency) = 0;
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000033
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000034 // Returns the packet's payload size. Zero should be treated as an
35 // end-of-stream (in the case that EndOfFile() is true) or an error.
Yves Gerey665174f2018-06-19 15:03:05 +020036 virtual size_t Read(WebRtcRTPHeader* rtpInfo,
37 uint8_t* payloadData,
38 size_t payloadSize,
39 uint32_t* offset) = 0;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000040 virtual bool EndOfFile() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000041
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000042 protected:
Yves Gerey665174f2018-06-19 15:03:05 +020043 void MakeRTPheader(uint8_t* rtpHeader,
44 uint8_t payloadType,
45 int16_t seqNo,
46 uint32_t timeStamp,
47 uint32_t ssrc);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000048
49 void ParseRTPHeader(WebRtcRTPHeader* rtpInfo, const uint8_t* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +000050};
51
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000052class RTPPacket {
53 public:
Yves Gerey665174f2018-06-19 15:03:05 +020054 RTPPacket(uint8_t payloadType,
55 uint32_t timeStamp,
56 int16_t seqNo,
57 const uint8_t* payloadData,
58 size_t payloadSize,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000059 uint32_t frequency);
60
61 ~RTPPacket();
62
63 uint8_t payloadType;
64 uint32_t timeStamp;
65 int16_t seqNo;
66 uint8_t* payloadData;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000067 size_t payloadSize;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000068 uint32_t frequency;
niklase@google.com470e71d2011-07-07 08:21:25 +000069};
70
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000071class RTPBuffer : public RTPStream {
72 public:
73 RTPBuffer();
74
75 ~RTPBuffer();
76
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000077 void Write(const uint8_t payloadType,
78 const uint32_t timeStamp,
79 const int16_t seqNo,
80 const uint8_t* payloadData,
81 const size_t payloadSize,
82 uint32_t frequency) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000083
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000084 size_t Read(WebRtcRTPHeader* rtpInfo,
85 uint8_t* payloadData,
86 size_t payloadSize,
87 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000088
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000089 bool EndOfFile() const override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000090
91 private:
92 RWLockWrapper* _queueRWLock;
Yves Gerey665174f2018-06-19 15:03:05 +020093 std::queue<RTPPacket*> _rtpQueue;
niklase@google.com470e71d2011-07-07 08:21:25 +000094};
95
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000096class RTPFile : public RTPStream {
97 public:
Yves Gerey665174f2018-06-19 15:03:05 +020098 ~RTPFile() {}
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000099
Yves Gerey665174f2018-06-19 15:03:05 +0200100 RTPFile() : _rtpFile(NULL), _rtpEOF(false) {}
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000101
Yves Gerey665174f2018-06-19 15:03:05 +0200102 void Open(const char* outFilename, const char* mode);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000103
104 void Close();
105
106 void WriteHeader();
107
108 void ReadHeader();
109
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000110 void Write(const uint8_t payloadType,
111 const uint32_t timeStamp,
112 const int16_t seqNo,
113 const uint8_t* payloadData,
114 const size_t payloadSize,
115 uint32_t frequency) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000116
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000117 size_t Read(WebRtcRTPHeader* rtpInfo,
118 uint8_t* payloadData,
119 size_t payloadSize,
120 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000121
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000122 bool EndOfFile() const override { return _rtpEOF; }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000123
124 private:
125 FILE* _rtpFile;
126 bool _rtpEOF;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127};
128
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000129} // namespace webrtc
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000130
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200131#endif // MODULES_AUDIO_CODING_TEST_RTPFILE_H_