diff --git a/trunk/src/app/srs_app_recv_thread.hpp b/trunk/src/app/srs_app_recv_thread.hpp index 9a4dcb5e80..b986b8bd63 100644 --- a/trunk/src/app/srs_app_recv_thread.hpp +++ b/trunk/src/app/srs_app_recv_thread.hpp @@ -61,8 +61,9 @@ class ISrsMessageHandler */ virtual bool can_handle() = 0; /** - * process the received message. - */ + * process the received message. + * @remark user must free this message. + */ virtual int handle(SrsCommonMessage* msg) = 0; /** * when recv message error. diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index e2613343a4..b08f01d813 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -916,7 +916,6 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg srs_error("fmle decode unpublish message failed. ret=%d", ret); return ret; } - SrsAutoFree(SrsPacket, pkt); // for flash, any packet is republish. diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 2aa5e157ec..6c853533ed 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -604,15 +604,15 @@ int SrsGopCache::cache(SrsSharedPtrMessage* shared_msg) // the gop cache know when to gop it. SrsSharedPtrMessage* msg = shared_msg; - - // disable gop cache when not h.264 - if (!SrsFlvCodec::video_is_h264(msg->payload, msg->size)) { - srs_info("gop donot cache video for none h.264"); - return ret; - } // got video, update the video count if acceptable if (msg->is_video()) { + // drop video when not h.264 + if (!SrsFlvCodec::video_is_h264(msg->payload, msg->size)) { + srs_info("gop cache drop video for none h.264"); + return ret; + } + cached_video_count++; audio_after_last_video_count = 0; } @@ -1464,11 +1464,25 @@ int SrsSource::on_audio(SrsCommonMessage* shared_audio) } srs_info("Audio dts=%"PRId64", size=%d", msg.timestamp, msg.size); + // directly process the audio message. if (!mix_correct) { return on_audio_imp(&msg); } - return do_mix_correct(&msg); + // insert msg to the queue. + mix_queue->push(msg.copy()); + + // fetch someone from mix queue. + SrsSharedPtrMessage* m = mix_queue->pop(); + if (!m) { + return ret; + } + + // consume the monotonically increase message. + ret = on_audio_imp(m); + srs_freep(m); + + return ret; } int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg) @@ -1628,11 +1642,26 @@ int SrsSource::on_video(SrsCommonMessage* shared_video) } srs_info("Video dts=%"PRId64", size=%d", msg.timestamp, msg.size); + // directly process the audio message. if (!mix_correct) { return on_video_imp(&msg); } - return do_mix_correct(&msg); + // insert msg to the queue. + mix_queue->push(msg.copy()); + + // fetch someone from mix queue. + SrsSharedPtrMessage* m = mix_queue->pop(); + if (!m) { + return ret; + } + SrsAutoFree(SrsSharedPtrMessage, m); + + // consume the monotonically increase message. + ret = on_video_imp(m); + srs_freep(m); + + return ret; } int SrsSource::on_video_imp(SrsSharedPtrMessage* msg) @@ -1766,29 +1795,6 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg) return ret; } -int SrsSource::do_mix_correct(SrsSharedPtrMessage* msg) -{ - int ret = ERROR_SUCCESS; - - // insert msg to the queue. - mix_queue->push(msg->copy()); - - // fetch someone from mix queue. - SrsSharedPtrMessage* m = mix_queue->pop(); - if (!m) { - return ret; - } - SrsAutoFree(SrsSharedPtrMessage, m); - - // consume the monotonically increase message. - if (m->is_audio()) { - return on_audio_imp(m); - } - - srs_assert(m->is_video()); - return on_video_imp(m); -} - int SrsSource::on_aggregate(SrsCommonMessage* msg) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index f7a75d4ac9..1f6d1c0fc8 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -536,8 +536,6 @@ class SrsSource : public ISrsReloadHandler virtual int on_video(SrsCommonMessage* video); private: virtual int on_video_imp(SrsSharedPtrMessage* video); -private: - virtual int do_mix_correct(SrsSharedPtrMessage* msg); public: virtual int on_aggregate(SrsCommonMessage* msg); /** diff --git a/trunk/src/protocol/srs_protocol_buffer.cpp b/trunk/src/protocol/srs_protocol_buffer.cpp index 24e64a48fb..1761312822 100644 --- a/trunk/src/protocol/srs_protocol_buffer.cpp +++ b/trunk/src/protocol/srs_protocol_buffer.cpp @@ -97,8 +97,8 @@ void SrsFastBuffer::set_buffer(int buffer_size) } // realloc for buffer change bigger. - int start = p - buffer; - int nb_bytes = end - p; + int start = (int)(p - buffer); + int nb_bytes = (int)(end - p); buffer = (char*)realloc(buffer, nb_resize_buf); nb_buffer = nb_resize_buf;