Skip to content
Permalink
Browse files

fixed recording bugs, isolated daemon service in separate user

  • Loading branch information...
jankammerath committed Jan 14, 2018
1 parent 8d21ea5 commit fdb5cdfe7d908941bde6f37001e0feeadd14050c
Showing with 38 additions and 8 deletions.
  1. +4 −0 Makefile
  2. BIN bin/iptvx
  3. +1 −0 iptvx.service
  4. +2 −0 iptvx.spec
  5. +28 −6 src/daemon.c
  6. +2 −1 src/db.c
  7. +1 −1 src/record.c
@@ -25,6 +25,8 @@ install:
chmod 644 /var/iptvx -R
chmod 644 /etc/iptvx -R
cp iptvx.service /etc/systemd/system/iptvx.service
useradd iptv
usermod -L iptv

clean:
rm -f bin/iptvx
@@ -44,3 +46,5 @@ packinstall:
chmod 644 $(DESTDIR)/var/iptvx -R
chmod 644 $(DESTDIR)/etc/iptvx -R
cp iptvx.service $(DESTDIR)/etc/systemd/system/iptvx.service
useradd iptv
usermod -L iptv
BIN +80 Bytes (100%) bin/iptvx
Binary file not shown.
@@ -4,6 +4,7 @@ Description=iptvx epg and recording service
[Service]
Type=simple
ExecStart=/usr/bin/iptvx --daemon
User=iptv

[Install]
WantedBy=multi-user.target
@@ -70,6 +70,8 @@ mkdir -p %{buildroot}%{_var}/iptvx/data/logo
cp app %{buildroot}%{_var}/iptvx/ -R
cp data/db %{buildroot}%{_var}/iptvx/db
chmod 755 %{buildroot}%{_var}/iptvx/ -R
useradd iptv
usermod -L iptv

%files
%{_bindir}/iptvx
@@ -308,9 +308,21 @@ GString* iptvx_daemon_get_recording_title(recording* rec){
recording iptvx_daemon_create_recording(char* channel, long start, long stop){
recording result;

result.channel = g_string_new(channel);
/* set the start time */
result.start = start;
if(result.start < time(NULL)){
/* recording should have started already, give it 10 secs */
result.start = time(NULL)+10;
}

/* set the stop time for the recording */
result.stop = stop;
if(result.stop < time(NULL)){
/* this is gone already, so take the next 5 minutes */
result.stop = time(NULL)+300;
}

result.channel = g_string_new(channel);
result.status = 0;
result.seconds_recorded = 0;
result.filesize = 0;
@@ -539,7 +551,7 @@ static int iptvx_daemon_handle_request(void * cls, struct MHD_Connection * conne
*/
void iptvx_daemon_check_recording(){
/* get the current timestamp */
long now = time(NULL);
long now = (long)time(NULL);

/* go through the list of scheduled recordings */
int c = 0;
@@ -548,9 +560,17 @@ void iptvx_daemon_check_recording(){

/* check if recording not active
and schedule for now */
if(rec->start >= (now-(rec->tolerance))
&& rec->stop <= (now+(rec->tolerance))
&& rec->status == 0){
long actual_start = (rec->start-(rec->tolerance));
long actual_stop = (rec->stop+(rec->tolerance));

if(actual_start <= now && actual_stop >= now && rec->status == 0){
/* it might be that the daemon was just fired up
and EPG data is not yet, ready and we need to
wait for it to come up */
while(iptvx_daemon_epg_data == NULL){
sleep(1);
}

/* add the url of the channel to the recording */
rec->url = iptvx_daemon_get_url(rec->channel);

@@ -655,8 +675,10 @@ void iptvx_daemon_run(){
/* start recording if necessary */
iptvx_daemon_check_recording();

printf("Daemon alive! (%d)\n",(long)time(NULL));

/* wait */
sleep(10);
sleep(5);
}

/* stop the daemon when finished */
@@ -328,7 +328,8 @@ GArray* iptvx_db_get_recording_list(){

char* get_recording_sql = "SELECT c.channelname, r.recordstart, "
"r.recordstop, r.recordtitle FROM record r, channel c "
"WHERE c.channelid = r.recordchannelid";
"WHERE c.channelid = r.recordchannelid "
"ORDER BY r.recordstop DESC";

sqlite3_stmt *getrec_stmt;
sqlite3_prepare_v2(db,get_recording_sql, -1, &getrec_stmt, NULL);
@@ -59,7 +59,7 @@ int iptvx_record_start_thread(void* recordingptr){
char* vlc_args[] = {
"--no-xlib", /* don't use the graphics lib */
"--repeat", /* ensure it retries on failure */
"--quiet", /* no verbose output */
"--quiet", /* '--quiet' no verbose output */
rec_param /* the actual file dumping */
};

0 comments on commit fdb5cdf

Please sign in to comment.
You can’t perform that action at this time.