• 1
  • 2
  • 3
  • 4(current)
  • 5
  • 6
  • 16
PVR Simple SQL Client w/ Recording
#46
(2018-05-31, 19:28)el_gonz87 Wrote:
(2018-05-31, 16:15)Mr Groch Wrote: I have changed this line:
https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L272

To:
cpp:
strParams = strParams + " --"+lineVect[0]+"="+lineVect[1];

And recrding of rtmp streams is now working. So I can confirm that problem is with too many " chars

Now I have problem with duration of those recordings, ffprobe says that duration is 00:00:00. I have tried adding --use_wallclock_as_timestamps 1 -fflags +genpts to output parameters but with no luck...
I think this is an FFMPEG issue. It may be due to the -v copy parameters, maybe it does not create timestamps appropriately. The fact FFPROBE detects a duration of 0 makes me think the FLV file doesn't have the appropriate data to get a duration. Have you tried actually remuxing? using a video codec and audio codec?

I must admit I was not able to test rtmp streams as I have none.  
 Hi, i've found cause of the issue. Is not FFMPEG problem - problem is in:
https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L399

ffmpeg in exec_stream_t can't properly exit when executing e_Stream.close(); so it is killed after. The solution is to clean exit ffmpeg - then duration and any other metadata is fine.

My working and tested proposition is in this diff of PVRRecorderThread.cpp file:

diff:
@@ -352,6 +352,7 @@ void *PVRRecorderThread:Tonguerocess(void)
   e_Stream.set_binary_mode(exec_stream_t:Confused_out);
   e_Stream.set_wait_timeout(exec_stream_t:Confused_in, g_iStrmTimeout*1000);
   e_Stream.set_wait_timeout(exec_stream_t:Confused_out, g_iStrmTimeout*1000);
+  e_Stream.set_wait_timeout(exec_stream_t:Confused_child, g_iStrmTimeout*1000);
   e_Stream.start(g_strFFMPEG, strParams);
 
   XBMC->Log(LOG_NOTICE, "Set stream timeout: %d", g_iStrmTimeout);
