UTest: Fix utest warnings.

pull/3201/head
winlin 2 years ago
parent cfbbe3044f
commit 9c81a0e1bd

@ -7246,20 +7246,11 @@ string SrsConfig::get_https_api_listen()
{
SRS_OVERWRITE_BY_ENV_STRING("srs.http_api.https.listen");
#ifdef SRS_UTEST
// We should not use static default, because we need to reset for different testcase.
string DEFAULT = "";
#else
static string DEFAULT = "";
#endif
// We should not use static default, because we need to reset for different use scenarios.
string DEFAULT = "1990";
// Follow the HTTPS server if config HTTP API as the same of HTTP server.
if (DEFAULT.empty()) {
if (get_http_api_listen() == get_http_stream_listen()) {
DEFAULT = get_https_stream_listen();
} else {
DEFAULT = "1990";
}
}
SrsConfDirective* conf = get_https_api();

@ -172,7 +172,7 @@ private:
public:
SrsFastCoroutine(std::string n, ISrsCoroutineHandler* h);
SrsFastCoroutine(std::string n, ISrsCoroutineHandler* h, SrsContextId cid);
~SrsFastCoroutine();
virtual ~SrsFastCoroutine();
public:
void set_stack_size(int v);
public:

@ -2047,7 +2047,7 @@ std::string SrsApmSpan::text_propagator()
// For text based propagation, for example, HTTP header "Traceparent: 00-bb8dedf16c53ab4b6ceb1f4ca6d985bb-29247096662468ab-01"
// About the "%.2x", please see https://www.quora.com/What-does-2x-do-in-C-code for detail.
int nn = snprintf(buf, sizeof(buf), "%.2x-%s-%s-%.2x", supportedVersion, ctx_->trace_id_.c_str(), ctx_->span_id_.c_str(), FlagsSampled);
if (nn > 0 && nn < sizeof(buf)) {
if (nn > 0 && nn < (int)sizeof(buf)) {
return string(buf, nn);
}

@ -91,6 +91,11 @@ std::string SrsCplxError::summary() {
if (_summary.empty()) {
stringstream ss;
ss << "code=" << code;
string code_str = srs_error_code_str(this);
if (!code_str.empty()) ss << "(" << code_str << ")";
SrsCplxError* next = this;
while (next) {
ss << " : " << next->msg;

@ -349,11 +349,6 @@ srs_error_t SrsTsContext::encode(ISrsStreamWriter* writer, SrsTsMessage* msg, Sr
}
}
void SrsTsContext::set_sync_byte(int8_t sb)
{
sync_byte = sb;
}
srs_error_t SrsTsContext::encode_pat_pmt(ISrsStreamWriter* writer, int16_t vpid, SrsTsStream vs, int16_t apid, SrsTsStream as)
{
srs_error_t err = srs_success;
@ -812,24 +807,24 @@ SrsTsPacket* SrsTsPacket::create_pes_first(SrsTsContext* context,
// LCOV_EXCL_STOP
}
pes->packet_start_code_prefix = 0x01;
pes->stream_id = (uint8_t)sid;
pes->PES_packet_length = (size > 0xFFFF)? 0:size;
pes->PES_scrambling_control = 0;
pes->PES_priority = 0;
pes->data_alignment_indicator = 0;
pes->copyright = 0;
pes->original_or_copy = 0;
pes->PTS_DTS_flags = (dts == pts)? 0x02:0x03;
pes->ESCR_flag = 0;
pes->ES_rate_flag = 0;
pes->DSM_trick_mode_flag = 0;
pes->additional_copy_info_flag = 0;
pes->PES_CRC_flag = 0;
pes->PES_extension_flag = 0;
pes->PES_header_data_length = 0; // calc in size.
pes->pts = pts;
pes->dts = dts;
pes->pes.packet_start_code_prefix = 0x01;
pes->pes.stream_id = (uint8_t)sid;
pes->pes.PES_packet_length = (size > 0xFFFF)? 0:size;
pes->pes.PES_scrambling_control = 0;
pes->pes.PES_priority = 0;
pes->pes.data_alignment_indicator = 0;
pes->pes.copyright = 0;
pes->pes.original_or_copy = 0;
pes->pes.PTS_DTS_flags = (dts == pts)? 0x02:0x03;
pes->pes.ESCR_flag = 0;
pes->pes.ES_rate_flag = 0;
pes->pes.DSM_trick_mode_flag = 0;
pes->pes.additional_copy_info_flag = 0;
pes->pes.PES_CRC_flag = 0;
pes->pes.PES_extension_flag = 0;
pes->pes.PES_header_data_length = 0; // calc in size.
pes->pes.pts = pts;
pes->pes.dts = dts;
return pkt;
}
@ -1249,7 +1244,7 @@ SrsTsPayload::~SrsTsPayload()
{
}
SrsTsPayloadPES::SrsTsPayloadPES(SrsTsPacket* p) : SrsTsPayload(p)
SrsMpegPES::SrsMpegPES()
{
nb_stuffings = 0;
nb_bytes = 0;
@ -1291,97 +1286,19 @@ SrsTsPayloadPES::SrsTsPayloadPES(SrsTsPacket* p) : SrsTsPayload(p)
original_stuff_length = 0;
P_STD_buffer_scale = 0;
P_STD_buffer_size = 0;
has_payload_ = false;
nb_payload_ = 0;
}
SrsTsPayloadPES::~SrsTsPayloadPES()
SrsMpegPES::~SrsMpegPES()
{
}
srs_error_t SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
srs_error_t SrsMpegPES::decode(SrsBuffer* stream)
{
srs_error_t err = srs_success;
// find the channel from chunk.
SrsTsChannel* channel = packet->context->get(packet->pid);
if (!channel) {
return srs_error_new(ERROR_STREAM_CASTER_TS_PSE, "ts: demux PES no channel for pid=%#x", packet->pid);
}
// init msg.
SrsTsMessage* msg = channel->msg;
if (!msg) {
msg = new SrsTsMessage(channel, packet);
channel->msg = msg;
}
// we must cache the fresh state of msg,
// for the PES_packet_length is 0, the first payload_unit_start_indicator always 1,
// so should check for the fresh and not completed it.
bool is_fresh_msg = msg->fresh();
// check when fresh, the payload_unit_start_indicator
// should be 1 for the fresh msg.
if (is_fresh_msg && !packet->payload_unit_start_indicator) {
return srs_error_new(ERROR_STREAM_CASTER_TS_PSE, "ts: PES fresh packet length=%d, us=%d, cc=%d",
msg->PES_packet_length, packet->payload_unit_start_indicator, packet->continuity_counter);
}
// check when not fresh and PES_packet_length>0,
// the payload_unit_start_indicator should never be 1 when not completed.
if (!is_fresh_msg && msg->PES_packet_length > 0 && !msg->completed(packet->payload_unit_start_indicator) && packet->payload_unit_start_indicator) {
srs_warn("ts: ignore PES packet length=%d, payload=%d, us=%d, cc=%d",
msg->PES_packet_length, msg->payload->length(), packet->payload_unit_start_indicator, packet->continuity_counter);
// reparse current msg.
stream->skip(stream->pos() * -1);
srs_freep(msg);
channel->msg = NULL;
return err;
}
// check the continuity counter
if (!is_fresh_msg) {
// late-incoming or duplicated continuity, drop message.
// @remark check overflow, the counter plus 1 should greater when invalid.
if (msg->continuity_counter >= packet->continuity_counter && ((msg->continuity_counter + 1) & 0x0f) > packet->continuity_counter) {
srs_warn("ts: drop PES %dB for duplicated cc=%#x", msg->continuity_counter);
stream->skip(stream->size() - stream->pos());
return err;
}
// when got partially message, the continous count must be continuous, or drop it.
if (((msg->continuity_counter + 1) & 0x0f) != packet->continuity_counter) {
srs_warn("ts: ignore continuity must be continous, msg=%#x, packet=%#x", msg->continuity_counter, packet->continuity_counter);
// reparse current msg.
stream->skip(stream->pos() * -1);
srs_freep(msg);
channel->msg = NULL;
return err;
}
}
msg->continuity_counter = packet->continuity_counter;
// for the PES_packet_length(0), reap when completed.
if (!is_fresh_msg && msg->completed(packet->payload_unit_start_indicator)) {
// reap previous PES packet.
*ppmsg = msg;
channel->msg = NULL;
// reparse current msg.
stream->skip(stream->pos() * -1);
return err;
}
// contious packet, append bytes for unit start is 0
if (!packet->payload_unit_start_indicator) {
if ((err = msg->dump(stream, &nb_bytes)) != srs_success) {
return srs_error_wrap(err, "ts: pes dump");
}
}
// when unit start, parse the fresh msg.
if (packet->payload_unit_start_indicator) {
// 6B fixed header.
if (!stream->require(6)) {
return srs_error_new(ERROR_STREAM_CASTER_TS_PSE, "ts: demux PSE");
@ -1403,8 +1320,6 @@ srs_error_t SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
// @remark the sid indicates the elementary stream format.
// the SrsTsPESStreamIdAudio and SrsTsPESStreamIdVideo is start by 0b110 or 0b1110
SrsTsPESStreamId sid = (SrsTsPESStreamId)stream_id;
msg->sid = sid;
if (sid != SrsTsPESStreamIdProgramStreamMap
&& sid != SrsTsPESStreamIdPaddingStream
&& sid != SrsTsPESStreamIdPrivateStream2
@ -1462,10 +1377,6 @@ srs_error_t SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
return srs_error_wrap(err, "dts/pts");
}
dts = pts;
// update the dts and pts of message.
msg->dts = dts;
msg->pts = pts;
}
// 10B
@ -1481,10 +1392,6 @@ srs_error_t SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
if (dts - pts > 90000 || pts - dts > 90000) {
srs_warn("ts: sync dts=%" PRId64 ", pts=%" PRId64, dts, pts);
}
// update the dts and pts of message.
msg->dts = dts;
msg->pts = pts;
}
// Ignore coverage bellow, for we don't use them in HLS.
@ -1627,21 +1534,24 @@ srs_error_t SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
// indicated in the PES_packet_length minus the number of bytes
// between the last byte of the PES_packet_length field and the
// first PES_packet_data_byte.
/**
* when actual packet length > 0xffff(65535),
* which exceed the max uint16_t packet length,
* use 0 packet length, the next unit start indicates the end of packet.
*/
//
// If the actual size > uin16_t, which exceed the PES_packet_length, then PES_packet_length is 0, and we
// should dump all left bytes in stream to message util next unit start packet.
// Otherwise, the PES_packet_length should greater than 0, which is a specified length, then we also dump
// the left bytes in stream, in such case, the nb_payload_ is the actual size of payload.
if (PES_packet_length > 0) {
int nb_packet = PES_packet_length - (stream->pos() - pos_packet);
msg->PES_packet_length = srs_max(0, nb_packet);
if (nb_packet < 0) {
return srs_error_new(ERROR_STREAM_CASTER_TS_PSE, "ts: Invalid PES_packet_length=%d, pos_packet=%d, pos=%d", PES_packet_length, pos_packet, stream->pos());
}
// xB
if ((err = msg->dump(stream, &nb_bytes)) != srs_success) {
return srs_error_wrap(err, "dump pes");
nb_payload_ = nb_packet;
}
// Now, it has payload. The size is specified by PES_packet_length, which might be:
// 0, Dump all bytes in stream util next unit start packet.
// nb_payload_, Dump specified bytes in stream.
has_payload_ = true;
// Ignore coverage bellow, for we don't use them in HLS.
// LCOV_EXCL_START
} else if (sid == SrsTsPESStreamIdProgramStreamMap
@ -1656,10 +1566,9 @@ srs_error_t SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
// PES_packet_data_byte
// }
// xB
if ((err = msg->dump(stream, &nb_bytes)) != srs_success) {
return srs_error_wrap(err, "dump packet");
}
// The pos_packet equals to stream pos, so the PES_packet_length is actually the payload length.
nb_payload_ = PES_packet_length;
has_payload_ = true;
} else if (sid == SrsTsPESStreamIdPaddingStream) {
// for (i = 0; i < PES_packet_length; i++) {
// padding_byte
@ -1674,26 +1583,11 @@ srs_error_t SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
stream->skip(nb_drop);
srs_warn("ts: drop the pes packet %dB for stream_id=%#x", nb_drop, stream_id);
}
}
// when fresh and the PES_packet_length is 0,
// the payload_unit_start_indicator always be 1,
// the message should never EOF for the first packet.
if (is_fresh_msg && msg->PES_packet_length == 0) {
return err;
}
// check msg, reap when completed.
if (msg->completed(packet->payload_unit_start_indicator)) {
*ppmsg = msg;
channel->msg = NULL;
srs_info("ts: reap msg for completed.");
}
return err;
}
int SrsTsPayloadPES::size()
int SrsMpegPES::size()
{
int sz = 0;
@ -1753,7 +1647,7 @@ int SrsTsPayloadPES::size()
return sz;
}
srs_error_t SrsTsPayloadPES::encode(SrsBuffer* stream)
srs_error_t SrsMpegPES::encode(SrsBuffer* stream)
{
srs_error_t err = srs_success;
@ -1909,7 +1803,7 @@ srs_error_t SrsTsPayloadPES::encode(SrsBuffer* stream)
return err;
}
srs_error_t SrsTsPayloadPES::decode_33bits_dts_pts(SrsBuffer* stream, int64_t* pv)
srs_error_t SrsMpegPES::decode_33bits_dts_pts(SrsBuffer* stream, int64_t* pv)
{
srs_error_t err = srs_success;
@ -1960,7 +1854,7 @@ srs_error_t SrsTsPayloadPES::decode_33bits_dts_pts(SrsBuffer* stream, int64_t* p
return err;
}
srs_error_t SrsTsPayloadPES::encode_33bits_dts_pts(SrsBuffer* stream, uint8_t fb, int64_t v)
srs_error_t SrsMpegPES::encode_33bits_dts_pts(SrsBuffer* stream, uint8_t fb, int64_t v)
{
srs_error_t err = srs_success;
@ -1987,6 +1881,147 @@ srs_error_t SrsTsPayloadPES::encode_33bits_dts_pts(SrsBuffer* stream, uint8_t fb
return err;
}
SrsTsPayloadPES::SrsTsPayloadPES(SrsTsPacket* p) : SrsTsPayload(p)
{
}
SrsTsPayloadPES::~SrsTsPayloadPES()
{
}
srs_error_t SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
{
srs_error_t err = srs_success;
// find the channel from chunk.
SrsTsChannel* channel = packet->context->get(packet->pid);
if (!channel) {
return srs_error_new(ERROR_STREAM_CASTER_TS_PSE, "ts: demux PES no channel for pid=%#x", packet->pid);
}
// init msg.
SrsTsMessage* msg = channel->msg;
if (!msg) {
msg = new SrsTsMessage(channel, packet);
channel->msg = msg;
}
// we must cache the fresh state of msg,
// for the PES_packet_length is 0, the first payload_unit_start_indicator always 1,
// so should check for the fresh and not completed it.
bool is_fresh_msg = msg->fresh();
// check when fresh, the payload_unit_start_indicator
// should be 1 for the fresh msg.
if (is_fresh_msg && !packet->payload_unit_start_indicator) {
return srs_error_new(ERROR_STREAM_CASTER_TS_PSE, "ts: PES fresh packet length=%d, us=%d, cc=%d",
msg->PES_packet_length, packet->payload_unit_start_indicator, packet->continuity_counter);
}
// check when not fresh and PES_packet_length>0,
// the payload_unit_start_indicator should never be 1 when not completed.
if (!is_fresh_msg && msg->PES_packet_length > 0 && !msg->completed(packet->payload_unit_start_indicator) && packet->payload_unit_start_indicator) {
srs_warn("ts: ignore PES packet length=%d, payload=%d, us=%d, cc=%d",
msg->PES_packet_length, msg->payload->length(), packet->payload_unit_start_indicator, packet->continuity_counter);
// reparse current msg.
stream->skip(stream->pos() * -1);
srs_freep(msg);
channel->msg = NULL;
return err;
}
// check the continuity counter
if (!is_fresh_msg) {
// late-incoming or duplicated continuity, drop message.
// @remark check overflow, the counter plus 1 should greater when invalid.
if (msg->continuity_counter >= packet->continuity_counter && ((msg->continuity_counter + 1) & 0x0f) > packet->continuity_counter) {
srs_warn("ts: drop PES %dB for duplicated cc=%#x", msg->continuity_counter);
stream->skip(stream->size() - stream->pos());
return err;
}
// when got partially message, the continous count must be continuous, or drop it.
if (((msg->continuity_counter + 1) & 0x0f) != packet->continuity_counter) {
srs_warn("ts: ignore continuity must be continous, msg=%#x, packet=%#x", msg->continuity_counter, packet->continuity_counter);
// reparse current msg.
stream->skip(stream->pos() * -1);
srs_freep(msg);
channel->msg = NULL;
return err;
}
}
msg->continuity_counter = packet->continuity_counter;
// for the PES_packet_length(0), reap when completed.
if (!is_fresh_msg && msg->completed(packet->payload_unit_start_indicator)) {
// reap previous PES packet.
*ppmsg = msg;
channel->msg = NULL;
// reparse current msg.
stream->skip(stream->pos() * -1);
return err;
}
// contious packet, append bytes for unit start is 0
if (!packet->payload_unit_start_indicator) {
if ((err = msg->dump(stream, &pes.nb_bytes)) != srs_success) {
return srs_error_wrap(err, "ts: pes dump");
}
}
// when unit start, parse the fresh msg.
if (packet->payload_unit_start_indicator) {
if ((err = pes.decode(stream)) != srs_success) {
return srs_error_wrap(err, "header");
}
// Update message when decode the first PES packet.
msg->sid = (SrsTsPESStreamId)pes.stream_id;
if (pes.PTS_DTS_flags == 0x02 || pes.PTS_DTS_flags == 0x03) {
msg->dts = pes.dts;
msg->pts = pes.pts;
}
if (pes.has_payload_) {
// The size of message, might be 0 or a positive value.
msg->PES_packet_length = pes.nb_payload_;
// xB
if ((err = msg->dump(stream, &pes.nb_bytes)) != srs_success) {
return srs_error_wrap(err, "dump pes");
}
}
}
// when fresh and the PES_packet_length is 0,
// the payload_unit_start_indicator always be 1,
// the message should never EOF for the first packet.
if (is_fresh_msg && msg->PES_packet_length == 0) {
return err;
}
// check msg, reap when completed.
if (msg->completed(packet->payload_unit_start_indicator)) {
*ppmsg = msg;
channel->msg = NULL;
srs_info("ts: reap msg for completed.");
}
return err;
}
int SrsTsPayloadPES::size()
{
return pes.size();
}
srs_error_t SrsTsPayloadPES::encode(SrsBuffer* stream)
{
return pes.encode(stream);
}
SrsTsPayloadPSI::SrsTsPayloadPSI(SrsTsPacket* p) : SrsTsPayload(p)
{
pointer_field = 0;

@ -28,6 +28,7 @@ class SrsTsPayload;
class SrsTsMessage;
class SrsTsPacket;
class SrsTsContext;
class SrsPsPacket;
// Transport Stream packets are 188 bytes in length.
#define SRS_TS_PACKET_SIZE 188
@ -90,14 +91,14 @@ enum SrsTsPidApply
{
SrsTsPidApplyReserved = 0, // TSPidTypeReserved, nothing parsed, used reserved.
SrsTsPidApplyPAT, // Program associtate table
SrsTsPidApplyPMT, // Program map table.
SrsTsPidApplyPAT, // Program associtate table for TS.
SrsTsPidApplyPMT, // Program map table for TS.
SrsTsPidApplyVideo, // for video
SrsTsPidApplyAudio, // vor audio
};
// Table 2-29 - Stream type assignments
// Table 2-29 - Stream type assignments, hls-mpeg-ts-iso13818-1.pdf, page 66
enum SrsTsStream
{
// ITU-T | ISO/IEC Reserved
@ -215,9 +216,7 @@ enum SrsTsPESStreamId
class SrsTsMessage
{
public:
// For decoder only,
// the ts messgae does not use them,
// for user to get the channel and packet.
// For decoder only, the ts message does not use them, for user to get the channel and packet.
SrsTsChannel* channel;
SrsTsPacket* packet;
public:
@ -294,12 +293,10 @@ private:
// When PAT and PMT writen, the context is ready.
// @see https://github.com/ossrs/srs/issues/834
bool ready;
// codec
private:
std::map<int, SrsTsChannel*> pids;
bool pure_audio;
int8_t sync_byte;
// encoder
private:
// when any codec changed, write the PAT/PMT.
SrsVideoCodecId vcodec;
@ -315,31 +312,27 @@ public:
virtual void on_pmt_parsed();
// Reset the context for a new ts segment start.
virtual void reset();
// codec
public:
// Get the pid apply, the parsed pid.
// @return the apply channel; NULL for invalid.
virtual SrsTsChannel* get(int pid);
// Set the pid apply, the parsed pid.
virtual void set(int pid, SrsTsPidApply apply_pid, SrsTsStream stream = SrsTsStreamReserved);
// decode methods
public:
// The stream contains only one ts packet.
// @param handler the ts message handler to process the msg.
// @remark we will consume all bytes in stream.
// Feed with ts packets, decode as ts message, callback handler if got one ts message.
// A ts video message can be decoded to NALUs by SrsRawH264Stream::annexb_demux.
// A ts audio message can be decoded to RAW frame by SrsRawAacStream::adts_demux.
// @param handler The ts message handler to process the msg.
// @remark We will consume all bytes in stream.
virtual srs_error_t decode(SrsBuffer* stream, ISrsTsHandler* handler);
// encode methods
public:
// Write the PES packet, the video/audio stream.
// @param msg the video/audio msg to write to ts.
// @param vc the video codec, write the PAT/PMT table when changed.
// @param ac the audio codec, write the PAT/PMT table when changed.
// Encode ts video/audio messages to the PES packets, as PES stream.
// @param msg The video/audio msg to write to ts.
// A ts video message is a frame with one or more NALUs, generally encoded by SrsTsMessageCache.cache_video.
// A ts audio message is an audio packet, encoded by SrsTsMessageCache.cache_audio to ADTS for AAC.
// @param vc The video codec, write the PAT/PMT table when changed.
// @param ac The audio codec, write the PAT/PMT table when changed.
virtual srs_error_t encode(ISrsStreamWriter* writer, SrsTsMessage* msg, SrsVideoCodecId vc, SrsAudioCodecId ac);
// drm methods
public:
// Set sync byte of ts segment.
// replace the standard ts sync byte to bravo sync byte.
virtual void set_sync_byte(int8_t sb);
private:
virtual srs_error_t encode_pat_pmt(ISrsStreamWriter* writer, int16_t vpid, SrsTsStream vs, int16_t apid, SrsTsStream as);
virtual srs_error_t encode_pes(ISrsStreamWriter* writer, SrsTsMessage* msg, int16_t pid, SrsTsStream sid, bool pure_audio);
@ -741,9 +734,8 @@ public:
virtual srs_error_t encode(SrsBuffer* stream) = 0;
};
// The PES payload of ts packet.
// 2.4.3.6 PES packet, hls-mpeg-ts-iso13818-1.pdf, page 49
class SrsTsPayloadPES : public SrsTsPayload
// Common MPEG PES packet for both TS and PS.
class SrsMpegPES
{
public:
// 3B
@ -994,10 +986,14 @@ public:
// This is a fixed 8-bit value equal to '1111 1111'. It is discarded by the decoder.
int nb_paddings;
public:
SrsTsPayloadPES(SrsTsPacket* p);
virtual ~SrsTsPayloadPES();
// Whether contains payload to dump to message.
bool has_payload_;
int nb_payload_;
public:
virtual srs_error_t decode(SrsBuffer* stream, SrsTsMessage** ppmsg);
SrsMpegPES();
virtual ~SrsMpegPES();
public:
virtual srs_error_t decode(SrsBuffer* stream);
public:
virtual int size();
virtual srs_error_t encode(SrsBuffer* stream);
@ -1006,6 +1002,22 @@ private:
virtual srs_error_t encode_33bits_dts_pts(SrsBuffer* stream, uint8_t fb, int64_t v);
};
// The PES payload of ts packet.
// 2.4.3.6 PES packet, hls-mpeg-ts-iso13818-1.pdf, page 49
class SrsTsPayloadPES : public SrsTsPayload
{
public:
SrsMpegPES pes;
public:
SrsTsPayloadPES(SrsTsPacket* p);
virtual ~SrsTsPayloadPES();
public:
virtual srs_error_t decode(SrsBuffer* stream, SrsTsMessage** ppmsg);
public:
virtual int size();
virtual srs_error_t encode(SrsBuffer* stream);
};
// The PSI payload of ts packet.
// 2.4.4 Program specific information, hls-mpeg-ts-iso13818-1.pdf, page 59
class SrsTsPayloadPSI : public SrsTsPayload

@ -765,7 +765,7 @@ VOID TEST(KernelRTCTest, NACKEncode)
vector<uint16_t> before = rtcp_nack_encode.get_lost_sns();
vector<uint16_t> after = rtcp_nack_decode.get_lost_sns();
EXPECT_TRUE(before.size() == after.size());
for(int i = 0; i < before.size() && i < after.size(); ++i) {
for(int i = 0; i < (int)before.size() && i < (int)after.size(); ++i) {
EXPECT_TRUE(before.at(i) == after.at(i));
}
}
@ -932,11 +932,11 @@ VOID TEST(KernelRTCTest, Ntp)
// Cover systime to ntp
SrsNtp ntp = SrsNtp::from_time_ms(now_ms);
ASSERT_EQ(ntp.system_ms_, now_ms);
ASSERT_EQ((srs_utime_t)ntp.system_ms_, now_ms);
// Cover ntp to systime
SrsNtp ntp1 = SrsNtp::to_time_ms(ntp.ntp_);
ASSERT_EQ(ntp1.system_ms_, now_ms);
ASSERT_EQ((srs_utime_t)ntp1.system_ms_, now_ms);
}
}
@ -945,10 +945,10 @@ VOID TEST(KernelRTCTest, Ntp)
srs_utime_t now_ms = srs_get_system_time() / 1000;
SrsNtp ntp = SrsNtp::from_time_ms(now_ms);
ASSERT_EQ(ntp.system_ms_, now_ms);
ASSERT_EQ((srs_utime_t)ntp.system_ms_, now_ms);
SrsNtp ntp1 = SrsNtp::to_time_ms(ntp.ntp_);
ASSERT_EQ(ntp1.system_ms_, now_ms);
ASSERT_EQ((srs_utime_t)ntp1.system_ms_, now_ms);
}
}
@ -1279,46 +1279,46 @@ VOID TEST(KernelRTCTest, JitterTimestamp)
SrsRtcTsJitter jitter(1000);
// Starts from the base.
EXPECT_EQ(1000, jitter.correct(0));
EXPECT_EQ((uint32_t)1000, jitter.correct(0));
// Start from here.
EXPECT_EQ(1010, jitter.correct(10));
EXPECT_EQ(1010, jitter.correct(10));
EXPECT_EQ(1020, jitter.correct(20));
EXPECT_EQ((uint32_t)1010, jitter.correct(10));
EXPECT_EQ((uint32_t)1010, jitter.correct(10));
EXPECT_EQ((uint32_t)1020, jitter.correct(20));
// Reset the base for jitter detected.
EXPECT_EQ(1020, jitter.correct(20 + 90*3*1000 + 1));
EXPECT_EQ(1019, jitter.correct(20 + 90*3*1000));
EXPECT_EQ(1021, jitter.correct(20 + 90*3*1000 + 2));
EXPECT_EQ(1019, jitter.correct(20 + 90*3*1000));
EXPECT_EQ(1020, jitter.correct(20 + 90*3*1000 + 1));
EXPECT_EQ((uint32_t)1020, jitter.correct(20 + 90*3*1000 + 1));
EXPECT_EQ((uint32_t)1019, jitter.correct(20 + 90*3*1000));
EXPECT_EQ((uint32_t)1021, jitter.correct(20 + 90*3*1000 + 2));
EXPECT_EQ((uint32_t)1019, jitter.correct(20 + 90*3*1000));
EXPECT_EQ((uint32_t)1020, jitter.correct(20 + 90*3*1000 + 1));
// Rollback the timestamp.
EXPECT_EQ(1020, jitter.correct(20));
EXPECT_EQ(1021, jitter.correct(20 + 1));
EXPECT_EQ(1021, jitter.correct(21));
EXPECT_EQ((uint32_t)1020, jitter.correct(20));
EXPECT_EQ((uint32_t)1021, jitter.correct(20 + 1));
EXPECT_EQ((uint32_t)1021, jitter.correct(21));
// Reset for jitter again.
EXPECT_EQ(1021, jitter.correct(21 + 90*3*1000 + 1));
EXPECT_EQ(1021, jitter.correct(21));
EXPECT_EQ((uint32_t)1021, jitter.correct(21 + 90*3*1000 + 1));
EXPECT_EQ((uint32_t)1021, jitter.correct(21));
// No jitter at edge.
EXPECT_EQ(1021 + 90*3*1000, jitter.correct(21 + 90*3*1000));
EXPECT_EQ(1021 + 90*3*1000 + 1, jitter.correct(21 + 90*3*1000 + 1));
EXPECT_EQ(1021 + 1, jitter.correct(21 + 1));
EXPECT_EQ((uint32_t)(1021 + 90*3*1000), jitter.correct(21 + 90*3*1000));
EXPECT_EQ((uint32_t)(1021 + 90*3*1000 + 1), jitter.correct(21 + 90*3*1000 + 1));
EXPECT_EQ((uint32_t)(1021 + 1), jitter.correct(21 + 1));
// Also safety to decrease the value.
EXPECT_EQ(1021, jitter.correct(21));
EXPECT_EQ(1010, jitter.correct(10));
EXPECT_EQ((uint32_t)1021, jitter.correct(21));
EXPECT_EQ((uint32_t)1010, jitter.correct(10));
// Try to reset to 0 base.
EXPECT_EQ(1010, jitter.correct(10 + 90*3*1000 + 1010));
EXPECT_EQ(0, jitter.correct(10 + 90*3*1000));
EXPECT_EQ(0, jitter.correct(0));
EXPECT_EQ((uint32_t)1010, jitter.correct(10 + 90*3*1000 + 1010));
EXPECT_EQ((uint32_t)0, jitter.correct(10 + 90*3*1000));
EXPECT_EQ((uint32_t)0, jitter.correct(0));
// Also safety to start from zero.
EXPECT_EQ(10, jitter.correct(10));
EXPECT_EQ(11, jitter.correct(11));
EXPECT_EQ((uint32_t)10, jitter.correct(10));
EXPECT_EQ((uint32_t)11, jitter.correct(11));
}
VOID TEST(KernelRTCTest, JitterSequence)
@ -1326,45 +1326,45 @@ VOID TEST(KernelRTCTest, JitterSequence)
SrsRtcSeqJitter jitter(100);
// Starts from the base.
EXPECT_EQ(100, jitter.correct(0));
EXPECT_EQ((uint32_t)100, jitter.correct(0));
// Normal without jitter.
EXPECT_EQ(101, jitter.correct(1));
EXPECT_EQ(102, jitter.correct(2));
EXPECT_EQ(101, jitter.correct(1));
EXPECT_EQ(103, jitter.correct(3));
EXPECT_EQ(110, jitter.correct(10));
EXPECT_EQ((uint32_t)101, jitter.correct(1));
EXPECT_EQ((uint32_t)102, jitter.correct(2));
EXPECT_EQ((uint32_t)101, jitter.correct(1));
EXPECT_EQ((uint32_t)103, jitter.correct(3));
EXPECT_EQ((uint32_t)110, jitter.correct(10));
// Reset the base for jitter detected.
EXPECT_EQ(110, jitter.correct(10 + 128 + 1));
EXPECT_EQ(109, jitter.correct(10 + 128));
EXPECT_EQ(110, jitter.correct(10 + 128 + 1));
EXPECT_EQ((uint32_t)110, jitter.correct(10 + 128 + 1));
EXPECT_EQ((uint32_t)109, jitter.correct(10 + 128));
EXPECT_EQ((uint32_t)110, jitter.correct(10 + 128 + 1));
// Rollback the timestamp.
EXPECT_EQ(110, jitter.correct(10));
EXPECT_EQ(111, jitter.correct(10 + 1));
EXPECT_EQ(111, jitter.correct(11));
EXPECT_EQ((uint32_t)110, jitter.correct(10));
EXPECT_EQ((uint32_t)111, jitter.correct(10 + 1));
EXPECT_EQ((uint32_t)111, jitter.correct(11));
// Reset for jitter again.
EXPECT_EQ(111, jitter.correct(11 + 128 + 1));
EXPECT_EQ(111, jitter.correct(11));
EXPECT_EQ((uint32_t)111, jitter.correct(11 + 128 + 1));
EXPECT_EQ((uint32_t)111, jitter.correct(11));
// No jitter at edge.
EXPECT_EQ(111 + 128, jitter.correct(11 + 128));
EXPECT_EQ(111 + 128 + 1, jitter.correct(11 + 128 + 1));
EXPECT_EQ(111 + 1, jitter.correct(11 + 1));
EXPECT_EQ((uint32_t)(111 + 128), jitter.correct(11 + 128));
EXPECT_EQ((uint32_t)(111 + 128 + 1), jitter.correct(11 + 128 + 1));
EXPECT_EQ((uint32_t)(111 + 1), jitter.correct(11 + 1));
// Also safety to decrease the value.
EXPECT_EQ(111, jitter.correct(11));
EXPECT_EQ(110, jitter.correct(10));
EXPECT_EQ((uint32_t)111, jitter.correct(11));
EXPECT_EQ((uint32_t)110, jitter.correct(10));
// Try to reset to 0 base.
EXPECT_EQ(110, jitter.correct(10 + 128 + 110));
EXPECT_EQ(0, jitter.correct(10 + 128));
EXPECT_EQ(0, jitter.correct(0));
EXPECT_EQ((uint32_t)110, jitter.correct(10 + 128 + 110));
EXPECT_EQ((uint32_t)0, jitter.correct(10 + 128));
EXPECT_EQ((uint32_t)0, jitter.correct(0));
// Also safety to start from zero.
EXPECT_EQ(10, jitter.correct(10));
EXPECT_EQ(11, jitter.correct(11));
EXPECT_EQ((uint32_t)10, jitter.correct(10));
EXPECT_EQ((uint32_t)11, jitter.correct(11));
}

@ -275,22 +275,22 @@ VOID TEST(ServiceStSRTTest, ReadWrite)
// Client send msg to server.
ssize_t nb_write = 0;
HELPER_EXPECT_SUCCESS(srt_client_socket->sendmsg((char*)content.data(), content.size(), &nb_write));
EXPECT_EQ(nb_write, content.size());
EXPECT_EQ((size_t)nb_write, content.size());
// Server recv msg from client
char buf[1500];
ssize_t nb_read = 0;
HELPER_EXPECT_SUCCESS(srt_server_accepted_socket->recvmsg(buf, sizeof(buf), &nb_read));
EXPECT_EQ(nb_read, content.size());
EXPECT_EQ((size_t)nb_read, content.size());
EXPECT_EQ(std::string(buf, nb_read), content);
// Server echo msg back to client.
HELPER_EXPECT_SUCCESS(srt_server_accepted_socket->sendmsg(buf, nb_read, &nb_write));
EXPECT_EQ(nb_write, content.size());
EXPECT_EQ((size_t)nb_write, content.size());
// Client recv echo msg from server.
HELPER_EXPECT_SUCCESS(srt_client_socket->recvmsg(buf, sizeof(buf), &nb_read));
EXPECT_EQ(nb_read, content.size());
EXPECT_EQ((size_t)nb_read, content.size());
EXPECT_EQ(std::string(buf, nb_read), content);
}

Loading…
Cancel
Save