diff --git a/README.md b/README.md
index 7ed3528e8..a8c97e198 100755
--- a/README.md
+++ b/README.md
@@ -209,7 +209,8 @@ Supported operating systems and hardware:
* 2013-10-17, Created.
## History
-* v1.0, 2014-07-19, fix [#121](https://github.com/winlinvip/simple-rtmp-server/issues/121), srs_info detail log compile failed. 0.9.168.
+* v1.0, 2014-07-26, fix [#124](https://github.com/winlinvip/simple-rtmp-server/issues/124), gop cache support disable video in publishing. 0.9.171.
+* v1.0, 2014-07-23, fix [#121](https://github.com/winlinvip/simple-rtmp-server/issues/121), srs_info detail log compile failed. 0.9.168.
* v1.0, 2014-07-19, fix [#119](https://github.com/winlinvip/simple-rtmp-server/issues/119), use iformat and oformat for ffmpeg transcode. 0.9.163.
* v1.0, 2014-07-13, [1.0 mainline6(0.9.160)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.mainline8) released. 50029 lines.
* v1.0, 2014-07-13, refine the bandwidth check/test, add as/js library, use srs-librtmp for linux tool. 0.9.159
diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp
index 08c239675..60cd53c60 100644
--- a/trunk/src/app/srs_app_source.cpp
+++ b/trunk/src/app/srs_app_source.cpp
@@ -46,6 +46,10 @@ using namespace std;
#define CONST_MAX_JITTER_MS 500
#define DEFAULT_FRAME_TIME_MS 40
+// for 26ms per audio packet,
+// 115 packets is 3s.
+#define __SRS_PURE_AUDIO_GUESS_COUNT 115
+
int _srs_time_jitter_string2int(std::string time_jitter)
{
if (time_jitter == "full") {
@@ -351,6 +355,7 @@ SrsGopCache::SrsGopCache()
{
cached_video_count = 0;
enable_gop_cache = true;
+ audio_count_after_last_video = 0;
}
SrsGopCache::~SrsGopCache()
@@ -383,6 +388,7 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg)
// got video, update the video count if acceptable
if (msg->header.is_video()) {
cached_video_count++;
+ audio_count_after_last_video = 0;
}
// no acceptable video or pure audio, disable the cache.
@@ -391,6 +397,18 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg)
return ret;
}
+ // ok, gop cache enabled, and got an audio.
+ if (msg->header.is_audio()) {
+ audio_count_after_last_video++;
+ }
+
+ // clear gop cache when pure audio count overflow
+ if (audio_count_after_last_video > __SRS_PURE_AUDIO_GUESS_COUNT) {
+ srs_warn("clear gop cache for guess pure audio overflow");
+ clear();
+ return ret;
+ }
+
// clear gop cache when got key frame
if (msg->header.is_video() && SrsFlvCodec::video_is_keyframe(msg->payload, msg->size)) {
srs_info("clear gop cache when got keyframe. vcount=%d, count=%d",
diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp
index ef3731740..bec0e7043 100644
--- a/trunk/src/app/srs_app_source.hpp
+++ b/trunk/src/app/srs_app_source.hpp
@@ -213,6 +213,19 @@ private:
*/
int cached_video_count;
/**
+ * when user disabled video when publishing, and gop cache enalbed,
+ * we will cache the audio/video for we already got video, but we never
+ * know when to clear the gop cache, for there is no video in future,
+ * so we must guess whether user disabled the video.
+ * when we got some audios after laster video, for instance, 600 audio packets,
+ * about 3s(26ms per packet) 115 audio packets, clear gop cache.
+ *
+ * @remark, it is ok for performance, for when we clear the gop cache,
+ * gop cache is disabled for pure audio stream.
+ * @see: https://github.com/winlinvip/simple-rtmp-server/issues/124
+ */
+ int audio_count_after_last_video;
+ /**
* cached gop.
*/
std::vector gop_cache;
diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp
index 544feca31..276ed6b8e 100644
--- a/trunk/src/core/srs_core.hpp
+++ b/trunk/src/core/srs_core.hpp
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
-#define VERSION_REVISION "170"
+#define VERSION_REVISION "171"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "SRS"