From 02f7f965b433b8b74c75bc429251d9087c10d3d8 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Fri, 14 Apr 2023 19:58:35 +0800 Subject: [PATCH] tmp --- main.c | 4 ++-- simp.c | 6 +++--- simp.h | 4 ++-- simp_ffmpeg_alsa.c | 18 +++++++++++------- simp_ffmpeg_input.c | 7 +++++-- simp_ffmpeg_output.c | 7 +++++-- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/main.c b/main.c index 19288d0..4dac9f1 100644 --- a/main.c +++ b/main.c @@ -16,12 +16,12 @@ int main(int argc, char* argv[]) simp_avio_t* in = NULL; simp_avio_t* out = NULL; - if (simp_avio_open(&in, "ffmpeg_input", argv[1]) < 0) { + if (simp_avio_open(&in, "ffmpeg_input", argv[1], NULL) < 0) { scf_loge("\n"); return -1; } - if (simp_avio_open(&out, "ffmpeg_output", argv[2]) < 0) { + if (simp_avio_open(&out, "ffmpeg_output", NULL, argv[2]) < 0) { scf_loge("\n"); return -1; } diff --git a/simp.c b/simp.c index ca33005..c3cf266 100644 --- a/simp.c +++ b/simp.c @@ -35,9 +35,9 @@ void simp_frame_free (simp_frame_t* f) } } -int simp_avio_open(simp_avio_t** pio, const char* type, const char* path) +int simp_avio_open(simp_avio_t** pio, const char* type, const char* in, const char* out) { - if (!pio || !type || !path) + if (!pio || !type || (!in && !out)) return -EINVAL; simp_avio_ops_t* ops = NULL; @@ -76,7 +76,7 @@ int simp_avio_open(simp_avio_t** pio, const char* type, const char* path) io->ops = ops; if (ops->open) { - int ret = ops->open(io, path); + int ret = ops->open(io, in, out); if (ret < 0) { free(io); return ret; diff --git a/simp.h b/simp.h index 28b08f4..a2fad70 100644 --- a/simp.h +++ b/simp.h @@ -136,7 +136,7 @@ struct simp_avio_ops_s { const char* type; - int (*open )(simp_avio_t* io, const char* path); + int (*open )(simp_avio_t* io, const char* in, const char* out); int (*close)(simp_avio_t* io); int (*run )(simp_avio_t* io); int (*stop )(simp_avio_t* io); @@ -145,7 +145,7 @@ struct simp_avio_ops_s simp_frame_t* simp_frame_alloc(); void simp_frame_free (simp_frame_t* f); -int simp_avio_open (simp_avio_t** pio, const char* type, const char* path); +int simp_avio_open (simp_avio_t** pio, const char* type, const char* in, const char* out); int simp_avio_close (simp_avio_t* io); int simp_avio_run (simp_avio_t* io); int simp_avio_stop (simp_avio_t* io); diff --git a/simp_ffmpeg_alsa.c b/simp_ffmpeg_alsa.c index 141b42e..eb51552 100644 --- a/simp_ffmpeg_alsa.c +++ b/simp_ffmpeg_alsa.c @@ -169,7 +169,7 @@ void simp_audio_free(simp_audio_t* priv) } } -static int _ffmpeg_alsa_open(simp_avio_t* io, const char* path) +static int _ffmpeg_alsa_open(simp_avio_t* io, const char* in, const char* out) { simp_audio_t* priv; AVStream* s; @@ -184,13 +184,17 @@ static int _ffmpeg_alsa_open(simp_avio_t* io, const char* path) priv->idx_in = -1; priv->idx_out = -1; - ret = _audio_input_init(priv, path); - if (ret < 0) - goto error; + if (in) { + ret = _audio_input_init(priv, in); + if (ret < 0) + goto error; + } - ret = _audio_output_init(priv, path); - if (ret < 0) - goto error; + if (out) { + ret = _audio_output_init(priv, out); + if (ret < 0) + goto error; + } io->priv = priv; return 0; diff --git a/simp_ffmpeg_input.c b/simp_ffmpeg_input.c index f28b7fa..1f06134 100644 --- a/simp_ffmpeg_input.c +++ b/simp_ffmpeg_input.c @@ -61,7 +61,7 @@ static int _audio_init(simp_ffmpeg_t* priv) return 0; } -static int _ffmpeg_input_open(simp_avio_t* io, const char* path) +static int _ffmpeg_input_open(simp_avio_t* io, const char* in, const char* out) { simp_ffmpeg_t* priv; AVStream* s; @@ -69,6 +69,9 @@ static int _ffmpeg_input_open(simp_avio_t* io, const char* path) int ret; int i; + if (!in) + return -EINVAL; + priv = calloc(1, sizeof(simp_ffmpeg_t)); if (!priv) return -ENOMEM; @@ -88,7 +91,7 @@ static int _ffmpeg_input_open(simp_avio_t* io, const char* path) goto error; } - ret = avformat_open_input(&priv->fmt_ctx, path, NULL, NULL); + ret = avformat_open_input(&priv->fmt_ctx, in, NULL, NULL); if (ret < 0) { scf_loge("ret: %s\n", av_err2str(ret)); goto error; diff --git a/simp_ffmpeg_output.c b/simp_ffmpeg_output.c index 70e0be8..26e1021 100644 --- a/simp_ffmpeg_output.c +++ b/simp_ffmpeg_output.c @@ -128,7 +128,7 @@ static int _audio_init(simp_ffmpeg_t* priv) return 0; } -static int _ffmpeg_output_open(simp_avio_t* io, const char* path) +static int _ffmpeg_output_open(simp_avio_t* io, const char* in, const char* out) { simp_ffmpeg_t* priv; AVStream* s; @@ -136,6 +136,9 @@ static int _ffmpeg_output_open(simp_avio_t* io, const char* path) int ret; int i; + if (!out) + return -EINVAL; + priv = calloc(1, sizeof(simp_ffmpeg_t)); if (!priv) return -ENOMEM; @@ -143,7 +146,7 @@ static int _ffmpeg_output_open(simp_avio_t* io, const char* path) priv->vidx = -1; priv->aidx = -1; - avformat_alloc_output_context2(&priv->fmt_ctx, NULL, NULL, path); + avformat_alloc_output_context2(&priv->fmt_ctx, NULL, NULL, out); if (!priv->fmt_ctx) { scf_loge("\n"); goto error; -- 2.25.1