2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-23 14:56:14 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_VIDEO_CODING_TEST_RTP_PLAYER_H_
|
|
|
|
|
#define WEBRTC_MODULES_VIDEO_CODING_TEST_RTP_PLAYER_H_
|
|
|
|
|
|
|
|
|
|
#include "typedefs.h"
|
|
|
|
|
#include "rtp_rtcp.h"
|
|
|
|
|
#include "critical_section_wrapper.h"
|
|
|
|
|
#include "video_coding_defines.h"
|
2013-01-21 07:42:11 +00:00
|
|
|
#include "webrtc/system_wrappers/interface/clock.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-01-23 14:56:14 +00:00
|
|
|
#include <list>
|
2011-07-07 08:21:25 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#define HDR_SIZE 8 // rtpplay packet header size in bytes
|
|
|
|
|
#define FIRSTLINELEN 40
|
|
|
|
|
#define RAND_VEC_LENGTH 4096
|
|
|
|
|
|
2012-01-23 15:23:31 +00:00
|
|
|
struct PayloadCodecTuple;
|
2012-01-23 14:56:14 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
struct RawRtpPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2013-04-02 15:54:38 +00:00
|
|
|
RawRtpPacket(uint8_t* rtp_data, uint16_t rtp_length);
|
2011-07-07 08:21:25 +00:00
|
|
|
~RawRtpPacket();
|
|
|
|
|
|
2012-01-23 14:56:14 +00:00
|
|
|
uint8_t* data;
|
|
|
|
|
uint16_t length;
|
|
|
|
|
int64_t resend_time_ms;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2012-01-23 14:56:14 +00:00
|
|
|
typedef std::list<PayloadCodecTuple*> PayloadTypeList;
|
|
|
|
|
typedef std::list<RawRtpPacket*> RtpPacketList;
|
|
|
|
|
typedef RtpPacketList::iterator RtpPacketIterator;
|
|
|
|
|
typedef RtpPacketList::const_iterator ConstRtpPacketIterator;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-01-23 14:56:14 +00:00
|
|
|
class LostPackets {
|
|
|
|
|
public:
|
|
|
|
|
LostPackets();
|
|
|
|
|
~LostPackets();
|
|
|
|
|
|
|
|
|
|
void AddPacket(RawRtpPacket* packet);
|
|
|
|
|
void SetResendTime(uint16_t sequenceNumber,
|
|
|
|
|
int64_t resendTime,
|
|
|
|
|
int64_t nowMs);
|
|
|
|
|
RawRtpPacket* NextPacketToResend(int64_t timeNow);
|
|
|
|
|
int NumberOfPacketsToResend() const;
|
|
|
|
|
void SetPacketResent(uint16_t seqNo, int64_t nowMs);
|
|
|
|
|
void Print() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
webrtc::CriticalSectionWrapper* crit_sect_;
|
|
|
|
|
int loss_count_;
|
|
|
|
|
FILE* debug_file_;
|
|
|
|
|
RtpPacketList packets_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PayloadCodecTuple
|
|
|
|
|
{
|
2013-04-02 15:54:38 +00:00
|
|
|
PayloadCodecTuple(uint8_t plType, std::string codecName, webrtc::VideoCodecType type) :
|
2011-07-07 08:21:25 +00:00
|
|
|
name(codecName), payloadType(plType), codecType(type) {};
|
|
|
|
|
const std::string name;
|
2013-04-02 15:54:38 +00:00
|
|
|
const uint8_t payloadType;
|
2011-07-07 08:21:25 +00:00
|
|
|
const webrtc::VideoCodecType codecType;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RTPPlayer : public webrtc::VCMPacketRequestCallback
|
|
|
|
|
{
|
|
|
|
|
public:
|
2011-12-21 15:24:01 +00:00
|
|
|
RTPPlayer(const char* filename,
|
|
|
|
|
webrtc::RtpData* callback,
|
2013-01-21 07:42:11 +00:00
|
|
|
webrtc::Clock* clock);
|
2011-07-07 08:21:25 +00:00
|
|
|
virtual ~RTPPlayer();
|
|
|
|
|
|
2013-04-02 15:54:38 +00:00
|
|
|
int32_t Initialize(const PayloadTypeList* payloadList);
|
|
|
|
|
int32_t NextPacket(const int64_t timeNow);
|
|
|
|
|
uint32_t TimeUntilNextPacket() const;
|
|
|
|
|
int32_t SimulatePacketLoss(float lossRate, bool enableNack = false, uint32_t rttMs = 0);
|
|
|
|
|
int32_t SetReordering(bool enabled);
|
|
|
|
|
int32_t ResendPackets(const uint16_t* sequenceNumbers, uint16_t length);
|
2011-07-07 08:21:25 +00:00
|
|
|
void Print() const;
|
|
|
|
|
|
|
|
|
|
private:
|
2013-04-02 15:54:38 +00:00
|
|
|
int32_t SendPacket(uint8_t* rtpData, uint16_t rtpLen);
|
|
|
|
|
int32_t ReadPacket(int16_t* rtpdata, uint32_t* offset);
|
|
|
|
|
int32_t ReadHeader();
|
2013-01-21 07:42:11 +00:00
|
|
|
webrtc::Clock* _clock;
|
2011-07-07 08:21:25 +00:00
|
|
|
FILE* _rtpFile;
|
2012-05-11 11:08:54 +00:00
|
|
|
webrtc::RtpRtcp* _rtpModule;
|
2013-04-02 15:54:38 +00:00
|
|
|
uint32_t _nextRtpTime;
|
2011-07-07 08:21:25 +00:00
|
|
|
webrtc::RtpData* _dataCallback;
|
|
|
|
|
bool _firstPacket;
|
|
|
|
|
float _lossRate;
|
|
|
|
|
bool _nackEnabled;
|
|
|
|
|
LostPackets _lostPackets;
|
2013-04-02 15:54:38 +00:00
|
|
|
uint32_t _resendPacketCount;
|
|
|
|
|
int32_t _noLossStartup;
|
2011-07-07 08:21:25 +00:00
|
|
|
bool _endOfFile;
|
2013-04-02 15:54:38 +00:00
|
|
|
uint32_t _rttMs;
|
|
|
|
|
int64_t _firstPacketRtpTime;
|
|
|
|
|
int64_t _firstPacketTimeMs;
|
2011-07-07 08:21:25 +00:00
|
|
|
RawRtpPacket* _reorderBuffer;
|
|
|
|
|
bool _reordering;
|
2013-04-02 15:54:38 +00:00
|
|
|
int16_t _nextPacket[8000];
|
|
|
|
|
int32_t _nextPacketLength;
|
2011-07-07 08:21:25 +00:00
|
|
|
int _randVec[RAND_VEC_LENGTH];
|
|
|
|
|
int _randVecPos;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_MODULES_VIDEO_CODING_TEST_RTP_PLAYER_H_
|