Skip to content

Commit

Permalink
fix gop cache, drop video only when video and not h.264
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jun 6, 2015
1 parent 2a1db36 commit 0fbfad4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
5 changes: 3 additions & 2 deletions trunk/src/app/srs_app_recv_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
68 changes: 37 additions & 31 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions trunk/src/app/srs_app_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/**
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/protocol/srs_protocol_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0fbfad4

Please sign in to comment.