www.makemkv.com

MakeMKV support forum
It is currently Mon Jul 16, 2018 10:22 pm

All times are UTC




Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: libmmbd with kodi18
PostPosted: Tue Mar 27, 2018 10:52 am 
Offline

Joined: Sat Mar 24, 2018 8:45 am
Posts: 5
I applied your changes. However, I am getting the below error after make
Code:
libmmbd/src/aacs.cpp: In function 'void aacs_set_fopen(AACS*, void*, void*)':
libmmbd/src/aacs.cpp:300:60: error: 'bd_disc_structure_pointer' was not declared in this scope
    BD_DISC bd_disc_structure = *reinterpret_cast<BD_DISC*>(bd_disc_structure_pointer); // Copy the BD_DISC structure
                                                            ^
Makefile:84: recipe for target 'out/libmmbd.so.0.full' failed
make: *** [out/libmmbd.so.0.full] Error 1

I double checked all changes were in the correct places. Anything else missing?


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Tue Mar 27, 2018 3:25 pm 
Offline

Joined: Thu Dec 30, 2010 7:51 pm
Posts: 15
My bad. Sorry about that.

The first line of the definition of aacs_set_fopen() should be:
Code:
AACS_PUBLIC void __cdecl aacs_set_fopen(AACS *aacs, void *bd_disc_structure_pointer, void* p)


I've edited my instructions to correct this omission.

dgktkr


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Tue Mar 27, 2018 5:37 pm 
Offline

Joined: Sat Mar 24, 2018 8:45 am
Posts: 5
Thanks for your quick feedback. I've adjusted the changes accordingly. With this I can now successfully build MakeMKV.

Will test how it works with kodi over the next days.

I assembled all changes into the below patch file, which you can apply with
Code:
patch -p1 < patch_file

