Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 06/11] avformat/hevc: use a single array for per-PS NALUs
Date: Wed,  3 Jul 2024 18:26:41 -0300
Message-ID: <20240703212648.48483-6-jamrial@gmail.com> (raw)
In-Reply-To: <20240703212648.48483-1-jamrial@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/hevc.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index 40f46668f9..6fe701032b 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -40,15 +40,20 @@ enum {
     NB_ARRAYS
 };
 
+
 #define FLAG_ARRAY_COMPLETENESS (1 << 0)
 #define FLAG_IS_NALFF           (1 << 1)
 
+typedef struct HVCCNALUnit {
+    uint16_t nalUnitLength;
+    const uint8_t *nalUnit;
+} HVCCNALUnit;
+
 typedef struct HVCCNALUnitArray {
     uint8_t  array_completeness;
     uint8_t  NAL_unit_type;
     uint16_t numNalus;
-    uint16_t *nalUnitLength;
-    const uint8_t **nalUnit;
+    HVCCNALUnit *nal;
 } HVCCNALUnitArray;
 
 typedef struct HEVCDecoderConfigurationRecord {
@@ -674,19 +679,17 @@ static void nal_unit_parse_header(GetBitContext *gb, uint8_t *nal_type,
 static int hvcc_array_add_nal_unit(const uint8_t *nal_buf, uint32_t nal_size,
                                    HVCCNALUnitArray *array)
 {
+    HVCCNALUnit *nal;
     int ret;
     uint16_t numNalus = array->numNalus;
 
-    ret = av_reallocp_array(&array->nalUnit, numNalus + 1, sizeof(uint8_t*));
-    if (ret < 0)
-        return ret;
-
-    ret = av_reallocp_array(&array->nalUnitLength, numNalus + 1, sizeof(uint16_t));
+    ret = av_reallocp_array(&array->nal, numNalus + 1, sizeof(*array->nal));
     if (ret < 0)
         return ret;
 
-    array->nalUnit      [numNalus] = nal_buf;
-    array->nalUnitLength[numNalus] = nal_size;
+    nal = &array->nal[numNalus];
+    nal->nalUnit       = nal_buf;
+    nal->nalUnitLength = nal_size;
     array->numNalus++;
 
     return 0;
@@ -785,8 +788,7 @@ static void hvcc_close(HEVCDecoderConfigurationRecord *hvcc)
     for (unsigned i = 0; i < FF_ARRAY_ELEMS(hvcc->arrays); i++) {
         HVCCNALUnitArray *const array = &hvcc->arrays[i];
         array->numNalus = 0;
-        av_freep(&array->nalUnit);
-        av_freep(&array->nalUnitLength);
+        av_freep(&array->nal);
     }
 }
 
@@ -871,7 +873,7 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc)
         for (unsigned k = 0; k < array->numNalus; k++)
             av_log(NULL, AV_LOG_TRACE,
                     "nalUnitLength[%u][%u]:                 %"PRIu16"\n",
-                   j, k, array->nalUnitLength[k]);
+                   j, k, array->nal[k].nalUnitLength);
         j++;
     }
 
@@ -972,12 +974,13 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc)
         avio_wb16(pb, array->numNalus);
 
         for (unsigned j = 0; j < array->numNalus; j++) {
+            HVCCNALUnit *nal = &array->nal[j];
+
             /* unsigned int(16) nalUnitLength; */
-            avio_wb16(pb, array->nalUnitLength[j]);
+            avio_wb16(pb, nal->nalUnitLength);
 
             /* bit(8*nalUnitLength) nalUnit; */
-            avio_write(pb, array->nalUnit[j],
-                       array->nalUnitLength[j]);
+            avio_write(pb, nal->nalUnit, nal->nalUnitLength);
         }
     }
 
-- 
2.45.2

_______________________________________________
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".

  parent reply	other threads:[~2024-07-03 21:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-03 21:26 [FFmpeg-devel] [PATCH 01/11] avformat/mov: add support for lhvC box parsing James Almer
2024-07-03 21:26 ` [FFmpeg-devel] [PATCH 02/11] avformat: Add a new stream disposition for multilayer video James Almer
2024-07-03 21:26 ` [FFmpeg-devel] [PATCH 03/11] avformat/mov: Mark streams with a layered HEVC box as multilayer James Almer
2024-07-03 21:26 ` [FFmpeg-devel] [PATCH 04/11] avformat/hevc: don't write NALUs with nuh_layer_id > 0 in hvcC boxes James Almer
2024-07-07 15:46   ` Andreas Rheinhardt
2024-07-07 16:09     ` James Almer
2024-07-03 21:26 ` [FFmpeg-devel] [PATCH 05/11] avformat/hevc: don't write the same array values per nal addition James Almer
2024-07-03 21:26 ` James Almer [this message]
2024-07-03 21:26 ` [FFmpeg-devel] [PATCH 07/11] avformat/hevc: store parameter set and layer IDs in HVCCNALUnit James Almer
2024-07-03 21:26 ` [FFmpeg-devel] [PATCH 08/11] avformat/hevc: add a function to write a lhvC box James Almer
2024-07-03 21:26 ` [FFmpeg-devel] [PATCH 09/11] avformat/movenc: add support for writing lhvC boxes James Almer
2024-07-03 21:26 ` [FFmpeg-devel] [PATCH 10/11] avformat/movenc: add support for writting vexu boxes James Almer
2024-07-03 21:26 ` [FFmpeg-devel] [PATCH 11/11] avformat/movenc: add support for writting hfov boxes James Almer
2024-07-07 15:21 ` [FFmpeg-devel] [PATCH 01/11] avformat/mov: add support for lhvC box parsing James Almer
2024-07-07 15:43 ` Andreas Rheinhardt
2024-07-07 16:18   ` James Almer

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=20240703212648.48483-6-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --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