From: yu.dongliang <18588496441@163.com> Date: Mon, 10 Apr 2023 08:27:59 +0000 (+0800) Subject: tmp X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=efeae0a8e8cf08b2371414c56865b38b6881c998;p=simplay.git tmp --- diff --git a/simp.c b/simp.c index fa77b46..df17b3b 100644 --- a/simp.c +++ b/simp.c @@ -1,10 +1,12 @@ #include"simp.h" extern simp_avio_ops_t simp_avio_ffmpeg_input; +extern simp_avio_ops_t simp_avio_ffmpeg_output; static simp_avio_ops_t* avio_array[] = { &simp_avio_ffmpeg_input, + &simp_avio_ffmpeg_output, NULL, }; diff --git a/simp_ffmpeg.h b/simp_ffmpeg.h index 9ebbe0d..aabb7a5 100644 --- a/simp_ffmpeg.h +++ b/simp_ffmpeg.h @@ -5,8 +5,8 @@ typedef struct { AVFormatContext* fmt_ctx; - AVCodecContext* vdec_ctx; - AVCodecContext* adec_ctx; + AVCodecContext* vcodec_ctx; + AVCodecContext* acodec_ctx; AVAudioFifo* afifo; diff --git a/simp_ffmpeg_input.c b/simp_ffmpeg_input.c index 0b3c98a..553b780 100644 --- a/simp_ffmpeg_input.c +++ b/simp_ffmpeg_input.c @@ -14,15 +14,15 @@ static int _video_init(simp_ffmpeg_t* priv) return -1; } - priv->vdec_ctx = avcodec_alloc_context3(c); - if (!priv->vdec_ctx) + priv->vcodec_ctx = avcodec_alloc_context3(c); + if (!priv->vcodec_ctx) return -1; - int ret = avcodec_parameters_to_context(priv->vdec_ctx, s->codecpar); + int ret = avcodec_parameters_to_context(priv->vcodec_ctx, s->codecpar); if (ret < 0) return -1; - ret = avcodec_open2(priv->vdec_ctx, c, NULL); + ret = avcodec_open2(priv->vcodec_ctx, c, NULL); if (ret < 0) { printf("avcodec_parameters_to_context error, ret: %d, %s\n", ret, av_err2str(ret)); return -1; @@ -44,15 +44,15 @@ static int _audio_init(simp_ffmpeg_t* priv) return -1; } - priv->adec_ctx = avcodec_alloc_context3(c); - if (!priv->adec_ctx) + priv->acodec_ctx = avcodec_alloc_context3(c); + if (!priv->acodec_ctx) return -1; - int ret = avcodec_parameters_to_context(priv->adec_ctx, s->codecpar); + int ret = avcodec_parameters_to_context(priv->acodec_ctx, s->codecpar); if (ret < 0) return -1; - ret = avcodec_open2(priv->adec_ctx, c, NULL); + ret = avcodec_open2(priv->acodec_ctx, c, NULL); if (ret < 0) { printf("avcodec_parameters_to_context error, ret: %d, %s\n", ret, av_err2str(ret)); return -1; @@ -61,7 +61,7 @@ static int _audio_init(simp_ffmpeg_t* priv) return 0; } -static int _ffmpeg_open(simp_avio_t* io, const char* path) +static int _ffmpeg_input_open(simp_avio_t* io, const char* path) { simp_ffmpeg_t* priv; AVStream* s; @@ -125,11 +125,11 @@ static int _ffmpeg_open(simp_avio_t* io, const char* path) if (ret < 0) goto error; - io->width = priv->vdec_ctx->width; - io->height = priv->vdec_ctx->height; - io->pix_fmt = priv->vdec_ctx->pix_fmt; + io->width = priv->vcodec_ctx->width; + io->height = priv->vcodec_ctx->height; + io->pix_fmt = priv->vcodec_ctx->pix_fmt; io->frame_rate = priv-> fmt_ctx->streams[priv->vidx]->r_frame_rate; - io->sample_aspect_ratio = priv->vdec_ctx->sample_aspect_ratio; + io->sample_aspect_ratio = priv->vcodec_ctx->sample_aspect_ratio; io->x = 0; io->y = 0; @@ -141,9 +141,9 @@ static int _ffmpeg_open(simp_avio_t* io, const char* path) if (ret < 0) goto error; - io->sample_fmt = priv->adec_ctx->sample_fmt; - io->sample_rate = priv->adec_ctx->time_base; - io->channels = priv->adec_ctx->channels; + io->sample_fmt = priv->acodec_ctx->sample_fmt; + io->sample_rate = priv->acodec_ctx->time_base; + io->channels = priv->acodec_ctx->channels; io->aopen = 1; } @@ -154,11 +154,11 @@ error: if (priv->fmt_ctx) avformat_close_input(&priv->fmt_ctx); - if (priv->vdec_ctx) - avcodec_close(priv->vdec_ctx); + if (priv->vcodec_ctx) + avcodec_close(priv->vcodec_ctx); - if (priv->adec_ctx) - avcodec_close(priv->adec_ctx); + if (priv->acodec_ctx) + avcodec_close(priv->acodec_ctx); if (priv->vframe) av_frame_free(&priv->vframe); @@ -170,7 +170,7 @@ error: return ret; } -static int _ffmpeg_close(simp_avio_t* io) +static int _ffmpeg_input_close(simp_avio_t* io) { simp_ffmpeg_t* priv; @@ -189,11 +189,11 @@ static int _ffmpeg_close(simp_avio_t* io) if (priv->fmt_ctx) avformat_close_input(&priv->fmt_ctx); - if (priv->vdec_ctx) - avcodec_close(priv->vdec_ctx); + if (priv->vcodec_ctx) + avcodec_close(priv->vcodec_ctx); - if (priv->adec_ctx) - avcodec_close(priv->adec_ctx); + if (priv->acodec_ctx) + avcodec_close(priv->acodec_ctx); if (priv->vframe) av_frame_free(&priv->vframe); @@ -272,7 +272,7 @@ static int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* p return 0; } -static void* __ffmpeg_run(void* arg) +static void* __ffmpeg_input_run(void* arg) { simp_avio_t* io = arg; simp_ffmpeg_t* priv = io->priv; @@ -308,7 +308,7 @@ static void* __ffmpeg_run(void* arg) continue; } - ret = __ffmpeg_decode(io, priv->adec_ctx, pkt, priv->aframe, &io->ain, NULL); + ret = __ffmpeg_decode(io, priv->acodec_ctx, pkt, priv->aframe, &io->ain, NULL); if (ret < 0) { io->error = ret; goto end; @@ -324,7 +324,7 @@ static void* __ffmpeg_run(void* arg) continue; } - ret = __ffmpeg_decode(io, priv->vdec_ctx, pkt, priv->vframe, &io->vin, &io->nb_vframes); + ret = __ffmpeg_decode(io, priv->vcodec_ctx, pkt, priv->vframe, &io->vin, &io->nb_vframes); if (ret < 0) { io->error = ret; goto end; @@ -346,9 +346,9 @@ end: return NULL; } -static int _ffmpeg_run(simp_avio_t* io) +static int _ffmpeg_input_run(simp_avio_t* io) { - if (pthread_create(&io->tid, NULL, __ffmpeg_run, io)) { + if (pthread_create(&io->tid, NULL, __ffmpeg_input_run, io)) { scf_loge("\n"); return -1; } @@ -359,8 +359,8 @@ static int _ffmpeg_run(simp_avio_t* io) simp_avio_ops_t simp_avio_ffmpeg_input = { .type = "ffmpeg_input", - .open = _ffmpeg_open, - .close = _ffmpeg_close, - .run = _ffmpeg_run, + .open = _ffmpeg_input_open, + .close = _ffmpeg_input_close, + .run = _ffmpeg_input_run, }; diff --git a/simp_ffmpeg_output.c b/simp_ffmpeg_output.c index cefe9f7..ff6c607 100644 --- a/simp_ffmpeg_output.c +++ b/simp_ffmpeg_output.c @@ -17,24 +17,24 @@ static int _video_init(simp_ffmpeg_t* priv) s->id = priv->fmt_ctx->nb_streams - 1; priv->vidx = s->id; - priv->vdec_ctx = avcodec_alloc_context3(c); - if (!priv->vdec_ctx) + priv->vcodec_ctx = avcodec_alloc_context3(c); + if (!priv->vcodec_ctx) return -1; - priv->vdec_ctx->codec_id = c->id; - priv->vdec_ctx->bit_rate = 1024 * 1024; - priv->vdec_ctx->width = 1920; - priv->vdec_ctx->height = 1080; - priv->vdec_ctx->time_base = (AVRational){1, 25}; - priv->vdec_ctx->gop_size = 30; - priv->vdec_ctx->max_b_frames = 2; - priv->vdec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; - s->time_base = priv->vdec_ctx->time_base; + priv->vcodec_ctx->codec_id = c->id; + priv->vcodec_ctx->bit_rate = 1024 * 1024; + priv->vcodec_ctx->width = 1920; + priv->vcodec_ctx->height = 1080; + priv->vcodec_ctx->time_base = (AVRational){1, 25}; + priv->vcodec_ctx->gop_size = 30; + priv->vcodec_ctx->max_b_frames = 2; + priv->vcodec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; + s->time_base = priv->vcodec_ctx->time_base; if (priv->fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) - priv->vdec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + priv->vcodec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - int ret = avcodec_open2(priv->vdec_ctx, c, NULL); + int ret = avcodec_open2(priv->vcodec_ctx, c, NULL); if (ret < 0) { printf("avcodec_parameters_to_context error, ret: %d, %s\n", ret, av_err2str(ret)); return ret; @@ -63,23 +63,23 @@ static int _audio_init(simp_ffmpeg_t* priv) s->id = priv->fmt_ctx->nb_streams - 1; priv->aidx = s->id; - priv->adec_ctx = avcodec_alloc_context3(c); - if (!priv->adec_ctx) + priv->acodec_ctx = avcodec_alloc_context3(c); + if (!priv->acodec_ctx) return -1; - 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; - priv->adec_ctx->channels = 2; - priv->adec_ctx->channel_layout = av_get_default_channel_layout(priv->adec_ctx->channels); - priv->adec_ctx->time_base = (AVRational){1, priv->adec_ctx->sample_rate}; - s->time_base = priv->adec_ctx->time_base; + priv->acodec_ctx->codec_id = c->id; + priv->acodec_ctx->bit_rate = 64 * 1024; + priv->acodec_ctx->sample_rate = 44100; + priv->acodec_ctx->sample_fmt = AV_SAMPLE_FMT_FLTP; + priv->acodec_ctx->channels = 2; + priv->acodec_ctx->channel_layout = av_get_default_channel_layout(priv->acodec_ctx->channels); + priv->acodec_ctx->time_base = (AVRational){1, priv->acodec_ctx->sample_rate}; + s->time_base = priv->acodec_ctx->time_base; if (priv->fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) - priv->adec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + priv->acodec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - int ret = avcodec_open2(priv->adec_ctx, c, NULL); + int ret = avcodec_open2(priv->acodec_ctx, c, NULL); if (ret < 0) { printf("avcodec_parameters_to_context error, ret: %d, %s\n", ret, av_err2str(ret)); return ret; @@ -107,7 +107,7 @@ static int _audio_init(simp_ffmpeg_t* priv) return 0; } -static int _ffmpeg_open(simp_avio_t* io, const char* path) +static int _ffmpeg_output_open(simp_avio_t* io, const char* path) { simp_ffmpeg_t* priv; AVStream* s; @@ -150,11 +150,11 @@ error: if (priv->fmt_ctx) avformat_free_context(priv->fmt_ctx); - if (priv->vdec_ctx) - avcodec_close(priv->vdec_ctx); + if (priv->vcodec_ctx) + avcodec_close(priv->vcodec_ctx); - if (priv->adec_ctx) - avcodec_close(priv->adec_ctx); + if (priv->acodec_ctx) + avcodec_close(priv->acodec_ctx); if (priv->afifo) av_audio_fifo_free(priv->afifo); @@ -163,7 +163,7 @@ error: return ret; } -static int _ffmpeg_close(simp_avio_t* io) +static int _ffmpeg_output_close(simp_avio_t* io) { simp_ffmpeg_t* priv; @@ -182,11 +182,11 @@ static int _ffmpeg_close(simp_avio_t* io) if (priv->fmt_ctx) avformat_free_context(priv->fmt_ctx); - if (priv->vdec_ctx) - avcodec_close(priv->vdec_ctx); + if (priv->vcodec_ctx) + avcodec_close(priv->vcodec_ctx); - if (priv->adec_ctx) - avcodec_close(priv->adec_ctx); + if (priv->acodec_ctx) + avcodec_close(priv->acodec_ctx); if (priv->afifo) av_audio_fifo_free(priv->afifo); @@ -238,7 +238,7 @@ static int __ffmpeg_encode(simp_avio_t* io, AVCodecContext* c, AVPacket* pkt, AV return 0; } -static void* __ffmpeg_run(void* arg) +static void* __ffmpeg_output_run(void* arg) { simp_avio_t* io = arg; simp_ffmpeg_t* priv = io->priv; @@ -257,7 +257,7 @@ static void* __ffmpeg_run(void* arg) scf_list_del(&f->list); pthread_mutex_unlock(&io->mutex); - int ret = __ffmpeg_encode(io, priv->vdec_ctx, priv->vpkt, f->frame); + int ret = __ffmpeg_encode(io, priv->vcodec_ctx, priv->vpkt, f->frame); simp_frame_free(f); f = NULL; @@ -296,7 +296,7 @@ static void* __ffmpeg_run(void* arg) goto end; } - ret = __ffmpeg_encode(io, priv->adec_ctx, priv->apkt, priv->aframe); + ret = __ffmpeg_encode(io, priv->acodec_ctx, priv->apkt, priv->aframe); if (ret < 0) { io->error = ret; goto end; @@ -317,9 +317,9 @@ end: return NULL; } -static int _ffmpeg_run(simp_avio_t* io) +static int _ffmpeg_output_run(simp_avio_t* io) { - if (pthread_create(&io->tid, NULL, __ffmpeg_run, io)) { + if (pthread_create(&io->tid, NULL, __ffmpeg_output_run, io)) { scf_loge("\n"); return -1; } @@ -330,8 +330,8 @@ static int _ffmpeg_run(simp_avio_t* io) simp_avio_ops_t simp_avio_ffmpeg_output = { .type = "ffmpeg_output", - .open = _ffmpeg_open, - .close = _ffmpeg_close, - .run = _ffmpeg_run, + .open = _ffmpeg_output_open, + .close = _ffmpeg_output_close, + .run = _ffmpeg_output_run, };