Kodi Community Forum
New MythTV add-on using libcmyth - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+---- Forum: PVR (https://forum.kodi.tv/forumdisplay.php?fid=136)
+---- Thread: New MythTV add-on using libcmyth (/showthread.php?tid=110694)



RE: New MythTV add-on using libcmyth - janbar - 2012-10-07

@Aubrien,

Good log. I am investigating...


RE: New MythTV add-on using libcmyth - fetzerch - 2012-10-07

(2012-10-07, 14:59)janbar Wrote: @Aubrien,

Good log. I am investigating...

@janbar: Did you have a closer look at the mythtv/mythfrontend sources and how they handle the chain updates and those 2 related events? The mythtv sources helped me a lot when implementing the multiplex detection. Both libcmyth and the myth protocol docs lack docs very often but mythtv's code itself is pretty readable.
I'm almost done with the fileops rework. If you and aubrian have a proper fix for the 'show stopping' and the 'delayed start', I can help integrating those changes into my repo.


RE: New MythTV add-on using libcmyth - janbar - 2012-10-07

(2012-10-07, 02:23)Aubrien Wrote: Janbar,
i couldn't get pastebin to take the log as it was loo large. Its quite alot of info for 5 mins of logging, but I know you need it to troubleshoot my issue. I used the email feature in the forum to send an email with the log and it says it sent successfully. Let me know if you get it or not. Thanks!

Here are some interesting things though...
Code:
19:54:45 T:2644073280   DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: switch file: current=0 , dir=0
19:55:01 T:2644073280   DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: switch file: current=0 , dir=1
19:55:03 T:2644073280   DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: switch file: current=1 , dir=0
19:55:03 T:2644073280   DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: switch file: current=1 , dir=0
20:00:06 T:2644073280   DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: switch file: current=1 , dir=1
20:00:07 T:2644073280   DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: switch file: current=2 , dir=1

Started at 19:54:45. 15s channel switch delay. 19:55:01 channel is changed. Next show is at 20:00:00.

This repeats for a while...
Code:
20:00:07 T:2644073280   ERROR: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: no more file
20:00:07 T:2644073280   ERROR: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: no more file
20:00:07 T:2644073280   ERROR: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: no more file

"wait until recorder is ready for watching" is never posted in the log so it is like the delay loop from below is never triggered. I changed i=20.

cmyth_livetv_chain_switch
Code:
for ( i = 0; i < 20; i++ ) {
                                pthread_mutex_unlock(&mutex);
                                usleep(500000);
                                pthread_mutex_lock(&mutex);
                                if ( rec->rec_livetv_chain->livetv_watch == 1 )
                                        break;
                        }

I think what is happening is it is setting the watch flag right away but there is a period of a few seconds where the hardware becomes ready and then begins to record while the file remains 0 size. Basically the backend says go and the hardware takes a few seconds. The same is true for the channel changes except it is more like 7s instead of 3s because it has to IR blast before the little blue light on the recorder comes on. If it were to wait until the file had a non 0 size AND the watch flag was ready then it may solve both the channel change delay and this issue in one swoop. You probably wouldn't need the watch flag at all really if you just checked the file size. I was playing around with the LiveTVDuration property and if it were 0 i wouldn't let it play or if it stopped increasing and then began increasing again then it was done with the program break. That might be a cheesy way of doing it though but it worked.

Hopefully you get my full log, but maybe the above will help too.

Ok, that is better with log. I understood what happened. The file switch for the program break is ok. Mythtv refill into the new buffer some data but quickly it has no more data to refill:

20:00:06 T:2644073280 DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: file switch to 2
20:00:06 T:2644073280 DEBUG: AddOnLog: PVR MythTV Client (cmyth): prog_update_callback
20:00:06 T:2644073280 DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_file_data_conn_fd {
20:00:06 T:2644073280 DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)__cmyth_rcv_string: string received '1'
20:00:06 T:2644073280 DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)__cmyth_rcv_string: string received '22140'
20:00:06 T:2644073280 DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)__cmyth_rcv_string: string received '32768'
20:00:07 T:2644073280 DEBUG: Previous line repeats 12 times.
20:00:07 T:2644073280 DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)__cmyth_rcv_string: string received '26764'
20:00:07 T:2644073280 DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)__cmyth_rcv_string: string received '0'
20:00:07 T:2644073280 DEBUG: Previous line repeats 1 times.

