winlin

refine ingest, start/stop ingest in server

@@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 32
33 SrsIngester::SrsIngester() 33 SrsIngester::SrsIngester()
34 { 34 {
  35 + // TODO: FIXME: support reload.
35 pthread = new SrsThread(this, SRS_INGESTER_SLEEP_US); 36 pthread = new SrsThread(this, SRS_INGESTER_SLEEP_US);
36 } 37 }
37 38
@@ -40,6 +41,16 @@ SrsIngester::~SrsIngester() @@ -40,6 +41,16 @@ SrsIngester::~SrsIngester()
40 srs_freep(pthread); 41 srs_freep(pthread);
41 } 42 }
42 43
  44 +int SrsIngester::start()
  45 +{
  46 + int ret = ERROR_SUCCESS;
  47 + return ret;
  48 +}
  49 +
  50 +void SrsIngester::stop()
  51 +{
  52 +}
  53 +
43 int SrsIngester::cycle() 54 int SrsIngester::cycle()
44 { 55 {
45 int ret = ERROR_SUCCESS; 56 int ret = ERROR_SUCCESS;
@@ -31,15 +31,29 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,15 +31,29 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 31
32 #ifdef SRS_INGEST 32 #ifdef SRS_INGEST
33 33
  34 +#include <vector>
  35 +
34 #include <srs_app_thread.hpp> 36 #include <srs_app_thread.hpp>
35 37
  38 +class SrsFFMPEG;
  39 +
  40 +/**
  41 +* ingest file/stream/device,
  42 +* encode with FFMPEG(optional),
  43 +* push to SRS(or any RTMP server) over RTMP.
  44 +*/
36 class SrsIngester : public ISrsThreadHandler 45 class SrsIngester : public ISrsThreadHandler
37 { 46 {
38 private: 47 private:
  48 + std::vector<SrsFFMPEG*> ffmpegs;
  49 +private:
39 SrsThread* pthread; 50 SrsThread* pthread;
40 public: 51 public:
41 SrsIngester(); 52 SrsIngester();
42 virtual ~SrsIngester(); 53 virtual ~SrsIngester();
  54 +public:
  55 + virtual int start();
  56 + virtual void stop();
43 // interface ISrsThreadHandler. 57 // interface ISrsThreadHandler.
44 public: 58 public:
45 virtual int cycle(); 59 virtual int cycle();
@@ -169,6 +169,9 @@ SrsServer::SrsServer() @@ -169,6 +169,9 @@ SrsServer::SrsServer()
169 #ifdef SRS_HTTP_SERVER 169 #ifdef SRS_HTTP_SERVER
170 http_stream_handler = SrsHttpHandler::create_http_stream(); 170 http_stream_handler = SrsHttpHandler::create_http_stream();
171 #endif 171 #endif
  172 +#ifdef SRS_INGEST
  173 + ingester = new SrsIngester();
  174 +#endif
172 } 175 }
173 176
174 SrsServer::~SrsServer() 177 SrsServer::~SrsServer()
@@ -193,6 +196,9 @@ SrsServer::~SrsServer() @@ -193,6 +196,9 @@ SrsServer::~SrsServer()
193 #ifdef SRS_HTTP_SERVER 196 #ifdef SRS_HTTP_SERVER
194 srs_freep(http_stream_handler); 197 srs_freep(http_stream_handler);
195 #endif 198 #endif
  199 +#ifdef SRS_INGEST
  200 + srs_freep(ingester);
  201 +#endif
196 } 202 }
197 203
198 int SrsServer::initialize() 204 int SrsServer::initialize()
@@ -371,11 +377,12 @@ int SrsServer::cycle() @@ -371,11 +377,12 @@ int SrsServer::cycle()
371 { 377 {
372 int ret = ERROR_SUCCESS; 378 int ret = ERROR_SUCCESS;
373 379
374 - // ingest streams  
375 - if ((ret = ingest_streams()) != ERROR_SUCCESS) {  
376 - srs_error("ingest streams failed. ret=%d", ret); 380 +#ifdef SRS_INGEST
  381 + if ((ret = ingester->start()) != ERROR_SUCCESS) {
  382 + srs_error("start ingest streams failed. ret=%d", ret);
377 return ret; 383 return ret;
378 } 384 }
  385 +#endif
379 386
380 // the deamon thread, update the time cache 387 // the deamon thread, update the time cache
381 while (true) { 388 while (true) {
@@ -404,6 +411,10 @@ int SrsServer::cycle() @@ -404,6 +411,10 @@ int SrsServer::cycle()
404 srs_trace("reload config success."); 411 srs_trace("reload config success.");
405 } 412 }
406 } 413 }
  414 +
  415 +#ifdef SRS_INGEST
  416 + ingester->stop();
  417 +#endif
407 418
408 return ret; 419 return ret;
409 } 420 }
@@ -448,15 +459,6 @@ void SrsServer::on_signal(int signo) @@ -448,15 +459,6 @@ void SrsServer::on_signal(int signo)
448 } 459 }
449 } 460 }
450 461
451 -int SrsServer::ingest_streams()  
452 -{  
453 - int ret = ERROR_SUCCESS;  
454 -#ifdef SRS_INGEST  
455 -  
456 -#endif  
457 - return ret;  
458 -}  
459 -  
460 void SrsServer::close_listeners() 462 void SrsServer::close_listeners()
461 { 463 {
462 std::vector<SrsListener*>::iterator it; 464 std::vector<SrsListener*>::iterator it;
@@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 class SrsServer; 39 class SrsServer;
40 class SrsConnection; 40 class SrsConnection;
41 class SrsHttpHandler; 41 class SrsHttpHandler;
  42 +class SrsIngester;
42 43
43 // listener type for server to identify the connection, 44 // listener type for server to identify the connection,
44 // that is, use different type to process the connection. 45 // that is, use different type to process the connection.
@@ -83,6 +84,9 @@ private: @@ -83,6 +84,9 @@ private:
83 #ifdef SRS_HTTP_SERVER 84 #ifdef SRS_HTTP_SERVER
84 SrsHttpHandler* http_stream_handler; 85 SrsHttpHandler* http_stream_handler;
85 #endif 86 #endif
  87 +#ifdef SRS_INGEST
  88 + SrsIngester* ingester;
  89 +#endif
86 private: 90 private:
87 std::vector<SrsConnection*> conns; 91 std::vector<SrsConnection*> conns;
88 std::vector<SrsListener*> listeners; 92 std::vector<SrsListener*> listeners;
@@ -100,7 +104,6 @@ public: @@ -100,7 +104,6 @@ public:
100 virtual void remove(SrsConnection* conn); 104 virtual void remove(SrsConnection* conn);
101 virtual void on_signal(int signo); 105 virtual void on_signal(int signo);
102 private: 106 private:
103 - virtual int ingest_streams();  
104 virtual void close_listeners(); 107 virtual void close_listeners();
105 virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd); 108 virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd);
106 public: 109 public: