update media logic to use different afc clients

This commit is contained in:
uncor3
2025-10-04 14:31:34 +00:00
parent 411ae160c2
commit 7f0b2d6136
11 changed files with 108 additions and 45 deletions
+14 -13
View File
@@ -14,12 +14,13 @@
QByteArray read_afc_file_to_byte_array(afc_client_t afcClient,
const char *path);
MediaStreamer::MediaStreamer(iDescriptorDevice *device, const QString &filePath,
QObject *parent)
: QTcpServer(parent), m_device(device), m_filePath(filePath),
m_cachedFileSize(-1), m_fileSizeCached(false)
MediaStreamer::MediaStreamer(iDescriptorDevice *device, afc_client_t afcClient,
const QString &filePath, QObject *parent)
: QTcpServer(parent), m_device(device), m_afcClient(afcClient),
m_filePath(filePath), m_cachedFileSize(-1), m_fileSizeCached(false)
{
// Listen on localhost with automatic port assignment
// todo: use qhostadress::localhost for jailbroken widget
if (!listen(QHostAddress::LocalHost, 0)) {
qWarning() << "MediaStreamer failed to start:" << errorString();
} else {
@@ -258,11 +259,12 @@ void MediaStreamer::streamFileRange(QTcpSocket *socket, qint64 startByte,
context->bytesRemaining = endByte - startByte + 1;
context->afcHandle = 0;
qDebug() << "m_filepath" << m_filePath;
// Open file on device
const QByteArray pathBytes = m_filePath.toUtf8();
afc_error_t openResult =
afc_file_open(m_device->afcClient, pathBytes.constData(),
AFC_FOPEN_RDONLY, &context->afcHandle);
afc_file_open(m_afcClient, pathBytes.constData(), AFC_FOPEN_RDONLY,
&context->afcHandle);
if (openResult != AFC_E_SUCCESS || context->afcHandle == 0) {
qWarning() << "Failed to open file on device:" << m_filePath;
@@ -273,11 +275,11 @@ void MediaStreamer::streamFileRange(QTcpSocket *socket, qint64 startByte,
// Seek to start position if needed
if (startByte > 0) {
afc_error_t seekResult = afc_file_seek(
m_device->afcClient, context->afcHandle, startByte, SEEK_SET);
afc_error_t seekResult =
afc_file_seek(m_afcClient, context->afcHandle, startByte, SEEK_SET);
if (seekResult != AFC_E_SUCCESS) {
qWarning() << "Failed to seek in file:" << m_filePath;
afc_file_close(m_device->afcClient, context->afcHandle);
afc_file_close(m_afcClient, context->afcHandle);
delete context;
socket->disconnectFromHost();
return;
@@ -334,7 +336,7 @@ qint64 MediaStreamer::getFileSize()
char **info = nullptr;
const QByteArray pathBytes = m_filePath.toUtf8();
afc_error_t result =
afc_get_file_info(m_device->afcClient, pathBytes.constData(), &info);
afc_get_file_info(m_afcClient, pathBytes.constData(), &info);
if (result != AFC_E_SUCCESS || !info) {
qWarning() << "Failed to get file info for:" << m_filePath;
@@ -410,9 +412,8 @@ void MediaStreamer::streamNextChunk(StreamingContext *context)
auto buffer = std::make_unique<char[]>(bytesToRead);
uint32_t bytesRead = 0;
afc_error_t readResult =
afc_file_read(context->device->afcClient, context->afcHandle,
buffer.get(), bytesToRead, &bytesRead);
afc_error_t readResult = afc_file_read(
m_afcClient, context->afcHandle, buffer.get(), bytesToRead, &bytesRead);
if (readResult != AFC_E_SUCCESS || bytesRead == 0) {
qWarning() << "AFC read error or EOF during streaming";