winlin

fix gop cache, drop video only when video and not h.264

@@ -62,6 +62,7 @@ public: @@ -62,6 +62,7 @@ public:
62 virtual bool can_handle() = 0; 62 virtual bool can_handle() = 0;
63 /** 63 /**
64 * process the received message. 64 * process the received message.
  65 + * @remark user must free this message.
65 */ 66 */
66 virtual int handle(SrsCommonMessage* msg) = 0; 67 virtual int handle(SrsCommonMessage* msg) = 0;
67 /** 68 /**
@@ -916,7 +916,6 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg @@ -916,7 +916,6 @@ int SrsRtmpConn::handle_publish_message(SrsSource* source, SrsCommonMessage* msg
916 srs_error("fmle decode unpublish message failed. ret=%d", ret); 916 srs_error("fmle decode unpublish message failed. ret=%d", ret);
917 return ret; 917 return ret;
918 } 918 }
919 -  
920 SrsAutoFree(SrsPacket, pkt); 919 SrsAutoFree(SrsPacket, pkt);
921 920
922 // for flash, any packet is republish. 921 // for flash, any packet is republish.
@@ -605,14 +605,14 @@ int SrsGopCache::cache(SrsSharedPtrMessage* shared_msg) @@ -605,14 +605,14 @@ int SrsGopCache::cache(SrsSharedPtrMessage* shared_msg)
605 // the gop cache know when to gop it. 605 // the gop cache know when to gop it.
606 SrsSharedPtrMessage* msg = shared_msg; 606 SrsSharedPtrMessage* msg = shared_msg;
607 607
608 - // disable gop cache when not h.264 608 + // got video, update the video count if acceptable
  609 + if (msg->is_video()) {
  610 + // drop video when not h.264
609 if (!SrsFlvCodec::video_is_h264(msg->payload, msg->size)) { 611 if (!SrsFlvCodec::video_is_h264(msg->payload, msg->size)) {
610 - srs_info("gop donot cache video for none h.264"); 612 + srs_info("gop cache drop video for none h.264");
611 return ret; 613 return ret;
612 } 614 }
613 615
614 - // got video, update the video count if acceptable  
615 - if (msg->is_video()) {  
616 cached_video_count++; 616 cached_video_count++;
617 audio_after_last_video_count = 0; 617 audio_after_last_video_count = 0;
618 } 618 }
@@ -1464,11 +1464,25 @@ int SrsSource::on_audio(SrsCommonMessage* shared_audio) @@ -1464,11 +1464,25 @@ int SrsSource::on_audio(SrsCommonMessage* shared_audio)
1464 } 1464 }
1465 srs_info("Audio dts=%"PRId64", size=%d", msg.timestamp, msg.size); 1465 srs_info("Audio dts=%"PRId64", size=%d", msg.timestamp, msg.size);
1466 1466
  1467 + // directly process the audio message.
1467 if (!mix_correct) { 1468 if (!mix_correct) {
1468 return on_audio_imp(&msg); 1469 return on_audio_imp(&msg);
1469 } 1470 }
1470 1471
1471 - return do_mix_correct(&msg); 1472 + // insert msg to the queue.
  1473 + mix_queue->push(msg.copy());
  1474 +
  1475 + // fetch someone from mix queue.
  1476 + SrsSharedPtrMessage* m = mix_queue->pop();
  1477 + if (!m) {
  1478 + return ret;
  1479 + }
  1480 +
  1481 + // consume the monotonically increase message.
  1482 + ret = on_audio_imp(m);
  1483 + srs_freep(m);
  1484 +
  1485 + return ret;
1472 } 1486 }
1473 1487
1474 int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg) 1488 int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg)
@@ -1628,11 +1642,26 @@ int SrsSource::on_video(SrsCommonMessage* shared_video) @@ -1628,11 +1642,26 @@ int SrsSource::on_video(SrsCommonMessage* shared_video)
1628 } 1642 }
1629 srs_info("Video dts=%"PRId64", size=%d", msg.timestamp, msg.size); 1643 srs_info("Video dts=%"PRId64", size=%d", msg.timestamp, msg.size);
1630 1644
  1645 + // directly process the audio message.
1631 if (!mix_correct) { 1646 if (!mix_correct) {
1632 return on_video_imp(&msg); 1647 return on_video_imp(&msg);
1633 } 1648 }
1634 1649
1635 - return do_mix_correct(&msg); 1650 + // insert msg to the queue.
  1651 + mix_queue->push(msg.copy());
  1652 +
  1653 + // fetch someone from mix queue.
  1654 + SrsSharedPtrMessage* m = mix_queue->pop();
  1655 + if (!m) {
  1656 + return ret;
  1657 + }
  1658 + SrsAutoFree(SrsSharedPtrMessage, m);
  1659 +
  1660 + // consume the monotonically increase message.
  1661 + ret = on_video_imp(m);
  1662 + srs_freep(m);
  1663 +
  1664 + return ret;
1636 } 1665 }
1637 1666
1638 int SrsSource::on_video_imp(SrsSharedPtrMessage* msg) 1667 int SrsSource::on_video_imp(SrsSharedPtrMessage* msg)
@@ -1766,29 +1795,6 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg) @@ -1766,29 +1795,6 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg)
1766 return ret; 1795 return ret;
1767 } 1796 }
1768 1797
1769 -int SrsSource::do_mix_correct(SrsSharedPtrMessage* msg)  
1770 -{  
1771 - int ret = ERROR_SUCCESS;  
1772 -  
1773 - // insert msg to the queue.  
1774 - mix_queue->push(msg->copy());  
1775 -  
1776 - // fetch someone from mix queue.  
1777 - SrsSharedPtrMessage* m = mix_queue->pop();  
1778 - if (!m) {  
1779 - return ret;  
1780 - }  
1781 - SrsAutoFree(SrsSharedPtrMessage, m);  
1782 -  
1783 - // consume the monotonically increase message.  
1784 - if (m->is_audio()) {  
1785 - return on_audio_imp(m);  
1786 - }  
1787 -  
1788 - srs_assert(m->is_video());  
1789 - return on_video_imp(m);  
1790 -}  
1791 -  
1792 int SrsSource::on_aggregate(SrsCommonMessage* msg) 1798 int SrsSource::on_aggregate(SrsCommonMessage* msg)
1793 { 1799 {
1794 int ret = ERROR_SUCCESS; 1800 int ret = ERROR_SUCCESS;
@@ -536,8 +536,6 @@ public: @@ -536,8 +536,6 @@ public:
536 virtual int on_video(SrsCommonMessage* video); 536 virtual int on_video(SrsCommonMessage* video);
537 private: 537 private:
538 virtual int on_video_imp(SrsSharedPtrMessage* video); 538 virtual int on_video_imp(SrsSharedPtrMessage* video);
539 -private:  
540 - virtual int do_mix_correct(SrsSharedPtrMessage* msg);  
541 public: 539 public:
542 virtual int on_aggregate(SrsCommonMessage* msg); 540 virtual int on_aggregate(SrsCommonMessage* msg);
543 /** 541 /**
@@ -97,8 +97,8 @@ void SrsFastBuffer::set_buffer(int buffer_size) @@ -97,8 +97,8 @@ void SrsFastBuffer::set_buffer(int buffer_size)
97 } 97 }
98 98
99 // realloc for buffer change bigger. 99 // realloc for buffer change bigger.
100 - int start = p - buffer;  
101 - int nb_bytes = end - p; 100 + int start = (int)(p - buffer);
  101 + int nb_bytes = (int)(end - p);
102 102
103 buffer = (char*)realloc(buffer, nb_resize_buf); 103 buffer = (char*)realloc(buffer, nb_resize_buf);
104 nb_buffer = nb_resize_buf; 104 nb_buffer = nb_resize_buf;