for bug #251, refine the directly access ptrs for hls,dvr,forwarder,consumer.
正在显示
8 个修改的文件
包含
97 行增加
和
67 行删除
| @@ -196,13 +196,16 @@ int SrsDvrPlan::on_meta_data(SrsOnMetaDataPacket* metadata) | @@ -196,13 +196,16 @@ int SrsDvrPlan::on_meta_data(SrsOnMetaDataPacket* metadata) | ||
| 196 | return ret; | 196 | return ret; |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | -int SrsDvrPlan::on_audio(SrsSharedPtrMessage* audio) | 199 | +int SrsDvrPlan::on_audio(SrsSharedPtrMessage* __audio) |
| 200 | { | 200 | { |
| 201 | int ret = ERROR_SUCCESS; | 201 | int ret = ERROR_SUCCESS; |
| 202 | 202 | ||
| 203 | if (!dvr_enabled) { | 203 | if (!dvr_enabled) { |
| 204 | return ret; | 204 | return ret; |
| 205 | } | 205 | } |
| 206 | + | ||
| 207 | + SrsSharedPtrMessage* audio = __audio->copy(); | ||
| 208 | + SrsAutoFree(SrsSharedPtrMessage, audio); | ||
| 206 | 209 | ||
| 207 | if ((jitter->correct(audio, 0, 0, jitter_algorithm)) != ERROR_SUCCESS) { | 210 | if ((jitter->correct(audio, 0, 0, jitter_algorithm)) != ERROR_SUCCESS) { |
| 208 | return ret; | 211 | return ret; |
| @@ -222,13 +225,16 @@ int SrsDvrPlan::on_audio(SrsSharedPtrMessage* audio) | @@ -222,13 +225,16 @@ int SrsDvrPlan::on_audio(SrsSharedPtrMessage* audio) | ||
| 222 | return ret; | 225 | return ret; |
| 223 | } | 226 | } |
| 224 | 227 | ||
| 225 | -int SrsDvrPlan::on_video(SrsSharedPtrMessage* video) | 228 | +int SrsDvrPlan::on_video(SrsSharedPtrMessage* __video) |
| 226 | { | 229 | { |
| 227 | int ret = ERROR_SUCCESS; | 230 | int ret = ERROR_SUCCESS; |
| 228 | 231 | ||
| 229 | if (!dvr_enabled) { | 232 | if (!dvr_enabled) { |
| 230 | return ret; | 233 | return ret; |
| 231 | } | 234 | } |
| 235 | + | ||
| 236 | + SrsSharedPtrMessage* video = __video->copy(); | ||
| 237 | + SrsAutoFree(SrsSharedPtrMessage, video); | ||
| 232 | 238 | ||
| 233 | char* payload = video->payload; | 239 | char* payload = video->payload; |
| 234 | int size = video->size; | 240 | int size = video->size; |
| @@ -571,30 +577,14 @@ int SrsDvr::on_meta_data(SrsOnMetaDataPacket* metadata) | @@ -571,30 +577,14 @@ int SrsDvr::on_meta_data(SrsOnMetaDataPacket* metadata) | ||
| 571 | return ret; | 577 | return ret; |
| 572 | } | 578 | } |
| 573 | 579 | ||
| 574 | -int SrsDvr::on_audio(SrsSharedPtrMessage* audio) | 580 | +int SrsDvr::on_audio(SrsSharedPtrMessage* __audio) |
| 575 | { | 581 | { |
| 576 | - int ret = ERROR_SUCCESS; | ||
| 577 | - | ||
| 578 | - SrsAutoFree(SrsSharedPtrMessage, audio); | ||
| 579 | - | ||
| 580 | - if ((ret = plan->on_audio(audio)) != ERROR_SUCCESS) { | ||
| 581 | - return ret; | ||
| 582 | - } | ||
| 583 | - | ||
| 584 | - return ret; | 582 | + return plan->on_audio(__audio); |
| 585 | } | 583 | } |
| 586 | 584 | ||
| 587 | -int SrsDvr::on_video(SrsSharedPtrMessage* video) | 585 | +int SrsDvr::on_video(SrsSharedPtrMessage* __video) |
| 588 | { | 586 | { |
| 589 | - int ret = ERROR_SUCCESS; | ||
| 590 | - | ||
| 591 | - SrsAutoFree(SrsSharedPtrMessage, video); | ||
| 592 | - | ||
| 593 | - if ((ret = plan->on_video(video)) != ERROR_SUCCESS) { | ||
| 594 | - return ret; | ||
| 595 | - } | ||
| 596 | - | ||
| 597 | - return ret; | 587 | + return plan->on_video(__video); |
| 598 | } | 588 | } |
| 599 | 589 | ||
| 600 | #endif | 590 | #endif |
| @@ -119,8 +119,14 @@ public: | @@ -119,8 +119,14 @@ public: | ||
| 119 | virtual int on_publish(); | 119 | virtual int on_publish(); |
| 120 | virtual void on_unpublish() = 0; | 120 | virtual void on_unpublish() = 0; |
| 121 | virtual int on_meta_data(SrsOnMetaDataPacket* metadata); | 121 | virtual int on_meta_data(SrsOnMetaDataPacket* metadata); |
| 122 | - virtual int on_audio(SrsSharedPtrMessage* audio); | ||
| 123 | - virtual int on_video(SrsSharedPtrMessage* video); | 122 | + /** |
| 123 | + * @param __audio, directly ptr, copy it if need to save it. | ||
| 124 | + */ | ||
| 125 | + virtual int on_audio(SrsSharedPtrMessage* __audio); | ||
| 126 | + /** | ||
| 127 | + * @param __video, directly ptr, copy it if need to save it. | ||
| 128 | + */ | ||
| 129 | + virtual int on_video(SrsSharedPtrMessage* __video); | ||
| 124 | // interface ISrsReloadHandler | 130 | // interface ISrsReloadHandler |
| 125 | public: | 131 | public: |
| 126 | virtual int on_reload_vhost_dvr(std::string vhost); | 132 | virtual int on_reload_vhost_dvr(std::string vhost); |
| @@ -166,7 +172,13 @@ public: | @@ -166,7 +172,13 @@ public: | ||
| 166 | virtual int initialize(SrsSource* source, SrsRequest* req); | 172 | virtual int initialize(SrsSource* source, SrsRequest* req); |
| 167 | virtual int on_publish(); | 173 | virtual int on_publish(); |
| 168 | virtual void on_unpublish(); | 174 | virtual void on_unpublish(); |
| 175 | + /** | ||
| 176 | + * @param audio, directly ptr, copy it if need to save it. | ||
| 177 | + */ | ||
| 169 | virtual int on_audio(SrsSharedPtrMessage* audio); | 178 | virtual int on_audio(SrsSharedPtrMessage* audio); |
| 179 | + /** | ||
| 180 | + * @param video, directly ptr, copy it if need to save it. | ||
| 181 | + */ | ||
| 170 | virtual int on_video(SrsSharedPtrMessage* video); | 182 | virtual int on_video(SrsSharedPtrMessage* video); |
| 171 | private: | 183 | private: |
| 172 | virtual int update_duration(SrsSharedPtrMessage* msg); | 184 | virtual int update_duration(SrsSharedPtrMessage* msg); |
| @@ -208,12 +220,14 @@ public: | @@ -208,12 +220,14 @@ public: | ||
| 208 | virtual int on_meta_data(SrsOnMetaDataPacket* metadata); | 220 | virtual int on_meta_data(SrsOnMetaDataPacket* metadata); |
| 209 | /** | 221 | /** |
| 210 | * mux the audio packets to dvr. | 222 | * mux the audio packets to dvr. |
| 223 | + * @param __audio, directly ptr, copy it if need to save it. | ||
| 211 | */ | 224 | */ |
| 212 | - virtual int on_audio(SrsSharedPtrMessage* audio); | 225 | + virtual int on_audio(SrsSharedPtrMessage* __audio); |
| 213 | /** | 226 | /** |
| 214 | * mux the video packets to dvr. | 227 | * mux the video packets to dvr. |
| 228 | + * @param __video, directly ptr, copy it if need to save it. | ||
| 215 | */ | 229 | */ |
| 216 | - virtual int on_video(SrsSharedPtrMessage* video); | 230 | + virtual int on_video(SrsSharedPtrMessage* __video); |
| 217 | }; | 231 | }; |
| 218 | 232 | ||
| 219 | #endif | 233 | #endif |
| @@ -156,9 +156,11 @@ void SrsForwarder::on_unpublish() | @@ -156,9 +156,11 @@ void SrsForwarder::on_unpublish() | ||
| 156 | kbps->set_io(NULL, NULL); | 156 | kbps->set_io(NULL, NULL); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | -int SrsForwarder::on_meta_data(SrsSharedPtrMessage* metadata) | 159 | +int SrsForwarder::on_meta_data(SrsSharedPtrMessage* __metadata) |
| 160 | { | 160 | { |
| 161 | int ret = ERROR_SUCCESS; | 161 | int ret = ERROR_SUCCESS; |
| 162 | + | ||
| 163 | + SrsSharedPtrMessage* metadata = __metadata->copy(); | ||
| 162 | 164 | ||
| 163 | if ((ret = jitter->correct(metadata, 0, 0, SrsRtmpJitterAlgorithmFULL)) != ERROR_SUCCESS) { | 165 | if ((ret = jitter->correct(metadata, 0, 0, SrsRtmpJitterAlgorithmFULL)) != ERROR_SUCCESS) { |
| 164 | srs_freep(metadata); | 166 | srs_freep(metadata); |
| @@ -172,10 +174,12 @@ int SrsForwarder::on_meta_data(SrsSharedPtrMessage* metadata) | @@ -172,10 +174,12 @@ int SrsForwarder::on_meta_data(SrsSharedPtrMessage* metadata) | ||
| 172 | return ret; | 174 | return ret; |
| 173 | } | 175 | } |
| 174 | 176 | ||
| 175 | -int SrsForwarder::on_audio(SrsSharedPtrMessage* msg) | 177 | +int SrsForwarder::on_audio(SrsSharedPtrMessage* __audio) |
| 176 | { | 178 | { |
| 177 | int ret = ERROR_SUCCESS; | 179 | int ret = ERROR_SUCCESS; |
| 178 | 180 | ||
| 181 | + SrsSharedPtrMessage* msg = __audio->copy(); | ||
| 182 | + | ||
| 179 | if ((ret = jitter->correct(msg, 0, 0, SrsRtmpJitterAlgorithmFULL)) != ERROR_SUCCESS) { | 183 | if ((ret = jitter->correct(msg, 0, 0, SrsRtmpJitterAlgorithmFULL)) != ERROR_SUCCESS) { |
| 180 | srs_freep(msg); | 184 | srs_freep(msg); |
| 181 | return ret; | 185 | return ret; |
| @@ -193,9 +197,11 @@ int SrsForwarder::on_audio(SrsSharedPtrMessage* msg) | @@ -193,9 +197,11 @@ int SrsForwarder::on_audio(SrsSharedPtrMessage* msg) | ||
| 193 | return ret; | 197 | return ret; |
| 194 | } | 198 | } |
| 195 | 199 | ||
| 196 | -int SrsForwarder::on_video(SrsSharedPtrMessage* msg) | 200 | +int SrsForwarder::on_video(SrsSharedPtrMessage* __video) |
| 197 | { | 201 | { |
| 198 | int ret = ERROR_SUCCESS; | 202 | int ret = ERROR_SUCCESS; |
| 203 | + | ||
| 204 | + SrsSharedPtrMessage* msg = __video->copy(); | ||
| 199 | 205 | ||
| 200 | if ((ret = jitter->correct(msg, 0, 0, SrsRtmpJitterAlgorithmFULL)) != ERROR_SUCCESS) { | 206 | if ((ret = jitter->correct(msg, 0, 0, SrsRtmpJitterAlgorithmFULL)) != ERROR_SUCCESS) { |
| 201 | srs_freep(msg); | 207 | srs_freep(msg); |
| @@ -80,9 +80,21 @@ public: | @@ -80,9 +80,21 @@ public: | ||
| 80 | public: | 80 | public: |
| 81 | virtual int on_publish(); | 81 | virtual int on_publish(); |
| 82 | virtual void on_unpublish(); | 82 | virtual void on_unpublish(); |
| 83 | - virtual int on_meta_data(SrsSharedPtrMessage* metadata); | ||
| 84 | - virtual int on_audio(SrsSharedPtrMessage* msg); | ||
| 85 | - virtual int on_video(SrsSharedPtrMessage* msg); | 83 | + /** |
| 84 | + * forward the audio packet. | ||
| 85 | + * @param __metadata, directly ptr, copy it if need to save it. | ||
| 86 | + */ | ||
| 87 | + virtual int on_meta_data(SrsSharedPtrMessage* __metadata); | ||
| 88 | + /** | ||
| 89 | + * forward the audio packet. | ||
| 90 | + * @param __audio, directly ptr, copy it if need to save it. | ||
| 91 | + */ | ||
| 92 | + virtual int on_audio(SrsSharedPtrMessage* __audio); | ||
| 93 | + /** | ||
| 94 | + * forward the video packet. | ||
| 95 | + * @param __video, directly ptr, copy it if need to save it. | ||
| 96 | + */ | ||
| 97 | + virtual int on_video(SrsSharedPtrMessage* __video); | ||
| 86 | // interface ISrsThreadHandler. | 98 | // interface ISrsThreadHandler. |
| 87 | public: | 99 | public: |
| 88 | virtual int cycle(); | 100 | virtual int cycle(); |
| @@ -1426,15 +1426,16 @@ int SrsHls::on_meta_data(SrsAmf0Object* metadata) | @@ -1426,15 +1426,16 @@ int SrsHls::on_meta_data(SrsAmf0Object* metadata) | ||
| 1426 | return ret; | 1426 | return ret; |
| 1427 | } | 1427 | } |
| 1428 | 1428 | ||
| 1429 | -int SrsHls::on_audio(SrsSharedPtrMessage* audio) | 1429 | +int SrsHls::on_audio(SrsSharedPtrMessage* __audio) |
| 1430 | { | 1430 | { |
| 1431 | int ret = ERROR_SUCCESS; | 1431 | int ret = ERROR_SUCCESS; |
| 1432 | 1432 | ||
| 1433 | - SrsAutoFree(SrsSharedPtrMessage, audio); | ||
| 1434 | - | ||
| 1435 | if (!hls_enabled) { | 1433 | if (!hls_enabled) { |
| 1436 | return ret; | 1434 | return ret; |
| 1437 | } | 1435 | } |
| 1436 | + | ||
| 1437 | + SrsSharedPtrMessage* audio = __audio->copy(); | ||
| 1438 | + SrsAutoFree(SrsSharedPtrMessage, audio); | ||
| 1438 | 1439 | ||
| 1439 | sample->clear(); | 1440 | sample->clear(); |
| 1440 | if ((ret = codec->audio_aac_demux(audio->payload, audio->size, sample)) != ERROR_SUCCESS) { | 1441 | if ((ret = codec->audio_aac_demux(audio->payload, audio->size, sample)) != ERROR_SUCCESS) { |
| @@ -1470,15 +1471,16 @@ int SrsHls::on_audio(SrsSharedPtrMessage* audio) | @@ -1470,15 +1471,16 @@ int SrsHls::on_audio(SrsSharedPtrMessage* audio) | ||
| 1470 | return ret; | 1471 | return ret; |
| 1471 | } | 1472 | } |
| 1472 | 1473 | ||
| 1473 | -int SrsHls::on_video(SrsSharedPtrMessage* video) | 1474 | +int SrsHls::on_video(SrsSharedPtrMessage* __video) |
| 1474 | { | 1475 | { |
| 1475 | int ret = ERROR_SUCCESS; | 1476 | int ret = ERROR_SUCCESS; |
| 1476 | 1477 | ||
| 1477 | - SrsAutoFree(SrsSharedPtrMessage, video); | ||
| 1478 | - | ||
| 1479 | if (!hls_enabled) { | 1478 | if (!hls_enabled) { |
| 1480 | return ret; | 1479 | return ret; |
| 1481 | } | 1480 | } |
| 1481 | + | ||
| 1482 | + SrsSharedPtrMessage* video = __video->copy(); | ||
| 1483 | + SrsAutoFree(SrsSharedPtrMessage, video); | ||
| 1482 | 1484 | ||
| 1483 | sample->clear(); | 1485 | sample->clear(); |
| 1484 | if ((ret = codec->video_avc_demux(video->payload, video->size, sample)) != ERROR_SUCCESS) { | 1486 | if ((ret = codec->video_avc_demux(video->payload, video->size, sample)) != ERROR_SUCCESS) { |
| @@ -326,12 +326,14 @@ public: | @@ -326,12 +326,14 @@ public: | ||
| 326 | virtual int on_meta_data(SrsAmf0Object* metadata); | 326 | virtual int on_meta_data(SrsAmf0Object* metadata); |
| 327 | /** | 327 | /** |
| 328 | * mux the audio packets to ts. | 328 | * mux the audio packets to ts. |
| 329 | + * @param __audio, directly ptr, copy it if need to save it. | ||
| 329 | */ | 330 | */ |
| 330 | - virtual int on_audio(SrsSharedPtrMessage* audio); | 331 | + virtual int on_audio(SrsSharedPtrMessage* __audio); |
| 331 | /** | 332 | /** |
| 332 | * mux the video packets to ts. | 333 | * mux the video packets to ts. |
| 334 | + * @param __video, directly ptr, copy it if need to save it. | ||
| 333 | */ | 335 | */ |
| 334 | - virtual int on_video(SrsSharedPtrMessage* video); | 336 | + virtual int on_video(SrsSharedPtrMessage* __video); |
| 335 | private: | 337 | private: |
| 336 | virtual void hls_mux(); | 338 | virtual void hls_mux(); |
| 337 | }; | 339 | }; |
| @@ -332,10 +332,12 @@ int SrsConsumer::get_time() | @@ -332,10 +332,12 @@ int SrsConsumer::get_time() | ||
| 332 | return jitter->get_time(); | 332 | return jitter->get_time(); |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | -int SrsConsumer::enqueue(SrsSharedPtrMessage* msg, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm ag) | 335 | +int SrsConsumer::enqueue(SrsSharedPtrMessage* __msg, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm ag) |
| 336 | { | 336 | { |
| 337 | int ret = ERROR_SUCCESS; | 337 | int ret = ERROR_SUCCESS; |
| 338 | 338 | ||
| 339 | + SrsSharedPtrMessage* msg = __msg->copy(); | ||
| 340 | + | ||
| 339 | if (!atc) { | 341 | if (!atc) { |
| 340 | if ((ret = jitter->correct(msg, tba, tbv, ag)) != ERROR_SUCCESS) { | 342 | if ((ret = jitter->correct(msg, tba, tbv, ag)) != ERROR_SUCCESS) { |
| 341 | srs_freep(msg); | 343 | srs_freep(msg); |
| @@ -409,7 +411,7 @@ void SrsGopCache::set(bool enabled) | @@ -409,7 +411,7 @@ void SrsGopCache::set(bool enabled) | ||
| 409 | srs_info("enable gop cache"); | 411 | srs_info("enable gop cache"); |
| 410 | } | 412 | } |
| 411 | 413 | ||
| 412 | -int SrsGopCache::cache(SrsSharedPtrMessage* msg) | 414 | +int SrsGopCache::cache(SrsSharedPtrMessage* __msg) |
| 413 | { | 415 | { |
| 414 | int ret = ERROR_SUCCESS; | 416 | int ret = ERROR_SUCCESS; |
| 415 | 417 | ||
| @@ -418,6 +420,9 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | @@ -418,6 +420,9 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | ||
| 418 | return ret; | 420 | return ret; |
| 419 | } | 421 | } |
| 420 | 422 | ||
| 423 | + // the gop cache know when to gop it. | ||
| 424 | + SrsSharedPtrMessage* msg = __msg; | ||
| 425 | + | ||
| 421 | // disable gop cache when not h.264 | 426 | // disable gop cache when not h.264 |
| 422 | if (!SrsFlvCodec::video_is_h264(msg->payload, msg->size)) { | 427 | if (!SrsFlvCodec::video_is_h264(msg->payload, msg->size)) { |
| 423 | srs_info("gop donot cache video for none h.264"); | 428 | srs_info("gop donot cache video for none h.264"); |
| @@ -840,15 +845,15 @@ int SrsSource::on_forwarder_start(SrsForwarder* forwarder) | @@ -840,15 +845,15 @@ int SrsSource::on_forwarder_start(SrsForwarder* forwarder) | ||
| 840 | 845 | ||
| 841 | // feed the forwarder the metadata/sequence header, | 846 | // feed the forwarder the metadata/sequence header, |
| 842 | // when reload to enable the forwarder. | 847 | // when reload to enable the forwarder. |
| 843 | - if (cache_metadata && (ret = forwarder->on_meta_data(cache_metadata->copy())) != ERROR_SUCCESS) { | 848 | + if (cache_metadata && (ret = forwarder->on_meta_data(cache_metadata)) != ERROR_SUCCESS) { |
| 844 | srs_error("forwarder process onMetaData message failed. ret=%d", ret); | 849 | srs_error("forwarder process onMetaData message failed. ret=%d", ret); |
| 845 | return ret; | 850 | return ret; |
| 846 | } | 851 | } |
| 847 | - if (cache_sh_video && (ret = forwarder->on_video(cache_sh_video->copy())) != ERROR_SUCCESS) { | 852 | + if (cache_sh_video && (ret = forwarder->on_video(cache_sh_video)) != ERROR_SUCCESS) { |
| 848 | srs_error("forwarder process video sequence header message failed. ret=%d", ret); | 853 | srs_error("forwarder process video sequence header message failed. ret=%d", ret); |
| 849 | return ret; | 854 | return ret; |
| 850 | } | 855 | } |
| 851 | - if (cache_sh_audio && (ret = forwarder->on_audio(cache_sh_audio->copy())) != ERROR_SUCCESS) { | 856 | + if (cache_sh_audio && (ret = forwarder->on_audio(cache_sh_audio)) != ERROR_SUCCESS) { |
| 852 | srs_error("forwarder process audio sequence header message failed. ret=%d", ret); | 857 | srs_error("forwarder process audio sequence header message failed. ret=%d", ret); |
| 853 | return ret; | 858 | return ret; |
| 854 | } | 859 | } |
| @@ -865,11 +870,11 @@ int SrsSource::on_hls_start() | @@ -865,11 +870,11 @@ int SrsSource::on_hls_start() | ||
| 865 | // when reload to start hls, hls will never get the sequence header in stream, | 870 | // when reload to start hls, hls will never get the sequence header in stream, |
| 866 | // use the SrsSource.on_hls_start to push the sequence header to HLS. | 871 | // use the SrsSource.on_hls_start to push the sequence header to HLS. |
| 867 | // TODO: maybe need to decode the metadata? | 872 | // TODO: maybe need to decode the metadata? |
| 868 | - if (cache_sh_video && (ret = hls->on_video(cache_sh_video->copy())) != ERROR_SUCCESS) { | 873 | + if (cache_sh_video && (ret = hls->on_video(cache_sh_video)) != ERROR_SUCCESS) { |
| 869 | srs_error("hls process video sequence header message failed. ret=%d", ret); | 874 | srs_error("hls process video sequence header message failed. ret=%d", ret); |
| 870 | return ret; | 875 | return ret; |
| 871 | } | 876 | } |
| 872 | - if (cache_sh_audio && (ret = hls->on_audio(cache_sh_audio->copy())) != ERROR_SUCCESS) { | 877 | + if (cache_sh_audio && (ret = hls->on_audio(cache_sh_audio)) != ERROR_SUCCESS) { |
| 873 | srs_error("hls process audio sequence header message failed. ret=%d", ret); | 878 | srs_error("hls process audio sequence header message failed. ret=%d", ret); |
| 874 | return ret; | 879 | return ret; |
| 875 | } | 880 | } |
| @@ -908,11 +913,11 @@ int SrsSource::on_dvr_request_sh() | @@ -908,11 +913,11 @@ int SrsSource::on_dvr_request_sh() | ||
| 908 | } | 913 | } |
| 909 | } | 914 | } |
| 910 | 915 | ||
| 911 | - if (cache_sh_video && (ret = dvr->on_video(cache_sh_video->copy())) != ERROR_SUCCESS) { | 916 | + if (cache_sh_video && (ret = dvr->on_video(cache_sh_video)) != ERROR_SUCCESS) { |
| 912 | srs_error("dvr process video sequence header message failed. ret=%d", ret); | 917 | srs_error("dvr process video sequence header message failed. ret=%d", ret); |
| 913 | return ret; | 918 | return ret; |
| 914 | } | 919 | } |
| 915 | - if (cache_sh_audio && (ret = dvr->on_audio(cache_sh_audio->copy())) != ERROR_SUCCESS) { | 920 | + if (cache_sh_audio && (ret = dvr->on_audio(cache_sh_audio)) != ERROR_SUCCESS) { |
| 916 | srs_error("dvr process audio sequence header message failed. ret=%d", ret); | 921 | srs_error("dvr process audio sequence header message failed. ret=%d", ret); |
| 917 | return ret; | 922 | return ret; |
| 918 | } | 923 | } |
| @@ -1048,8 +1053,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | @@ -1048,8 +1053,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | ||
| 1048 | std::vector<SrsConsumer*>::iterator it; | 1053 | std::vector<SrsConsumer*>::iterator it; |
| 1049 | for (it = consumers.begin(); it != consumers.end(); ++it) { | 1054 | for (it = consumers.begin(); it != consumers.end(); ++it) { |
| 1050 | SrsConsumer* consumer = *it; | 1055 | SrsConsumer* consumer = *it; |
| 1051 | - SrsSharedPtrMessage* copy = cache_metadata->copy(); | ||
| 1052 | - if ((ret = consumer->enqueue(copy, atc, sample_rate, frame_rate, jitter_algorithm)) != ERROR_SUCCESS) { | 1056 | + if ((ret = consumer->enqueue(cache_metadata, atc, sample_rate, frame_rate, jitter_algorithm)) != ERROR_SUCCESS) { |
| 1053 | srs_error("dispatch the metadata failed. ret=%d", ret); | 1057 | srs_error("dispatch the metadata failed. ret=%d", ret); |
| 1054 | return ret; | 1058 | return ret; |
| 1055 | } | 1059 | } |
| @@ -1062,7 +1066,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | @@ -1062,7 +1066,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | ||
| 1062 | std::vector<SrsForwarder*>::iterator it; | 1066 | std::vector<SrsForwarder*>::iterator it; |
| 1063 | for (it = forwarders.begin(); it != forwarders.end(); ++it) { | 1067 | for (it = forwarders.begin(); it != forwarders.end(); ++it) { |
| 1064 | SrsForwarder* forwarder = *it; | 1068 | SrsForwarder* forwarder = *it; |
| 1065 | - if ((ret = forwarder->on_meta_data(cache_metadata->copy())) != ERROR_SUCCESS) { | 1069 | + if ((ret = forwarder->on_meta_data(cache_metadata)) != ERROR_SUCCESS) { |
| 1066 | srs_error("forwarder process onMetaData message failed. ret=%d", ret); | 1070 | srs_error("forwarder process onMetaData message failed. ret=%d", ret); |
| 1067 | return ret; | 1071 | return ret; |
| 1068 | } | 1072 | } |
| @@ -1086,7 +1090,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | @@ -1086,7 +1090,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | ||
| 1086 | srs_verbose("initialize shared ptr audio success."); | 1090 | srs_verbose("initialize shared ptr audio success."); |
| 1087 | 1091 | ||
| 1088 | #ifdef SRS_AUTO_HLS | 1092 | #ifdef SRS_AUTO_HLS |
| 1089 | - if ((ret = hls->on_audio(msg.copy())) != ERROR_SUCCESS) { | 1093 | + if ((ret = hls->on_audio(&msg)) != ERROR_SUCCESS) { |
| 1090 | srs_warn("hls process audio message failed, ignore and disable hls. ret=%d", ret); | 1094 | srs_warn("hls process audio message failed, ignore and disable hls. ret=%d", ret); |
| 1091 | 1095 | ||
| 1092 | // unpublish, ignore ret. | 1096 | // unpublish, ignore ret. |
| @@ -1098,7 +1102,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | @@ -1098,7 +1102,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | ||
| 1098 | #endif | 1102 | #endif |
| 1099 | 1103 | ||
| 1100 | #ifdef SRS_AUTO_DVR | 1104 | #ifdef SRS_AUTO_DVR |
| 1101 | - if ((ret = dvr->on_audio(msg.copy())) != ERROR_SUCCESS) { | 1105 | + if ((ret = dvr->on_audio(&msg)) != ERROR_SUCCESS) { |
| 1102 | srs_warn("dvr process audio message failed, ignore and disable dvr. ret=%d", ret); | 1106 | srs_warn("dvr process audio message failed, ignore and disable dvr. ret=%d", ret); |
| 1103 | 1107 | ||
| 1104 | // unpublish, ignore ret. | 1108 | // unpublish, ignore ret. |
| @@ -1115,8 +1119,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | @@ -1115,8 +1119,7 @@ int SrsSource::on_audio(SrsCommonMessage* __audio) | ||
| 1115 | SrsConsumer** pconsumer = consumers.data(); | 1119 | SrsConsumer** pconsumer = consumers.data(); |
| 1116 | for (int i = 0; i < nb_consumers; i++) { | 1120 | for (int i = 0; i < nb_consumers; i++) { |
| 1117 | SrsConsumer* consumer = pconsumer[i]; | 1121 | SrsConsumer* consumer = pconsumer[i]; |
| 1118 | - SrsSharedPtrMessage* copy = msg.copy(); | ||
| 1119 | - if ((ret = consumer->enqueue(copy, atc, sample_rate, frame_rate, jitter_algorithm)) != ERROR_SUCCESS) { | 1122 | + if ((ret = consumer->enqueue(&msg, atc, sample_rate, frame_rate, jitter_algorithm)) != ERROR_SUCCESS) { |
| 1120 | srs_error("dispatch the audio failed. ret=%d", ret); | 1123 | srs_error("dispatch the audio failed. ret=%d", ret); |
| 1121 | return ret; | 1124 | return ret; |
| 1122 | } | 1125 | } |
| @@ -1197,7 +1200,7 @@ int SrsSource::on_video(SrsCommonMessage* __video) | @@ -1197,7 +1200,7 @@ int SrsSource::on_video(SrsCommonMessage* __video) | ||
| 1197 | srs_verbose("initialize shared ptr video success."); | 1200 | srs_verbose("initialize shared ptr video success."); |
| 1198 | 1201 | ||
| 1199 | #ifdef SRS_AUTO_HLS | 1202 | #ifdef SRS_AUTO_HLS |
| 1200 | - if ((ret = hls->on_video(msg.copy())) != ERROR_SUCCESS) { | 1203 | + if ((ret = hls->on_video(&msg)) != ERROR_SUCCESS) { |
| 1201 | srs_warn("hls process video message failed, ignore and disable hls. ret=%d", ret); | 1204 | srs_warn("hls process video message failed, ignore and disable hls. ret=%d", ret); |
| 1202 | 1205 | ||
| 1203 | // unpublish, ignore ret. | 1206 | // unpublish, ignore ret. |
| @@ -1209,7 +1212,7 @@ int SrsSource::on_video(SrsCommonMessage* __video) | @@ -1209,7 +1212,7 @@ int SrsSource::on_video(SrsCommonMessage* __video) | ||
| 1209 | #endif | 1212 | #endif |
| 1210 | 1213 | ||
| 1211 | #ifdef SRS_AUTO_DVR | 1214 | #ifdef SRS_AUTO_DVR |
| 1212 | - if ((ret = dvr->on_video(msg.copy())) != ERROR_SUCCESS) { | 1215 | + if ((ret = dvr->on_video(&msg)) != ERROR_SUCCESS) { |
| 1213 | srs_warn("dvr process video message failed, ignore and disable dvr. ret=%d", ret); | 1216 | srs_warn("dvr process video message failed, ignore and disable dvr. ret=%d", ret); |
| 1214 | 1217 | ||
| 1215 | // unpublish, ignore ret. | 1218 | // unpublish, ignore ret. |
| @@ -1224,8 +1227,7 @@ int SrsSource::on_video(SrsCommonMessage* __video) | @@ -1224,8 +1227,7 @@ int SrsSource::on_video(SrsCommonMessage* __video) | ||
| 1224 | if (true) { | 1227 | if (true) { |
| 1225 | for (int i = 0; i < (int)consumers.size(); i++) { | 1228 | for (int i = 0; i < (int)consumers.size(); i++) { |
| 1226 | SrsConsumer* consumer = consumers.at(i); | 1229 | SrsConsumer* consumer = consumers.at(i); |
| 1227 | - SrsSharedPtrMessage* copy = msg.copy(); | ||
| 1228 | - if ((ret = consumer->enqueue(copy, atc, sample_rate, frame_rate, jitter_algorithm)) != ERROR_SUCCESS) { | 1230 | + if ((ret = consumer->enqueue(&msg, atc, sample_rate, frame_rate, jitter_algorithm)) != ERROR_SUCCESS) { |
| 1229 | srs_error("dispatch the video failed. ret=%d", ret); | 1231 | srs_error("dispatch the video failed. ret=%d", ret); |
| 1230 | return ret; | 1232 | return ret; |
| 1231 | } | 1233 | } |
| @@ -1234,11 +1236,11 @@ int SrsSource::on_video(SrsCommonMessage* __video) | @@ -1234,11 +1236,11 @@ int SrsSource::on_video(SrsCommonMessage* __video) | ||
| 1234 | } | 1236 | } |
| 1235 | 1237 | ||
| 1236 | // copy to all forwarders. | 1238 | // copy to all forwarders. |
| 1237 | - if (true) { | 1239 | + if (!forwarders.empty()) { |
| 1238 | std::vector<SrsForwarder*>::iterator it; | 1240 | std::vector<SrsForwarder*>::iterator it; |
| 1239 | for (it = forwarders.begin(); it != forwarders.end(); ++it) { | 1241 | for (it = forwarders.begin(); it != forwarders.end(); ++it) { |
| 1240 | SrsForwarder* forwarder = *it; | 1242 | SrsForwarder* forwarder = *it; |
| 1241 | - if ((ret = forwarder->on_video(msg.copy())) != ERROR_SUCCESS) { | 1243 | + if ((ret = forwarder->on_video(&msg)) != ERROR_SUCCESS) { |
| 1242 | srs_error("forwarder process video message failed. ret=%d", ret); | 1244 | srs_error("forwarder process video message failed. ret=%d", ret); |
| 1243 | return ret; | 1245 | return ret; |
| 1244 | } | 1246 | } |
| @@ -1512,20 +1514,20 @@ void SrsSource::on_unpublish() | @@ -1512,20 +1514,20 @@ void SrsSource::on_unpublish() | ||
| 1512 | SrsRtmpJitterAlgorithm ag = jitter_algorithm; | 1514 | SrsRtmpJitterAlgorithm ag = jitter_algorithm; |
| 1513 | 1515 | ||
| 1514 | // copy metadata. | 1516 | // copy metadata. |
| 1515 | - if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy(), atc, tba, tbv, ag)) != ERROR_SUCCESS) { | 1517 | + if (cache_metadata && (ret = consumer->enqueue(cache_metadata, atc, tba, tbv, ag)) != ERROR_SUCCESS) { |
| 1516 | srs_error("dispatch metadata failed. ret=%d", ret); | 1518 | srs_error("dispatch metadata failed. ret=%d", ret); |
| 1517 | return ret; | 1519 | return ret; |
| 1518 | } | 1520 | } |
| 1519 | srs_info("dispatch metadata success"); | 1521 | srs_info("dispatch metadata success"); |
| 1520 | 1522 | ||
| 1521 | // copy sequence header | 1523 | // copy sequence header |
| 1522 | - if (cache_sh_video && (ret = consumer->enqueue(cache_sh_video->copy(), atc, tba, tbv, ag)) != ERROR_SUCCESS) { | 1524 | + if (cache_sh_video && (ret = consumer->enqueue(cache_sh_video, atc, tba, tbv, ag)) != ERROR_SUCCESS) { |
| 1523 | srs_error("dispatch video sequence header failed. ret=%d", ret); | 1525 | srs_error("dispatch video sequence header failed. ret=%d", ret); |
| 1524 | return ret; | 1526 | return ret; |
| 1525 | } | 1527 | } |
| 1526 | srs_info("dispatch video sequence header success"); | 1528 | srs_info("dispatch video sequence header success"); |
| 1527 | 1529 | ||
| 1528 | - if (cache_sh_audio && (ret = consumer->enqueue(cache_sh_audio->copy(), atc, tba, tbv, ag)) != ERROR_SUCCESS) { | 1530 | + if (cache_sh_audio && (ret = consumer->enqueue(cache_sh_audio, atc, tba, tbv, ag)) != ERROR_SUCCESS) { |
| 1529 | srs_error("dispatch audio sequence header failed. ret=%d", ret); | 1531 | srs_error("dispatch audio sequence header failed. ret=%d", ret); |
| 1530 | return ret; | 1532 | return ret; |
| 1531 | } | 1533 | } |
| @@ -184,6 +184,7 @@ public: | @@ -184,6 +184,7 @@ public: | ||
| 184 | virtual int get_time(); | 184 | virtual int get_time(); |
| 185 | /** | 185 | /** |
| 186 | * enqueue an shared ptr message. | 186 | * enqueue an shared ptr message. |
| 187 | + * @param __msg, directly ptr, copy it if need to save it. | ||
| 187 | * @param whether atc, donot use jitter correct if true. | 188 | * @param whether atc, donot use jitter correct if true. |
| 188 | * @param tba timebase of audio. | 189 | * @param tba timebase of audio. |
| 189 | * used to calc the audio time delta if time-jitter detected. | 190 | * used to calc the audio time delta if time-jitter detected. |
| @@ -191,7 +192,7 @@ public: | @@ -191,7 +192,7 @@ public: | ||
| 191 | * used to calc the video time delta if time-jitter detected. | 192 | * used to calc the video time delta if time-jitter detected. |
| 192 | * @param ag the algorithm of time jitter. | 193 | * @param ag the algorithm of time jitter. |
| 193 | */ | 194 | */ |
| 194 | - virtual int enqueue(SrsSharedPtrMessage* msg, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm ag); | 195 | + virtual int enqueue(SrsSharedPtrMessage* __msg, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm ag); |
| 195 | /** | 196 | /** |
| 196 | * get packets in consumer queue. | 197 | * get packets in consumer queue. |
| 197 | * @param msgs the msgs array to dump packets to send. | 198 | * @param msgs the msgs array to dump packets to send. |
| @@ -252,8 +253,9 @@ public: | @@ -252,8 +253,9 @@ public: | ||
| 252 | * only for h264 codec | 253 | * only for h264 codec |
| 253 | * 1. cache the gop when got h264 video packet. | 254 | * 1. cache the gop when got h264 video packet. |
| 254 | * 2. clear gop when got keyframe. | 255 | * 2. clear gop when got keyframe. |
| 256 | + * @param __msg, directly ptr, copy it if need to save it. | ||
| 255 | */ | 257 | */ |
| 256 | - virtual int cache(SrsSharedPtrMessage* msg); | 258 | + virtual int cache(SrsSharedPtrMessage* __msg); |
| 257 | /** | 259 | /** |
| 258 | * clear the gop cache. | 260 | * clear the gop cache. |
| 259 | */ | 261 | */ |
-
请 注册 或 登录 后发表评论