ijkPlayer源码分析 PacketQueue分析( 二 )

 
重置、销毁操作
// stream_close时第一个调用它,主要是置abort_request为1,阻断后续所有流程static void packet_queue_abort(PacketQueue *q) {SDL_LockMutex(q->mutex);q->abort_request = 1;SDL_CondSignal(q->cond);SDL_UnlockMutex(q->mutex);}// seek或destory时调用static void packet_queue_flush(PacketQueue *q) {SDL_LockMutex(q->mutex);// 释放所有pktMyAVPacketList *pkt, *pkt1;for (pkt = q->first_pkt; pkt; pkt = pkt1) {pkt1 = pkt->next;av_packet_unref(&pkt->pkt);// 回收,放到链表头部pkt->next = q->recycle_pkt;q->recycle_pkt = pkt;}q->last_pkt = NULL;q->first_pkt = NULL;q->nb_packets = 0;q->size = 0;q->duration = 0;SDL_UnlockMutex(q->mutex);}// 清空所有pkt,包括recycle_pkt,stream_close处调用static void packet_queue_destroy(PacketQueue *q) {packet_queue_flush(q);SDL_LockMutex(q->mutex);while (q->recycle_pkt) {MyAVPacketList *pkt = q->recycle_pkt;if (pkt)q->recycle_pkt = pkt->next;av_freep(&pkt);}SDL_UnlockMutex(q->mutex);SDL_DestroyMutex(q->mutex);SDL_DestroyCond(q->cond);}



推荐阅读