Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions iaa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,38 @@
#include "config/config.h"
#include "logging.h"
#include "utils.h"

using namespace config;

#ifdef USE_IAA
#include <iostream>

#include "utils.h"

#define PREPENDED_BLOCK_LENGTH 5
#define MAX_BUFFER_SIZE (2 << 20)

void IAAJob::InitJob(qpl_path_t execution_path) {
uint32_t size;
qpl_status status = qpl_get_job_size(execution_path, &size);
if (status != QPL_STS_OK) {
jobs_[execution_path] = nullptr;
return;
}

QplJobPtr job = nullptr;
try {
jobs_[execution_path] = reinterpret_cast<qpl_job*>(new char[size]);
job = CreateQplJob(size);
} catch (std::bad_alloc& e) {
jobs_[execution_path] = nullptr;
return;
}
status = qpl_init_job(execution_path, jobs_[execution_path]);
status = qpl_init_job(execution_path, job.get());
if (status != QPL_STS_OK) {
delete[] jobs_[execution_path];
jobs_[execution_path] = nullptr;
return;
}

// Transfer ownership to the jobs_ vector
jobs_[execution_path] = std::move(job);
}

void IAAJob::DestroyJob(qpl_path_t execution_path) {
if (jobs_[execution_path] != nullptr) {
qpl_fini_job(jobs_[execution_path]);
delete[] jobs_[execution_path];
jobs_[execution_path] = nullptr;
if (jobs_[execution_path]) {
jobs_[execution_path].reset();
}
}

Expand Down Expand Up @@ -68,7 +66,7 @@ int CompressIAA(uint8_t* input, uint32_t* input_length, uint8_t* output,
}

qpl_job* job = job_.GetJob(execution_path);
if (job == nullptr) {
if (!job) {
Log(LogLevel::LOG_ERROR, "CompressIAA() Line ", __LINE__,
" Error qpl_job is null\n");
return 1;
Expand Down Expand Up @@ -197,7 +195,7 @@ int UncompressIAA(uint8_t* input, uint32_t* input_length, uint8_t* output,
}

qpl_job* job = job_.GetJob(execution_path);
if (job == nullptr) {
if (!job) {
Log(LogLevel::LOG_ERROR, "UncompressIAA() Line ", __LINE__,
" Error qpl_job is null\n");
return 1;
Expand Down
36 changes: 23 additions & 13 deletions iaa.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,46 @@
#ifdef USE_IAA
#define VISIBLE_FOR_TESTING __attribute__((visibility("default")))

#include <memory>
#include <vector>

#include "qpl/qpl.h"

inline constexpr unsigned int PREPENDED_BLOCK_LENGTH = 5;
inline constexpr unsigned int MAX_BUFFER_SIZE = (2 << 20);

class IAAJob {
public:
IAAJob() : jobs_(3, nullptr) {}

~IAAJob() {
for (qpl_job* job : jobs_) {
if (job != nullptr) {
qpl_fini_job(job);
delete[] job;
}
}
}
IAAJob() : jobs_(3) {}

qpl_job* GetJob(qpl_path_t execution_path) {
if (jobs_[execution_path] == nullptr) {
if (!jobs_[execution_path]) {
InitJob(execution_path);
}
return jobs_[execution_path];
return jobs_[execution_path].get();
}

void DestroyJob(qpl_path_t execution_path);

private:
struct QplJobDeleter {
void operator()(qpl_job* job) const {
if (job) {
qpl_fini_job(job);
delete[] reinterpret_cast<char*>(job);
}
}
};

using QplJobPtr = std::unique_ptr<qpl_job, QplJobDeleter>;

void InitJob(qpl_path_t execution_path);

std::vector<qpl_job*> jobs_;
QplJobPtr CreateQplJob(uint32_t size) {
return QplJobPtr(reinterpret_cast<qpl_job*>(new char[size]));
}

std::vector<QplJobPtr> jobs_;
};

int CompressIAA(uint8_t* input, uint32_t* input_length, uint8_t* output,
Expand Down