AVFormatContext的interrupt_callback字段
自定义中断回调的I/O层。
它的类型是AVIOInterruptCB,它在注释部分解释:
回调,用于检查是否中止阻塞函数。
在这种情况下,AVERROR_EXIT由中断的函数返回。在阻塞操作期间,以不透明作为参数调用回调。如果回调返回1,则阻塞操作将被中止。
如果在AVFormatContext或AVIOContext中在此结构之后添加了新元素,则无法在此结构中添加任何成员。
我有两个问题:
avformat_close_input的输入时,就会发出"TEARDOWN“消息,但是它不会到达RTSP服务器.。
对于2:下面是演示的快速伪代码:
int pkts = 0;
bool early_exit = false;
int InterruptCallback(void* ctx) {
return early_exit ? 1 : 0;
}
void main() {
ctx = avformat_alloc_context
ctx->interrupt_callback.callback = InterruptCallback;
avformat_open_input
avformat_find_stream_info
pkts=0;
while(!early_exit) {
av_read_frame
if (pkts++ > 100) early_exit=true;
}
avformat_close_input
}如果我根本不使用中断回调,就会发出TEARDOWN,并且它也会到达RTSP服务器,这样它就可以实际地断开连接。否则,它不会拆除它,我不得不等到TCP套接字超时。
使用这个中断回调的正确方法是什么?
发布于 2021-07-17 11:16:57
https://stackoverflow.com/questions/68414179
复制相似问题