Skip to content

Commit 2b57abf

Browse files
committed
清理缓存时保留keyframe
1 parent f0941c5 commit 2b57abf

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

ijkmedia/ijkplayer/ff_ffplay.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,39 @@ static void packet_queue_flush(PacketQueue *q)
259259
SDL_UnlockMutex(q->mutex);
260260
}
261261

262+
static void packet_queue_flush_videocache(PacketQueue *q)
263+
{
264+
MyAVPacketList *pkt, *pkt1;
265+
266+
SDL_LockMutex(q->mutex);
267+
for (pkt = q->first_pkt; pkt; pkt = pkt1) {
268+
pkt1 = pkt->next;
269+
270+
if ((&pkt->pkt)->flags & AV_PKT_FLAG_KEY) {
271+
q->last_pkt = pkt;
272+
q->first_pkt = pkt;
273+
q->nb_packets = 1;
274+
q->size = 1;
275+
q->duration = MIN_PKT_DURATION;
276+
continue;
277+
}
278+
279+
av_packet_unref(&pkt->pkt);
280+
#ifdef FFP_MERGE
281+
av_freep(&pkt);
282+
#else
283+
pkt->next = q->recycle_pkt;
284+
q->recycle_pkt = pkt;
285+
#endif
286+
}
287+
// q->last_pkt = NULL;
288+
// q->first_pkt = NULL;
289+
// q->nb_packets = 0;
290+
// q->size = 0;
291+
// q->duration = 0;
292+
SDL_UnlockMutex(q->mutex);
293+
}
294+
262295
static void packet_queue_destroy(PacketQueue *q)
263296
{
264297
packet_queue_flush(q);
@@ -5502,7 +5535,7 @@ void ffp_flush_player_cache(FFPlayer *ffp) {
55025535
}
55035536

55045537
if (is->video_stream >= 0) {
5505-
packet_queue_flush(&is->videoq);
5538+
packet_queue_flush_videocache(&is->videoq);
55065539
packet_queue_put(&is->videoq, &flush_pkt);
55075540
}
55085541
}

0 commit comments

Comments
 (0)