|
6 | 6 | #include "config/config.h" |
7 | 7 | #include "logging.h" |
8 | 8 | #include "utils.h" |
| 9 | + |
9 | 10 | using namespace config; |
| 11 | + |
10 | 12 | #ifdef USE_IAA |
11 | | -#include <iostream> |
12 | 13 |
|
13 | 14 | #include "utils.h" |
14 | 15 |
|
15 | | -#define PREPENDED_BLOCK_LENGTH 5 |
16 | | -#define MAX_BUFFER_SIZE (2 << 20) |
17 | | - |
18 | 16 | void IAAJob::InitJob(qpl_path_t execution_path) { |
19 | 17 | uint32_t size; |
20 | 18 | qpl_status status = qpl_get_job_size(execution_path, &size); |
21 | 19 | if (status != QPL_STS_OK) { |
22 | | - jobs_[execution_path] = nullptr; |
23 | 20 | return; |
24 | 21 | } |
| 22 | + |
| 23 | + QplJobPtr job = nullptr; |
25 | 24 | try { |
26 | | - jobs_[execution_path] = reinterpret_cast<qpl_job*>(new char[size]); |
| 25 | + job = CreateQplJob(size); |
27 | 26 | } catch (std::bad_alloc& e) { |
28 | | - jobs_[execution_path] = nullptr; |
29 | 27 | return; |
30 | 28 | } |
31 | | - status = qpl_init_job(execution_path, jobs_[execution_path]); |
| 29 | + status = qpl_init_job(execution_path, job.get()); |
32 | 30 | if (status != QPL_STS_OK) { |
33 | | - delete[] jobs_[execution_path]; |
34 | | - jobs_[execution_path] = nullptr; |
| 31 | + return; |
35 | 32 | } |
| 33 | + |
| 34 | + // Transfer ownership to the jobs_ vector |
| 35 | + jobs_[execution_path] = std::move(job); |
36 | 36 | } |
37 | 37 |
|
38 | 38 | void IAAJob::DestroyJob(qpl_path_t execution_path) { |
39 | | - if (jobs_[execution_path] != nullptr) { |
40 | | - qpl_fini_job(jobs_[execution_path]); |
41 | | - delete[] jobs_[execution_path]; |
42 | | - jobs_[execution_path] = nullptr; |
| 39 | + if (jobs_[execution_path]) { |
| 40 | + jobs_[execution_path].reset(); |
43 | 41 | } |
44 | 42 | } |
45 | 43 |
|
@@ -68,7 +66,7 @@ int CompressIAA(uint8_t* input, uint32_t* input_length, uint8_t* output, |
68 | 66 | } |
69 | 67 |
|
70 | 68 | qpl_job* job = job_.GetJob(execution_path); |
71 | | - if (job == nullptr) { |
| 69 | + if (!job) { |
72 | 70 | Log(LogLevel::LOG_ERROR, "CompressIAA() Line ", __LINE__, |
73 | 71 | " Error qpl_job is null\n"); |
74 | 72 | return 1; |
@@ -197,7 +195,7 @@ int UncompressIAA(uint8_t* input, uint32_t* input_length, uint8_t* output, |
197 | 195 | } |
198 | 196 |
|
199 | 197 | qpl_job* job = job_.GetJob(execution_path); |
200 | | - if (job == nullptr) { |
| 198 | + if (!job) { |
201 | 199 | Log(LogLevel::LOG_ERROR, "UncompressIAA() Line ", __LINE__, |
202 | 200 | " Error qpl_job is null\n"); |
203 | 201 | return 1; |
|
0 commit comments