blob: b5f52990b76f6b81acf7101b3e91f27014883656 [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
11#ifndef RTPFILE_H
12#define RTPFILE_H
13
14#include "audio_coding_module.h"
15#include "module_common_types.h"
16#include "typedefs.h"
17#include "rw_lock_wrapper.h"
18#include <stdio.h>
19#include <queue>
20
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23class RTPStream
24{
25public:
26 virtual ~RTPStream(){}
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000027
niklase@google.com470e71d2011-07-07 08:21:25 +000028 virtual void Write(const WebRtc_UWord8 payloadType, const WebRtc_UWord32 timeStamp,
29 const WebRtc_Word16 seqNo, const WebRtc_UWord8* payloadData,
30 const WebRtc_UWord16 payloadSize, WebRtc_UWord32 frequency) = 0;
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000031
32 // 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.
niklase@google.com470e71d2011-07-07 08:21:25 +000034 virtual WebRtc_UWord16 Read(WebRtcRTPHeader* rtpInfo,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000035 WebRtc_UWord8* payloadData,
niklase@google.com470e71d2011-07-07 08:21:25 +000036 WebRtc_UWord16 payloadSize,
37 WebRtc_UWord32* offset) = 0;
38 virtual bool EndOfFile() const = 0;
39
40protected:
41 void MakeRTPheader(WebRtc_UWord8* rtpHeader,
42 WebRtc_UWord8 payloadType, WebRtc_Word16 seqNo,
43 WebRtc_UWord32 timeStamp, WebRtc_UWord32 ssrc);
44 void ParseRTPHeader(WebRtcRTPHeader* rtpInfo, const WebRtc_UWord8* rtpHeader);
45};
46
47class RTPPacket
48{
49public:
50 RTPPacket(WebRtc_UWord8 payloadType, WebRtc_UWord32 timeStamp,
51 WebRtc_Word16 seqNo, const WebRtc_UWord8* payloadData,
52 WebRtc_UWord16 payloadSize, WebRtc_UWord32 frequency);
53 ~RTPPacket();
54 WebRtc_UWord8 payloadType;
55 WebRtc_UWord32 timeStamp;
56 WebRtc_Word16 seqNo;
57 WebRtc_UWord8* payloadData;
58 WebRtc_UWord16 payloadSize;
59 WebRtc_UWord32 frequency;
60};
61
62class RTPBuffer : public RTPStream
63{
64public:
65 RTPBuffer();
66 ~RTPBuffer();
67 void Write(const WebRtc_UWord8 payloadType, const WebRtc_UWord32 timeStamp,
68 const WebRtc_Word16 seqNo, const WebRtc_UWord8* payloadData,
69 const WebRtc_UWord16 payloadSize, WebRtc_UWord32 frequency);
70 WebRtc_UWord16 Read(WebRtcRTPHeader* rtpInfo,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000071 WebRtc_UWord8* payloadData,
niklase@google.com470e71d2011-07-07 08:21:25 +000072 WebRtc_UWord16 payloadSize,
73 WebRtc_UWord32* offset);
74 virtual bool EndOfFile() const;
75private:
76 RWLockWrapper* _queueRWLock;
77 std::queue<RTPPacket *> _rtpQueue;
78};
79
80class RTPFile : public RTPStream
81{
82public:
83 ~RTPFile(){}
84 RTPFile() : _rtpFile(NULL),_rtpEOF(false) {}
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000085 void Open(const char *outFilename, const char *mode);
niklase@google.com470e71d2011-07-07 08:21:25 +000086 void Close();
87 void WriteHeader();
88 void ReadHeader();
89 void Write(const WebRtc_UWord8 payloadType, const WebRtc_UWord32 timeStamp,
90 const WebRtc_Word16 seqNo, const WebRtc_UWord8* payloadData,
91 const WebRtc_UWord16 payloadSize, WebRtc_UWord32 frequency);
92 WebRtc_UWord16 Read(WebRtcRTPHeader* rtpInfo,
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +000093 WebRtc_UWord8* payloadData,
niklase@google.com470e71d2011-07-07 08:21:25 +000094 WebRtc_UWord16 payloadSize,
95 WebRtc_UWord32* offset);
96 bool EndOfFile() const { return _rtpEOF; }
97private:
98 FILE* _rtpFile;
99 bool _rtpEOF;
100};
101
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000102} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000103#endif