So by default if the buffer is empty, we try to switch to next file:

20:00:07 T:2644073280 DEBUG: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: switch file: current=2 , dir=1
20:00:07 T:2644073280 ERROR: AddOnLog: PVR MythTV Client (cmyth): LibCMyth: (cmyth)cmyth_livetv_chain_switch: no more file
20:00:07 T:2644073280 INFO: AddOnLog: PVR MythTV Client (cmyth): ReadLiveStream: Read 0 Bytes!

But there is no next file. This is the last. In your case we must wait refill of buffer. Also the timeout is activated only when livetv_watch != 1. That means only when we are waiting for the new program info (between message LIVETV_WATCH and DONE_RECORDING). Here we have new program info already.
I must to update to enable timeout all the time.






RE: New MythTV add-on using libcmyth - Aubrien - 2012-10-07

I was trying to do something simple like adjusting the delay condition to as so...

Code:
if ( rec->rec_livetv_chain->livetv_watch != 1 || rec->rec_livetv_file==NULL || rec->rec_livetv_file->file_length<15000 ) {
                        cmyth_dbg(CMYTH_DBG_ERROR,
                                  "%s: wait until recorder is ready for watching\n",
                                  __FUNCTION__);
                        for ( i = 0; i < 30; i++ ) {
                                pthread_mutex_unlock(&mutex);
                                usleep(500000);
                                pthread_mutex_lock(&mutex);
                                if ( rec->rec_livetv_chain->livetv_watch == 1  || rec->rec_livetv_file!=NULL || rec->rec_livetv_file->file_length>=15000)
                                        break;
                        }
                        if ( rec->rec_livetv_chain->livetv_watch != 1 || rec->rec_livetv_file==NULL || rec->rec_livetv_file->file_length<15000 ) {
                                return 0;
                        }

So it has to be safe to watch by the flag, the file has to exist, it it must be of a certain min size (15000). I left this on last night when I went o be and the kids messed with it before I got up so I don't know if it works yet but it does work for the first transition I saw before going to bed. Does this sound like it may be on the right track?

I was also thinking about the channel change delay. Is this the same issue because it tries to read from the file too soon? Maybe the fix for this buffer related issue could remove the need for a channel tune delay if done right. Just read from the file when it is ready and have a max timout or something.


RE: New MythTV add-on using libcmyth - janbar - 2012-10-07

@Aubrien,

I had a timeout on empty buffer to manage your case. It is not related to program break. Just player need to wait refilling buffer. commit is 4bb5093.
I hope it close your issue. Think player retry x150 reads before closing live stream. So waiting 0.5s x 150 ~ 1 minute. At the moment i fixed 0.5s per retry.
br.


RE: New MythTV add-on using libcmyth - allen00se - 2012-10-07

Well.. all off a sudden my mythbackend server has become unstable, I get about 10 minutes of live tv before it just stops playing. Fortunately I dont believe it is related to the addon. I get the same crap if I try and watch tv from the frontend that is running on my backend server. Long story short I decided to push ahead to 0.26. I made the changes sugested earlier in this thread and built the addon. At first glance it didnt want to connect but then like magic it worked. Channels and EPg came across, but when I try to watch tv i get the spinning circle and then nothing happens. I checked the backend log and for some reason xbmc is trying to tune with all 4 of my tuners at the same time. Its getting late so im giving up, is anyone interested in taking a look at my logs or are we staying away from .26 for now? I wish i could get mythtv to be stable for a while, its killing me to have my live TV so buggy.


RE: New MythTV add-on using libcmyth - Aubrien - 2012-10-07

Thanks Janbar,
When I start playback with the update it freezes a few seconds into playback forever now. Also, if I set the channel change delay to 0 and try to start playback it just shows a busy icon forever on the screen and freezes until I force quit. Something is causing a deadlock with the new code. I can send another log via email if needed but I will wait until you request it since I don't want to abuse your inbox.


RE: New MythTV add-on using libcmyth - janbar - 2012-10-07

(2012-10-07, 15:48)cfetzer Wrote:
(2012-10-07, 14:59)janbar Wrote: @Aubrien,

Good log. I am investigating...

@janbar: Did you have a closer look at the mythtv/mythfrontend sources and how they handle the chain updates and those 2 related events? The mythtv sources helped me a lot when implementing the multiplex detection. Both libcmyth and the myth protocol docs lack docs very often but mythtv's code itself is pretty readable.
I'm almost done with the fileops rework. If you and aubrian have a proper fix for the 'show stopping' and the 'delayed start', I can help integrating those changes into my repo.

@cfetzer
Yes had a look and to resolve it i added event LIVETV_WATCH to manage the program break. Now it is closed and i am preparing to merge with you. Aubrien has a special context needing a delay to refill buffer after each stage: spawn tv, switch channel and program break. At the moment libcmyth or xbmc player does not manage any delay before retry. So retries to read live stream loop without delay and after 150 retries in a short time the player close live stream. I try to find a global solution with him to manage this case without adding unnecessary waiting time. I think it is possible and it will be an improvement for the addon.
Soon i will pull request to you. This merge it is an hard work and i don't want to break anything. br

Also i will making more than one pull request to simplify the merge. My updated cmyth is fully compatible even without program break management.



RE: New MythTV add-on using libcmyth - Aubrien - 2012-10-07

janbar/cfetzer,
Just wanted to take a minute to say thank you both! I am always posting data and logs and such but I need to take a moment to thank the developer(s) on the other end. Without the work of you then we would still be sitting idle waiting on tsp42. The community came together and made it happen and I really like that about the xbmc community.

Now...I have some additional info on the freeze for the new buffer feature. Even though the playback is froze on the frontend, the blue light is on with the capture device so I know it is capturing. I saw in my log that I have a "Read 0 bytes!" entry (just once) so that is what must be causing the hang. I have found in my experiments that if I ever cause that then I cant recover and the stream is effectively dead. So it is slipping out of the guard clause and trying to read anyway when the buffer is empty.

I agree that this feature would make the addon much better once working. One interesting thing to note is I bet alof of you are using a ceton digital tuner card which has fast channel changes. While this is an option for cable, if you use Dish Network or DirectTV then you cant use a digital tuner like the ceton because they dont support cablecards and it is not a clear qam signal. basically, if you use satellite then you are using a set top box and there is a good chance that you are using the Happague HD-PVR card I have and an IR blaster. Additionally, if you wanted to bypass any DRM and just own the raw files then the analog loophole provided by the HD-PVR is an attractive option. I have full 1080i HD video and 5.1 audio over fiber being captured by the device with no DRM. Not only will this make the addon better once working, but it is really an essential part of making the addon work across all setups.


RE: New MythTV add-on using libcmyth - fetzerch - 2012-10-07

(2012-10-07, 20:02)janbar Wrote:
(2012-10-07, 15:48)cfetzer Wrote:
(2012-10-07, 14:59)janbar Wrote: @Aubrien,

Good log. I am investigating...

@janbar: Did you have a closer look at the mythtv/mythfrontend sources and how they handle the chain updates and those 2 related events? The mythtv sources helped me a lot when implementing the multiplex detection. Both libcmyth and the myth protocol docs lack docs very often but mythtv's code itself is pretty readable.
I'm almost done with the fileops rework. If you and aubrian have a proper fix for the 'show stopping' and the 'delayed start', I can help integrating those changes into my repo.

@cfetzer
Yes had a look and to resolve it i added event LIVETV_WATCH to manage the program break. Now it is closed and i am preparing to merge with you. Aubrien has a special context needing a delay to refill buffer after each stage: spawn tv, switch channel and program break. At the moment libcmyth or xbmc player does not manage any delay before retry. So retries to read live stream loop without delay and after 150 retries in a short time the player close live stream. I try to find a global solution with him to manage this case without adding unnecessary waiting time. I think it is possible and it will be an improvement for the addon.
Soon i will pull request to you. This merge it is an hard work and i don't want to break anything. br

Also i will making more than one pull request to simplify the merge. My updated cmyth is fully compatible even without program break management.

Great Smile I'm done now with the cleanups.
FileOps uses now XBMC's internal file system access methods and no more boost::filesystem and I also fixed the bug that images for new recordings were only present after a xbmc restart.
Also the translations are now done via Transifex ( https://www.transifex.com/projects/p/pvrmythtvcmyth ). Anyone is welcome to contribute translations!

@janbar: Yes, please add either different commits to a single PR or create multiple PRs. Please split / combine them by topics and please split all cmyth related commits (so they can be merged to libcmyth upstream at some time). Currently I have all cmyth related commits prefixed with [cmyth] and all plugin related commits with [mythtv-cmyth].
Then it would be great if you could either comment your changes quite verbose (either in the source files or in the PRs). That helps to understand all the details.
And just let me know if you need any help with the merge!


RE: New MythTV add-on using libcmyth - janbar - 2012-10-07

(2012-10-07, 20:23)cfetzer Wrote:
(2012-10-07, 20:02)janbar Wrote:
(2012-10-07, 15:48)cfetzer Wrote: @janbar: Did you have a closer look at the mythtv/mythfrontend sources and how they handle the chain updates and those 2 related events? The mythtv sources helped me a lot when implementing the multiplex detection. Both libcmyth and the myth protocol docs lack docs very often but mythtv's code itself is pretty readable.
I'm almost done with the fileops rework. If you and aubrian have a proper fix for the 'show stopping' and the 'delayed start', I can help integrating those changes into my repo.

@cfetzer
Yes had a look and to resolve it i added event LIVETV_WATCH to manage the program break. Now it is closed and i am preparing to merge with you. Aubrien has a special context needing a delay to refill buffer after each stage: spawn tv, switch channel and program break. At the moment libcmyth or xbmc player does not manage any delay before retry. So retries to read live stream loop without delay and after 150 retries in a short time the player close live stream. I try to find a global solution with him to manage this case without adding unnecessary waiting time. I think it is possible and it will be an improvement for the addon.
Soon i will pull request to you. This merge it is an hard work and i don't want to break anything. br

Also i will making more than one pull request to simplify the merge. My updated cmyth is fully compatible even without program break management.

Great Smile I'm done now with the cleanups.
FileOps uses now XBMC's internal file system access methods and no more boost::filesystem and I also fixed the bug that images for new recordings were only present after a xbmc restart.
Also the translations are now done via Transifex ( https://www.transifex.com/projects/p/pvrmythtvcmyth ). Anyone is welcome to contribute translations!

@janbar: Yes, please add either different commits to a single PR or create multiple PRs. Please split / combine them by topics and please split all cmyth related commits (so they can be merged to libcmyth upstream at some time). Currently I have all cmyth related commits prefixed with [cmyth] and all plugin related commits with [mythtv-cmyth].
Then it would be great if you could either comment your changes quite verbose (either in the source files or in the PRs). That helps to understand all the details.
And just let me know if you need any help with the merge!

GREAT work. I completed the merge and now program break runs perfectly.


RE: New MythTV add-on using libcmyth - janbar - 2012-10-07

@cfetzer

I resolved lot of issues. Not only program break. I merged in one pass with meld because there was too many dependancies.
The topics are:
[cmyth] IPv6 issue resolved
[cmyth] Enable atomic dec/inc for __X86_64__ to avoid disaster.
[addon] Create an UID for MythProgram based on MythTV primary key. Filename path could be null !
[addon] Check NULL proginfo before inserting into map: Proginfo_fill() fails (segment fault and unsigned long chanid < 0 !).
[cmyth] add materials to manage program break.
[addon] two new triggers in event handler to manage program break.

At the moment i merged with your master using xbmc api 1.3.0. I pushed to the branch janbar/new_master.



RE: New MythTV add-on using libcmyth - janbar - 2012-10-07

@cfetzer:
I just understand that now your cmyth is linked as static like my old_master. Great, It is better for the now.


RE: New MythTV add-on using libcmyth - Aubrien - 2012-10-08

OK just so I understand; are we are all merged up and are now rebased in cfetzer only for development? It will be nice to have everything in one spot as well as being able to use it against the xbmc nightlies. I understand why it has been the way it is with tsp missing and all so please don't think I'm complaining. I just have to keep hopping around between source trees right now so I can test this stuff and its a bit time consuming and confusing sometimes.


RE: New MythTV add-on using libcmyth - janbar - 2012-10-08

@Aubrien

I am merging with cfetzer. If you need to test my last dev (timeout for empty buffer) then use my branch: old_master. Thanks.

Also in my master you will find the addon pvr.mythtv.cmyth merged with cfetzer but with the api 1.3.0 (same as you have, not the nightly ). It is more stale.