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;
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;
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;
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;
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;
}
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);
return ret;
}
-static int _ffmpeg_close(simp_avio_t* io)
+static int _ffmpeg_input_close(simp_avio_t* io)
{
simp_ffmpeg_t* priv;
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);
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;
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;
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;
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;
}
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,
};
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;
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;
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;
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);
return ret;
}
-static int _ffmpeg_close(simp_avio_t* io)
+static int _ffmpeg_output_close(simp_avio_t* io)
{
simp_ffmpeg_t* priv;
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);
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;
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;
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;
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;
}
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,
};