2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-04-12 11:02:38 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "RTPFile.h"
|
2011-11-23 12:20:35 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
#include <stdlib.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
#include <limits>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
#include <Winsock2.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-09-04 09:55:40 +00:00
|
|
|
// TODO(tlegrand): Consider removing usage of gtest.
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/gtest.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-16 10:09:04 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
|
2019-02-18 12:00:06 +01:00
|
|
|
void RTPStream::ParseRTPHeader(RTPHeader* rtp_header,
|
2013-05-03 07:34:12 +00:00
|
|
|
const uint8_t* rtpHeader) {
|
2019-02-18 12:00:06 +01:00
|
|
|
rtp_header->payloadType = rtpHeader[1];
|
|
|
|
|
rtp_header->sequenceNumber =
|
2013-05-03 07:34:12 +00:00
|
|
|
(static_cast<uint16_t>(rtpHeader[2]) << 8) | rtpHeader[3];
|
2019-02-18 12:00:06 +01:00
|
|
|
rtp_header->timestamp = (static_cast<uint32_t>(rtpHeader[4]) << 24) |
|
|
|
|
|
(static_cast<uint32_t>(rtpHeader[5]) << 16) |
|
|
|
|
|
(static_cast<uint32_t>(rtpHeader[6]) << 8) |
|
|
|
|
|
rtpHeader[7];
|
|
|
|
|
rtp_header->ssrc = (static_cast<uint32_t>(rtpHeader[8]) << 24) |
|
|
|
|
|
(static_cast<uint32_t>(rtpHeader[9]) << 16) |
|
|
|
|
|
(static_cast<uint32_t>(rtpHeader[10]) << 8) |
|
|
|
|
|
rtpHeader[11];
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
void RTPStream::MakeRTPheader(uint8_t* rtpHeader,
|
|
|
|
|
uint8_t payloadType,
|
|
|
|
|
int16_t seqNo,
|
|
|
|
|
uint32_t timeStamp,
|
|
|
|
|
uint32_t ssrc) {
|
2015-02-23 21:28:22 +00:00
|
|
|
rtpHeader[0] = 0x80;
|
|
|
|
|
rtpHeader[1] = payloadType;
|
|
|
|
|
rtpHeader[2] = (seqNo >> 8) & 0xFF;
|
|
|
|
|
rtpHeader[3] = seqNo & 0xFF;
|
|
|
|
|
rtpHeader[4] = timeStamp >> 24;
|
|
|
|
|
rtpHeader[5] = (timeStamp >> 16) & 0xFF;
|
|
|
|
|
rtpHeader[6] = (timeStamp >> 8) & 0xFF;
|
|
|
|
|
rtpHeader[7] = timeStamp & 0xFF;
|
|
|
|
|
rtpHeader[8] = ssrc >> 24;
|
|
|
|
|
rtpHeader[9] = (ssrc >> 16) & 0xFF;
|
|
|
|
|
rtpHeader[10] = (ssrc >> 8) & 0xFF;
|
|
|
|
|
rtpHeader[11] = ssrc & 0xFF;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
RTPPacket::RTPPacket(uint8_t payloadType,
|
|
|
|
|
uint32_t timeStamp,
|
|
|
|
|
int16_t seqNo,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const uint8_t* payloadData,
|
|
|
|
|
size_t payloadSize,
|
2013-05-03 07:34:12 +00:00
|
|
|
uint32_t frequency)
|
|
|
|
|
: payloadType(payloadType),
|
|
|
|
|
timeStamp(timeStamp),
|
|
|
|
|
seqNo(seqNo),
|
|
|
|
|
payloadSize(payloadSize),
|
|
|
|
|
frequency(frequency) {
|
|
|
|
|
if (payloadSize > 0) {
|
|
|
|
|
this->payloadData = new uint8_t[payloadSize];
|
|
|
|
|
memcpy(this->payloadData, payloadData, payloadSize);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
RTPPacket::~RTPPacket() {
|
|
|
|
|
delete[] payloadData;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
void RTPBuffer::Write(const uint8_t payloadType,
|
|
|
|
|
const uint32_t timeStamp,
|
|
|
|
|
const int16_t seqNo,
|
|
|
|
|
const uint8_t* payloadData,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t payloadSize,
|
|
|
|
|
uint32_t frequency) {
|
2013-05-03 07:34:12 +00:00
|
|
|
RTPPacket* packet = new RTPPacket(payloadType, timeStamp, seqNo, payloadData,
|
|
|
|
|
payloadSize, frequency);
|
2020-10-28 14:05:07 +01:00
|
|
|
MutexLock lock(&mutex_);
|
2013-05-03 07:34:12 +00:00
|
|
|
_rtpQueue.push(packet);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-18 12:00:06 +01:00
|
|
|
size_t RTPBuffer::Read(RTPHeader* rtp_header,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
uint8_t* payloadData,
|
|
|
|
|
size_t payloadSize,
|
|
|
|
|
uint32_t* offset) {
|
2020-10-28 14:05:07 +01:00
|
|
|
RTPPacket* packet;
|
|
|
|
|
{
|
|
|
|
|
MutexLock lock(&mutex_);
|
|
|
|
|
packet = _rtpQueue.front();
|
|
|
|
|
_rtpQueue.pop();
|
|
|
|
|
}
|
2019-02-18 12:00:06 +01:00
|
|
|
rtp_header->markerBit = 1;
|
|
|
|
|
rtp_header->payloadType = packet->payloadType;
|
|
|
|
|
rtp_header->sequenceNumber = packet->seqNo;
|
|
|
|
|
rtp_header->ssrc = 0;
|
|
|
|
|
rtp_header->timestamp = packet->timeStamp;
|
2013-05-03 07:34:12 +00:00
|
|
|
if (packet->payloadSize > 0 && payloadSize >= packet->payloadSize) {
|
|
|
|
|
memcpy(payloadData, packet->payloadData, packet->payloadSize);
|
|
|
|
|
} else {
|
2014-09-25 07:38:14 +00:00
|
|
|
return 0;
|
2013-05-03 07:34:12 +00:00
|
|
|
}
|
|
|
|
|
*offset = (packet->timeStamp / (packet->frequency / 1000));
|
|
|
|
|
|
|
|
|
|
return packet->payloadSize;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
bool RTPBuffer::EndOfFile() const {
|
2020-10-28 14:05:07 +01:00
|
|
|
MutexLock lock(&mutex_);
|
|
|
|
|
return _rtpQueue.empty();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
void RTPFile::Open(const char* filename, const char* mode) {
|
|
|
|
|
if ((_rtpFile = fopen(filename, mode)) == NULL) {
|
|
|
|
|
printf("Cannot write file %s.\n", filename);
|
|
|
|
|
ADD_FAILURE() << "Unable to write file";
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
void RTPFile::Close() {
|
|
|
|
|
if (_rtpFile != NULL) {
|
|
|
|
|
fclose(_rtpFile);
|
|
|
|
|
_rtpFile = NULL;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
void RTPFile::WriteHeader() {
|
|
|
|
|
// Write data in a format that NetEQ and RTP Play can parse
|
|
|
|
|
fprintf(_rtpFile, "#!RTPencode%s\n", "1.0");
|
|
|
|
|
uint32_t dummy_variable = 0;
|
|
|
|
|
// should be converted to network endian format, but does not matter when 0
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
EXPECT_EQ(1u, fwrite(&dummy_variable, 4, 1, _rtpFile));
|
|
|
|
|
EXPECT_EQ(1u, fwrite(&dummy_variable, 4, 1, _rtpFile));
|
|
|
|
|
EXPECT_EQ(1u, fwrite(&dummy_variable, 4, 1, _rtpFile));
|
|
|
|
|
EXPECT_EQ(1u, fwrite(&dummy_variable, 2, 1, _rtpFile));
|
|
|
|
|
EXPECT_EQ(1u, fwrite(&dummy_variable, 2, 1, _rtpFile));
|
2013-05-03 07:34:12 +00:00
|
|
|
fflush(_rtpFile);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
void RTPFile::ReadHeader() {
|
|
|
|
|
uint32_t start_sec, start_usec, source;
|
|
|
|
|
uint16_t port, padding;
|
|
|
|
|
char fileHeader[40];
|
|
|
|
|
EXPECT_TRUE(fgets(fileHeader, 40, _rtpFile) != 0);
|
|
|
|
|
EXPECT_EQ(1u, fread(&start_sec, 4, 1, _rtpFile));
|
|
|
|
|
start_sec = ntohl(start_sec);
|
|
|
|
|
EXPECT_EQ(1u, fread(&start_usec, 4, 1, _rtpFile));
|
|
|
|
|
start_usec = ntohl(start_usec);
|
|
|
|
|
EXPECT_EQ(1u, fread(&source, 4, 1, _rtpFile));
|
|
|
|
|
source = ntohl(source);
|
|
|
|
|
EXPECT_EQ(1u, fread(&port, 2, 1, _rtpFile));
|
|
|
|
|
port = ntohs(port);
|
|
|
|
|
EXPECT_EQ(1u, fread(&padding, 2, 1, _rtpFile));
|
|
|
|
|
padding = ntohs(padding);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 00:28:06 +00:00
|
|
|
void RTPFile::Write(const uint8_t payloadType,
|
|
|
|
|
const uint32_t timeStamp,
|
|
|
|
|
const int16_t seqNo,
|
|
|
|
|
const uint8_t* payloadData,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
const size_t payloadSize,
|
|
|
|
|
uint32_t frequency) {
|
2013-05-03 07:34:12 +00:00
|
|
|
/* write RTP packet to file */
|
|
|
|
|
uint8_t rtpHeader[12];
|
|
|
|
|
MakeRTPheader(rtpHeader, payloadType, seqNo, timeStamp, 0);
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
ASSERT_LE(12 + payloadSize + 8, std::numeric_limits<u_short>::max());
|
|
|
|
|
uint16_t lengthBytes = htons(static_cast<u_short>(12 + payloadSize + 8));
|
|
|
|
|
uint16_t plen = htons(static_cast<u_short>(12 + payloadSize));
|
2013-05-03 07:34:12 +00:00
|
|
|
uint32_t offsetMs;
|
|
|
|
|
|
|
|
|
|
offsetMs = (timeStamp / (frequency / 1000));
|
|
|
|
|
offsetMs = htonl(offsetMs);
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
EXPECT_EQ(1u, fwrite(&lengthBytes, 2, 1, _rtpFile));
|
|
|
|
|
EXPECT_EQ(1u, fwrite(&plen, 2, 1, _rtpFile));
|
|
|
|
|
EXPECT_EQ(1u, fwrite(&offsetMs, 4, 1, _rtpFile));
|
|
|
|
|
EXPECT_EQ(1u, fwrite(&rtpHeader, 12, 1, _rtpFile));
|
|
|
|
|
EXPECT_EQ(payloadSize, fwrite(payloadData, 1, payloadSize, _rtpFile));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-18 12:00:06 +01:00
|
|
|
size_t RTPFile::Read(RTPHeader* rtp_header,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
uint8_t* payloadData,
|
|
|
|
|
size_t payloadSize,
|
|
|
|
|
uint32_t* offset) {
|
2013-05-03 07:34:12 +00:00
|
|
|
uint16_t lengthBytes;
|
|
|
|
|
uint16_t plen;
|
|
|
|
|
uint8_t rtpHeader[12];
|
|
|
|
|
size_t read_len = fread(&lengthBytes, 2, 1, _rtpFile);
|
|
|
|
|
/* Check if we have reached end of file. */
|
|
|
|
|
if ((read_len == 0) && feof(_rtpFile)) {
|
|
|
|
|
_rtpEOF = true;
|
2014-09-25 07:38:14 +00:00
|
|
|
return 0;
|
2013-05-03 07:34:12 +00:00
|
|
|
}
|
|
|
|
|
EXPECT_EQ(1u, fread(&plen, 2, 1, _rtpFile));
|
|
|
|
|
EXPECT_EQ(1u, fread(offset, 4, 1, _rtpFile));
|
|
|
|
|
lengthBytes = ntohs(lengthBytes);
|
|
|
|
|
plen = ntohs(plen);
|
|
|
|
|
*offset = ntohl(*offset);
|
|
|
|
|
EXPECT_GT(plen, 11);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(1u, fread(rtpHeader, 12, 1, _rtpFile));
|
2019-02-18 12:00:06 +01:00
|
|
|
ParseRTPHeader(rtp_header, rtpHeader);
|
2013-05-03 07:34:12 +00:00
|
|
|
EXPECT_EQ(lengthBytes, plen + 8);
|
|
|
|
|
|
|
|
|
|
if (plen == 0) {
|
2014-09-25 07:38:14 +00:00
|
|
|
return 0;
|
2013-05-03 07:34:12 +00:00
|
|
|
}
|
|
|
|
|
if (lengthBytes < 20) {
|
2014-09-25 07:38:14 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
if (payloadSize < static_cast<size_t>((lengthBytes - 20))) {
|
2014-09-25 07:38:14 +00:00
|
|
|
return 0;
|
2013-05-03 07:34:12 +00:00
|
|
|
}
|
|
|
|
|
lengthBytes -= 20;
|
|
|
|
|
EXPECT_EQ(lengthBytes, fread(payloadData, 1, lengthBytes, _rtpFile));
|
|
|
|
|
return lengthBytes;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-03 07:34:12 +00:00
|
|
|
} // namespace webrtc
|