in the makemkv-oss-1.12.0 folder.
Here's the content of the patch_file:
Code:
--- a/libmmbd/src/aacs.cpp
+++ b/libmmbd/src/aacs.cpp
@@ -23,6 +23,109 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <string>
+
+typedef struct bd_mutex_s BD_MUTEX;
+struct bd_mutex_s {
+    void *impl;
+};
+
+
+typedef void    (*fptr_void)(...);
+typedef int     (*fptr_int)(...);
+typedef int32_t (*fptr_int32)(...);
+typedef void*   (*fptr_p_void)(...);
+
+typedef struct bd_aacs BD_AACS;
+
+struct bd_aacs {
+    void           *h_libaacs;   /* library handle from dlopen */
+    void           *aacs;        /* aacs handle from aacs_open() */
+
+    const uint8_t *disc_id;
+    uint32_t       mkbv;
+
+    /* function pointers */
+    fptr_int       decrypt_unit;
+    fptr_int       decrypt_bus;
+
+    int            impl_id;
+};
+
+typedef struct bd_bdplus BD_BDPLUS;
+
+struct bd_bdplus {
+    void           *h_libbdplus; /* library handle from dlopen */
+
+    void           *bdplus;      /* bdplus handle from bdplus_open() */
+
+    /* functions */
+    fptr_int32     event;
+    fptr_p_void    m2ts;
+    fptr_int32     m2ts_close;
+    fptr_int32     seek;
+    fptr_int32     fixup;
+
+    /* old API */
+    fptr_p_void    title;
+
+    int impl_id;
+};
+
+typedef struct bd_dec BD_DEC;
+struct bd_dec {
+    int        use_menus;
+    BD_AACS   *aacs;
+    BD_BDPLUS *bdplus;
+};
+
+
+typedef struct bd_file_s BD_FILE_H;
+struct bd_file_s
+{
+    void* internal;
+    void    (*close) (BD_FILE_H *file);
+    int64_t (*seek)  (BD_FILE_H *file, int64_t offset, int32_t origin);
+    int64_t (*tell)  (BD_FILE_H *file);
+    int     (*eof)   (BD_FILE_H *file);
+    int64_t (*read)  (BD_FILE_H *file, uint8_t *buf, int64_t size);
+    int64_t (*write) (BD_FILE_H *file, const uint8_t *buf, int64_t size);
+};
+
+typedef struct
+{
+    char    d_name[256];
+} BD_DIRENT;
+
+typedef struct bd_dir_s BD_DIR_H;
+struct bd_dir_s
+{
+    void* internal;
+    void (*close)(BD_DIR_H *dir);
+    int (*read)(BD_DIR_H *dir, BD_DIRENT *entry);
+};
+
+typedef struct bd_disc BD_DISC;
+
+struct bd_disc {
+    BD_MUTEX  ovl_mutex;     /* protect access to overlay root */
+    BD_MUTEX  properties_mutex; /* protect access to properties file */
+
+    char     *disc_root;     /* disc filesystem root (if disc is mounted) */
+    char     *overlay_root;  /* overlay filesystem root (if set) */
+
+    BD_DEC   *dec;
+
+    void         *fs_handle;
+    BD_FILE_H * (*pf_file_open_bdrom)(void *, const char *);
+    BD_DIR_H *  (*pf_dir_open_bdrom)(void *, const char *);
+    void        (*pf_fs_close)(void *);
+
+    const char   *udf_volid;
+    char         *properties_file;  /* NULL if not yet used */
+
+    int8_t        avchd;  /* -1 - unknown. 0 - no. 1 - yes */
+};

 /*
     WARNING!
@@ -97,6 +200,8 @@
     return (AACS*)mmbd;
 }

+static std::string *cxx_string_pointer;  // declare a persistent file scope variable
+
 AACS_PUBLIC int __cdecl aacs_open_device(AACS *aacs, const char *path, const char *keyfile_path)
 {
     if (keyfile_path) {
@@ -110,7 +215,8 @@
         }
     }

-    if (mmbd_open((MMBD*)aacs,path)) {
+    const char * c_string_path = (*cxx_string_pointer).c_str(); // convert to the C string we're after
+    if (mmbd_open((MMBD*)aacs,c_string_path)) {  // change path to c_string_path
         return AACS_ERROR_CORRUPTED_DISC;
     }

@@ -189,8 +295,11 @@
     return (const uint8_t *)"mmbd_fake_aacs_get_bdj_root_cert_hash";
 }

-AACS_PUBLIC void __cdecl aacs_set_fopen(AACS *aacs, void *handle, void* p)
+AACS_PUBLIC void __cdecl aacs_set_fopen(AACS *aacs, void *bd_disc_structure_pointer, void* p)
 {
+   BD_DISC bd_disc_structure = *reinterpret_cast<BD_DISC*>(bd_disc_structure_pointer); // Copy the BD_DISC structure
+
+   cxx_string_pointer = reinterpret_cast<std::string*>(bd_disc_structure.fs_handle); // Copy the C++ string object pointer of interest
 }

 static void* file_open = NULL;
--- a/libmmbd/src/aacs.h
+++ b/libmmbd/src/aacs.h
@@ -197,7 +197,7 @@

 AACS_PUBLIC struct aacs_basic_cci * __cdecl aacs_get_basic_cci(AACS *, uint32_t title);

-AACS_PUBLIC void __cdecl aacs_set_fopen(AACS *aacs, void *handle, void* p);
+AACS_PUBLIC void __cdecl aacs_set_fopen(AACS *aacs, void *bd_disc_structure_pointer, void* p);
 AACS_PUBLIC void* __cdecl aacs_register_file(void* p);

 #ifdef __cplusplus
--- q/libmmbd/src/bdplus.cpp
+++ b/libmmbd/src/bdplus.cpp
@@ -44,6 +44,12 @@
     uint64_t    offset;
 } BDPLUS_CTX;

+// provide a minimal bdplus_set_fopen()
+AACS_PUBLIC BDPLUS_CTX* __cdecl bdplus_set_fopen(BDPLUS_CTX* ctx, void *bd_disc_structure_pointer, void* p)
+{
+    return ctx;
+}
+
 /*
     This function requires aacs_vid value produced by aacs_get_vid, not an actual disc VID.
 */
