All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
19 #include "dualinput.h"
20 #include "libavutil/timestamp.h"
22 static int process_frame(FFFrameSync *fs)
23 {
24  AVFilterContext *ctx = fs->parent;
26  AVFrame *mainpic = NULL, *secondpic = NULL;
27  int ret = 0;
29  if ((ret = ff_framesync_get_frame(&s->fs, 0, &mainpic, 1)) < 0 ||
30  (ret = ff_framesync_get_frame(&s->fs, 1, &secondpic, 0)) < 0) {
31  av_frame_free(&mainpic);
32  return ret;
33  }
34  av_assert0(mainpic);
35  mainpic->pts = av_rescale_q(s->fs.pts, s->fs.time_base, ctx->outputs[0]->time_base);
36  if (secondpic && !ctx->is_disabled)
37  mainpic = s->process(ctx, mainpic, secondpic);
38  ret = ff_filter_frame(ctx->outputs[0], mainpic);
39  av_assert1(ret != AVERROR(EAGAIN));
40  return ret;
41 }
44 {
46  int ret;
48  if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
49  return ret;
51  in = s->fs.in;
52  s->fs.opaque = s;
54  in[0].time_base = ctx->inputs[0]->time_base;
55  in[1].time_base = ctx->inputs[1]->time_base;
56  in[0].sync = 2;
57  in[0].before = EXT_STOP;
58  in[0].after = EXT_INFINITY;
59  in[1].sync = 1;
60  in[1].before = EXT_NULL;
61  in[1].after = EXT_INFINITY;
63  if (s->shortest)
64  in[0].after = in[1].after = EXT_STOP;
65  if (!s->repeatlast) {
66  in[1].after = EXT_NULL;
67  in[1].sync = 0;
68  }
70  return ff_framesync_configure(&s->fs);
71 }
74  AVFilterLink *inlink, AVFrame *in)
75 {
76  return ff_framesync_filter_frame(&s->fs, inlink, in);
77 }
80 {
81  return ff_framesync_request_frame(&s->fs, outlink);
82 }
85 {
87 }
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
This structure describes decoded (raw) audio or video data.
Definition: frame.h:181
AVFormatContext * ctx
Definition: movenc-test.c:48
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
Definition: framesync.h:175
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:77
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:351
int64_t pts
Timestamp of the current event.
Definition: framesync.h:170
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:93
int ff_dualinput_filter_frame(FFDualInputContext *s, AVFilterLink *inlink, AVFrame *in)
Definition: dualinput.c:73
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:312
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1163
timestamp utils, mostly useful for debugging/logging purposes
void * parent
Definition: framesync.h:155
int shortest
terminate stream when the second input terminates
Definition: dualinput.h:36
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:262
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:206
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:98
void ff_dualinput_uninit(FFDualInputContext *s)
Definition: dualinput.c:84
Input stream structure.
Definition: framesync.h:83
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
int ff_framesync_filter_frame(FFFrameSync *fs, AVFilterLink *inlink, AVFrame *in)
Accept a frame on a filter input.
Definition: framesync.c:300
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:266
Frame sync structure.
Definition: framesync.h:153
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:154
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:103
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
int ff_framesync_request_frame(FFFrameSync *fs, AVFilterLink *outlink)
Request a frame on the filter output.
Definition: framesync.c:314
AVRational time_base
Time base for the output events.
Definition: framesync.h:165
AVFrame *(* process)(AVFilterContext *ctx, AVFrame *main, const AVFrame *second)
Definition: dualinput.h:35
FFFrameSync fs
Definition: dualinput.h:33
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:180
Extend the frame to infinity.
Definition: framesync.h:77
static int process_frame(FFFrameSync *fs)
Definition: dualinput.c:22
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int repeatlast
repeat last second frame
Definition: dualinput.h:37
int ff_framesync_init(FFFrameSync *fs, void *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:49
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events...
Definition: framesync.h:146
Ignore this stream and continue processing the other ones.
Definition: framesync.h:72
int ff_dualinput_init(AVFilterContext *ctx, FFDualInputContext *s)
Definition: dualinput.c:43
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:316
Completely stop all streams with this one.
Definition: framesync.h:67
Double input streams helper for filters.
An instance of a filter.
Definition: avfilter.h:304
int ff_dualinput_request_frame(FFDualInputContext *s, AVFilterLink *outlink)
Definition: dualinput.c:79
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
Definition: framesync.c:229