From bc2a91c8904957e03796fbded0989bb182210010 Mon Sep 17 00:00:00 2001 From: shuanglong.wang Date: Fri, 28 Apr 2017 04:44:11 +0000 Subject: PD#142712:fix the bug that some err media scan not exit that may consume large memory Change-Id: I5edd9d879185bb2dc03b56c488f27711a78f1ee8 --- diff --git a/libavformat/avio.h b/libavformat/avio.h index 4f4ac3c..5f5111e 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -146,6 +146,8 @@ typedef struct AVIOContext { * This field is internal to libavformat and access from outside is not allowed. */ int writeout_count; + + int mediascan_flag; } AVIOContext; /* unbuffered I/O */ @@ -332,6 +334,7 @@ int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen); #define AVIO_FLAG_READ 1 /**< read-only */ #define AVIO_FLAG_WRITE 2 /**< write-only */ #define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE) /**< read-write pseudo flag */ + /** * @} */ diff --git a/libavformat/utils.c b/libavformat/utils.c index 5211ffd..0c732c5 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -70,6 +70,13 @@ const char *avformat_license(void) return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; } +int64_t avformat_getcurtime_us(void) +{ + struct timespec timeval; + clock_gettime(CLOCK_MONOTONIC, &timeval); + return ((int64_t)timeval.tv_nsec / 1000 + (int64_t)timeval.tv_sec * 1000000); +} + #define RELATIVE_TS_BASE (INT64_MAX - (1LL<<48)) static int is_relative(int64_t ts) { @@ -1304,12 +1311,17 @@ static int read_from_packet_buffer(AVPacketList **pkt_buffer, static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { int ret = 0, i, got_packet = 0; - + int64_t first_timeval = avformat_getcurtime_us(); av_init_packet(pkt); while (!got_packet && !s->parse_queue) { AVStream *st; AVPacket cur_pkt; + if (s->pb->mediascan_flag) { + if (avformat_getcurtime_us() > (first_timeval + s->max_analyze_duration)) { + return -1; + } + } /* read next packet */ ret = ff_read_packet(s, &cur_pkt); -- cgit