Massive amount of untested Singe code added.

This commit is contained in:
Scott Duensing 2019-12-04 21:32:31 -06:00
parent 90a24f67d4
commit fa91f8e281
5 changed files with 1493 additions and 95 deletions

View file

@ -37,10 +37,6 @@
#include "extensions.h" #include "extensions.h"
#define VERSION_STRING "v2.00"
#define COPYRIGHT_END_YEAR "2020"
typedef struct RatioS { typedef struct RatioS {
int aspectNum; int aspectNum;
int aspectDom; int aspectDom;
@ -85,6 +81,8 @@ void showUsage(char *name, char *message) {
// 00000000011111111112222222222333333333344444444445555555555666666666677777777778 // 00000000011111111112222222222333333333344444444445555555555666666666677777777778
// 12345678901234567890123456789012345678901234567890123456789012345678901234567890 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
utilSay(" -z, --scalefactor=PERCENT reduce screen size for overscan compensation"); utilSay(" -z, --scalefactor=PERCENT reduce screen size for overscan compensation");
utilSay(" -a, --aspect=N:D force aspect ratio");
utilSay(" -u, --stretch use ugly stretched video");
utilSay(" -x, --xresolution=VALUE specify horizontal resolution"); utilSay(" -x, --xresolution=VALUE specify horizontal resolution");
utilSay(" -y, --yresolution=VALUE specify vertical resolution"); utilSay(" -y, --yresolution=VALUE specify vertical resolution");
utilSay(" -h, --help this display"); utilSay(" -h, --help this display");
@ -103,19 +101,17 @@ int main(int argc, char *argv[]) {
int x = 0; int x = 0;
int err = 0; int err = 0;
int flags = 0; int flags = 0;
int thisFrame = -1;
int lastFrame = -1;
int videoHandle = -1;
int optionIndex = 0; int optionIndex = 0;
int bestResIndex = -1; int bestResIndex = -1;
int bestRatioIndex = -1; int bestRatioIndex = -1;
int aspectNum = -1;
int aspectDom = -1;
char *temp = NULL; char *temp = NULL;
char *aspectString = NULL;
float thisRatio = 0; float thisRatio = 0;
float bestRatio = 9999; float bestRatio = 9999;
bool running = true;
SDL_Window *window = NULL; SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL; SDL_Renderer *renderer = NULL;
SDL_Texture *texture = NULL;
SDL_DisplayMode mode; SDL_DisplayMode mode;
static struct option options[] = { static struct option options[] = {
{ "nomouse", no_argument, NULL, 'm' }, { "nomouse", no_argument, NULL, 'm' },
@ -124,11 +120,13 @@ int main(int argc, char *argv[]) {
{ "mutesound", no_argument, NULL, 's' }, { "mutesound", no_argument, NULL, 's' },
{ "fullscreen", no_argument, NULL, 'f' }, { "fullscreen", no_argument, NULL, 'f' },
{ "fullscreen_window", no_argument, NULL, 'w' }, { "fullscreen_window", no_argument, NULL, 'w' },
{ "stretch", no_argument, NULL, 'u' },
{ "datadir", optional_argument, NULL, 'd' }, { "datadir", optional_argument, NULL, 'd' },
{ "framefile", optional_argument, NULL, 'v' }, { "framefile", optional_argument, NULL, 'v' },
{ "volume_vldp", optional_argument, NULL, 'l' }, { "volume_vldp", optional_argument, NULL, 'l' },
{ "volume_nonlvdp", optional_argument, NULL, 'e' }, { "volume_nonlvdp", optional_argument, NULL, 'e' },
{ "scalefactor", optional_argument, NULL, 'z' }, { "scalefactor", optional_argument, NULL, 'z' },
{ "aspect", optional_argument, NULL, 'a' },
{ "xresolution", optional_argument, NULL, 'x' }, { "xresolution", optional_argument, NULL, 'x' },
{ "yresolution", optional_argument, NULL, 'y' }, { "yresolution", optional_argument, NULL, 'y' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
@ -167,7 +165,7 @@ int main(int argc, char *argv[]) {
while (true) { while (true) {
optionIndex = 0; optionIndex = 0;
opterr = 0; opterr = 0;
x = getopt_long(argc, argv, "mnsfwhd:v:l:e:z:x:y:", options, &optionIndex); x = getopt_long(argc, argv, "mnsfwha:d:v:l:e:z:x:y:", options, &optionIndex);
// Out of options? // Out of options?
if (x == -1) break; if (x == -1) break;
@ -199,6 +197,11 @@ int main(int argc, char *argv[]) {
_confFullScreenWindow = true; _confFullScreenWindow = true;
break; break;
// Ugly Stretched Video
case 'u':
_confStretchVideo = true;
break;
// Video File // Video File
case 'v': case 'v':
if (_confVideoFile) free(_confVideoFile); if (_confVideoFile) free(_confVideoFile);
@ -226,6 +229,12 @@ int main(int argc, char *argv[]) {
_confScaleFactor = atoi(optarg); _confScaleFactor = atoi(optarg);
break; break;
// Aspect
case 'a':
if (aspectString) free(aspectString);
aspectString = strdup(optarg);
break;
// X Resolution // X Resolution
case 'x': case 'x':
_confXResolution = atoi(optarg); _confXResolution = atoi(optarg);
@ -339,6 +348,27 @@ int main(int argc, char *argv[]) {
// Determine resolution if not specified // Determine resolution if not specified
if ((_confXResolution <= 0) || (_confYResolution <= 0)) { if ((_confXResolution <= 0) || (_confYResolution <= 0)) {
// Did they specify an aspect ratio?
if (aspectString) {
aspectNum = atoi(aspectString);
temp = strstr(aspectString, ":");
if (temp) {
temp++;
aspectDom = atoi(temp);
temp = NULL;
}
if ((aspectNum > 0) && (aspectDom > 0)) {
// Do we understand what they asked for?
x = 0;
while (modes[x].ratio.aspectNum != 0) {
if ((modes[x].ratio.aspectNum == aspectNum) && (modes[x].ratio.aspectDom == aspectDom)) {
bestRatioIndex = x;
break;
}
x++;
}
}
} else {
// Find our current aspect ratio // Find our current aspect ratio
x = 0; x = 0;
while (modes[x].ratio.aspectNum != 0) { while (modes[x].ratio.aspectNum != 0) {
@ -349,6 +379,8 @@ int main(int argc, char *argv[]) {
} }
x++; x++;
} }
}
if (bestRatioIndex < 0) showUsage(argv[0], "Unknown aspect ratio.");
x = 0; x = 0;
// Were both resolutions not specified? // Were both resolutions not specified?
if ((_confXResolution <= 0) && (_confYResolution <= 0)) { if ((_confXResolution <= 0) && (_confYResolution <= 0)) {
@ -436,65 +468,13 @@ int main(int argc, char *argv[]) {
err = Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 44100 /* freq */ * 16 /* bits */ * 2 /* channels */ * 2 /* seconds */); err = Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 44100 /* freq */ * 16 /* bits */ * 2 /* channels */ * 2 /* seconds */);
if (err != 0) utilDie("%s", Mix_GetError()); if (err != 0) utilDie("%s", Mix_GetError());
// Start our video playback system
if (videoInit()) utilDie("Unable to initialize video player.");
// Finish our setup // Finish our setup
SDL_DisableScreenSaver(); SDL_DisableScreenSaver();
if (videoInit()) utilDie("Unable to initialize video player."); singe(window, renderer);
videoHandle = videoLoad(_confVideoFile, _confDataDir, renderer);
if (videoHandle < 0) utilDie("Unable to load video file: %s", _confVideoFile);
videoPlay(videoHandle);
while (running) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYUP:
switch (event.key.keysym.sym) {
case SDLK_ESCAPE:
running = false;
break;
case SDLK_SPACE:
if (videoIsPlaying(videoHandle)) {
videoPause(videoHandle);
} else {
videoPlay(videoHandle);
}
break;
case SDLK_RIGHT:
videoSeek(videoHandle, lastFrame + 1);
break;
case SDLK_LEFT:
videoSeek(videoHandle, lastFrame - 1);
break;
case SDLK_UP:
videoSeek(videoHandle, lastFrame + 100);
break;
case SDLK_DOWN:
videoSeek(videoHandle, lastFrame - 100);
break;
}
break;
case SDL_QUIT:
running = 0;
break;
}
}
thisFrame = videoUpdate(videoHandle, &texture);
if ((thisFrame != lastFrame) && (thisFrame >= 0)) {
utilSay("Presenting frame %d", thisFrame);
lastFrame = thisFrame;
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
}
videoUnload(videoHandle);
// Shutdown // Shutdown
videoQuit(); videoQuit();

File diff suppressed because it is too large Load diff

View file

@ -24,10 +24,19 @@
#define SINGE_H #define SINGE_H
#include <SDL2/SDL.h>
#define SINGE_VERSION 2.00
#define VERSION_STRING "v2.00"
#define COPYRIGHT_END_YEAR "2020"
// Command line options // Command line options
extern char *_confVideoFile; extern char *_confVideoFile;
extern char *_confScriptFile; extern char *_confScriptFile;
extern char *_confDataDir; extern char *_confDataDir;
extern int _confStretchVideo;
extern int _confNoMouse; extern int _confNoMouse;
extern int _confNoStats; extern int _confNoStats;
extern int _confNoSound; extern int _confNoSound;
@ -40,4 +49,7 @@ extern int _confXResolution;
extern int _confYResolution; extern int _confYResolution;
void singe(SDL_Window *window, SDL_Renderer *renderer);
#endif // SINGE_H #endif // SINGE_H

View file

@ -25,7 +25,6 @@
#include "thirdparty/uthash.h" #include "thirdparty/uthash.h"
#include "common.h"
#include "util.h" #include "util.h"
#include "videoPlayer.h" #include "videoPlayer.h"
@ -154,7 +153,40 @@ int videoIsPlaying(int playerIndex) {
} }
int videoLoad(char *filename, char *indexPath, SDL_Renderer *renderer) { int videoGetFrame(int playerIndex) {
VideoPlayerT *v = NULL;
// Get our player structure
HASH_FIND_INT(_videoPlayerHash, &playerIndex, v);
if (!v) utilDie("No video player at index %d in videoGetHeight.", playerIndex);
return v->frame;
}
int videoGetHeight(int playerIndex) {
VideoPlayerT *v = NULL;
// Get our player structure
HASH_FIND_INT(_videoPlayerHash, &playerIndex, v);
if (!v) utilDie("No video player at index %d in videoGetHeight.", playerIndex);
return v->propFrame->EncodedHeight;
}
int videoGetWidth(int playerIndex) {
VideoPlayerT *v = NULL;
// Get our player structure
HASH_FIND_INT(_videoPlayerHash, &playerIndex, v);
if (!v) utilDie("No video player at index %d in videoGetWidth.", playerIndex);
return v->propFrame->EncodedWidth;
}
int videoLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer) {
char indexName[1024]; char indexName[1024];
int pixelFormats[2]; int pixelFormats[2];
int result = -1; int result = -1;
@ -232,10 +264,11 @@ int videoLoad(char *filename, char *indexPath, SDL_Renderer *renderer) {
// Create video texture // Create video texture
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
v->videoTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_STATIC, v->propFrame->EncodedWidth, v->propFrame->EncodedHeight); v->videoTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_STREAMING, v->propFrame->EncodedWidth, v->propFrame->EncodedHeight);
if (v->videoTexture == NULL) utilDie("%s", SDL_GetError()); if (v->videoTexture == NULL) utilDie("%s", SDL_GetError());
if (!stretchVideo) {
SDL_RenderSetLogicalSize(renderer, v->propFrame->EncodedWidth, v->propFrame->EncodedHeight); SDL_RenderSetLogicalSize(renderer, v->propFrame->EncodedWidth, v->propFrame->EncodedHeight);
}
// Determine audio format // Determine audio format
switch (v->audioProps->SampleFormat) { switch (v->audioProps->SampleFormat) {

View file

@ -26,10 +26,15 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "common.h"
int videoInit(void); int videoInit(void);
int videoIsPlaying(int playerIndex); int videoIsPlaying(int playerIndex);
int videoLoad(char *filename, char *indexPath, SDL_Renderer *renderer); int videoGetFrame(int playerIndex);
int videoGetHeight(int playerIndex);
int videoGetWidth(int playerIndex);
int videoLoad(char *filename, char *indexPath, bool stretchVideo, SDL_Renderer *renderer);
int videoPause(int playerIndex); int videoPause(int playerIndex);
int videoPlay(int playerIndex); int videoPlay(int playerIndex);
int videoQuit(void); int videoQuit(void);