--- a/libmmbd/src/bdplus.h
+++ b/libmmbd/src/bdplus.h
@@ -29,6 +29,7 @@
 extern "C" {
 #endif

+AACS_PUBLIC BDPLUS_CTX* __cdecl bdplus_set_fopen(BDPLUS_CTX* ctx, void *bd_disc_structure_pointer, void* p);
 AACS_PUBLIC BDPLUS_CTX* __cdecl bdplus_init(const char *path, const char *keyfile_path,const uint8_t* aacs_vid);
 AACS_PUBLIC int __cdecl bdplus_free(BDPLUS_CTX* ctx);

--- a/libmmbd/src/libmmbd.vers
+++ b/libmmbd/src/libmmbd.vers
@@ -33,6 +33,7 @@
   aacs_get_device_nonce;
   aacs_get_bus_encryption;
   aacs_register_file;
+  bdplus_set_fopen;
   bdplus_init;
   bdplus_free;
   bdplus_set_title;


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Thu Mar 29, 2018 1:02 pm 
Offline

Joined: Sat Mar 24, 2018 8:45 am
Posts: 5
Only partial success so far. With the changes applied I can play some BDs while attempting to play back another initially crashed kodi. After a few tries and playing with the settings inside kodi I can now play back all BDs from kodi - with all settings back to where they initially were, which is kind of strange.

The worst is, that after each BD playback, one or more instances of makemkvcon remain as defunct in my process list.
Since I'm monitoring my system for background processes this keeps my pc from going to sleep.

I can probably tune my monitoing to ignore defunct processes but it's still kinda ugly to have these zombie makemkvcon processes piling up.

Anyone have a cure for this?


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Wed Apr 04, 2018 9:01 am 
Offline

Joined: Sun Jan 15, 2017 4:14 pm
Posts: 2
@G0llum: i've applied your patch based on the great work of @dgktkr and, after some days of intensive use, i never seen any kind of problem.

I can play a bd, stop it, change with a bd+ and play it without any issue.

After a heavy sequence of play bd, stop it, change disk, play it... I didn't noticed any defunct makemkvcon process nor kodi crashes.

I tested this on my self compiled LibreELEC cloned from git (the last today), with kodi versions 18.0-ALPHA2 Git:9af16f4 and 18.0-ALPHA2 Git:72f69fc on a x86_64 platform (athlon X2 245e), with a Nvidia 730GT using either top and ps commands.

I use my own kodi settings (VDPAU) and never need to tune them after the patch

If you have more tips on how to reproduce your problem i'll be happy to test and compare results.


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Sat Apr 07, 2018 8:55 am 
Offline

Joined: Mon Dec 04, 2017 11:26 am
Posts: 8
Hi have just installed kodi 18 via nightly-build ppa and compiled build makemkv from scratch
as followed:

Code:
wget http://www.makemkv.com/download/makemkv-bin-1.12.0.tar.gz
wget http://www.makemkv.com/download/makemkv-oss-1.12.0.tar.gz

sudo apt-get install build-essential pkg-config libc6-dev libssl-dev libexpat1-dev libavcodec-dev libgl1-mesa-dev libqt4-dev zlib1g-dev

tar -xzf makemkv-oss-1.12.0.tar.gz
cd ./makemkv-oss-1.12.0
sudo nano ./patch_file
---
paste Content from here:
http://makemkv.com/forum2/viewtopic.php?f=3&t=16824&sid=c50aa1bc707de1a23e41303bd756c447&start=15#p61629
---
patch -p1 < patch_file
./configure
make
sudo make install

cd ..
tar -xzf makemkv-bin-1.12.0.tar.gz
cd ./makemkv-bin-1.12.0
make
sudo make install


But if i click on the index.bdmv or movieobject.bdmv in kodi18, kodi 18 still crashes (restarts).
Did i anything wrong? How can I debug this?


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Sat Apr 07, 2018 3:46 pm 
Offline

Joined: Sat Dec 23, 2017 3:43 am
Posts: 5
I have tested the patch and can confirm that this gets blurays working in kodi 18, but I see two issues. Defunct instances of makemkvcon hang around. Also, the patch breaks bluray playback with mpv, and probably with other applications that use the older libbluray api, ie not bd_open_files(). Still though, I think this is a proof of concept that we can fix this within makemkv.

EDIT: I have attached a modified patch file. I moved the new declarations in aacs.cpp over to aacs.h. The main change, I edited aacs_open_device() so that if *path is NULL, we use the new *cxx_string_pointer; otherwise we don't touch the *path that is provided to mmbd_open. This works with Kodi and works with mpv. I still get the zombie makemkvcon, but it's only when loading bluray from kodi, using *cxx_string_pointer. Bluray with mpv does not leave a zombie process.

EDIT 2: I don't think this patch is the source of the zombie makemkvcon. I previously had hardcoded a path for mmbd_open(), and that method with kodi results in zombie processes too. Not sure how to debug, or if it can even be fixed within libmmbd.

EDIT 3: Should not have moved the static variable declaration to aacs.h... fixed.


Attachments:
kodi_mmbd-v3_patch.txt [6.14 KiB]
Downloaded 202 times


Last edited by mosquitogang201 on Sat Apr 14, 2018 9:56 pm, edited 1 time in total.
Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Wed Apr 11, 2018 7:38 pm 
Offline

Joined: Wed Apr 04, 2018 10:55 am
Posts: 5
@TheUlpio

How do you build makemkv as an add-on to work in libreelec?

I compiled makemkv on ubuntu with the new patch in this thread. Then I copied the binary and the libmmbd in my existing add-on directory on libreelec. But its not working. I got the message playback is not possible because of AACS. What I´m doing wrong?

Edit: Its working now. I build the complete add-on with a new compiled makemkv-oss source.
It´s working with the latest Libreelec nightly.


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Thu Apr 12, 2018 7:23 pm 
Offline

Joined: Sun Jan 15, 2017 4:14 pm
Posts: 2
christian wrote:
@TheUlpio

How do you build makemkv as an add-on to work in libreelec?

I compiled makemkv on ubuntu with the new patch in this thread. Then I copied the binary and the libmmbd in my existing add-on directory on libreelec. But its not working. I got the message playback is not possible because of AACS. What I´m doing wrong?

Edit: Its working now. I build the complete add-on with a new compiled makemkv-oss source.
It´s working with the latest Libreelec nightly.

I don't build makemkv as an addon, i build it in-tree using my own package.mk. Building the addon in an host distro involves to set-up a cross compile environment imho. Finally i'm glad to ear that your addon is working :)

