diff options
| author | Mistivia <i@mistivia.com> | 2025-09-14 00:42:27 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-09-14 01:10:32 +0800 |
| commit | 8640bf35e76aa19710a563144e30d31db2685746 (patch) | |
| tree | 915fb1f0bc55caad0f52eb59a543d1315cfe0320 | |
| parent | 35c8f8e94f0346856130b2a96a7c99790796e53f (diff) | |
fix s3 client init bug
| -rw-r--r-- | ezlive_config.c (renamed from config.c) | 6 | ||||
| -rw-r--r-- | ezlive_config.h (renamed from config.h) | 0 | ||||
| -rw-r--r-- | main.c | 18 | ||||
| -rw-r--r-- | s3_client.cpp | 8 | ||||
| -rw-r--r-- | s3_worker.c | 3 | ||||
| -rw-r--r-- | transcode_talker.c | 3 |
6 files changed, 29 insertions, 9 deletions
diff --git a/config.c b/ezlive_config.c index 458c79c..08347d8 100644 --- a/config.c +++ b/ezlive_config.c @@ -1,4 +1,4 @@ -#include "config.h" +#include "ezlive_config.h" #include <stdlib.h> #include <stdio.h> @@ -92,6 +92,10 @@ int EZLiveConfig_validate(EZLiveConfig *self) { if (!self->bucket || strlen(self->bucket) == 0) return -3; if (!self->endpoint || strlen(self->endpoint) == 0) return -4; if (!self->s3_path || strlen(self->s3_path) == 0) return -5; + if (self->s3_path[strlen(self->s3_path) - 1] != '/') { + fprintf(stderr, "invalid s3 path. path should end with '\'.\n"); + return -10; + } if (!self->access_key || strlen(self->access_key) == 0) return -6; if (!self->secret_key || strlen(self->secret_key) == 0) return -7; if (self->listening_port <= 0 || self->listening_port > 65535) return -8; diff --git a/config.h b/ezlive_config.h index 58b3f7d..58b3f7d 100644 --- a/config.h +++ b/ezlive_config.h @@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> +#include "ezlive_config.h" #include "rtmpserver.h" #include "ringbuf.h" #include "transcode_talker.h" @@ -57,7 +58,22 @@ void on_rtmp_audio(void *ctx, int64_t timestamp, char *buf, size_t size) { RingBuffer_write_word32be(rb, size + 11); } -int main() { +int main(int argc, char **argv) { + ezlive_config = malloc(sizeof(EZLiveConfig)); + EZLiveConfig_init(ezlive_config); + if (argc == 1) { + EZLiveConfig_load(ezlive_config, "./config"); + } else if (argc == 2) { + EZLiveConfig_load(ezlive_config, argv[1]); + } else { + fprintf(stderr, "wrong args.\n"); + exit(-1); + } + int ret; + if ((ret = EZLiveConfig_validate(ezlive_config)) < 0) { + fprintf(stderr, "ezlive config error: %d.\n", ret); + exit(-1); + } srand((unsigned) time(NULL)); MainCtx main_ctx; RtmpCallbacks rtmp_cbs = { diff --git a/s3_client.cpp b/s3_client.cpp index aeb3510..42aa05c 100644 --- a/s3_client.cpp +++ b/s3_client.cpp @@ -9,21 +9,21 @@ #include <aws/s3/model/DeleteObjectRequest.h> #include <aws/core/auth/AWSCredentials.h> -#include "config.h" +#include "ezlive_config.h" #include <unistd.h> namespace { Aws::S3::S3Client *s3client; -Aws::SDKOptions aws_options; -Aws::S3::S3ClientConfiguration config; -Aws::Auth::AWSCredentials credentials; } void S3Client_init() { + Aws::SDKOptions aws_options; Aws::InitAPI(aws_options); + Aws::S3::S3ClientConfiguration config; + Aws::Auth::AWSCredentials credentials; config.endpointOverride = ezlive_config->endpoint; config.region = ezlive_config->region; credentials = Aws::Auth::AWSCredentials(ezlive_config->access_key, ezlive_config->secret_key); diff --git a/s3_worker.c b/s3_worker.c index 15fdb09..a6ae2ab 100644 --- a/s3_worker.c +++ b/s3_worker.c @@ -4,7 +4,7 @@ #include <stdlib.h> #include <string.h> -#include "config.h" +#include "ezlive_config.h" #include "task_queue.h" #include "s3_client.h" @@ -16,6 +16,7 @@ void exec_s3_task(void *vtask) { if (task->task_type == kUploadTask) { snprintf(obj_name_buf, 255, "%s%s", ezlive_config->s3_path, task->remote_name); S3Client_put(task->local_file, obj_name_buf); + remove(task->local_file); } else if (task->task_type == kDeleteTask) { snprintf(obj_name_buf, 255, "%s%s", ezlive_config->s3_path, task->remote_name); S3Client_delete(obj_name_buf); diff --git a/transcode_talker.c b/transcode_talker.c index 3d22de5..241c6c4 100644 --- a/transcode_talker.c +++ b/transcode_talker.c @@ -2,7 +2,6 @@ #include "fsutils.h" #include "ringbuf.h" -#include <bits/pthreadtypes.h> #include <libavformat/avformat.h> #include <libavformat/avio.h> #include <libavutil/mem.h> @@ -244,7 +243,7 @@ void* TranscodeTalker_main (void *vself) { // open new ts segment_start_pts = pts_time; - snprintf(out_filename, sizeof(out_filename), "segment_%03d.ts", segment_index); + tmp_local_filename("/tmp/ezlive", out_filename); output_stream = start_new_output_file(in_fmt_ctx, &out_fmt_ctx, out_filename, audio_stream_index, video_stream_index); } } |
