blob: 7b146b39268007103b8c94df2c3f743d20e557b4 [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
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000023class RTPStream {
24 public:
25 virtual ~RTPStream() {
26 }
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000027
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000028 virtual void Write(const uint8_t payloadType, const uint32_t timeStamp,
29 const int16_t seqNo, const uint8_t* payloadData,
30 const uint16_t payloadSize, uint32_t frequency) = 0;
andrew@webrtc.org975e4a32012-01-17 19:27:33 +000031
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000032 // 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.
34 virtual uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
35 uint16_t payloadSize, uint32_t* offset) = 0;
36 virtual bool EndOfFile() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000038 protected:
39 void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType, int16_t seqNo,
40 uint32_t timeStamp, uint32_t ssrc);
41
42 void ParseRTPHeader(WebRtcRTPHeader* rtpInfo, const uint8_t* rtpHeader);
niklase@google.com470e71d2011-07-07 08:21:25 +000043};
44
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000045class RTPPacket {
46 public:
47 RTPPacket(uint8_t payloadType, uint32_t timeStamp, int16_t seqNo,
48 const uint8_t* payloadData, uint16_t payloadSize,
49 uint32_t frequency);
50
51 ~RTPPacket();
52
53 uint8_t payloadType;
54 uint32_t timeStamp;
55 int16_t seqNo;
56 uint8_t* payloadData;
57 uint16_t payloadSize;
58 uint32_t frequency;
niklase@google.com470e71d2011-07-07 08:21:25 +000059};
60
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000061class RTPBuffer : public RTPStream {
62 public:
63 RTPBuffer();
64
65 ~RTPBuffer();
66
67 void Write(const uint8_t payloadType, const uint32_t timeStamp,
68 const int16_t seqNo, const uint8_t* payloadData,
69 const uint16_t payloadSize, uint32_t frequency);
70
71 uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
72 uint16_t payloadSize, uint32_t* offset);
73
74 virtual bool EndOfFile() const;
75
76 private:
77 RWLockWrapper* _queueRWLock;
78 std::queue<RTPPacket *> _rtpQueue;
niklase@google.com470e71d2011-07-07 08:21:25 +000079};
80
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000081class RTPFile : public RTPStream {
82 public:
83 ~RTPFile() {
84 }
85
86 RTPFile()
87 : _rtpFile(NULL),
88 _rtpEOF(false) {
89 }
90
91 void Open(const char *outFilename, const char *mode);
92
93 void Close();
94
95 void WriteHeader();
96
97 void ReadHeader();
98
99 void Write(const uint8_t payloadType, const uint32_t timeStamp,
100 const int16_t seqNo, const uint8_t* payloadData,
101 const uint16_t payloadSize, uint32_t frequency);
102
103 uint16_t Read(WebRtcRTPHeader* rtpInfo, uint8_t* payloadData,
104 uint16_t payloadSize, uint32_t* offset);
105
106 bool EndOfFile() const {
107 return _rtpEOF;
108 }
109
110 private:
111 FILE* _rtpFile;
112 bool _rtpEOF;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113};
114
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000115} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000116#endif