winlin

drop metadata when drop sequence header. support PCUC 0x1a

... ... @@ -1463,7 +1463,11 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata
srs_verbose("initialize shared ptr metadata success.");
// copy to all consumer
if (true) {
bool drop_for_reduce = false;
if (cache_metadata && _srs_config->get_reduce_sequence_header(_req->vhost)) {
drop_for_reduce = true;
}
if (!drop_for_reduce) {
std::vector<SrsConsumer*>::iterator it;
for (it = consumers.begin(); it != consumers.end(); ++it) {
SrsConsumer* consumer = *it;
... ... @@ -2084,10 +2088,10 @@ void SrsSource::on_unpublish()
hds->on_unpublish();
#endif
// only clear the gop cache metadata,
// donot clear the sequence header, for it maybe not changed.
// only clear the gop cache,
// donot clear the sequence header, for it maybe not changed,
// when drop dup sequence header, drop the metadata also.
gop_cache->clear();
srs_freep(cache_metadata);
srs_info("clear cache/metadata when unpublish.");
srs_trace("cleanup when unpublish");
... ...
... ... @@ -4240,10 +4240,22 @@ int SrsPlayPacket::get_message_type()
int SrsPlayPacket::get_size()
{
return SrsAmf0Size::str(command_name) + SrsAmf0Size::number()
+ SrsAmf0Size::null() + SrsAmf0Size::str(stream_name)
+ SrsAmf0Size::number() + SrsAmf0Size::number()
+ SrsAmf0Size::boolean();
int size = SrsAmf0Size::str(command_name) + SrsAmf0Size::number()
+ SrsAmf0Size::null() + SrsAmf0Size::str(stream_name);
if (start != -2 || duration != -1 || !reset) {
size += SrsAmf0Size::number();
}
if (duration != -1 || !reset) {
size += SrsAmf0Size::number();
}
if (!reset) {
size += SrsAmf0Size::boolean();
}
return size;
}
int SrsPlayPacket::encode_packet(SrsStream* stream)
... ... @@ -4274,19 +4286,19 @@ int SrsPlayPacket::encode_packet(SrsStream* stream)
}
srs_verbose("encode stream_name success.");
if ((ret = srs_amf0_write_number(stream, start)) != ERROR_SUCCESS) {
if ((start != -2 || duration != -1 || !reset) && (ret = srs_amf0_write_number(stream, start)) != ERROR_SUCCESS) {
srs_error("encode start failed. ret=%d", ret);
return ret;
}
srs_verbose("encode start success.");
if ((ret = srs_amf0_write_number(stream, duration)) != ERROR_SUCCESS) {
if ((duration != -1 || !reset) && (ret = srs_amf0_write_number(stream, duration)) != ERROR_SUCCESS) {
srs_error("encode duration failed. ret=%d", ret);
return ret;
}
srs_verbose("encode duration success.");
if ((ret = srs_amf0_write_boolean(stream, reset)) != ERROR_SUCCESS) {
if (!reset && (ret = srs_amf0_write_boolean(stream, reset)) != ERROR_SUCCESS) {
srs_error("encode reset failed. ret=%d", ret);
return ret;
}
... ... @@ -5117,14 +5129,29 @@ int SrsUserControlPacket::decode(SrsStream* stream)
{
int ret = ERROR_SUCCESS;
if (!stream->require(6)) {
if (!stream->require(2)) {
ret = ERROR_RTMP_MESSAGE_DECODE;
srs_error("decode user control failed. ret=%d", ret);
return ret;
}
event_type = stream->read_2bytes();
event_data = stream->read_4bytes();
if (event_type == SrsPCUCFmsEvent0) {
if (!stream->require(1)) {
ret = ERROR_RTMP_MESSAGE_DECODE;
srs_error("decode user control failed. ret=%d", ret);
return ret;
}
event_data = stream->read_1bytes();
} else {
if (!stream->require(4)) {
ret = ERROR_RTMP_MESSAGE_DECODE;
srs_error("decode user control failed. ret=%d", ret);
return ret;
}
event_data = stream->read_4bytes();
}
if (event_type == SrcPCUCSetBufferLength) {
if (!stream->require(4)) {
... ... @@ -5154,11 +5181,19 @@ int SrsUserControlPacket::get_message_type()
int SrsUserControlPacket::get_size()
{
if (event_type == SrcPCUCSetBufferLength) {
return 2 + 4 + 4;
int size = 2;
if (event_type == SrsPCUCFmsEvent0) {
size += 1;
} else {
return 2 + 4;
size += 4;
}
if (event_type == SrcPCUCSetBufferLength) {
size += 4;
}
return size;
}
int SrsUserControlPacket::encode_packet(SrsStream* stream)
... ... @@ -5172,7 +5207,12 @@ int SrsUserControlPacket::encode_packet(SrsStream* stream)
}
stream->write_2bytes(event_type);
stream->write_4bytes(event_data);
if (event_type == SrsPCUCFmsEvent0) {
stream->write_1bytes(event_data);
} else {
stream->write_4bytes(event_data);
}
// when event type is set buffer length,
// write the extra buffer length.
... ...
... ... @@ -1991,6 +1991,13 @@ enum SrcPCUCEventType
* kMsgPingRequest request.
*/
SrcPCUCPingResponse = 0x07,
/**
* for PCUC size=3, the payload is "00 1A 01",
* where we think the event is 0x001a, fms defined msg,
* which has only 1bytes event data.
*/
SrsPCUCFmsEvent0 = 0x1a,
};
/**
... ... @@ -2019,6 +2026,11 @@ public:
* @see: SrcPCUCEventType
*/
int16_t event_type;
/**
* the event data generally in 4bytes.
* @remark for event type is 0x001a, only 1bytes.
* @see SrsPCUCFmsEvent0
*/
int32_t event_data;
/**
* 4bytes if event_type is SetBufferLength; otherwise 0.
... ...