Skip to content

Commit 2cc5808

Browse files
committed
improvement(avformatdemuxer): work around fast seek error when mp3 seek to end
Signed-off-by: pingkai <pingkai010@gmail.com> (cherry picked from commit 25aa429)
1 parent 4ce7060 commit 2cc5808

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

framework/demuxer/avFormatDemuxer.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ namespace Cicada {
9595

9696
av_dict_set_int(&mInputOpts, "safe", 0, 0);
9797
av_dict_set(&mInputOpts, "protocol_whitelist", "file,http,https,tcp,tls", 0);
98+
av_dict_set_int(&mInputOpts, "usetoc", 1, 0);
9899
/*If a url with mp4 ext name, but is not a mp4 file, the mp4 demuxer will be matched
99100
* by ext name , mp4 demuxer will try to find moov box, it will ignore the return value
100101
* of the avio_*, and don't check interrupt flag, if the url is a network file, here will
@@ -173,7 +174,7 @@ namespace Cicada {
173174
/*
174175
* this flag is only affect on mp3 and flac
175176
*/
176-
if (mCtx->duration > 600 * AV_TIME_BASE) {
177+
if (mCtx->duration > 600 * AV_TIME_BASE && strcmp(mCtx->iformat->name, "mp3") == 0) {
177178
mCtx->flags |= AVFMT_FLAG_FAST_SEEK;
178179
}
179180

@@ -458,6 +459,7 @@ namespace Cicada {
458459

459460
int avFormatDemuxer::Seek(int64_t us, int flags, int index)
460461
{
462+
us = getWorkAroundSeekPos(us);
461463
if (!bOpened) {
462464
mStartTime = us;
463465
return static_cast<int>(us);
@@ -714,4 +716,12 @@ namespace Cicada {
714716
#endif
715717
}
716718

719+
int64_t avFormatDemuxer::getWorkAroundSeekPos(int64_t pos)
720+
{
721+
if (!bOpened || mCtx == nullptr || !(mCtx->flags & AVFMT_FLAG_FAST_SEEK) || mCtx->duration <= 0) {
722+
return pos;
723+
}
724+
725+
return pos >= mCtx->duration - 2 * AV_TIME_BASE ? mCtx->duration - 2 * AV_TIME_BASE : pos;
726+
}
717727
}

framework/demuxer/avFormatDemuxer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ namespace Cicada {
113113
int readLoop();
114114

115115
#endif
116+
inline int64_t getWorkAroundSeekPos(int64_t pos);
116117

117118

118119
protected:

0 commit comments

Comments
 (0)