Prepare use of s337m_get_packet from outside. --- libavformat/s337m.c | 28 +++++++++++++++++++++------- libavformat/s337m.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 libavformat/s337m.h
diff --git a/libavformat/s337m.c b/libavformat/s337m.c index 8956afb23f..eb26952834 100644 --- a/libavformat/s337m.c +++ b/libavformat/s337m.c @@ -21,6 +21,7 @@ #include "libavutil/intreadwrite.h" #include "avformat.h" #include "spdif.h" +#include "s337m.h" #define MARKER_16LE 0x72F81F4E #define MARKER_20LE 0x20876FF0E154 @@ -141,18 +142,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 pos; + int64_t pos, 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)) { @@ -165,10 +168,10 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) pos = avio_tell(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; - if ((ret = av_new_packet(pkt, offset)) < 0) + if (ret = av_new_packet(pkt, FFMIN(offset, size - (pos - orig_pos))) < 0) return ret; pkt->pos = pos; @@ -183,6 +186,17 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) else bswap_buf24(pkt->data, pkt->size); + return 0; +} + +int ff_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) { @@ -201,6 +215,6 @@ AVInputFormat ff_s337m_demuxer = { .long_name = NULL_IF_CONFIG_SMALL("SMPTE 337M"), .read_probe = s337m_probe, .read_header = s337m_read_header, - .read_packet = s337m_read_packet, + .read_packet = ff_s337m_read_packet, .flags = AVFMT_GENERIC_INDEX, }; diff --git a/libavformat/s337m.h b/libavformat/s337m.h new file mode 100644 index 0000000000..86d2da6f57 --- /dev/null +++ b/libavformat/s337m.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2017 foo86 + * + * 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); + +int ff_s337m_read_packet(AVFormatContext *s, AVPacket *pkt); +#endif /* AVFORMAT_S337M_H */ -- 2.14.1.windows.1 _______________________________________________ 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".