Re: [FFmpeg-devel] [PATCH 7/8] avformat/movenc: add support for Immersive Audio Model and Formats in ISOBMFF

2024-02-20 Thread James Almer

On 2/20/2024 11:21 AM, Andreas Rheinhardt wrote:

James Almer:

On 2/20/2024 10:37 AM, Andreas Rheinhardt wrote:

@@ -7862,7 +8087,7 @@ static int avif_write_trailer(AVFormatContext *s)
     // write extent offsets.
   pos_backup = avio_tell(pb);
-    for (i = 0; i < s->nb_streams; i++) {
+    for (i = 0; i < mov->nb_streams; i++) {

Can you use loop-scope for all the iterators that you touch where
possible, please?


Can you elaborate?


Use "for (int i = 0;" when you already touch the line (where possible).

- Andreas


Done. Thanks.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 7/8] avformat/movenc: add support for Immersive Audio Model and Formats in ISOBMFF

2024-02-20 Thread Andreas Rheinhardt
James Almer:
> On 2/20/2024 10:37 AM, Andreas Rheinhardt wrote:
>>> @@ -7862,7 +8087,7 @@ static int avif_write_trailer(AVFormatContext *s)
>>>     // write extent offsets.
>>>   pos_backup = avio_tell(pb);
>>> -    for (i = 0; i < s->nb_streams; i++) {
>>> +    for (i = 0; i < mov->nb_streams; i++) {
>> Can you use loop-scope for all the iterators that you touch where
>> possible, please?
> 
> Can you elaborate?

Use "for (int i = 0;" when you already touch the line (where possible).

- Andreas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 7/8] avformat/movenc: add support for Immersive Audio Model and Formats in ISOBMFF

2024-02-20 Thread James Almer

On 2/20/2024 10:37 AM, Andreas Rheinhardt wrote:

@@ -7862,7 +8087,7 @@ static int avif_write_trailer(AVFormatContext *s)
  
  // write extent offsets.

  pos_backup = avio_tell(pb);
-for (i = 0; i < s->nb_streams; i++) {
+for (i = 0; i < mov->nb_streams; i++) {

Can you use loop-scope for all the iterators that you touch where
possible, please?


Can you elaborate?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 7/8] avformat/movenc: add support for Immersive Audio Model and Formats in ISOBMFF

2024-02-20 Thread Andreas Rheinhardt
James Almer:
> Signed-off-by: James Almer 
> ---
>  libavformat/movenc.c | 349 +++
>  libavformat/movenc.h |   6 +
>  2 files changed, 293 insertions(+), 62 deletions(-)
> 
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index c71a9983ed..cd63b353b8 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -32,6 +32,7 @@
>  #include "dovi_isom.h"
>  #include "riff.h"
>  #include "avio.h"
> +#include "iamf_writer.h"
>  #include "isom.h"
>  #include "av1.h"
>  #include "avc.h"
> @@ -41,12 +42,14 @@
>  #include "libavcodec/flac.h"
>  #include "libavcodec/get_bits.h"
>  
> +#include "libavcodec/bsf.h"
>  #include "libavcodec/internal.h"
>  #include "libavcodec/put_bits.h"
>  #include "libavcodec/vc1_common.h"
>  #include "libavcodec/raw.h"
>  #include "internal.h"
>  #include "libavutil/avstring.h"
> +#include "libavutil/bprint.h"
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/csp.h"
>  #include "libavutil/intfloat.h"
> @@ -316,6 +319,32 @@ static int mov_write_sdtp_tag(AVIOContext *pb, MOVTrack 
> *track)
>  return update_size(pb, pos);
>  }
>  
> +static int mov_write_iacb_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack 
> *track)
> +{
> +AVIOContext *dyn_bc;
> +int64_t pos = avio_tell(pb);
> +uint8_t *dyn_buf = NULL;
> +int dyn_size;
> +int ret = avio_open_dyn_buf(&dyn_bc);
> +if (ret < 0)
> +return ret;
> +
> +avio_wb32(pb, 0);
> +ffio_wfourcc(pb, "iacb");
> +avio_w8(pb, 1); // configurationVersion
> +
> +ret = ff_iamf_write_descriptors(track->iamf, dyn_bc, s);
> +if (ret < 0)
> +return ret;
> +
> +dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
> +ffio_write_leb(pb, dyn_size);
> +avio_write(pb, dyn_buf, dyn_size);
> +av_free(dyn_buf);
> +
> +return update_size(pb, pos);
> +}
> +
>  static int mov_write_amr_tag(AVIOContext *pb, MOVTrack *track)
>  {
>  avio_wb32(pb, 0x11); /* size */
> @@ -1358,6 +1387,8 @@ static int mov_write_audio_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
>  ret = mov_write_wave_tag(s, pb, track);
>  else if (track->tag == MKTAG('m','p','4','a'))
>  ret = mov_write_esds_tag(pb, track);
> +else if (track->tag == MKTAG('i','a','m','f'))
> +ret = mov_write_iacb_tag(mov->fc, pb, track);
>  else if (track->par->codec_id == AV_CODEC_ID_AMR_NB)
>  ret = mov_write_amr_tag(pb, track);
>  else if (track->par->codec_id == AV_CODEC_ID_AC3)
> @@ -2529,7 +2560,7 @@ static int mov_write_video_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
>  
>  if (track->mode == MODE_AVIF) {
>  mov_write_ccst_tag(pb);
> -if (s->nb_streams > 0 && track == &mov->tracks[1])
> +if (mov->nb_streams > 0 && track == &mov->tracks[1])
>  mov_write_aux_tag(pb, "auxi");
>  }
>  
> @@ -3124,9 +3155,9 @@ static int mov_write_iloc_tag(AVIOContext *pb, 
> MOVMuxContext *mov, AVFormatConte
>  avio_wb32(pb, 0); /* Version & flags */
>  avio_w8(pb, (4 << 4) + 4); /* offset_size(4) and length_size(4) */
>  avio_w8(pb, 0); /* base_offset_size(4) and reserved(4) */
> -avio_wb16(pb, s->nb_streams); /* item_count */
> +avio_wb16(pb, mov->nb_streams); /* item_count */
>  
> -for (int i = 0; i < s->nb_streams; i++) {
> +for (int i = 0; i < mov->nb_streams; i++) {
>  avio_wb16(pb, i + 1); /* item_id */
>  avio_wb16(pb, 0); /* data_reference_index */
>  avio_wb16(pb, 1); /* extent_count */
> @@ -3145,9 +3176,9 @@ static int mov_write_iinf_tag(AVIOContext *pb, 
> MOVMuxContext *mov, AVFormatConte
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "iinf");
>  avio_wb32(pb, 0); /* Version & flags */
> -avio_wb16(pb, s->nb_streams); /* entry_count */
> +avio_wb16(pb, mov->nb_streams); /* entry_count */
>  
> -for (int i = 0; i < s->nb_streams; i++) {
> +for (int i = 0; i < mov->nb_streams; i++) {
>  int64_t infe_pos = avio_tell(pb);
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "infe");
> @@ -3216,7 +3247,7 @@ static int mov_write_ipco_tag(AVIOContext *pb, 
> MOVMuxContext *mov, AVFormatConte
>  int64_t pos = avio_tell(pb);
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "ipco");
> -for (int i = 0; i < s->nb_streams; i++) {
> +for (int i = 0; i < mov->nb_streams; i++) {
>  mov_write_ispe_tag(pb, mov, s, i);
>  mov_write_pixi_tag(pb, mov, s, i);
>  mov_write_av1c_tag(pb, &mov->tracks[i]);
> @@ -3234,9 +3265,9 @@ static int mov_write_ipma_tag(AVIOContext *pb, 
> MOVMuxContext *mov, AVFormatConte
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "ipma");
>  avio_wb32(pb, 0); /* Version & flags */
> -avio_wb32(pb, s->nb_streams); /* entry_count */
> +avio_wb32(pb, mov->nb_streams); /* entry_count */
>  
> -for (int i = 0, index = 1; i < s->nb_streams; i++) {
> +for (int i = 0, ind

[FFmpeg-devel] [PATCH 7/8] avformat/movenc: add support for Immersive Audio Model and Formats in ISOBMFF

2024-02-17 Thread James Almer
Signed-off-by: James Almer 
---
 libavformat/movenc.c | 349 +++
 libavformat/movenc.h |   6 +
 2 files changed, 293 insertions(+), 62 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index c71a9983ed..cd63b353b8 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -32,6 +32,7 @@
 #include "dovi_isom.h"
 #include "riff.h"
 #include "avio.h"
+#include "iamf_writer.h"
 #include "isom.h"
 #include "av1.h"
 #include "avc.h"
@@ -41,12 +42,14 @@
 #include "libavcodec/flac.h"
 #include "libavcodec/get_bits.h"
 
+#include "libavcodec/bsf.h"
 #include "libavcodec/internal.h"
 #include "libavcodec/put_bits.h"
 #include "libavcodec/vc1_common.h"
 #include "libavcodec/raw.h"
 #include "internal.h"
 #include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/csp.h"
 #include "libavutil/intfloat.h"
@@ -316,6 +319,32 @@ static int mov_write_sdtp_tag(AVIOContext *pb, MOVTrack 
*track)
 return update_size(pb, pos);
 }
 
+static int mov_write_iacb_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack 
*track)
+{
+AVIOContext *dyn_bc;
+int64_t pos = avio_tell(pb);
+uint8_t *dyn_buf = NULL;
+int dyn_size;
+int ret = avio_open_dyn_buf(&dyn_bc);
+if (ret < 0)
+return ret;
+
+avio_wb32(pb, 0);
+ffio_wfourcc(pb, "iacb");
+avio_w8(pb, 1); // configurationVersion
+
+ret = ff_iamf_write_descriptors(track->iamf, dyn_bc, s);
+if (ret < 0)
+return ret;
+
+dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
+ffio_write_leb(pb, dyn_size);
+avio_write(pb, dyn_buf, dyn_size);
+av_free(dyn_buf);
+
+return update_size(pb, pos);
+}
+
 static int mov_write_amr_tag(AVIOContext *pb, MOVTrack *track)
 {
 avio_wb32(pb, 0x11); /* size */
@@ -1358,6 +1387,8 @@ static int mov_write_audio_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContex
 ret = mov_write_wave_tag(s, pb, track);
 else if (track->tag == MKTAG('m','p','4','a'))
 ret = mov_write_esds_tag(pb, track);
+else if (track->tag == MKTAG('i','a','m','f'))
+ret = mov_write_iacb_tag(mov->fc, pb, track);
 else if (track->par->codec_id == AV_CODEC_ID_AMR_NB)
 ret = mov_write_amr_tag(pb, track);
 else if (track->par->codec_id == AV_CODEC_ID_AC3)
@@ -2529,7 +2560,7 @@ static int mov_write_video_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContex
 
 if (track->mode == MODE_AVIF) {
 mov_write_ccst_tag(pb);
-if (s->nb_streams > 0 && track == &mov->tracks[1])
+if (mov->nb_streams > 0 && track == &mov->tracks[1])
 mov_write_aux_tag(pb, "auxi");
 }
 
@@ -3124,9 +3155,9 @@ static int mov_write_iloc_tag(AVIOContext *pb, 
MOVMuxContext *mov, AVFormatConte
 avio_wb32(pb, 0); /* Version & flags */
 avio_w8(pb, (4 << 4) + 4); /* offset_size(4) and length_size(4) */
 avio_w8(pb, 0); /* base_offset_size(4) and reserved(4) */
-avio_wb16(pb, s->nb_streams); /* item_count */
+avio_wb16(pb, mov->nb_streams); /* item_count */
 
-for (int i = 0; i < s->nb_streams; i++) {
+for (int i = 0; i < mov->nb_streams; i++) {
 avio_wb16(pb, i + 1); /* item_id */
 avio_wb16(pb, 0); /* data_reference_index */
 avio_wb16(pb, 1); /* extent_count */
@@ -3145,9 +3176,9 @@ static int mov_write_iinf_tag(AVIOContext *pb, 
MOVMuxContext *mov, AVFormatConte
 avio_wb32(pb, 0); /* size */
 ffio_wfourcc(pb, "iinf");
 avio_wb32(pb, 0); /* Version & flags */
-avio_wb16(pb, s->nb_streams); /* entry_count */
+avio_wb16(pb, mov->nb_streams); /* entry_count */
 
-for (int i = 0; i < s->nb_streams; i++) {
+for (int i = 0; i < mov->nb_streams; i++) {
 int64_t infe_pos = avio_tell(pb);
 avio_wb32(pb, 0); /* size */
 ffio_wfourcc(pb, "infe");
@@ -3216,7 +3247,7 @@ static int mov_write_ipco_tag(AVIOContext *pb, 
MOVMuxContext *mov, AVFormatConte
 int64_t pos = avio_tell(pb);
 avio_wb32(pb, 0); /* size */
 ffio_wfourcc(pb, "ipco");
-for (int i = 0; i < s->nb_streams; i++) {
+for (int i = 0; i < mov->nb_streams; i++) {
 mov_write_ispe_tag(pb, mov, s, i);
 mov_write_pixi_tag(pb, mov, s, i);
 mov_write_av1c_tag(pb, &mov->tracks[i]);
@@ -3234,9 +3265,9 @@ static int mov_write_ipma_tag(AVIOContext *pb, 
MOVMuxContext *mov, AVFormatConte
 avio_wb32(pb, 0); /* size */
 ffio_wfourcc(pb, "ipma");
 avio_wb32(pb, 0); /* Version & flags */
-avio_wb32(pb, s->nb_streams); /* entry_count */
+avio_wb32(pb, mov->nb_streams); /* entry_count */
 
-for (int i = 0, index = 1; i < s->nb_streams; i++) {
+for (int i = 0, index = 1; i < mov->nb_streams; i++) {
 avio_wb16(pb, i + 1); /* item_ID */
 avio_w8(pb, 4); /* association_count */
 
@@ -4213,7 +4244,7 @@ static int mov_write_covr(AVIOContext *pb, 
AVFormatContext *s)
 int64_t pos = 0;
 int i;
 
-for (i = 0; i < s->nb_