Skip to content

Commit

Permalink
for ossrs#250, refine parse pes packet, remove the clear method.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jan 29, 2015
1 parent 1685cdd commit b38bae2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
29 changes: 13 additions & 16 deletions trunk/src/kernel/srs_kernel_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,15 @@ SrsTsChannel::~SrsTsChannel()
srs_freep(msg);
}

SrsTsMessage::SrsTsMessage()
SrsTsMessage::SrsTsMessage(SrsTsChannel* c, SrsTsPacket* p)
{
payload = NULL;
clear();
channel = c;
packet = p;

dts = pts = 0;
continuity_counter = 0;
PES_packet_length = 0;
payload = new SrsSimpleBuffer();
}

SrsTsMessage::~SrsTsMessage()
Expand Down Expand Up @@ -469,15 +474,6 @@ bool SrsTsMessage::fresh()
return payload->length() == 0;
}

void SrsTsMessage::clear()
{
dts = pts = 0;
continuity_counter = 0;
PES_packet_length = 0;
srs_freep(payload);
payload = new SrsSimpleBuffer();
}

ISrsTsHandler::ISrsTsHandler()
{
}
Expand Down Expand Up @@ -941,7 +937,7 @@ int SrsTsPayloadPES::decode(SrsStream* stream, SrsTsMessage** ppmsg)
// init msg.
SrsTsMessage* msg = channel->msg;
if (!msg) {
msg = new SrsTsMessage();
msg = new SrsTsMessage(channel, packet);
channel->msg = msg;
}

Expand All @@ -967,7 +963,8 @@ int SrsTsPayloadPES::decode(SrsStream* stream, SrsTsMessage** ppmsg)

// reparse current msg.
stream->skip(stream->pos() * -1);
msg->clear();
srs_freep(msg);
channel->msg = NULL;
return ERROR_SUCCESS;
}

Expand All @@ -991,7 +988,8 @@ int SrsTsPayloadPES::decode(SrsStream* stream, SrsTsMessage** ppmsg)

// reparse current msg.
stream->skip(stream->pos() * -1);
msg->clear();
srs_freep(msg);
channel->msg = NULL;
return ERROR_SUCCESS;
}
}
Expand All @@ -1005,7 +1003,6 @@ int SrsTsPayloadPES::decode(SrsStream* stream, SrsTsMessage** ppmsg)

// reparse current msg.
stream->skip(stream->pos() * -1);

return ret;
}

Expand Down
10 changes: 5 additions & 5 deletions trunk/src/kernel/srs_kernel_ts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SrsSimpleBuffer;
class SrsTsAdaptationField;
class SrsTsPayload;
class SrsTsMessage;
class SrsTsPacket;

// Transport Stream packets are 188 bytes in length.
#define SRS_TS_PACKET_SIZE 188
Expand Down Expand Up @@ -192,14 +193,17 @@ struct SrsTsChannel
*/
class SrsTsMessage
{
private:
SrsTsChannel* channel;
SrsTsPacket* packet;
public:
int64_t dts;
int64_t pts;
u_int16_t PES_packet_length;
u_int8_t continuity_counter;
SrsSimpleBuffer* payload;
public:
SrsTsMessage();
SrsTsMessage(SrsTsChannel* c, SrsTsPacket* p);
virtual ~SrsTsMessage();
public:
/**
Expand All @@ -219,10 +223,6 @@ class SrsTsMessage
* whether the message is fresh.
*/
virtual bool fresh();
/**
* clear current message.
*/
virtual void clear();
};

/**
Expand Down

0 comments on commit b38bae2

Please sign in to comment.