From aa2b7afb444444f9d2d237398417c1b1a204a772 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 6 Jan 2017 14:32:01 +0800 Subject: [PATCH] refine code, print protocol level info. --- trunk/src/protocol/srs_rtmp_stack.cpp | 25 ++++++++++++++++++++++--- trunk/src/protocol/srs_rtmp_stack.hpp | 7 +++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/trunk/src/protocol/srs_rtmp_stack.cpp b/trunk/src/protocol/srs_rtmp_stack.cpp index fece534aa..f44c3aa51 100644 --- a/trunk/src/protocol/srs_rtmp_stack.cpp +++ b/trunk/src/protocol/srs_rtmp_stack.cpp @@ -229,6 +229,8 @@ SrsProtocol::SrsProtocol(ISrsProtocolReaderWriter* io) warned_c0c3_cache_dry = false; auto_response_when_recv = true; + show_debug_info = true; + in_buffer_length = 0; cs_cache = NULL; if (SRS_PERF_CHUNK_STREAM_CACHE > 0) { @@ -896,6 +898,8 @@ int SrsProtocol::send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, return ret; } + print_debug_info(); + return ret; } @@ -1473,6 +1477,9 @@ int SrsProtocol::on_recv_message(SrsCommonMessage* msg) } srs_verbose("decode packet from message payload success."); break; + case RTMP_MSG_VideoMessage: + case RTMP_MSG_AudioMessage: + print_debug_info(); default: return ret; } @@ -1508,8 +1515,7 @@ int SrsProtocol::on_recv_message(SrsCommonMessage* msg) if (pkt->chunk_size < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE || pkt->chunk_size > SRS_CONSTS_RTMP_MAX_CHUNK_SIZE) { - srs_warn("accept chunk size %d, but should in [%d, %d], " - "@see: https://github.com/ossrs/srs/issues/160", + srs_warn("accept chunk=%d, should in [%d, %d], please see #160", pkt->chunk_size, SRS_CONSTS_RTMP_MIN_CHUNK_SIZE, SRS_CONSTS_RTMP_MAX_CHUNK_SIZE); } @@ -1531,7 +1537,8 @@ int SrsProtocol::on_recv_message(SrsCommonMessage* msg) srs_assert(pkt != NULL); if (pkt->event_type == SrcPCUCSetBufferLength) { - srs_trace("buffer=%d, in.ack=%d, out.ack=%d, in.chunk=%d, out.chunk=%d", pkt->extra_data, + in_buffer_length = pkt->extra_data; + srs_info("buffer=%d, in.ack=%d, out.ack=%d, in.chunk=%d, out.chunk=%d", pkt->extra_data, in_ack_size.window, out_ack_size.window, in_chunk_size, out_chunk_size); } if (pkt->event_type == SrcPCUCPingRequest) { @@ -1594,6 +1601,9 @@ int SrsProtocol::on_send_packet(SrsMessageHeader* mh, SrsPacket* packet) } break; } + case RTMP_MSG_VideoMessage: + case RTMP_MSG_AudioMessage: + print_debug_info(); default: break; } @@ -1670,6 +1680,15 @@ int SrsProtocol::response_ping_message(int32_t timestamp) return ret; } +void SrsProtocol::print_debug_info() +{ + if (show_debug_info) { + show_debug_info = false; + srs_trace("protocol in.buffer=%d, in.ack=%d, out.ack=%d, in.chunk=%d, out.chunk=%d", in_buffer_length, + in_ack_size.window, out_ack_size.window, in_chunk_size, out_chunk_size); + } +} + SrsChunkStream::SrsChunkStream(int _cid) { fmt = 0; diff --git a/trunk/src/protocol/srs_rtmp_stack.hpp b/trunk/src/protocol/srs_rtmp_stack.hpp index d0b8c81c6..fdd8a1051 100644 --- a/trunk/src/protocol/srs_rtmp_stack.hpp +++ b/trunk/src/protocol/srs_rtmp_stack.hpp @@ -235,6 +235,11 @@ private: AckWindowSize in_ack_size; // The output ack window, to require peer to response the ack. AckWindowSize out_ack_size; + // The buffer length set by peer. + int32_t in_buffer_length; + // Whether print the protocol level debug info. + // Generally we print the debug info when got or send first A/V packet. + bool show_debug_info; /** * whether auto response when recv messages. * default to true for it's very easy to use the protocol stack. @@ -490,6 +495,8 @@ private: * auto response the ping message. */ virtual int response_ping_message(int32_t timestamp); +private: + virtual void print_debug_info(); }; /**