Skip to content

Commit

Permalink
[Update] docker support.
Browse files Browse the repository at this point in the history
  • Loading branch information
SighingSnow committed Jul 19, 2022
1 parent 2dfd727 commit b9218bd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const unsigned int screen_height = 600;
const unsigned int SCR_WIDTH = screen_width * scale;
const unsigned int SCR_HEIGHT = screen_height * scale;
// webrtc
const std::string DEFAULT_IP_ADDRESS = "127.0.0.1";
const uint16_t defaultPort = 8000;
// FFMPEG parameters
const int inlinesize[2] = {SCR_WIDTH*3,0}; // For sws_scale convert function
Expand Down
13 changes: 11 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void doMain(int argc,char* argv[])
Streamer* streamer = new Streamer(*scene);
bool dump_video_opt = false;
int ors_gpu_id = 0;
std::string ip_addr = "127.0.0.1";
// -h help
// -d dump local video
// -gpu number e.g. -gpu 0 is using cpu
Expand All @@ -34,16 +35,24 @@ void doMain(int argc,char* argv[])
ors_gpu_id = (argv[index+1][0]-'0');
std::cout<<"[MAIN] Trying to access "<<gpu_str[ors_gpu_id]<<" for encoding"<<std::endl;
index++;
}
else if(std::string(argv[index]) == "-docker") {
ip_addr = "host.docker.internal";
}
else if(std::string(argv[index]) == "-ip"){
if(index+1 >= argc) {
exit(-1);
}
ip_addr = std::string(argv[index+1]);
}
index++;
}
return;
};
parseArgv();

SetScene(scene);
scene->AttachStreamer(streamer);
streamer->beginStream(dump_video_opt,ors_gpu_id);
streamer->beginStream(dump_video_opt,ors_gpu_id,ip_addr);
scene->DrawScene();
streamer->endStream();
scene->Terminate();
Expand Down
5 changes: 5 additions & 0 deletions src/rtc_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ void RtcPublisher::setUp()
return;
}

void RtcPublisher::setPubAddr(const std::string addr)
{
DEFAULT_IP_ADDRESS = addr;
}

void RtcPublisher::publish(uint8_t *buf, int size) {
//TODO: current buf is raw, no pps and sps data
int index = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/rtc_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class RtcPublisher {
}
void setUp();
void publish(uint8_t *buf, int size);
void setPubAddr(const std::string addr);
~RtcPublisher(){
dc->close();
pc->close();
Expand All @@ -36,6 +37,7 @@ class RtcPublisher {
void setInputCallBack(std::function<void(char)>* func_keyboard,
std::function<void(double,double)>* func_mouse_move);
protected:
std::string DEFAULT_IP_ADDRESS = "127.0.0.1";
Configuration rtc_config;
shared_ptr<WebSocket> ws;
std::shared_ptr<H264FileParser> video;
Expand Down
1 change: 1 addition & 0 deletions src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ void Scene::initTrees()
t.radius = 22;
initBranch(t);
initLeaves(t.pos_,t.theight,t.radius,t.leaves_);
//std::cout<<"leaves num"<<t.leaves_.size()<<std::endl;
}
return;
}
Expand Down
7 changes: 4 additions & 3 deletions src/streamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Streamer::initRtmp() {
rtmp_publisher->setUp();
}

void Streamer::beginStream(bool dump_video_opt,int ors_gpu_id)
void Streamer::beginStream(bool dump_video_opt,int ors_gpu_id,std::string ip_addr)
{
encoder = new Encoder();
encoder->dump_video_option = dump_video_opt;
Expand All @@ -29,7 +29,7 @@ void Streamer::beginStream(bool dump_video_opt,int ors_gpu_id)
initRtmp();
}
else if(rtc_publish_option){
initRtc();
initRtc(ip_addr);
}
}

Expand Down Expand Up @@ -63,9 +63,10 @@ void Streamer::endStream()
encoder->endEncode();
}

void Streamer::initRtc()
void Streamer::initRtc(std::string ip_addr)
{
rtc_publisher = new RtcPublisher();
rtc_publisher->setPubAddr(ip_addr);
rtc_publisher->setUp();
// bind callback
func_keyboard = std::bind(&Scene::clientKeyboardCallback,scene_,std::placeholders::_1);
Expand Down
4 changes: 2 additions & 2 deletions src/streamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using json = nlohmann::json;
class Streamer {
public:
Streamer(Scene & scene);
void beginStream(bool dump_video_opt = false,int ors_gpu_id = 0);
void beginStream(bool dump_video_opt = false,int ors_gpu_id = 0,string ip_addr = "");
void endStream();
void encode(uint8_t* buffer);
void setDumpVideoOpt(bool val);
Expand All @@ -31,7 +31,7 @@ class Streamer {
RtmpPublisher* rtmp_publisher;
RtcPublisher* rtc_publisher;
private:
void initRtc();
void initRtc(std::string ip_addr);
void initRtmp();
void rtmpPublish(uint8_t* buf,int size);
void rtcPublish(uint8_t* buf,int size);
Expand Down

0 comments on commit b9218bd

Please sign in to comment.