Jump to content

RTMP Server Controller App

Zeruel

Hello fellow programmers!

 

 

So recently I was getting into RTMP servers for twitch streaming, since streaming to twitch using the RTMP method is way easier on the gaming PC. I have the ROG Swift, so capture cards are a no go and I need ~90% of my system resources going to gaming to push 144hz @ 1440p.

 

 

Setting up Nginx and the RTMP module is pretty dead easy.

 

Follow this guide ->  http://www.helping-squad.com/nginx-rtmp-installation/

 

Keep in mind im using Nginx 1.6.3 stable instead of 1.7.x mainline. Adjust your wget command for the latest Ngnix version.

 

 

I got it working and was able to stream to twitch.

 

The Linux commands are...

 

  • ./nginx "to start"
  • ./nginx -s stop "stop server"
  • ./nginx -s reload "reload configuration file" 

Also to change the bitrate, fps, and resolution you need to go in to the nginx.conf file. 

 

 

 

So now to my program!

 

What I plan to do is make a little GUI using curses to control some aspects of the server like turning it on,off, reloading the conf file, bitrate, fps, resolution, and CPU preset.

 

Here is a picture of my current progress.

 

jHDUcwG.png

 

 

Currently only the working options are ON,OFF, Reload, and EXIT. I plan to parse my way through the config file and figure out things from there.

 

My code!

 

