Skip to content

Commit

Permalink
Fix unlikely race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
oreo639 committed Apr 6, 2021
1 parent 66635ca commit d8d4702
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,20 @@ void videoDecode_thread(void* nul) {
scaleframe = getFrameScalef(vinfo->width, vinfo->height, SCREEN_WIDTH, SCREEN_HEIGHT);
}

isplaying = true;

while (isplaying)
{
if (THEORA_eos(&vidCtx))
break;

if (THEORA_HasVideo(&vidCtx)) {
th_ycbcr_buffer ybr;
if (THEORA_getvideo(&vidCtx, ybr)) {
frameWrite(&frame, vinfo, ybr);
}
}

if (THEORA_HasAudio(&vidCtx)) {
for (int cur_wvbuf = 0; cur_wvbuf < WAVEBUFCOUNT; cur_wvbuf++) {
ndspWaveBuf *buf = &waveBuf[cur_wvbuf];
Expand All @@ -93,13 +102,6 @@ void videoDecode_thread(void* nul) {
DSP_FlushDataCache(buf->data_pcm16, buffSize * sizeof(int16_t));
}
}

if (THEORA_HasVideo(&vidCtx)) {
th_ycbcr_buffer ybr;
if (THEORA_getvideo(&vidCtx, ybr)) {
frameWrite(&frame, vinfo, ybr);
}
}
}

printf("frames: %d dropped: %d\n", vidCtx.frames, vidCtx.dropped);
Expand Down Expand Up @@ -215,7 +217,6 @@ static void changeFile(const char* filepath) {
}

printf("Theora Create sucessful.\n");
isplaying = true;

s32 prio;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
Expand Down

0 comments on commit d8d4702

Please sign in to comment.