Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: talk/media/base/rtpdump.h

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/media/base/rtpdataengine_unittest.cc ('k') | talk/media/base/rtpdump.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 enum RtpDumpPacketFilter { 49 enum RtpDumpPacketFilter {
50 PF_NONE = 0x0, 50 PF_NONE = 0x0,
51 PF_RTPHEADER = 0x1, 51 PF_RTPHEADER = 0x1,
52 PF_RTPPACKET = 0x3, // includes header 52 PF_RTPPACKET = 0x3, // includes header
53 // PF_RTCPHEADER = 0x4, // TODO(juberti) 53 // PF_RTCPHEADER = 0x4, // TODO(juberti)
54 PF_RTCPPACKET = 0xC, // includes header 54 PF_RTCPPACKET = 0xC, // includes header
55 PF_ALL = 0xF 55 PF_ALL = 0xF
56 }; 56 };
57 57
58 struct RtpDumpFileHeader { 58 struct RtpDumpFileHeader {
59 RtpDumpFileHeader(uint32 start_ms, uint32 s, uint16 p); 59 RtpDumpFileHeader(uint32_t start_ms, uint32_t s, uint16_t p);
60 void WriteToByteBuffer(rtc::ByteBuffer* buf); 60 void WriteToByteBuffer(rtc::ByteBuffer* buf);
61 61
62 static const char kFirstLine[]; 62 static const char kFirstLine[];
63 static const size_t kHeaderLength = 16; 63 static const size_t kHeaderLength = 16;
64 uint32 start_sec; // start of recording, the seconds part. 64 uint32_t start_sec; // start of recording, the seconds part.
65 uint32 start_usec; // start of recording, the microseconds part. 65 uint32_t start_usec; // start of recording, the microseconds part.
66 uint32 source; // network source (multicast address). 66 uint32_t source; // network source (multicast address).
67 uint16 port; // UDP port. 67 uint16_t port; // UDP port.
68 uint16 padding; // 2 bytes padding. 68 uint16_t padding; // 2 bytes padding.
69 }; 69 };
70 70
71 struct RtpDumpPacket { 71 struct RtpDumpPacket {
72 RtpDumpPacket() {} 72 RtpDumpPacket() {}
73 73
74 RtpDumpPacket(const void* d, size_t s, uint32 elapsed, bool rtcp) 74 RtpDumpPacket(const void* d, size_t s, uint32_t elapsed, bool rtcp)
75 : elapsed_time(elapsed), 75 : elapsed_time(elapsed), original_data_len((rtcp) ? 0 : s) {
76 original_data_len((rtcp) ? 0 : s) {
77 data.resize(s); 76 data.resize(s);
78 memcpy(&data[0], d, s); 77 memcpy(&data[0], d, s);
79 } 78 }
80 79
81 // In the rtpdump file format, RTCP packets have their data len set to zero, 80 // In the rtpdump file format, RTCP packets have their data len set to zero,
82 // since RTCP has an internal length field. 81 // since RTCP has an internal length field.
83 bool is_rtcp() const { return original_data_len == 0; } 82 bool is_rtcp() const { return original_data_len == 0; }
84 bool IsValidRtpPacket() const; 83 bool IsValidRtpPacket() const;
85 bool IsValidRtcpPacket() const; 84 bool IsValidRtcpPacket() const;
86 // Get the payload type, sequence number, timestampe, and SSRC of the RTP 85 // Get the payload type, sequence number, timestampe, and SSRC of the RTP
87 // packet. Return true and set the output parameter if successful. 86 // packet. Return true and set the output parameter if successful.
88 bool GetRtpPayloadType(int* pt) const; 87 bool GetRtpPayloadType(int* pt) const;
89 bool GetRtpSeqNum(int* seq_num) const; 88 bool GetRtpSeqNum(int* seq_num) const;
90 bool GetRtpTimestamp(uint32* ts) const; 89 bool GetRtpTimestamp(uint32_t* ts) const;
91 bool GetRtpSsrc(uint32* ssrc) const; 90 bool GetRtpSsrc(uint32_t* ssrc) const;
92 bool GetRtpHeaderLen(size_t* len) const; 91 bool GetRtpHeaderLen(size_t* len) const;
93 // Get the type of the RTCP packet. Return true and set the output parameter 92 // Get the type of the RTCP packet. Return true and set the output parameter
94 // if successful. 93 // if successful.
95 bool GetRtcpType(int* type) const; 94 bool GetRtcpType(int* type) const;
96 95
97 static const size_t kHeaderLength = 8; 96 static const size_t kHeaderLength = 8;
98 uint32 elapsed_time; // Milliseconds since the start of recording. 97 uint32_t elapsed_time; // Milliseconds since the start of recording.
99 std::vector<uint8> data; // The actual RTP or RTCP packet. 98 std::vector<uint8_t> data; // The actual RTP or RTCP packet.
100 size_t original_data_len; // The original length of the packet; may be 99 size_t original_data_len; // The original length of the packet; may be
101 // greater than data.size() if only part of the 100 // greater than data.size() if only part of the
102 // packet was recorded. 101 // packet was recorded.
103 }; 102 };
104 103
105 class RtpDumpReader { 104 class RtpDumpReader {
106 public: 105 public:
107 explicit RtpDumpReader(rtc::StreamInterface* stream) 106 explicit RtpDumpReader(rtc::StreamInterface* stream)
108 : stream_(stream), 107 : stream_(stream),
109 file_header_read_(false), 108 file_header_read_(false),
110 first_line_and_file_header_len_(0), 109 first_line_and_file_header_len_(0),
111 start_time_ms_(0), 110 start_time_ms_(0),
112 ssrc_override_(0) { 111 ssrc_override_(0) {
113 } 112 }
114 virtual ~RtpDumpReader() {} 113 virtual ~RtpDumpReader() {}
115 114
116 // Use the specified ssrc, rather than the ssrc from dump, for RTP packets. 115 // Use the specified ssrc, rather than the ssrc from dump, for RTP packets.
117 void SetSsrc(uint32 ssrc); 116 void SetSsrc(uint32_t ssrc);
118 virtual rtc::StreamResult ReadPacket(RtpDumpPacket* packet); 117 virtual rtc::StreamResult ReadPacket(RtpDumpPacket* packet);
119 118
120 protected: 119 protected:
121 rtc::StreamResult ReadFileHeader(); 120 rtc::StreamResult ReadFileHeader();
122 bool RewindToFirstDumpPacket() { 121 bool RewindToFirstDumpPacket() {
123 return stream_->SetPosition(first_line_and_file_header_len_); 122 return stream_->SetPosition(first_line_and_file_header_len_);
124 } 123 }
125 124
126 private: 125 private:
127 // Check if its matches "#!rtpplay1.0 address/port\n". 126 // Check if its matches "#!rtpplay1.0 address/port\n".
128 bool CheckFirstLine(const std::string& first_line); 127 bool CheckFirstLine(const std::string& first_line);
129 128
130 rtc::StreamInterface* stream_; 129 rtc::StreamInterface* stream_;
131 bool file_header_read_; 130 bool file_header_read_;
132 size_t first_line_and_file_header_len_; 131 size_t first_line_and_file_header_len_;
133 uint32 start_time_ms_; 132 uint32_t start_time_ms_;
134 uint32 ssrc_override_; 133 uint32_t ssrc_override_;
135 134
136 RTC_DISALLOW_COPY_AND_ASSIGN(RtpDumpReader); 135 RTC_DISALLOW_COPY_AND_ASSIGN(RtpDumpReader);
137 }; 136 };
138 137
139 // RtpDumpLoopReader reads RTP dump packets from the input stream and rewinds 138 // RtpDumpLoopReader reads RTP dump packets from the input stream and rewinds
140 // the stream when it ends. RtpDumpLoopReader maintains the elapsed time, the 139 // the stream when it ends. RtpDumpLoopReader maintains the elapsed time, the
141 // RTP sequence number and the RTP timestamp properly. RtpDumpLoopReader can 140 // RTP sequence number and the RTP timestamp properly. RtpDumpLoopReader can
142 // handle both RTP dump and RTCP dump. We assume that the dump does not mix 141 // handle both RTP dump and RTCP dump. We assume that the dump does not mix
143 // RTP packets and RTCP packets. 142 // RTP packets and RTCP packets.
144 class RtpDumpLoopReader : public RtpDumpReader { 143 class RtpDumpLoopReader : public RtpDumpReader {
(...skipping 12 matching lines...) Expand all
157 156
158 // During the second and later loops, update the elapsed time of the dump 157 // During the second and later loops, update the elapsed time of the dump
159 // packet. If the dumped packet is a RTP packet, update its RTP sequence 158 // packet. If the dumped packet is a RTP packet, update its RTP sequence
160 // number and timestamp as well. 159 // number and timestamp as well.
161 void UpdateDumpPacket(RtpDumpPacket* packet); 160 void UpdateDumpPacket(RtpDumpPacket* packet);
162 161
163 int loop_count_; 162 int loop_count_;
164 // How much to increase the elapsed time, RTP sequence number, RTP timestampe 163 // How much to increase the elapsed time, RTP sequence number, RTP timestampe
165 // for each loop. They are calcualted with the variables below during the 164 // for each loop. They are calcualted with the variables below during the
166 // first loop. 165 // first loop.
167 uint32 elapsed_time_increases_; 166 uint32_t elapsed_time_increases_;
168 int rtp_seq_num_increase_; 167 int rtp_seq_num_increase_;
169 uint32 rtp_timestamp_increase_; 168 uint32_t rtp_timestamp_increase_;
170 // How many RTP packets and how many payload frames in the input stream. RTP 169 // How many RTP packets and how many payload frames in the input stream. RTP
171 // packets belong to the same frame have the same RTP timestamp, different 170 // packets belong to the same frame have the same RTP timestamp, different
172 // dump timestamp, and different RTP sequence number. 171 // dump timestamp, and different RTP sequence number.
173 uint32 packet_count_; 172 uint32_t packet_count_;
174 uint32 frame_count_; 173 uint32_t frame_count_;
175 // The elapsed time, RTP sequence number, and RTP timestamp of the first and 174 // The elapsed time, RTP sequence number, and RTP timestamp of the first and
176 // the previous dump packets in the input stream. 175 // the previous dump packets in the input stream.
177 uint32 first_elapsed_time_; 176 uint32_t first_elapsed_time_;
178 int first_rtp_seq_num_; 177 int first_rtp_seq_num_;
179 uint32 first_rtp_timestamp_; 178 uint32_t first_rtp_timestamp_;
180 uint32 prev_elapsed_time_; 179 uint32_t prev_elapsed_time_;
181 int prev_rtp_seq_num_; 180 int prev_rtp_seq_num_;
182 uint32 prev_rtp_timestamp_; 181 uint32_t prev_rtp_timestamp_;
183 182
184 RTC_DISALLOW_COPY_AND_ASSIGN(RtpDumpLoopReader); 183 RTC_DISALLOW_COPY_AND_ASSIGN(RtpDumpLoopReader);
185 }; 184 };
186 185
187 class RtpDumpWriter { 186 class RtpDumpWriter {
188 public: 187 public:
189 explicit RtpDumpWriter(rtc::StreamInterface* stream); 188 explicit RtpDumpWriter(rtc::StreamInterface* stream);
190 189
191 // Filter to control what packets we actually record. 190 // Filter to control what packets we actually record.
192 void set_packet_filter(int filter); 191 void set_packet_filter(int filter);
193 // Write a RTP or RTCP packet. The parameters data points to the packet and 192 // Write a RTP or RTCP packet. The parameters data points to the packet and
194 // data_len is its length. 193 // data_len is its length.
195 rtc::StreamResult WriteRtpPacket(const void* data, size_t data_len) { 194 rtc::StreamResult WriteRtpPacket(const void* data, size_t data_len) {
196 return WritePacket(data, data_len, GetElapsedTime(), false); 195 return WritePacket(data, data_len, GetElapsedTime(), false);
197 } 196 }
198 rtc::StreamResult WriteRtcpPacket(const void* data, size_t data_len) { 197 rtc::StreamResult WriteRtcpPacket(const void* data, size_t data_len) {
199 return WritePacket(data, data_len, GetElapsedTime(), true); 198 return WritePacket(data, data_len, GetElapsedTime(), true);
200 } 199 }
201 rtc::StreamResult WritePacket(const RtpDumpPacket& packet) { 200 rtc::StreamResult WritePacket(const RtpDumpPacket& packet) {
202 return WritePacket(&packet.data[0], packet.data.size(), packet.elapsed_time, 201 return WritePacket(&packet.data[0], packet.data.size(), packet.elapsed_time,
203 packet.is_rtcp()); 202 packet.is_rtcp());
204 } 203 }
205 uint32 GetElapsedTime() const; 204 uint32_t GetElapsedTime() const;
206 205
207 bool GetDumpSize(size_t* size) { 206 bool GetDumpSize(size_t* size) {
208 // Note that we use GetPosition(), rather than GetSize(), to avoid flush the 207 // Note that we use GetPosition(), rather than GetSize(), to avoid flush the
209 // stream per write. 208 // stream per write.
210 return stream_ && size && stream_->GetPosition(size); 209 return stream_ && size && stream_->GetPosition(size);
211 } 210 }
212 211
213 protected: 212 protected:
214 rtc::StreamResult WriteFileHeader(); 213 rtc::StreamResult WriteFileHeader();
215 214
216 private: 215 private:
217 rtc::StreamResult WritePacket(const void* data, size_t data_len, 216 rtc::StreamResult WritePacket(const void* data,
218 uint32 elapsed, bool rtcp); 217 size_t data_len,
218 uint32_t elapsed,
219 bool rtcp);
219 size_t FilterPacket(const void* data, size_t data_len, bool rtcp); 220 size_t FilterPacket(const void* data, size_t data_len, bool rtcp);
220 rtc::StreamResult WriteToStream(const void* data, size_t data_len); 221 rtc::StreamResult WriteToStream(const void* data, size_t data_len);
221 222
222 rtc::StreamInterface* stream_; 223 rtc::StreamInterface* stream_;
223 int packet_filter_; 224 int packet_filter_;
224 bool file_header_written_; 225 bool file_header_written_;
225 uint32 start_time_ms_; // Time when the record starts. 226 uint32_t start_time_ms_; // Time when the record starts.
226 // If writing to the stream takes longer than this many ms, log a warning. 227 // If writing to the stream takes longer than this many ms, log a warning.
227 uint32 warn_slow_writes_delay_; 228 uint32_t warn_slow_writes_delay_;
228 RTC_DISALLOW_COPY_AND_ASSIGN(RtpDumpWriter); 229 RTC_DISALLOW_COPY_AND_ASSIGN(RtpDumpWriter);
229 }; 230 };
230 231
231 } // namespace cricket 232 } // namespace cricket
232 233
233 #endif // TALK_MEDIA_BASE_RTPDUMP_H_ 234 #endif // TALK_MEDIA_BASE_RTPDUMP_H_
OLDNEW
« no previous file with comments | « talk/media/base/rtpdataengine_unittest.cc ('k') | talk/media/base/rtpdump.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698