ffmpeg支持interrupt_callback机制,可以对输入(或输出)的AVFormatContext的interrupt_callback成员设置,然后再回调函数中做控制。 // 回调函数的参数,用了时间 typedef struct { time_t lasttime; } Runner; //回调函数static int interrupt_callback(void *p) { Runner *r = (Runner *)p; if (r->lasttime >...
ret = avformat_open_input(&ctx, url, NULL, &opts); 2. 设置interrupt_callback定义返回机制 设置回调,监控read超时情况,回调方法为: int64_t lastReadPacktTime; static int interrupt_cb(void *ctx) { int timeout = 3; if (av_gettime() - lastReadPacktTime > timeout * 1000 * 1000) { retu...
//打开成功后 设置回调,监控read超时情况 通过这种方式可以动态修改 context->ifmt_ctx->interrupt_callback.opaque = (void*)context; context->ifmt_ctx->interrupt_callback.callback = interruptCallback;//设置回调 //每次读流之前记录一下起始时间 context->read_start_time = time(NULL); int ret = av...
player->avformat_context = avformat_alloc_context(); player->avformat_context->interrupt_callback.callback = interrupt_cb; player->avformat_context->interrupt_callback.opaque = player; // open input file AVDictionary *options = NULL; //++ for find trsp if ((strstr(url, "rtsp") == url)...
2. 设置interrupt_callback定义返回机制 设置回调,监控read超时情况,回调方法为: int64_t lastReadPacktTime;staticintinterrupt_cb(void*ctx) {inttimeout =3;if(av_gettime() - lastReadPacktTime > timeout *1000*1000) {return-1; }return0;
cb.callback = interrupt_callback; //这里可以传递一个可选参数,实际上传递类的指针,然后获取到当前执行 //av_read_frame前m_tStart的值 cb.opaque = this; //设置中断 AVFormatContext* pAVFormatContext = avformat_alloc_context(); pAVFormatContext->interrupt_callback = cb; ...
player->avformat_context->interrupt_callback.callback = interrupt_cb; player->avformat_context->interrupt_callback.opaque = player; // open input file AVDictionary *options = NULL; //++ for find trsp if ((strstr(url, "rtsp") == url) || (strstr(url, "RTSP") == url)) ...
因此,我们需要一个中断机制,在等待超时或者退出播放的时候,就可以轻松中断掉这个阻塞过程。 ffmpeg 提供了一个很简单的回调机制,即注册一个自定义的回调函数,用于外部中断阻塞的网络操作,用法如下所示: 1 2 3 4 5 6 7 8 9 10 staticintcustom_interrupt_callback(void*arg) { ...
ⅱ. ic->interrupt_callback.callback = decode_interrupt_cb; ⅲ. avformat_open_input打开媒体⽂件 ⅳ. avformat_find_stream_info 读取媒体⽂件的包获取更多的stream信息 ⅴ. 检测是否指定播放起始时间,如果指定时间则seek到指定位置avformat_seek_file ...
read_size=0;for(;;){int analyzed_all_streams;if(ff_check_interrupt(&ic->interrupt_callback)){ret=AVERROR_EXIT;av_log(ic,AV_LOG_DEBUG,"interrupted\n");break;}/* check if one codec still needs to be handled */for(i=0;i