On Thu, Mar 07, 2019 at 09:31:19PM -0500, Andriy Gelman wrote: > From: Andriy Gelman <andriy.gel...@gmail.com> > > Reduces buffering latency with low bitrate streams, where > 8192 bytes can mean several seconds. > --- > libavformat/mpegts.c | 59 +++++++++++++++++++++++++++----------------- > 1 file changed, 36 insertions(+), 23 deletions(-) > > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c > index b04fd7b4f4..88e2150d55 100644 > --- a/libavformat/mpegts.c > +++ b/libavformat/mpegts.c > @@ -53,6 +53,9 @@ > (prev_dividend) = (dividend); > \ > } while (0) > > +#define PROBE_PACKET_MAX_BUF 8192 > +#define PROBE_PACKET_MARGIN 5 > + > enum MpegTSFilterType { > MPEGTS_PES, > MPEGTS_SECTION, > @@ -591,28 +594,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_MAX_BUF) { > + ret = avio_read_partial(pb, buf + buf_size, PROBE_PACKET_MAX_BUF - > buf_size); > + if (ret < 0) > + return AVERROR_INVALIDDATA; > + buf_size += ret; > + > + score = analyze(buf, buf_size, TS_PACKET_SIZE, 0); > + dvhs_score = analyze(buf, buf_size, TS_DVHS_PACKET_SIZE, 0); > + fec_score = analyze(buf, buf_size, TS_FEC_PACKET_SIZE, 0); > + av_log(NULL, AV_LOG_TRACE, "Probe: %d, score: %d, dvhs_score: %d, > fec_score: %d \n", > + buf_size, score, dvhs_score, fec_score);
av_log() should have a context not NULL otherwise it cannot be associated with the source if there are multiple demuxers patch probably ok otherwise thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope
signature.asc
Description: PGP signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel