diff --git a/CHANGES b/CHANGES index 231f24112..6450d53d1 100644 --- a/CHANGES +++ b/CHANGES @@ -70,6 +70,7 @@ Misc: - Qt: Move frame upload back onto main thread - All: Enable link-time optimization - GBA Thread: Make GBASyncWaitFrameStart time out + - GBA: Move A/V stream interface into core 0.1.1: (2015-01-24) Bugfixes: diff --git a/src/gba/audio.c b/src/gba/audio.c index 63b83556f..6d30f9f08 100644 --- a/src/gba/audio.c +++ b/src/gba/audio.c @@ -822,9 +822,8 @@ static void _sample(struct GBAAudio* audio) { } produced = blip_samples_avail(audio->left); #endif - struct GBAThread* thread = GBAThreadGetContext(); - if (thread && thread->stream) { - thread->stream->postAudioFrame(thread->stream, sampleLeft, sampleRight); + if (audio->p->stream) { + audio->p->stream->postAudioFrame(audio->p->stream, sampleLeft, sampleRight); } GBASyncProduceAudio(audio->p->sync, produced >= audio->samples); } diff --git a/src/gba/gba.c b/src/gba/gba.c index bb18400bb..c55aeffba 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -77,7 +77,9 @@ static void GBAInit(struct ARMCore* cpu, struct ARMComponent* component) { gba->romVf = 0; gba->biosVf = 0; + gba->logHandler = 0; gba->logLevel = GBA_LOG_INFO | GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL; + gba->stream = 0; gba->biosChecksum = GBAChecksum(gba->memory.bios, SIZE_BIOS); @@ -733,8 +735,8 @@ void GBAFrameEnded(struct GBA* gba) { return; } - if (thread->stream) { - thread->stream->postVideoFrame(thread->stream, thread->renderer); + if (gba->stream) { + gba->stream->postVideoFrame(gba->stream, gba->video.renderer); } if (thread->frameCallback) { diff --git a/src/gba/gba.h b/src/gba/gba.h index 4c67a662c..386dae68d 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -96,6 +96,11 @@ struct VFile; typedef void (*GBALogHandler)(struct GBAThread*, enum GBALogLevel, const char* format, va_list args); +struct GBAAVStream { + void (*postVideoFrame)(struct GBAAVStream*, struct GBAVideoRenderer* renderer); + void (*postAudioFrame)(struct GBAAVStream*, int16_t left, int16_t right); +}; + struct GBATimer { uint16_t reload; uint16_t oldReload; @@ -146,6 +151,7 @@ struct GBA { GBALogHandler logHandler; enum GBALogLevel logLevel; + struct GBAAVStream* stream; enum GBAIdleLoopOptimization idleOptimization; uint32_t idleLoop; diff --git a/src/gba/supervisor/thread.c b/src/gba/supervisor/thread.c index ae08c440d..d39d74730 100644 --- a/src/gba/supervisor/thread.c +++ b/src/gba/supervisor/thread.c @@ -135,6 +135,7 @@ static THREAD_ENTRY _GBAThreadRun(void* context) { threadContext->gba = &gba; gba.logLevel = threadContext->logLevel; gba.logHandler = threadContext->logHandler; + gba.stream = threadContext->stream; gba.idleOptimization = threadContext->idleOptimization; #ifdef USE_PTHREADS pthread_setspecific(_contextKey, threadContext); diff --git a/src/gba/supervisor/thread.h b/src/gba/supervisor/thread.h index a39c52a4e..7a2a3778b 100644 --- a/src/gba/supervisor/thread.h +++ b/src/gba/supervisor/thread.h @@ -48,11 +48,6 @@ struct GBASync { Mutex audioBufferMutex; }; -struct GBAAVStream { - void (*postVideoFrame)(struct GBAAVStream*, struct GBAVideoRenderer* renderer); - void (*postAudioFrame)(struct GBAAVStream*, int32_t left, int32_t right); -}; - struct GBAThread { // Output enum ThreadState state; diff --git a/src/platform/ffmpeg/ffmpeg-encoder.c b/src/platform/ffmpeg/ffmpeg-encoder.c index 184ac5a8d..a53106a76 100644 --- a/src/platform/ffmpeg/ffmpeg-encoder.c +++ b/src/platform/ffmpeg/ffmpeg-encoder.c @@ -22,7 +22,7 @@ #include static void _ffmpegPostVideoFrame(struct GBAAVStream*, struct GBAVideoRenderer* renderer); -static void _ffmpegPostAudioFrame(struct GBAAVStream*, int32_t left, int32_t right); +static void _ffmpegPostAudioFrame(struct GBAAVStream*, int16_t left, int16_t right); enum { PREFERRED_SAMPLE_RATE = 0x8000 @@ -357,7 +357,7 @@ bool FFmpegEncoderIsOpen(struct FFmpegEncoder* encoder) { return !!encoder->context; } -void _ffmpegPostAudioFrame(struct GBAAVStream* stream, int32_t left, int32_t right) { +void _ffmpegPostAudioFrame(struct GBAAVStream* stream, int16_t left, int16_t right) { struct FFmpegEncoder* encoder = (struct FFmpegEncoder*) stream; if (!encoder->context || !encoder->audioCodec) { return;