intisTaskStateRunning(char* taskId){ int* state = getTaskState(taskId); if (state == NULL) { return0; } return *state == RUNNING; }
while (av_read_frame(ss->ifmt_ctx, ss->dePkt) >= 0) { if (!isTaskStateRunning(ss->taskId)) { LogWarn("------------- task %s state is stopped, break the loop -------------", ss->taskId); break; } ... }
/** * Custom interrupt callbacks for the I/O layer. * * demuxing: set by the user before avformat_open_input(). * muxing: set by the user before avformat_write_header() * (mainly useful for AVFMT_NOFILE formats). The callback * should also be passed to avio_open2() if it's used to * open the file. */ AVIOInterruptCB interrupt_callback;
}
/** * Callback for checking whether to abort blocking functions. * AVERROR_EXIT is returned in this case by the interrupted * function. During blocking operations, callback is called with * opaque as parameter. If the callback returns 1, the * blocking operation will be aborted. * * No members can be added to this struct without a major bump, if * new elements have been added after this struct in AVFormatContext * or AVIOContext. */ typedefstructAVIOInterruptCB { int (*callback)(void*); void *opaque; } AVIOInterruptCB;
所以这里设置一个回调函数,在任务状态为Stop的时候返回1即可:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
intisTaskStateRunning(char* taskId){ int* state = getTaskState(taskId); if (state == NULL) { return0; } return *state == RUNNING; }
intinterruptCallBack(void* taskId){ if (isTaskStateRunning((char*)taskId)) { return0; } return1; }