blob: dd6ee72e2e41615347fd7e6eac99d8ba48db2877 [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"
18#include "modules/include/module_common_types.h"
19#include "system_wrappers/include/rw_lock_wrapper.h"
20#include "typedefs.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:
26 virtual ~RTPStream() {
27 }
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000028
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000029 virtual void Write(const uint8_t payloadType, const uint32_t timeStamp,
30 const int16_t seqNo, const uint8_t* payloadData,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000031 const size_t payloadSize, 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.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000035 virtual size_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
36 size_t payloadSize, uint32_t* offset) = 0;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000037 virtual bool EndOfFile() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039 protected:
40 void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType, int16_t seqNo,
41 uint32_t timeStamp, uint32_t ssrc);
42
43 void ParseRTPHeader(WebRtcRTPHeader* rtpInfo, const uint8_t* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +000044};
45
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000046class RTPPacket {
47 public:
48 RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000049 const uint8_t* payloadData, size_t payloadSize,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000050 uint32_t frequency);
51
52 ~RTPPacket();
53
54 uint8_t payloadType;
55 uint32_t timeStamp;
56 int16_t seqNo;
57 uint8_t* payloadData;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000058 size_t payloadSize;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000059 uint32_t frequency;
niklase@google.com470e71d2011-07-07 08:21:25 +000060};
61
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000062class RTPBuffer : public RTPStream {
63 public:
64 RTPBuffer();
65
66 ~RTPBuffer();
67
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000068 void Write(const uint8_t payloadType,
69 const uint32_t timeStamp,
70 const int16_t seqNo,
71 const uint8_t* payloadData,
72 const size_t payloadSize,
73 uint32_t frequency) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000074
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000075 size_t Read(WebRtcRTPHeader* rtpInfo,
76 uint8_t* payloadData,
77 size_t payloadSize,
78 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000079
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000080 bool EndOfFile() const override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000081
82 private:
83 RWLockWrapper* _queueRWLock;
84 std::queue<RTPPacket *> _rtpQueue;
niklase@google.com470e71d2011-07-07 08:21:25 +000085};
86
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000087class RTPFile : public RTPStream {
88 public:
89 ~RTPFile() {
90 }
91
92 RTPFile()
93 : _rtpFile(NULL),
94 _rtpEOF(false) {
95 }
96
97 void Open(const char *outFilename, const char *mode);
98
99 void Close();
100
101 void WriteHeader();
102
103 void ReadHeader();
104
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000105 void Write(const uint8_t payloadType,
106 const uint32_t timeStamp,
107 const int16_t seqNo,
108 const uint8_t* payloadData,
109 const size_t payloadSize,
110 uint32_t frequency) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000111
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000112 size_t Read(WebRtcRTPHeader* rtpInfo,
113 uint8_t* payloadData,
114 size_t payloadSize,
115 uint32_t* offset) override;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000116
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000117 bool EndOfFile() const override { return _rtpEOF; }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000118
119 private:
120 FILE* _rtpFile;
121 bool _rtpEOF;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122};
123
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000124} // namespace webrtc
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000125
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200126#endif // MODULES_AUDIO_CODING_TEST_RTPFILE_H_