blob: 9b6d5fcafefc9be0221d2a71e040e62dece4b97d [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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_RTPFILE_H_
12#define WEBRTC_MODULES_AUDIO_CODING_MAIN_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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000017#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
18#include "webrtc/modules/interface/module_common_types.h"
19#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
20#include "webrtc/typedefs.h"
21
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,
31 const uint16_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.
35 virtual uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
36 uint16_t payloadSize, uint32_t* offset) = 0;
37 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,
49 const uint8_t* payloadData, uint16_t payloadSize,
50 uint32_t frequency);
51
52 ~RTPPacket();
53
54 uint8_t payloadType;
55 uint32_t timeStamp;
56 int16_t seqNo;
57 uint8_t* payloadData;
58 uint16_t payloadSize;
59 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
68 void Write(const uint8_t payloadType, const uint32_t timeStamp,
69 const int16_t seqNo, const uint8_t* payloadData,
70 const uint16_t payloadSize, uint32_t frequency);
71
72 uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
73 uint16_t payloadSize, uint32_t* offset);
74
75 virtual bool EndOfFile() const;
76
77 private:
78 RWLockWrapper* _queueRWLock;
79 std::queue<RTPPacket *> _rtpQueue;
niklase@google.com470e71d2011-07-07 08:21:25 +000080};
81
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000082class RTPFile : public RTPStream {
83 public:
84 ~RTPFile() {
85 }
86
87 RTPFile()
88 : _rtpFile(NULL),
89 _rtpEOF(false) {
90 }
91
92 void Open(const char *outFilename, const char *mode);
93
94 void Close();
95
96 void WriteHeader();
97
98 void ReadHeader();
99
100 void Write(const uint8_t payloadType, const uint32_t timeStamp,
101 const int16_t seqNo, const uint8_t* payloadData,
102 const uint16_t payloadSize, uint32_t frequency);
103
104 uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
105 uint16_t payloadSize, uint32_t* offset);
106
107 bool EndOfFile() const {
108 return _rtpEOF;
109 }
110
111 private:
112 FILE* _rtpFile;
113 bool _rtpEOF;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114};
115
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000116} // namespace webrtc
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000117
118#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_RTPFILE_H_