generic-pc/video: fix stillpicture race condition

This commit is contained in:
Stefan Seyfried
2016-10-30 15:57:18 +01:00
parent 95d07cdfc9
commit 2525823506
2 changed files with 26 additions and 5 deletions

View File

@@ -99,6 +99,7 @@ VDec::VDec()
display_aspect = DISPLAY_AR_16_9; display_aspect = DISPLAY_AR_16_9;
display_crop = DISPLAY_AR_MODE_LETTERBOX; display_crop = DISPLAY_AR_MODE_LETTERBOX;
v_format = VIDEO_FORMAT_MPEG2; v_format = VIDEO_FORMAT_MPEG2;
stillpicture = false;
} }
VDec::~VDec(void) VDec::~VDec(void)
@@ -271,6 +272,12 @@ void VDec::ShowPicture(const char *fname)
lt_info("%s(%s)\n", __func__, fname); lt_info("%s(%s)\n", __func__, fname);
if (access(fname, R_OK)) if (access(fname, R_OK))
return; return;
still_m.lock();
stillpicture = true;
buf_num = 0;
buf_in = 0;
buf_out = 0;
still_m.unlock();
unsigned int i; unsigned int i;
int stream_id = -1; int stream_id = -1;
@@ -370,6 +377,10 @@ void VDec::ShowPicture(const char *fname)
void cVideo::StopPicture() void cVideo::StopPicture()
{ {
lt_info("%s\n", __func__);
vdec->still_m.lock();
vdec->stillpicture = false;
vdec->still_m.unlock();
} }
void cVideo::Standby(unsigned int) void cVideo::Standby(unsigned int)
@@ -550,7 +561,8 @@ void VDec::run(void)
} }
if (avpkt.size > len) if (avpkt.size > len)
lt_info("%s: WARN: pkt->size %d != len %d\n", __func__, avpkt.size, len); lt_info("%s: WARN: pkt->size %d != len %d\n", __func__, avpkt.size, len);
if (got_frame) { still_m.lock();
if (got_frame && ! stillpicture) {
unsigned int need = avpicture_get_size(VDEC_PIXFMT, c->width, c->height); unsigned int need = avpicture_get_size(VDEC_PIXFMT, c->width, c->height);
convert = sws_getCachedContext(convert, convert = sws_getCachedContext(convert,
c->width, c->height, c->pix_fmt, c->width, c->height, c->pix_fmt,
@@ -600,7 +612,9 @@ void VDec::run(void)
lt_debug("%s: time_base: %d/%d, ticks: %d rate: %d pts 0x%" PRIx64 "\n", __func__, lt_debug("%s: time_base: %d/%d, ticks: %d rate: %d pts 0x%" PRIx64 "\n", __func__,
c->time_base.num, c->time_base.den, c->ticks_per_frame, dec_r, c->time_base.num, c->time_base.den, c->ticks_per_frame, dec_r,
av_frame_get_best_effort_timestamp(frame)); av_frame_get_best_effort_timestamp(frame));
} } else
lt_info("%s: got_frame: %d stillpicture: %d\n", __func__, got_frame, stillpicture);
still_m.unlock();
av_free_packet(&avpkt); av_free_packet(&avpkt);
} }
sws_freeContext(convert); sws_freeContext(convert);
@@ -614,9 +628,13 @@ void VDec::run(void)
av_free(pIOCtx); av_free(pIOCtx);
/* reset output buffers */ /* reset output buffers */
bufpos = 0; bufpos = 0;
buf_num = 0; still_m.lock();
buf_in = 0; if (!stillpicture) {
buf_out = 0; buf_num = 0;
buf_in = 0;
buf_out = 0;
}
still_m.unlock();
lt_info("======================== end decoder thread ================================\n"); lt_info("======================== end decoder thread ================================\n");
} }

View File

@@ -30,6 +30,7 @@ class VDec : public OpenThreads::Thread
{ {
friend class GLFbPC; friend class GLFbPC;
friend class cDemux; friend class cDemux;
friend class cVideo;
private: private:
/* called from GL thread */ /* called from GL thread */
class SWFramebuffer : public std::vector<unsigned char> class SWFramebuffer : public std::vector<unsigned char>
@@ -100,5 +101,7 @@ class VDec : public OpenThreads::Thread
int pig_y; int pig_y;
int pig_w; int pig_w;
int pig_h; int pig_h;
OpenThreads::Mutex still_m;
bool stillpicture;
}; };
#endif #endif