Skip to content

Commit

Permalink
experimental backend TAF encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Sep 16, 2024
1 parent 161f617 commit 4ec3cff
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/handler_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ error_t handleApiFileDelete(HttpConnection *connection, const char_t *uri, const
error_t handleApiFileMove(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
error_t handleApiDirectoryDelete(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
error_t handleApiAssignUnknown(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
error_t handleApiEncodeFile(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
error_t handleApiPcmUpload(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
error_t handleApiContent(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
error_t handleApiContentDownload(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx);
Expand Down
60 changes: 58 additions & 2 deletions src/handler_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,60 @@ error_t taf_encode_end(void *in_ctx)
return NO_ERROR;
}

error_t handleApiEncodeFile(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx)
{
char overlay[16];
const char *rootPath = NULL;

if (queryPrepare(queryString, &rootPath, overlay, sizeof(overlay), &client_ctx->settings) != NO_ERROR)
{
return ERROR_FAILURE;
}

char_t post_data[BODY_BUFFER_SIZE];
error_t error = parsePostData(connection, post_data, BODY_BUFFER_SIZE);
if (error != NO_ERROR)
{
TRACE_ERROR("parsePostData failed with error %s\r\n", error2text(error));
return error;
}

char multisource[99][PATH_LEN];
uint8_t multisource_size = 0;
char source[256 + 3];
char target[256 + 3];

if (!queryGet(post_data, "source", source, sizeof(source)))
{
TRACE_ERROR("source missing!\r\n");
return ERROR_INVALID_REQUEST;
}
if (!queryGet(post_data, "target", target, sizeof(target)))
{
TRACE_ERROR("target missing!\r\n");
return ERROR_INVALID_REQUEST;
}
sanitizePath(target, false);
char *targetAbsolute = custom_asprintf("%s%c%s", rootPath, PATH_SEPARATOR, target);
sanitizePath(targetAbsolute, false);

// TODO implement multiple sources
sanitizePath(source, false);
osSprintf(multisource[multisource_size++], "%s%c%s", rootPath, PATH_SEPARATOR, source);
sanitizePath(multisource[multisource_size - 1], false);
TRACE_INFO("Encode: '%s'\r\n", multisource[multisource_size - 1]);

TRACE_INFO("Encode %" PRIu8 " files to '%s'\r\n", multisource_size, target);
size_t current_source = 0;
error = ffmpeg_convert(multisource, multisource_size, &current_source, target, 0);
osFreeMem(targetAbsolute);
if (error != NO_ERROR)
{
TRACE_ERROR("ffmpeg_convert failed with error %s\r\n", error2text(error));
}

return error;
}
error_t handleApiPcmUpload(HttpConnection *connection, const char_t *uri, const char_t *queryString, client_ctx_t *client_ctx)
{
char overlay[16];
Expand Down Expand Up @@ -2065,11 +2119,13 @@ error_t handleApiFileMove(HttpConnection *connection, const char_t *uri, const c
char source[256 + 3];
char target[256 + 3];

if (!queryGet(post_data, "source", source, sizeof(source))) {
if (!queryGet(post_data, "source", source, sizeof(source)))
{
TRACE_ERROR("source missing!\r\n");
return ERROR_INVALID_REQUEST;
}
if (!queryGet(post_data, "target", target, sizeof(target))) {
if (!queryGet(post_data, "target", target, sizeof(target)))
{
TRACE_ERROR("target missing!\r\n");
return ERROR_INVALID_REQUEST;
}
Expand Down
1 change: 1 addition & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ request_type_t request_paths[] = {
{REQ_POST, "/api/uploadFirmware", SERTY_WEB, &handleApiUploadFirmware},
{REQ_GET, "/api/patchFirmware", SERTY_WEB, &handleApiPatchFirmware},
{REQ_POST, "/api/fileUpload", SERTY_WEB, &handleApiFileUpload},
{REQ_POST, "/api/fileEncode", SERTY_WEB, &handleApiEncodeFile},
{REQ_POST, "/api/pcmUpload", SERTY_WEB, &handleApiPcmUpload},
{REQ_GET, "/api/fileIndexV2", SERTY_WEB, &handleApiFileIndexV2},
{REQ_GET, "/api/fileIndex", SERTY_WEB, &handleApiFileIndex},
Expand Down

0 comments on commit 4ec3cff

Please sign in to comment.