tmp
authoryu.dongliang <18588496441@163.com>
Sat, 8 Apr 2023 14:53:23 +0000 (22:53 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 8 Apr 2023 14:53:23 +0000 (22:53 +0800)
simp.c
simp_ffmpeg_input.c
simp_ffmpeg_output.c
simp_filter.c

diff --git a/simp.c b/simp.c
index cf38bde4c71fc51c19ced2654eb25de2847b6713..4491bfc99c1ff529b5a3e0858c5bbc9356641302 100644 (file)
--- a/simp.c
+++ b/simp.c
@@ -63,8 +63,8 @@ int simp_avio_open(simp_avio_t** pio, const char* type, const char* path)
        scf_list_init(&io->vout);
        scf_list_init(&io->aout);
 
-       pthread_mutex_init(&io->mutex);
-       pthread_cond_init (&io->cond);
+       pthread_mutex_init(&io->mutex, NULL);
+       pthread_cond_init (&io->cond , NULL);
 
        io->tid      = -1;
        io->width    = -1;
index 6efcddaf2bad06e991417c42be90c1ed92102d29..ba0099591af5032d68620822756f1c87c941c78d 100644 (file)
@@ -1,5 +1,5 @@
 #include"simp_ffmpeg.h"
-#include"scf_log.h"
+#include"scf_def.h"
 
 static int _video_init(simp_ffmpeg_t* priv)
 {
@@ -194,7 +194,7 @@ static int _ffmpeg_close(simp_avio_t* io)
        return 0;
 }
 
-int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* pkt, AVFrame* frame, scf_list_t* h)
+static int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* pkt, AVFrame* frame, scf_list_t* h)
 {
        int ret = avcodec_send_packet(dec_ctx, pkt);
        if (ret < 0) {
@@ -231,7 +231,7 @@ int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* pkt, AVF
        return 0;
 }
 
-void* __ffmpeg_run(void* arg)
+static void* __ffmpeg_run(void* arg)
 {
        simp_avio_t*    io     = arg;
        simp_ffmpeg_t*  priv   = io->priv;
@@ -243,13 +243,13 @@ void* __ffmpeg_run(void* arg)
        if (!pkt)
                goto end;
 
-       while (!priv->exit) {
+       while (!io->exit) {
 
                int ret = av_read_frame(priv->fmt_ctx, pkt);
                if (ret < 0) {
                        scf_loge("av_read_frame error, ret: %s\n", av_err2str(ret));
                        av_packet_free(&pkt);
-                       priv->error = ret;
+                       io->error = ret;
                        break;
                }
 
@@ -283,7 +283,7 @@ void* __ffmpeg_run(void* arg)
                        }
                }
 
-               av_packet_unref(&pkt);
+               av_packet_unref(pkt);
        }
 
 end:
index 447c007831026fd075c5352f54434da292530fd4..db14f49f4475867def7a7db42cf534f82534dcdb 100644 (file)
@@ -1,5 +1,5 @@
 #include"simp_ffmpeg.h"
-#include"scf_log.h"
+#include"scf_def.h"
 
 static int _video_init(simp_ffmpeg_t* priv)
 {
@@ -21,7 +21,7 @@ static int _video_init(simp_ffmpeg_t* priv)
        if (!priv->vdec_ctx)
                return -1;
 
-       priv->vdec_ctx->codec_id     = c->codec_id;
+       priv->vdec_ctx->codec_id     = c->id;
        priv->vdec_ctx->bit_rate     = 1024 * 1024;
        priv->vdec_ctx->width        = 1920;
        priv->vdec_ctx->height       = 1080;
@@ -63,7 +63,7 @@ static int _audio_init(simp_ffmpeg_t* priv)
        if (!priv->adec_ctx)
                return -1;
 
-       priv->adec_ctx->codec_id       = c->codec_id;
+       priv->adec_ctx->codec_id       = c->id;
        priv->adec_ctx->bit_rate       = 64 * 1024;
        priv->adec_ctx->sample_rate    = 44100;
        priv->adec_ctx->sample_fmt     = AV_SAMPLE_FMT_FLTP;
@@ -125,7 +125,7 @@ static int _ffmpeg_open(simp_avio_t* io, const char* path)
 
 error:
        if (priv->fmt_ctx)
-               avformat_close_output(&priv->fmt_ctx);
+               avformat_free_context(priv->fmt_ctx);
 
        if (priv->vdec_ctx)
                avcodec_close(priv->vdec_ctx);
@@ -154,7 +154,7 @@ static int _ffmpeg_close(simp_avio_t* io)
 
                if (priv) {
                        if (priv->fmt_ctx)
-                               avformat_close_output(&priv->fmt_ctx);
+                               avformat_free_context(priv->fmt_ctx);
 
                        if (priv->vdec_ctx)
                                avcodec_close(priv->vdec_ctx);
@@ -175,7 +175,7 @@ static int _ffmpeg_close(simp_avio_t* io)
        return 0;
 }
 
-int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* pkt, AVFrame* frame, scf_list_t* h)
+static int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* pkt, AVFrame* frame, scf_list_t* h)
 {
        int ret = avcodec_send_packet(dec_ctx, pkt);
        if (ret < 0) {
@@ -212,7 +212,7 @@ int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* pkt, AVF
        return 0;
 }
 
-void* __ffmpeg_run(void* arg)
+static void* __ffmpeg_run(void* arg)
 {
        simp_avio_t*    io     = arg;
        simp_ffmpeg_t*  priv   = io->priv;
@@ -227,13 +227,10 @@ void* __ffmpeg_run(void* arg)
        if (!pkt)
                goto end;
 
-       while (!priv->exit) {
+       while (!io->exit) {
                pthread_mutex_lock(&io->mutex);
 
                pthread_mutex_unlock(&io->mutex);
-
-
-
        }
 
 end:
index ed9c19e7c633688e0a746ab4d22ddd79998a5c6e..0a64851116df0ee410c543bacecfeeed458c0218 100644 (file)
@@ -62,14 +62,14 @@ static int _init_filters(simp_filter_t* f, const char* vfilters_descr, const cha
                        voutputs        = tmp;
                }
 
-               if (io->sample_rate > 0 && io->channels > 0 && io->aopen) {
+               if (io->sample_rate.den > 0 && io->channels > 0 && io->aopen) {
 
                        snprintf(args, sizeof(args),
                                        "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%"PRIx64,
                                        io->sample_rate.num, io->sample_rate.den,
                                        io->sample_rate.den /io->sample_rate.num,
                                        av_get_sample_fmt_name(io->sample_fmt),
-                                       av_get_default_channel_layout(io->channel_layout));
+                                       av_get_default_channel_layout(io->channels));
 
                        ret = avfilter_graph_create_filter(&io->abuffersrc_ctx, abuffersrc, "in", args, NULL, f->agraph);
                        if (ret < 0)
@@ -185,8 +185,8 @@ int simp_filter_open(simp_filter_t** pf)
        scf_list_init(&f->inputs);
        scf_list_init(&f->outputs);
 
-       pthread_mutex_init(&f->mutex);
-       pthread_cond_init (&f->cond);
+       pthread_mutex_init(&f->mutex, NULL);
+       pthread_cond_init (&f->cond,  NULL);
 
        f->tid = -1;
        return 0;
@@ -223,7 +223,7 @@ static void* __filter_run(void* arg)
 
                        int64_t time = sys_time - io->start_time;
 
-                       if (vopen) {
+                       if (io->vopen) {
                                pthread_mutex_lock(&io->mutex);
 
                                if (!scf_list_empty(&io->vin)) {
@@ -256,7 +256,7 @@ static void* __filter_run(void* arg)
                                }
                        }
 
-                       if (aopen) {
+                       if (io->aopen) {
                                pthread_mutex_lock(&io->mutex);
 
                                if (!scf_list_empty(&io->ain)) {
@@ -382,7 +382,7 @@ int simp_filter_run(simp_filter_t*  f)
 int simp_filter_add_input(simp_filter_t* f, simp_avio_t* input)
 {
        if (f && input) {
-               scf_list_add_tail(&f->inputs, input);
+               scf_list_add_tail(&f->inputs, &input->list);
                return 0;
        }
 
@@ -393,7 +393,7 @@ int simp_filter_add_input(simp_filter_t* f, simp_avio_t* input)
 int simp_filter_add_output(simp_filter_t* f, simp_avio_t* output)
 {
        if (f && output) {
-               scf_list_add_tail(&f->outputs, output);
+               scf_list_add_tail(&f->outputs, &output->list);
                return 0;
        }