From: Nicolas Gaullier <nicolas.gaullier@cji.paris> To: ffmpeg-devel@ffmpeg.org Cc: Nicolas Gaullier <nicolas.gaullier@cji.paris> Subject: [FFmpeg-devel] [PATCH 1/6] avformat/s337m: Split read_packet/get_packet Date: Mon, 13 Feb 2023 19:09:31 +0100 Message-ID: <20230213180936.815-2-nicolas.gaullier@cji.paris> (raw) In-Reply-To: <20230213180936.815-1-nicolas.gaullier@cji.paris> Prepare use of s337m_get_packet from outside. --- libavformat/s337m.c | 24 ++++++++++++++++++++---- libavformat/s337m.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 libavformat/s337m.h diff --git a/libavformat/s337m.c b/libavformat/s337m.c index 6fecfeffae..582c8b3670 100644 --- a/libavformat/s337m.c +++ b/libavformat/s337m.c @@ -22,6 +22,7 @@ #include "avformat.h" #include "internal.h" #include "spdif.h" +#include "s337m.h" #define MARKER_16LE 0x72F81F4E #define MARKER_20LE 0x20876FF0E154 @@ -142,17 +143,20 @@ static void bswap_buf24(uint8_t *data, int size) FFSWAP(uint8_t, data[0], data[2]); } -static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) +int ff_s337m_get_packet(AVIOContext *pb, AVPacket *pkt, int size, enum AVCodecID *codec, void *avc) { - AVIOContext *pb = s->pb; uint64_t state = 0; int ret, data_type, data_size, offset; - enum AVCodecID codec; + int64_t orig_pos = avio_tell(pb); while (!IS_LE_MARKER(state)) { state = (state << 8) | avio_r8(pb); if (avio_feof(pb)) return AVERROR_EOF; + if (avio_tell(pb) - orig_pos + 6 >= size) { + av_log(avc, AV_LOG_ERROR, "s337m : sync bytes not found at packet pos=0x%"PRIx64" size=%d\n", orig_pos, size); + return AVERROR_INVALIDDATA; + } } if (IS_16LE_MARKER(state)) { @@ -163,8 +167,9 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) data_size = avio_rl24(pb); } - if ((ret = s337m_get_offset_and_codec(s, state, data_type, data_size, &offset, &codec)) < 0) + if ((ret = s337m_get_offset_and_codec(avc, state, data_type, data_size, &offset, codec)) < 0) return ret; + offset = FFMIN(offset, size - (avio_tell(pb) - orig_pos)); if ((ret = av_get_packet(pb, pkt, offset)) != offset) return ret < 0 ? ret : AVERROR_EOF; @@ -174,6 +179,17 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) else bswap_buf24(pkt->data, pkt->size); + return 0; +} + +static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + enum AVCodecID codec; + int ret; + + if ((ret = ff_s337m_get_packet(s->pb, pkt, avio_size(s->pb), &codec, s)) < 0) + return ret; + if (!s->nb_streams) { AVStream *st = avformat_new_stream(s, NULL); if (!st) { diff --git a/libavformat/s337m.h b/libavformat/s337m.h new file mode 100644 index 0000000000..f7bd0c16f6 --- /dev/null +++ b/libavformat/s337m.h @@ -0,0 +1,37 @@ +/* + * SMPTE ST 337 common header + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFORMAT_S337M_H +#define AVFORMAT_S337M_H + +/** + * Read s337m packets in a PCM_S16LE/S24LE stereo stream + * Returns the first inner packet found + * Note that it does not require a clean guard band + * @param pb Associated IO context + * @param pkt On success, returns a DOLBY E packet + * @param size Maximum IO read size available for reading at current position + * @param codec Returns AV_CODEC_ID_DOLBY_E + * @param avc For av_log + * @return = 0 on success (an error is raised if no s337m was found) + */ +int ff_s337m_get_packet(AVIOContext *pb, AVPacket *pkt, int size, enum AVCodecID *codec, void *avc); + +#endif /* AVFORMAT_S337M_H */ -- 2.30.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".
next prev parent reply other threads:[~2023-02-13 18:09 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-13 18:09 [FFmpeg-devel] [PATCH 0/6] wavdev: s337m support Nicolas Gaullier 2023-02-13 18:09 ` Nicolas Gaullier [this message] 2023-02-16 10:36 ` [FFmpeg-devel] [PATCH 1/6] avformat/s337m: Split read_packet/get_packet Tomas Härdin 2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 2/6] avformat/s337m: Consider container bit resolution Nicolas Gaullier 2023-02-16 10:36 ` Tomas Härdin 2023-02-17 9:44 ` Nicolas Gaullier 2023-02-21 9:47 ` Tomas Härdin 2023-02-21 10:43 ` Nicolas Gaullier 2023-02-22 10:07 ` Tomas Härdin 2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 3/6] avformat/s337m: New ff_s337m_probe() Nicolas Gaullier 2023-02-16 10:36 ` Tomas Härdin 2023-02-17 10:12 ` Nicolas Gaullier 2023-02-21 9:41 ` Tomas Härdin 2023-02-21 10:57 ` Nicolas Gaullier 2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 4/6] avformat/wavdec: s337m support Nicolas Gaullier 2023-02-16 10:36 ` Tomas Härdin 2023-02-17 10:30 ` Nicolas Gaullier 2023-02-21 9:53 ` Tomas Härdin 2023-02-21 12:30 ` Nicolas Gaullier 2023-02-22 10:10 ` Tomas Härdin 2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 5/6] avformat/wavdec.c: Reindent after last commit Nicolas Gaullier 2023-02-13 18:09 ` [FFmpeg-devel] [PATCH 6/6] avformat/wavdec: Test s337m Nicolas Gaullier
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=20230213180936.815-2-nicolas.gaullier@cji.paris \ --to=nicolas.gaullier@cji.paris \ --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