From 6f531ed8b05221d8c5f9ea5f35c51d1b250e1eeb Mon Sep 17 00:00:00 2001 From: martii Date: Fri, 2 Aug 2013 12:44:51 +0200 Subject: [PATCH] libeplayer3: cleanup --- libeplayer3/container/text_srt.c | 13 +-- libeplayer3/container/text_ssa.c | 17 ++-- libeplayer3/include/misc.h | 50 ++-------- libeplayer3/include/playback.h | 1 - libeplayer3/playback/playback.c | 151 ++++++------------------------- libeplayer3/tools/eplayer2.c | 2 +- 6 files changed, 47 insertions(+), 187 deletions(-) diff --git a/libeplayer3/container/text_srt.c b/libeplayer3/container/text_srt.c index c051b51..d6ac82b 100644 --- a/libeplayer3/container/text_srt.c +++ b/libeplayer3/container/text_srt.c @@ -34,7 +34,6 @@ #include #include -#include #include "common.h" #include "misc.h" #include "subtitle.h" @@ -302,7 +301,7 @@ static int SrtGetSubtitle(Context_t *context, char * Filename) { srt_printf(10, "folder: %s\n", FilenameFolder); - getExtension(copyFilename, &FilenameExtension); + FilenameExtension = getExtension(copyFilename); if (FilenameExtension == NULL) { @@ -331,16 +330,13 @@ static int SrtGetSubtitle(Context_t *context, char * Filename) { strcpy(subtitleFilename, (*dirzeiger).d_name); // Extension of Relativ Subtitle File Name - getExtension(subtitleFilename, &subtitleExtension); + subtitleExtension = getExtension(subtitleFilename); if (subtitleExtension == NULL) continue; if (strcmp(subtitleExtension, "srt") != 0) - { - free(subtitleExtension); continue; - } /* cut extension */ subtitleFilename[strlen(subtitleFilename) - strlen(subtitleExtension) - 1] = '\0'; @@ -371,13 +367,10 @@ static int SrtGetSubtitle(Context_t *context, char * Filename) { Subtitle.Id = i++, context->manager->subtitle->Command(context, MANAGER_ADD, &Subtitle); } - - free(subtitleExtension); } /* while */ closedir(dir); } /* if dir */ - free(FilenameExtension); free(copyFilename); srt_printf(10, "<\n"); @@ -430,7 +423,6 @@ static int SrtCloseSubtitle(Context_t *context __attribute__((unused))) { return cERR_SRT_NO_ERROR; } - static int SrtSwitchSubtitle(Context_t *context, int* arg) { int ret = cERR_SRT_NO_ERROR; @@ -447,6 +439,7 @@ static int SrtSwitchSubtitle(Context_t *context, int* arg) { hasThreadStarted = 1; } + return ret; } diff --git a/libeplayer3/container/text_ssa.c b/libeplayer3/container/text_ssa.c index 96d4b21..04430e2 100644 --- a/libeplayer3/container/text_ssa.c +++ b/libeplayer3/container/text_ssa.c @@ -68,11 +68,11 @@ if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x); #define TRACKWRAP 20 #define MAXLINELENGTH 1000 +static const char FILENAME[] = "text_ssa.c"; + //Buffer size used in getLine function. Do not set to value less than 1 !!! #define SSA_BUFFER_SIZE 14 -static const char FILENAME[] = "text_ssa.c"; - /* ***************************** */ /* Types */ /* ***************************** */ @@ -240,9 +240,11 @@ static char ** SsaManagerList(Context_t *context __attribute__((unused))) { if (Tracks != NULL) { char help[256]; int i = 0, j = 0; + tracklist = malloc(sizeof(char *) * ((TrackCount*2) + 1)); for (i = 0, j = 0; i < TrackCount; i++, j+=2) { + sprintf(help, "%d", Tracks[i].Id); tracklist[j] = strdup(help); tracklist[j+1] = strdup(Tracks[i].File); @@ -303,7 +305,7 @@ static int SsaGetSubtitle(Context_t *context, char * Filename) { ssa_printf(10, "folder: %s\n", FilenameFolder); - getExtension(copyFilename, &FilenameExtension); + FilenameExtension = getExtension(copyFilename); if (FilenameExtension == NULL) { @@ -332,16 +334,13 @@ static int SsaGetSubtitle(Context_t *context, char * Filename) { strcpy(subtitleFilename, (*dirzeiger).d_name); // Extension of Relativ Subtitle File Name - getExtension(subtitleFilename, &subtitleExtension); + subtitleExtension = getExtension(subtitleFilename); if (subtitleExtension == NULL) continue; if ( strcmp(subtitleExtension, "ssa") != 0 && strcmp(subtitleExtension, "ass") != 0 ) - { - free(subtitleExtension); continue; - } /* cut extension */ subtitleFilename[strlen(subtitleFilename) - strlen(subtitleExtension) - 1] = '\0'; @@ -372,17 +371,13 @@ static int SsaGetSubtitle(Context_t *context, char * Filename) { Subtitle.Id = i++; context->manager->subtitle->Command(context, MANAGER_ADD, &Subtitle); } - - free(subtitleExtension); } /* while */ closedir(dir); } /* if dir */ - free(FilenameExtension); free(copyFilename); ssa_printf(10, "<\n"); - return cERR_SSA_NO_ERROR; } diff --git a/libeplayer3/include/misc.h b/libeplayer3/include/misc.h index 9b819d0..bd248f2 100644 --- a/libeplayer3/include/misc.h +++ b/libeplayer3/include/misc.h @@ -37,48 +37,14 @@ void FlushBits(BitPacker_t * ld); /* MISC Functions */ /* ***************************** */ -static inline void getExtension(char * FILENAMEname, char ** extension) { - - int i = 0; - int stringlength; - - if (extension == NULL) - return; - - *extension = NULL; - - if (FILENAMEname == NULL) - return; - - stringlength = (int) strlen(FILENAMEname); - - for (i = 0; stringlength - i > 0; i++) { - if (FILENAMEname[stringlength - i - 1] == '.') { - *extension = strdup(FILENAMEname+(stringlength - i)); - break; - } - } -} - -static inline void getUPNPExtension(char * FILENAMEname, char ** extension) { - char* str; - - if (extension == NULL) - return; - - *extension = NULL; - - if (FILENAMEname == NULL) - return; - - str = strstr(FILENAMEname, "ext="); - - if (str != NULL) - { - *extension = strdup(str + strlen("ext=") + 1); - return; - } - *extension = NULL; +static inline char *getExtension(char * name) +{ + if (name) { + char *ext = strrchr(name, '.'); + if (ext) + return ext + 1; + } + return NULL; } /* the function returns the base name */ diff --git a/libeplayer3/include/playback.h b/libeplayer3/include/playback.h index 1ad2bca..02f1e07 100644 --- a/libeplayer3/include/playback.h +++ b/libeplayer3/include/playback.h @@ -11,7 +11,6 @@ typedef struct PlaybackHandler_s { unsigned char isFile; unsigned char isHttp; - unsigned char isUPNP; unsigned char isPlaying; unsigned char isPaused; diff --git a/libeplayer3/playback/playback.c b/libeplayer3/playback/playback.c index 7e73aac..c90bf0d 100644 --- a/libeplayer3/playback/playback.c +++ b/libeplayer3/playback/playback.c @@ -171,155 +171,60 @@ static int PlaybackOpen(Context_t *context, char * uri) { playback_printf(10, "URI=%s\n", uri); + if (context->playback->isPlaying) { // shouldn't happen + playback_err("playback already running\n"); + return cERR_PLAYBACK_ERROR; + } + + char * extension = NULL; + context->playback->uri = strdup(uri); - if (!context->playback->isPlaying) { - if (!strncmp("file://", uri, 7) || !strncmp("myts://", uri, 7)) { - char * extension = NULL; - context->playback->isFile = 1; - context->playback->isHttp = 0; - context->playback->isUPNP = 0; + context->playback->isFile = 0; + context->playback->isHttp = 0; + + if (!strncmp("file://", uri, 7) || !strncmp("myts://", uri, 7)) { + context->playback->isFile = 1; if (!strncmp("myts://", uri, 7)) { memcpy(context->playback->uri, "file", 4); - memcpy(uri, "file", 4); context->playback->noprobe = 1; } else context->playback->noprobe = 0; - getExtension(uri+7, &extension); - + extension = getExtension(context->playback->uri+7); if(!extension) return cERR_PLAYBACK_ERROR; - if(context->container->Command(context, CONTAINER_ADD, extension) < 0) - return cERR_PLAYBACK_ERROR; - if (context->container->selectedContainer != NULL) { - if(context->container->selectedContainer->Command(context, CONTAINER_INIT, uri) < 0) - return cERR_PLAYBACK_ERROR; - } else { - return cERR_PLAYBACK_ERROR; - } - - free(extension); - //CHECK FOR SUBTITLES if (context->container && context->container->textSrtContainer) - context->container->textSrtContainer->Command(context, CONTAINER_INIT, uri+7); + context->container->textSrtContainer->Command(context, CONTAINER_INIT, context->playback->uri+7); if (context->container && context->container->textSsaContainer) - context->container->textSsaContainer->Command(context, CONTAINER_INIT, uri+7); + context->container->textSsaContainer->Command(context, CONTAINER_INIT, context->playback->uri+7); if (context->container && context->container->assContainer) context->container->assContainer->Command(context, CONTAINER_INIT, NULL); - } else if (!strncmp("http://", uri, 7)) { -/* char * extension = NULL;*/ - context->playback->isFile = 0; + } else if (strstr(uri, "://")) { context->playback->isHttp = 1; - context->playback->isUPNP = 0; - - /* Hellmaster1024: http streams often do not have a propper ending like .mp3 so we let ffmpeg handle - all kind of http streams - if(!extension) - getExtension(uri+7, &extension); - - if(!extension) - return cERR_PLAYBACK_ERROR;*/ - - if(context->container->Command(context, CONTAINER_ADD, "mp3") < 0) - return cERR_PLAYBACK_ERROR; - - if (context->container->selectedContainer != NULL) - { - if(context->container->selectedContainer->Command(context, CONTAINER_INIT, context->playback->uri) < 0) - return cERR_PLAYBACK_ERROR; - } else - { - return cERR_PLAYBACK_ERROR; - } - - //free(extension); - } /* http */ - else if (!strncmp("mms://", uri, 6) || !strncmp("rtsp://", uri, 7) || !strncmp("rtmp://", uri, 7) || !strncmp("rtmpt://", uri, 8) || !strncmp("rtmpe://", uri, 8) || !strncmp("rtmpte://", uri, 9) || !strncmp("rtmps://", uri, 8) || !strncmp("rtp://", uri, 6)) { -/* char * extension = NULL; */ - context->playback->isFile = 0; - context->playback->isHttp = 1; - context->playback->isUPNP = 0; - /* Hellmaster1024: http streams often do not have a propper ending like .mp3 so we let ffmpeg handle - all kind of http streams - if (!extension) - getExtension(uri+6, &extension); - - if(!extension) - return cERR_PLAYBACK_ERROR;*/ - + extension = "mp3"; if (!strncmp("mms://", uri, 6)) { // mms is in reality called rtsp, and ffmpeg expects this char * tUri = (char*)malloc(strlen(uri) + 2); strncpy(tUri+1, uri, strlen(uri)+1); strncpy(tUri, "rtsp", 4); free(context->playback->uri); - context->playback->uri = strdup(tUri); - free(tUri); + context->playback->uri = tUri; } - - if(context->container->Command(context, CONTAINER_ADD, "mp3") < 0) - return cERR_PLAYBACK_ERROR; - - if (context->container->selectedContainer != NULL) - { - if(context->container->selectedContainer->Command(context, CONTAINER_INIT, context->playback->uri) < 0) - return cERR_PLAYBACK_ERROR; - } else - { - return cERR_PLAYBACK_ERROR; - } - - //free(extension); - } /* upnp */ - else if (!strncmp("upnp://", uri, 7)) { - char * extension = NULL; - context->playback->isFile = 0; - context->playback->isHttp = 0; - context->playback->isUPNP = 1; - - context->playback->uri += 7; /* jump over upnp:// */ - - getUPNPExtension(uri+7, &extension); - - if(!extension) - return cERR_PLAYBACK_ERROR; - - if(context->container->Command(context, CONTAINER_ADD, extension) < 0) - { - playback_err("container CONTAINER_ADD failed\n"); - return cERR_PLAYBACK_ERROR; - } - if (context->container->selectedContainer != NULL) { - if(context->container->selectedContainer->Command(context, CONTAINER_INIT, uri+7) < 0) - { - playback_err("container CONTAINER_INIT failed\n"); - return cERR_PLAYBACK_ERROR; - } - } else { - playback_err("selected container is null\n"); - return cERR_PLAYBACK_ERROR; - } - - free(extension); - - } /* upnp */ - else { - playback_err("Unknown stream (%s)\n", uri); - return cERR_PLAYBACK_ERROR; - } + } else { + playback_err("Unknown stream (%s)\n", uri); + return cERR_PLAYBACK_ERROR; } - else - { - playback_err("playback already running\n"); - return cERR_PLAYBACK_ERROR; - } + if ((context->container->Command(context, CONTAINER_ADD, extension) < 0) + || (!context->container->selectedContainer) + || (context->container->selectedContainer->Command(context, CONTAINER_INIT, context->playback->uri) < 0)) + return cERR_PLAYBACK_ERROR; playback_printf(10, "exiting with value 0\n"); @@ -336,7 +241,6 @@ static int PlaybackClose(Context_t *context) { playback_err("container delete failed\n"); } -//FIXME KILLED BY signal 7 or 11 if (context->container && context->container->textSrtContainer) context->container->textSrtContainer->Command(context, CONTAINER_DEL, NULL); @@ -355,6 +259,10 @@ static int PlaybackClose(Context_t *context) { context->playback->BackWard = 0; context->playback->SlowMotion = 0; context->playback->Speed = 0; + if(context->playback->uri) { + free(context->playback->uri); + context->playback->uri = NULL; + } playback_printf(10, "exiting with value %d\n", ret); @@ -1074,7 +982,6 @@ PlaybackHandler_t PlaybackHandler = { 0, 0, 0, - 0, 1, 0, &Command, diff --git a/libeplayer3/tools/eplayer2.c b/libeplayer3/tools/eplayer2.c index 476ed4f..874e865 100644 --- a/libeplayer3/tools/eplayer2.c +++ b/libeplayer3/tools/eplayer2.c @@ -170,7 +170,7 @@ int main(int argc,char* argv[]) { out.screen_width = xRes; out.screen_height = yRes; out.framebufferFD = fd; - out.destination = lfb; + out.destination = (uint32_t *)lfb; out.destStride = stride; out.shareFramebuffer = 1;