History

avcodec/packet_internal: Add proper PacketList struct

Up until now, we had a PacketList structure which is actually a PacketListEntry; a proper PacketList did not exist and all the related functions just passed pointers to pointers to the head and tail elements around. All these pointers were actually consecutive elements of their containing structs, i.e. the users already treated them as if they were a struct. So add a proper PacketList struct and rename the current PacketList to PacketListEntry; also make the functions use this structure instead of the pair of pointers.

Andreas Rheinhardt committed 4 years ago

Commit d61240f1 parent b74e47c20 files · +153 −175Browse files

Showing the changes to libavdevice/decklink_dec.cpp (1 of 20 files). Show all

Unified · Split

libavdevice/decklink_dec.cpp+14−15
@@ -483,16 +483,16 @@ static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q) · 482 unmodified lines
483 483
484static void avpacket_queue_flush(AVPacketQueue *q)484static void avpacket_queue_flush(AVPacketQueue *q)
485{485{
486 PacketList *pkt, *pkt1;486 PacketListEntry *pkt, *pkt1;
487 487
488 pthread_mutex_lock(&q->mutex);488 pthread_mutex_lock(&q->mutex);
489 for (pkt = q->first_pkt; pkt != NULL; pkt = pkt1) {489 for (pkt = q->pkt_list.head; pkt != NULL; pkt = pkt1) {
490 pkt1 = pkt->next;490 pkt1 = pkt->next;
491 av_packet_unref(&pkt->pkt);491 av_packet_unref(&pkt->pkt);
492 av_freep(&pkt);492 av_freep(&pkt);
493 }493 }
494 q->last_pkt = NULL;494 q->pkt_list.head = NULL;
495 q->first_pkt = NULL;495 q->pkt_list.tail = NULL;
496 q->nb_packets = 0;496 q->nb_packets = 0;
497 q->size = 0;497 q->size = 0;
498 pthread_mutex_unlock(&q->mutex);498 pthread_mutex_unlock(&q->mutex);
@@ -516,7 +516,7 @@ static unsigned long long avpacket_queue_size(AVPacketQueue *q) · 17 unmodified lines
516 516
517static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)517static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
518{518{
519 PacketList *pkt1;519 PacketListEntry *pkt1;
520 520
521 // Drop Packet if queue size is > maximum queue size521 // Drop Packet if queue size is > maximum queue size
522 if (avpacket_queue_size(q) > (uint64_t)q->max_q_size) {522 if (avpacket_queue_size(q) > (uint64_t)q->max_q_size) {
@@ -530,7 +530,7 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) · 7 unmodified lines
530 return -1;530 return -1;
531 }531 }
532 532
533 pkt1 = (PacketList *)av_malloc(sizeof(PacketList));533 pkt1 = (PacketListEntry *)av_malloc(sizeof(*pkt1));
534 if (!pkt1) {534 if (!pkt1) {
535 av_packet_unref(pkt);535 av_packet_unref(pkt);
536 return -1;536 return -1;
@@ -540,13 +540,13 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) · 3 unmodified lines
540 540
541 pthread_mutex_lock(&q->mutex);541 pthread_mutex_lock(&q->mutex);
542 542
543 if (!q->last_pkt) {543 if (!q->pkt_list.tail) {
544 q->first_pkt = pkt1;544 q->pkt_list.head = pkt1;
545 } else {545 } else {
546 q->last_pkt->next = pkt1;546 q->pkt_list.tail->next = pkt1;
547 }547 }
548 548
549 q->last_pkt = pkt1;549 q->pkt_list.tail = pkt1;
550 q->nb_packets++;550 q->nb_packets++;
551 q->size += pkt1->pkt.size + sizeof(*pkt1);551 q->size += pkt1->pkt.size + sizeof(*pkt1);
552 552
@@ -558,17 +558,16 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) · 5 unmodified lines
558 558
559static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block)559static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block)
560{560{
561 PacketList *pkt1;
562 int ret;561 int ret;
563 562
564 pthread_mutex_lock(&q->mutex);563 pthread_mutex_lock(&q->mutex);
565 564
566 for (;; ) {565 for (;; ) {
567 pkt1 = q->first_pkt;566 PacketListEntry *pkt1 = q->pkt_list.head;
568 if (pkt1) {567 if (pkt1) {
569 q->first_pkt = pkt1->next;568 q->pkt_list.head = pkt1->next;
570 if (!q->first_pkt) {569 if (!q->pkt_list.head) {
571 q->last_pkt = NULL;570 q->pkt_list.tail = NULL;
572 }571 }
573 q->nb_packets--;572 q->nb_packets--;
574 q->size -= pkt1->pkt.size + sizeof(*pkt1);573 q->size -= pkt1->pkt.size + sizeof(*pkt1);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t