Bink: clean up headers and formatting
This commit is contained in:
parent
3c3b436cc1
commit
e6a01e2379
2 changed files with 123 additions and 207 deletions
304
src/bink.c
304
src/bink.c
|
@ -1,40 +1,27 @@
|
||||||
|
#include "bink.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "fixer.h"
|
|
||||||
|
|
||||||
#include "bink.h"
|
|
||||||
|
|
||||||
#include <AL/al.h>
|
#include <AL/al.h>
|
||||||
#include <AL/alc.h>
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <libavcodec/avcodec.h>
|
||||||
|
#include <libavformat/avformat.h>
|
||||||
|
#include <libavutil/avutil.h>
|
||||||
|
#include <libavutil/imgutils.h>
|
||||||
|
#include <libswscale/swscale.h>
|
||||||
|
|
||||||
#include "libavcodec/avcodec.h"
|
|
||||||
#include "libavformat/avformat.h"
|
|
||||||
#include "libavutil/avutil.h"
|
|
||||||
#include "libavutil/imgutils.h"
|
|
||||||
#include "libavutil/channel_layout.h"
|
|
||||||
#include "libswscale/swscale.h"
|
|
||||||
|
|
||||||
|
|
||||||
//#define DISABLE_MOVIES
|
|
||||||
//#define DISABLE_MUSIC
|
|
||||||
//#define DISABLE_FMVS
|
|
||||||
|
|
||||||
extern void SDL_Delay();
|
|
||||||
extern uint SDL_GetTicks();
|
|
||||||
extern int SoundSys_IsOn();
|
extern int SoundSys_IsOn();
|
||||||
extern void DrawAvpMenuBink(char* buf, int width, int height, int pitch);
|
extern void DrawAvpMenuBink(char* buf, int width, int height, int pitch);
|
||||||
extern float PlatVolumeToGain(int volume);
|
extern float PlatVolumeToGain(int volume);
|
||||||
|
|
||||||
|
|
||||||
//#define AL_CHECK() { int err = alGetError(); if(err!=AL_NO_ERROR) printf("%s:%d ALError %04x\n", __FILE__, __LINE__, err); }
|
//#define AL_CHECK() { int err = alGetError(); if(err!=AL_NO_ERROR) printf("%s:%d ALError %04x\n", __FILE__, __LINE__, err); }
|
||||||
#define AL_CHECK() {}
|
#define AL_CHECK() {}
|
||||||
|
|
||||||
#define FRAMEQUEUESIZE 4
|
#define FRAMEQUEUESIZE 4
|
||||||
|
|
||||||
struct binkMovie
|
struct binkMovie {
|
||||||
{
|
|
||||||
AVFormatContext* avContext;
|
AVFormatContext* avContext;
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
|
|
||||||
|
@ -60,22 +47,16 @@ struct binkMovie
|
||||||
ALuint alFreeBuffers[FRAMEQUEUESIZE];
|
ALuint alFreeBuffers[FRAMEQUEUESIZE];
|
||||||
ALuint alNumFreeBuffers;
|
ALuint alNumFreeBuffers;
|
||||||
ALuint alNumChannels;
|
ALuint alNumChannels;
|
||||||
ALenum alFormat;
|
ALenum alFormat;
|
||||||
ALuint alSampleRate;
|
ALuint alSampleRate;
|
||||||
|
|
||||||
uint timeStart;
|
uint timeStart;
|
||||||
|
|
||||||
BOOL looping;
|
BOOL looping;
|
||||||
BOOL isfmv;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
static void BinkRenderMovie(struct binkMovie* aMovie)
|
static void BinkRenderMovie(struct binkMovie* aMovie)
|
||||||
{
|
{
|
||||||
if(aMovie && aMovie->videoFrame && aMovie->videoScalePicture[0])
|
if (aMovie && aMovie->videoFrame && aMovie->videoScalePicture[0]) {
|
||||||
{
|
|
||||||
DrawAvpMenuBink(
|
DrawAvpMenuBink(
|
||||||
aMovie->videoScalePicture[0],
|
aMovie->videoScalePicture[0],
|
||||||
aMovie->videoFrame->width,
|
aMovie->videoFrame->width,
|
||||||
|
@ -84,7 +65,6 @@ static void BinkRenderMovie(struct binkMovie* aMovie)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void BinkInitMovieStruct(struct binkMovie* aMovie)
|
static void BinkInitMovieStruct(struct binkMovie* aMovie)
|
||||||
{
|
{
|
||||||
*aMovie = (struct binkMovie){
|
*aMovie = (struct binkMovie){
|
||||||
|
@ -96,28 +76,26 @@ static void BinkInitMovieStruct(struct binkMovie* aMovie)
|
||||||
|
|
||||||
static void BinkReleaseMovie(struct binkMovie* aMovie)
|
static void BinkReleaseMovie(struct binkMovie* aMovie)
|
||||||
{
|
{
|
||||||
if(aMovie->alInited)
|
if (aMovie->alInited) {
|
||||||
{
|
|
||||||
alSourceStop(aMovie->alSource);
|
alSourceStop(aMovie->alSource);
|
||||||
alDeleteSources(1, &aMovie->alSource);
|
alDeleteSources(1, &aMovie->alSource);
|
||||||
alDeleteBuffers(FRAMEQUEUESIZE, aMovie->alBuffers);
|
alDeleteBuffers(FRAMEQUEUESIZE, aMovie->alBuffers);
|
||||||
if(aMovie->audioTempBuffer)
|
if (aMovie->audioTempBuffer)
|
||||||
free(aMovie->audioTempBuffer);
|
free(aMovie->audioTempBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(aMovie->videoScaleContext)
|
if (aMovie->avContext)
|
||||||
av_freep(&aMovie->videoScalePicture[0]);
|
|
||||||
|
|
||||||
if(aMovie->avContext)
|
|
||||||
avformat_close_input(&aMovie->avContext);
|
avformat_close_input(&aMovie->avContext);
|
||||||
if(aMovie->audioCodecContext)
|
if (aMovie->audioCodecContext)
|
||||||
avcodec_free_context(&aMovie->audioCodecContext);
|
avcodec_free_context(&aMovie->audioCodecContext);
|
||||||
if(aMovie->audioFrame)
|
if (aMovie->audioFrame)
|
||||||
av_frame_free(&aMovie->audioFrame);
|
av_frame_free(&aMovie->audioFrame);
|
||||||
if(aMovie->videoCodecContext)
|
if (aMovie->videoCodecContext)
|
||||||
avcodec_free_context(&aMovie->videoCodecContext);
|
avcodec_free_context(&aMovie->videoCodecContext);
|
||||||
if(aMovie->videoFrame)
|
if (aMovie->videoFrame)
|
||||||
av_frame_free(&aMovie->videoFrame);
|
av_frame_free(&aMovie->videoFrame);
|
||||||
|
if (aMovie->videoScaleContext)
|
||||||
|
av_freep(&aMovie->videoScalePicture[0]);
|
||||||
|
|
||||||
BinkInitMovieStruct(aMovie);
|
BinkInitMovieStruct(aMovie);
|
||||||
}
|
}
|
||||||
|
@ -125,15 +103,16 @@ static void BinkReleaseMovie(struct binkMovie* aMovie)
|
||||||
|
|
||||||
static int DecodeVideoFrame(struct binkMovie* aMovie)
|
static int DecodeVideoFrame(struct binkMovie* aMovie)
|
||||||
{
|
{
|
||||||
int ret = avcodec_receive_frame(aMovie->videoCodecContext, aMovie->videoFrame);
|
if (avcodec_receive_frame(aMovie->videoCodecContext, aMovie->videoFrame) != 0)
|
||||||
if (ret < 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(aMovie->videoScaleContext==NULL)
|
if (aMovie->videoScaleContext == NULL) {
|
||||||
{
|
if (aMovie->videoScaleWidth == 0)
|
||||||
if(aMovie->videoScaleWidth==0) aMovie->videoScaleWidth = aMovie->videoFrame->width;
|
aMovie->videoScaleWidth = aMovie->videoFrame->width;
|
||||||
if(aMovie->videoScaleHeight==0) aMovie->videoScaleHeight = aMovie->videoFrame->height;
|
if (aMovie->videoScaleHeight == 0)
|
||||||
if(aMovie->videoScaleFormat==AV_PIX_FMT_NONE) aMovie->videoScaleFormat = AV_PIX_FMT_RGB565;
|
aMovie->videoScaleHeight = aMovie->videoFrame->height;
|
||||||
|
if (aMovie->videoScaleFormat == AV_PIX_FMT_NONE)
|
||||||
|
aMovie->videoScaleFormat = AV_PIX_FMT_RGB565;
|
||||||
|
|
||||||
aMovie->videoScaleContext = sws_getContext(
|
aMovie->videoScaleContext = sws_getContext(
|
||||||
aMovie->videoFrame->width, aMovie->videoFrame->height,
|
aMovie->videoFrame->width, aMovie->videoFrame->height,
|
||||||
|
@ -142,7 +121,7 @@ static int DecodeVideoFrame(struct binkMovie* aMovie)
|
||||||
aMovie->videoScaleFormat,
|
aMovie->videoScaleFormat,
|
||||||
SWS_FAST_BILINEAR, NULL, NULL, NULL);
|
SWS_FAST_BILINEAR, NULL, NULL, NULL);
|
||||||
|
|
||||||
if (aMovie->videoScaleContext==NULL)
|
if (aMovie->videoScaleContext == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
av_image_alloc(aMovie->videoScalePicture, aMovie->videoScaleLineSize,
|
av_image_alloc(aMovie->videoScalePicture, aMovie->videoScaleLineSize,
|
||||||
|
@ -159,19 +138,13 @@ static int DecodeVideoFrame(struct binkMovie* aMovie)
|
||||||
|
|
||||||
static int DecodeAudioFrame(struct binkMovie* aMovie)
|
static int DecodeAudioFrame(struct binkMovie* aMovie)
|
||||||
{
|
{
|
||||||
int decoded_frame_ready = 0;
|
if (avcodec_receive_frame(aMovie->audioCodecContext, aMovie->audioFrame) != 0)
|
||||||
av_frame_unref(aMovie->audioFrame);
|
|
||||||
//avcodec_get_frame_defaults(aMovie->audioFrame);
|
|
||||||
|
|
||||||
int ret = avcodec_receive_frame(aMovie->audioCodecContext, aMovie->audioFrame);
|
|
||||||
if (ret < 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(!SoundSys_IsOn())
|
if (!SoundSys_IsOn())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(!aMovie->alInited)
|
if (!aMovie->alInited) {
|
||||||
{
|
|
||||||
alGenSources(1, &aMovie->alSource);
|
alGenSources(1, &aMovie->alSource);
|
||||||
AL_CHECK();
|
AL_CHECK();
|
||||||
|
|
||||||
|
@ -188,46 +161,46 @@ static int DecodeAudioFrame(struct binkMovie* aMovie)
|
||||||
|
|
||||||
AL_CHECK();
|
AL_CHECK();
|
||||||
|
|
||||||
aMovie->alNumFreeBuffers=FRAMEQUEUESIZE;
|
aMovie->alNumFreeBuffers = FRAMEQUEUESIZE;
|
||||||
for(int i=0; i<aMovie->alNumFreeBuffers; i++)
|
for (int i=0; i < aMovie->alNumFreeBuffers; i++)
|
||||||
aMovie->alFreeBuffers[i] = aMovie->alBuffers[i];
|
aMovie->alFreeBuffers[i] = aMovie->alBuffers[i];
|
||||||
|
|
||||||
switch(aMovie->audioFrame->channel_layout)
|
switch (aMovie->audioFrame->channel_layout) {
|
||||||
{
|
|
||||||
case AV_CH_LAYOUT_MONO:
|
case AV_CH_LAYOUT_MONO:
|
||||||
aMovie->alFormat = (aMovie->audioFrame->format == AV_SAMPLE_FMT_U8) ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16;
|
aMovie->alFormat = (aMovie->audioFrame->format == AV_SAMPLE_FMT_U8) ?
|
||||||
|
AL_FORMAT_MONO8 : AL_FORMAT_MONO16;
|
||||||
aMovie->alNumChannels = 1;
|
aMovie->alNumChannels = 1;
|
||||||
break;
|
break;
|
||||||
case AV_CH_LAYOUT_STEREO:
|
case AV_CH_LAYOUT_STEREO:
|
||||||
aMovie->alFormat = (aMovie->audioFrame->format == AV_SAMPLE_FMT_U8) ? AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16;
|
aMovie->alFormat = (aMovie->audioFrame->format == AV_SAMPLE_FMT_U8) ?
|
||||||
|
AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16;
|
||||||
aMovie->alNumChannels = 2;
|
aMovie->alNumChannels = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
aMovie->alSampleRate = aMovie->audioFrame->sample_rate;
|
aMovie->alSampleRate = aMovie->audioFrame->sample_rate;
|
||||||
aMovie->audioTempBuffer = malloc(aMovie->alNumChannels * aMovie->audioFrame->nb_samples * 2 * 2);
|
aMovie->audioTempBuffer =
|
||||||
aMovie->alInited=TRUE;
|
malloc(aMovie->alNumChannels * aMovie->audioFrame->nb_samples * 2 * 2);
|
||||||
|
aMovie->alInited = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(aMovie->audioTempBuffer, 0, aMovie->alNumChannels * aMovie->audioFrame->nb_samples * 2 * 2);
|
memset(aMovie->audioTempBuffer, 0,
|
||||||
|
aMovie->alNumChannels * aMovie->audioFrame->nb_samples * 2 * 2);
|
||||||
|
|
||||||
if(aMovie->alNumChannels==0)
|
if (aMovie->alNumChannels == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// reclaim completed frames
|
// reclaim completed frames
|
||||||
int processedBuffers = 0;
|
int processedBuffers = 0;
|
||||||
alGetSourcei(aMovie->alSource, AL_BUFFERS_PROCESSED, &processedBuffers);
|
alGetSourcei(aMovie->alSource, AL_BUFFERS_PROCESSED, &processedBuffers);
|
||||||
if(processedBuffers>0)
|
if (processedBuffers > 0) {
|
||||||
{
|
|
||||||
alSourceStop(aMovie->alSource);
|
alSourceStop(aMovie->alSource);
|
||||||
while(processedBuffers>0)
|
while (processedBuffers > 0) {
|
||||||
{
|
|
||||||
ALuint buffer = 0;
|
ALuint buffer = 0;
|
||||||
alSourceUnqueueBuffers(aMovie->alSource, 1, &buffer);
|
alSourceUnqueueBuffers(aMovie->alSource, 1, &buffer);
|
||||||
AL_CHECK();
|
AL_CHECK();
|
||||||
|
|
||||||
if(buffer>0)
|
if (buffer > 0) {
|
||||||
{
|
|
||||||
aMovie->alFreeBuffers[aMovie->alNumFreeBuffers] = buffer;
|
aMovie->alFreeBuffers[aMovie->alNumFreeBuffers] = buffer;
|
||||||
aMovie->alNumFreeBuffers++;
|
aMovie->alNumFreeBuffers++;
|
||||||
}
|
}
|
||||||
|
@ -237,27 +210,20 @@ static int DecodeAudioFrame(struct binkMovie* aMovie)
|
||||||
}
|
}
|
||||||
|
|
||||||
// queue this frame
|
// queue this frame
|
||||||
if(aMovie->alNumFreeBuffers>0)
|
if (aMovie->alNumFreeBuffers > 0) {
|
||||||
{
|
|
||||||
ALuint alBuffer = aMovie->alFreeBuffers[aMovie->alNumFreeBuffers-1];
|
ALuint alBuffer = aMovie->alFreeBuffers[aMovie->alNumFreeBuffers-1];
|
||||||
|
|
||||||
int sampleCount = aMovie->audioFrame->nb_samples * aMovie->alNumChannels;
|
int sampleCount = aMovie->audioFrame->nb_samples * aMovie->alNumChannels;
|
||||||
|
uint dataSize = sampleCount * 2; // 16bit is deafult
|
||||||
|
void* data = (void*)aMovie->audioFrame->extended_data[0];
|
||||||
|
|
||||||
|
switch (aMovie->audioFrame->format) {
|
||||||
// 16bit is deafult
|
case AV_SAMPLE_FMT_U8: {
|
||||||
uint dataSize = sampleCount*2;
|
|
||||||
void* data = (void*) aMovie->audioFrame->extended_data[0];
|
|
||||||
|
|
||||||
switch(aMovie->audioFrame->format)
|
|
||||||
{
|
|
||||||
case AV_SAMPLE_FMT_U8:
|
|
||||||
{
|
|
||||||
dataSize = sampleCount;
|
dataSize = sampleCount;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
case AV_SAMPLE_FMT_S16:
|
case AV_SAMPLE_FMT_S16: {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
unsigned short* p = (unsigned short*) data;
|
unsigned short* p = (unsigned short*) data;
|
||||||
for(int i=0; i<sampleCount; i++)
|
for(int i=0; i<sampleCount; i++)
|
||||||
|
@ -265,54 +231,48 @@ static int DecodeAudioFrame(struct binkMovie* aMovie)
|
||||||
*/
|
*/
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case AV_SAMPLE_FMT_FLT:
|
case AV_SAMPLE_FMT_FLT: {
|
||||||
{
|
data = (void*)aMovie->audioTempBuffer;
|
||||||
data = (void*) aMovie->audioTempBuffer;
|
short* tempBuf = (short*)aMovie->audioTempBuffer;
|
||||||
short* tempBuf = (short*) aMovie->audioTempBuffer;
|
float* srcBuf = (float*)aMovie->audioFrame->extended_data[0];
|
||||||
float* srcBuf = (float*) aMovie->audioFrame->extended_data[0];
|
for (int i = 0; i < sampleCount; i++) {
|
||||||
for(int i=0; i<sampleCount; i++)
|
|
||||||
{
|
|
||||||
float val = srcBuf[i] * 32768;
|
float val = srcBuf[i] * 32768;
|
||||||
if(val > 32767) val = 32767;
|
if (val > 32767)
|
||||||
if(val < -32768) val = 32768;
|
val = 32767;
|
||||||
tempBuf[i] = (short) val;
|
if (val < -32768)
|
||||||
|
val = 32768;
|
||||||
|
tempBuf[i] = (short)val;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case AV_SAMPLE_FMT_S32:
|
case AV_SAMPLE_FMT_S32: {
|
||||||
{
|
data = (void*)aMovie->audioTempBuffer;
|
||||||
data = (void*) aMovie->audioTempBuffer;
|
short* tempBuf = (short*)aMovie->audioTempBuffer;
|
||||||
short* tempBuf = (short*) aMovie->audioTempBuffer;
|
unsigned int* srcBuf = (unsigned int*)aMovie->audioFrame->extended_data[0];
|
||||||
unsigned int* srcBuf = (unsigned int*) aMovie->audioFrame->extended_data[0];
|
for(int i = 0; i < sampleCount; i++)
|
||||||
for(int i=0; i<sampleCount; i++)
|
tempBuf[i] = (short)(((*srcBuf - *srcBuf>>2) >> 16) & 0x0000FFFF);
|
||||||
tempBuf[i] = (short) (((*srcBuf - *srcBuf>>2) >> 16) & 0x0000FFFF);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case AV_SAMPLE_FMT_FLTP:
|
case AV_SAMPLE_FMT_FLTP: {
|
||||||
{
|
data = (void*)aMovie->audioTempBuffer;
|
||||||
data = (void*) aMovie->audioTempBuffer;
|
short* tempBuf = (short*)aMovie->audioTempBuffer;
|
||||||
short* tempBuf = (short*) aMovie->audioTempBuffer;
|
for (int i = 0; i < aMovie->audioFrame->nb_samples; i++) {
|
||||||
|
for (int j = 0; j < aMovie->alNumChannels; j++) {
|
||||||
for(int i=0; i<aMovie->audioFrame->nb_samples; i++)
|
float* srcBuf = (float*)aMovie->audioFrame->extended_data[j];
|
||||||
{
|
|
||||||
for(int j=0; j<aMovie->alNumChannels; j++)
|
|
||||||
{
|
|
||||||
float* srcBuf = (float*) aMovie->audioFrame->extended_data[j];
|
|
||||||
float val = srcBuf[i] * 32768;
|
float val = srcBuf[i] * 32768;
|
||||||
if(val > 32767) val = 32767;
|
if (val > 32767)
|
||||||
if(val < -32768) val = 32768;
|
val = 32767;
|
||||||
tempBuf[(i*aMovie->alNumChannels)+j] = (short) val;
|
if (val < -32768)
|
||||||
|
val = 32768;
|
||||||
|
tempBuf[(i*aMovie->alNumChannels)+j] = (short)val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
alSourceStop(aMovie->alSource);
|
alSourceStop(aMovie->alSource);
|
||||||
|
|
||||||
//printf("fmt=%d, buffer size=%d, rdy=%d, len=%d, s1=%d, samples=%d\n", aMovie->audioFrame->format, dataSize, decoded_frame_ready, len, aPacket->size, sampleCount);
|
alBufferData(alBuffer, aMovie->alFormat, data, dataSize - 16, aMovie->alSampleRate);
|
||||||
|
|
||||||
alBufferData(alBuffer, aMovie->alFormat, data, dataSize-16, aMovie->alSampleRate);
|
|
||||||
AL_CHECK();
|
AL_CHECK();
|
||||||
|
|
||||||
alSourceQueueBuffers(aMovie->alSource, 1, &alBuffer);
|
alSourceQueueBuffers(aMovie->alSource, 1, &alBuffer);
|
||||||
|
@ -334,6 +294,7 @@ static int ReadFrame(struct binkMovie* aMovie)
|
||||||
{
|
{
|
||||||
// Read from file if no packet is buffered.
|
// Read from file if no packet is buffered.
|
||||||
if (!aMovie->packet.buf && av_read_frame(aMovie->avContext, &aMovie->packet) < 0) {
|
if (!aMovie->packet.buf && av_read_frame(aMovie->avContext, &aMovie->packet) < 0) {
|
||||||
|
// No more packets in file.
|
||||||
if (aMovie->looping) {
|
if (aMovie->looping) {
|
||||||
av_seek_frame(aMovie->avContext, -1, 0, 0);
|
av_seek_frame(aMovie->avContext, -1, 0, 0);
|
||||||
return ReadFrame(aMovie);
|
return ReadFrame(aMovie);
|
||||||
|
@ -363,33 +324,28 @@ static int ReadFrame(struct binkMovie* aMovie)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int BinkStartMovie(struct binkMovie* aMovie, const char* aFilename,
|
||||||
static int BinkStartMovie(struct binkMovie* aMovie, const char* aFilename, BOOL aLoopFlag, BOOL aFmvFlag, BOOL aMusicFlag)
|
BOOL aLoopFlag, BOOL aFmvFlag, BOOL aMusicFlag)
|
||||||
{
|
{
|
||||||
BinkInitMovieStruct(aMovie);
|
BinkInitMovieStruct(aMovie);
|
||||||
aMovie->looping = aLoopFlag;
|
aMovie->looping = aLoopFlag;
|
||||||
|
|
||||||
if(aFmvFlag)
|
if (aFmvFlag) {
|
||||||
{
|
|
||||||
aMovie->videoScaleWidth = 128;
|
aMovie->videoScaleWidth = 128;
|
||||||
aMovie->videoScaleHeight = 96;
|
aMovie->videoScaleHeight = 96;
|
||||||
aMovie->videoScaleFormat = AV_PIX_FMT_RGB24;
|
aMovie->videoScaleFormat = AV_PIX_FMT_RGB24;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(avformat_open_input(&aMovie->avContext, aFilename, NULL, NULL) < 0)
|
if (avformat_open_input(&aMovie->avContext, aFilename, NULL, NULL) != 0)
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if(!avformat_find_stream_info(aMovie->avContext, NULL) < 0)
|
if (avformat_find_stream_info(aMovie->avContext, NULL) < 0) {
|
||||||
{
|
|
||||||
BinkReleaseMovie(aMovie);
|
BinkReleaseMovie(aMovie);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numStreams = 0;
|
int numStreams = 0;
|
||||||
for(int i=0; i<aMovie->avContext->nb_streams; i++)
|
for (int i = 0; i < aMovie->avContext->nb_streams; i++) {
|
||||||
{
|
|
||||||
const AVStream* stream = aMovie->avContext->streams[i];
|
const AVStream* stream = aMovie->avContext->streams[i];
|
||||||
const AVCodec* codec = avcodec_find_decoder(stream->codecpar->codec_id);
|
const AVCodec* codec = avcodec_find_decoder(stream->codecpar->codec_id);
|
||||||
if (!codec)
|
if (!codec)
|
||||||
|
@ -398,49 +354,41 @@ static int BinkStartMovie(struct binkMovie* aMovie, const char* aFilename, BOOL
|
||||||
if (!context)
|
if (!context)
|
||||||
continue;
|
continue;
|
||||||
if (avcodec_parameters_to_context(context, stream->codecpar) < 0 ||
|
if (avcodec_parameters_to_context(context, stream->codecpar) < 0 ||
|
||||||
avcodec_open2(context, codec, NULL) < 0) {
|
avcodec_open2(context, codec, NULL) != 0) {
|
||||||
avcodec_free_context(&context);
|
avcodec_free_context(&context);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aMovie->videoStreamIndex < 0 && context->codec_type == AVMEDIA_TYPE_VIDEO)
|
if (aMovie->videoStreamIndex < 0 && context->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||||
{
|
|
||||||
aMovie->videoCodecContext = context;
|
aMovie->videoCodecContext = context;
|
||||||
aMovie->videoStreamIndex = i;
|
aMovie->videoStreamIndex = i;
|
||||||
aMovie->videoFrame = av_frame_alloc();
|
aMovie->videoFrame = av_frame_alloc();
|
||||||
aMovie->videoFrameDuration =
|
aMovie->videoFrameDuration =
|
||||||
1000.0f * (float)stream->time_base.num / (float)stream->time_base.den;
|
1000.0f * (float)stream->time_base.num / (float)stream->time_base.den;
|
||||||
numStreams++;
|
numStreams++;
|
||||||
}
|
} else if (aMovie->audioStreamIndex < 0 && context->codec_type == AVMEDIA_TYPE_AUDIO) {
|
||||||
else if (aMovie->audioStreamIndex < 0 && context->codec_type == AVMEDIA_TYPE_AUDIO)
|
|
||||||
{
|
|
||||||
aMovie->audioCodecContext = context;
|
aMovie->audioCodecContext = context;
|
||||||
aMovie->audioStreamIndex = i;
|
aMovie->audioStreamIndex = i;
|
||||||
aMovie->audioFrame = av_frame_alloc();
|
aMovie->audioFrame = av_frame_alloc();
|
||||||
numStreams++;
|
numStreams++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
avcodec_free_context(&context);
|
avcodec_free_context(&context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(aMovie->videoStreamIndex < 0 && aMovie->audioStreamIndex < 0)
|
if (aMovie->videoStreamIndex < 0 && aMovie->audioStreamIndex < 0) {
|
||||||
{
|
|
||||||
BinkReleaseMovie(aMovie);
|
BinkReleaseMovie(aMovie);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!aFmvFlag)
|
if (!aFmvFlag) {
|
||||||
{
|
for (int i = 0; i < (FRAMEQUEUESIZE-1) * numStreams; i++)
|
||||||
for(int i=0; i<(FRAMEQUEUESIZE-1) * numStreams; i++)
|
|
||||||
ReadFrame(aMovie);
|
ReadFrame(aMovie);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int BinkUpdateMovie(struct binkMovie* aMovie)
|
static int BinkUpdateMovie(struct binkMovie* aMovie)
|
||||||
{
|
{
|
||||||
if(!aMovie->avContext)
|
if(!aMovie->avContext)
|
||||||
|
@ -467,21 +415,15 @@ static int BinkUpdateMovie(struct binkMovie* aMovie)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !eof || playing;
|
return !eof || playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayBinkedFMV(char* filenamePtr, int volume)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
void PlayBinkedFMV(char *filenamePtr, int volume)
|
|
||||||
{
|
{
|
||||||
struct binkMovie movie;
|
struct binkMovie movie;
|
||||||
|
|
||||||
if (BinkStartMovie(&movie, filenamePtr, FALSE, FALSE, FALSE)) {
|
if (BinkStartMovie(&movie, filenamePtr, FALSE, FALSE, FALSE)) {
|
||||||
alSourcef(movie.alSource, AL_GAIN, PlatVolumeToGain(volume));
|
alSourcef(movie.alSource, AL_GAIN, PlatVolumeToGain(volume));
|
||||||
|
|
||||||
while (BinkUpdateMovie(&movie)) {
|
while (BinkUpdateMovie(&movie)) {
|
||||||
BinkRenderMovie(&movie);
|
BinkRenderMovie(&movie);
|
||||||
FlipBuffers();
|
FlipBuffers();
|
||||||
|
@ -501,94 +443,78 @@ void StartMenuBackgroundBink()
|
||||||
BinkStartMovie(&menuBackgroundMovie, "FMVs/Menubackground.bik", TRUE, FALSE, FALSE);
|
BinkStartMovie(&menuBackgroundMovie, "FMVs/Menubackground.bik", TRUE, FALSE, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int PlayMenuBackgroundBink()
|
int PlayMenuBackgroundBink()
|
||||||
{
|
{
|
||||||
ClearScreenToBlack();
|
ClearScreenToBlack();
|
||||||
if(BinkUpdateMovie(&menuBackgroundMovie))
|
if (BinkUpdateMovie(&menuBackgroundMovie)) {
|
||||||
{
|
|
||||||
BinkRenderMovie(&menuBackgroundMovie);
|
BinkRenderMovie(&menuBackgroundMovie);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EndMenuBackgroundBink()
|
void EndMenuBackgroundBink()
|
||||||
{
|
{
|
||||||
BinkReleaseMovie(&menuBackgroundMovie);
|
BinkReleaseMovie(&menuBackgroundMovie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
struct binkMovie musicMovie;
|
struct binkMovie musicMovie;
|
||||||
|
|
||||||
int StartMusicBink(char* filenamePtr, BOOL looping)
|
int StartMusicBink(char* filenamePtr, BOOL looping)
|
||||||
{
|
{
|
||||||
if(!SoundSys_IsOn())
|
if (!SoundSys_IsOn())
|
||||||
return 0;
|
return 0;
|
||||||
|
return BinkStartMovie(&musicMovie, filenamePtr, looping, FALSE, TRUE);
|
||||||
int ret = BinkStartMovie(&musicMovie, filenamePtr, looping, FALSE, TRUE);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int PlayMusicBink(int volume)
|
int PlayMusicBink(int volume)
|
||||||
{
|
{
|
||||||
if(!SoundSys_IsOn())
|
if (!SoundSys_IsOn())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if(!musicMovie.avContext)
|
if (!musicMovie.avContext)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if(!(musicMovie.audioStreamIndex>=0 && musicMovie.alInited))
|
if (musicMovie.audioStreamIndex < 0 || !musicMovie.alInited)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
alSourcef(musicMovie.alSource, AL_GAIN, PlatVolumeToGain(volume));
|
alSourcef(musicMovie.alSource, AL_GAIN, PlatVolumeToGain(volume));
|
||||||
for(int i=0; i<musicMovie.avContext->nb_streams * FRAMEQUEUESIZE; i++)
|
for (int i = 0; i < musicMovie.avContext->nb_streams * FRAMEQUEUESIZE; i++) {
|
||||||
{
|
|
||||||
int processedBuffers = 0;
|
int processedBuffers = 0;
|
||||||
alGetSourcei(musicMovie.alSource, AL_BUFFERS_PROCESSED, &processedBuffers);
|
alGetSourcei(musicMovie.alSource, AL_BUFFERS_PROCESSED, &processedBuffers);
|
||||||
if(processedBuffers + musicMovie.alNumFreeBuffers > 0)
|
if (processedBuffers + musicMovie.alNumFreeBuffers > 0)
|
||||||
{
|
if (!ReadFrame(&musicMovie))
|
||||||
if(!ReadFrame(&musicMovie))
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndMusicBink()
|
void EndMusicBink()
|
||||||
{
|
{
|
||||||
if(!SoundSys_IsOn())
|
if (SoundSys_IsOn())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BinkReleaseMovie(&musicMovie);
|
BinkReleaseMovie(&musicMovie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
FMVHandle CreateBinkFMV(char* filenamePtr)
|
FMVHandle CreateBinkFMV(char* filenamePtr)
|
||||||
{
|
{
|
||||||
struct binkMovie* movie = malloc(sizeof(struct binkMovie));
|
struct binkMovie* movie = malloc(sizeof(struct binkMovie));
|
||||||
BinkInitMovieStruct(movie);
|
BinkInitMovieStruct(movie);
|
||||||
|
|
||||||
if(!BinkStartMovie(movie, filenamePtr, FALSE, TRUE, FALSE))
|
if (!BinkStartMovie(movie, filenamePtr, FALSE, TRUE, FALSE)) {
|
||||||
{
|
|
||||||
free(movie);
|
free(movie);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return (FMVHandle)movie;
|
return (FMVHandle)movie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int UpdateBinkFMV(FMVHandle aFmvHandle, int volume)
|
int UpdateBinkFMV(FMVHandle aFmvHandle, int volume)
|
||||||
{
|
{
|
||||||
if(aFmvHandle==0)
|
if (aFmvHandle == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
struct binkMovie* movie = (struct binkMovie*)aFmvHandle;
|
struct binkMovie* movie = (struct binkMovie*)aFmvHandle;
|
||||||
|
@ -600,10 +526,9 @@ int UpdateBinkFMV(FMVHandle aFmvHandle, int volume)
|
||||||
return BinkUpdateMovie(movie);
|
return BinkUpdateMovie(movie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CloseBinkFMV(FMVHandle aFmvHandle)
|
void CloseBinkFMV(FMVHandle aFmvHandle)
|
||||||
{
|
{
|
||||||
if(aFmvHandle==0)
|
if (aFmvHandle == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct binkMovie* movie = (struct binkMovie*)aFmvHandle;
|
struct binkMovie* movie = (struct binkMovie*)aFmvHandle;
|
||||||
|
@ -611,18 +536,13 @@ void CloseBinkFMV(FMVHandle aFmvHandle)
|
||||||
free(movie);
|
free(movie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char* GetBinkFMVImage(FMVHandle aFmvHandle)
|
char* GetBinkFMVImage(FMVHandle aFmvHandle)
|
||||||
{
|
{
|
||||||
if(aFmvHandle==0)
|
if (aFmvHandle == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
struct binkMovie* movie = (struct binkMovie*)aFmvHandle;
|
struct binkMovie* movie = (struct binkMovie*)aFmvHandle;
|
||||||
|
|
||||||
if(!movie->videoScaleContext)
|
if(!movie->videoScaleContext)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return movie->videoScalePicture[0];
|
return movie->videoScalePicture[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
26
src/bink.h
26
src/bink.h
|
@ -1,15 +1,14 @@
|
||||||
#ifndef _BINK_H_
|
#ifndef BINK_H
|
||||||
#define _BINK_H_
|
#define BINK_H
|
||||||
|
|
||||||
extern BOOL BinkSys_Init();
|
#include "fixer.h"
|
||||||
extern void BinkSys_Release();
|
|
||||||
|
|
||||||
//--- intro/outro
|
//--- intro/outro
|
||||||
extern void PlayBinkedFMV(char *filenamePtr, int volume);
|
extern void PlayBinkedFMV(char* filenamePtr, int volume);
|
||||||
|
|
||||||
//--- menu background
|
//--- menu background
|
||||||
extern void StartMenuBackgroundBink();
|
extern void StartMenuBackgroundBink();
|
||||||
extern int PlayMenuBackgroundBink();
|
extern int PlayMenuBackgroundBink();
|
||||||
extern void EndMenuBackgroundBink();
|
extern void EndMenuBackgroundBink();
|
||||||
|
|
||||||
//---- music
|
//---- music
|
||||||
|
@ -17,15 +16,12 @@ extern int StartMusicBink(char* filenamePtr, BOOL looping);
|
||||||
extern int PlayMusicBink(int volume);
|
extern int PlayMusicBink(int volume);
|
||||||
extern void EndMusicBink();
|
extern void EndMusicBink();
|
||||||
|
|
||||||
|
|
||||||
//---- ingame fmv
|
//---- ingame fmv
|
||||||
typedef unsigned int FMVHandle;
|
typedef unsigned int FMVHandle;
|
||||||
|
|
||||||
extern FMVHandle CreateBinkFMV(char* filenamePtr);
|
extern FMVHandle CreateBinkFMV(char* filenamePtr);
|
||||||
extern int UpdateBinkFMV(FMVHandle aFmvHandle, int volume);
|
extern int UpdateBinkFMV(FMVHandle aFmvHandle, int volume);
|
||||||
extern void CloseBinkFMV(FMVHandle aFmvHandle);
|
extern void CloseBinkFMV(FMVHandle aFmvHandle);
|
||||||
extern char* GetBinkFMVImage(FMVHandle aFmvHandle);
|
extern char* GetBinkFMVImage(FMVHandle aFmvHandle);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif //_BINK_H_
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue