Do not wait in the FFMPEG thread.

Signed-off-by: max_10 <max_10@gmx.de>
This commit is contained in:
samsamsam
2018-03-30 14:29:35 +02:00
committed by Thilo Graf
parent 5ccc49af32
commit b0e666e1cb
4 changed files with 38 additions and 11 deletions

View File

@@ -182,7 +182,7 @@ static void releaseMutex(const char *filename __attribute__((unused)), const con
typedef int32_t (* Write_FN)(Context_t *context, void *);
static int32_t Write(Write_FN WriteFun, Context_t *context, void *privateData)
static int32_t Write(Write_FN WriteFun, Context_t *context, void *privateData, int64_t pts __attribute__((unused)))
{
/* Because Write is blocking we will release mutex which protect
* avformat structures, during write time
@@ -485,6 +485,10 @@ static int64_t calcPts(uint32_t avContextIdx, AVStream *stream, int64_t pts)
{
pts = INVALID_PTS_VALUE;
}
else
{
pts &= 0x01FFFFFFFF; // PES header can handle only 33 bit PTS
}
return pts;
}
@@ -571,6 +575,14 @@ static void FFMPEGThread(Context_t *context)
int8_t isWaitingForFinish = 0;
while (context && context->playback && context->playback->isPlaying)
{
/* When user press PAUSE we call pause on AUDIO and VIDEO decoders,
* we will not wait here because we can still fill
* DVB drivers buffers at PAUSE time
*
* In the future we can add buffering queue before injection in to
* AUDIO, VIDEO decoders, so we can not wait here
*/
#ifdef __sh__
//IF MOVIE IS PAUSED, WAIT
if (context->playback->isPaused)
{
@@ -579,6 +591,7 @@ static void FFMPEGThread(Context_t *context)
usleep(10000);
continue;
}
#endif
if (context->playback->isSeeking)
{
ffmpeg_printf(10, "seeking\n");
@@ -835,7 +848,7 @@ static void FFMPEGThread(Context_t *context)
{
avOut.infoFlags = 1; // TS container
}
if (Write(context->output->video->Write, context, &avOut) < 0)
if (Write(context->output->video->Write, context, &avOut, pts) < 0)
{
ffmpeg_err("writing data to video device failed\n");
}
@@ -903,7 +916,7 @@ static void FFMPEGThread(Context_t *context)
avOut.width = 0;
avOut.height = 0;
avOut.type = "audio";
if (Write(context->output->audio->Write, context, &avOut) < 0)
if (Write(context->output->audio->Write, context, &avOut, pts) < 0)
{
ffmpeg_err("(raw pcm) writing data to audio device failed\n");
}
@@ -1079,7 +1092,7 @@ static void FFMPEGThread(Context_t *context)
avOut.width = 0;
avOut.height = 0;
avOut.type = "audio";
if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut) < 0)
if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0)
{
ffmpeg_err("writing data to audio device failed\n");
}
@@ -1100,7 +1113,7 @@ static void FFMPEGThread(Context_t *context)
avOut.width = 0;
avOut.height = 0;
avOut.type = "audio";
if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut) < 0)
if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0)
{
ffmpeg_err("(aac) writing data to audio device failed\n");
}
@@ -1117,7 +1130,7 @@ static void FFMPEGThread(Context_t *context)
avOut.width = 0;
avOut.height = 0;
avOut.type = "audio";
if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut) < 0)
if (!context->playback->BackWard && Write(context->output->audio->Write, context, &avOut, pts) < 0)
{
ffmpeg_err("writing data to audio device failed\n");
}
@@ -1146,7 +1159,7 @@ static void FFMPEGThread(Context_t *context)
subOut.data = (uint8_t *)packet.data;
subOut.pts = pts;
subOut.durationMS = duration;
if (Write(context->output->subtitle->Write, context, &subOut) < 0)
if (Write(context->output->subtitle->Write, context, &subOut, pts) < 0)
{
ffmpeg_err("writing data to teletext fifo failed\n");
}