diff mbox series

[FFmpeg-devel,v3] decklink: Convert to using avpriv_packet_list functions

Message ID 1683907497-31677-1-git-send-email-dheitmueller@ltnglobal.com
State Accepted
Commit 859c34706d341f6b30f8e4993027657bf987765d
Headers show
Series [FFmpeg-devel,v3] decklink: Convert to using avpriv_packet_list functions | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Devin Heitmueller May 12, 2023, 4:04 p.m. UTC
The existing DecklinkQueue implementation was using the PacketList
structure but wasn't using the standard avpriv_packet_list_get and
avpriv_packet_list_put functions.  Convert to using them so we
eliminate the duplicate logic, per Marton Balint's suggestion.

Updated to reflect feedback from Marton Balint provided on 05/11/23.

Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
---
 libavdevice/decklink_common.cpp | 50 +++++++++++++----------------------------
 1 file changed, 15 insertions(+), 35 deletions(-)

Comments

Devin Heitmueller May 27, 2023, 3:18 p.m. UTC | #1
Hello Marton,

On Fri, May 12, 2023 at 11:09 AM Devin Heitmueller
<devin.heitmueller@ltnglobal.com> wrote:
>
> The existing DecklinkQueue implementation was using the PacketList
> structure but wasn't using the standard avpriv_packet_list_get and
> avpriv_packet_list_put functions.  Convert to using them so we
> eliminate the duplicate logic, per Marton Balint's suggestion.
>
> Updated to reflect feedback from Marton Balint provided on 05/11/23.
>
> Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>

I believe this version of the patch incorporates the changes you
requested.  Did you have any further comments before it can be merged?

Thanks,

Devin
Marton Balint May 30, 2023, 10:23 p.m. UTC | #2
On Sat, 27 May 2023, Devin Heitmueller wrote:

> Hello Marton,
>
> On Fri, May 12, 2023 at 11:09 AM Devin Heitmueller
> <devin.heitmueller@ltnglobal.com> wrote:
>>
>> The existing DecklinkQueue implementation was using the PacketList
>> structure but wasn't using the standard avpriv_packet_list_get and
>> avpriv_packet_list_put functions.  Convert to using them so we
>> eliminate the duplicate logic, per Marton Balint's suggestion.
>>
>> Updated to reflect feedback from Marton Balint provided on 05/11/23.
>>
>> Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
>
> I believe this version of the patch incorporates the changes you
> requested.  Did you have any further comments before it can be merged?
>

Will apply, thanks.

Marton
diff mbox series

Patch

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 74e26e9..b6cc8d7 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -402,16 +402,12 @@  void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *
 
 void ff_decklink_packet_queue_flush(DecklinkPacketQueue *q)
 {
-    PacketListEntry *pkt, *pkt1;
+    AVPacket pkt;
 
     pthread_mutex_lock(&q->mutex);
-    for (pkt = q->pkt_list.head; pkt != NULL; pkt = pkt1) {
-        pkt1 = pkt->next;
-        av_packet_unref(&pkt->pkt);
-        av_freep(&pkt);
+    while (avpriv_packet_list_get(&q->pkt_list, &pkt) == 0) {
+        av_packet_unref(&pkt);
     }
-    q->pkt_list.head = NULL;
-    q->pkt_list.tail = NULL;
     q->nb_packets = 0;
     q->size       = 0;
     pthread_mutex_unlock(&q->mutex);
@@ -435,7 +431,8 @@  unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q)
 
 int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt)
 {
-    PacketListEntry *pkt1;
+    int pkt_size = pkt->size;
+    int ret;
 
     // Drop Packet if queue size is > maximum queue size
     if (ff_decklink_packet_queue_size(q) > (uint64_t)q->max_q_size) {
@@ -449,30 +446,19 @@  int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt)
         return -1;
     }
 
-    pkt1 = (PacketListEntry *)av_malloc(sizeof(*pkt1));
-    if (!pkt1) {
-        av_packet_unref(pkt);
-        return -1;
-    }
-    av_packet_move_ref(&pkt1->pkt, pkt);
-    pkt1->next = NULL;
-
     pthread_mutex_lock(&q->mutex);
 
-    if (!q->pkt_list.tail) {
-        q->pkt_list.head = pkt1;
+    ret = avpriv_packet_list_put(&q->pkt_list, pkt, NULL, 0);
+    if (ret == 0) {
+        q->nb_packets++;
+        q->size += pkt_size + sizeof(AVPacket);
+        pthread_cond_signal(&q->cond);
     } else {
-        q->pkt_list.tail->next = pkt1;
+        av_packet_unref(pkt);
     }
 
-    q->pkt_list.tail = pkt1;
-    q->nb_packets++;
-    q->size += pkt1->pkt.size + sizeof(*pkt1);
-
-    pthread_cond_signal(&q->cond);
-
     pthread_mutex_unlock(&q->mutex);
-    return 0;
+    return ret;
 }
 
 int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int block)
@@ -482,16 +468,10 @@  int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int bloc
     pthread_mutex_lock(&q->mutex);
 
     for (;; ) {
-        PacketListEntry *pkt1 = q->pkt_list.head;
-        if (pkt1) {
-            q->pkt_list.head = pkt1->next;
-            if (!q->pkt_list.head) {
-                q->pkt_list.tail = NULL;
-            }
+        ret = avpriv_packet_list_get(&q->pkt_list, pkt);
+        if (ret == 0) {
             q->nb_packets--;
-            q->size -= pkt1->pkt.size + sizeof(*pkt1);
-            *pkt     = pkt1->pkt;
-            av_free(pkt1);
+            q->size -= pkt->size + sizeof(AVPacket);
             ret = 1;
             break;
         } else if (!block) {