#include <menu.h>#include <string.h>#include <stdlib.h>#include <string>#include <fstream>#include <iostream>#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))#define CTRLD 	4using namespace std;const char *appName = "Nginx Server Controller App";const char *choices[] = {                        "Turn ON",                        "Turn OFF",                        "Reload CONF",			"Bitrate",			"Framerate",			"CPU Preset",			"Resolution",			"EXIT",                        (char *)NULL,                  };void print_in_middle(WINDOW *win, int starty, int startx, int width, const char *string, chtype color);bool currentOption(  const char* input, WINDOW *my_menu_window, MENU *my_menu );bool nginxPID();int main(){	ITEM **my_items;	int c;					MENU *my_menu;        WINDOW *my_menu_win;        int n_choices, i;	bool loop = true;		/* Initialize curses */	initscr();	start_color();        cbreak();        noecho();	curs_set(0);	keypad(stdscr, TRUE);	init_pair(1, COLOR_RED, COLOR_BLACK);	init_pair(2, COLOR_CYAN, COLOR_BLACK);	init_pair(3, COLOR_MAGENTA, COLOR_BLACK);	init_pair(4, COLOR_GREEN, COLOR_BLACK);	init_pair(5, COLOR_WHITE, COLOR_BLACK);	/* Create items */        n_choices = ARRAY_SIZE(choices);        my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));        for(i = 0; i < n_choices; ++i)                my_items[i] = new_item(choices[i], 0 );	/* Crate menu */	my_menu = new_menu((ITEM **)my_items);	/* Create the window to be associated with the menu */        my_menu_win = newwin(25, 65, 4, 4);        keypad(my_menu_win, TRUE);     	/* Set main window and sub window */        set_menu_win(my_menu, my_menu_win);        set_menu_sub(my_menu, derwin(my_menu_win, 10, 38, 5, 18));	/* Set menu mark to the string " * " */        set_menu_mark(my_menu, " -> ");	/* Print a border around the main window and print a title */        box(my_menu_win, 0, 0);	print_in_middle(my_menu_win, 1, 0, 65, appName, COLOR_PAIR(1));	mvwaddch(my_menu_win, 2, 0, ACS_LTEE);	mvwhline(my_menu_win, 2, 1, ACS_HLINE, 65);	mvwaddch(my_menu_win, 2, 64, ACS_RTEE);	refresh();        	/* Post the menu */	post_menu(my_menu);	wrefresh(my_menu_win);	mvwprintw( my_menu_win, 3, 3, "Server Staus: " );		wattron( my_menu_win ,COLOR_PAIR(2));	mvwprintw( my_menu_win, 5, 3, "Server Options" );	for( i = 0; i < 3; ++i )	{		mvwprintw( my_menu_win, (5 + i), 17, "|" );	}	wattroff( my_menu_win, COLOR_PAIR(2));	wattron( my_menu_win, COLOR_PAIR(3));	mvwprintw( my_menu_win, 8, 3, "Encode Options" );	for( i = 0; i < 4; ++i )	{		mvwprintw( my_menu_win, (8 + i), 17, "|" );	}	wattroff( my_menu_win, COLOR_PAIR(3));		wattron( my_menu_win, COLOR_PAIR(5));	mvwprintw( my_menu_win, 12, 3, "Exit Program  " );	mvwprintw( my_menu_win, 12, 17, "|" );	wattroff( my_menu_win, COLOR_PAIR(5));	if( nginxPID() == false ) 	{		 mvwprintw( my_menu_win, 3, 16, " OFF    " );			}	else if( nginxPID() == true )	{	       mvwprintw( my_menu_win, 3, 16, " ON    " );	}		while( loop != false && (c = wgetch(my_menu_win))  )	{       switch(c)	        {	case KEY_DOWN:				menu_driver(my_menu, REQ_DOWN_ITEM);				break;			case KEY_UP:				menu_driver(my_menu, REQ_UP_ITEM);				break;			case 10:				loop = currentOption( item_name(current_item(my_menu)), my_menu_win, my_menu );				break;					}                wrefresh(my_menu_win);	}		/* Unpost and free all the memory taken up */	curs_set(1);        unpost_menu(my_menu);        free_menu(my_menu);        for(i = 0; i < n_choices; ++i)                free_item(my_items[i]);	endwin();	clear();	exit( EXIT_SUCCESS );}void print_in_middle(WINDOW *win, int starty, int startx, int width, const char *string, chtype color){	int length, x, y;	float temp;	if(win == NULL)		win = stdscr;	getyx(win, y, x);	if(startx != 0)		x = startx;	if(starty != 0)		y = starty;	if(width == 0)		width = 80;	length = strlen(string);	temp = (width - length)/ 2;	x = startx + (int)temp;	wattron(win, color);	mvwprintw(win, y, x, "%s", string);	wattroff(win, color);	refresh();}bool currentOption( const char* input, WINDOW *my_menu_win, MENU *my_menu ){	if( strcmp( input, choices[0] ) == 0 )	{		if( nginxPID() == false )		{			system( "./nginx" );			mvwprintw( my_menu_win, 3, 16, " ON                     " );		}	}	else if( strcmp( input, choices[1] ) == 0 )	{				if( nginxPID() == true )		{			system( "./nginx -s stop" );			mvwprintw( my_menu_win, 3, 16, " OFF                   " );		}	}			else if( strcmp( input, choices[2] ) == 0 )	{		if( nginxPID() == true )		{				system( "./nginx -s reload" );			mvwprintw( my_menu_win, 3, 16, " ON - Live and Reloaded" );		}	}	else if( strcmp( input, choices[3] ) == 0 )	{		//What to do here? Parse through nginx CONF  file Researching options			}	else if( strcmp( input, choices[4] ) == 0 )	{	}	else if( strcmp( input, choices[5] ) == 0 )	{			} 	else if( strcmp( input, choices[6] ) == 0 )	{	}	else if( strcmp( input, choices[7] ) == 0 )	{		if( nginxPID() == true )		{			system( "./nginx -s stop" );		}		return false;	}	return true;}bool nginxPID(){	ifstream pid("/usr/local/nginx/logs/nginx.pid" );	return pid.is_open();} 

Please feel free to make any comments or critique it!

[ Cruel Angel ]:     Exterior  -   BENQ XL2420T   |   SteelSeries MLG Sensei   |   Corsair K70 RED   |   Corsair 900D  |                                                                                                    CPU:    -   4.7Ghz @ 1.425v             |

                             Interior    -   i7 4770k   |    Maximus VI Formula    |   Corsair Vengeance Pro 16GB    |   ASUS GTX 980 Strix SLIx2  |  840 Pro 512Gb    |    WD Black 2TB  |           RAM:   -   2400Mhz OC @ 1.650v    |

                             Cooling   -   XSPC 120mm x7 Total Radiator Space   |   XSPC RayStorm    |    PrimoChill Tubing/Res  |                                                                                             GPU:   -   1000Mhz @ 1.158            |

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×