diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index a69576377..0cde9b451 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1279,24 +1279,14 @@ int SrsOriginHub::on_dvr_request_sh() } if (cache_sh_video) { - // TODO: Use cached format for sh. - if ((ret = format->on_video(cache_sh_video)) != ERROR_SUCCESS) { - return ret; - } - - if ((ret = dvr->on_video(cache_sh_video, format)) != ERROR_SUCCESS) { + if ((ret = dvr->on_video(cache_sh_video, source->meta->vsh_format())) != ERROR_SUCCESS) { srs_error("dvr process video sequence header message failed. ret=%d", ret); return ret; } } if (cache_sh_audio) { - // TODO: Use cached format for sh. - if ((ret = format->on_audio(cache_sh_audio)) != ERROR_SUCCESS) { - return ret; - } - - if ((ret = dvr->on_audio(cache_sh_audio, format)) != ERROR_SUCCESS) { + if ((ret = dvr->on_audio(cache_sh_audio, source->meta->ash_format())) != ERROR_SUCCESS) { srs_error("dvr process audio sequence header message failed. ret=%d", ret); return ret; } @@ -1601,6 +1591,8 @@ void SrsOriginHub::destroy_forwarders() SrsMetaCache::SrsMetaCache() { meta = video = audio = NULL; + vformat = new SrsRtmpFormat(); + aformat = new SrsRtmpFormat(); } SrsMetaCache::~SrsMetaCache() @@ -1625,11 +1617,21 @@ SrsSharedPtrMessage* SrsMetaCache::vsh() return video; } +SrsFormat* SrsMetaCache::vsh_format() +{ + return vformat; +} + SrsSharedPtrMessage* SrsMetaCache::ash() { return audio; } +SrsFormat* SrsMetaCache::ash_format() +{ + return aformat; +} + int SrsMetaCache::dumps(SrsConsumer* consumer, bool atc, SrsRtmpJitterAlgorithm ag, bool dm, bool ds) { int ret = ERROR_SUCCESS; @@ -1728,16 +1730,18 @@ int SrsMetaCache::update_data(SrsMessageHeader* header, SrsOnMetaDataPacket* met return ret; } -void SrsMetaCache::update_ash(SrsSharedPtrMessage* msg) +int SrsMetaCache::update_ash(SrsSharedPtrMessage* msg) { srs_freep(audio); audio = msg->copy(); + return aformat->on_audio(msg); } -void SrsMetaCache::update_vsh(SrsSharedPtrMessage* msg) +int SrsMetaCache::update_vsh(SrsSharedPtrMessage* msg) { srs_freep(video); video = msg->copy(); + return vformat->on_video(msg); } std::map SrsSource::pool; @@ -2236,7 +2240,9 @@ int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg) // for example, the mp3 is used for hls to write the "right" audio codec. // TODO: FIXME: to refine the stream info system. if (is_aac_sequence_header || !meta->ash()) { - meta->update_ash(msg); + if ((ret = meta->update_ash(msg)) != ERROR_SUCCESS) { + return ret; + } } // when sequence header, donot push to gop cache and adjust the timestamp. @@ -2342,8 +2348,8 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg) // cache the sequence header if h264 // donot cache the sequence header to gop_cache, return here. - if (is_sequence_header) { - meta->update_vsh(msg); + if (is_sequence_header && (ret = meta->update_vsh(msg)) != ERROR_SUCCESS) { + return ret; } // Copy to hub to all utilities. diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 495023c9f..7f05e42d7 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -34,6 +34,7 @@ #include #include +class SrsFormat; class SrsRtmpFormat; class SrsConsumer; class SrsPlayEdge; @@ -496,6 +497,9 @@ private: SrsSharedPtrMessage* video; // The cached audio sequence header, for example, asc for aac. SrsSharedPtrMessage* audio; + // The format for sequence header. + SrsRtmpFormat* vformat; + SrsRtmpFormat* aformat; public: SrsMetaCache(); virtual ~SrsMetaCache(); @@ -507,8 +511,10 @@ public: virtual SrsSharedPtrMessage* data(); // Get the cached vsh(video sequence header). virtual SrsSharedPtrMessage* vsh(); + virtual SrsFormat* vsh_format(); // Get the cached ash(audio sequence header). virtual SrsSharedPtrMessage* ash(); + virtual SrsFormat* ash_format(); // Dumps cached metadata to consumer. // @param dm Whether dumps the metadata. // @param ds Whether dumps the sequence header. @@ -517,9 +523,9 @@ public: // Update the cached metadata by packet. virtual int update_data(SrsMessageHeader* header, SrsOnMetaDataPacket* metadata, bool& updated); // Update the cached audio sequence header. - virtual void update_ash(SrsSharedPtrMessage* msg); + virtual int update_ash(SrsSharedPtrMessage* msg); // Update the cached video sequence header. - virtual void update_vsh(SrsSharedPtrMessage* msg); + virtual int update_vsh(SrsSharedPtrMessage* msg); }; /**