Fix PIP threading problems.

This commit is contained in:
Johns 2013-01-05 20:44:54 +01:00
parent d4702b9a9e
commit fa09d940c5
2 changed files with 27 additions and 7 deletions

View File

@ -1518,6 +1518,11 @@ static void FixPacketForFFMpeg(VideoDecoder * vdecoder, AVPacket * avpkt)
*/ */
int VideoPollInput(VideoStream * stream) int VideoPollInput(VideoStream * stream)
{ {
if (!stream->Decoder) { // closing
fprintf(stderr, "no decoder\n");
return -1;
}
if (stream->ClearBuffers) { if (stream->ClearBuffers) {
atomic_set(&stream->PacketsFilled, 0); atomic_set(&stream->PacketsFilled, 0);
stream->PacketRead = stream->PacketWrite; stream->PacketRead = stream->PacketWrite;
@ -1549,6 +1554,11 @@ int VideoDecodeInput(VideoStream * stream)
AVPacket *avpkt; AVPacket *avpkt;
int saved_size; int saved_size;
if (!stream->Decoder) { // closing
fprintf(stderr, "no decoder\n");
return -1;
}
if (stream->ClearBuffers) { // clear buffer request if (stream->ClearBuffers) { // clear buffer request
atomic_set(&stream->PacketsFilled, 0); atomic_set(&stream->PacketsFilled, 0);
stream->PacketRead = stream->PacketWrite; stream->PacketRead = stream->PacketWrite;
@ -2987,16 +2997,17 @@ void PipStop(void)
return; return;
} }
if (PipVideoStream->HwDecoder) {
VideoDelHwDecoder(PipVideoStream->HwDecoder);
PipVideoStream->HwDecoder = NULL;
// FIXME: does CodecVideoClose call hw decoder?
}
if (PipVideoStream->Decoder) { if (PipVideoStream->Decoder) {
PipVideoStream->SkipStream = 1; PipVideoStream->SkipStream = 1;
CodecVideoClose(PipVideoStream->Decoder); CodecVideoClose(PipVideoStream->Decoder);
CodecVideoDelDecoder(PipVideoStream->Decoder); CodecVideoDelDecoder(PipVideoStream->Decoder);
PipVideoStream->Decoder = NULL; PipVideoStream->Decoder = NULL;
} }
if (PipVideoStream->HwDecoder) {
VideoDelHwDecoder(PipVideoStream->HwDecoder);
PipVideoStream->HwDecoder = NULL;
}
VideoPacketExit(PipVideoStream); VideoPacketExit(PipVideoStream);
PipVideoStream->NewStream = 1; PipVideoStream->NewStream = 1;

15
video.c
View File

@ -8231,6 +8231,7 @@ static void VdpauSyncRenderFrame(VdpauDecoder * decoder,
while (atomic_read(&decoder->SurfacesFilled) >= VIDEO_SURFACES_MAX) { while (atomic_read(&decoder->SurfacesFilled) >= VIDEO_SURFACES_MAX) {
struct timespec abstime; struct timespec abstime;
fprintf(stderr, "video/vdpau: must be removed\n");
pthread_mutex_unlock(&VideoLockMutex); pthread_mutex_unlock(&VideoLockMutex);
abstime = decoder->FrameTime; abstime = decoder->FrameTime;
@ -8378,6 +8379,7 @@ static void VdpauDisplayHandlerThread(void)
} }
decoded = 0; decoded = 0;
pthread_mutex_lock(&VideoLockMutex);
for (i = 0; i < VdpauDecoderN; ++i) { for (i = 0; i < VdpauDecoderN; ++i) {
int filled; int filled;
@ -8389,10 +8391,8 @@ static void VdpauDisplayHandlerThread(void)
filled = atomic_read(&decoder->SurfacesFilled); filled = atomic_read(&decoder->SurfacesFilled);
if (filled < VIDEO_SURFACES_MAX) { if (filled < VIDEO_SURFACES_MAX) {
// FIXME: hot polling // FIXME: hot polling
pthread_mutex_lock(&VideoLockMutex);
// fetch+decode or reopen // fetch+decode or reopen
err = VideoDecodeInput(decoder->Stream); err = VideoDecodeInput(decoder->Stream);
pthread_mutex_unlock(&VideoLockMutex);
} else { } else {
err = VideoPollInput(decoder->Stream); err = VideoPollInput(decoder->Stream);
} }
@ -8409,6 +8409,7 @@ static void VdpauDisplayHandlerThread(void)
} }
decoded = 1; decoded = 1;
} }
pthread_mutex_unlock(&VideoLockMutex);
if (!decoded) { // nothing decoded, sleep if (!decoded) { // nothing decoded, sleep
// FIXME: sleep on wakeup // FIXME: sleep on wakeup
@ -9459,7 +9460,13 @@ struct _video_hw_decoder_
/// ///
VideoHwDecoder *VideoNewHwDecoder(VideoStream * stream) VideoHwDecoder *VideoNewHwDecoder(VideoStream * stream)
{ {
return VideoUsedModule->NewHwDecoder(stream); VideoHwDecoder *hw;
VideoThreadLock();
hw = VideoUsedModule->NewHwDecoder(stream);
VideoThreadUnlock();
return hw;
} }
/// ///
@ -9470,7 +9477,9 @@ VideoHwDecoder *VideoNewHwDecoder(VideoStream * stream)
void VideoDelHwDecoder(VideoHwDecoder * hw_decoder) void VideoDelHwDecoder(VideoHwDecoder * hw_decoder)
{ {
if (hw_decoder) { if (hw_decoder) {
VideoThreadLock();
VideoUsedModule->DelHwDecoder(hw_decoder); VideoUsedModule->DelHwDecoder(hw_decoder);
VideoThreadUnlock();
} }
} }