To return in topic, can you check if the disk playback on your system originates zombie makemkvcon processes?


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Sat Apr 14, 2018 7:09 am 
Offline

Joined: Wed Apr 04, 2018 10:55 am
Posts: 5
I can confirm that libreelec 9 generates 2 processes of makemkvcon.bin per movie. The first process is by reading the titles of the bluray and the second by starting the main movie. When I watch a second movie it also generates two of them. So after two movies I have four processes.

But I don't know how it was on kodi 17.6. Maybe the same. Maybe someone can test it on kodi 17.6 or on linux with VLC Player by changing the vlc library with the makemkv library.

Edit:
For Bluray Menus. I can confirm that they are also working with libmmbd. I have installed java and Libbluray-j2se-1.0.1 as an add-on in libreelec 9.0. For instructions search in the libreelec forum. Its only working on generic systems.


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Sun Apr 29, 2018 1:30 pm 
Offline

Joined: Wed Apr 04, 2018 10:55 am
Posts: 5
After updating to Milhouse Build #0425 the makemkv does not work anymore. With version #0424 everything is fine.
Anyone with the same problem?


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Mon Apr 30, 2018 4:34 pm 
Offline

Joined: Sat Mar 24, 2018 8:45 am
Posts: 5
I am not using libreelec but I was able to compile latest MakeMKV on Ubuntu 16.04 on top of kodi 18 built from sources on April 29. It works with DVDs but BD playback is broken as with the previous unpatched release.

I haven't looked yet at the MakeMKV sources, but I was hoping it would contain some fix to address the broken BD playback with kodi. Not sure if the patch can be applied unchanged also to the latest code.


Top
 Profile  
Reply with quote  
 Post subject: Re: libmmbd with kodi18
PostPosted: Fri May 04, 2018 2:49 pm 
Offline

Joined: Wed Apr 04, 2018 10:55 am
Posts: 5
The patch is also working with version 1.12.2


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group