diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-02-24 16:03:57 +0000 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2016-02-24 16:03:57 +0000 |
commit | 10424024a16a7646169b9c9008c5f7b77cbc2211 (patch) | |
tree | ea852976be3a8b8d0cd3d57bc1beb918b89991d0 /libavfilter/buffersrc.c | |
parent | 6992276acaaee32b33bd5f6e2f0d89588c4ae59a (diff) | |
parent | b3dd30db0b2d857147fc0e1461a00bd6172a26a3 (diff) | |
download | ffmpeg-10424024a16a7646169b9c9008c5f7b77cbc2211.tar.gz |
Merge commit 'b3dd30db0b2d857147fc0e1461a00bd6172a26a3'
* commit 'b3dd30db0b2d857147fc0e1461a00bd6172a26a3':
lavfi: pass the hw frames context through the filter chain
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavfilter/buffersrc.c')
-rw-r--r-- | libavfilter/buffersrc.c | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 27ad8e49ec..9294811d36 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -54,6 +54,8 @@ typedef struct BufferSourceContext { AVRational pixel_aspect; char *sws_param; + AVBufferRef *hw_frames_ctx; + /* audio only */ int sample_rate; enum AVSampleFormat sample_fmt; @@ -61,6 +63,7 @@ typedef struct BufferSourceContext { uint64_t channel_layout; char *channel_layout_str; + int got_format_from_params; int eof; } BufferSourceContext; @@ -76,6 +79,62 @@ typedef struct BufferSourceContext { return AVERROR(EINVAL);\ } +AVBufferSrcParameters *av_buffersrc_parameters_alloc(void) +{ + AVBufferSrcParameters *par = av_mallocz(sizeof(*par)); + if (!par) + return NULL; + + par->format = -1; + + return par; +} + +int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *param) +{ + BufferSourceContext *s = ctx->priv; + + if (param->time_base.num > 0 && param->time_base.den > 0) + s->time_base = param->time_base; + + switch (ctx->filter->outputs[0].type) { + case AVMEDIA_TYPE_VIDEO: + if (param->format != AV_PIX_FMT_NONE) { + s->got_format_from_params = 1; + s->pix_fmt = param->format; + } + if (param->width > 0) + s->w = param->width; + if (param->height > 0) + s->h = param->height; + if (param->sample_aspect_ratio.num > 0 && param->sample_aspect_ratio.den > 0) + s->pixel_aspect = param->sample_aspect_ratio; + if (param->frame_rate.num > 0 && param->frame_rate.den > 0) + s->frame_rate = param->frame_rate; + if (param->hw_frames_ctx) { + av_buffer_unref(&s->hw_frames_ctx); + s->hw_frames_ctx = av_buffer_ref(param->hw_frames_ctx); + if (!s->hw_frames_ctx) + return AVERROR(ENOMEM); + } + break; + case AVMEDIA_TYPE_AUDIO: + if (param->format != AV_SAMPLE_FMT_NONE) { + s->got_format_from_params = 1; + s->sample_fmt = param->format; + } + if (param->sample_rate > 0) + s->sample_rate = param->sample_rate; + if (param->channel_layout) + s->channel_layout = param->channel_layout; + break; + default: + return AVERROR_BUG; + } + + return 0; +} + int attribute_align_arg av_buffersrc_write_frame(AVFilterContext *ctx, const AVFrame *frame) { return av_buffersrc_add_frame_flags(ctx, (AVFrame *)frame, @@ -187,7 +246,8 @@ static av_cold int init_video(AVFilterContext *ctx) { BufferSourceContext *c = ctx->priv; - if (c->pix_fmt == AV_PIX_FMT_NONE || !c->w || !c->h || av_q2d(c->time_base) <= 0) { + if (!(c->pix_fmt != AV_PIX_FMT_NONE || c->got_format_from_params) || !c->w || !c->h || + av_q2d(c->time_base) <= 0) { av_log(ctx, AV_LOG_ERROR, "Invalid parameters provided.\n"); return AVERROR(EINVAL); } @@ -251,7 +311,7 @@ static av_cold int init_audio(AVFilterContext *ctx) BufferSourceContext *s = ctx->priv; int ret = 0; - if (s->sample_fmt == AV_SAMPLE_FMT_NONE) { + if (!(s->sample_fmt != AV_SAMPLE_FMT_NONE || s->got_format_from_params)) { av_log(ctx, AV_LOG_ERROR, "Sample format was not set or was invalid\n"); return AVERROR(EINVAL); } @@ -305,6 +365,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_fifo_generic_read(s->fifo, &frame, sizeof(frame), NULL); av_frame_free(&frame); } + av_buffer_unref(&s->hw_frames_ctx); av_fifo_freep(&s->fifo); } @@ -352,6 +413,12 @@ static int config_props(AVFilterLink *link) link->w = c->w; link->h = c->h; link->sample_aspect_ratio = c->pixel_aspect; + + if (c->hw_frames_ctx) { + link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx); + if (!link->hw_frames_ctx) + return AVERROR(ENOMEM); + } break; case AVMEDIA_TYPE_AUDIO: if (!c->channel_layout) |