From: Marton Balint <cus@passwd.hu> To: ffmpeg-devel@ffmpeg.org Cc: Marton Balint <cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 4/5] avformat/mov: factorize reading the main part of the chnl atom to mov_chan Date: Mon, 12 Feb 2024 22:15:36 +0100 Message-ID: <20240212211537.18468-4-cus@passwd.hu> (raw) In-Reply-To: <20240212211537.18468-1-cus@passwd.hu> Signed-off-by: Marton Balint <cus@passwd.hu> --- libavformat/mov.c | 58 +++-------------------------------------- libavformat/mov_chan.c | 59 ++++++++++++++++++++++++++++++++++++++++++ libavformat/mov_chan.h | 10 +++++++ 3 files changed, 73 insertions(+), 54 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 42b0135987..52436d71d6 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -953,9 +953,8 @@ static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_chnl(MOVContext *c, AVIOContext *pb, MOVAtom atom) { int64_t end = av_sat_add64(avio_tell(pb), atom.size); - int stream_structure; int version, flags; - int ret = 0; + int ret; AVStream *st; if (c->fc->nb_streams < 1) @@ -971,58 +970,9 @@ static int mov_read_chnl(MOVContext *c, AVIOContext *pb, MOVAtom atom) return AVERROR_INVALIDDATA; } - stream_structure = avio_r8(pb); - - // stream carries channels - if (stream_structure & 1) { - int layout = avio_r8(pb); - - av_log(c->fc, AV_LOG_TRACE, "'chnl' layout %d\n", layout); - if (!layout) { - uint8_t *positions = av_malloc(st->codecpar->ch_layout.nb_channels); - - if (!positions) - return AVERROR(ENOMEM); - for (int i = 0; i < st->codecpar->ch_layout.nb_channels; i++) { - int speaker_pos = avio_r8(pb); - - av_log(c->fc, AV_LOG_TRACE, "speaker_position %d\n", speaker_pos); - if (speaker_pos == 126) { // explicit position - avpriv_request_sample(c->fc, "explicit position"); - av_freep(&positions); - return AVERROR_PATCHWELCOME; - } else { - positions[i] = speaker_pos; - } - } - - ret = ff_mov_get_layout_from_channel_positions(positions, - st->codecpar->ch_layout.nb_channels, - &st->codecpar->ch_layout); - av_freep(&positions); - if (ret) { - av_log(c->fc, AV_LOG_ERROR, - "get channel layout from speaker positions failed, %s\n", - av_err2str(ret)); - return ret; - } - } else { - uint64_t omitted_channel_map = avio_rb64(pb); - - if (omitted_channel_map) { - avpriv_request_sample(c->fc, "omitted_channel_map 0x%" PRIx64 " != 0", - omitted_channel_map); - return AVERROR_PATCHWELCOME; - } - ff_mov_get_channel_layout_from_config(layout, &st->codecpar->ch_layout); - } - } - - // stream carries objects - if (stream_structure & 2) { - int obj_count = avio_r8(pb); - av_log(c->fc, AV_LOG_TRACE, "'chnl' with object_count %d\n", obj_count); - } + ret = ff_mov_read_chnl(c->fc, pb, st); + if (ret < 0) + return ret; if (avio_tell(pb) != end) { av_log(c->fc, AV_LOG_WARNING, "skip %" PRId64 " bytes of unknown data inside chnl\n", diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 79768bc210..cce9d7a697 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -863,3 +863,62 @@ error: av_channel_layout_uninit(layout); return ret; } + +int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb, AVStream *st) +{ + int stream_structure = avio_r8(pb); + int ret; + + // stream carries channels + if (stream_structure & 1) { + int layout = avio_r8(pb); + + av_log(s, AV_LOG_TRACE, "'chnl' layout %d\n", layout); + if (!layout) { + uint8_t *positions = av_malloc(st->codecpar->ch_layout.nb_channels); + + if (!positions) + return AVERROR(ENOMEM); + for (int i = 0; i < st->codecpar->ch_layout.nb_channels; i++) { + int speaker_pos = avio_r8(pb); + + av_log(s, AV_LOG_TRACE, "speaker_position %d\n", speaker_pos); + if (speaker_pos == 126) { // explicit position + avpriv_request_sample(s, "explicit position"); + av_freep(&positions); + return AVERROR_PATCHWELCOME; + } else { + positions[i] = speaker_pos; + } + } + + ret = ff_mov_get_layout_from_channel_positions(positions, + st->codecpar->ch_layout.nb_channels, + &st->codecpar->ch_layout); + av_freep(&positions); + if (ret) { + av_log(s, AV_LOG_ERROR, + "get channel layout from speaker positions failed, %s\n", + av_err2str(ret)); + return ret; + } + } else { + uint64_t omitted_channel_map = avio_rb64(pb); + + if (omitted_channel_map) { + avpriv_request_sample(s, "omitted_channel_map 0x%" PRIx64 " != 0", + omitted_channel_map); + return AVERROR_PATCHWELCOME; + } + ff_mov_get_channel_layout_from_config(layout, &st->codecpar->ch_layout); + } + } + + // stream carries objects + if (stream_structure & 2) { + int obj_count = avio_r8(pb); + av_log(s, AV_LOG_TRACE, "'chnl' with object_count %d\n", obj_count); + } + + return 0; +} diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h index 8c807798ab..b7d435b99f 100644 --- a/libavformat/mov_chan.h +++ b/libavformat/mov_chan.h @@ -189,4 +189,14 @@ int ff_mov_get_channel_positions_from_layout(const AVChannelLayout *layout, int ff_mov_get_layout_from_channel_positions(const uint8_t *position, int position_num, AVChannelLayout *layout); +/** + * Read 'chnl' tag from the input stream. + * + * @param s AVFormatContext + * @param pb AVIOContext + * @param st The stream to set codec values for + * @return 0 if ok, or negative AVERROR code on failure + */ +int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb, AVStream *st); + #endif /* AVFORMAT_MOV_CHAN_H */ -- 2.35.3 _______________________________________________ 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".
next prev parent reply other threads:[~2024-02-12 21:16 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-12 21:15 [FFmpeg-devel] [PATCH 1/5] avutil/channel_layout: change AV_CHAN_SILENCE to AV_CHAN_UNUSED in the docs Marton Balint 2024-02-12 21:15 ` [FFmpeg-devel] [PATCH 2/5] avutil/channel_layout: add AV_CHANNEL_ORDER_NB Marton Balint 2024-02-13 17:25 ` James Almer 2024-02-13 20:27 ` Marton Balint 2024-02-15 14:51 ` Anton Khirnov 2024-02-16 22:42 ` Marton Balint 2024-02-16 22:44 ` James Almer 2024-02-17 23:15 ` Marton Balint 2024-02-12 21:15 ` [FFmpeg-devel] [PATCH 3/5] avutil/tests/channel_layout: add tests for av_channel_order_retype Marton Balint 2024-02-13 17:39 ` [FFmpeg-devel] [PATCH] avutil/channel_layout: print known layout names in custom layout James Almer 2024-02-18 12:58 ` James Almer 2024-02-12 21:15 ` Marton Balint [this message] 2024-02-12 21:15 ` [FFmpeg-devel] [PATCH 5/5] avformat/mov: rework ff_mov_read_chnl Marton Balint 2024-02-15 14:52 ` Anton Khirnov 2024-02-15 21:12 ` Marton Balint 2024-02-12 22:09 ` [FFmpeg-devel] [PATCH 1/5] avutil/channel_layout: change AV_CHAN_SILENCE to AV_CHAN_UNUSED in the docs 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=20240212211537.18468-4-cus@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