3 #include <QCryptographicHash>
19 #include <libbluray/bluray.h>
20 #include <libbluray/log_control.h>
21 #include <libbluray/meta_data.h>
23 #include "libbluray/bluray.h"
24 #include "util/log_control.h"
25 #include "libbluray/bdnav/meta_data.h"
28 #define LOC QString("BDInfo: ")
32 LOG(VB_PLAYBACK, LOG_INFO, QString(
"BDInfo: Trying %1").arg(Filename));
33 QString name = Filename;
35 if (name.startsWith(
"bd:"))
38 while (name.startsWith(
"//"))
43 name = QDir(QDir::cleanPath(name)).canonicalPath();
46 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"'%1' nonexistent").arg(name));
50 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Opened MythBDBuffer device at '%1'").arg(name));
53 bd_set_debug_handler([](
const char *Message) {
LOG(VB_PLAYBACK, LOG_DEBUG,
LOC + QString(Message).trimmed()); });
54 bd_set_debug_mask(DBG_CRIT | DBG_NAV | DBG_BLURAY);
60 BLURAY* bdnav =
nullptr;
69 bdhandle =
MythFileOpen(Filename.toLocal8Bit().data(), O_RDONLY);
75 bd_open_stream(bdnav, &bdhandle,
76 [](
void *Handle,
void *
Buf,
int LBA,
int NumBlocks) {
77 if (
MythFileSeek(*(
static_cast<int*
>(Handle)), LBA * 2048LL, SEEK_SET) != -1)
79 static_cast<size_t>(NumBlocks) * 2048) / 2048);
87 QByteArray keyfile = QString(
"%1/KEYDB.cfg").arg(
GetConfDir()).toLatin1();
88 bdnav = bd_open(name.toLocal8Bit().data(), keyfile.constData());
93 m_lastError = tr(
"Could not open Blu-ray device: %1").arg(name);
106 LOG(VB_PLAYBACK, LOG_INFO,
LOC +
"Done");
110 QString &SerialNum,
const QString &Filename,
111 const QString &LogPrefix)
113 const meta_dl *metaDiscLibrary = bd_get_meta(BluRay);
117 Name = QString(metaDiscLibrary->di_name);
123 Name = dir.dirName();
124 LOG(VB_PLAYBACK, LOG_DEBUG, LogPrefix + QString(
"Generated bd name '%1'")
132 for (uint32_t idx = 0; idx < 200; idx++)
134 QString clip = QString(
"BDMV/CLIPINF/%1.clpi").arg(idx, 5, 10, QChar(
'0'));
135 void* buffer =
nullptr;
136 int64_t buffersize = 0;
137 if (bd_read_file(BluRay, clip.toLocal8Bit().data(), &buffer, &buffersize) != 0)
139 QCryptographicHash crypto(QCryptographicHash::Sha1);
141 crypto.addData(
reinterpret_cast<const char*
>(&idx),
sizeof(idx));
143 crypto.addData(
reinterpret_cast<const char*
>(&buffersize),
sizeof(buffersize));
145 crypto.addData(
reinterpret_cast<const char*
>(buffer),
static_cast<int>(buffersize));
146 SerialNum = QString(
"%1__gen").arg(QString(crypto.result().toBase64()));
148 LOG(VB_PLAYBACK, LOG_DEBUG, LogPrefix + QString(
"Generated serial number '%1'")
154 if (SerialNum.isEmpty())
155 LOG(VB_GENERAL, LOG_ERR, LogPrefix +
"Unable to generate serial number");
167 return !(
Name.isEmpty() && SerialNum.isEmpty());