@@ -395,9 +396,15 @@ void *PVRRecorderThread:Tonguerocess(void)
     if (nowTimer.Timer.endTime<time(NULL) || nowTimer.Status == PVR_STREAM_IS_STOPPING || nowTimer.Status == PVR_STREAM_STOPPED || nowTimer.bIsDeleted == true)
     {
       // recording stopped
-      e_Stream.close();
-      e_Stream.kill();
-              
+      // send "q" to ffmpeg for clean exit
+      e_Stream.in() << "q";
+      e_Stream.close_in();
+      if (!e_Stream.close())
+      {
+        e_Stream.kill();
+        XBMC->Log(LOG_NOTICE, "Record command failed to close, killing");
+      }
+
       XBMC->Log(LOG_NOTICE, "Recording stopped %s", nowTimer.Timer.strTitle);
                  
       // correct duration time & add to cache
@@ -459,9 +466,15 @@ void *PVRRecorderThread:Tonguerocess(void)
     else if (now-lastRead>=g_iStrmTimeout)
     {
       // something wrong - data not growing
-      e_Stream.close();
-      e_Stream.kill();
-         
+      // send "q" to ffmpeg for clean exit
+      e_Stream.in() << "q";
+      e_Stream.close_in();
+      if (!e_Stream.close())
+      {
+        e_Stream.kill();
+        XBMC->Log(LOG_NOTICE, "Record command failed to close, killing");
+      }
+
       XBMC->Log(LOG_NOTICE, "Recording failed %s", nowTimer.Timer.strTitle);
                    
       // correct duration time & add to cache
Reply
#47
(2018-06-02, 16:36)Mr Groch Wrote:
(2018-05-31, 19:28)el_gonz87 Wrote:
(2018-05-31, 16:15)Mr Groch Wrote: I have changed this line:
https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L272

To:
cpp:
strParams = strParams + " --"+lineVect[0]+"="+lineVect[1];

And recrding of rtmp streams is now working. So I can confirm that problem is with too many " chars

Now I have problem with duration of those recordings, ffprobe says that duration is 00:00:00. I have tried adding --use_wallclock_as_timestamps 1 -fflags +genpts to output parameters but with no luck...
I think this is an FFMPEG issue. It may be due to the -v copy parameters, maybe it does not create timestamps appropriately. The fact FFPROBE detects a duration of 0 makes me think the FLV file doesn't have the appropriate data to get a duration. Have you tried actually remuxing? using a video codec and audio codec?

I must admit I was not able to test rtmp streams as I have none.   
 Hi, i've found cause of the issue. Is not FFMPEG problem - problem is in:
https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L399

ffmpeg in exec_stream_t can't properly exit when executing e_Stream.close(); so it is killed after. The solution is to clean exit ffmpeg - then duration and any other metadata is fine.

My working and tested proposition is in this diff of PVRRecorderThread.cpp file:

diff:
@@ -352,6 +352,7 @@ void *PVRRecorderThread:Tonguerocess(void)
   e_Stream.set_binary_mode(exec_stream_t:Confused_out);
   e_Stream.set_wait_timeout(exec_stream_t:Confused_in, g_iStrmTimeout*1000);
   e_Stream.set_wait_timeout(exec_stream_t:Confused_out, g_iStrmTimeout*1000);
+  e_Stream.set_wait_timeout(exec_stream_t:Confused_child, g_iStrmTimeout*1000);
   e_Stream.start(g_strFFMPEG, strParams);
 
   XBMC->Log(LOG_NOTICE, "Set stream timeout: %d", g_iStrmTimeout);
@@ -395,9 +396,15 @@ void *PVRRecorderThread:Tonguerocess(void)
     if (nowTimer.Timer.endTime<time(NULL) || nowTimer.Status == PVR_STREAM_IS_STOPPING || nowTimer.Status == PVR_STREAM_STOPPED || nowTimer.bIsDeleted == true)
     {
       // recording stopped
-      e_Stream.close();
-      e_Stream.kill();
-              
+      // send "q" to ffmpeg for clean exit
+      e_Stream.in() << "q";
+      e_Stream.close_in();
+      if (!e_Stream.close())
+      {
+        e_Stream.kill();
+        XBMC->Log(LOG_NOTICE, "Record command failed to close, killing");
+      }
+
       XBMC->Log(LOG_NOTICE, "Recording stopped %s", nowTimer.Timer.strTitle);
                  
       // correct duration time & add to cache
@@ -459,9 +466,15 @@ void *PVRRecorderThread:Tonguerocess(void)
     else if (now-lastRead>=g_iStrmTimeout)
     {
       // something wrong - data not growing
-      e_Stream.close();
-      e_Stream.kill();
-         
+      // send "q" to ffmpeg for clean exit
+      e_Stream.in() << "q";
+      e_Stream.close_in();
+      if (!e_Stream.close())
+      {
+        e_Stream.kill();
+        XBMC->Log(LOG_NOTICE, "Record command failed to close, killing");
+      }
+
       XBMC->Log(LOG_NOTICE, "Recording failed %s", nowTimer.Timer.strTitle);
                    
       // correct duration time & add to cache
 
That's excellent and good catch! Will commit this to master branch, thanks for supporting the addon development.
Reply
#48
I've found another issue - there is huge glitch when any text from EPG have new line chars (\n) - timers and recordings handling crashes then...
There should be eresing new line chars or escaping/taging them like you do with | char
Reply
#49
deleted
Reply
#50
(2018-06-05, 17:03)Mr Groch Wrote: I've found another issue - there is huge glitch when any text from EPG have new line chars (\n) - timers and recordings handling crashes then...
There should be eresing new line chars or escaping/taging them like you do with | char
 Hmmmmm.... I thought my EPG provider had line breaks, will look at translating them when reading/writing to cache file.
Reply
#51
Another bug, but I haven't yet found place in code responsible for that...

Kodi crashes when recording is stoped from timer end. When I end recording manually, there is no crash.

Here is compare of logs when recording stoped by timer (with crash):
https://paste.ubuntu.com/p/DMjvK64gY2/

Here when I stop recording manually (no crash):
https://paste.ubuntu.com/p/B8Rvhyx28h/
Reply
#52
I think, that I have found the issue. But can't test it right now.

After adding sleep, scheduler process loop isn't able to execute else if statament on line https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L185, but always first will be executed https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L146, and then pRecorder on line https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L162 is not ready for deleting, because is still busy.

Conclusion - https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L185 need to be executed first, I will try to refactor this localy later and test it
Reply
#53
(2018-06-13, 14:03)Mr Groch Wrote: I think, that I have found the issue. But can't test it right now.

After adding sleep, scheduler process loop isn't able to execute else if statament on line https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L185, but always first will be executed https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L146, and then pRecorder on line https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L162 is not ready for deleting, because is still busy.

Conclusion - https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L185 need to be executed first, I will try to refactor this localy later and test it
 Hi there. Thanks again for your committed testing. I have implemented fixes to this issue and the previous (line breaks in EPG). Please download latest commits from master branch.

For some reason Ubuntu 16.04 did not crash when timer ended recording, so I have no way of knowing if this actually fixed it but I think you are right the IFs should be reordered. I put the stop recording IF as the first to execute. Let me know if this does not fix the problem for you.
Reply
#54
I have implemented other solution, I think that it is better, because sheduler now waits for recording thread to end. No race condition. Your solution only changes the order, so still recorder can be destroyed before recording ends.

diff:
@@ -143,7 +143,7 @@ void *PVRSchedulerThread:Tonguerocess(void)
       
             s_triggerTimerUpdate = true;
           }
-          else if (currTimer.Timer.endTime < time(NULL))
+          else if (currTimer.Timer.endTime < time(NULL) && (currTimer.Timer.state == PVR_TIMER_STATE_COMPLETED))
           {
             if (currTimer.Timer.iTimerType != PVR_TIMER_TYPE_NONE) 
             {

Also I have fund that your commit adcab0fbecc208912f83135952b7d967f2a11fde need also following timeot to be set:

diff:
@@ -352,6 +352,7 @@ void *PVRRecorderThread:Tonguerocess(void)
   e_Stream.set_binary_mode(exec_stream_t:Confused_out);
   e_Stream.set_wait_timeout(exec_stream_t:Confused_in, g_iStrmTimeout*1000);
   e_Stream.set_wait_timeout(exec_stream_t:Confused_out, g_iStrmTimeout*1000);
+  e_Stream.set_wait_timeout(exec_stream_t:Confused_child, g_iStrmTimeout*1000);
   e_Stream.start(g_strFFMPEG, strParams);
 
   XBMC->Log(LOG_NOTICE, "Set stream timeout: %d", g_iStrmTimeout);

Default child timeout is 1 s and not always quiting ffmpeg with 'q' will end in 1 s, so it is killed...
Reply
#55
(2018-06-13, 20:56)Mr Groch Wrote: I have implemented other solution, I think that it is better, because sheduler now waits for recording thread to end. No race condition. Your solution only changes the order, so still recorder can be destroyed before recording ends.

diff:
@@ -143,7 +143,7 @@ void *PVRSchedulerThread:Tonguerocess(void)
       
             s_triggerTimerUpdate = true;
           }
-          else if (currTimer.Timer.endTime < time(NULL))
+          else if (currTimer.Timer.endTime < time(NULL) && (currTimer.Timer.state == PVR_TIMER_STATE_COMPLETED))
           {
             if (currTimer.Timer.iTimerType != PVR_TIMER_TYPE_NONE) 
             {

Also I have fund that your commit adcab0fbecc208912f83135952b7d967f2a11fde need also following timeot to be set:

diff:
@@ -352,6 +352,7 @@ void *PVRRecorderThread:Tonguerocess(void)
   e_Stream.set_binary_mode(exec_stream_t:Confused_out);
   e_Stream.set_wait_timeout(exec_stream_t:Confused_in, g_iStrmTimeout*1000);
   e_Stream.set_wait_timeout(exec_stream_t:Confused_out, g_iStrmTimeout*1000);
+  e_Stream.set_wait_timeout(exec_stream_t:Confused_child, g_iStrmTimeout*1000);
   e_Stream.start(g_strFFMPEG, strParams);
 
   XBMC->Log(LOG_NOTICE, "Set stream timeout: %d", g_iStrmTimeout);

Default child timeout is 1 s and not always quiting ffmpeg with 'q' will end in 1 s, so it is killed...
 I see your point on first one, although very unlikely it would not execute first IF (perfect timing), I added a safe guard, however the added code should be this:
&& !(currTimer.Timer.state == PVR_TIMER_STATE_RECORDING)

Recordings can exit due to completion or error (stream times out due to buffering, etc..). The above code basically checks for no active recording.

As for 2nd, again this was not issue on Ubuntu for me, but I added the lines, check out latest commit and let me know.
Reply
#56
Thanks, I have tested your latest commit and both - recording from manual start/stop and recording from timer works great!

I have found another issue :/ Timers don't work well after Kodi restart. Timers will be loaded at start (I can see notification and in log), but timer tasks aren't added to Kodi recording taks. Next when it is time for recording start - I can see in log lots of "Try to start recording ..." till timer end. Recording is not started. I think that addon can't get channel for recording at https://github.com/gonzalo-hvega/pvr.ipt...d.cpp#L283

When I add after Kodi restart another timer for this channel, I see that channeluid in timer cache file is different...

I think that you should delete timers on addon load when channeluid is not known

I don't have idea how to fix this right now, maybe mark channel ny name or channel number (or both, because my prvider sometimes double the same channel name - alternative source) in timers?
Reply
#57
Here is a simple fix for dummy timers after Kodi restart, when channel can not be found on m3u list any more:

PVRDvrData.cpp:

diff:
@@ -142,7 +142,11 @@ bool PVRDvrData::LoadTimers(void)
         {
           if (jobEntry.Timer.startTime > time(NULL) || jobEntry.Timer.iTimerType != PVR_TIMER_TYPE_NONE || jobEntry.Timer.endTime > time(NULL))
           {
-            m_timers[jobEntry.Timer.iClientIndex] = jobEntry; 
+            PVRIptvChannel currChannel;
+            if (GetChannel(jobEntry.Timer, currChannel))
+            {
+              m_timers[jobEntry.Timer.iClientIndex] = jobEntry;
+            }
           }
         }
       }


I have also found a bug, when file exceeds size of 4 294 967 295 bytes. It was lucky catch after I was wondering why some of my long recording tasks were just deleted at the end of recording....

PVRRecorderThread.cpp

diff:
@@ -360,7 +361,7 @@ void *PVRRecorderThread:Tonguerocess(void)
   std:Confusedtring readBuffer;
   streamsize bytesRead;
   time_t lastRead = time(NULL);
-  int lastSize = 0;
+  int64_t lastSize = 0;
 
   while(true)
   {
Reply
#58
Is this plugin stable enough for everyday use?  Is it possible to add a NAS as a storage to record to and play from?
Reply
#59
Hi there,

I'm trying to get this addon working on my RPi3 with libreelec and want to share my experiences and problems with you.
Using ffmpeg with libx264 doesn't really offers a good performance for encoding  (around 6-8fps), so I decided to compile h264_omx library alongside with LibreELEC. This enables hardware accelerated encoding for the RPi3 and now I'm reaching 30fps+ easily. That's awesome!

Starting the recording with the addon is no problem but the downside is that I'm always getting an annoying overlay at the left upper corner in kodi from the stream I'm recording in that moment. It looks like this:
Image
Does anyone know how to remove that?

When I stop the recording, Kodi crashes with a segmentation fault. I tried to encapsulate the issue and I'm pretty sure it comes from this line: PVRRecorderThread.cpp#L448.

My Kodi crash log: Crashlog

Any ideas why this happens and how to fix it?
Reply
#60
@MhhhxX

The forum moderators have determined that Banned_addons (wiki) are present on your system. To receive assistance here, these banned items must be removed. If a clean log is not submitted within 3 days, then the relevant post(s) will be removed after this time.
My Signature
Links to : Official:Forum rules (wiki) | Official:Forum rules/Banned add-ons (wiki) | Debug Log (wiki)
Links to : HOW-TO:Create Music Library (wiki) | HOW-TO:Create_Video_Library (wiki)  ||  Artwork (wiki) | Basic controls (wiki) | Import-export library (wiki) | Movie sets (wiki) | Movie universe (wiki) | NFO files (wiki) | Quick start guide (wiki)
Reply
  • 1
  • 2
  • 3
  • 4(current)
  • 5
  • 6
  • 16

Logout Mark Read Team Forum Stats Members Help
PVR Simple SQL Client w/ Recording11