diff --git a/README.md b/README.md index 0deb4f423..29e11c544 100755 --- a/README.md +++ b/README.md @@ -208,6 +208,7 @@ Supported operating systems and hardware: * 2013-10-17, Created.
## History +* v1.0, 2014-08-24, fix [#150](https://github.com/winlinvip/simple-rtmp-server/issues/150), forward should forward the sequence header when retry. 0.9.208. * v1.0, 2014-08-22, for [#165](https://github.com/winlinvip/simple-rtmp-server/issues/165), refine dh wrapper, ensure public key is 128bytes. 0.9.206. * v1.0, 2014-08-19, for [#160](https://github.com/winlinvip/simple-rtmp-server/issues/160), support forward/edge to flussonic, disable debug_srs_upnode to make flussonic happy. 0.9.201. * v1.0, 2014-08-17, for [#155](https://github.com/winlinvip/simple-rtmp-server/issues/155), refine for osx, with ssl/http, disable statistics. 0.9.198. diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index f9562a12d..984669c88 100644 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -46,6 +46,7 @@ using namespace std; #include #include #include +#include // when error, forwarder sleep for a while and retry. #define SRS_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL) @@ -64,6 +65,8 @@ SrsForwarder::SrsForwarder(SrsSource* _source) pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_US, true); queue = new SrsMessageQueue(); jitter = new SrsRtmpJitter(); + + sh_video = sh_audio = NULL; } SrsForwarder::~SrsForwarder() @@ -74,6 +77,9 @@ SrsForwarder::~SrsForwarder() srs_freep(queue); srs_freep(jitter); srs_freep(kbps); + + srs_freep(sh_video); + srs_freep(sh_audio); } int SrsForwarder::initialize(SrsRequest* req, string ep_forward) @@ -179,6 +185,11 @@ int SrsForwarder::on_audio(SrsSharedPtrMessage* msg) return ret; } + if (SrsFlvCodec::audio_is_sequence_header(msg->payload, msg->size)) { + srs_freep(sh_audio); + sh_audio = msg->copy(); + } + if ((ret = queue->enqueue(msg)) != ERROR_SUCCESS) { return ret; } @@ -195,6 +206,11 @@ int SrsForwarder::on_video(SrsSharedPtrMessage* msg) return ret; } + if (SrsFlvCodec::video_is_sequence_header(msg->payload, msg->size)) { + srs_freep(sh_video); + sh_video = msg->copy(); + } + if ((ret = queue->enqueue(msg)) != ERROR_SUCCESS) { return ret; } @@ -371,6 +387,21 @@ int SrsForwarder::forward() SrsSharedPtrMessageArray msgs(SYS_MAX_FORWARD_SEND_MSGS); + // update sequence header + // TODO: FIXME: maybe need to zero the sequence header timestamp. + if (sh_video) { + if ((ret = client->send_and_free_message(sh_video->copy(), stream_id)) != ERROR_SUCCESS) { + srs_error("forwarder send sh_video to server failed. ret=%d", ret); + return ret; + } + } + if (sh_audio) { + if ((ret = client->send_and_free_message(sh_audio->copy(), stream_id)) != ERROR_SUCCESS) { + srs_error("forwarder send sh_audio to server failed. ret=%d", ret); + return ret; + } + } + while (pthread->can_loop()) { // switch to other st-threads. st_usleep(0); diff --git a/trunk/src/app/srs_app_forward.hpp b/trunk/src/app/srs_app_forward.hpp index 5d8b18012..c2fdb6f57 100644 --- a/trunk/src/app/srs_app_forward.hpp +++ b/trunk/src/app/srs_app_forward.hpp @@ -65,6 +65,12 @@ private: SrsRtmpClient* client; SrsRtmpJitter* jitter; SrsMessageQueue* queue; + /** + * cache the sequence header for retry when slave is failed. + * @see https://github.com/winlinvip/simple-rtmp-server/issues/150 + */ + SrsSharedPtrMessage* sh_audio; + SrsSharedPtrMessage* sh_video; public: SrsForwarder(SrsSource* _source); virtual ~SrsForwarder(); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index b7eb18bf0..8ba58a250 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 "207" +#define VERSION_REVISION "208" #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION // server info. #define RTMP_SIG_SRS_KEY "SRS"