fix #124, gop cache support disable video in publishing. 0.9.171.
正在显示
4 个修改的文件
包含
34 行增加
和
2 行删除
| @@ -209,7 +209,8 @@ Supported operating systems and hardware: | @@ -209,7 +209,8 @@ Supported operating systems and hardware: | ||
| 209 | * 2013-10-17, Created.<br/> | 209 | * 2013-10-17, Created.<br/> |
| 210 | 210 | ||
| 211 | ## History | 211 | ## History |
| 212 | -* 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. | 212 | +* 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. |
| 213 | +* 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. | ||
| 213 | * 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. | 214 | * 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. |
| 214 | * <strong>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.</strong> | 215 | * <strong>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.</strong> |
| 215 | * v1.0, 2014-07-13, refine the bandwidth check/test, add as/js library, use srs-librtmp for linux tool. 0.9.159 | 216 | * v1.0, 2014-07-13, refine the bandwidth check/test, add as/js library, use srs-librtmp for linux tool. 0.9.159 |
| @@ -46,6 +46,10 @@ using namespace std; | @@ -46,6 +46,10 @@ using namespace std; | ||
| 46 | #define CONST_MAX_JITTER_MS 500 | 46 | #define CONST_MAX_JITTER_MS 500 |
| 47 | #define DEFAULT_FRAME_TIME_MS 40 | 47 | #define DEFAULT_FRAME_TIME_MS 40 |
| 48 | 48 | ||
| 49 | +// for 26ms per audio packet, | ||
| 50 | +// 115 packets is 3s. | ||
| 51 | +#define __SRS_PURE_AUDIO_GUESS_COUNT 115 | ||
| 52 | + | ||
| 49 | int _srs_time_jitter_string2int(std::string time_jitter) | 53 | int _srs_time_jitter_string2int(std::string time_jitter) |
| 50 | { | 54 | { |
| 51 | if (time_jitter == "full") { | 55 | if (time_jitter == "full") { |
| @@ -351,6 +355,7 @@ SrsGopCache::SrsGopCache() | @@ -351,6 +355,7 @@ SrsGopCache::SrsGopCache() | ||
| 351 | { | 355 | { |
| 352 | cached_video_count = 0; | 356 | cached_video_count = 0; |
| 353 | enable_gop_cache = true; | 357 | enable_gop_cache = true; |
| 358 | + audio_count_after_last_video = 0; | ||
| 354 | } | 359 | } |
| 355 | 360 | ||
| 356 | SrsGopCache::~SrsGopCache() | 361 | SrsGopCache::~SrsGopCache() |
| @@ -383,6 +388,7 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | @@ -383,6 +388,7 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | ||
| 383 | // got video, update the video count if acceptable | 388 | // got video, update the video count if acceptable |
| 384 | if (msg->header.is_video()) { | 389 | if (msg->header.is_video()) { |
| 385 | cached_video_count++; | 390 | cached_video_count++; |
| 391 | + audio_count_after_last_video = 0; | ||
| 386 | } | 392 | } |
| 387 | 393 | ||
| 388 | // no acceptable video or pure audio, disable the cache. | 394 | // no acceptable video or pure audio, disable the cache. |
| @@ -391,6 +397,18 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | @@ -391,6 +397,18 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | ||
| 391 | return ret; | 397 | return ret; |
| 392 | } | 398 | } |
| 393 | 399 | ||
| 400 | + // ok, gop cache enabled, and got an audio. | ||
| 401 | + if (msg->header.is_audio()) { | ||
| 402 | + audio_count_after_last_video++; | ||
| 403 | + } | ||
| 404 | + | ||
| 405 | + // clear gop cache when pure audio count overflow | ||
| 406 | + if (audio_count_after_last_video > __SRS_PURE_AUDIO_GUESS_COUNT) { | ||
| 407 | + srs_warn("clear gop cache for guess pure audio overflow"); | ||
| 408 | + clear(); | ||
| 409 | + return ret; | ||
| 410 | + } | ||
| 411 | + | ||
| 394 | // clear gop cache when got key frame | 412 | // clear gop cache when got key frame |
| 395 | if (msg->header.is_video() && SrsFlvCodec::video_is_keyframe(msg->payload, msg->size)) { | 413 | if (msg->header.is_video() && SrsFlvCodec::video_is_keyframe(msg->payload, msg->size)) { |
| 396 | srs_info("clear gop cache when got keyframe. vcount=%d, count=%d", | 414 | srs_info("clear gop cache when got keyframe. vcount=%d, count=%d", |
| @@ -213,6 +213,19 @@ private: | @@ -213,6 +213,19 @@ private: | ||
| 213 | */ | 213 | */ |
| 214 | int cached_video_count; | 214 | int cached_video_count; |
| 215 | /** | 215 | /** |
| 216 | + * when user disabled video when publishing, and gop cache enalbed, | ||
| 217 | + * we will cache the audio/video for we already got video, but we never | ||
| 218 | + * know when to clear the gop cache, for there is no video in future, | ||
| 219 | + * so we must guess whether user disabled the video. | ||
| 220 | + * when we got some audios after laster video, for instance, 600 audio packets, | ||
| 221 | + * about 3s(26ms per packet) 115 audio packets, clear gop cache. | ||
| 222 | + * | ||
| 223 | + * @remark, it is ok for performance, for when we clear the gop cache, | ||
| 224 | + * gop cache is disabled for pure audio stream. | ||
| 225 | + * @see: https://github.com/winlinvip/simple-rtmp-server/issues/124 | ||
| 226 | + */ | ||
| 227 | + int audio_count_after_last_video; | ||
| 228 | + /** | ||
| 216 | * cached gop. | 229 | * cached gop. |
| 217 | */ | 230 | */ |
| 218 | std::vector<SrsSharedPtrMessage*> gop_cache; | 231 | std::vector<SrsSharedPtrMessage*> gop_cache; |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
| 33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
| 34 | -#define VERSION_REVISION "170" | 34 | +#define VERSION_REVISION "171" |
| 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
-
请 注册 或 登录 后发表评论