summaryrefslogtreecommitdiff
authorshuanglong.wang <shuanglong.wang@amlogic.com>2017-04-28 04:44:11 (GMT)
committer Zhi Zhou <zhi.zhou@amlogic.com>2017-05-11 11:12:24 (GMT)
commitbc2a91c8904957e03796fbded0989bb182210010 (patch)
treed84d602a581de27c7d83ea9e4c2a1fd73d7e3366
parent27bd1805995fb76df2b07525fc9544ce4a7b859f (diff)
downloadffmpeg-bc2a91c8904957e03796fbded0989bb182210010.zip
ffmpeg-bc2a91c8904957e03796fbded0989bb182210010.tar.gz
ffmpeg-bc2a91c8904957e03796fbded0989bb182210010.tar.bz2
PD#142712:fix the bug that some err media scan not exit that may consume large memory
Change-Id: I5edd9d879185bb2dc03b56c488f27711a78f1ee8
Diffstat
-rw-r--r--libavformat/avio.h3
-rw-r--r--libavformat/utils.c14
2 files changed, 16 insertions, 1 deletions
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);