正在显示
6 个修改的文件
包含
43 行增加
和
41 行删除
| @@ -31,65 +31,65 @@ using namespace std; | @@ -31,65 +31,65 @@ using namespace std; | ||
| 31 | // the sleep interval for http async callback. | 31 | // the sleep interval for http async callback. |
| 32 | #define SRS_AUTO_ASYNC_CALLBACL_SLEEP_US 300000 | 32 | #define SRS_AUTO_ASYNC_CALLBACL_SLEEP_US 300000 |
| 33 | 33 | ||
| 34 | -ISrsDvrAsyncCall::ISrsDvrAsyncCall() | 34 | +ISrsAsyncCallTask::ISrsAsyncCallTask() |
| 35 | { | 35 | { |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | -ISrsDvrAsyncCall::~ISrsDvrAsyncCall() | 38 | +ISrsAsyncCallTask::~ISrsAsyncCallTask() |
| 39 | { | 39 | { |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | -SrsDvrAsyncCallThread::SrsDvrAsyncCallThread() | 42 | +SrsAsyncCallWorker::SrsAsyncCallWorker() |
| 43 | { | 43 | { |
| 44 | pthread = new SrsThread("async", this, SRS_AUTO_ASYNC_CALLBACL_SLEEP_US, true); | 44 | pthread = new SrsThread("async", this, SRS_AUTO_ASYNC_CALLBACL_SLEEP_US, true); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | -SrsDvrAsyncCallThread::~SrsDvrAsyncCallThread() | 47 | +SrsAsyncCallWorker::~SrsAsyncCallWorker() |
| 48 | { | 48 | { |
| 49 | stop(); | 49 | stop(); |
| 50 | srs_freep(pthread); | 50 | srs_freep(pthread); |
| 51 | 51 | ||
| 52 | - std::vector<ISrsDvrAsyncCall*>::iterator it; | ||
| 53 | - for (it = callbacks.begin(); it != callbacks.end(); ++it) { | ||
| 54 | - ISrsDvrAsyncCall* call = *it; | ||
| 55 | - srs_freep(call); | 52 | + std::vector<ISrsAsyncCallTask*>::iterator it; |
| 53 | + for (it = tasks.begin(); it != tasks.end(); ++it) { | ||
| 54 | + ISrsAsyncCallTask* task = *it; | ||
| 55 | + srs_freep(task); | ||
| 56 | } | 56 | } |
| 57 | - callbacks.clear(); | 57 | + tasks.clear(); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | -int SrsDvrAsyncCallThread::call(ISrsDvrAsyncCall* c) | 60 | +int SrsAsyncCallWorker::execute(ISrsAsyncCallTask* t) |
| 61 | { | 61 | { |
| 62 | int ret = ERROR_SUCCESS; | 62 | int ret = ERROR_SUCCESS; |
| 63 | 63 | ||
| 64 | - callbacks.push_back(c); | 64 | + tasks.push_back(t); |
| 65 | 65 | ||
| 66 | return ret; | 66 | return ret; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | -int SrsDvrAsyncCallThread::start() | 69 | +int SrsAsyncCallWorker::start() |
| 70 | { | 70 | { |
| 71 | return pthread->start(); | 71 | return pthread->start(); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | -void SrsDvrAsyncCallThread::stop() | 74 | +void SrsAsyncCallWorker::stop() |
| 75 | { | 75 | { |
| 76 | pthread->stop(); | 76 | pthread->stop(); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | -int SrsDvrAsyncCallThread::cycle() | 79 | +int SrsAsyncCallWorker::cycle() |
| 80 | { | 80 | { |
| 81 | int ret = ERROR_SUCCESS; | 81 | int ret = ERROR_SUCCESS; |
| 82 | 82 | ||
| 83 | - std::vector<ISrsDvrAsyncCall*> copies = callbacks; | ||
| 84 | - callbacks.clear(); | 83 | + std::vector<ISrsAsyncCallTask*> copies = tasks; |
| 84 | + tasks.clear(); | ||
| 85 | 85 | ||
| 86 | - std::vector<ISrsDvrAsyncCall*>::iterator it; | 86 | + std::vector<ISrsAsyncCallTask*>::iterator it; |
| 87 | for (it = copies.begin(); it != copies.end(); ++it) { | 87 | for (it = copies.begin(); it != copies.end(); ++it) { |
| 88 | - ISrsDvrAsyncCall* call = *it; | ||
| 89 | - if ((ret = call->call()) != ERROR_SUCCESS) { | ||
| 90 | - srs_warn("ignore async callback %s, ret=%d", call->to_string().c_str(), ret); | 88 | + ISrsAsyncCallTask* task = *it; |
| 89 | + if ((ret = task->call()) != ERROR_SUCCESS) { | ||
| 90 | + srs_warn("ignore async callback %s, ret=%d", task->to_string().c_str(), ret); | ||
| 91 | } | 91 | } |
| 92 | - srs_freep(call); | 92 | + srs_freep(task); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | return ret; | 95 | return ret; |
| @@ -42,29 +42,31 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -42,29 +42,31 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 42 | * a video and pass it to the dvr again. | 42 | * a video and pass it to the dvr again. |
| 43 | * futhurmore, the aync call never block the main worker thread. | 43 | * futhurmore, the aync call never block the main worker thread. |
| 44 | */ | 44 | */ |
| 45 | -class ISrsDvrAsyncCall | 45 | +class ISrsAsyncCallTask |
| 46 | { | 46 | { |
| 47 | public: | 47 | public: |
| 48 | - ISrsDvrAsyncCall(); | ||
| 49 | - virtual ~ISrsDvrAsyncCall(); | 48 | + ISrsAsyncCallTask(); |
| 49 | + virtual ~ISrsAsyncCallTask(); | ||
| 50 | public: | 50 | public: |
| 51 | virtual int call() = 0; | 51 | virtual int call() = 0; |
| 52 | virtual std::string to_string() = 0; | 52 | virtual std::string to_string() = 0; |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | /** | 55 | /** |
| 56 | -* the async callback for dvr. | ||
| 57 | -*/ | ||
| 58 | -class SrsDvrAsyncCallThread : public ISrsThreadHandler | 56 | + * the async callback for dvr. |
| 57 | + * when worker call with the task, the worker will do it in isolate thread. | ||
| 58 | + * that is, the task is execute/call in async mode. | ||
| 59 | + */ | ||
| 60 | +class SrsAsyncCallWorker : public ISrsThreadHandler | ||
| 59 | { | 61 | { |
| 60 | private: | 62 | private: |
| 61 | SrsThread* pthread; | 63 | SrsThread* pthread; |
| 62 | - std::vector<ISrsDvrAsyncCall*> callbacks; | 64 | + std::vector<ISrsAsyncCallTask*> tasks; |
| 63 | public: | 65 | public: |
| 64 | - SrsDvrAsyncCallThread(); | ||
| 65 | - virtual ~SrsDvrAsyncCallThread(); | 66 | + SrsAsyncCallWorker(); |
| 67 | + virtual ~SrsAsyncCallWorker(); | ||
| 66 | public: | 68 | public: |
| 67 | - virtual int call(ISrsDvrAsyncCall* c); | 69 | + virtual int execute(ISrsAsyncCallTask* t); |
| 68 | public: | 70 | public: |
| 69 | virtual int start(); | 71 | virtual int start(); |
| 70 | virtual void stop(); | 72 | virtual void stop(); |
| @@ -548,7 +548,7 @@ SrsDvrPlan::SrsDvrPlan() | @@ -548,7 +548,7 @@ SrsDvrPlan::SrsDvrPlan() | ||
| 548 | 548 | ||
| 549 | dvr_enabled = false; | 549 | dvr_enabled = false; |
| 550 | segment = new SrsFlvSegment(this); | 550 | segment = new SrsFlvSegment(this); |
| 551 | - async = new SrsDvrAsyncCallThread(); | 551 | + async = new SrsAsyncCallWorker(); |
| 552 | } | 552 | } |
| 553 | 553 | ||
| 554 | SrsDvrPlan::~SrsDvrPlan() | 554 | SrsDvrPlan::~SrsDvrPlan() |
| @@ -629,7 +629,7 @@ int SrsDvrPlan::on_reap_segment() | @@ -629,7 +629,7 @@ int SrsDvrPlan::on_reap_segment() | ||
| 629 | { | 629 | { |
| 630 | int ret = ERROR_SUCCESS; | 630 | int ret = ERROR_SUCCESS; |
| 631 | 631 | ||
| 632 | - if ((ret = async->call(new SrsDvrAsyncCallOnDvr(req, segment->get_path()))) != ERROR_SUCCESS) { | 632 | + if ((ret = async->execute(new SrsDvrAsyncCallOnDvr(req, segment->get_path()))) != ERROR_SUCCESS) { |
| 633 | return ret; | 633 | return ret; |
| 634 | } | 634 | } |
| 635 | 635 |
| @@ -178,7 +178,7 @@ public: | @@ -178,7 +178,7 @@ public: | ||
| 178 | /** | 178 | /** |
| 179 | * the dvr async call. | 179 | * the dvr async call. |
| 180 | */ | 180 | */ |
| 181 | -class SrsDvrAsyncCallOnDvr : public ISrsDvrAsyncCall | 181 | +class SrsDvrAsyncCallOnDvr : public ISrsAsyncCallTask |
| 182 | { | 182 | { |
| 183 | private: | 183 | private: |
| 184 | std::string path; | 184 | std::string path; |
| @@ -206,7 +206,7 @@ public: | @@ -206,7 +206,7 @@ public: | ||
| 206 | SrsRequest* req; | 206 | SrsRequest* req; |
| 207 | protected: | 207 | protected: |
| 208 | SrsFlvSegment* segment; | 208 | SrsFlvSegment* segment; |
| 209 | - SrsDvrAsyncCallThread* async; | 209 | + SrsAsyncCallWorker* async; |
| 210 | bool dvr_enabled; | 210 | bool dvr_enabled; |
| 211 | public: | 211 | public: |
| 212 | SrsDvrPlan(); | 212 | SrsDvrPlan(); |
| @@ -286,7 +286,7 @@ SrsHlsMuxer::SrsHlsMuxer() | @@ -286,7 +286,7 @@ SrsHlsMuxer::SrsHlsMuxer() | ||
| 286 | acodec = SrsCodecAudioReserved1; | 286 | acodec = SrsCodecAudioReserved1; |
| 287 | should_write_cache = false; | 287 | should_write_cache = false; |
| 288 | should_write_file = true; | 288 | should_write_file = true; |
| 289 | - async = new SrsDvrAsyncCallThread(); | 289 | + async = new SrsAsyncCallWorker(); |
| 290 | context = new SrsTsContext(); | 290 | context = new SrsTsContext(); |
| 291 | } | 291 | } |
| 292 | 292 | ||
| @@ -669,7 +669,7 @@ int SrsHlsMuxer::segment_close(string log_desc) | @@ -669,7 +669,7 @@ int SrsHlsMuxer::segment_close(string log_desc) | ||
| 669 | segments.push_back(current); | 669 | segments.push_back(current); |
| 670 | 670 | ||
| 671 | // use async to call the http hooks, for it will cause thread switch. | 671 | // use async to call the http hooks, for it will cause thread switch. |
| 672 | - if ((ret = async->call(new SrsDvrAsyncCallOnHls(req, | 672 | + if ((ret = async->execute(new SrsDvrAsyncCallOnHls(req, |
| 673 | current->full_path, current->uri, m3u8, m3u8_url, | 673 | current->full_path, current->uri, m3u8, m3u8_url, |
| 674 | current->sequence_no, current->duration))) != ERROR_SUCCESS) | 674 | current->sequence_no, current->duration))) != ERROR_SUCCESS) |
| 675 | { | 675 | { |
| @@ -677,7 +677,7 @@ int SrsHlsMuxer::segment_close(string log_desc) | @@ -677,7 +677,7 @@ int SrsHlsMuxer::segment_close(string log_desc) | ||
| 677 | } | 677 | } |
| 678 | 678 | ||
| 679 | // use async to call the http hooks, for it will cause thread switch. | 679 | // use async to call the http hooks, for it will cause thread switch. |
| 680 | - if ((ret = async->call(new SrsDvrAsyncCallOnHlsNotify(req, current->uri))) != ERROR_SUCCESS) { | 680 | + if ((ret = async->execute(new SrsDvrAsyncCallOnHlsNotify(req, current->uri))) != ERROR_SUCCESS) { |
| 681 | return ret; | 681 | return ret; |
| 682 | } | 682 | } |
| 683 | 683 |
| @@ -159,7 +159,7 @@ public: | @@ -159,7 +159,7 @@ public: | ||
| 159 | /** | 159 | /** |
| 160 | * the hls async call: on_hls | 160 | * the hls async call: on_hls |
| 161 | */ | 161 | */ |
| 162 | -class SrsDvrAsyncCallOnHls : public ISrsDvrAsyncCall | 162 | +class SrsDvrAsyncCallOnHls : public ISrsAsyncCallTask |
| 163 | { | 163 | { |
| 164 | private: | 164 | private: |
| 165 | std::string path; | 165 | std::string path; |
| @@ -180,7 +180,7 @@ public: | @@ -180,7 +180,7 @@ public: | ||
| 180 | /** | 180 | /** |
| 181 | * the hls async call: on_hls_notify | 181 | * the hls async call: on_hls_notify |
| 182 | */ | 182 | */ |
| 183 | -class SrsDvrAsyncCallOnHlsNotify : public ISrsDvrAsyncCall | 183 | +class SrsDvrAsyncCallOnHlsNotify : public ISrsAsyncCallTask |
| 184 | { | 184 | { |
| 185 | private: | 185 | private: |
| 186 | std::string ts_url; | 186 | std::string ts_url; |
| @@ -215,7 +215,7 @@ private: | @@ -215,7 +215,7 @@ private: | ||
| 215 | double hls_aof_ratio; | 215 | double hls_aof_ratio; |
| 216 | double hls_fragment; | 216 | double hls_fragment; |
| 217 | double hls_window; | 217 | double hls_window; |
| 218 | - SrsDvrAsyncCallThread* async; | 218 | + SrsAsyncCallWorker* async; |
| 219 | private: | 219 | private: |
| 220 | // whether use floor algorithm for timestamp. | 220 | // whether use floor algorithm for timestamp. |
| 221 | bool hls_ts_floor; | 221 | bool hls_ts_floor; |
-
请 注册 或 登录 后发表评论