Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Marton Balint <cus@passwd.hu>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v2 3/4] decklink: Convert to using avpriv_packet_list functions
Date: Thu, 11 May 2023 23:34:32 +0200 (CEST)
Message-ID: <badda78e-1437-5f97-821-e386e1468639@passwd.hu> (raw)
In-Reply-To: <1682707254-27604-4-git-send-email-dheitmueller@ltnglobal.com>



On Fri, 28 Apr 2023, Devin Heitmueller 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.
>
> Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
> ---
> libavdevice/decklink_common.cpp | 45 +++++++++++------------------------------
> 1 file changed, 12 insertions(+), 33 deletions(-)
>
> diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
> index 74e26e9..af1b731 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;
> +    size_t pkt_size = pkt->size;

AVPacket->size is int so size_t is a bit strange here.

> +    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,26 +446,14 @@ 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;
> -    } else {
> -        q->pkt_list.tail->next = pkt1;
> +    ret = avpriv_packet_list_put(&q->pkt_list, pkt, NULL, 0);
> +    if (ret == 0) {
> +        q->nb_packets++;
> +        q->size += pkt_size + sizeof(AVPacket);
>     }

else av_packet_unref() to not leak packet data in case of failure?

>
> -    q->pkt_list.tail = pkt1;
> -    q->nb_packets++;
> -    q->size += pkt1->pkt.size + sizeof(*pkt1);
> -
>     pthread_cond_signal(&q->cond);

Maybe only cond_signal if avpriv_packet_list_put was successful?

>
>     pthread_mutex_unlock(&q->mutex);

You have to return the ret code, not 0 in the end of the function in 
order to propagate avpriv_packet_list_put failure.

> @@ -482,16 +467,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) {

Thanks,
Marton

> -- 
> 1.8.3.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2023-05-11 21:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 18:40 [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 1/4] decklink: Move AVPacketQueue into decklink_common Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 2/4] decklink: rename AVPacketQueue to DecklinkPacketQueue Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 3/4] decklink: Convert to using avpriv_packet_list functions Devin Heitmueller
2023-05-11 21:34   ` Marton Balint [this message]
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 4/4] decklink_enc: add support for SMPTE 2038 VANC packet output Devin Heitmueller
2023-06-06 18:56   ` Devin Heitmueller
2023-06-22 11:54     ` Devin Heitmueller
2023-06-26  7:07       ` Marton Balint
2023-05-11 14:36 ` [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
2023-05-11 21:18   ` Marton Balint
2023-05-11 21:26     ` Devin Heitmueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=badda78e-1437-5f97-821-e386e1468639@passwd.hu \
    --to=cus@passwd.hu \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git