正在显示
5 个修改的文件
包含
27 行增加
和
0 行删除
| @@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 26 | #ifdef SRS_AUTO_DVR | 26 | #ifdef SRS_AUTO_DVR |
| 27 | 27 | ||
| 28 | #include <srs_kernel_error.hpp> | 28 | #include <srs_kernel_error.hpp> |
| 29 | +#include <srs_protocol_rtmp_stack.hpp> | ||
| 29 | 30 | ||
| 30 | SrsDvr::SrsDvr(SrsSource* source) | 31 | SrsDvr::SrsDvr(SrsSource* source) |
| 31 | { | 32 | { |
| @@ -55,12 +56,14 @@ int SrsDvr::on_meta_data(SrsAmf0Object* metadata) | @@ -55,12 +56,14 @@ int SrsDvr::on_meta_data(SrsAmf0Object* metadata) | ||
| 55 | int SrsDvr::on_audio(SrsSharedPtrMessage* audio) | 56 | int SrsDvr::on_audio(SrsSharedPtrMessage* audio) |
| 56 | { | 57 | { |
| 57 | int ret = ERROR_SUCCESS; | 58 | int ret = ERROR_SUCCESS; |
| 59 | + srs_freep(audio); | ||
| 58 | return ret; | 60 | return ret; |
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | int SrsDvr::on_video(SrsSharedPtrMessage* video) | 63 | int SrsDvr::on_video(SrsSharedPtrMessage* video) |
| 62 | { | 64 | { |
| 63 | int ret = ERROR_SUCCESS; | 65 | int ret = ERROR_SUCCESS; |
| 66 | + srs_freep(video); | ||
| 64 | return ret; | 67 | return ret; |
| 65 | } | 68 | } |
| 66 | 69 |
| @@ -79,6 +79,7 @@ int SrsEncoder::on_publish(SrsRequest* req) | @@ -79,6 +79,7 @@ int SrsEncoder::on_publish(SrsRequest* req) | ||
| 79 | srs_error("st_thread_create failed. ret=%d", ret); | 79 | srs_error("st_thread_create failed. ret=%d", ret); |
| 80 | return ret; | 80 | return ret; |
| 81 | } | 81 | } |
| 82 | + srs_trace("encoder thread cid=%d, current_cid=%d", pthread->cid(), _srs_context->get_id()); | ||
| 82 | 83 | ||
| 83 | return ret; | 84 | return ret; |
| 84 | } | 85 | } |
| @@ -61,6 +61,7 @@ SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us) | @@ -61,6 +61,7 @@ SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us) | ||
| 61 | 61 | ||
| 62 | tid = NULL; | 62 | tid = NULL; |
| 63 | loop = false; | 63 | loop = false; |
| 64 | + _cid = -1; | ||
| 64 | } | 65 | } |
| 65 | 66 | ||
| 66 | SrsThread::~SrsThread() | 67 | SrsThread::~SrsThread() |
| @@ -68,6 +69,11 @@ SrsThread::~SrsThread() | @@ -68,6 +69,11 @@ SrsThread::~SrsThread() | ||
| 68 | stop(); | 69 | stop(); |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 72 | +int SrsThread::cid() | ||
| 73 | +{ | ||
| 74 | + return _cid; | ||
| 75 | +} | ||
| 76 | + | ||
| 71 | int SrsThread::start() | 77 | int SrsThread::start() |
| 72 | { | 78 | { |
| 73 | int ret = ERROR_SUCCESS; | 79 | int ret = ERROR_SUCCESS; |
| @@ -83,6 +89,11 @@ int SrsThread::start() | @@ -83,6 +89,11 @@ int SrsThread::start() | ||
| 83 | return ret; | 89 | return ret; |
| 84 | } | 90 | } |
| 85 | 91 | ||
| 92 | + // wait for cid to ready, for parent thread to get the cid. | ||
| 93 | + while (_cid < 0) { | ||
| 94 | + st_usleep(10 * SRS_TIME_MILLISECONDS); | ||
| 95 | + } | ||
| 96 | + | ||
| 86 | return ret; | 97 | return ret; |
| 87 | } | 98 | } |
| 88 | 99 | ||
| @@ -111,6 +122,7 @@ void SrsThread::thread_cycle() | @@ -111,6 +122,7 @@ void SrsThread::thread_cycle() | ||
| 111 | { | 122 | { |
| 112 | int ret = ERROR_SUCCESS; | 123 | int ret = ERROR_SUCCESS; |
| 113 | 124 | ||
| 125 | + _cid = _srs_context->get_id(); | ||
| 114 | srs_assert(handler); | 126 | srs_assert(handler); |
| 115 | 127 | ||
| 116 | _srs_context->generate_id(); | 128 | _srs_context->generate_id(); |
| @@ -84,6 +84,7 @@ class SrsThread | @@ -84,6 +84,7 @@ class SrsThread | ||
| 84 | { | 84 | { |
| 85 | private: | 85 | private: |
| 86 | st_thread_t tid; | 86 | st_thread_t tid; |
| 87 | + int _cid; | ||
| 87 | bool loop; | 88 | bool loop; |
| 88 | private: | 89 | private: |
| 89 | ISrsThreadHandler* handler; | 90 | ISrsThreadHandler* handler; |
| @@ -98,6 +99,12 @@ public: | @@ -98,6 +99,12 @@ public: | ||
| 98 | virtual ~SrsThread(); | 99 | virtual ~SrsThread(); |
| 99 | public: | 100 | public: |
| 100 | /** | 101 | /** |
| 102 | + * get the context id. @see: ISrsThreadContext.get_id(). | ||
| 103 | + * used for parent thread to get the id. | ||
| 104 | + * @remark when start thread, parent thread will block and wait for this id ready. | ||
| 105 | + */ | ||
| 106 | + virtual int cid(); | ||
| 107 | + /** | ||
| 101 | * start the thread, invoke the cycle of handler util | 108 | * start the thread, invoke the cycle of handler util |
| 102 | * user stop the thread. | 109 | * user stop the thread. |
| 103 | * @remark ignore any error of cycle of handler. | 110 | * @remark ignore any error of cycle of handler. |
| @@ -124,4 +124,8 @@ extern bool srs_is_little_endian(); | @@ -124,4 +124,8 @@ extern bool srs_is_little_endian(); | ||
| 124 | className(const className&); \ | 124 | className(const className&); \ |
| 125 | className& operator= (const className&) | 125 | className& operator= (const className&) |
| 126 | 126 | ||
| 127 | +// const time for st to convert to us | ||
| 128 | +#define SRS_TIME_MILLISECONDS 1000 | ||
| 129 | +#define SRS_TIME_SECONDS 1000000 | ||
| 130 | + | ||
| 127 | #endif | 131 | #endif |
-
请 注册 或 登录 后发表评论