[FFmpeg-devel] [PATCH v3] avformat/mpegts: reduce buffering during initialization
Michael Niedermayer
michael at niedermayer.cc
Thu Mar 7 22:08:24 EET 2019
On Wed, Mar 06, 2019 at 10:15:36PM -0500, Andriy Gelman wrote:
> From: Andriy Gelman <andriy.gelman at gmail.com>
>
> Reduces buffering latency with low bitrate streams, where
> 8192 bytes can mean several seconds.
> ---
> libavformat/mpegts.c | 60 +++++++++++++++++++++++++++-----------------
> 1 file changed, 37 insertions(+), 23 deletions(-)
>
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index b04fd7b4f4..7d03500043 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -53,6 +53,10 @@
> (prev_dividend) = (dividend); \
> } while (0)
>
> +#define PROBE_PACKET_MAX_BUF 8192
> +#define PROBE_PACKET_STEP 512
> +#define PROBE_PACKET_MARGIN 5
> +
> enum MpegTSFilterType {
> MPEGTS_PES,
> MPEGTS_SECTION,
> @@ -591,28 +595,42 @@ static int analyze(const uint8_t *buf, int size, int packet_size,
> return best_score - FFMAX(stat_all - 10*best_score, 0)/10;
> }
>
> -/* autodetect fec presence. Must have at least 1024 bytes */
> -static int get_packet_size(const uint8_t *buf, int size)
> +/* autodetect fec presence */
> +static int get_packet_size(AVIOContext* pb)
> {
> int score, fec_score, dvhs_score;
> + int margin;
> + int ret;
>
> - if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
> - return AVERROR_INVALIDDATA;
> + /*init buffer to store stream for probing */
> + uint8_t buf[PROBE_PACKET_MAX_BUF] = {0};
> + int buf_size = 0;
>
> - score = analyze(buf, size, TS_PACKET_SIZE, 0);
> - dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, 0);
> - fec_score = analyze(buf, size, TS_FEC_PACKET_SIZE, 0);
> - av_log(NULL, AV_LOG_TRACE, "score: %d, dvhs_score: %d, fec_score: %d \n",
> - score, dvhs_score, fec_score);
> -
> - if (score > fec_score && score > dvhs_score)
> - return TS_PACKET_SIZE;
> - else if (dvhs_score > score && dvhs_score > fec_score)
> - return TS_DVHS_PACKET_SIZE;
> - else if (score < fec_score && dvhs_score < fec_score)
> - return TS_FEC_PACKET_SIZE;
> - else
> - return AVERROR_INVALIDDATA;
> + while (buf_size + PROBE_PACKET_STEP <= PROBE_PACKET_MAX_BUF) {
> + ret = avio_read(pb, buf + buf_size, PROBE_PACKET_STEP);
have you tried avio_read_partial() ?
it may be better to request the full remaining size of the buffer and accept
whatever is available.
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Democracy is the form of government in which you can choose your dictator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190307/49b05aa0/attachment.sig>
More information about the ffmpeg-devel
mailing list