Commit b929b395 authored by Mikhail Karpenko's avatar Mikhail Karpenko

WIP: compile streamer without errors

parent a7ff4fa8
/** /**
* @file FILENAME * @file srteamer.cpp
* @brief BRIEF DESCRIPTION * @brief Streamer implementation
* @copyright Copyright (C) YEAR Elphel Inc. * @copyright Copyright (C) 2017 Elphel Inc.
* @author AUTHOR <EMAIL> * @author AUTHOR <EMAIL>
* *
* @par License: * @par License:
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
using namespace std; using namespace std;
#undef RTSP_DEBUG //#undef RTSP_DEBUG
//#define RTSP_DEBUG #define RTSP_DEBUG
#undef RTSP_DEBUG_2 //#undef RTSP_DEBUG_2
//#define RTSP_DEBUG_2 #define RTSP_DEBUG_2
#ifdef RTSP_DEBUG #ifdef RTSP_DEBUG
#define D(a) a #define D(a) a
...@@ -48,14 +48,13 @@ using namespace std; ...@@ -48,14 +48,13 @@ using namespace std;
#define D2(a) #define D2(a)
#endif #endif
Streamer *Streamer::_streamer = NULL; //Streamer *Streamer::_streamer = NULL;
Streamer::Streamer(const map<string, string> &_args) { Streamer::Streamer(const map<string, string> &_args, int port_num) {
if(_streamer != NULL) sensor_port = port_num;
throw("can't make an another instance of streamer"); _streamer = this;
else
_streamer = this;
session = new Session(); session = new Session();
params = new Parameters(sensor_port);
args = _args; args = _args;
audio = NULL; audio = NULL;
session->process_audio = false; session->process_audio = false;
...@@ -65,7 +64,7 @@ Streamer::Streamer(const map<string, string> &_args) { ...@@ -65,7 +64,7 @@ Streamer::Streamer(const map<string, string> &_args) {
session->rtp_out.ip_cached = 0; session->rtp_out.ip_cached = 0;
session->video.fps_scale = 1; session->video.fps_scale = 1;
audio_init(); audio_init();
video = new Video(); video = new Video(sensor_port, params);
if(opt_present("f")) { if(opt_present("f")) {
float fps = 0; float fps = 0;
fps = atof(args["f"].c_str()); fps = atof(args["f"].c_str());
...@@ -79,13 +78,13 @@ D( cout << "use fps: " << fps << endl;) ...@@ -79,13 +78,13 @@ D( cout << "use fps: " << fps << endl;)
} }
void Streamer::audio_init(void) { void Streamer::audio_init(void) {
if(audio != NULL) { if (audio != NULL) {
D( cerr << "delete audio" << endl;) D(cerr << "delete audio" << endl;)
delete audio; delete audio;
} }
D( cout << "audio_enabled == " << session->process_audio << endl;) D(cout << "audio_enabled == " << session->process_audio << endl;)
audio = new Audio(session->process_audio, session->audio.sample_rate, session->audio.channels); audio = new Audio(session->process_audio, params, session->audio.sample_rate, session->audio.channels);
if(audio->present() && session->process_audio) { if (audio->present() && session->process_audio) {
session->process_audio = true; session->process_audio = true;
session->audio.type = audio->ptype(); session->audio.type = audio->ptype();
session->audio.sample_rate = audio->sample_rate(); session->audio.sample_rate = audio->sample_rate();
...@@ -101,6 +100,7 @@ D( cout << "audio_enabled == " << session->process_audio << endl;) ...@@ -101,6 +100,7 @@ D( cout << "audio_enabled == " << session->process_audio << endl;)
Streamer::~Streamer(void) { Streamer::~Streamer(void) {
delete video; delete video;
delete audio; delete audio;
delete params;
} }
int Streamer::f_handler(void *ptr, RTSP_Server *rtsp_server, RTSP_Server::event event) { int Streamer::f_handler(void *ptr, RTSP_Server *rtsp_server, RTSP_Server::event event) {
...@@ -122,7 +122,7 @@ D( cerr << "update_settings" << endl;) ...@@ -122,7 +122,7 @@ D( cerr << "update_settings" << endl;)
// if(connected_count == 0) { // if(connected_count == 0) {
// don't change "on the fly" if someone already connected - like mcast clients // don't change "on the fly" if someone already connected - like mcast clients
Parameters *params = Parameters::instance(); // Parameters *params = Parameters::instance();
// multicast parameters // multicast parameters
// - multicast ip // - multicast ip
// new values // new values
...@@ -350,7 +350,7 @@ D( cerr << "event: running= " << running << " ";) ...@@ -350,7 +350,7 @@ D( cerr << "event: running= " << running << " ";)
update_settings(true); update_settings(true);
break; break;
case RTSP_Server::PARAMS_WAS_CHANGED: /// Update frame size, fps before starting new stream (generating SDP file) case RTSP_Server::PARAMS_WAS_CHANGED: /// Update frame size, fps before starting new stream (generating SDP file)
return (update_settings(false) || !(Parameters::instance()->daemon_enabled())); return (update_settings(false) || !(params->daemon_enabled()));
case RTSP_Server::PLAY: case RTSP_Server::PLAY:
D( cerr << "==PLAY==";) D( cerr << "==PLAY==";)
if(connected_count == 0) { if(connected_count == 0) {
...@@ -421,7 +421,7 @@ D( cerr << endl;) ...@@ -421,7 +421,7 @@ D( cerr << endl;)
} }
void Streamer::Main(void) { void Streamer::Main(void) {
D( cerr << "start Main" << endl;) D( cerr << "start Main for sensor port " << sensor_port << endl;)
string def_mcast = "232.1.1.1"; string def_mcast = "232.1.1.1";
int def_port = 20020; int def_port = 20020;
string def_ttl = "2"; string def_ttl = "2";
...@@ -433,29 +433,36 @@ D( cerr << "start Main" << endl;) ...@@ -433,29 +433,36 @@ D( cerr << "start Main" << endl;)
session->rtp_out.port_audio = def_port + 2; session->rtp_out.port_audio = def_port + 2;
session->rtp_out.ttl = def_ttl; session->rtp_out.ttl = def_ttl;
rtsp_server = NULL; rtsp_server = NULL;
while(true) { while (true) {
/// Check if the streamer is enabled, restart loop after waiting /// Check if the streamer is enabled, restart loop after waiting
if(!video->waitDaemonEnabled(-1)) { if (!video->waitDaemonEnabled(-1)) {
sched_yield(); sched_yield();
continue; /// may use particular bit instead of the "default" -1 continue; /// may use particular bit instead of the "default" -1
} }
update_settings(true); update_settings(true);
/// Got here if is and was enabled (may use more actions instead of just "continue" /// Got here if is and was enabled (may use more actions instead of just "continue"
// start RTSP server // start RTSP server
D2( cerr << "start server" << endl;) D2( cerr << "start server" << endl;)
if(rtsp_server == NULL) if (rtsp_server == NULL)
rtsp_server = new RTSP_Server(Streamer::f_handler, (void *)this, session); rtsp_server = new RTSP_Server(Streamer::f_handler, (void *) this, params, session);
rtsp_server->main(); rtsp_server->main();
D2( cerr << "server was stopped" << endl;) D2( cerr << "server was stopped" << endl;)
D2( cerr << "stop video" << endl;) D2( cerr << "stop video" << endl;)
video->Stop(); video->Stop();
D2( cerr << "stop audio" << endl;) D2( cerr << "stop audio" << endl;)
if(audio != NULL) { if (audio != NULL) {
audio->Stop(); audio->Stop();
// free audio resource - other app can use soundcard // free audio resource - other app can use soundcard
D2( cerr << "delete audio" << endl;) D2( cerr << "delete audio" << endl;)
delete audio; delete audio;
audio = NULL; audio = NULL;
} }
} }
} }
void *Streamer::pthread_f(void *_this)
{
Streamer *__this = (Streamer *)_this;
__this->Main();
return NULL;
}
/** /**
* @file FILENAME * @file streamer.h
* @brief BRIEF DESCRIPTION * @brief Streamer implementation
* @copyright Copyright (C) YEAR Elphel Inc. * @copyright Copyright (C) 2017 Elphel Inc.
* @author AUTHOR <EMAIL> * @author AUTHOR <EMAIL>
* *
* @par License: * @par License:
...@@ -33,7 +33,7 @@ using namespace std; ...@@ -33,7 +33,7 @@ using namespace std;
class Streamer { class Streamer {
public: public:
Streamer(const map<string, string> &args); Streamer(const map<string, string> &args, int port_num);
~Streamer(); ~Streamer();
void Main(void); void Main(void);
bool opt_present(string name) { bool opt_present(string name) {
...@@ -41,11 +41,13 @@ public: ...@@ -41,11 +41,13 @@ public:
return true; return true;
return false; return false;
} }
static Streamer *instance(void) { Streamer *instance(void) {
return _streamer; return _streamer;
} }
static void *pthread_f(void *_this);
protected: protected:
static Streamer *_streamer; Streamer *_streamer;
static int f_handler(void *ptr, RTSP_Server *rtsp_server, RTSP_Server::event event); static int f_handler(void *ptr, RTSP_Server *rtsp_server, RTSP_Server::event event);
int handler(RTSP_Server *rtsp_server, RTSP_Server::event event); int handler(RTSP_Server *rtsp_server, RTSP_Server::event event);
...@@ -54,9 +56,11 @@ protected: ...@@ -54,9 +56,11 @@ protected:
map<string, string> args; map<string, string> args;
RTSP_Server *rtsp_server; RTSP_Server *rtsp_server;
Session *session; Session *session;
int sensor_port;
Audio *audio; Audio *audio;
Video *video; Video *video;
Parameters *params;
bool running; bool running;
int connected_count; int connected_count;
void audio_init(void); void audio_init(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment