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
483483
484484 static void avpacket_queue_flush(AVPacketQueue *q)
485485 {
486− PacketList *pkt, *pkt1;
486+ PacketListEntry *pkt, *pkt1;
487487
488488 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) {
490490 pkt1 = pkt->next;
491491 av_packet_unref(&pkt->pkt);
492492 av_freep(&pkt);
493493 }
494− q->last_pkt = NULL;
495− q->first_pkt = NULL;
494+ q->pkt_list.head = NULL;
495+ q->pkt_list.tail = NULL;
496496 q->nb_packets = 0;
497497 q->size = 0;
498498 pthread_mutex_unlock(&q->mutex);
@@ -516,7 +516,7 @@ static unsigned long long avpacket_queue_size(AVPacketQueue *q) · 17 unmodified lines
516516
517517 static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
518518 {
519− PacketList *pkt1;
519+ PacketListEntry *pkt1;
520520
521521 // Drop Packet if queue size is > maximum queue size
522522 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
530530 return -1;
531531 }
532532
533− pkt1 = (PacketList *)av_malloc(sizeof(PacketList));
533+ pkt1 = (PacketListEntry *)av_malloc(sizeof(*pkt1));
534534 if (!pkt1) {
535535 av_packet_unref(pkt);
536536 return -1;
@@ -540,13 +540,13 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) · 3 unmodified lines
540540
541541 pthread_mutex_lock(&q->mutex);
542542
543− if (!q->last_pkt) {
544− q->first_pkt = pkt1;
543+ if (!q->pkt_list.tail) {
544+ q->pkt_list.head = pkt1;
545545 } else {
546− q->last_pkt->next = pkt1;
546+ q->pkt_list.tail->next = pkt1;
547547 }
548548
549− q->last_pkt = pkt1;
549+ q->pkt_list.tail = pkt1;
550550 q->nb_packets++;
551551 q->size += pkt1->pkt.size + sizeof(*pkt1);
552552
@@ -558,17 +558,16 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) · 5 unmodified lines
558558
559559 static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block)
560560 {
561− PacketList *pkt1;
562561 int ret;
563562
564563 pthread_mutex_lock(&q->mutex);
565564
566565 for (;; ) {
567− pkt1 = q->first_pkt;
566+ PacketListEntry *pkt1 = q->pkt_list.head;
568567 if (pkt1) {
569− q->first_pkt = pkt1->next;
570− if (!q->first_pkt) {
571− q->last_pkt = NULL;
568+ q->pkt_list.head = pkt1->next;
569+ if (!q->pkt_list.head) {
570+ q->pkt_list.tail = NULL;
572571 }
573572 q->nb_packets--;
574573 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