[PATCH] libhb update to allow multiple instances

Archive of historical development discussions
Discussions / Development has moved to GitHub
Forum rules
*******************************
Please be aware we are now using GitHub for issue tracking and feature requests.
- This section of the forum is now closed to new topics.

*******************************
Post Reply
RandomEngy
Novice
Posts: 50
Joined: Thu Mar 29, 2007 2:56 am

[PATCH] libhb update to allow multiple instances

Post by RandomEngy »

Been talking with j45 and we worked out this patch.

http://engy.us/misc/hblib_instance_changes.patch

This fix reworks how previews are stored to disk and how preview storage is cleaned up. We still store in <temp>/hb.<pid>/ but the previews are now named <instance id>_<title index>_<preview number> . We have an id on every handbrake instance that increments each time a new one is made. When an instance is cleaned up, we remove all previews for that instance. A new method is also added, hb_global_close(), which needs to be called on application exit. This is the only meaningful API change for the GUIs. If it's not called, it will leave empty directories in the temp folder. Right now the global close will only remove the hb.<pid> folder.

This gives us two advantages: Now you can close handbrake instances without deleting the entire preview directory. That means you can use an instance for scanning, then re-use it to encode rather than needing to re-scan. Second, it no longer uses the memory address of the title in the preview file name, which lets P-Invoking from C# work (since when marshaling back titles, they'll have new addresses).
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: [PATCH] libhb update to allow multiple instances

Post by JohnAStebbins »

In hb_close(), hb_remove_previews() should not be called till after the instance's thread has exited. I moved it to thread_func().
http://handbrake.fr/pastebin/pastebin.php?show=1275

Aside from that, works for me.
RandomEngy
Novice
Posts: 50
Joined: Thu Mar 29, 2007 2:56 am

Re: [PATCH] libhb update to allow multiple instances

Post by RandomEngy »

Isn't hb_remove_previews() called between scans on the same instance? Still, I guess there's nothing wrong with moving it down there.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: [PATCH] libhb update to allow multiple instances

Post by JohnAStebbins »

It is, and if hb_scan were to be called at an inappropriate time, like when scan were still in progress or anything else that could modify the title list, things would break badly. Keeping sanity in this case is left up to the caller of hb_scan. In the case of hb_close, it should make sure that all threads are finished working before calling hb_remove_previews. That being said, there's a bit of code that should have been added when I implemented scan cancelling a while back. thread_func should make sure the scan_thread is finished before exiting.
http://handbrake.fr/pastebin/pastebin.php?show=1276
RandomEngy
Novice
Posts: 50
Joined: Thu Mar 29, 2007 2:56 am

Re: [PATCH] libhb update to allow multiple instances

Post by RandomEngy »

Sounds good to me. Thanks for looking it over.
Post Reply