|
|
|
|
@ -87,6 +87,9 @@ void media_async_submit(struct media_async* ma, struct UASYNC* ua,
|
|
|
|
|
if (done) done(arg, MEDIA_ASYNC_CANCELLED); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
unsigned active = 0; |
|
|
|
|
for (struct ma_thread_ctx* pending = ma->jobs; pending; pending = pending->next) active++; |
|
|
|
|
if (active >= 16) { DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "media task limit reached active=%u", active); done(arg, -1); return; } |
|
|
|
|
struct ma_thread_ctx* job = u_calloc(1, sizeof(*job)); |
|
|
|
|
if (!job) { DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "media task allocation failed"); done(arg, -1); return; } |
|
|
|
|
job->owner = ma; job->ua = ua; job->work = work; job->data = data; job->done = done; job->arg = arg; |
|
|
|
|
@ -114,8 +117,9 @@ int ma_sha256_file(const char* path, uint8_t hash_out[32]) {
|
|
|
|
|
uint8_t buf[65536]; |
|
|
|
|
size_t rd; |
|
|
|
|
while ((rd = fread(buf, 1, sizeof(buf), f)) > 0) SHA256_Update(&ctx, buf, rd); |
|
|
|
|
fclose(f); |
|
|
|
|
|
|
|
|
|
int error = ferror(f); |
|
|
|
|
if (fclose(f)) error = 1; |
|
|
|
|
if (error) { DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "ma_sha256_file: read/close failed path=%s", path); return -1; } |
|
|
|
|
SHA256_Final(hash_out, &ctx); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
@ -162,8 +166,11 @@ int ma_copy_file(const char* src, const char* dst) {
|
|
|
|
|
fclose(s); fclose(d); return -1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fclose(s); fclose(d); |
|
|
|
|
return 0; |
|
|
|
|
int error = ferror(s); |
|
|
|
|
if (fclose(s)) error = 1; |
|
|
|
|
if (fclose(d)) error = 1; |
|
|
|
|
if (error) DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "ma_copy_file: read/close failed src=%s dst=%s", src, dst); |
|
|
|
|
return error ? -1 : 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int ma_file_size(const char* path) { |
|
|
|
|
|