AVFrame*last_frame;// buffering the last frame for duplicating eventually
char*filename;// user-specified map file
char*buf;// line buffer for the map file
char*cur;// current position in the line buffer
char*end;// end pointer of the line buffer
int64_tptsi;// input pts to map to [0-N] output pts
int64_tpts;// output pts
inttb_num;// output timebase num
inttb_den;// output timebase den
}FsyncContext;
#define OFFSET(x) offsetof(FsyncContext, x)
staticconstAVOptionfsync_options[]={
{"file","set the file name to use for frame sync",OFFSET(filename),AV_OPT_TYPE_STRING,{.str=""},.flags=AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM},
{"f","set the file name to use for frame sync",OFFSET(filename),AV_OPT_TYPE_STRING,{.str=""},.flags=AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM},
{NULL}
};
/**
*Fillsthebufferfromcurtoend,add\0atEOF
*/
staticintbuf_fill(FsyncContext*ctx)
{
intret;
intnum=ctx->end-ctx->cur;
ret=avio_read(ctx->avio_ctx,ctx->cur,num);
if(ret<0)
returnret;
if(ret<num){
*(ctx->cur+ret)='\0';
}
returnret;
}
/**
*Copiescurtoendtothebeginningandfillstherest
*/
staticintbuf_reload(FsyncContext*ctx)
{
inti,ret;
intnum=ctx->end-ctx->cur;
for(i=0;i<num;i++){
ctx->buf[i]=*ctx->cur++;
}
ctx->cur=ctx->buf+i;
ret=buf_fill(ctx);
if(ret<0)
returnret;
ctx->cur=ctx->buf;
returnret;
}
/**
*Skipfromcurovereol
*/
staticvoidbuf_skip_eol(FsyncContext*ctx)
{
char*i;
for(i=ctx->cur;i<ctx->end;i++){
if(*i!='\n')// && *i != '\r')
break;
}
ctx->cur=i;
}
/**
*Getnumberofbytesfromcuruntileol
*
*@return>=0incaseofsuccess,
*-1incasethereisnolineendingbeforeendofbuffer
*/
staticintbuf_get_line_count(FsyncContext*ctx)
{
intret=0;
char*i;
for(i=ctx->cur;i<ctx->end;i++,ret++){
if(*i=='\0'||*i=='\n')
returnret;
}
return-1;
}
/**
*Getnumberofbytesfromcurto'\0'
*/
staticintbuf_get_zero(FsyncContext*ctx)
{
returnav_strnlen(ctx->cur,ctx->end-ctx->cur);
}
staticintactivate(AVFilterContext*ctx)
{
FsyncContext*s=ctx->priv;
AVFilterLink*inlink=ctx->inputs[0];
AVFilterLink*outlink=ctx->outputs[0];
intret,line_count;
AVFrame*frame;
FF_FILTER_FORWARD_STATUS_BACK(outlink,inlink);
buf_skip_eol(s);
line_count=buf_get_line_count(s);
if(line_count<0){
line_count=buf_reload(s);
if(line_count<0)
returnline_count;
line_count=buf_get_line_count(s);
if(line_count<0)
returnline_count;
}
if(avio_feof(s->avio_ctx)&&buf_get_zero(s)<3){
av_log(ctx,AV_LOG_DEBUG,"End of file. To zero = %i\n",buf_get_zero(s));