libeplayer3: fix seeking

Origin commit data
------------------
Branch: master
Commit: 0feee1d3b4
Author: martii <m4rtii@gmx.de>
Date: 2013-11-19 (Tue, 19 Nov 2013)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
martii
2013-11-19 22:38:26 +01:00
parent e35b24a3cc
commit 74562bc318
2 changed files with 53 additions and 45 deletions

View File

@@ -62,6 +62,7 @@ static void printContainerCapabilities() {
} }
static int selectContainer(Context_t *context, char * extension) { static int selectContainer(Context_t *context, char * extension) {
#if 0
int i, j; int i, j;
int ret = -1; int ret = -1;
@@ -86,6 +87,10 @@ static int selectContainer(Context_t *context, char * extension) {
} }
return ret; return ret;
#else
context->container->selectedContainer = AvailableContainer[0];
return 0;
#endif
} }

View File

@@ -114,12 +114,10 @@ static off_t seek_target_bytes = 0;
static int do_seek_target_bytes = 0; static int do_seek_target_bytes = 0;
static int64_t seek_target_seconds = 0.0; static int64_t seek_target_seconds = 0.0;
static int do_seek_target_seconds = 0; static int do_seek_target_seconds = 0;
static int seek_target_flag = 0;
/* ***************************** */ /* ***************************** */
/* Prototypes */ /* Prototypes */
/* ***************************** */ /* ***************************** */
static int container_ffmpeg_seek_bytes(off_t pos);
static int container_ffmpeg_seek(Context_t *context, float sec, int absolute); static int container_ffmpeg_seek(Context_t *context, float sec, int absolute);
/* ***************************** */ /* ***************************** */
@@ -329,6 +327,7 @@ static void FFMPEGThread(Context_t *context) {
threadname[16] = 0; threadname[16] = 0;
prctl (PR_SET_NAME, (unsigned long)&threadname); prctl (PR_SET_NAME, (unsigned long)&threadname);
int64_t lastPts = -1, currentVideoPts = -1, currentAudioPts = -1, showtime = 0, bofcount = 0; int64_t lastPts = -1, currentVideoPts = -1, currentAudioPts = -1, showtime = 0, bofcount = 0;
off_t lastPos = -1;
AudioVideoOut_t avOut; AudioVideoOut_t avOut;
SwrContext *swr = NULL; SwrContext *swr = NULL;
@@ -377,10 +376,27 @@ static void FFMPEGThread(Context_t *context) {
if(bofcount == 1) if(bofcount == 1)
{ {
showtime = av_gettime(); showtime = av_gettime();
releaseMutex(FILENAME, __FUNCTION__,__LINE__);
usleep(100000); usleep(100000);
continue; continue;
} }
if (avContext->iformat->flags & AVFMT_TS_DISCONT) {
if (lastPos < 0)
lastPos = avio_tell(avContext->pb);
if (lastPos > 0) {
float br;
if (avContext->bit_rate)
br = avContext->bit_rate / 8.0;
else
br = 180000.0;
do_seek_target_seconds = 0;
do_seek_target_bytes = 1;
lastPos += context->playback->Speed * 8 * br;
seek_target_bytes = lastPos;
}
} else {
if (lastPts < 0) if (lastPts < 0)
lastPts = (currentVideoPts > 0) ? currentVideoPts : currentAudioPts; lastPts = (currentVideoPts > 0) ? currentVideoPts : currentAudioPts;
@@ -389,32 +405,32 @@ static void FFMPEGThread(Context_t *context) {
do_seek_target_bytes = 0; do_seek_target_bytes = 0;
lastPts += context->playback->Speed * 8 * AV_TIME_BASE; lastPts += context->playback->Speed * 8 * AV_TIME_BASE;
seek_target_seconds = lastPts; seek_target_seconds = lastPts;
seek_target_flag = 0;
showtime = av_gettime() + 300000; //jump back every 300ms
} }
}
showtime = av_gettime() + 300000; //jump back every 300ms
} else { } else {
bofcount = 0; bofcount = 0;
if (!context->playback->BackWard) if (!context->playback->BackWard)
lastPts = -1; lastPts = -1, lastPos = -1;
} }
if (do_seek_target_seconds || do_seek_target_bytes) { if (do_seek_target_seconds || do_seek_target_bytes) {
int res; int res;
if (do_seek_target_seconds) { if (do_seek_target_seconds) {
int64_t seek_target_seconds_min = seek_target_seconds - 15 * AV_TIME_BASE;
if (seek_target_seconds < 0) if (seek_target_seconds < 0)
seek_target_seconds = 0; seek_target_seconds = 0;
if (seek_target_seconds_min < 0) res = avformat_seek_file(avContext, -1, INT64_MIN, seek_target_seconds, INT64_MAX, 0);
seek_target_seconds_min = 0; } else {
res = avformat_seek_file(avContext, -1, seek_target_seconds_min, seek_target_seconds, INT64_MAX, seek_target_flag); if (seek_target_bytes < 0)
} else seek_target_bytes = 0;
res = container_ffmpeg_seek_bytes(seek_target_bytes); res = avformat_seek_file(avContext, -1, INT64_MIN, seek_target_bytes, INT64_MAX, AVSEEK_FLAG_BYTE);
}
if (res < 0 && context->playback->BackWard) if (res < 0 && context->playback->BackWard)
bofcount = 1; bofcount = 1;
do_seek_target_seconds = do_seek_target_bytes = 0; do_seek_target_seconds = do_seek_target_bytes = 0;
restart_audio_resampling = 1; restart_audio_resampling = 1;
latestPts = 0; latestPts = 0;
seek_target_flag = 0;
// flush streams // flush streams
unsigned int i; unsigned int i;
@@ -427,8 +443,18 @@ static void FFMPEGThread(Context_t *context) {
AVPacket packet; AVPacket packet;
av_init_packet(&packet); av_init_packet(&packet);
if (av_read_frame(avContext, &packet) == 0 ) int av_res = av_read_frame(avContext, &packet);
{ if (av_res == AVERROR(EAGAIN)) {
av_free_packet(&packet);
releaseMutex(FILENAME, __FUNCTION__,__LINE__);
continue;
}
if (av_res) { // av_read_frame failed
ffmpeg_err("no data ->end of file reached ?\n");
av_free_packet(&packet);
releaseMutex(FILENAME, __FUNCTION__,__LINE__);
break; // while
}
long long int pts; long long int pts;
Track_t * videoTrack = NULL; Track_t * videoTrack = NULL;
Track_t * audioTrack = NULL; Track_t * audioTrack = NULL;
@@ -816,12 +842,6 @@ static void FFMPEGThread(Context_t *context) {
//ffmpeg_err("writing data to teletext fifo failed\n"); //ffmpeg_err("writing data to teletext fifo failed\n");
} }
} }
} else { // av_read_frame failed
ffmpeg_err("no data ->end of file reached ? \n");
av_free_packet(&packet);
releaseMutex(FILENAME, __FUNCTION__,__LINE__);
break; // while
}
av_free_packet(&packet); av_free_packet(&packet);
releaseMutex(FILENAME, __FUNCTION__,__LINE__); releaseMutex(FILENAME, __FUNCTION__,__LINE__);
@@ -1424,27 +1444,10 @@ static int container_ffmpeg_stop(Context_t *context) {
return ret; return ret;
} }
static int container_ffmpeg_seek_bytes(off_t pos) {
int flag = AVSEEK_FLAG_BYTE;
ffmpeg_printf(20, "seeking to position %lld (bytes)\n", pos);
if (avformat_seek_file(avContext, -1, INT64_MIN, pos, INT64_MAX, flag) < 0)
{
ffmpeg_err( "Error seeking\n");
return cERR_CONTAINER_FFMPEG_ERR;
}
ffmpeg_printf(30, "current_pos after seek %lld\n", avio_tell(avContext->pb));
return cERR_CONTAINER_FFMPEG_NO_ERROR;
}
static int container_ffmpeg_seek(Context_t *context, float sec, int absolute) { static int container_ffmpeg_seek(Context_t *context, float sec, int absolute) {
Track_t * videoTrack = NULL; Track_t * videoTrack = NULL;
Track_t * audioTrack = NULL; Track_t * audioTrack = NULL;
Track_t * current = NULL; Track_t * current = NULL;
seek_target_flag = 0;
if (absolute) { if (absolute) {
ffmpeg_printf(10, "goto %f sec\n", sec); ffmpeg_printf(10, "goto %f sec\n", sec);