blob: 9a2d43a14b4e52436c2b4a2199b7ae06d6e0e2ac [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,
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
henrike@webrtc.org47658f12014-09-10 22:14:59 +000068 virtual void Write(const uint8_t payloadType, const uint32_t timeStamp,
69 const int16_t seqNo, const uint8_t* payloadData,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000070 const size_t payloadSize, uint32_t frequency) OVERRIDE;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000071
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000072 virtual size_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
73 size_t payloadSize, uint32_t* offset) OVERRIDE;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000074
henrike@webrtc.org47658f12014-09-10 22:14:59 +000075 virtual bool EndOfFile() const OVERRIDE;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000076
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
henrike@webrtc.org47658f12014-09-10 22:14:59 +0000100 virtual void Write(const uint8_t payloadType, const uint32_t timeStamp,
101 const int16_t seqNo, const uint8_t* payloadData,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000102 const size_t payloadSize, uint32_t frequency) OVERRIDE;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000103
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000104 virtual size_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
105 size_t payloadSize, uint32_t* offset) OVERRIDE;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000106
henrike@webrtc.org47658f12014-09-10 22:14:59 +0000107 virtual bool EndOfFile() const OVERRIDE {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000108 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_