avformat/mov: add an offset to IAMF streams

Using audio_substream_id for AVStream ids is not ideal give that in containers
like mp4, the IAMF structure is opaque to the outside and other streams may
share such id values.

Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit a8f2374507)
This commit is contained in:
James Almer
2024-12-20 12:57:48 -03:00
parent f1cbd81e9e
commit 3157e62866
7 changed files with 59 additions and 31 deletions

View File

@@ -30,10 +30,10 @@
#include "iamf_parse.h"
#include "iamf_reader.h"
static AVStream *find_stream_by_id(AVFormatContext *s, int id)
static AVStream *find_stream_by_id(AVFormatContext *s, int id, int stream_id_offset)
{
for (int i = 0; i < s->nb_streams; i++)
if (s->streams[i]->id == id)
if (s->streams[i]->id == id + stream_id_offset)
return s->streams[i];
av_log(s, AV_LOG_ERROR, "Invalid stream id %d\n", id);
@@ -44,7 +44,7 @@ static int audio_frame_obu(AVFormatContext *s, const IAMFDemuxContext *c,
AVIOContext *pb, AVPacket *pkt,
int len, enum IAMF_OBU_Type type,
unsigned skip_samples, unsigned discard_padding,
int id_in_bitstream)
int stream_id_offset, int id_in_bitstream)
{
AVStream *st;
int ret, audio_substream_id;
@@ -58,7 +58,7 @@ static int audio_frame_obu(AVFormatContext *s, const IAMFDemuxContext *c,
} else
audio_substream_id = type - IAMF_OBU_IA_AUDIO_FRAME_ID0;
st = find_stream_by_id(s, audio_substream_id);
st = find_stream_by_id(s, audio_substream_id, stream_id_offset);
if (!st)
return AVERROR_INVALIDDATA;
@@ -276,7 +276,7 @@ fail:
}
int ff_iamf_read_packet(AVFormatContext *s, IAMFDemuxContext *c,
AVIOContext *pb, int max_size, AVPacket *pkt)
AVIOContext *pb, int max_size, int stream_id_offset, AVPacket *pkt)
{
int read = 0;
@@ -306,7 +306,7 @@ int ff_iamf_read_packet(AVFormatContext *s, IAMFDemuxContext *c,
read += len;
if (type >= IAMF_OBU_IA_AUDIO_FRAME && type <= IAMF_OBU_IA_AUDIO_FRAME_ID17) {
ret = audio_frame_obu(s, c, pb, pkt, obu_size, type,
skip_samples, discard_padding,
skip_samples, discard_padding, stream_id_offset,
type == IAMF_OBU_IA_AUDIO_FRAME);
if (ret < 0)
return ret;