1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 11:51:57 +00:00

Merge branch '2.0release' into develop

This commit is contained in:
winlin 2015-08-19 15:14:35 +08:00
commit a5dd3a8e7b
9 changed files with 54 additions and 26 deletions

View file

@ -875,8 +875,9 @@ vhost stream.control.com {
# delivery packets in constant interval(not cbr).
# @remark 0 to disable the minimal interval.
# @remark >0 to make the srs to send message one by one.
# @remark user can get the right packets interval in ms by srs_rtmp_dump.
# default: 0
send_min_interval 10;
send_min_interval 10.0;
# whether reduce the sequence header,
# for some client which cannot got duplicated sequence header,
# while the sequence header is not changed yet.

View file

@ -256,8 +256,10 @@ int main(int argc, char** argv)
}
}
int64_t nb_packets = 0;
u_int32_t pre_timestamp = 0;
int64_t pre_now = srs_utils_time_ms();
int64_t start_time = pre_now;
for (;;) {
int size;
char type;
@ -269,7 +271,7 @@ int main(int argc, char** argv)
goto rtmp_destroy;
}
if (srs_human_print_rtmp_packet3(type, timestamp, data, size, pre_timestamp, pre_now) != 0) {
if (srs_human_print_rtmp_packet4(type, timestamp, data, size, pre_timestamp, pre_now, start_time, nb_packets++) != 0) {
srs_human_trace("print rtmp packet failed.");
goto rtmp_destroy;
}

View file

@ -2518,9 +2518,9 @@ bool SrsConfig::get_tcp_nodelay(string vhost)
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
int SrsConfig::get_send_min_interval(string vhost)
double SrsConfig::get_send_min_interval(string vhost)
{
static int DEFAULT = 0;
static double DEFAULT = 0.0;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
@ -2532,7 +2532,7 @@ int SrsConfig::get_send_min_interval(string vhost)
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
return ::atof(conf->arg0().c_str());
}
bool SrsConfig::get_reduce_sequence_header(string vhost)

View file

@ -529,7 +529,7 @@ public:
/**
* the minimal send interval in ms.
*/
virtual int get_send_min_interval(std::string vhost);
virtual double get_send_min_interval(std::string vhost);
/**
* whether reduce the sequence header.
*/

View file

@ -256,9 +256,9 @@ int SrsRtmpConn::on_reload_vhost_smi(string vhost)
return ret;
}
int smi = _srs_config->get_send_min_interval(vhost);
double smi = _srs_config->get_send_min_interval(vhost);
if (smi != send_min_interval) {
srs_trace("apply smi %d=>%d", send_min_interval, smi);
srs_trace("apply smi %.2f=>%.2f", send_min_interval, smi);
send_min_interval = smi;
}
@ -615,7 +615,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
// set the sock options.
set_sock_options();
srs_trace("start play smi=%d, mw_sleep=%d, mw_enabled=%d, realtime=%d",
srs_trace("start play smi=%.2f, mw_sleep=%d, mw_enabled=%d, realtime=%d",
send_min_interval, mw_sleep, mw_enabled, realtime);
while (!disposed) {
@ -667,7 +667,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
// get messages from consumer.
// each msg in msgs.msgs must be free, for the SrsMessageArray never free them.
// @remark when enable send_min_interval, only fetch one message a time.
int count = send_min_interval? 1 : 0;
int count = (send_min_interval > 0)? 1 : 0;
if ((ret = consumer->dump_packets(&msgs, count)) != ERROR_SUCCESS) {
srs_error("get messages from consumer failed. ret=%d", ret);
return ret;
@ -745,7 +745,7 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRe
// apply the minimal interval for delivery stream in ms.
if (send_min_interval > 0) {
st_usleep(send_min_interval * 1000);
st_usleep((int64_t)(send_min_interval * 1000));
}
}

View file

@ -86,7 +86,7 @@ private:
// @see https://github.com/simple-rtmp-server/srs/issues/257
bool realtime;
// the minimal interval in ms for delivery stream.
int send_min_interval;
double send_min_interval;
public:
SrsRtmpConn(SrsServer* svr, st_netfd_t c);
virtual ~SrsRtmpConn();

View file

@ -1450,6 +1450,13 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata
return ret;
}
// when already got metadata, drop when reduce sequence header.
bool drop_for_reduce = false;
if (cache_metadata && _srs_config->get_reduce_sequence_header(_req->vhost)) {
drop_for_reduce = true;
srs_warn("drop for reduce sh metadata, size=%d", msg->size);
}
// create a shared ptr message.
srs_freep(cache_metadata);
cache_metadata = new SrsSharedPtrMessage();
@ -1463,10 +1470,6 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata
srs_verbose("initialize shared ptr metadata success.");
// copy to all consumer
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) {

View file

@ -2324,9 +2324,20 @@ int srs_human_print_rtmp_packet2(char type, u_int32_t timestamp, char* data, int
}
int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now)
{
return srs_human_print_rtmp_packet4(type, timestamp, data, size, pre_timestamp, pre_now, 0, 0);
}
int srs_human_print_rtmp_packet4(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now, int64_t starttime, int64_t nb_packets)
{
int ret = ERROR_SUCCESS;
// packets interval in milliseconds.
double pi = 0;
if (pre_now > starttime) {
pi = (pre_now - starttime) / (double)nb_packets;
}
int diff = 0;
if (pre_timestamp > 0) {
diff = (int)timestamp - (int)pre_timestamp;
@ -2339,22 +2350,22 @@ int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int
u_int32_t pts;
if (srs_utils_parse_timestamp(timestamp, type, data, size, &pts) != 0) {
srs_human_trace("Rtmp packet type=%s, dts=%d, diff=%d, ndiff=%d, size=%d, DecodeError",
srs_human_flv_tag_type2string(type), timestamp, diff, ndiff, size
srs_human_trace("Rtmp packet id=%"PRId64"/%.1f, type=%s, dts=%d, diff=%d, ndiff=%d, size=%d, DecodeError",
nb_packets, pi, srs_human_flv_tag_type2string(type), timestamp, diff, ndiff, size
);
return ret;
}
if (type == SRS_RTMP_TYPE_VIDEO) {
srs_human_trace("Video packet type=%s, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d, %s(%s,%s)",
srs_human_flv_tag_type2string(type), timestamp, pts, diff, ndiff, size,
srs_human_trace("Video packet id=%"PRId64"/%.1f, type=%s, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d, %s(%s,%s)",
nb_packets, pi, srs_human_flv_tag_type2string(type), timestamp, pts, diff, ndiff, size,
srs_human_flv_video_codec_id2string(srs_utils_flv_video_codec_id(data, size)),
srs_human_flv_video_avc_packet_type2string(srs_utils_flv_video_avc_packet_type(data, size)),
srs_human_flv_video_frame_type2string(srs_utils_flv_video_frame_type(data, size))
);
} else if (type == SRS_RTMP_TYPE_AUDIO) {
srs_human_trace("Audio packet type=%s, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d, %s(%s,%s,%s,%s)",
srs_human_flv_tag_type2string(type), timestamp, pts, diff, ndiff, size,
srs_human_trace("Audio packet id=%"PRId64"/%.1f, type=%s, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d, %s(%s,%s,%s,%s)",
nb_packets, pi, srs_human_flv_tag_type2string(type), timestamp, pts, diff, ndiff, size,
srs_human_flv_audio_sound_format2string(srs_utils_flv_audio_sound_format(data, size)),
srs_human_flv_audio_sound_rate2string(srs_utils_flv_audio_sound_rate(data, size)),
srs_human_flv_audio_sound_size2string(srs_utils_flv_audio_sound_size(data, size)),
@ -2362,8 +2373,8 @@ int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int
srs_human_flv_audio_aac_packet_type2string(srs_utils_flv_audio_aac_packet_type(data, size))
);
} else if (type == SRS_RTMP_TYPE_SCRIPT) {
srs_human_verbose("Data packet type=%s, time=%d, diff=%d, ndiff=%d, size=%d",
srs_human_flv_tag_type2string(type), timestamp, diff, ndiff, size);
srs_human_verbose("Data packet id=%"PRId64"/%.1f, type=%s, time=%d, diff=%d, ndiff=%d, size=%d",
nb_packets, pi, srs_human_flv_tag_type2string(type), timestamp, diff, ndiff, size);
int nparsed = 0;
while (nparsed < size) {
int nb_parsed_this = 0;
@ -2379,8 +2390,8 @@ int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int
srs_freep(amf0_str);
}
} else {
srs_human_trace("Rtmp packet type=%#x, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d",
type, timestamp, pts, diff, ndiff, size);
srs_human_trace("Rtmp packet id=%"PRId64"/%.1f, type=%#x, dts=%d, pts=%d, diff=%d, ndiff=%d, size=%d",
nb_packets, pi, type, timestamp, pts, diff, ndiff, size);
}
return ret;

View file

@ -904,8 +904,19 @@ extern const char* srs_human_flv_audio_aac_packet_type2string(char aac_packet_ty
* @return an error code for parse the timetstamp to dts and pts.
*/
extern int srs_human_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int size);
/**
* @param pre_timestamp the previous timestamp in ms to calc the diff.
*/
extern int srs_human_print_rtmp_packet2(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp);
/**
* @param pre_now the previous system time in ms to calc the ndiff.
*/
extern int srs_human_print_rtmp_packet3(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now);
/**
* @param starttime the rtmpdump starttime in ms.
* @param nb_packets the number of packets received, to calc the packets interval in ms.
*/
extern int srs_human_print_rtmp_packet4(char type, u_int32_t timestamp, char* data, int size, u_int32_t pre_timestamp, int64_t pre_now, int64_t starttime, int64_t nb_packets);
// log to console, for use srs-librtmp application.
extern const char* srs_human_format_time();