diff --git a/libeplayer3/container/container.c b/libeplayer3/container/container.c index 5fb11cc..30ae8fd 100644 --- a/libeplayer3/container/container.c +++ b/libeplayer3/container/container.c @@ -44,46 +44,53 @@ if (debug_level >= level) printf(x); } while (0) static const char FILENAME[] = "container.c"; -static Container_t * AvailableContainer[] = { +static Container_t *AvailableContainer[] = { &FFMPEGContainer, NULL }; -static void printContainerCapabilities() { +static void printContainerCapabilities() +{ int i, j; container_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); container_printf(10, "Capabilities: "); for (i = 0; AvailableContainer[i] != NULL; i++) - for (j = 0; AvailableContainer[i]->Capabilities[j] != NULL; j++) - container_printf(10, "%s ", AvailableContainer[i]->Capabilities[j]); + for (j = 0; AvailableContainer[i]->Capabilities[j] != NULL; j++) + container_printf(10, "%s ", + AvailableContainer[i]->Capabilities[j]); container_printf(10, "\n"); } -static int selectContainer(Context_t *context, char * extension __attribute__((unused))) { +static int selectContainer(Context_t * context, char *extension + __attribute__ ((unused))) +{ #if 0 int i, j; int ret = -1; container_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - for (i = 0; AvailableContainer[i] != NULL; i++) - { - for (j = 0; AvailableContainer[i]->Capabilities[j] != NULL; j++) - if (!strcasecmp(AvailableContainer[i]->Capabilities[j], extension)) { - context->container->selectedContainer = AvailableContainer[i]; + for (i = 0; AvailableContainer[i] != NULL; i++) { + for (j = 0; AvailableContainer[i]->Capabilities[j] != NULL; j++) + if (!strcasecmp + (AvailableContainer[i]->Capabilities[j], extension)) { + context->container->selectedContainer = + AvailableContainer[i]; - container_printf(10, "Selected Container: %s\n", context->container->selectedContainer->Name); - ret = 0; - break; - } - if (ret == 0) - break; + container_printf(10, "Selected Container: %s\n", + context->container->selectedContainer-> + Name); + ret = 0; + break; + } + if (ret == 0) + break; } if (ret != 0) { - container_err("No Container found :-(\n"); + container_err("No Container found :-(\n"); } return ret; @@ -94,28 +101,30 @@ static int selectContainer(Context_t *context, char * extension __attribute__(( } -static int Command(void *_context, ContainerCmd_t command, void * argument) { - Context_t* context = (Context_t*) _context; +static int Command(void *_context, ContainerCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = 0; container_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - switch(command) { - case CONTAINER_ADD: { - ret = selectContainer(context, (char*) argument); - break; - } - case CONTAINER_CAPABILITIES: { - printContainerCapabilities(); - break; - } - case CONTAINER_DEL: { - context->container->selectedContainer = NULL; - break; - } + switch (command) { + case CONTAINER_ADD:{ + ret = selectContainer(context, (char *) argument); + break; + } + case CONTAINER_CAPABILITIES:{ + printContainerCapabilities(); + break; + } + case CONTAINER_DEL:{ + context->container->selectedContainer = NULL; + break; + } default: - container_err("%s::%s ContainerCmd %d not supported!\n", FILENAME, __FUNCTION__, command); - break; + container_err("%s::%s ContainerCmd %d not supported!\n", FILENAME, + __FUNCTION__, command); + break; } return ret; diff --git a/libeplayer3/container/container_ass.c b/libeplayer3/container/container_ass.c index 4f7890a..cd5e753 100644 --- a/libeplayer3/container/container_ass.c +++ b/libeplayer3/container/container_ass.c @@ -84,24 +84,23 @@ if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x); /* ***************************** */ typedef struct ass_s { - unsigned char* data; - int len; - unsigned char* extradata; - int extralen; - - long long int pts; - float duration; + unsigned char *data; + int len; + unsigned char *extradata; + int extralen; + + long long int pts; + float duration; } ass_t; -typedef struct region_s -{ +typedef struct region_s { unsigned int x; unsigned int y; unsigned int w; unsigned int h; - time_t undisplay; - - struct region_s* next; + time_t undisplay; + + struct region_s *next; } region_t; /* ***************************** */ @@ -121,17 +120,17 @@ static ASS_Renderer *ass_renderer; //static float ass_font_scale = 0.4; // was: 0.7 //static float ass_line_spacing = 0.4; // was: 0.7 -static unsigned int screen_width = 0; -static unsigned int screen_height = 0; -static uint32_t *destination = NULL; -static int destStride = 0; -static void (*framebufferBlit)(void) = NULL; +static unsigned int screen_width = 0; +static unsigned int screen_height = 0; +static uint32_t *destination = NULL; +static int destStride = 0; +static void (*framebufferBlit) (void) = NULL; static int needsBlit = 0; -static ASS_Track* ass_track = NULL; +static ASS_Track *ass_track = NULL; -static region_t* firstRegion = NULL; +static region_t *firstRegion = NULL; /* ***************************** */ /* Prototypes */ @@ -141,7 +140,9 @@ static region_t* firstRegion = NULL; /* MISC Functions */ /* ***************************** */ -void ass_msg_callback(int level __attribute__((unused)), const char *format, va_list va, void *ctx __attribute__((unused))) +void ass_msg_callback(int level + __attribute__ ((unused)), const char *format, + va_list va, void *ctx __attribute__ ((unused))) { int n; char *str; @@ -150,13 +151,14 @@ void ass_msg_callback(int level __attribute__((unused)), const char *format, va_ va_copy(dst, va); n = vsnprintf(NULL, 0, format, va); if (n > 0 && (str = malloc(n + 1))) { - vsnprintf(str, n + 1, format, dst); - ass_printf(100, "%s\n", str); - free(str); + vsnprintf(str, n + 1, format, dst); + ass_printf(100, "%s\n", str); + free(str); } } -static void getMutex(int line) { +static void getMutex(int line) +{ ass_printf(150, "%d requesting mutex\n", line); pthread_mutex_lock(&mutex); @@ -164,7 +166,8 @@ static void getMutex(int line) { ass_printf(150, "%d received mutex\n", line); } -static void releaseMutex(int line) { +static void releaseMutex(int line) +{ pthread_mutex_unlock(&mutex); ass_printf(150, "%d released mutex\n", line); @@ -178,46 +181,43 @@ static void releaseMutex(int line) { */ void releaseRegions() { - region_t* next, *old; - Writer_t* writer; + region_t *next, *old; + Writer_t *writer; if (firstRegion == NULL) - return; + return; writer = getDefaultFramebufferWriter(); - if (writer == NULL) - { - ass_err("no framebuffer writer found!\n"); + if (writer == NULL) { + ass_err("no framebuffer writer found!\n"); } next = firstRegion; - while (next) - { - if (writer) - { - WriterFBCallData_t out; - - ass_printf(100, "release: w %d h %d x %d y %d\n", - next->w, next->h, next->x, next->y); + while (next) { + if (writer) { + WriterFBCallData_t out; - out.data = NULL; - out.Width = next->w; - out.Height = next->h; - out.x = next->x; - out.y = next->y; + ass_printf(100, "release: w %d h %d x %d y %d\n", + next->w, next->h, next->x, next->y); - out.Screen_Width = screen_width; - out.Screen_Height = screen_height; - out.destination = destination; - out.destStride = destStride; + out.data = NULL; + out.Width = next->w; + out.Height = next->h; + out.x = next->x; + out.y = next->y; - writer->writeData(&out); - needsBlit = 1; - } - old = next; - next = next->next; - free(old); + out.Screen_Width = screen_width; + out.Screen_Height = screen_height; + out.destination = destination; + out.destStride = destStride; + + writer->writeData(&out); + needsBlit = 1; + } + old = next; + next = next->next; + free(old); } firstRegion = NULL; @@ -231,80 +231,77 @@ void releaseRegions() void checkRegions() { #define cDeltaTime 2 - region_t* next, *old, *prev; - Writer_t* writer; + region_t *next, *old, *prev; + Writer_t *writer; time_t now = time(NULL); - + if (firstRegion == NULL) - return; + return; writer = getDefaultFramebufferWriter(); - if (!writer) - { - ass_err("no framebuffer writer found!\n"); + if (!writer) { + ass_err("no framebuffer writer found!\n"); } prev = next = firstRegion; - while (next) - { - if (now > next->undisplay + cDeltaTime) - { - ass_printf(100, "undisplay: %ld > %ld\n", now, next->undisplay + cDeltaTime); + while (next) { + if (now > next->undisplay + cDeltaTime) { + ass_printf(100, "undisplay: %ld > %ld\n", now, + next->undisplay + cDeltaTime); - if (writer) - { - WriterFBCallData_t out; + if (writer) { + WriterFBCallData_t out; - ass_printf(100, "release: w %d h %d x %d y %d\n", - next->w, next->h, next->x, next->y); + ass_printf(100, "release: w %d h %d x %d y %d\n", + next->w, next->h, next->x, next->y); - out.data = NULL; - out.Width = next->w; - out.Height = next->h; - out.x = next->x; - out.y = next->y; - - out.Screen_Width = screen_width; - out.Screen_Height = screen_height; - out.destination = destination; - out.destStride = destStride; + out.data = NULL; + out.Width = next->w; + out.Height = next->h; + out.x = next->x; + out.y = next->y; - writer->writeData(&out); - needsBlit = 1; - } - - old = next; - next = prev->next = next->next; + out.Screen_Width = screen_width; + out.Screen_Height = screen_height; + out.destination = destination; + out.destStride = destStride; - if (old == firstRegion) - firstRegion = next; - free(old); - } else - { - prev = next; - next = next->next; - } + writer->writeData(&out); + needsBlit = 1; + } + + old = next; + next = prev->next = next->next; + + if (old == firstRegion) + firstRegion = next; + free(old); + } else { + prev = next; + next = next->next; + } } } /* store a display region for later release */ -void storeRegion(unsigned int x, unsigned int y, unsigned int w, unsigned int h, time_t undisplay) +void storeRegion(unsigned int x, unsigned int y, unsigned int w, + unsigned int h, time_t undisplay) { - region_t** new = &firstRegion; - + region_t **new = &firstRegion; + ass_printf(100, "%d %d %d %d %ld\n", x, y, w, h, undisplay); while (*new) new = &(*new)->next; - + *new = malloc(sizeof(region_t)); - (*new)->next = NULL; - (*new)->x = x; - (*new)->y = y; - (*new)->w = w; - (*new)->h = h; + (*new)->next = NULL; + (*new)->x = x; + (*new)->y = y; + (*new)->w = w; + (*new)->h = h; (*new)->undisplay = undisplay; } @@ -312,89 +309,89 @@ void storeRegion(unsigned int x, unsigned int y, unsigned int w, unsigned int h, /* Worker Thread */ /* **************************** */ -static void ASSThread(Context_t *context) { +static void ASSThread(Context_t * context) +{ char threadname[17]; strncpy(threadname, __func__, sizeof(threadname)); threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); - Writer_t* writer; - + prctl(PR_SET_NAME, (unsigned long) &threadname); + Writer_t *writer; + ass_printf(10, "\n"); - while ( context->playback->isCreationPhase ) - { - ass_err("Thread waiting for end of init phase...\n"); - usleep(1000); + while (context->playback->isCreationPhase) { + ass_err("Thread waiting for end of init phase...\n"); + usleep(1000); } - + ass_printf(10, "Running!\n"); writer = getDefaultFramebufferWriter(); - if (writer == NULL) - { - ass_err("no framebuffer writer found!\n"); + if (writer == NULL) { + ass_err("no framebuffer writer found!\n"); } - while ( context && context->playback && context->playback->isPlaying ) { + while (context && context->playback && context->playback->isPlaying) { - //IF MOVIE IS PAUSED, WAIT - if (context->playback->isPaused) { - ass_printf(20, "paused\n"); + //IF MOVIE IS PAUSED, WAIT + if (context->playback->isPaused) { + ass_printf(20, "paused\n"); - usleep(100000); - continue; - } + usleep(100000); + continue; + } - if (context->playback->isSeeking) { - ass_printf(10, "seeking\n"); + if (context->playback->isSeeking) { + ass_printf(10, "seeking\n"); - usleep(100000); - continue; - } + usleep(100000); + continue; + } - if ((isContainerRunning) && (ass_track)) - { - ASS_Image * img = NULL; - int change = 0; - unsigned long int playPts; - - if (context && context->playback) - { - if (context->playback->Command(context, PLAYBACK_PTS, &playPts) < 0) - continue; - } + if ((isContainerRunning) && (ass_track)) { + ASS_Image *img = NULL; + int change = 0; + unsigned long int playPts; - //FIXME: durch den sleep bleibt die cpu usage zw. 5 und 13%, ohne - // steigt sie bei Verwendung von subtiteln bis auf 95%. - // ich hoffe dadurch gehen keine subtitle verloren, wenn die playPts - // durch den sleep verschlafen wird. Besser wäre es den nächsten - // subtitel zeitpunkt zu bestimmen und solange zu schlafen. - usleep(10000); - if(!context->playback->mayWriteToFramebuffer) + if (context && context->playback) { + if (context->playback-> + Command(context, PLAYBACK_PTS, &playPts) < 0) + continue; + } + //FIXME: durch den sleep bleibt die cpu usage zw. 5 und 13%, ohne + // steigt sie bei Verwendung von subtiteln bis auf 95%. + // ich hoffe dadurch gehen keine subtitle verloren, wenn die playPts + // durch den sleep verschlafen wird. Besser wäre es den nächsten + // subtitel zeitpunkt zu bestimmen und solange zu schlafen. + usleep(10000); + if (!context->playback->mayWriteToFramebuffer) continue; - getMutex(__LINE__); + getMutex(__LINE__); checkRegions(); - if(ass_renderer && ass_track) - img = ass_render_frame(ass_renderer, ass_track, playPts / 90.0, &change); + if (ass_renderer && ass_track) + img = + ass_render_frame(ass_renderer, ass_track, + playPts / 90.0, &change); - ass_printf(150, "img %p pts %lu %f\n", img, playPts, playPts / 90.0); + ass_printf(150, "img %p pts %lu %f\n", img, playPts, + playPts / 90.0); - if(img && ass_renderer && ass_track) - { - /* the spec says, that if a new set of regions is present - * the complete display switches to the new state. So lets - * release the old regions on display. - */ - if (change != 0) - releaseRegions(); + if (img && ass_renderer && ass_track) { + /* the spec says, that if a new set of regions is present + * the complete display switches to the new state. So lets + * release the old regions on display. + */ + if (change != 0) + releaseRegions(); time_t now = time(NULL); time_t undisplay = now + 10; if (ass_track && ass_track->events) - undisplay = now + (ass_track->events->Duration + 500) / 90000; + undisplay = + now + (ass_track->events->Duration + 500) / 90000; ASS_Image *it; int x0 = screen_width - 1; @@ -402,85 +399,87 @@ static void ASSThread(Context_t *context) { int x1 = 0; int y1 = 0; for (it = img; it; it = it->next) { - if (it->w && it->h) { - if (it->dst_x < x0) - x0 = it->dst_x; - if (it->dst_y < y0) - y0 = it->dst_y; - if (it->dst_x + it->w > x1) - x1 = it->dst_x + it->w; - if (it->dst_y + it->h > y1) - y1 = it->dst_y + it->h; - } + if (it->w && it->h) { + if (it->dst_x < x0) + x0 = it->dst_x; + if (it->dst_y < y0) + y0 = it->dst_y; + if (it->dst_x + it->w > x1) + x1 = it->dst_x + it->w; + if (it->dst_y + it->h > y1) + y1 = it->dst_y + it->h; + } } - if (x1 > 0 && y1 > 0) - { - x1++; - y1++; - int x, y; - uint32_t *dst = destination + y0 * destStride/sizeof(uint32_t) + x0; - int destStrideDiff = destStride/sizeof(uint32_t) - (x1 - x0); - for (y = y0; y < y1; y++) { - for (x = x0; x < x1; x++) - *dst++ = 0x80808080; - dst += destStrideDiff; - } - storeRegion(x0, y0, x1 - x0, y1 - y0, undisplay); + if (x1 > 0 && y1 > 0) { + x1++; + y1++; + int x, y; + uint32_t *dst = + destination + y0 * destStride / sizeof(uint32_t) + + x0; + int destStrideDiff = + destStride / sizeof(uint32_t) - (x1 - x0); + for (y = y0; y < y1; y++) { + for (x = x0; x < x1; x++) + *dst++ = 0x80808080; + dst += destStrideDiff; + } + storeRegion(x0, y0, x1 - x0, y1 - y0, undisplay); + needsBlit = 1; + } + + while (context && context->playback + && context->playback->isPlaying && img) { + WriterFBCallData_t out; + + ass_printf(100, + "w %d h %d s %d x %d y %d c %d chg %d now %ld und %ld\n", + img->w, img->h, img->stride, img->dst_x, + img->dst_y, img->color, change, now, + undisplay); + + /* api docu said w and h can be zero which + * means image should not be rendered + */ + if ((img->w != 0) && (img->h != 0) && writer) { + out.data = img->bitmap; + out.Width = img->w; + out.Height = img->h; + out.Stride = img->stride; + out.x = img->dst_x; + out.y = img->dst_y; + out.color = img->color; + + out.Screen_Width = screen_width; + out.Screen_Height = screen_height; + out.destination = destination; + out.destStride = destStride; + + if (context && context->playback + && context->playback->isPlaying && writer) + writer->writeData(&out); + needsBlit = 1; + } + + /* Next image */ + img = img->next; } + } + releaseMutex(__LINE__); + } else { + usleep(1000); + } - while (context && context->playback && context->playback->isPlaying && img) - { - WriterFBCallData_t out; - - ass_printf(100, "w %d h %d s %d x %d y %d c %d chg %d now %ld und %ld\n", - img->w, img->h, img->stride, - img->dst_x, img->dst_y, img->color, - change, now, undisplay); - - /* api docu said w and h can be zero which - * means image should not be rendered - */ - if ((img->w != 0) && (img->h != 0) && writer) - { - out.data = img->bitmap; - out.Width = img->w; - out.Height = img->h; - out.Stride = img->stride; - out.x = img->dst_x; - out.y = img->dst_y; - out.color = img->color; - - out.Screen_Width = screen_width; - out.Screen_Height = screen_height; - out.destination = destination; - out.destStride = destStride; - - if(context && context->playback && context->playback->isPlaying && writer) - writer->writeData(&out); - - needsBlit = 1; - } - - /* Next image */ - img = img->next; - } - } - releaseMutex(__LINE__); - } else - { - usleep(1000); - } - if (needsBlit && framebufferBlit) framebufferBlit(); - needsBlit = 0; + needsBlit = 0; - /* cleanup no longer used but not overwritten regions */ + /* cleanup no longer used but not overwritten regions */ getMutex(__LINE__); - checkRegions(); + checkRegions(); releaseMutex(__LINE__); - } /* while */ + } /* while */ if (needsBlit && framebufferBlit) framebufferBlit(); @@ -496,7 +495,7 @@ static void ASSThread(Context_t *context) { /* Container part for ass */ /* **************************** */ -int container_ass_init(Context_t *context) +int container_ass_init(Context_t * context) { SubtitleOutputDef_t output; @@ -505,42 +504,45 @@ int container_ass_init(Context_t *context) ass_library = ass_library_init(); if (!ass_library) { - ass_err("ass_library_init failed!\n"); - return cERR_CONTAINER_ASS_ERROR; + ass_err("ass_library_init failed!\n"); + return cERR_CONTAINER_ASS_ERROR; } if (debug_level >= 100) - ass_set_message_cb(ass_library, ass_msg_callback, NULL); + ass_set_message_cb(ass_library, ass_msg_callback, NULL); + + ass_set_extract_fonts(ass_library, 1); + ass_set_style_overrides(ass_library, NULL); - ass_set_extract_fonts( ass_library, 1 ); - ass_set_style_overrides( ass_library, NULL ); - ass_renderer = ass_renderer_init(ass_library); if (!ass_renderer) { - ass_err("ass_renderer_init failed!\n"); + ass_err("ass_renderer_init failed!\n"); - if (ass_library) - ass_library_done(ass_library); - ass_library = NULL; + if (ass_library) + ass_library_done(ass_library); + ass_library = NULL; - return cERR_CONTAINER_ASS_ERROR; + return cERR_CONTAINER_ASS_ERROR; } - context->output->subtitle->Command(context, OUTPUT_GET_SUBTITLE_OUTPUT, &output); + context->output->subtitle->Command(context, OUTPUT_GET_SUBTITLE_OUTPUT, + &output); + + screen_width = output.screen_width; + screen_height = output.screen_height; + destination = output.destination; + destStride = output.destStride; + framebufferBlit = output.framebufferBlit; - screen_width = output.screen_width; - screen_height = output.screen_height; - destination = output.destination; - destStride = output.destStride; - framebufferBlit = output.framebufferBlit; - ass_printf(10, "width %d, height %d\n", screen_width, screen_height); ass_set_frame_size(ass_renderer, screen_width, screen_height); - ass_set_margins(ass_renderer, (int)(0.03 * screen_height), (int)(0.03 * screen_height) , - (int)(0.03 * screen_width ), (int)(0.03 * screen_width ) ); - + ass_set_margins(ass_renderer, (int) (0.03 * screen_height), + (int) (0.03 * screen_height), + (int) (0.03 * screen_width), + (int) (0.03 * screen_width)); + ass_set_use_margins(ass_renderer, 1); // ass_set_font_scale(ass_renderer, (ass_font_scale * screen_height) / 240.0); @@ -548,79 +550,79 @@ int container_ass_init(Context_t *context) // ass_set_line_spacing(ass_renderer, (ass_line_spacing * screen_height) / 240.0); ass_set_fonts(ass_renderer, ASS_FONT, "Arial", 0, NULL, 1); - ass_set_aspect_ratio( ass_renderer, 1.0, 1.0); + ass_set_aspect_ratio(ass_renderer, 1.0, 1.0); isContainerRunning = 1; return cERR_CONTAINER_ASS_NO_ERROR; } -int container_ass_process_data(Context_t *context __attribute__((unused)), SubtitleData_t* data) +int container_ass_process_data(Context_t * context + __attribute__ ((unused)), + SubtitleData_t * data) { int first_kiss; - + ass_printf(20, ">\n"); - if (!isContainerRunning) - { - ass_err("Container not running\n"); - return cERR_CONTAINER_ASS_ERROR; + if (!isContainerRunning) { + ass_err("Container not running\n"); + return cERR_CONTAINER_ASS_ERROR; } - if (ass_track == NULL) - { - first_kiss = 1; - ass_track = ass_new_track(ass_library); + if (ass_track == NULL) { + first_kiss = 1; + ass_track = ass_new_track(ass_library); - if (ass_track == NULL) - { - ass_err("error creating ass_track\n"); - return cERR_CONTAINER_ASS_ERROR; - } - ass_track->PlayResX = screen_width; - ass_track->PlayResY = screen_height; + if (ass_track == NULL) { + ass_err("error creating ass_track\n"); + return cERR_CONTAINER_ASS_ERROR; + } + ass_track->PlayResX = screen_width; + ass_track->PlayResY = screen_height; } - if ((data->extradata) && (first_kiss)) - { - ass_printf(30,"processing private %d bytes\n",data->extralen); - ass_process_codec_private(ass_track, (char*) data->extradata, data->extralen); - ass_printf(30,"processing private done\n"); + if ((data->extradata) && (first_kiss)) { + ass_printf(30, "processing private %d bytes\n", data->extralen); + ass_process_codec_private(ass_track, (char *) data->extradata, + data->extralen); + ass_printf(30, "processing private done\n"); } - if (data->data) - { - ass_printf(30,"processing data %d bytes\n",data->len); - ass_process_data(ass_track, (char*) data->data, data->len); - ass_printf(30,"processing data done\n"); + if (data->data) { + ass_printf(30, "processing data %d bytes\n", data->len); + ass_process_data(ass_track, (char *) data->data, data->len); + ass_printf(30, "processing data done\n"); } return cERR_CONTAINER_ASS_NO_ERROR; } -static int container_ass_stop(Context_t *context __attribute__((unused))) { +static int container_ass_stop(Context_t * context __attribute__ ((unused))) +{ int ret = cERR_CONTAINER_ASS_NO_ERROR; int wait_time = 20; - Writer_t* writer; + Writer_t *writer; ass_printf(10, "\n"); - if (!isContainerRunning) - { - ass_err("Container not running\n"); - return cERR_CONTAINER_ASS_ERROR; + if (!isContainerRunning) { + ass_err("Container not running\n"); + return cERR_CONTAINER_ASS_ERROR; } - while ( (hasPlayThreadStarted != 0) && (--wait_time) > 0 ) { - ass_printf(10, "Waiting for ass thread to terminate itself, will try another %d times\n", wait_time); + while ((hasPlayThreadStarted != 0) && (--wait_time) > 0) { + ass_printf(10, + "Waiting for ass thread to terminate itself, will try another %d times\n", + wait_time); - usleep(100000); + usleep(100000); } if (wait_time == 0) { - ass_err( "Timeout waiting for thread!\n"); + ass_err("Timeout waiting for thread!\n"); - ret = cERR_CONTAINER_ASS_ERROR; + ret = cERR_CONTAINER_ASS_ERROR; } getMutex(__LINE__); @@ -628,18 +630,18 @@ static int container_ass_stop(Context_t *context __attribute__((unused))) { releaseRegions(); if (ass_track) - ass_free_track(ass_track); + ass_free_track(ass_track); ass_track = NULL; if (ass_renderer) - ass_renderer_done(ass_renderer); + ass_renderer_done(ass_renderer); ass_renderer = NULL; if (ass_library) - ass_library_done(ass_library); + ass_library_done(ass_library); ass_library = NULL; - + isContainerRunning = 0; hasPlayThreadStarted = 0; @@ -647,7 +649,7 @@ static int container_ass_stop(Context_t *context __attribute__((unused))) { writer = getDefaultFramebufferWriter(); if (writer) { - writer->reset(); + writer->reset(); } releaseMutex(__LINE__); @@ -656,7 +658,8 @@ static int container_ass_stop(Context_t *context __attribute__((unused))) { return ret; } -static int container_ass_switch_subtitle(Context_t* context, int* arg __attribute__((unused))) +static int container_ass_switch_subtitle(Context_t * context, int *arg + __attribute__ ((unused))) { int error; int ret = cERR_CONTAINER_ASS_NO_ERROR; @@ -664,39 +667,38 @@ static int container_ass_switch_subtitle(Context_t* context, int* arg __attribut ass_printf(10, "\n"); - if (!isContainerRunning) - { - ass_err("Container not running\n"); - return cERR_CONTAINER_ASS_ERROR; + if (!isContainerRunning) { + ass_err("Container not running\n"); + return cERR_CONTAINER_ASS_ERROR; } - if ( context && context->playback && context->playback->isPlaying ) { - ass_printf(10, "is Playing\n"); - } - else { - ass_printf(10, "is NOT Playing\n"); + if (context && context->playback && context->playback->isPlaying) { + ass_printf(10, "is Playing\n"); + } else { + ass_printf(10, "is NOT Playing\n"); } if (hasPlayThreadStarted == 0) { - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - if((error = pthread_create(&PlayThread, &attr, (void *)&ASSThread, context)) != 0) { - ass_printf(10, "Error creating thread, error:%d:%s\n", error,strerror(error)); + if ((error = + pthread_create(&PlayThread, &attr, (void *) &ASSThread, + context)) != 0) { + ass_printf(10, "Error creating thread, error:%d:%s\n", error, + strerror(error)); - hasPlayThreadStarted = 0; - ret = cERR_CONTAINER_ASS_ERROR; - } - else { - ass_printf(10, "Created thread\n"); + hasPlayThreadStarted = 0; + ret = cERR_CONTAINER_ASS_ERROR; + } else { + ass_printf(10, "Created thread\n"); - hasPlayThreadStarted = 1; - } - } - else { - ass_printf(10, "A thread already exists!\n"); + hasPlayThreadStarted = 1; + } + } else { + ass_printf(10, "A thread already exists!\n"); - ret = cERR_CONTAINER_ASS_ERROR; + ret = cERR_CONTAINER_ASS_ERROR; } getMutex(__LINE__); @@ -707,48 +709,47 @@ static int container_ass_switch_subtitle(Context_t* context, int* arg __attribut * process_data is called. */ if (ass_track) - ass_free_track(ass_track); + ass_free_track(ass_track); ass_track = NULL; releaseMutex(__LINE__); ass_printf(10, "exiting with value %d\n", ret); - + return ret; } -static int Command(void *_context, ContainerCmd_t command, void * argument) +static int Command(void *_context, ContainerCmd_t command, void *argument) { - Context_t *context = (Context_t*) _context; + Context_t *context = (Context_t *) _context; int ret = cERR_CONTAINER_ASS_NO_ERROR; ass_printf(50, "Command %d\n", command); - switch(command) - { - case CONTAINER_INIT: { - ret = container_ass_init(context); - break; - } - case CONTAINER_STOP: { - ret = container_ass_stop(context); - break; - } - case CONTAINER_SWITCH_SUBTITLE: { - ret = container_ass_switch_subtitle(context, (int*) argument); - break; - } - case CONTAINER_DATA: { - SubtitleData_t* data = (SubtitleData_t*) argument; - ret = container_ass_process_data(context, data); - break; - } + switch (command) { + case CONTAINER_INIT:{ + ret = container_ass_init(context); + break; + } + case CONTAINER_STOP:{ + ret = container_ass_stop(context); + break; + } + case CONTAINER_SWITCH_SUBTITLE:{ + ret = container_ass_switch_subtitle(context, (int *) argument); + break; + } + case CONTAINER_DATA:{ + SubtitleData_t *data = (SubtitleData_t *) argument; + ret = container_ass_process_data(context, data); + break; + } default: - ass_err("ContainerCmd %d not supported!\n", command); - ret = cERR_CONTAINER_ASS_ERROR; - break; + ass_err("ContainerCmd %d not supported!\n", command); + ret = cERR_CONTAINER_ASS_ERROR; + break; } ass_printf(50, "exiting with value %d\n", ret); @@ -756,7 +757,7 @@ static int Command(void *_context, ContainerCmd_t command, void * argument) return ret; } -static char *ASS_Capabilities[] = {"ass", NULL }; +static char *ASS_Capabilities[] = { "ass", NULL }; Container_t ASSContainer = { "ASS", diff --git a/libeplayer3/container/container_ffmpeg.c b/libeplayer3/container/container_ffmpeg.c index 5688cb6..1371b43 100644 --- a/libeplayer3/container/container_ffmpeg.c +++ b/libeplayer3/container/container_ffmpeg.c @@ -88,7 +88,7 @@ if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x); #define cERR_CONTAINER_FFMPEG_ERR -9 #define cERR_CONTAINER_FFMPEG_END_OF_FILE -10 -static const char* FILENAME = "container_ffmpeg.c"; +static const char *FILENAME = "container_ffmpeg.c"; /* ***************************** */ /* Types */ @@ -102,7 +102,7 @@ static const char* FILENAME = "container_ffmpeg.c"; static pthread_t PlayThread; static int hasPlayThreadStarted = 0; -static AVFormatContext* avContext = NULL; +static AVFormatContext *avContext = NULL; static unsigned char isContainerRunning = 0; @@ -113,87 +113,88 @@ float seek_sec_abs = 0.0, seek_sec_rel = 0.0; /* ***************************** */ /* Prototypes */ /* ***************************** */ -static int container_ffmpeg_seek(Context_t *context, float sec, int absolute); +static int container_ffmpeg_seek(Context_t * context, float sec, + int absolute); /* ***************************** */ /* MISC Functions */ /* ***************************** */ -static char* Codec2Encoding(AVCodecContext *codec, int* version) +static char *Codec2Encoding(AVCodecContext * codec, int *version) { - fprintf(stderr, "Codec ID: %ld (%.8lx)\n", (long)codec->codec_id, (long)codec->codec_id); - switch (codec->codec_id) - { + fprintf(stderr, "Codec ID: %ld (%.8lx)\n", (long) codec->codec_id, + (long) codec->codec_id); + switch (codec->codec_id) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: - return "V_MPEG1"; + return "V_MPEG1"; case AV_CODEC_ID_H263: case AV_CODEC_ID_H263P: case AV_CODEC_ID_H263I: - return "V_H263"; + return "V_H263"; case AV_CODEC_ID_FLV1: - return "V_FLV"; + return "V_FLV"; case AV_CODEC_ID_VP5: case AV_CODEC_ID_VP6: case AV_CODEC_ID_VP6F: - return "V_VP6"; + return "V_VP6"; case AV_CODEC_ID_RV10: case AV_CODEC_ID_RV20: - return "V_RMV"; + return "V_RMV"; case AV_CODEC_ID_MPEG4: case AV_CODEC_ID_MSMPEG4V1: case AV_CODEC_ID_MSMPEG4V2: case AV_CODEC_ID_MSMPEG4V3: - return "V_MSCOMP"; + return "V_MSCOMP"; case AV_CODEC_ID_WMV1: - *version = 1; - return "V_WMV"; + *version = 1; + return "V_WMV"; case AV_CODEC_ID_WMV2: - *version = 2; - return "V_WMV"; + *version = 2; + return "V_WMV"; case AV_CODEC_ID_WMV3: - *version = 3; - return "V_WMV"; + *version = 3; + return "V_WMV"; case AV_CODEC_ID_VC1: - return "V_VC1"; + return "V_VC1"; case AV_CODEC_ID_H264: - return "V_MPEG4/ISO/AVC"; + return "V_MPEG4/ISO/AVC"; case AV_CODEC_ID_AVS: - return "V_AVS"; + return "V_AVS"; case AV_CODEC_ID_MP2: - return "A_MPEG/L3"; + return "A_MPEG/L3"; case AV_CODEC_ID_MP3: - return "A_MP3"; + return "A_MP3"; case AV_CODEC_ID_AC3: - return "A_AC3"; + return "A_AC3"; case AV_CODEC_ID_EAC3: - return "A_EAC3"; + return "A_EAC3"; case AV_CODEC_ID_DTS: - return "A_DTS"; + return "A_DTS"; #if 0 case AV_CODEC_ID_AAC: - return "A_AAC"; + return "A_AAC"; case AV_CODEC_ID_WMAV1: case AV_CODEC_ID_WMAV2: case AV_CODEC_ID_WMAPRO: - return "A_WMA"; + return "A_WMA"; case AV_CODEC_ID_MLP: - return "A_MLP"; + return "A_MLP"; case AV_CODEC_ID_RA_144: - return "A_RMA"; + return "A_RMA"; case AV_CODEC_ID_RA_288: - return "A_RMA"; + return "A_RMA"; case AV_CODEC_ID_VORBIS: - return "A_VORBIS"; + return "A_VORBIS"; case AV_CODEC_ID_FLAC: - return return "A_FLAC"; + return return "A_FLAC"; case AV_CODEC_ID_PCM_S16LE: return "A_PCM"; #endif /* subtitle */ case AV_CODEC_ID_SSA: - return "S_TEXT/ASS"; /* Hellmaster1024: seems to be ASS instead of SSA */ - case AV_CODEC_ID_TEXT: /* Hellmaster1024: i dont have most of this, but lets hope it is normal text :-) */ + return "S_TEXT/ASS"; /* Hellmaster1024: seems to be ASS instead of SSA */ + case AV_CODEC_ID_TEXT: /* Hellmaster1024: i dont have most of this, but lets hope it is normal text :-) */ case AV_CODEC_ID_DVD_SUBTITLE: case AV_CODEC_ID_DVB_SUBTITLE: case AV_CODEC_ID_XSUB: @@ -201,105 +202,109 @@ static char* Codec2Encoding(AVCodecContext *codec, int* version) case AV_CODEC_ID_HDMV_PGS_SUBTITLE: case AV_CODEC_ID_DVB_TELETEXT: case AV_CODEC_ID_SRT: - return "S_TEXT/SRT"; /* fixme */ + return "S_TEXT/SRT"; /* fixme */ default: // Default to injected-pcm for unhandled audio types. if (codec->codec_type == AVMEDIA_TYPE_AUDIO) - return "A_IPCM"; - ffmpeg_err("Codec ID %ld (%.8lx) not found\n", (long)codec->codec_id, (long)codec->codec_id); + return "A_IPCM"; + ffmpeg_err("Codec ID %ld (%.8lx) not found\n", + (long) codec->codec_id, (long) codec->codec_id); } return NULL; } -long long int calcPts(AVStream* stream, int64_t pts) +long long int calcPts(AVStream * stream, int64_t pts) { - if (!stream) - { - ffmpeg_err("stream / packet null\n"); - return INVALID_PTS_VALUE; + if (!stream) { + ffmpeg_err("stream / packet null\n"); + return INVALID_PTS_VALUE; } - if(pts == AV_NOPTS_VALUE) - pts = INVALID_PTS_VALUE; + if (pts == AV_NOPTS_VALUE) + pts = INVALID_PTS_VALUE; else if (avContext->start_time == AV_NOPTS_VALUE) - pts = 90000.0 * (double)pts * av_q2d(stream->time_base); + pts = 90000.0 * (double) pts *av_q2d(stream->time_base); else - pts = 90000.0 * (double)pts * av_q2d(stream->time_base) - 90000.0 * avContext->start_time / AV_TIME_BASE; + pts = + 90000.0 * (double) pts *av_q2d(stream->time_base) - + 90000.0 * avContext->start_time / AV_TIME_BASE; if (pts & 0x8000000000000000ull) - pts = INVALID_PTS_VALUE; + pts = INVALID_PTS_VALUE; return pts; } /*Hellmaster1024: get the Duration of the subtitle from the SSA line*/ -float getDurationFromSSALine(unsigned char* line){ - int i,h,m,s,ms; - char* Text = strdup((char*) line); - char* ptr1; - char* ptr[10]; +float getDurationFromSSALine(unsigned char *line) +{ + int i, h, m, s, ms; + char *Text = strdup((char *) line); + char *ptr1; + char *ptr[10]; long int msec; ptr1 = Text; - ptr[0]=Text; - for (i=0; i < 3 && *ptr1 != '\0'; ptr1++) { - if (*ptr1 == ',') { - ptr[++i]=ptr1+1; - *ptr1 = '\0'; - } + ptr[0] = Text; + for (i = 0; i < 3 && *ptr1 != '\0'; ptr1++) { + if (*ptr1 == ',') { + ptr[++i] = ptr1 + 1; + *ptr1 = '\0'; + } } - sscanf(ptr[2],"%d:%d:%d.%d",&h,&m,&s,&ms); - msec = (ms*10) + (s*1000) + (m*60*1000) + (h*24*60*1000); - sscanf(ptr[1],"%d:%d:%d.%d",&h,&m,&s,&ms); - msec -= (ms*10) + (s*1000) + (m*60*1000) + (h*24*60*1000); + sscanf(ptr[2], "%d:%d:%d.%d", &h, &m, &s, &ms); + msec = (ms * 10) + (s * 1000) + (m * 60 * 1000) + (h * 24 * 60 * 1000); + sscanf(ptr[1], "%d:%d:%d.%d", &h, &m, &s, &ms); + msec -= + (ms * 10) + (s * 1000) + (m * 60 * 1000) + (h * 24 * 60 * 1000); ffmpeg_printf(10, "%s %s %f\n", ptr[2], ptr[1], (float) msec / 1000.0); free(Text); - return (float)msec/1000.0; + return (float) msec / 1000.0; } /* search for metatdata in context and stream * and map it to our metadata. */ -static char* searchMeta(AVDictionary * metadata, char* ourTag) +static char *searchMeta(AVDictionary * metadata, char *ourTag) { - AVDictionaryEntry *tag = NULL; - int i = 0; + AVDictionaryEntry *tag = NULL; + int i = 0; - while (metadata_map[i] != NULL) - { - if (strcmp(ourTag, metadata_map[i]) == 0) - { - while ((tag = av_dict_get(metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) - { - if (strcmp(tag->key, metadata_map[ i + 1 ]) == 0) - { - return tag->value; - } - } - } - i++; - } + while (metadata_map[i] != NULL) { + if (strcmp(ourTag, metadata_map[i]) == 0) { + while ((tag = + av_dict_get(metadata, "", tag, + AV_DICT_IGNORE_SUFFIX))) { + if (strcmp(tag->key, metadata_map[i + 1]) == 0) { + return tag->value; + } + } + } + i++; + } - return NULL; + return NULL; } /* **************************** */ /* Worker Thread */ /* **************************** */ -static void FFMPEGThread(Context_t *context) { +static void FFMPEGThread(Context_t * context) +{ char threadname[17]; strncpy(threadname, __func__, sizeof(threadname)); threadname[16] = 0; - prctl (PR_SET_NAME, (unsigned long)&threadname); + prctl(PR_SET_NAME, (unsigned long) &threadname); hasPlayThreadStarted = 1; - int64_t lastPts = -1, currentVideoPts = -1, currentAudioPts = -1, showtime = 0, bofcount = 0; + int64_t lastPts = -1, currentVideoPts = -1, currentAudioPts = + -1, showtime = 0, bofcount = 0; off_t lastPos = -1; AudioVideoOut_t avOut; @@ -312,516 +317,594 @@ static void FFMPEGThread(Context_t *context) { ffmpeg_printf(10, "\n"); - while ( context->playback->isCreationPhase ) - { - ffmpeg_err("Thread waiting for end of init phase...\n"); - usleep(1000); + while (context->playback->isCreationPhase) { + ffmpeg_err("Thread waiting for end of init phase...\n"); + usleep(1000); } ffmpeg_printf(10, "Running!\n"); - while ( context && context->playback && context->playback->isPlaying && !context->playback->abortRequested ) { + while (context && context->playback && context->playback->isPlaying + && !context->playback->abortRequested) { - //IF MOVIE IS PAUSED, WAIT - if (context->playback->isPaused) { - ffmpeg_printf(20, "paused\n"); + //IF MOVIE IS PAUSED, WAIT + if (context->playback->isPaused) { + ffmpeg_printf(20, "paused\n"); - usleep(100000); - continue; - } + usleep(100000); + continue; + } if (!context->playback || !context->playback->isPlaying) - continue; + continue; int seek_target_flag = 0; int64_t seek_target = INT64_MIN; if (seek_sec_rel != 0.0) { - if (avContext->iformat->flags & AVFMT_TS_DISCONT) { - float br = (avContext->bit_rate) ? br = avContext->bit_rate / 8.0 : 180000.0; - seek_target_flag = AVSEEK_FLAG_BYTE; - seek_target = avio_tell(avContext->pb) + seek_sec_rel * br; - } else { - lastPts = (currentVideoPts > 0) ? currentVideoPts : currentAudioPts; - if (lastPts > 0) - seek_target = ((currentVideoPts > 0) ? currentVideoPts : currentAudioPts) + seek_sec_rel * AV_TIME_BASE; - } - seek_sec_rel = 0.0; - lastPts = -1; - lastPos = -1; + if (avContext->iformat->flags & AVFMT_TS_DISCONT) { + float br = (avContext->bit_rate) ? br = + avContext->bit_rate / 8.0 : 180000.0; + seek_target_flag = AVSEEK_FLAG_BYTE; + seek_target = avio_tell(avContext->pb) + seek_sec_rel * br; + } else { + lastPts = + (currentVideoPts > + 0) ? currentVideoPts : currentAudioPts; + if (lastPts > 0) + seek_target = + ((currentVideoPts > + 0) ? currentVideoPts : currentAudioPts) + + seek_sec_rel * AV_TIME_BASE; + } + seek_sec_rel = 0.0; + lastPts = -1; + lastPos = -1; } else if (seek_sec_abs != 0.0) { - if (avContext->iformat->flags & AVFMT_TS_DISCONT) { - float br = (avContext->bit_rate) ? br = avContext->bit_rate / 8.0 : 180000.0; - seek_target_flag = AVSEEK_FLAG_BYTE; - seek_target = seek_sec_abs * br; - } else { - seek_target = seek_sec_abs * AV_TIME_BASE; - } - seek_sec_abs = 0.0; - lastPts = -1; - lastPos = -1; + if (avContext->iformat->flags & AVFMT_TS_DISCONT) { + float br = (avContext->bit_rate) ? br = + avContext->bit_rate / 8.0 : 180000.0; + seek_target_flag = AVSEEK_FLAG_BYTE; + seek_target = seek_sec_abs * br; + } else { + seek_target = seek_sec_abs * AV_TIME_BASE; + } + seek_sec_abs = 0.0; + lastPts = -1; + lastPos = -1; } else if (context->playback->BackWard && av_gettime() >= showtime) { - context->output->Command(context, OUTPUT_CLEAR, "video"); + context->output->Command(context, OUTPUT_CLEAR, "video"); - if(bofcount == 1) { - showtime = av_gettime(); - usleep(100000); - continue; - } + if (bofcount == 1) { + showtime = av_gettime(); + usleep(100000); + continue; + } - if (avContext->iformat->flags & AVFMT_TS_DISCONT) { - if (lastPos < 0) - lastPos = avio_tell(avContext->pb); + if (avContext->iformat->flags & AVFMT_TS_DISCONT) { + if (lastPos < 0) + lastPos = avio_tell(avContext->pb); - if (lastPos > 0) { - float br; - if (avContext->bit_rate) - br = avContext->bit_rate / 8.0; - else - br = 180000.0; - lastPos += context->playback->Speed * 8 * br; - seek_target_flag = AVSEEK_FLAG_BYTE; - seek_target = lastPos; - } - } else { - if (lastPts < 0) - lastPts = (currentVideoPts > 0) ? currentVideoPts : currentAudioPts; - - if (lastPts > 0) { - lastPts += context->playback->Speed * 8 * AV_TIME_BASE; - seek_target = lastPts; - } + if (lastPos > 0) { + float br; + if (avContext->bit_rate) + br = avContext->bit_rate / 8.0; + else + br = 180000.0; + lastPos += context->playback->Speed * 8 * br; + seek_target_flag = AVSEEK_FLAG_BYTE; + seek_target = lastPos; } - showtime = av_gettime() + 300000; //jump back every 300ms + } else { + if (lastPts < 0) + lastPts = + (currentVideoPts > + 0) ? currentVideoPts : currentAudioPts; + + if (lastPts > 0) { + lastPts += context->playback->Speed * 8 * AV_TIME_BASE; + seek_target = lastPts; + } + } + showtime = av_gettime() + 300000; //jump back every 300ms } else { - bofcount = 0; - if (!context->playback->BackWard) - lastPts = -1, lastPos = -1; + bofcount = 0; + if (!context->playback->BackWard) + lastPts = -1, lastPos = -1; } if (seek_target > INT64_MIN) { - int res; - if (seek_target < 0) - seek_target = 0; - res = avformat_seek_file(avContext, -1, INT64_MIN, seek_target, INT64_MAX, seek_target_flag); + int res; + if (seek_target < 0) + seek_target = 0; + res = + avformat_seek_file(avContext, -1, INT64_MIN, seek_target, + INT64_MAX, seek_target_flag); - if (res < 0 && context->playback->BackWard) - bofcount = 1; - seek_target = INT64_MIN; - restart_audio_resampling = 1; - latestPts = 0; + if (res < 0 && context->playback->BackWard) + bofcount = 1; + seek_target = INT64_MIN; + restart_audio_resampling = 1; + latestPts = 0; - // flush streams - unsigned int i; - for (i = 0; i < avContext->nb_streams; i++) - if (avContext->streams[i]->codec && avContext->streams[i]->codec->codec) - avcodec_flush_buffers(avContext->streams[i]->codec); + // flush streams + unsigned int i; + for (i = 0; i < avContext->nb_streams; i++) + if (avContext->streams[i]->codec + && avContext->streams[i]->codec->codec) + avcodec_flush_buffers(avContext->streams[i]->codec); } - AVPacket packet; + AVPacket packet; av_init_packet(&packet); int av_res = av_read_frame(avContext, &packet); if (av_res == AVERROR(EAGAIN)) { - av_free_packet(&packet); - continue; + av_free_packet(&packet); + continue; } - if (av_res) { // av_read_frame failed - ffmpeg_err("no data ->end of file reached ?\n"); - av_free_packet(&packet); - break; // while + if (av_res) { // av_read_frame failed + ffmpeg_err("no data ->end of file reached ?\n"); + av_free_packet(&packet); + break; // while } - long long int pts; - Track_t * videoTrack = NULL; - Track_t * audioTrack = NULL; - Track_t * subtitleTrack = NULL; - Track_t * dvbsubtitleTrack = NULL; - Track_t * teletextTrack = NULL; + long long int pts; + Track_t *videoTrack = NULL; + Track_t *audioTrack = NULL; + Track_t *subtitleTrack = NULL; + Track_t *dvbsubtitleTrack = NULL; + Track_t *teletextTrack = NULL; - context->playback->readCount += packet.size; + context->playback->readCount += packet.size; - int pid = avContext->streams[packet.stream_index]->id; + int pid = avContext->streams[packet.stream_index]->id; - if (context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack) < 0) - ffmpeg_err("error getting video track\n"); + if (context->manager->video-> + Command(context, MANAGER_GET_TRACK, &videoTrack) < 0) + ffmpeg_err("error getting video track\n"); - if (context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack) < 0) - ffmpeg_err("error getting audio track\n"); + if (context->manager->audio-> + Command(context, MANAGER_GET_TRACK, &audioTrack) < 0) + ffmpeg_err("error getting audio track\n"); - if (context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack) < 0) - ffmpeg_err("error getting subtitle track\n"); + if (context->manager->subtitle-> + Command(context, MANAGER_GET_TRACK, &subtitleTrack) < 0) + ffmpeg_err("error getting subtitle track\n"); - if (context->manager->dvbsubtitle->Command(context, MANAGER_GET_TRACK, &dvbsubtitleTrack) < 0) - ffmpeg_err("error getting dvb subtitle track\n"); + if (context->manager->dvbsubtitle-> + Command(context, MANAGER_GET_TRACK, &dvbsubtitleTrack) < 0) + ffmpeg_err("error getting dvb subtitle track\n"); - if (context->manager->teletext->Command(context, MANAGER_GET_TRACK, &teletextTrack) < 0) - ffmpeg_err("error getting teletext track\n"); + if (context->manager->teletext-> + Command(context, MANAGER_GET_TRACK, &teletextTrack) < 0) + ffmpeg_err("error getting teletext track\n"); - ffmpeg_printf(200, "packet.size %d - index %d\n", packet.size, pid); + ffmpeg_printf(200, "packet.size %d - index %d\n", packet.size, + pid); - if (videoTrack && (videoTrack->Id == pid)) { - currentVideoPts = videoTrack->pts = pts = calcPts(videoTrack->stream, packet.pts); + if (videoTrack && (videoTrack->Id == pid)) { + currentVideoPts = videoTrack->pts = pts = + calcPts(videoTrack->stream, packet.pts); - if ((currentVideoPts > latestPts) && (currentVideoPts != INVALID_PTS_VALUE)) - latestPts = currentVideoPts; + if ((currentVideoPts > latestPts) + && (currentVideoPts != INVALID_PTS_VALUE)) + latestPts = currentVideoPts; - ffmpeg_printf(200, "VideoTrack index = %d %lld\n",pid, currentVideoPts); + ffmpeg_printf(200, "VideoTrack index = %d %lld\n", pid, + currentVideoPts); - avOut.data = packet.data; - avOut.len = packet.size; - avOut.pts = pts; - avOut.extradata = videoTrack->extraData; - avOut.extralen = videoTrack->extraSize; - avOut.frameRate = videoTrack->frame_rate; - avOut.timeScale = videoTrack->TimeScale; - avOut.width = videoTrack->width; - avOut.height = videoTrack->height; - avOut.type = "video"; + avOut.data = packet.data; + avOut.len = packet.size; + avOut.pts = pts; + avOut.extradata = videoTrack->extraData; + avOut.extralen = videoTrack->extraSize; + avOut.frameRate = videoTrack->frame_rate; + avOut.timeScale = videoTrack->TimeScale; + avOut.width = videoTrack->width; + avOut.height = videoTrack->height; + avOut.type = "video"; - if (context->output->video->Write(context, &avOut) < 0) { - ffmpeg_err("writing data to video device failed\n"); + if (context->output->video->Write(context, &avOut) < 0) { + ffmpeg_err("writing data to video device failed\n"); + } + } else if (audioTrack && (audioTrack->Id == pid)) { + currentAudioPts = audioTrack->pts = pts = + calcPts(audioTrack->stream, packet.pts); + + if ((currentAudioPts > latestPts) && (!videoTrack)) + latestPts = currentAudioPts; + + ffmpeg_printf(200, "AudioTrack index = %d\n", pid); + if (audioTrack->inject_raw_pcm == 1) { + ffmpeg_printf(200, "write audio raw pcm\n"); + + pcmPrivateData_t extradata; + extradata.uNoOfChannels = + ((AVStream *) audioTrack->stream)->codec->channels; + extradata.uSampleRate = + ((AVStream *) audioTrack->stream)->codec->sample_rate; + extradata.uBitsPerSample = 16; + extradata.bLittleEndian = 1; + + avOut.data = packet.data; + avOut.len = packet.size; + avOut.pts = pts; + avOut.extradata = (unsigned char *) &extradata; + avOut.extralen = sizeof(extradata); + avOut.frameRate = 0; + avOut.timeScale = 0; + avOut.width = 0; + avOut.height = 0; + avOut.type = "audio"; + + if (!context->playback->BackWard + && context->output->audio->Write(context, + &avOut) < 0) { + ffmpeg_err + ("(raw pcm) writing data to audio device failed\n"); + } + } else if (audioTrack->inject_as_pcm == 1) { + AVCodecContext *c = + ((AVStream *) (audioTrack->stream))->codec; + + if (restart_audio_resampling) { + restart_audio_resampling = 0; + if (swr) { + swr_free(&swr); + swr = NULL; } - } else if (audioTrack && (audioTrack->Id == pid)) { - currentAudioPts = audioTrack->pts = pts = calcPts(audioTrack->stream, packet.pts); + if (decoded_frame) { + avcodec_free_frame(&decoded_frame); + decoded_frame = NULL; + } + context->output->Command(context, OUTPUT_CLEAR, NULL); + context->output->Command(context, OUTPUT_PLAY, NULL); + } - if ((currentAudioPts > latestPts) && (!videoTrack)) - latestPts = currentAudioPts; + while (packet.size > 0) { + int got_frame = 0; + if (!decoded_frame) { + if (!(decoded_frame = avcodec_alloc_frame())) { + fprintf(stderr, "out of memory\n"); + exit(1); + } + } else + avcodec_get_frame_defaults(decoded_frame); - ffmpeg_printf(200, "AudioTrack index = %d\n",pid); - if (audioTrack->inject_raw_pcm == 1){ - ffmpeg_printf(200,"write audio raw pcm\n"); + int len = + avcodec_decode_audio4(c, decoded_frame, &got_frame, + &packet); + if (len < 0) { +// fprintf(stderr, "avcodec_decode_audio4: %d\n", len); + break; + } - pcmPrivateData_t extradata; - extradata.uNoOfChannels = ((AVStream*) audioTrack->stream)->codec->channels; - extradata.uSampleRate = ((AVStream*) audioTrack->stream)->codec->sample_rate; - extradata.uBitsPerSample = 16; - extradata.bLittleEndian = 1; + packet.data += len; + packet.size -= len; - avOut.data = packet.data; - avOut.len = packet.size; - avOut.pts = pts; - avOut.extradata = (unsigned char *) &extradata; - avOut.extralen = sizeof(extradata); - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; - avOut.type = "audio"; + if (!got_frame) + continue; - if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0) - { - ffmpeg_err("(raw pcm) writing data to audio device failed\n"); - } - } - else if (audioTrack->inject_as_pcm == 1) - { - AVCodecContext *c = ((AVStream*)(audioTrack->stream))->codec; - - if (restart_audio_resampling) { - restart_audio_resampling = 0; - if (swr) { - swr_free(&swr); - swr = NULL; - } - if (decoded_frame) { - avcodec_free_frame(&decoded_frame); - decoded_frame = NULL; - } - context->output->Command(context, OUTPUT_CLEAR, NULL); - context->output->Command(context, OUTPUT_PLAY, NULL); + int e; + if (!swr) { + int rates[] = + { 48000, 96000, 192000, 44100, 88200, 176400, + 0 }; + int *rate = rates; + int in_rate = c->sample_rate; + while (*rate + && ((*rate / in_rate) * in_rate != *rate) + && (in_rate / *rate) * *rate != in_rate) + rate++; + out_sample_rate = *rate ? *rate : 44100; + swr = swr_alloc(); + out_channels = c->channels; + if (c->channel_layout == 0) { + // FIXME -- need to guess, looks pretty much like a bug in the FFMPEG WMA decoder + c->channel_layout = AV_CH_LAYOUT_STEREO; } - while(packet.size > 0) - { - int got_frame = 0; - if (!decoded_frame) { - if (!(decoded_frame = avcodec_alloc_frame())) { - fprintf(stderr, "out of memory\n"); - exit(1); - } - } else - avcodec_get_frame_defaults(decoded_frame); + out_channel_layout = c->channel_layout; + // player2 won't play mono + if (out_channel_layout == AV_CH_LAYOUT_MONO) { + out_channel_layout = AV_CH_LAYOUT_STEREO; + out_channels = 2; + } - int len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &packet); - if (len < 0) { -// fprintf(stderr, "avcodec_decode_audio4: %d\n", len); - break; - } + av_opt_set_int(swr, "in_channel_layout", + c->channel_layout, 0); + av_opt_set_int(swr, "out_channel_layout", + out_channel_layout, 0); + av_opt_set_int(swr, "in_sample_rate", + c->sample_rate, 0); + av_opt_set_int(swr, "out_sample_rate", + out_sample_rate, 0); + av_opt_set_int(swr, "in_sample_fmt", c->sample_fmt, + 0); + av_opt_set_int(swr, "out_sample_fmt", + AV_SAMPLE_FMT_S16, 0); - packet.data += len; - packet.size -= len; - - if (!got_frame) - continue; - - int e; - if (!swr) { - int rates[] = { 48000, 96000, 192000, 44100, 88200, 176400, 0 }; - int *rate = rates; - int in_rate = c->sample_rate; - while (*rate && ((*rate / in_rate) * in_rate != *rate) && (in_rate / *rate) * *rate != in_rate) - rate++; - out_sample_rate = *rate ? *rate : 44100; - swr = swr_alloc(); - out_channels = c->channels; - if (c->channel_layout == 0) { - // FIXME -- need to guess, looks pretty much like a bug in the FFMPEG WMA decoder - c->channel_layout = AV_CH_LAYOUT_STEREO; - } - - out_channel_layout = c->channel_layout; - // player2 won't play mono - if (out_channel_layout == AV_CH_LAYOUT_MONO) { - out_channel_layout = AV_CH_LAYOUT_STEREO; - out_channels = 2; - } - - av_opt_set_int(swr, "in_channel_layout", c->channel_layout, 0); - av_opt_set_int(swr, "out_channel_layout", out_channel_layout, 0); - av_opt_set_int(swr, "in_sample_rate", c->sample_rate, 0); - av_opt_set_int(swr, "out_sample_rate", out_sample_rate, 0); - av_opt_set_int(swr, "in_sample_fmt", c->sample_fmt, 0); - av_opt_set_int(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); - - e = swr_init(swr); - if (e < 0) { - fprintf(stderr, "swr_init: %d (icl=%d ocl=%d isr=%d osr=%d isf=%d osf=%d\n", - -e, - (int)c->channel_layout, (int)out_channel_layout, c->sample_rate, out_sample_rate, c->sample_fmt, AV_SAMPLE_FMT_S16); - swr_free(&swr); - swr = NULL; - } - } - - uint8_t *output = NULL; - int in_samples = decoded_frame->nb_samples; - int out_samples = av_rescale_rnd(swr_get_delay(swr, c->sample_rate) + in_samples, out_sample_rate, c->sample_rate, AV_ROUND_UP); - e = av_samples_alloc(&output, NULL, out_channels, out_samples, AV_SAMPLE_FMT_S16, 1); - if (e < 0) { - fprintf(stderr, "av_samples_alloc: %d\n", -e); - continue; - } - int64_t next_in_pts = av_rescale(av_frame_get_best_effort_timestamp(decoded_frame), - ((AVStream*) audioTrack->stream)->time_base.num * (int64_t)out_sample_rate * c->sample_rate, - ((AVStream*) audioTrack->stream)->time_base.den); - int64_t next_out_pts = av_rescale(swr_next_pts(swr, next_in_pts), - ((AVStream*) audioTrack->stream)->time_base.den, - ((AVStream*) audioTrack->stream)->time_base.num * (int64_t)out_sample_rate * c->sample_rate); - currentAudioPts = audioTrack->pts = pts = calcPts(audioTrack->stream, next_out_pts); - out_samples = swr_convert(swr, &output, out_samples, (const uint8_t **) &decoded_frame->data[0], in_samples); - - pcmPrivateData_t extradata; - - extradata.uSampleRate = out_sample_rate; - extradata.uNoOfChannels = av_get_channel_layout_nb_channels(out_channel_layout); - extradata.uBitsPerSample = 16; - extradata.bLittleEndian = 1; - - avOut.data = output; - avOut.len = out_samples * sizeof(short) * out_channels; - - avOut.pts = pts; - avOut.extradata = (unsigned char *) &extradata; - avOut.extralen = sizeof(extradata); - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; - avOut.type = "audio"; - - if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0) - ffmpeg_err("writing data to audio device failed\n"); - av_freep(&output); + e = swr_init(swr); + if (e < 0) { + fprintf(stderr, + "swr_init: %d (icl=%d ocl=%d isr=%d osr=%d isf=%d osf=%d\n", + -e, (int) c->channel_layout, + (int) out_channel_layout, + c->sample_rate, out_sample_rate, + c->sample_fmt, AV_SAMPLE_FMT_S16); + swr_free(&swr); + swr = NULL; } } - else if (audioTrack->have_aacheader == 1) - { - ffmpeg_printf(200,"write audio aac\n"); - avOut.data = packet.data; - avOut.len = packet.size; - avOut.pts = pts; - avOut.extradata = audioTrack->aacbuf; - avOut.extralen = audioTrack->aacbuflen; - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; - avOut.type = "audio"; - - if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0) - { - ffmpeg_err("(aac) writing data to audio device failed\n"); - } + uint8_t *output = NULL; + int in_samples = decoded_frame->nb_samples; + int out_samples = + av_rescale_rnd(swr_get_delay(swr, c->sample_rate) + + in_samples, out_sample_rate, + c->sample_rate, AV_ROUND_UP); + e = av_samples_alloc(&output, NULL, out_channels, + out_samples, AV_SAMPLE_FMT_S16, + 1); + if (e < 0) { + fprintf(stderr, "av_samples_alloc: %d\n", -e); + continue; } - else - { - avOut.data = packet.data; - avOut.len = packet.size; - avOut.pts = pts; - avOut.extradata = NULL; - avOut.extralen = 0; - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; - avOut.type = "audio"; + int64_t next_in_pts = + av_rescale(av_frame_get_best_effort_timestamp + (decoded_frame), + ((AVStream *) audioTrack->stream)-> + time_base.num * + (int64_t) out_sample_rate * + c->sample_rate, + ((AVStream *) audioTrack->stream)-> + time_base.den); + int64_t next_out_pts = + av_rescale(swr_next_pts(swr, next_in_pts), + ((AVStream *) audioTrack->stream)-> + time_base.den, + ((AVStream *) audioTrack->stream)-> + time_base.num * + (int64_t) out_sample_rate * + c->sample_rate); + currentAudioPts = audioTrack->pts = pts = + calcPts(audioTrack->stream, next_out_pts); + out_samples = + swr_convert(swr, &output, out_samples, + (const uint8_t **) &decoded_frame-> + data[0], in_samples); - if (!context->playback->BackWard && context->output->audio->Write(context, &avOut) < 0) - { - ffmpeg_err("writing data to audio device failed\n"); - } - } - } else if (subtitleTrack && (subtitleTrack->Id == pid)) { - float duration=3.0; - ffmpeg_printf(100, "subtitleTrack->stream %p \n", subtitleTrack->stream); + pcmPrivateData_t extradata; - pts = calcPts(subtitleTrack->stream, packet.pts); + extradata.uSampleRate = out_sample_rate; + extradata.uNoOfChannels = + av_get_channel_layout_nb_channels + (out_channel_layout); + extradata.uBitsPerSample = 16; + extradata.bLittleEndian = 1; - if ((pts > latestPts) && (!videoTrack) && (!audioTrack)) - latestPts = pts; + avOut.data = output; + avOut.len = out_samples * sizeof(short) * out_channels; - /*Hellmaster1024: in mkv the duration for ID_TEXT is stored in convergence_duration */ - ffmpeg_printf(20, "Packet duration %d\n", packet.duration); - ffmpeg_printf(20, "Packet convergence_duration %lld\n", packet.convergence_duration); + avOut.pts = pts; + avOut.extradata = (unsigned char *) &extradata; + avOut.extralen = sizeof(extradata); + avOut.frameRate = 0; + avOut.timeScale = 0; + avOut.width = 0; + avOut.height = 0; + avOut.type = "audio"; - if(packet.duration != 0) // FIXME: packet.duration is 32 bit, AV_NOPTS_VALUE is 64 bit --martii - duration=((float)packet.duration)/1000.0; - else if(packet.convergence_duration != 0 && packet.convergence_duration != AV_NOPTS_VALUE ) - duration=((float)packet.convergence_duration)/1000.0; - else if(((AVStream*)subtitleTrack->stream)->codec->codec_id == AV_CODEC_ID_SSA) - { - /*Hellmaster1024 if the duration is not stored in packet.duration or - packet.convergence_duration we need to calculate it any other way, for SSA it is stored in - the Text line*/ - duration = getDurationFromSSALine(packet.data); + if (!context->playback->BackWard + && context->output->audio->Write(context, + &avOut) < 0) + ffmpeg_err + ("writing data to audio device failed\n"); + av_freep(&output); + } + } else if (audioTrack->have_aacheader == 1) { + ffmpeg_printf(200, "write audio aac\n"); + + avOut.data = packet.data; + avOut.len = packet.size; + avOut.pts = pts; + avOut.extradata = audioTrack->aacbuf; + avOut.extralen = audioTrack->aacbuflen; + avOut.frameRate = 0; + avOut.timeScale = 0; + avOut.width = 0; + avOut.height = 0; + avOut.type = "audio"; + + if (!context->playback->BackWard + && context->output->audio->Write(context, + &avOut) < 0) { + ffmpeg_err + ("(aac) writing data to audio device failed\n"); + } + } else { + avOut.data = packet.data; + avOut.len = packet.size; + avOut.pts = pts; + avOut.extradata = NULL; + avOut.extralen = 0; + avOut.frameRate = 0; + avOut.timeScale = 0; + avOut.width = 0; + avOut.height = 0; + avOut.type = "audio"; + + if (!context->playback->BackWard + && context->output->audio->Write(context, + &avOut) < 0) { + ffmpeg_err("writing data to audio device failed\n"); + } + } + } else if (subtitleTrack && (subtitleTrack->Id == pid)) { + float duration = 3.0; + ffmpeg_printf(100, "subtitleTrack->stream %p \n", + subtitleTrack->stream); + + pts = calcPts(subtitleTrack->stream, packet.pts); + + if ((pts > latestPts) && (!videoTrack) && (!audioTrack)) + latestPts = pts; + + /*Hellmaster1024: in mkv the duration for ID_TEXT is stored in convergence_duration */ + ffmpeg_printf(20, "Packet duration %d\n", packet.duration); + ffmpeg_printf(20, "Packet convergence_duration %lld\n", + packet.convergence_duration); + + if (packet.duration != 0) // FIXME: packet.duration is 32 bit, AV_NOPTS_VALUE is 64 bit --martii + duration = ((float) packet.duration) / 1000.0; + else if (packet.convergence_duration != 0 + && packet.convergence_duration != AV_NOPTS_VALUE) + duration = ((float) packet.convergence_duration) / 1000.0; + else if (((AVStream *) subtitleTrack->stream)->codec-> + codec_id == AV_CODEC_ID_SSA) { + /*Hellmaster1024 if the duration is not stored in packet.duration or + packet.convergence_duration we need to calculate it any other way, for SSA it is stored in + the Text line */ + duration = getDurationFromSSALine(packet.data); + } else { + /* no clue yet */ + } + + /* konfetti: I've found cases where the duration from getDurationFromSSALine + * is zero (start end and are really the same in text). I think it make's + * no sense to pass those. + */ + if (duration > 0.0) { + /* is there a decoder ? */ + if (((AVStream *) subtitleTrack->stream)->codec->codec) { + AVSubtitle sub; + int got_sub_ptr; + + if (avcodec_decode_subtitle2 + (((AVStream *) subtitleTrack->stream)->codec, &sub, + &got_sub_ptr, &packet) < 0) { + ffmpeg_err("error decoding subtitle\n"); } else { - /* no clue yet */ - } + unsigned int i; - /* konfetti: I've found cases where the duration from getDurationFromSSALine - * is zero (start end and are really the same in text). I think it make's - * no sense to pass those. - */ - if (duration > 0.0) - { - /* is there a decoder ? */ - if (((AVStream*) subtitleTrack->stream)->codec->codec) - { - AVSubtitle sub; - int got_sub_ptr; + ffmpeg_printf(0, "format %d\n", sub.format); + ffmpeg_printf(0, "start_display_time %d\n", + sub.start_display_time); + ffmpeg_printf(0, "end_display_time %d\n", + sub.end_display_time); + ffmpeg_printf(0, "num_rects %d\n", sub.num_rects); + ffmpeg_printf(0, "pts %lld\n", sub.pts); - if (avcodec_decode_subtitle2(((AVStream*) subtitleTrack->stream)->codec, &sub, &got_sub_ptr, &packet) < 0) - { - ffmpeg_err("error decoding subtitle\n"); - } else - { - unsigned int i; + for (i = 0; i < sub.num_rects; i++) { - ffmpeg_printf(0, "format %d\n", sub.format); - ffmpeg_printf(0, "start_display_time %d\n", sub.start_display_time); - ffmpeg_printf(0, "end_display_time %d\n", sub.end_display_time); - ffmpeg_printf(0, "num_rects %d\n", sub.num_rects); - ffmpeg_printf(0, "pts %lld\n", sub.pts); + ffmpeg_printf(0, "x %d\n", sub.rects[i]->x); + ffmpeg_printf(0, "y %d\n", sub.rects[i]->y); + ffmpeg_printf(0, "w %d\n", sub.rects[i]->w); + ffmpeg_printf(0, "h %d\n", sub.rects[i]->h); + ffmpeg_printf(0, "nb_colors %d\n", + sub.rects[i]->nb_colors); + ffmpeg_printf(0, "type %d\n", + sub.rects[i]->type); + ffmpeg_printf(0, "text %s\n", + sub.rects[i]->text); + ffmpeg_printf(0, "ass %s\n", + sub.rects[i]->ass); + // pict ->AVPicture - for (i = 0; i < sub.num_rects; i++) - { - - ffmpeg_printf(0, "x %d\n", sub.rects[i]->x); - ffmpeg_printf(0, "y %d\n", sub.rects[i]->y); - ffmpeg_printf(0, "w %d\n", sub.rects[i]->w); - ffmpeg_printf(0, "h %d\n", sub.rects[i]->h); - ffmpeg_printf(0, "nb_colors %d\n", sub.rects[i]->nb_colors); - ffmpeg_printf(0, "type %d\n", sub.rects[i]->type); - ffmpeg_printf(0, "text %s\n", sub.rects[i]->text); - ffmpeg_printf(0, "ass %s\n", sub.rects[i]->ass); - // pict ->AVPicture - - } - } - - if(((AVStream*)subtitleTrack->stream)->codec->codec_id == AV_CODEC_ID_SSA) - { - SubtitleData_t data; - - ffmpeg_printf(10, "videoPts %lld\n", currentVideoPts); - - data.data = packet.data; - data.len = packet.size; - data.extradata = subtitleTrack->extraData; - data.extralen = subtitleTrack->extraSize; - data.pts = pts; - data.duration = duration; - - context->container->assContainer->Command(context, CONTAINER_DATA, &data); - } - else - { - /* hopefully native text ;) */ - - unsigned char* line = text_to_ass((char *)packet.data,pts/90,duration); - ffmpeg_printf(50,"text line is %s\n",(char *)packet.data); - ffmpeg_printf(50,"Sub line is %s\n",line); - ffmpeg_printf(20, "videoPts %lld %f\n", currentVideoPts,currentVideoPts/90000.0); - SubtitleData_t data; - data.data = line; - data.len = strlen((char*)line); - data.extradata = (unsigned char *) DEFAULT_ASS_HEAD; - data.extralen = strlen(DEFAULT_ASS_HEAD); - data.pts = pts; - data.duration = duration; - - context->container->assContainer->Command(context, CONTAINER_DATA, &data); - free(line); - } } - } /* duration */ - } - else if (dvbsubtitleTrack && (dvbsubtitleTrack->Id == pid)) { - dvbsubtitleTrack->pts = pts = calcPts(dvbsubtitleTrack->stream, packet.pts); - - ffmpeg_printf(200, "DvbSubTitle index = %d\n",pid); - - avOut.data = packet.data; - avOut.len = packet.size; - avOut.pts = pts; - avOut.extradata = NULL; - avOut.extralen = 0; - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; - avOut.type = "dvbsubtitle"; - - if (context->output->dvbsubtitle->Write(context, &avOut) < 0) - { - //ffmpeg_err("writing data to dvbsubtitle fifo failed\n"); } - } else if (teletextTrack && (teletextTrack->Id == pid)) { - teletextTrack->pts = pts = calcPts(teletextTrack->stream, packet.pts); - ffmpeg_printf(200, "TeleText index = %d\n",pid); + if (((AVStream *) subtitleTrack->stream)->codec-> + codec_id == AV_CODEC_ID_SSA) { + SubtitleData_t data; - avOut.data = packet.data; - avOut.len = packet.size; - avOut.pts = pts; - avOut.extradata = NULL; - avOut.extralen = 0; - avOut.frameRate = 0; - avOut.timeScale = 0; - avOut.width = 0; - avOut.height = 0; - avOut.type = "teletext"; + ffmpeg_printf(10, "videoPts %lld\n", + currentVideoPts); - if (context->output->teletext->Write(context, &avOut) < 0) - { - //ffmpeg_err("writing data to teletext fifo failed\n"); + data.data = packet.data; + data.len = packet.size; + data.extradata = subtitleTrack->extraData; + data.extralen = subtitleTrack->extraSize; + data.pts = pts; + data.duration = duration; + + context->container->assContainer->Command(context, + CONTAINER_DATA, + &data); + } else { + /* hopefully native text ;) */ + + unsigned char *line = + text_to_ass((char *) packet.data, pts / 90, + duration); + ffmpeg_printf(50, "text line is %s\n", + (char *) packet.data); + ffmpeg_printf(50, "Sub line is %s\n", line); + ffmpeg_printf(20, "videoPts %lld %f\n", + currentVideoPts, + currentVideoPts / 90000.0); + SubtitleData_t data; + data.data = line; + data.len = strlen((char *) line); + data.extradata = + (unsigned char *) DEFAULT_ASS_HEAD; + data.extralen = strlen(DEFAULT_ASS_HEAD); + data.pts = pts; + data.duration = duration; + + context->container->assContainer->Command(context, + CONTAINER_DATA, + &data); + free(line); } + } + } /* duration */ + } else if (dvbsubtitleTrack && (dvbsubtitleTrack->Id == pid)) { + dvbsubtitleTrack->pts = pts = + calcPts(dvbsubtitleTrack->stream, packet.pts); + + ffmpeg_printf(200, "DvbSubTitle index = %d\n", pid); + + avOut.data = packet.data; + avOut.len = packet.size; + avOut.pts = pts; + avOut.extradata = NULL; + avOut.extralen = 0; + avOut.frameRate = 0; + avOut.timeScale = 0; + avOut.width = 0; + avOut.height = 0; + avOut.type = "dvbsubtitle"; + + if (context->output->dvbsubtitle->Write(context, &avOut) < 0) { + //ffmpeg_err("writing data to dvbsubtitle fifo failed\n"); } + } else if (teletextTrack && (teletextTrack->Id == pid)) { + teletextTrack->pts = pts = + calcPts(teletextTrack->stream, packet.pts); + + ffmpeg_printf(200, "TeleText index = %d\n", pid); + + avOut.data = packet.data; + avOut.len = packet.size; + avOut.pts = pts; + avOut.extradata = NULL; + avOut.extralen = 0; + avOut.frameRate = 0; + avOut.timeScale = 0; + avOut.width = 0; + avOut.height = 0; + avOut.type = "teletext"; + + if (context->output->teletext->Write(context, &avOut) < 0) { + //ffmpeg_err("writing data to teletext fifo failed\n"); + } + } av_free_packet(&packet); - } /* while */ + } /* while */ - if (context && context->playback && context->output && context->playback->abortRequested) + if (context && context->playback && context->output + && context->playback->abortRequested) context->output->Command(context, OUTPUT_CLEAR, NULL); if (swr) @@ -833,7 +916,7 @@ static void FFMPEGThread(Context_t *context) { hasPlayThreadStarted = 0; if (context->playback) - context->playback->isPlaying = 0; + context->playback->isPlaying = 0; ffmpeg_printf(10, "terminating\n"); } @@ -845,12 +928,12 @@ static void FFMPEGThread(Context_t *context) { static int terminating = 0; static int interrupt_cb(void *ctx) { - PlaybackHandler_t *p = (PlaybackHandler_t *)ctx; - return p->abortRequested; + PlaybackHandler_t *p = (PlaybackHandler_t *) ctx; + return p->abortRequested; } -int container_ffmpeg_init(Context_t *context, char * filename) +int container_ffmpeg_init(Context_t * context, char *filename) { int err; @@ -899,7 +982,7 @@ int container_ffmpeg_init(Context_t *context, char * filename) avContext->iformat->flags |= AVFMT_SEEK_TO_PTS; avContext->flags = AVFMT_FLAG_GENPTS; if (context->playback->noprobe) - avContext->max_analyze_duration = 1; + avContext->max_analyze_duration = 1; ffmpeg_printf(20, "find_streaminfo\n"); @@ -911,7 +994,7 @@ int container_ffmpeg_init(Context_t *context, char * filename) * until other works are done and we can prove this. */ avformat_close_input(&avContext); - //for buffered io (end) + //for buffered io (end) return cERR_CONTAINER_FFMPEG_STREAM; #endif } @@ -923,34 +1006,44 @@ int container_ffmpeg_init(Context_t *context, char * filename) return res; } -int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initial) +int container_ffmpeg_update_tracks(Context_t * context, char *filename, + int initial) { if (terminating) return cERR_CONTAINER_FFMPEG_NO_ERROR; - Track_t * audioTrack = NULL; - Track_t * subtitleTrack = NULL; - Track_t * dvbsubtitleTrack = NULL; - Track_t * teletextTrack = NULL; + Track_t *audioTrack = NULL; + Track_t *subtitleTrack = NULL; + Track_t *dvbsubtitleTrack = NULL; + Track_t *teletextTrack = NULL; - context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack); + context->manager->audio->Command(context, MANAGER_GET_TRACK, + &audioTrack); if (initial) - context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack); - context->manager->dvbsubtitle->Command(context, MANAGER_GET_TRACK, &dvbsubtitleTrack); - context->manager->teletext->Command(context, MANAGER_GET_TRACK, &teletextTrack); + context->manager->subtitle->Command(context, MANAGER_GET_TRACK, + &subtitleTrack); + context->manager->dvbsubtitle->Command(context, MANAGER_GET_TRACK, + &dvbsubtitleTrack); + context->manager->teletext->Command(context, MANAGER_GET_TRACK, + &teletextTrack); if (context->manager->video) - context->manager->video->Command(context, MANAGER_INIT_UPDATE, NULL); + context->manager->video->Command(context, MANAGER_INIT_UPDATE, + NULL); if (context->manager->audio) - context->manager->audio->Command(context, MANAGER_INIT_UPDATE, NULL); + context->manager->audio->Command(context, MANAGER_INIT_UPDATE, + NULL); #if 0 if (context->manager->subtitle) - context->manager->subtitle->Command(context, MANAGER_INIT_UPDATE, NULL); + context->manager->subtitle->Command(context, MANAGER_INIT_UPDATE, + NULL); #endif if (context->manager->dvbsubtitle) - context->manager->dvbsubtitle->Command(context, MANAGER_INIT_UPDATE, NULL); + context->manager->dvbsubtitle->Command(context, + MANAGER_INIT_UPDATE, NULL); if (context->manager->teletext) - context->manager->teletext->Command(context, MANAGER_INIT_UPDATE, NULL); + context->manager->teletext->Command(context, MANAGER_INIT_UPDATE, + NULL); ffmpeg_printf(20, "dump format\n"); av_dump_format(avContext, 0, filename, 0); @@ -959,18 +1052,19 @@ int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initi unsigned int n; - for ( n = 0; n < avContext->nb_streams; n++) { + for (n = 0; n < avContext->nb_streams; n++) { Track_t track; AVStream *stream = avContext->streams[n]; int version = 0; - char* encoding = Codec2Encoding(stream->codec, &version); + char *encoding = Codec2Encoding(stream->codec, &version); if (encoding != NULL) - ffmpeg_printf(1, "%d. encoding = %s - version %d\n", n, encoding, version); + ffmpeg_printf(1, "%d. encoding = %s - version %d\n", n, + encoding, version); if (!stream->id) - stream->id = n; + stream->id = n; /* some values in track are unset and therefor copyTrack segfaults. * so set it by default to NULL! @@ -979,24 +1073,25 @@ int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initi switch (stream->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: - ffmpeg_printf(10, "CODEC_TYPE_VIDEO %d\n",stream->codec->codec_type); + ffmpeg_printf(10, "CODEC_TYPE_VIDEO %d\n", + stream->codec->codec_type); if (encoding != NULL) { - track.type = eTypeES; - track.version = version; + track.type = eTypeES; + track.version = version; - track.width = stream->codec->width; - track.height = stream->codec->height; + track.width = stream->codec->width; + track.height = stream->codec->height; - track.extraData = stream->codec->extradata; - track.extraSize = stream->codec->extradata_size; + track.extraData = stream->codec->extradata; + track.extraSize = stream->codec->extradata_size; - track.frame_rate = stream->r_frame_rate.num; + track.frame_rate = stream->r_frame_rate.num; - track.aacbuf = 0; + track.aacbuf = 0; track.have_aacheader = -1; - double frame_rate = av_q2d(stream->r_frame_rate); /* rational to double */ + double frame_rate = av_q2d(stream->r_frame_rate); /* rational to double */ ffmpeg_printf(10, "frame_rate = %f\n", frame_rate); @@ -1009,47 +1104,57 @@ int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initi else track.TimeScale = 1000; - ffmpeg_printf(10, "bit_rate = %d\n",stream->codec->bit_rate); - ffmpeg_printf(10, "flags = %d\n",stream->codec->flags); - ffmpeg_printf(10, "frame_bits = %d\n",stream->codec->frame_bits); - ffmpeg_printf(10, "time_base.den %d\n",stream->time_base.den); - ffmpeg_printf(10, "time_base.num %d\n",stream->time_base.num); - ffmpeg_printf(10, "frame_rate %d\n",stream->r_frame_rate.num); - ffmpeg_printf(10, "TimeScale %d\n",stream->r_frame_rate.den); + ffmpeg_printf(10, "bit_rate = %d\n", + stream->codec->bit_rate); + ffmpeg_printf(10, "flags = %d\n", stream->codec->flags); + ffmpeg_printf(10, "frame_bits = %d\n", + stream->codec->frame_bits); + ffmpeg_printf(10, "time_base.den %d\n", + stream->time_base.den); + ffmpeg_printf(10, "time_base.num %d\n", + stream->time_base.num); + ffmpeg_printf(10, "frame_rate %d\n", + stream->r_frame_rate.num); + ffmpeg_printf(10, "TimeScale %d\n", + stream->r_frame_rate.den); ffmpeg_printf(10, "frame_rate %d\n", track.frame_rate); ffmpeg_printf(10, "TimeScale %d\n", track.TimeScale); - track.Name = "und"; - track.Encoding = encoding; - track.stream = stream; - track.Id = stream->id; + track.Name = "und"; + track.Encoding = encoding; + track.stream = stream; + track.Id = stream->id; - if(stream->duration == AV_NOPTS_VALUE) { - ffmpeg_printf(10, "Stream has no duration so we take the duration from context\n"); + if (stream->duration == AV_NOPTS_VALUE) { + ffmpeg_printf(10, + "Stream has no duration so we take the duration from context\n"); track.duration = (double) avContext->duration / 1000.0; - } - else { - track.duration = (double) stream->duration * av_q2d(stream->time_base) * 1000.0; + } else { + track.duration = + (double) stream->duration * + av_q2d(stream->time_base) * 1000.0; } if (context->manager->video) - if (context->manager->video->Command(context, MANAGER_ADD, &track) < 0) { + if (context->manager->video-> + Command(context, MANAGER_ADD, &track) < 0) { /* konfetti: fixme: is this a reason to return with error? */ ffmpeg_err("failed to add track %d\n", n); } - } - else { - ffmpeg_err("codec type video but codec unknown %d\n", stream->codec->codec_id); + } else { + ffmpeg_err("codec type video but codec unknown %d\n", + stream->codec->codec_id); } break; case AVMEDIA_TYPE_AUDIO: - ffmpeg_printf(10, "CODEC_TYPE_AUDIO %d\n",stream->codec->codec_type); + ffmpeg_printf(10, "CODEC_TYPE_AUDIO %d\n", + stream->codec->codec_type); if (encoding != NULL) { AVDictionaryEntry *lang; - track.type = eTypeES; + track.type = eTypeES; lang = av_dict_get(stream->metadata, "language", NULL, 0); @@ -1057,123 +1162,140 @@ int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initi ffmpeg_printf(10, "Language %s\n", track.Name); - track.Encoding = encoding; - track.stream = stream; - track.Id = stream->id; - track.duration = (double)stream->duration * av_q2d(stream->time_base) * 1000.0; - track.aacbuf = 0; + track.Encoding = encoding; + track.stream = stream; + track.Id = stream->id; + track.duration = + (double) stream->duration * av_q2d(stream->time_base) * + 1000.0; + track.aacbuf = 0; track.have_aacheader = -1; - if(stream->duration == AV_NOPTS_VALUE) { - ffmpeg_printf(10, "Stream has no duration so we take the duration from context\n"); + if (stream->duration == AV_NOPTS_VALUE) { + ffmpeg_printf(10, + "Stream has no duration so we take the duration from context\n"); track.duration = (double) avContext->duration / 1000.0; - } - else { - track.duration = (double) stream->duration * av_q2d(stream->time_base) * 1000.0; + } else { + track.duration = + (double) stream->duration * + av_q2d(stream->time_base) * 1000.0; } - if(!strncmp(encoding, "A_IPCM", 6)) - { + if (!strncmp(encoding, "A_IPCM", 6)) { track.inject_as_pcm = 1; - ffmpeg_printf(10, " Handle inject_as_pcm = %d\n", track.inject_as_pcm); + ffmpeg_printf(10, " Handle inject_as_pcm = %d\n", + track.inject_as_pcm); - AVCodec *codec = avcodec_find_decoder(stream->codec->codec_id); + AVCodec *codec = + avcodec_find_decoder(stream->codec->codec_id); //( (AVStream*) audioTrack->stream)->codec->flags |= CODEC_FLAG_TRUNCATED; - if(codec != NULL && !avcodec_open2(stream->codec, codec, NULL)) - printf("AVCODEC__INIT__SUCCESS\n"); - else - printf("AVCODEC__INIT__FAILED\n"); + if (codec != NULL + && !avcodec_open2(stream->codec, codec, NULL)) + printf("AVCODEC__INIT__SUCCESS\n"); + else + printf("AVCODEC__INIT__FAILED\n"); } #if 0 - else if(stream->codec->codec_id == AV_CODEC_ID_AAC) { - ffmpeg_printf(10,"Create AAC ExtraData\n"); - ffmpeg_printf(10,"stream->codec->extradata_size %d\n", stream->codec->extradata_size); - Hexdump(stream->codec->extradata, stream->codec->extradata_size); + else if (stream->codec->codec_id == AV_CODEC_ID_AAC) { + ffmpeg_printf(10, "Create AAC ExtraData\n"); + ffmpeg_printf(10, "stream->codec->extradata_size %d\n", + stream->codec->extradata_size); + Hexdump(stream->codec->extradata, + stream->codec->extradata_size); - /* extradata -13 10 56 e5 9d 48 00 (anderen cops) - object_type: 00010 2 = LC - sample_rate: 011 0 6 = 24000 - chan_config: 0010 2 = Stereo - 000 0 - 1010110 111 = 0x2b7 - 00101 = SBR - 1 - 0011 = 48000 - 101 01001000 = 0x548 - ps = 0 - 0000000 -*/ + /* extradata + 13 10 56 e5 9d 48 00 (anderen cops) + object_type: 00010 2 = LC + sample_rate: 011 0 6 = 24000 + chan_config: 0010 2 = Stereo + 000 0 + 1010110 111 = 0x2b7 + 00101 = SBR + 1 + 0011 = 48000 + 101 01001000 = 0x548 + ps = 0 + 0000000 + */ - unsigned int object_type = 2; // LC - unsigned int sample_index = aac_get_sample_rate_index(stream->codec->sample_rate); + unsigned int object_type = 2; // LC + unsigned int sample_index = + aac_get_sample_rate_index(stream->codec-> + sample_rate); unsigned int chan_config = stream->codec->channels; - if(stream->codec->extradata_size >= 2) { + if (stream->codec->extradata_size >= 2) { object_type = stream->codec->extradata[0] >> 3; - sample_index = ((stream->codec->extradata[0] & 0x7) << 1) + sample_index = + ((stream->codec->extradata[0] & 0x7) << 1) + (stream->codec->extradata[1] >> 7); - chan_config = (stream->codec->extradata[1] >> 3) && 0xf; + chan_config = (stream->codec->extradata[1] >> 3) + && 0xf; } - ffmpeg_printf(10,"aac object_type %d\n", object_type); - ffmpeg_printf(10,"aac sample_index %d\n", sample_index); - ffmpeg_printf(10,"aac chan_config %d\n", chan_config); + ffmpeg_printf(10, "aac object_type %d\n", object_type); + ffmpeg_printf(10, "aac sample_index %d\n", + sample_index); + ffmpeg_printf(10, "aac chan_config %d\n", chan_config); - object_type -= 1; // Cause of ADTS + object_type -= 1; // Cause of ADTS track.aacbuflen = AAC_HEADER_LENGTH; track.aacbuf = malloc(8); track.aacbuf[0] = 0xFF; track.aacbuf[1] = 0xF1; - track.aacbuf[2] = ((object_type & 0x03) << 6) | (sample_index << 2) | ((chan_config >> 2) & 0x01); + track.aacbuf[2] = + ((object_type & 0x03) << 6) | (sample_index << 2) | + ((chan_config >> 2) & 0x01); track.aacbuf[3] = (chan_config & 0x03) << 6; track.aacbuf[4] = 0x00; track.aacbuf[5] = 0x1F; track.aacbuf[6] = 0xFC; printf("AAC_HEADER -> "); - Hexdump(track.aacbuf,7); + Hexdump(track.aacbuf, 7); track.have_aacheader = 1; - } else if(stream->codec->codec_id == AV_CODEC_ID_WMAV1 - || stream->codec->codec_id == AV_CODEC_ID_WMAV2 - || stream->codec->codec_id == AV_CODEC_ID_WMAPRO) //if (stream->codec->extradata_size > 0) + } else if (stream->codec->codec_id == AV_CODEC_ID_WMAV1 || stream->codec->codec_id == AV_CODEC_ID_WMAV2 || stream->codec->codec_id == AV_CODEC_ID_WMAPRO) //if (stream->codec->extradata_size > 0) { - ffmpeg_printf(10,"Create WMA ExtraData\n"); + ffmpeg_printf(10, "Create WMA ExtraData\n"); track.aacbuflen = 104 + stream->codec->extradata_size; track.aacbuf = malloc(track.aacbuflen); - memset (track.aacbuf, 0, track.aacbuflen); + memset(track.aacbuf, 0, track.aacbuflen); unsigned char ASF_Stream_Properties_Object[16] = - {0x91,0x07,0xDC,0xB7,0xB7,0xA9,0xCF,0x11,0x8E,0xE6,0x00,0xC0,0x0C,0x20,0x53,0x65}; - memcpy(track.aacbuf + 0, ASF_Stream_Properties_Object, 16); // ASF_Stream_Properties_Object - memcpy(track.aacbuf + 16, &track.aacbuflen, 4); //FrameDateLength + { 0x91, 0x07, 0xDC, 0xB7, 0xB7, 0xA9, 0xCF, 0x11, +0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 }; + memcpy(track.aacbuf + 0, ASF_Stream_Properties_Object, 16); // ASF_Stream_Properties_Object + memcpy(track.aacbuf + 16, &track.aacbuflen, 4); //FrameDateLength unsigned int sizehi = 0; - memcpy(track.aacbuf + 20, &sizehi, 4); // sizehi (not used) + memcpy(track.aacbuf + 20, &sizehi, 4); // sizehi (not used) unsigned char ASF_Audio_Media[16] = - {0x40,0x9E,0x69,0xF8,0x4D,0x5B,0xCF,0x11,0xA8,0xFD,0x00,0x80,0x5F,0x5C,0x44,0x2B}; - memcpy(track.aacbuf + 24, ASF_Audio_Media, 16); //ASF_Audio_Media + { 0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, +0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B }; + memcpy(track.aacbuf + 24, ASF_Audio_Media, 16); //ASF_Audio_Media unsigned char ASF_Audio_Spread[16] = - {0x50,0xCD,0xC3,0xBF,0x8F,0x61,0xCF,0x11,0x8B,0xB2,0x00,0xAA,0x00,0xB4,0xE2,0x20}; - memcpy(track.aacbuf + 40, ASF_Audio_Spread, 16); //ASF_Audio_Spread + { 0x50, 0xCD, 0xC3, 0xBF, 0x8F, 0x61, 0xCF, 0x11, +0x8B, 0xB2, 0x00, 0xAA, 0x00, 0xB4, 0xE2, 0x20 }; + memcpy(track.aacbuf + 40, ASF_Audio_Spread, 16); //ASF_Audio_Spread - memset(track.aacbuf + 56, 0, 4); // time_offset (not used) - memset(track.aacbuf + 60, 0, 4); // time_offset_hi (not used) + memset(track.aacbuf + 56, 0, 4); // time_offset (not used) + memset(track.aacbuf + 60, 0, 4); // time_offset_hi (not used) - unsigned int type_specific_data_length = 18 + stream->codec->extradata_size; - memcpy(track.aacbuf + 64, &type_specific_data_length, 4); //type_specific_data_length + unsigned int type_specific_data_length = + 18 + stream->codec->extradata_size; + memcpy(track.aacbuf + 64, &type_specific_data_length, 4); //type_specific_data_length unsigned int error_correction_data_length = 8; - memcpy(track.aacbuf + 68, &error_correction_data_length, 4); //error_correction_data_length + memcpy(track.aacbuf + 68, &error_correction_data_length, 4); //error_correction_data_length - unsigned short flags = 1; // stream_number - memcpy(track.aacbuf + 72, &flags, 2); //flags + unsigned short flags = 1; // stream_number + memcpy(track.aacbuf + 72, &flags, 2); //flags unsigned int reserved = 0; - memcpy(track.aacbuf + 74, &reserved, 4); // reserved + memcpy(track.aacbuf + 74, &reserved, 4); // reserved // type_specific_data #define WMA_VERSION_1 0x160 @@ -1181,44 +1303,56 @@ int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initi #define WMA_VERSION_9_PRO 0x162 #define WMA_LOSSLESS 0x163 unsigned short codec_id = 0; - switch(stream->codec->codec_id) { + switch (stream->codec->codec_id) { //TODO: What code for lossless ? - case AV_CODEC_ID_WMAPRO: - codec_id = WMA_VERSION_9_PRO; - break; - case AV_CODEC_ID_WMAV2: - codec_id = WMA_VERSION_2_9 ; - break; - case AV_CODEC_ID_WMAV1: - default: - codec_id = WMA_VERSION_1; - break; + case AV_CODEC_ID_WMAPRO: + codec_id = WMA_VERSION_9_PRO; + break; + case AV_CODEC_ID_WMAV2: + codec_id = WMA_VERSION_2_9; + break; + case AV_CODEC_ID_WMAV1: + default: + codec_id = WMA_VERSION_1; + break; } - memcpy(track.aacbuf + 78, &codec_id, 2); //codec_id + memcpy(track.aacbuf + 78, &codec_id, 2); //codec_id - unsigned short number_of_channels = stream->codec->channels; - memcpy(track.aacbuf + 80, &number_of_channels, 2); //number_of_channels + unsigned short number_of_channels = + stream->codec->channels; + memcpy(track.aacbuf + 80, &number_of_channels, 2); //number_of_channels - unsigned int samples_per_second = stream->codec->sample_rate; - ffmpeg_printf(1, "samples_per_second = %d\n", samples_per_second); - memcpy(track.aacbuf + 82, &samples_per_second, 4); //samples_per_second + unsigned int samples_per_second = + stream->codec->sample_rate; + ffmpeg_printf(1, "samples_per_second = %d\n", + samples_per_second); + memcpy(track.aacbuf + 82, &samples_per_second, 4); //samples_per_second - unsigned int average_number_of_bytes_per_second = stream->codec->bit_rate / 8; - ffmpeg_printf(1, "average_number_of_bytes_per_second = %d\n", average_number_of_bytes_per_second); - memcpy(track.aacbuf + 86, &average_number_of_bytes_per_second, 4); //average_number_of_bytes_per_second + unsigned int average_number_of_bytes_per_second = + stream->codec->bit_rate / 8; + ffmpeg_printf(1, + "average_number_of_bytes_per_second = %d\n", + average_number_of_bytes_per_second); + memcpy(track.aacbuf + 86, &average_number_of_bytes_per_second, 4); //average_number_of_bytes_per_second - unsigned short block_alignment = stream->codec->block_align; - ffmpeg_printf(1, "block_alignment = %d\n", block_alignment); - memcpy(track.aacbuf + 90, &block_alignment, 2); //block_alignment + unsigned short block_alignment = + stream->codec->block_align; + ffmpeg_printf(1, "block_alignment = %d\n", + block_alignment); + memcpy(track.aacbuf + 90, &block_alignment, 2); //block_alignment unsigned short bits_per_sample = - stream->codec->sample_fmt>=0?(stream->codec->sample_fmt+1)*8:8; - ffmpeg_printf(1, "bits_per_sample = %d (%d)\n", bits_per_sample, stream->codec->sample_fmt); - memcpy(track.aacbuf + 92, &bits_per_sample, 2); //bits_per_sample + stream->codec->sample_fmt >= + 0 ? (stream->codec->sample_fmt + 1) * 8 : 8; + ffmpeg_printf(1, "bits_per_sample = %d (%d)\n", + bits_per_sample, + stream->codec->sample_fmt); + memcpy(track.aacbuf + 92, &bits_per_sample, 2); //bits_per_sample - memcpy(track.aacbuf + 94, &stream->codec->extradata_size, 2); //bits_per_sample + memcpy(track.aacbuf + 94, &stream->codec->extradata_size, 2); //bits_per_sample - memcpy(track.aacbuf + 96, stream->codec->extradata, stream->codec->extradata_size); + memcpy(track.aacbuf + 96, stream->codec->extradata, + stream->codec->extradata_size); ffmpeg_printf(1, "aacbuf:\n"); Hexdump(track.aacbuf, track.aacbuflen); @@ -1230,114 +1364,143 @@ int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initi } #endif - if (context->manager->audio) - { - if (context->manager->audio->Command(context, MANAGER_ADD, &track) < 0) { + if (context->manager->audio) { + if (context->manager->audio-> + Command(context, MANAGER_ADD, &track) < 0) { /* konfetti: fixme: is this a reason to return with error? */ ffmpeg_err("failed to add track %d\n", n); } } - } - else { - ffmpeg_err("codec type audio but codec unknown %d\n", stream->codec->codec_id); + } else { + ffmpeg_err("codec type audio but codec unknown %d\n", + stream->codec->codec_id); } break; case AVMEDIA_TYPE_SUBTITLE: - { - AVDictionaryEntry *lang; + { + AVDictionaryEntry *lang; - ffmpeg_printf(10, "CODEC_TYPE_SUBTITLE %d\n",stream->codec->codec_type); + ffmpeg_printf(10, "CODEC_TYPE_SUBTITLE %d\n", + stream->codec->codec_type); - lang = av_dict_get(stream->metadata, "language", NULL, 0); + lang = av_dict_get(stream->metadata, "language", NULL, 0); - track.Name = lang ? lang->value : "und"; + track.Name = lang ? lang->value : "und"; - ffmpeg_printf(10, "Language %s\n", track.Name); + ffmpeg_printf(10, "Language %s\n", track.Name); - track.Encoding = encoding; - track.stream = stream; - track.Id = stream->id; - track.duration = (double)stream->duration * av_q2d(stream->time_base) * 1000.0; + track.Encoding = encoding; + track.stream = stream; + track.Id = stream->id; + track.duration = + (double) stream->duration * av_q2d(stream->time_base) * + 1000.0; - track.aacbuf = 0; - track.have_aacheader = -1; + track.aacbuf = 0; + track.have_aacheader = -1; - track.width = -1; /* will be filled online from videotrack */ - track.height = -1; /* will be filled online from videotrack */ + track.width = -1; /* will be filled online from videotrack */ + track.height = -1; /* will be filled online from videotrack */ - track.extraData = stream->codec->extradata; - track.extraSize = stream->codec->extradata_size; + track.extraData = stream->codec->extradata; + track.extraSize = stream->codec->extradata_size; - ffmpeg_printf(1, "subtitle codec %d\n", stream->codec->codec_id); - ffmpeg_printf(1, "subtitle width %d\n", stream->codec->width); - ffmpeg_printf(1, "subtitle height %d\n", stream->codec->height); - ffmpeg_printf(1, "subtitle stream %p\n", stream); + ffmpeg_printf(1, "subtitle codec %d\n", + stream->codec->codec_id); + ffmpeg_printf(1, "subtitle width %d\n", + stream->codec->width); + ffmpeg_printf(1, "subtitle height %d\n", + stream->codec->height); + ffmpeg_printf(1, "subtitle stream %p\n", stream); - if(stream->duration == AV_NOPTS_VALUE) { - ffmpeg_printf(10, "Stream has no duration so we take the duration from context\n"); - track.duration = (double) avContext->duration / 1000.0; - } - else { - track.duration = (double) stream->duration * av_q2d(stream->time_base) * 1000.0; - } + if (stream->duration == AV_NOPTS_VALUE) { + ffmpeg_printf(10, + "Stream has no duration so we take the duration from context\n"); + track.duration = (double) avContext->duration / 1000.0; + } else { + track.duration = + (double) stream->duration * + av_q2d(stream->time_base) * 1000.0; + } - ffmpeg_printf(10, "FOUND SUBTITLE %s\n", track.Name); + ffmpeg_printf(10, "FOUND SUBTITLE %s\n", track.Name); - if (stream->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT && context->manager->teletext) { - ffmpeg_printf(10, "dvb_teletext\n"); - int i = 0; - AVDictionaryEntry *t = NULL; - do { + if (stream->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT + && context->manager->teletext) { + ffmpeg_printf(10, "dvb_teletext\n"); + int i = 0; + AVDictionaryEntry *t = NULL; + do { char tmp[30]; snprintf(tmp, sizeof(tmp), "teletext_%d", i); t = av_dict_get(stream->metadata, tmp, NULL, 0); if (t) { - track.Name = t->value; - if (context->manager->teletext->Command(context, MANAGER_ADD, &track) < 0) - ffmpeg_err("failed to add teletext track %d\n", n); + track.Name = t->value; + if (context->manager->teletext-> + Command(context, MANAGER_ADD, &track) < 0) + ffmpeg_err + ("failed to add teletext track %d\n", + n); } i++; - } while (t); - } else if (stream->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE && context->manager->dvbsubtitle) { - ffmpeg_printf(10, "dvb_subtitle\n"); - lang = av_dict_get(stream->metadata, "language", NULL, 0); - if (context->manager->dvbsubtitle->Command(context, MANAGER_ADD, &track) < 0) { - ffmpeg_err("failed to add dvbsubtitle track %d\n", n); - } - } else if (initial && context->manager->subtitle) { - if (!stream->codec->codec) { - stream->codec->codec = avcodec_find_decoder(stream->codec->codec_id); - if (!stream->codec->codec) - ffmpeg_err("avcodec_find_decoder failed for subtitle track %d\n", n); - else if (avcodec_open2(stream->codec, stream->codec->codec, NULL)) { - ffmpeg_err("avcodec_open2 failed for subtitle track %d\n", n); - stream->codec->codec = NULL; + } while (t); + } else if (stream->codec->codec_id == + AV_CODEC_ID_DVB_SUBTITLE + && context->manager->dvbsubtitle) { + ffmpeg_printf(10, "dvb_subtitle\n"); + lang = + av_dict_get(stream->metadata, "language", NULL, 0); + if (context->manager->dvbsubtitle-> + Command(context, MANAGER_ADD, &track) < 0) { + ffmpeg_err("failed to add dvbsubtitle track %d\n", + n); + } + } else if (initial && context->manager->subtitle) { + if (!stream->codec->codec) { + stream->codec->codec = + avcodec_find_decoder(stream->codec->codec_id); + if (!stream->codec->codec) + ffmpeg_err + ("avcodec_find_decoder failed for subtitle track %d\n", + n); + else if (avcodec_open2 + (stream->codec, stream->codec->codec, + NULL)) { + ffmpeg_err + ("avcodec_open2 failed for subtitle track %d\n", + n); + stream->codec->codec = NULL; + } + } + if (stream->codec->codec + && context->manager->subtitle->Command(context, + MANAGER_ADD, + &track) < + 0) { + /* konfetti: fixme: is this a reason to return with error? */ + ffmpeg_err("failed to add subtitle track %d\n", n); } } - if (stream->codec->codec && context->manager->subtitle->Command(context, MANAGER_ADD, &track) < 0) { - /* konfetti: fixme: is this a reason to return with error? */ - ffmpeg_err("failed to add subtitle track %d\n", n); - } - } - break; - } + break; + } case AVMEDIA_TYPE_UNKNOWN: case AVMEDIA_TYPE_DATA: case AVMEDIA_TYPE_ATTACHMENT: case AVMEDIA_TYPE_NB: default: - ffmpeg_err("not handled or unknown codec_type %d\n", stream->codec->codec_type); - break; + ffmpeg_err("not handled or unknown codec_type %d\n", + stream->codec->codec_type); + break; } - } /* for */ + } /* for */ return cERR_CONTAINER_FFMPEG_NO_ERROR; } -static int container_ffmpeg_play(Context_t *context) +static int container_ffmpeg_play(Context_t * context) { int error; int ret = 0; @@ -1345,10 +1508,9 @@ static int container_ffmpeg_play(Context_t *context) ffmpeg_printf(10, "\n"); - if ( context && context->playback && context->playback->isPlaying ) { + if (context && context->playback && context->playback->isPlaying) { ffmpeg_printf(10, "is Playing\n"); - } - else { + } else { ffmpeg_printf(10, "is NOT Playing\n"); } @@ -1356,15 +1518,16 @@ static int container_ffmpeg_play(Context_t *context) pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - if((error = pthread_create(&PlayThread, &attr, (void *)&FFMPEGThread, context)) != 0) { - ffmpeg_printf(10, "Error creating thread, error:%d:%s\n", error,strerror(error)); + if ((error = + pthread_create(&PlayThread, &attr, (void *) &FFMPEGThread, + context)) != 0) { + ffmpeg_printf(10, "Error creating thread, error:%d:%s\n", + error, strerror(error)); ret = cERR_CONTAINER_FFMPEG_ERR; - } - else { + } else { ffmpeg_printf(10, "Created thread\n"); } - } - else { + } else { ffmpeg_printf(10, "A thread already exists!\n"); ret = cERR_CONTAINER_FFMPEG_ERR; } @@ -1374,13 +1537,13 @@ static int container_ffmpeg_play(Context_t *context) return ret; } -static int container_ffmpeg_stop(Context_t *context) { +static int container_ffmpeg_stop(Context_t * context) +{ int ret = cERR_CONTAINER_FFMPEG_NO_ERROR; ffmpeg_printf(10, "\n"); - if (!isContainerRunning) - { + if (!isContainerRunning) { ffmpeg_err("Container not running\n"); return cERR_CONTAINER_FFMPEG_ERR; } @@ -1404,29 +1567,36 @@ static int container_ffmpeg_stop(Context_t *context) { return ret; } -static int container_ffmpeg_seek(Context_t *context __attribute__((unused)), float sec, int absolute) { - if (absolute) - seek_sec_abs = sec, seek_sec_rel = 0.0; - else - seek_sec_abs = 0.0, seek_sec_rel = sec; +static int container_ffmpeg_seek(Context_t * context + __attribute__ ((unused)), float sec, + int absolute) +{ + if (absolute) + seek_sec_abs = sec, seek_sec_rel = 0.0; + else + seek_sec_abs = 0.0, seek_sec_rel = sec; return cERR_CONTAINER_FFMPEG_NO_ERROR; } -static int container_ffmpeg_get_length(Context_t *context, double * length) { +static int container_ffmpeg_get_length(Context_t * context, double *length) +{ ffmpeg_printf(50, "\n"); - Track_t * videoTrack = NULL; - Track_t * audioTrack = NULL; - Track_t * subtitleTrack = NULL; - Track_t * current = NULL; + Track_t *videoTrack = NULL; + Track_t *audioTrack = NULL; + Track_t *subtitleTrack = NULL; + Track_t *current = NULL; if (length == NULL) { - ffmpeg_err( "null pointer passed\n"); + ffmpeg_err("null pointer passed\n"); return cERR_CONTAINER_FFMPEG_ERR; } - context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack); - context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack); - context->manager->subtitle->Command(context, MANAGER_GET_TRACK, &subtitleTrack); + context->manager->video->Command(context, MANAGER_GET_TRACK, + &videoTrack); + context->manager->audio->Command(context, MANAGER_GET_TRACK, + &audioTrack); + context->manager->subtitle->Command(context, MANAGER_GET_TRACK, + &subtitleTrack); if (videoTrack != NULL) current = videoTrack; @@ -1442,42 +1612,48 @@ static int container_ffmpeg_get_length(Context_t *context, double * length) { return cERR_CONTAINER_FFMPEG_ERR; else *length = (current->duration / 1000.0); - } - else { - if (avContext != NULL) - { + } else { + if (avContext != NULL) { *length = (avContext->duration / 1000.0); - } else - { - ffmpeg_err( "no Track not context ->no problem :D\n"); - return cERR_CONTAINER_FFMPEG_ERR; + } else { + ffmpeg_err("no Track not context ->no problem :D\n"); + return cERR_CONTAINER_FFMPEG_ERR; } } return cERR_CONTAINER_FFMPEG_NO_ERROR; } -static int container_ffmpeg_switch_audio(Context_t* context, int* arg) +static int container_ffmpeg_switch_audio(Context_t * context, int *arg) { ffmpeg_printf(10, "track %d\n", *arg); - /* Hellmaster1024: nothing to do here!*/ - float sec=-5.0; - context->playback->Command(context, PLAYBACK_SEEK, (void*)&sec); + /* Hellmaster1024: nothing to do here! */ + float sec = -5.0; + context->playback->Command(context, PLAYBACK_SEEK, (void *) &sec); return cERR_CONTAINER_FFMPEG_NO_ERROR; } -static int container_ffmpeg_switch_subtitle(Context_t* context __attribute__((unused)), int* arg __attribute__((unused))) +static int container_ffmpeg_switch_subtitle(Context_t * context + __attribute__ ((unused)), + int *arg + __attribute__ ((unused))) { - /* Hellmaster1024: nothing to do here!*/ + /* Hellmaster1024: nothing to do here! */ return cERR_CONTAINER_FFMPEG_NO_ERROR; } -static int container_ffmpeg_switch_dvbsubtitle(Context_t* context __attribute__((unused)), int* arg __attribute__((unused))) +static int container_ffmpeg_switch_dvbsubtitle(Context_t * context + __attribute__ ((unused)), + int *arg + __attribute__ ((unused))) { return cERR_CONTAINER_FFMPEG_NO_ERROR; } -static int container_ffmpeg_switch_teletext(Context_t* context __attribute__((unused)), int* arg __attribute__((unused))) +static int container_ffmpeg_switch_teletext(Context_t * context + __attribute__ ((unused)), + int *arg + __attribute__ ((unused))) { return cERR_CONTAINER_FFMPEG_NO_ERROR; } @@ -1490,55 +1666,50 @@ static int container_ffmpeg_switch_teletext(Context_t* context __attribute__((un * I do not free the string here because this is the wrong way. The mechanism * should be changed, or e2 should pass it in a different way... */ -static int container_ffmpeg_get_info(Context_t* context, char ** infoString) +static int container_ffmpeg_get_info(Context_t * context, + char **infoString) { - Track_t * videoTrack = NULL; - Track_t * audioTrack = NULL; - char* meta = NULL; + Track_t *videoTrack = NULL; + Track_t *audioTrack = NULL; + char *meta = NULL; ffmpeg_printf(20, ">\n"); - if (avContext != NULL) - { - if ((infoString == NULL) || (*infoString == NULL)) - { - ffmpeg_err("infostring NULL\n"); - return cERR_CONTAINER_FFMPEG_ERR; - } + if (avContext != NULL) { + if ((infoString == NULL) || (*infoString == NULL)) { + ffmpeg_err("infostring NULL\n"); + return cERR_CONTAINER_FFMPEG_ERR; + } - ffmpeg_printf(20, "%s\n", *infoString); + ffmpeg_printf(20, "%s\n", *infoString); - context->manager->video->Command(context, MANAGER_GET_TRACK, &videoTrack); - context->manager->audio->Command(context, MANAGER_GET_TRACK, &audioTrack); + context->manager->video->Command(context, MANAGER_GET_TRACK, + &videoTrack); + context->manager->audio->Command(context, MANAGER_GET_TRACK, + &audioTrack); - if ((meta = searchMeta(avContext->metadata, *infoString)) == NULL) - { - if (audioTrack != NULL) - { - AVStream* stream = audioTrack->stream; + if ((meta = searchMeta(avContext->metadata, *infoString)) == NULL) { + if (audioTrack != NULL) { + AVStream *stream = audioTrack->stream; - meta = searchMeta(stream->metadata, *infoString); - } + meta = searchMeta(stream->metadata, *infoString); + } - if ((meta == NULL) && (videoTrack != NULL)) - { - AVStream* stream = videoTrack->stream; + if ((meta == NULL) && (videoTrack != NULL)) { + AVStream *stream = videoTrack->stream; - meta = searchMeta(stream->metadata, *infoString); - } - } + meta = searchMeta(stream->metadata, *infoString); + } + } - if (meta != NULL) - { - *infoString = strdup(meta); - } - else - { - ffmpeg_printf(1, "no metadata found for \"%s\"\n", *infoString); - *infoString = strdup("not found"); - } - } else - { + if (meta != NULL) { + *infoString = strdup(meta); + } else { + ffmpeg_printf(1, "no metadata found for \"%s\"\n", + *infoString); + *infoString = strdup("not found"); + } + } else { ffmpeg_err("avContext NULL\n"); return cERR_CONTAINER_FFMPEG_ERR; } @@ -1547,9 +1718,9 @@ static int container_ffmpeg_get_info(Context_t* context, char ** infoString) } -static int Command(void *_context, ContainerCmd_t command, void * argument) +static int Command(void *_context, ContainerCmd_t command, void *argument) { - Context_t *context = (Context_t*) _context; + Context_t *context = (Context_t *) _context; int ret = cERR_CONTAINER_FFMPEG_NO_ERROR; ffmpeg_printf(50, "Command %d\n", command); @@ -1558,64 +1729,73 @@ static int Command(void *_context, ContainerCmd_t command, void * argument) return cERR_CONTAINER_FFMPEG_ERR; if (command == CONTAINER_INIT && avContext) return cERR_CONTAINER_FFMPEG_ERR; - switch(command) - { - case CONTAINER_INIT: { - char * filename = (char *)argument; - ret = container_ffmpeg_init(context, filename); - break; - } - case CONTAINER_PLAY: { - ret = container_ffmpeg_play(context); - break; - } - case CONTAINER_STOP: { - ret = container_ffmpeg_stop(context); - break; - } - case CONTAINER_SEEK: { - ret = container_ffmpeg_seek(context, (float)*((float*)argument), 0); - break; - } - case CONTAINER_SEEK_ABS: { - ret = container_ffmpeg_seek(context, (float)*((float*)argument), -1); - break; - } - case CONTAINER_LENGTH: { - double length = 0; - ret = container_ffmpeg_get_length(context, &length); + switch (command) { + case CONTAINER_INIT:{ + char *filename = (char *) argument; + ret = container_ffmpeg_init(context, filename); + break; + } + case CONTAINER_PLAY:{ + ret = container_ffmpeg_play(context); + break; + } + case CONTAINER_STOP:{ + ret = container_ffmpeg_stop(context); + break; + } + case CONTAINER_SEEK:{ + ret = + container_ffmpeg_seek(context, + (float) *((float *) argument), 0); + break; + } + case CONTAINER_SEEK_ABS:{ + ret = + container_ffmpeg_seek(context, + (float) *((float *) argument), -1); + break; + } + case CONTAINER_LENGTH:{ + double length = 0; + ret = container_ffmpeg_get_length(context, &length); - *((double*)argument) = (double)length; - break; - } - case CONTAINER_SWITCH_AUDIO: { - ret = container_ffmpeg_switch_audio(context, (int*) argument); - break; - } - case CONTAINER_SWITCH_SUBTITLE: { - ret = container_ffmpeg_switch_subtitle(context, (int*) argument); - break; - } - case CONTAINER_INFO: { - ret = container_ffmpeg_get_info(context, (char **)argument); - break; - } - case CONTAINER_STATUS: { - *((int*)argument) = hasPlayThreadStarted; - break; - } - case CONTAINER_LAST_PTS: { - *((long long int*)argument) = latestPts; - break; - } - case CONTAINER_SWITCH_DVBSUBTITLE: { - ret = container_ffmpeg_switch_dvbsubtitle(context, (int*) argument); - break; - } - case CONTAINER_SWITCH_TELETEXT: { - ret = container_ffmpeg_switch_teletext(context, (int*) argument); - break; - } + *((double *) argument) = (double) length; + break; + } + case CONTAINER_SWITCH_AUDIO:{ + ret = container_ffmpeg_switch_audio(context, (int *) argument); + break; + } + case CONTAINER_SWITCH_SUBTITLE:{ + ret = + container_ffmpeg_switch_subtitle(context, + (int *) argument); + break; + } + case CONTAINER_INFO:{ + ret = container_ffmpeg_get_info(context, (char **) argument); + break; + } + case CONTAINER_STATUS:{ + *((int *) argument) = hasPlayThreadStarted; + break; + } + case CONTAINER_LAST_PTS:{ + *((long long int *) argument) = latestPts; + break; + } + case CONTAINER_SWITCH_DVBSUBTITLE:{ + ret = + container_ffmpeg_switch_dvbsubtitle(context, + (int *) argument); + break; + } + case CONTAINER_SWITCH_TELETEXT:{ + ret = + container_ffmpeg_switch_teletext(context, + (int *) argument); + break; + } default: ffmpeg_err("ContainerCmd %d not supported!\n", command); ret = cERR_CONTAINER_FFMPEG_ERR; @@ -1627,7 +1807,10 @@ static int Command(void *_context, ContainerCmd_t command, void * argument) return ret; } -static char *FFMPEG_Capabilities[] = {"avi", "mkv", "mp4", "ts", "mov", "flv", "flac", "mp3", "mpg", "m2ts", "vob", "wmv","wma", "asf", "mp2", "m4v", "m4a", "divx", "dat", "mpeg", "trp", "mts", "vdr", "ogg", "wav", "wtv", "ogm", "3gp", NULL }; +static char *FFMPEG_Capabilities[] = + { "avi", "mkv", "mp4", "ts", "mov", "flv", "flac", "mp3", "mpg", +"m2ts", "vob", "wmv", "wma", "asf", "mp2", "m4v", "m4a", "divx", "dat", "mpeg", "trp", "mts", "vdr", +"ogg", "wav", "wtv", "ogm", "3gp", NULL }; Container_t FFMPEGContainer = { "FFMPEG", diff --git a/libeplayer3/container/text_srt.c b/libeplayer3/container/text_srt.c index 46f5f34..9ddf95b 100644 --- a/libeplayer3/container/text_srt.c +++ b/libeplayer3/container/text_srt.c @@ -74,7 +74,7 @@ static const char FILENAME[] = "text_srt.c"; /* ***************************** */ typedef struct { - char * File; + char *File; int Id; } SrtTrack_t; @@ -84,11 +84,11 @@ static pthread_t thread_sub; /* Varaibles */ /* ***************************** */ -static SrtTrack_t * Tracks; +static SrtTrack_t *Tracks; static int TrackCount = 0; -static int CurrentTrack = -1; //no as default. +static int CurrentTrack = -1; //no as default. -FILE * fsub = NULL; +FILE *fsub = NULL; static int hasThreadStarted = 0; @@ -100,28 +100,29 @@ static int hasThreadStarted = 0; /* MISC Functions */ /* ***************************** */ -void data_to_manager(Context_t *context, char* Text, unsigned long long int Pts, double Duration) +void data_to_manager(Context_t * context, char *Text, + unsigned long long int Pts, double Duration) { srt_printf(20, "--> Text= \"%s\"\n", Text); - if( context && - context->playback && - context->playback->isPlaying){ - int sl = strlen(Text)-1; - while(sl && (Text[sl]=='\n' || Text[sl]=='\r')) Text[sl--]='\0'; /*Delete last \n or \r */ - unsigned char* line = text_to_ass(Text, Pts, Duration); - srt_printf(50,"Sub text is %s\n",Text); - srt_printf(50,"Sub line is %s\n",line); - SubtitleData_t data; - data.data = line; - data.len = strlen((char*)line); - data.extradata = (unsigned char *) DEFAULT_ASS_HEAD; - data.extralen = strlen(DEFAULT_ASS_HEAD); - data.pts = Pts*90; - data.duration = Duration; + if (context && context->playback && context->playback->isPlaying) { + int sl = strlen(Text) - 1; + while (sl && (Text[sl] == '\n' || Text[sl] == '\r')) + Text[sl--] = '\0'; /*Delete last \n or \r */ + unsigned char *line = text_to_ass(Text, Pts, Duration); + srt_printf(50, "Sub text is %s\n", Text); + srt_printf(50, "Sub line is %s\n", line); + SubtitleData_t data; + data.data = line; + data.len = strlen((char *) line); + data.extradata = (unsigned char *) DEFAULT_ASS_HEAD; + data.extralen = strlen(DEFAULT_ASS_HEAD); + data.pts = Pts * 90; + data.duration = Duration; - context->container->assContainer->Command(context, CONTAINER_DATA, &data); - free(line); + context->container->assContainer->Command(context, CONTAINER_DATA, + &data); + free(line); } srt_printf(20, "<-- Text= \"%s\"\n", Text); @@ -131,72 +132,83 @@ void data_to_manager(Context_t *context, char* Text, unsigned long long int Pts, /* Worker Thread */ /* ***************************** */ -static void* SrtSubtitleThread(void *data) { +static void *SrtSubtitleThread(void *data) +{ int pos = 0; - char Data[MAXLINELENGTH]; + char Data[MAXLINELENGTH]; unsigned long long int Pts = 0; double Duration = 0; - char * Text = NULL; + char *Text = NULL; - Context_t *context = (Context_t*) data; + Context_t *context = (Context_t *) data; srt_printf(10, "\n"); - while(context && context->playback && context->playback->isPlaying && fsub && fgets(Data, MAXLINELENGTH, fsub)) { - srt_printf(20, "pos=%d\n", pos); + while (context && context->playback && context->playback->isPlaying + && fsub && fgets(Data, MAXLINELENGTH, fsub)) { + srt_printf(20, "pos=%d\n", pos); - if(pos == 0) - { - if(Data[0] == '\n' || Data[0] == '\0' || Data[0] == 13 /* ^M */) - continue; /* Empty line not allowed here */ - pos++; - } else if(pos == 1) - { - int ret, horIni, minIni, secIni, milIni, horFim, minFim, secFim, milFim; + if (pos == 0) { + if (Data[0] == '\n' || Data[0] == '\0' + || Data[0] == 13 /* ^M */ ) + continue; /* Empty line not allowed here */ + pos++; + } else if (pos == 1) { + int ret, horIni, minIni, secIni, milIni, horFim, minFim, + secFim, milFim; - ret = sscanf(Data, "%d:%d:%d,%d --> %d:%d:%d,%d", &horIni, &minIni, &secIni, &milIni, &horFim, &minFim, &secFim, &milFim); - if (ret!=8) continue; /* Data is not in correct format */ + ret = + sscanf(Data, "%d:%d:%d,%d --> %d:%d:%d,%d", &horIni, + &minIni, &secIni, &milIni, &horFim, &minFim, + &secFim, &milFim); + if (ret != 8) + continue; /* Data is not in correct format */ - Pts = (horIni*3600 + minIni*60 + secIni)*1000 + milIni; - Duration = ((horFim*3600 + minFim*60 + secFim) * 1000 + milFim - Pts) / 1000.0; + Pts = (horIni * 3600 + minIni * 60 + secIni) * 1000 + milIni; + Duration = + ((horFim * 3600 + minFim * 60 + secFim) * 1000 + milFim - + Pts) / 1000.0; - pos++; + pos++; - } else if(pos == 2) { - srt_printf(20, "Data[0] = %d \'%c\'\n", Data[0], Data[0]); + } else if (pos == 2) { + srt_printf(20, "Data[0] = %d \'%c\'\n", Data[0], Data[0]); - if(Data[0] == '\n' || Data[0] == '\0' || Data[0] == 13 /* ^M */) { - if(Text == NULL) - Text = strdup(" \n"); /* better to display at least one character */ + if (Data[0] == '\n' || Data[0] == '\0' + || Data[0] == 13 /* ^M */ ) { + if (Text == NULL) + Text = strdup(" \n"); /* better to display at least one character */ - /*Hellmaster 1024 since we have waited, we have to check if we are still paying */ - data_to_manager(context, Text, Pts, Duration); - free(Text); - Text = NULL; - pos = 0; - continue; - } + /*Hellmaster 1024 since we have waited, we have to check if we are still paying */ + data_to_manager(context, Text, Pts, Duration); + free(Text); + Text = NULL; + pos = 0; + continue; + } - if(!Text) { - Text = strdup(Data); - } else { - int length = strlen(Text) /* \0 -> \n */ + strlen(Data) + 2 /* \0 */; - char * tmpText = Text; - Text = (char*)malloc(length); + if (!Text) { + Text = strdup(Data); + } else { + int length = + strlen(Text) /* \0 -> \n */ +strlen(Data) + + 2 /* \0 */ ; + char *tmpText = Text; + Text = (char *) malloc(length); - strcpy(Text, tmpText); - strcat(Text, Data); - free(tmpText); - } - } - } /* while */ + strcpy(Text, tmpText); + strcat(Text, Data); + free(tmpText); + } + } + } /* while */ hasThreadStarted = 0; - if(Text) { - data_to_manager(context, Text, Pts, Duration); - free(Text); - Text = NULL; + if (Text) { + data_to_manager(context, Text, Pts, Duration); + free(Text); + Text = NULL; } srt_printf(0, "thread has ended\n"); @@ -208,58 +220,62 @@ static void* SrtSubtitleThread(void *data) { /* Functions */ /* ***************************** */ -static void SrtManagerAdd(Context_t *context __attribute__((unused)), SrtTrack_t track) { - srt_printf(10, "%s %d\n",track.File, track.Id); +static void SrtManagerAdd(Context_t * context + __attribute__ ((unused)), SrtTrack_t track) +{ + srt_printf(10, "%s %d\n", track.File, track.Id); if (Tracks == NULL) { - Tracks = malloc(sizeof(SrtTrack_t) * TRACKWRAP); + Tracks = malloc(sizeof(SrtTrack_t) * TRACKWRAP); } if (TrackCount < TRACKWRAP) { - Tracks[TrackCount].File = strdup(track.File); - Tracks[TrackCount].Id = track.Id; - TrackCount++; + Tracks[TrackCount].File = strdup(track.File); + Tracks[TrackCount].Id = track.Id; + TrackCount++; } } #if 0 -static char ** SrtManagerList(Context_t *context __attribute__((unused))) { - char ** tracklist = NULL; +static char **SrtManagerList(Context_t * context __attribute__ ((unused))) +{ + char **tracklist = NULL; srt_printf(10, "\n"); if (Tracks != NULL) { - char help[256]; - int i = 0, j = 0; + char help[256]; + int i = 0, j = 0; - tracklist = malloc(sizeof(char *) * ((TrackCount*2) + 1)); + tracklist = malloc(sizeof(char *) * ((TrackCount * 2) + 1)); - for (i = 0, j = 0; i < TrackCount; i++, j+=2) { + 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); - } - tracklist[j] = NULL; + sprintf(help, "%d", Tracks[i].Id); + tracklist[j] = strdup(help); + tracklist[j + 1] = strdup(Tracks[i].File); + } + tracklist[j] = NULL; } return tracklist; } #endif -static void SrtManagerDel(Context_t * context __attribute__((unused))) { +static void SrtManagerDel(Context_t * context __attribute__ ((unused))) +{ int i = 0; srt_printf(10, "\n"); - if(Tracks != NULL) { - for (i = 0; i < TrackCount; i++) { - if (Tracks[i].File != NULL) - free(Tracks[i].File); - Tracks[i].File = NULL; - } - free(Tracks); - Tracks = NULL; + if (Tracks != NULL) { + for (i = 0; i < TrackCount; i++) { + if (Tracks[i].File != NULL) + free(Tracks[i].File); + Tracks[i].File = NULL; + } + free(Tracks); + Tracks = NULL; } TrackCount = 0; @@ -267,31 +283,30 @@ static void SrtManagerDel(Context_t * context __attribute__((unused))) { } -static int SrtGetSubtitle(Context_t *context, char * Filename) { +static int SrtGetSubtitle(Context_t * context, char *Filename) +{ struct dirent *dirzeiger; - DIR * dir; - int i = TEXTSRTOFFSET; - char * copyFilename = NULL; - char * FilenameExtension = NULL; - char * FilenameFolder = NULL; - char * FilenameShort = NULL; + DIR *dir; + int i = TEXTSRTOFFSET; + char *copyFilename = NULL; + char *FilenameExtension = NULL; + char *FilenameFolder = NULL; + char *FilenameShort = NULL; srt_printf(10, "\n"); - if (Filename == NULL) - { - srt_err("Filename NULL\n"); - return cERR_SRT_ERROR; + if (Filename == NULL) { + srt_err("Filename NULL\n"); + return cERR_SRT_ERROR; } srt_printf(10, "file: %s\n", Filename); copyFilename = strdup(Filename); - if (copyFilename == NULL) - { - srt_err("copyFilename NULL\n"); - return cERR_SRT_ERROR; + if (copyFilename == NULL) { + srt_err("copyFilename NULL\n"); + return cERR_SRT_ERROR; } FilenameFolder = dirname(copyFilename); @@ -300,11 +315,10 @@ static int SrtGetSubtitle(Context_t *context, char * Filename) { FilenameExtension = getExtension(copyFilename); - if (FilenameExtension == NULL) - { - srt_err("FilenameExtension NULL\n"); - free(copyFilename); - return cERR_SRT_ERROR; + if (FilenameExtension == NULL) { + srt_err("FilenameExtension NULL\n"); + free(copyFilename); + return cERR_SRT_ERROR; } srt_printf(10, "ext: %s\n", FilenameExtension); @@ -312,84 +326,94 @@ static int SrtGetSubtitle(Context_t *context, char * Filename) { FilenameShort = basename(copyFilename); /* cut extension */ - FilenameShort[strlen(FilenameShort) - strlen(FilenameExtension) - 1] = '\0'; + FilenameShort[strlen(FilenameShort) - strlen(FilenameExtension) - 1] = + '\0'; srt_printf(10, "basename: %s\n", FilenameShort); - srt_printf(10, "%s\n%s | %s | %s\n", copyFilename, FilenameFolder, FilenameShort, FilenameExtension); + srt_printf(10, "%s\n%s | %s | %s\n", copyFilename, FilenameFolder, + FilenameShort, FilenameExtension); - if((dir = opendir(FilenameFolder)) != NULL) { - while((dirzeiger = readdir(dir)) != NULL) { - char subtitleFilename[PATH_MAX]; - char *subtitleExtension = NULL; + if ((dir = opendir(FilenameFolder)) != NULL) { + while ((dirzeiger = readdir(dir)) != NULL) { + char subtitleFilename[PATH_MAX]; + char *subtitleExtension = NULL; - srt_printf(20, "%s\n",(*dirzeiger).d_name); + srt_printf(20, "%s\n", (*dirzeiger).d_name); - strcpy(subtitleFilename, (*dirzeiger).d_name); + strcpy(subtitleFilename, (*dirzeiger).d_name); - // Extension of Relativ Subtitle File Name - subtitleExtension = getExtension(subtitleFilename); + // Extension of Relativ Subtitle File Name + subtitleExtension = getExtension(subtitleFilename); - if (subtitleExtension == NULL) - continue; + if (subtitleExtension == NULL) + continue; - if (strcmp(subtitleExtension, "srt") != 0) - continue; + if (strcmp(subtitleExtension, "srt") != 0) + continue; - /* cut extension */ - subtitleFilename[strlen(subtitleFilename) - strlen(subtitleExtension) - 1] = '\0'; + /* cut extension */ + subtitleFilename[strlen(subtitleFilename) - + strlen(subtitleExtension) - 1] = '\0'; - srt_printf(10, "%s %s\n", FilenameShort, subtitleFilename); + srt_printf(10, "%s %s\n", FilenameShort, subtitleFilename); - if (strncmp(FilenameShort, subtitleFilename,strlen(FilenameShort)) == 0) - { - char absSubtitleFileName[PATH_MAX]; - /* found something of interest, so now make an absolut path name */ + if (strncmp + (FilenameShort, subtitleFilename, + strlen(FilenameShort)) == 0) { + char absSubtitleFileName[PATH_MAX]; + /* found something of interest, so now make an absolut path name */ - sprintf(absSubtitleFileName, "%s/%s.%s", FilenameFolder, subtitleFilename, subtitleExtension); + sprintf(absSubtitleFileName, "%s/%s.%s", FilenameFolder, + subtitleFilename, subtitleExtension); - srt_printf(10, "SRT: %s [%s]\n", subtitleExtension, subtitleFilename); - srt_printf(10, "\t->%s\n", absSubtitleFileName); + srt_printf(10, "SRT: %s [%s]\n", subtitleExtension, + subtitleFilename); + srt_printf(10, "\t->%s\n", absSubtitleFileName); - SrtTrack_t SrtSubtitle = { - absSubtitleFileName, - i, - }; + SrtTrack_t SrtSubtitle = { + absSubtitleFileName, + i, + }; - SrtManagerAdd(context, SrtSubtitle); + SrtManagerAdd(context, SrtSubtitle); - Track_t Subtitle; + Track_t Subtitle; memset(&Subtitle, 0, sizeof(Subtitle)); Subtitle.Name = subtitleExtension; - Subtitle.Encoding = "S_TEXT/SRT"; - Subtitle.Id = i++, - context->manager->subtitle->Command(context, MANAGER_ADD, &Subtitle); - } - } /* while */ + Subtitle.Encoding = "S_TEXT/SRT"; + Subtitle.Id = i++, + context->manager->subtitle->Command(context, + MANAGER_ADD, + &Subtitle); + } + } /* while */ closedir(dir); - } /* if dir */ - + } + /* if dir */ free(copyFilename); srt_printf(10, "<\n"); return cERR_SRT_NO_ERROR; } -static int SrtOpenSubtitle(Context_t *context __attribute__((unused)), int pid) { +static int SrtOpenSubtitle(Context_t * context + __attribute__ ((unused)), int pid) +{ srt_printf(10, "\n"); - if(pid < TEXTSRTOFFSET) { - srt_err("trackid not for us\n"); - return cERR_SRT_ERROR; + if (pid < TEXTSRTOFFSET) { + srt_err("trackid not for us\n"); + return cERR_SRT_ERROR; } int trackid; for (trackid = 0; trackid < TrackCount; trackid++) if (Tracks[trackid].Id == pid) - break; + break; - if(trackid == TrackCount) { - srt_err("trackid not for us\n"); - return cERR_SRT_ERROR; + if (trackid == TrackCount) { + srt_err("trackid not for us\n"); + return cERR_SRT_ERROR; } srt_printf(10, "%s\n", Tracks[trackid].File); @@ -398,19 +422,19 @@ static int SrtOpenSubtitle(Context_t *context __attribute__((unused)), int pid) srt_printf(10, "%s\n", fsub ? "fsub!=NULL" : "fsub==NULL"); - if(!fsub) - { - srt_err("cannot open file %s\n", Tracks[trackid].File); - return cERR_SRT_ERROR; + if (!fsub) { + srt_err("cannot open file %s\n", Tracks[trackid].File); + return cERR_SRT_ERROR; } return cERR_SRT_NO_ERROR; } -static int SrtCloseSubtitle(Context_t *context __attribute__((unused))) { +static int SrtCloseSubtitle(Context_t * context __attribute__ ((unused))) +{ srt_printf(10, "\n"); - if(fsub) - fclose(fsub); + if (fsub) + fclose(fsub); /* this closes the thread! */ fsub = NULL; @@ -420,27 +444,29 @@ static int SrtCloseSubtitle(Context_t *context __attribute__((unused))) { return cERR_SRT_NO_ERROR; } -static int SrtSwitchSubtitle(Context_t *context, int* arg) { +static int SrtSwitchSubtitle(Context_t * context, int *arg) +{ int ret = cERR_SRT_NO_ERROR; srt_printf(10, "arg:%d\n", *arg); ret = SrtCloseSubtitle(context); - if (( (ret |= SrtOpenSubtitle(context, *arg)) == cERR_SRT_NO_ERROR) && (!hasThreadStarted)) - { - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&thread_sub, &attr, &SrtSubtitleThread, context); + if (((ret |= SrtOpenSubtitle(context, *arg)) == cERR_SRT_NO_ERROR) + && (!hasThreadStarted)) { + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&thread_sub, &attr, &SrtSubtitleThread, context); - hasThreadStarted = 1; + hasThreadStarted = 1; } return ret; } -static int SrtDel(Context_t *context) { +static int SrtDel(Context_t * context) +{ int ret = cERR_SRT_NO_ERROR; srt_printf(10, "\n"); @@ -451,29 +477,30 @@ static int SrtDel(Context_t *context) { return ret; } -static int Command(void *_context, ContainerCmd_t command, void * argument) { - Context_t *context = (Context_t*) _context; +static int Command(void *_context, ContainerCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_SRT_NO_ERROR; srt_printf(10, "\n"); - switch(command) { - case CONTAINER_INIT: { - char * filename = (char *)argument; - ret = SrtGetSubtitle(context, filename); - break; - } - case CONTAINER_DEL: { - ret = SrtDel(context); - break; - } - case CONTAINER_SWITCH_SUBTITLE: { - ret = SrtSwitchSubtitle(context, (int*) argument); - break; - } + switch (command) { + case CONTAINER_INIT:{ + char *filename = (char *) argument; + ret = SrtGetSubtitle(context, filename); + break; + } + case CONTAINER_DEL:{ + ret = SrtDel(context); + break; + } + case CONTAINER_SWITCH_SUBTITLE:{ + ret = SrtSwitchSubtitle(context, (int *) argument); + break; + } default: - srt_err("ConatinerCmd not supported! %d\n", command); - break; + srt_err("ConatinerCmd not supported! %d\n", command); + break; } srt_printf(10, "ret = %d\n", ret); diff --git a/libeplayer3/container/text_ssa.c b/libeplayer3/container/text_ssa.c index 04430e2..9319515 100644 --- a/libeplayer3/container/text_ssa.c +++ b/libeplayer3/container/text_ssa.c @@ -78,7 +78,7 @@ static const char FILENAME[] = "text_ssa.c"; /* ***************************** */ typedef struct { - char * File; + char *File; int Id; } SsaTrack_t; @@ -88,9 +88,9 @@ typedef struct { static pthread_t thread_sub; -static SsaTrack_t * Tracks; +static SsaTrack_t *Tracks; static int TrackCount = 0; -FILE * fssa = NULL; +FILE *fssa = NULL; static int hasThreadStarted = 0; @@ -110,44 +110,40 @@ char *SSAgetLine() k = tamAux = 0; - if(SSA_BUFFER_SIZE>0) - { + if (SSA_BUFFER_SIZE > 0) { - strInput = (char*)malloc(1*sizeof(char)); - strInput[0]='\0'; + strInput = (char *) malloc(1 * sizeof(char)); + strInput[0] = '\0'; - while(tamAux!=1) - { + while (tamAux != 1) { - if((ch = fgetc(fssa))!=EOF) - { - ungetc(ch , fssa); - fgets(c, SSA_BUFFER_SIZE, fssa); - strAux = (char*)strchr(c,'\n'); - tam = strlen(c); - if(strAux != NULL) - { - tamAux = strlen(strAux); - tam--; - } + if ((ch = fgetc(fssa)) != EOF) { + ungetc(ch, fssa); + fgets(c, SSA_BUFFER_SIZE, fssa); + strAux = (char *) strchr(c, '\n'); + tam = strlen(c); + if (strAux != NULL) { + tamAux = strlen(strAux); + tam--; + } - k = k + tam; - strInput = (char*)realloc(strInput, (k+1)*sizeof(char)); + k = k + tam; + strInput = + (char *) realloc(strInput, (k + 1) * sizeof(char)); - if(k!=tam) - strncat(strInput, c, tam); - else - strncpy(strInput, c, tam); + if (k != tam) + strncat(strInput, c, tam); + else + strncpy(strInput, c, tam); - strInput[k] = '\0'; + strInput[k] = '\0'; - } - else { - tamAux = 1; - fclose(fssa); - fssa = NULL; - } - } + } else { + tamAux = 1; + fclose(fssa); + fssa = NULL; + } + } } @@ -158,54 +154,55 @@ char *SSAgetLine() /* ***************************** */ /* Worker Thread */ /* ***************************** */ -static void* SsaSubtitleThread(void *Data) { - Context_t *context = (Context_t*) Data; - char * head =malloc(sizeof(char)*1); +static void *SsaSubtitleThread(void *Data) +{ + Context_t *context = (Context_t *) Data; + char *head = malloc(sizeof(char) * 1); ssa_printf(10, "\n"); - head[0]='\0'; + head[0] = '\0'; - while ( context && context->playback && context->playback->isPlaying && fssa ) { - char *line = NULL; + while (context && context->playback && context->playback->isPlaying + && fssa) { + char *line = NULL; - do - { - line = SSAgetLine(); - if(strncmp(line,"Dialogue: ",10)) { - int head_len = strlen(head); - int line_len = strlen(line); - head = realloc(head, line_len + head_len +2); - memcpy(head + head_len, line, sizeof(char)*line_len+1); - head[head_len + line_len] = '\n'; - head[head_len + line_len + 1] = '\0'; - } - } while (strncmp(line,"Dialogue: ",10)!=0 && fssa); + do { + line = SSAgetLine(); + if (strncmp(line, "Dialogue: ", 10)) { + int head_len = strlen(head); + int line_len = strlen(line); + head = realloc(head, line_len + head_len + 2); + memcpy(head + head_len, line, sizeof(char) * line_len + 1); + head[head_len + line_len] = '\n'; + head[head_len + line_len + 1] = '\0'; + } + } while (strncmp(line, "Dialogue: ", 10) != 0 && fssa); - /*Hellmaster 1024 since we have waited, we have to check if we are still paying */ - if( context && - context->playback && - context->playback->isPlaying) { - SubtitleData_t data; + /*Hellmaster 1024 since we have waited, we have to check if we are still paying */ + if (context && context->playback && context->playback->isPlaying) { + SubtitleData_t data; - data.data = (unsigned char*) line; - data.len = strlen(line); - data.extradata = (unsigned char*) head; - data.extralen = strlen(head); - data.pts = 0; - data.duration = 0.0; - context->container->assContainer->Command(context, CONTAINER_DATA, &data); - } - free(line); - line = NULL; - continue; + data.data = (unsigned char *) line; + data.len = strlen(line); + data.extradata = (unsigned char *) head; + data.extralen = strlen(head); + data.pts = 0; + data.duration = 0.0; + context->container->assContainer->Command(context, + CONTAINER_DATA, + &data); + } + free(line); + line = NULL; + continue; } hasThreadStarted = 0; - if(head) { - free(head); - head = NULL; + if (head) { + free(head); + head = NULL; } ssa_printf(0, "thread has ended\n"); @@ -217,88 +214,91 @@ static void* SsaSubtitleThread(void *Data) { /* Functions */ /* ***************************** */ -static void SsaManagerAdd(Context_t *context __attribute__((unused)), SsaTrack_t track) { +static void SsaManagerAdd(Context_t * context + __attribute__ ((unused)), SsaTrack_t track) +{ ssa_printf(10, "%s %d\n", track.File, track.Id); if (Tracks == NULL) { - Tracks = malloc(sizeof(SsaTrack_t) * TRACKWRAP); + Tracks = malloc(sizeof(SsaTrack_t) * TRACKWRAP); } if (TrackCount < TRACKWRAP) { - Tracks[TrackCount].File = strdup(track.File); - Tracks[TrackCount].Id = track.Id; - TrackCount++; + Tracks[TrackCount].File = strdup(track.File); + Tracks[TrackCount].Id = track.Id; + TrackCount++; } } #if 0 -static char ** SsaManagerList(Context_t *context __attribute__((unused))) { - char ** tracklist = NULL; +static char **SsaManagerList(Context_t * context __attribute__ ((unused))) +{ + char **tracklist = NULL; ssa_printf(10, "\n"); if (Tracks != NULL) { - char help[256]; - int i = 0, j = 0; + char help[256]; + int i = 0, j = 0; - tracklist = malloc(sizeof(char *) * ((TrackCount*2) + 1)); + tracklist = malloc(sizeof(char *) * ((TrackCount * 2) + 1)); - for (i = 0, j = 0; i < TrackCount; i++, j+=2) { + 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); - } - tracklist[j] = NULL; + sprintf(help, "%d", Tracks[i].Id); + tracklist[j] = strdup(help); + tracklist[j + 1] = strdup(Tracks[i].File); + } + tracklist[j] = NULL; } return tracklist; } #endif -static void SsaManagerDel(Context_t * context __attribute__((unused))) { +static void SsaManagerDel(Context_t * context __attribute__ ((unused))) +{ int i = 0; ssa_printf(10, "\n"); - if(Tracks != NULL) { - for (i = 0; i < TrackCount; i++) { - if (Tracks[i].File != NULL) - free(Tracks[i].File); - Tracks[i].File = NULL; - } - free(Tracks); - Tracks = NULL; + if (Tracks != NULL) { + for (i = 0; i < TrackCount; i++) { + if (Tracks[i].File != NULL) + free(Tracks[i].File); + Tracks[i].File = NULL; + } + free(Tracks); + Tracks = NULL; } TrackCount = 0; } -static int SsaGetSubtitle(Context_t *context, char * Filename) { +static int SsaGetSubtitle(Context_t * context, char *Filename) +{ struct dirent *dirzeiger; - DIR * dir; - int i = TEXTSSAOFFSET; - char * copyFilename = NULL; - char * FilenameExtension = NULL; - char * FilenameFolder = NULL; - char * FilenameShort = NULL; + DIR *dir; + int i = TEXTSSAOFFSET; + char *copyFilename = NULL; + char *FilenameExtension = NULL; + char *FilenameFolder = NULL; + char *FilenameShort = NULL; ssa_printf(10, "\n"); - if (Filename == NULL) - { - ssa_err("Filename NULL\n"); - return cERR_SSA_ERROR; + if (Filename == NULL) { + ssa_err("Filename NULL\n"); + return cERR_SSA_ERROR; } ssa_printf(10, "file: %s\n", Filename); copyFilename = strdup(Filename); - if (copyFilename == NULL) - { - ssa_err("copyFilename NULL\n"); - return cERR_SSA_ERROR; + if (copyFilename == NULL) { + ssa_err("copyFilename NULL\n"); + return cERR_SSA_ERROR; } FilenameFolder = dirname(copyFilename); @@ -307,11 +307,10 @@ static int SsaGetSubtitle(Context_t *context, char * Filename) { FilenameExtension = getExtension(copyFilename); - if (FilenameExtension == NULL) - { - ssa_err("FilenameExtension NULL\n"); - free(copyFilename); - return cERR_SSA_ERROR; + if (FilenameExtension == NULL) { + ssa_err("FilenameExtension NULL\n"); + free(copyFilename); + return cERR_SSA_ERROR; } ssa_printf(10, "ext: %s\n", FilenameExtension); @@ -319,84 +318,94 @@ static int SsaGetSubtitle(Context_t *context, char * Filename) { FilenameShort = basename(copyFilename); /* cut extension */ - FilenameShort[strlen(FilenameShort) - strlen(FilenameExtension) - 1] = '\0'; + FilenameShort[strlen(FilenameShort) - strlen(FilenameExtension) - 1] = + '\0'; ssa_printf(10, "basename: %s\n", FilenameShort); - ssa_printf(10, "%s\n%s | %s | %s\n", copyFilename, FilenameFolder, FilenameShort, FilenameExtension); + ssa_printf(10, "%s\n%s | %s | %s\n", copyFilename, FilenameFolder, + FilenameShort, FilenameExtension); - if((dir = opendir(FilenameFolder)) != NULL) { - while((dirzeiger = readdir(dir)) != NULL) { - char subtitleFilename[PATH_MAX]; - char *subtitleExtension = NULL; + if ((dir = opendir(FilenameFolder)) != NULL) { + while ((dirzeiger = readdir(dir)) != NULL) { + char subtitleFilename[PATH_MAX]; + char *subtitleExtension = NULL; - ssa_printf(20, "%s\n",(*dirzeiger).d_name); + ssa_printf(20, "%s\n", (*dirzeiger).d_name); - strcpy(subtitleFilename, (*dirzeiger).d_name); + strcpy(subtitleFilename, (*dirzeiger).d_name); - // Extension of Relativ Subtitle File Name - subtitleExtension = getExtension(subtitleFilename); + // Extension of Relativ Subtitle File Name + subtitleExtension = getExtension(subtitleFilename); - if (subtitleExtension == NULL) - continue; + if (subtitleExtension == NULL) + continue; - if ( strcmp(subtitleExtension, "ssa") != 0 && strcmp(subtitleExtension, "ass") != 0 ) - continue; + if (strcmp(subtitleExtension, "ssa") != 0 + && strcmp(subtitleExtension, "ass") != 0) + continue; - /* cut extension */ - subtitleFilename[strlen(subtitleFilename) - strlen(subtitleExtension) - 1] = '\0'; + /* cut extension */ + subtitleFilename[strlen(subtitleFilename) - + strlen(subtitleExtension) - 1] = '\0'; - ssa_printf(10, "%s %s\n", FilenameShort, subtitleFilename); + ssa_printf(10, "%s %s\n", FilenameShort, subtitleFilename); - if (strncmp(FilenameShort, subtitleFilename,strlen(FilenameShort)) == 0) - { - char absSubtitleFileName[PATH_MAX]; - /* found something of interest, so now make an absolut path name */ + if (strncmp + (FilenameShort, subtitleFilename, + strlen(FilenameShort)) == 0) { + char absSubtitleFileName[PATH_MAX]; + /* found something of interest, so now make an absolut path name */ - sprintf(absSubtitleFileName, "%s/%s.%s", FilenameFolder, subtitleFilename, subtitleExtension); + sprintf(absSubtitleFileName, "%s/%s.%s", FilenameFolder, + subtitleFilename, subtitleExtension); - ssa_printf(10, "SSA: %s [%s]\n", subtitleExtension, subtitleFilename); - ssa_printf(10, "\t->%s\n", absSubtitleFileName); + ssa_printf(10, "SSA: %s [%s]\n", subtitleExtension, + subtitleFilename); + ssa_printf(10, "\t->%s\n", absSubtitleFileName); - SsaTrack_t SsaSubtitle = { - absSubtitleFileName, - i, - }; + SsaTrack_t SsaSubtitle = { + absSubtitleFileName, + i, + }; - SsaManagerAdd(context, SsaSubtitle); + SsaManagerAdd(context, SsaSubtitle); - Track_t Subtitle; + Track_t Subtitle; memset(&Subtitle, 0, sizeof(Subtitle)); - Subtitle.Name = subtitleExtension; - Subtitle.Encoding = "S_TEXT/SSA"; - Subtitle.Id = i++; - context->manager->subtitle->Command(context, MANAGER_ADD, &Subtitle); - } - } /* while */ + Subtitle.Name = subtitleExtension; + Subtitle.Encoding = "S_TEXT/SSA"; + Subtitle.Id = i++; + context->manager->subtitle->Command(context, MANAGER_ADD, + &Subtitle); + } + } /* while */ closedir(dir); - } /* if dir */ - + } + /* if dir */ free(copyFilename); ssa_printf(10, "<\n"); return cERR_SSA_NO_ERROR; } -static int SsaOpenSubtitle(Context_t *context __attribute__((unused)), int pid) { +static int SsaOpenSubtitle(Context_t * context + __attribute__ ((unused)), int pid) +{ ssa_printf(10, "\n"); - if(pid < TEXTSSAOFFSET) { - ssa_err("trackid not for us\n"); - return cERR_SSA_ERROR; + if (pid < TEXTSSAOFFSET) { + ssa_err("trackid not for us\n"); + return cERR_SSA_ERROR; } int trackid; for (trackid = 0; trackid < TrackCount; trackid++) if (Tracks[trackid].Id == pid) - break; + break; - if(trackid == TrackCount) { - ssa_err("trackid not for us\n"); - return cERR_SSA_ERROR; + if (trackid == TrackCount) { + ssa_err("trackid not for us\n"); + return cERR_SSA_ERROR; } ssa_printf(10, "%s\n", Tracks[trackid].File); @@ -405,19 +414,19 @@ static int SsaOpenSubtitle(Context_t *context __attribute__((unused)), int pid) ssa_printf(10, "%s\n", fssa ? "fssa!=NULL" : "fssa==NULL"); - if (!fssa) - { - ssa_err("cannot open file %s\n", Tracks[trackid].File); - return cERR_SSA_ERROR; + if (!fssa) { + ssa_err("cannot open file %s\n", Tracks[trackid].File); + return cERR_SSA_ERROR; } return cERR_SSA_NO_ERROR; } -static int SsaCloseSubtitle(Context_t *context __attribute__((unused))) { +static int SsaCloseSubtitle(Context_t * context __attribute__ ((unused))) +{ ssa_printf(10, "\n"); - if(fssa) - fclose(fssa); + if (fssa) + fclose(fssa); /* this closes the thread! */ fssa = NULL; @@ -427,27 +436,29 @@ static int SsaCloseSubtitle(Context_t *context __attribute__((unused))) { return cERR_SSA_NO_ERROR; } -static int SsaSwitchSubtitle(Context_t *context, int* arg) { +static int SsaSwitchSubtitle(Context_t * context, int *arg) +{ int ret = cERR_SSA_NO_ERROR; ssa_printf(10, "\n"); ret = SsaCloseSubtitle(context); - if (((ret |= SsaOpenSubtitle(context, *arg)) == cERR_SSA_NO_ERROR) && (!hasThreadStarted)) - { - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&thread_sub, &attr, &SsaSubtitleThread, context); + if (((ret |= SsaOpenSubtitle(context, *arg)) == cERR_SSA_NO_ERROR) + && (!hasThreadStarted)) { + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&thread_sub, &attr, &SsaSubtitleThread, context); - hasThreadStarted = 1; + hasThreadStarted = 1; } return ret; } -static int SsaDel(Context_t *context) { +static int SsaDel(Context_t * context) +{ int ret = cERR_SSA_NO_ERROR; ssa_printf(10, "\n"); @@ -459,29 +470,30 @@ static int SsaDel(Context_t *context) { return ret; } -static int Command(void *_context, ContainerCmd_t command, void * argument) { - Context_t *context = (Context_t*) _context; +static int Command(void *_context, ContainerCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_SSA_NO_ERROR; ssa_printf(10, "\n"); - switch(command) { - case CONTAINER_INIT: { - char * filename = (char *)argument; - ret = SsaGetSubtitle(context, filename); - break; - } - case CONTAINER_DEL: { - ret = SsaDel(context); - break; - } - case CONTAINER_SWITCH_SUBTITLE: { - ret = SsaSwitchSubtitle(context, (int*) argument); - break; - } + switch (command) { + case CONTAINER_INIT:{ + char *filename = (char *) argument; + ret = SsaGetSubtitle(context, filename); + break; + } + case CONTAINER_DEL:{ + ret = SsaDel(context); + break; + } + case CONTAINER_SWITCH_SUBTITLE:{ + ret = SsaSwitchSubtitle(context, (int *) argument); + break; + } default: - ssa_err("ConatinerCmd not supported! %d\n", command); - break; + ssa_err("ConatinerCmd not supported! %d\n", command); + break; } ssa_printf(10, "ret = %d\n", ret); diff --git a/libeplayer3/include/aac.h b/libeplayer3/include/aac.h index b9a6283..ce4f85e 100644 --- a/libeplayer3/include/aac.h +++ b/libeplayer3/include/aac.h @@ -22,36 +22,36 @@ #define AAC_HEADER_LENGTH 7 -static inline int aac_get_sample_rate_index (uint32_t sample_rate) +static inline int aac_get_sample_rate_index(uint32_t sample_rate) { if (96000 <= sample_rate) - return 0; + return 0; else if (88200 <= sample_rate) - return 1; + return 1; else if (64000 <= sample_rate) - return 2; + return 2; else if (48000 <= sample_rate) - return 3; + return 3; else if (44100 <= sample_rate) - return 4; + return 4; else if (32000 <= sample_rate) - return 5; + return 5; else if (24000 <= sample_rate) - return 6; + return 6; else if (22050 <= sample_rate) - return 7; + return 7; else if (16000 <= sample_rate) - return 8; + return 8; else if (12000 <= sample_rate) - return 9; + return 9; else if (11025 <= sample_rate) - return 10; + return 10; else if (8000 <= sample_rate) - return 11; + return 11; else if (7350 <= sample_rate) - return 12; + return 12; else - return 13; + return 13; } #endif diff --git a/libeplayer3/include/common.h b/libeplayer3/include/common.h index 6147750..452dffb 100644 --- a/libeplayer3/include/common.h +++ b/libeplayer3/include/common.h @@ -8,11 +8,12 @@ #include typedef struct Context_s { - PlaybackHandler_t * playback; - ContainerHandler_t * container; - OutputHandler_t * output; - ManagerHandler_t * manager; + PlaybackHandler_t *playback; + ContainerHandler_t *container; + OutputHandler_t *output; + ManagerHandler_t *manager; } Context_t; -int container_ffmpeg_update_tracks(Context_t *context, char *filename, int initial); +int container_ffmpeg_update_tracks(Context_t * context, char *filename, + int initial); #endif diff --git a/libeplayer3/include/container.h b/libeplayer3/include/container.h index b4bba9f..dac8709 100644 --- a/libeplayer3/include/container.h +++ b/libeplayer3/include/container.h @@ -3,30 +3,30 @@ #include -typedef enum { -CONTAINER_INIT, -CONTAINER_ADD, -CONTAINER_CAPABILITIES, -CONTAINER_PLAY, -CONTAINER_STOP, -CONTAINER_SEEK, -CONTAINER_SEEK_ABS, -CONTAINER_LENGTH, -CONTAINER_DEL, -CONTAINER_SWITCH_AUDIO, -CONTAINER_SWITCH_SUBTITLE, -CONTAINER_SWITCH_DVBSUBTITLE, -CONTAINER_SWITCH_TELETEXT, -CONTAINER_INFO, -CONTAINER_STATUS, -CONTAINER_LAST_PTS, -CONTAINER_DATA +typedef enum { + CONTAINER_INIT, + CONTAINER_ADD, + CONTAINER_CAPABILITIES, + CONTAINER_PLAY, + CONTAINER_STOP, + CONTAINER_SEEK, + CONTAINER_SEEK_ABS, + CONTAINER_LENGTH, + CONTAINER_DEL, + CONTAINER_SWITCH_AUDIO, + CONTAINER_SWITCH_SUBTITLE, + CONTAINER_SWITCH_DVBSUBTITLE, + CONTAINER_SWITCH_TELETEXT, + CONTAINER_INFO, + CONTAINER_STATUS, + CONTAINER_LAST_PTS, + CONTAINER_DATA } ContainerCmd_t; typedef struct Container_s { - char * Name; - int (* Command) (/*Context_t*/void *, ContainerCmd_t, void *); - char ** Capabilities; + char *Name; + int (*Command) ( /*Context_t */ void *, ContainerCmd_t, void *); + char **Capabilities; } Container_t; @@ -34,13 +34,13 @@ typedef struct Container_s { extern Container_t FFMPEGContainer; typedef struct ContainerHandler_s { - char * Name; - Container_t * selectedContainer; - Container_t * textSrtContainer; - Container_t * textSsaContainer; - Container_t * assContainer; + char *Name; + Container_t *selectedContainer; + Container_t *textSrtContainer; + Container_t *textSsaContainer; + Container_t *assContainer; - int (* Command) (/*Context_t*/void *, ContainerCmd_t, void *); + int (*Command) ( /*Context_t */ void *, ContainerCmd_t, void *); } ContainerHandler_t; #endif diff --git a/libeplayer3/include/debug.h b/libeplayer3/include/debug.h index 502f7a7..3951ca0 100644 --- a/libeplayer3/include/debug.h +++ b/libeplayer3/include/debug.h @@ -8,11 +8,10 @@ static inline void Hexdump(unsigned char *Data, int length) { int k; - for (k = 0; k < length; k++) - { - printf("%02x ", Data[k]); - if (((k+1)&31)==0) - printf("\n"); + for (k = 0; k < length; k++) { + printf("%02x ", Data[k]); + if (((k + 1) & 31) == 0) + printf("\n"); } printf("\n"); diff --git a/libeplayer3/include/ffmpeg_metadata.h b/libeplayer3/include/ffmpeg_metadata.h index b8a7472..4c2e640 100644 --- a/libeplayer3/include/ffmpeg_metadata.h +++ b/libeplayer3/include/ffmpeg_metadata.h @@ -11,35 +11,34 @@ /* metatdata map list: */ -char* metadata_map[] = -{ - /* our tags ffmpeg tag / id3v2 */ - "Title", "TIT2", - "Title", "TT2", - "Artist", "TPE1", - "Artist", "TP1", - "AlbumArtist", "TPE2", - "AlbumArtist", "TP2", - "Album", "TALB", - "Album", "TAL", - "Year", "TDRL", /* fixme */ - "Year", "TDRC", /* fixme */ - "Comment", "unknown", - "Track", "TRCK", - "Track", "TRK", - "Copyright", "TCOP", - "Composer", "TCOM", - "Genre", "TCON", - "Genre", "TCO", - "EncodedBy", "TENC", - "EncodedBy", "TEN", - "Language", "TLAN", - "Performer", "TPE3", - "Performer", "TP3", - "Publisher", "TPUB", - "Encoder", "TSSE", - "Disc", "TPOS", - NULL +char *metadata_map[] = { + /* our tags ffmpeg tag / id3v2 */ + "Title", "TIT2", + "Title", "TT2", + "Artist", "TPE1", + "Artist", "TP1", + "AlbumArtist", "TPE2", + "AlbumArtist", "TP2", + "Album", "TALB", + "Album", "TAL", + "Year", "TDRL", /* fixme */ + "Year", "TDRC", /* fixme */ + "Comment", "unknown", + "Track", "TRCK", + "Track", "TRK", + "Copyright", "TCOP", + "Composer", "TCOM", + "Genre", "TCON", + "Genre", "TCO", + "EncodedBy", "TENC", + "EncodedBy", "TEN", + "Language", "TLAN", + "Performer", "TPE3", + "Performer", "TP3", + "Publisher", "TPUB", + "Encoder", "TSSE", + "Disc", "TPOS", + NULL }; #endif diff --git a/libeplayer3/include/manager.h b/libeplayer3/include/manager.h index f5aa225..081f3e3 100644 --- a/libeplayer3/include/manager.h +++ b/libeplayer3/include/manager.h @@ -3,7 +3,7 @@ #include #include - + typedef enum { MANAGER_ADD, MANAGER_LIST, @@ -22,62 +22,62 @@ typedef enum { } eTrackTypeEplayer; typedef struct Track_s { - char * Name; - char * Encoding; - int Id; + char *Name; + char *Encoding; + int Id; /* new field for ffmpeg - add at the end so no problem - * can occur with not changed srt saa container - */ - char* language; + * can occur with not changed srt saa container + */ + char *language; /* length of track */ - long long int duration; - unsigned int frame_rate; - unsigned int TimeScale; - int version; - long long int pts; + long long int duration; + unsigned int frame_rate; + unsigned int TimeScale; + int version; + long long int pts; /* for later use: */ - eTrackTypeEplayer type; - int width; - int height; + eTrackTypeEplayer type; + int width; + int height; /* stream from ffmpeg */ - void * stream; + void *stream; /* codec extra data (header or some other stuff) */ - void * extraData; - int extraSize; + void *extraData; + int extraSize; - uint8_t* aacbuf; - unsigned int aacbuflen; - int have_aacheader; + uint8_t *aacbuf; + unsigned int aacbuflen; + int have_aacheader; /* If player2 or the elf do not support decoding of audio codec set this. * AVCodec is than used for softdecoding and stream will be injected as PCM */ - int inject_as_pcm; - int inject_raw_pcm; + int inject_as_pcm; + int inject_raw_pcm; - int pending; + int pending; } Track_t; typedef struct Manager_s { - char * Name; - int (* Command) (/*Context_t*/void *, ManagerCmd_t, void *); - char ** Capabilities; + char *Name; + int (*Command) ( /*Context_t */ void *, ManagerCmd_t, void *); + char **Capabilities; } Manager_t; typedef struct ManagerHandler_s { - char * Name; - Manager_t * audio; - Manager_t * video; - Manager_t * subtitle; - Manager_t * dvbsubtitle; - Manager_t * teletext; + char *Name; + Manager_t *audio; + Manager_t *video; + Manager_t *subtitle; + Manager_t *dvbsubtitle; + Manager_t *teletext; } ManagerHandler_t; -void freeTrack(Track_t* track); -void copyTrack(Track_t* to, Track_t* from); +void freeTrack(Track_t * track); +void copyTrack(Track_t * to, Track_t * from); #endif diff --git a/libeplayer3/include/misc.h b/libeplayer3/include/misc.h index bd248f2..0235229 100644 --- a/libeplayer3/include/misc.h +++ b/libeplayer3/include/misc.h @@ -9,11 +9,10 @@ /* Types */ /* ***************************** */ -typedef struct BitPacker_s -{ - unsigned char* Ptr; /* write pointer */ - unsigned int BitBuffer; /* bitreader shifter */ - int Remaining; /* number of remaining in the shifter */ +typedef struct BitPacker_s { + unsigned char *Ptr; /* write pointer */ + unsigned int BitBuffer; /* bitreader shifter */ + int Remaining; /* number of remaining in the shifter */ } BitPacker_t; /* ***************************** */ @@ -37,54 +36,52 @@ void FlushBits(BitPacker_t * ld); /* MISC Functions */ /* ***************************** */ -static inline char *getExtension(char * name) +static inline char *getExtension(char *name) { - if (name) { - char *ext = strrchr(name, '.'); - if (ext) - return ext + 1; - } - return NULL; + if (name) { + char *ext = strrchr(name, '.'); + if (ext) + return ext + 1; + } + return NULL; } /* the function returns the base name */ -static inline char * basename(char * name) +static inline char *basename(char *name) { - int i = 0; - int pos = 0; + int i = 0; + int pos = 0; - while(name[i] != 0) - { - if(name[i] == '/') - pos = i; - i++; - } + while (name[i] != 0) { + if (name[i] == '/') + pos = i; + i++; + } - if(name[pos] == '/') - pos++; + if (name[pos] == '/') + pos++; - return name + pos; + return name + pos; } /* the function returns the directry name */ -static inline char * dirname(char * name) +static inline char *dirname(char *name) { - static char path[100]; - unsigned int i = 0; - int pos = 0; + static char path[100]; + unsigned int i = 0; + int pos = 0; - while((name[i] != 0) && (i < sizeof(path))) - { - if(name[i] == '/') - pos = i; - path[i] = name[i]; - i++; - } + while ((name[i] != 0) && (i < sizeof(path))) { + if (name[i] == '/') + pos = i; + path[i] = name[i]; + i++; + } - path[i] = 0; - path[pos] = 0; + path[i] = 0; + path[pos] = 0; - return path; + return path; } #endif diff --git a/libeplayer3/include/output.h b/libeplayer3/include/output.h index 6b37060..d966e63 100644 --- a/libeplayer3/include/output.h +++ b/libeplayer3/include/output.h @@ -32,30 +32,29 @@ typedef enum { OUTPUT_SET_SUBTITLE_OUTPUT } OutputCmd_t; -typedef struct -{ - unsigned char* data; - unsigned int len; +typedef struct { + unsigned char *data; + unsigned int len; - unsigned char* extradata; - unsigned int extralen; - - unsigned long long int pts; - - float frameRate; - unsigned int timeScale; - - unsigned int width; - unsigned int height; - - char* type; + unsigned char *extradata; + unsigned int extralen; + + unsigned long long int pts; + + float frameRate; + unsigned int timeScale; + + unsigned int width; + unsigned int height; + + char *type; } AudioVideoOut_t; typedef struct Output_s { - char * Name; - int (* Command) (/*Context_t*/void *, OutputCmd_t, void *); - int (* Write) (/*Context_t*/void *, void* privateData); - char ** Capabilities; + char *Name; + int (*Command) ( /*Context_t */ void *, OutputCmd_t, void *); + int (*Write) ( /*Context_t */ void *, void *privateData); + char **Capabilities; } Output_t; @@ -64,13 +63,13 @@ extern Output_t SubtitleOutput; extern Output_t PipeOutput; typedef struct OutputHandler_s { - char * Name; - Output_t * audio; - Output_t * video; - Output_t * subtitle; - Output_t * dvbsubtitle; - Output_t * teletext; - int (* Command) (/*Context_t*/void *, OutputCmd_t, void *); + char *Name; + Output_t *audio; + Output_t *video; + Output_t *subtitle; + Output_t *dvbsubtitle; + Output_t *teletext; + int (*Command) ( /*Context_t */ void *, OutputCmd_t, void *); } OutputHandler_t; #endif diff --git a/libeplayer3/include/pcm.h b/libeplayer3/include/pcm.h index 36e2d76..416d047 100644 --- a/libeplayer3/include/pcm.h +++ b/libeplayer3/include/pcm.h @@ -20,8 +20,7 @@ #ifndef pcm_h_ #define pcm_h_ -typedef struct pcmPrivateData_s -{ +typedef struct pcmPrivateData_s { int uNoOfChannels; int uSampleRate; int uBitsPerSample; diff --git a/libeplayer3/include/pes.h b/libeplayer3/include/pes.h index 6a8d342..6af0050 100644 --- a/libeplayer3/include/pes.h +++ b/libeplayer3/include/pes.h @@ -26,7 +26,8 @@ #define VC1_VIDEO_PES_START_CODE 0xfd #define AAC_AUDIO_PES_START_CODE 0xcf -int InsertPesHeader (unsigned char *data, int size, unsigned char stream_id, unsigned long long int pts, int pic_start_code); +int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, + unsigned long long int pts, int pic_start_code); int InsertVideoPrivateDataHeader(unsigned char *data, int payload_size); #endif diff --git a/libeplayer3/include/playback.h b/libeplayer3/include/playback.h index 584ff03..64f6f06 100644 --- a/libeplayer3/include/playback.h +++ b/libeplayer3/include/playback.h @@ -2,10 +2,18 @@ #define PLAYBACK_H_ #include -typedef enum {PLAYBACK_OPEN, PLAYBACK_CLOSE, PLAYBACK_PLAY, PLAYBACK_STOP, PLAYBACK_PAUSE, PLAYBACK_CONTINUE, PLAYBACK_FLUSH, PLAYBACK_TERM, PLAYBACK_FASTFORWARD, PLAYBACK_SEEK, PLAYBACK_SEEK_ABS, PLAYBACK_PTS, PLAYBACK_LENGTH, PLAYBACK_SWITCH_AUDIO, PLAYBACK_SWITCH_SUBTITLE, PLAYBACK_INFO, PLAYBACK_SLOWMOTION, PLAYBACK_FASTBACKWARD, PLAYBACK_GET_FRAME_COUNT, PLAYBACK_SWITCH_TELETEXT, PLAYBACK_SWITCH_DVBSUBTITLE, PLAYBACK_FRAMEBUFFER_LOCK, PLAYBACK_FRAMEBUFFER_UNLOCK} PlaybackCmd_t; +typedef enum { PLAYBACK_OPEN, PLAYBACK_CLOSE, PLAYBACK_PLAY, PLAYBACK_STOP, + PLAYBACK_PAUSE, PLAYBACK_CONTINUE, PLAYBACK_FLUSH, PLAYBACK_TERM, + PLAYBACK_FASTFORWARD, PLAYBACK_SEEK, PLAYBACK_SEEK_ABS, + PLAYBACK_PTS, PLAYBACK_LENGTH, PLAYBACK_SWITCH_AUDIO, + PLAYBACK_SWITCH_SUBTITLE, PLAYBACK_INFO, PLAYBACK_SLOWMOTION, + PLAYBACK_FASTBACKWARD, PLAYBACK_GET_FRAME_COUNT, + PLAYBACK_SWITCH_TELETEXT, PLAYBACK_SWITCH_DVBSUBTITLE, + PLAYBACK_FRAMEBUFFER_LOCK, + PLAYBACK_FRAMEBUFFER_UNLOCK } PlaybackCmd_t; typedef struct PlaybackHandler_s { - char * Name; + char *Name; int fd; @@ -31,9 +39,9 @@ typedef struct PlaybackHandler_s { unsigned char mayWriteToFramebuffer; unsigned char abortRequested; - int (* Command) (/*Context_t*/void *, PlaybackCmd_t, void *); - char * uri; - unsigned char noprobe; /* hack: only minimal probing in av_find_stream_info */ + int (*Command) ( /*Context_t */ void *, PlaybackCmd_t, void *); + char *uri; + unsigned char noprobe; /* hack: only minimal probing in av_find_stream_info */ unsigned long long readCount; } PlaybackHandler_t; diff --git a/libeplayer3/include/subtitle.h b/libeplayer3/include/subtitle.h index 7d7b951..0737a47 100644 --- a/libeplayer3/include/subtitle.h +++ b/libeplayer3/include/subtitle.h @@ -33,93 +33,95 @@ Style: Default,Arial,64,16777215,0,16777215,0,0,0,2,2,2,2,20,20,10,0\n\n\ [Events]\n\ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n\n\n" -static inline unsigned char* text_to_ass(char *text, long long int pts, double duration) +static inline unsigned char *text_to_ass(char *text, long long int pts, + double duration) { - char buf[1024]; - unsigned int x,pos=0; - for(x=0;x #include -typedef enum { eNone, eAudio, eVideo, eGfx} eWriterType_t; +typedef enum { eNone, eAudio, eVideo, eGfx } eWriterType_t; typedef struct { - int fd; - unsigned char* data; - unsigned int len; + int fd; + unsigned char *data; + unsigned int len; unsigned long long int Pts; - unsigned char* private_data; - unsigned int private_size; - unsigned int FrameRate; - unsigned int FrameScale; - unsigned int Width; - unsigned int Height; - unsigned char Version; + unsigned char *private_data; + unsigned int private_size; + unsigned int FrameRate; + unsigned int FrameScale; + unsigned int Width; + unsigned int Height; + unsigned char Version; } WriterAVCallData_t; typedef struct { - unsigned char* data; - unsigned int Width; - unsigned int Height; - unsigned int Stride; - unsigned int color; + unsigned char *data; + unsigned int Width; + unsigned int Height; + unsigned int Stride; + unsigned int color; - unsigned int x; /* dst x ->given by ass */ - unsigned int y; /* dst y ->given by ass */ + unsigned int x; /* dst x ->given by ass */ + unsigned int y; /* dst y ->given by ass */ /* destination values if we use a shared framebuffer */ - int fd; - unsigned int Screen_Width; - unsigned int Screen_Height; - uint32_t *destination; - unsigned int destStride; + int fd; + unsigned int Screen_Width; + unsigned int Screen_Height; + uint32_t *destination; + unsigned int destStride; } WriterFBCallData_t; typedef struct WriterCaps_s { - char* name; - eWriterType_t type; - char* textEncoding; + char *name; + eWriterType_t type; + char *textEncoding; /* fixme: revise if this is an enum! */ - int dvbEncoding; + int dvbEncoding; } WriterCaps_t; typedef struct Writer_s { - int (* reset) (); - int (* writeData) (void*); - int (* writeReverseData) (void*); + int (*reset) (); + int (*writeData) (void *); + int (*writeReverseData) (void *); WriterCaps_t *caps; } Writer_t; @@ -79,10 +79,10 @@ extern Writer_t WriterFramebuffer; extern Writer_t WriterPipe; extern Writer_t WriterDVBSubtitle; -Writer_t* getWriter(char* encoding); +Writer_t *getWriter(char *encoding); -Writer_t* getDefaultVideoWriter(); -Writer_t* getDefaultAudioWriter(); -Writer_t* getDefaultFramebufferWriter(); +Writer_t *getDefaultVideoWriter(); +Writer_t *getDefaultAudioWriter(); +Writer_t *getDefaultFramebufferWriter(); #endif diff --git a/libeplayer3/manager/audio.c b/libeplayer3/manager/audio.c index 42e8112..cb40e14 100644 --- a/libeplayer3/manager/audio.c +++ b/libeplayer3/manager/audio.c @@ -65,9 +65,9 @@ static const char FILENAME[] = "audio.c"; /* Varaibles */ /* ***************************** */ -static Track_t * Tracks = NULL; +static Track_t *Tracks = NULL; static int TrackCount = 0; -static int CurrentTrack = 0; //TRACK[0] as default. +static int CurrentTrack = 0; //TRACK[0] as default. /* ***************************** */ /* Prototypes */ @@ -77,191 +77,208 @@ static int CurrentTrack = 0; //TRACK[0] as default. /* Functions */ /* ***************************** */ -static int ManagerAdd(Context_t *context, Track_t track) { +static int ManagerAdd(Context_t * context, Track_t track) +{ - audio_mgr_printf(10, "%s::%s name=\"%s\" encoding=\"%s\" id=%d\n", FILENAME, __FUNCTION__, track.Name, track.Encoding, track.Id); + audio_mgr_printf(10, "%s::%s name=\"%s\" encoding=\"%s\" id=%d\n", + FILENAME, __FUNCTION__, track.Name, track.Encoding, + track.Id); if (Tracks == NULL) { - Tracks = malloc(sizeof(Track_t) * TRACKWRAP); + Tracks = malloc(sizeof(Track_t) * TRACKWRAP); int i; for (i = 0; i < TRACKWRAP; i++) - Tracks[i].Id = -1; + Tracks[i].Id = -1; } - if (Tracks == NULL) - { - audio_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return cERR_AUDIO_MGR_ERROR; + if (Tracks == NULL) { + audio_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); + return cERR_AUDIO_MGR_ERROR; } int i; for (i = 0; i < TRACKWRAP; i++) { if (Tracks[i].Id == track.Id) { - Tracks[i].pending = 0; - return cERR_AUDIO_MGR_NO_ERROR; + Tracks[i].pending = 0; + return cERR_AUDIO_MGR_NO_ERROR; } } if (TrackCount < TRACKWRAP) { - copyTrack(&Tracks[TrackCount], &track); - TrackCount++; + copyTrack(&Tracks[TrackCount], &track); + TrackCount++; } else { - audio_mgr_err("%s:%s TrackCount out if range %d - %d\n", FILENAME, __FUNCTION__, TrackCount, TRACKWRAP); - return cERR_AUDIO_MGR_ERROR; + audio_mgr_err("%s:%s TrackCount out if range %d - %d\n", FILENAME, + __FUNCTION__, TrackCount, TRACKWRAP); + return cERR_AUDIO_MGR_ERROR; } if (TrackCount > 0) - context->playback->isAudio = 1; + context->playback->isAudio = 1; audio_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); return cERR_AUDIO_MGR_NO_ERROR; } -static char ** ManagerList(Context_t *context __attribute__((unused))) { +static char **ManagerList(Context_t * context __attribute__ ((unused))) +{ int i = 0, j = 0; - char ** tracklist = NULL; + char **tracklist = NULL; audio_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); if (Tracks != NULL) { - tracklist = malloc(sizeof(char *) * ((TrackCount*2) + 1)); + tracklist = malloc(sizeof(char *) * ((TrackCount * 2) + 1)); - if (tracklist == NULL) - { - audio_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return NULL; - } + if (tracklist == NULL) { + audio_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); + return NULL; + } - for (i = 0, j = 0; i < TrackCount; i++, j+=2) { + for (i = 0, j = 0; i < TrackCount; i++, j += 2) { if (Tracks[i].pending) continue; size_t len = strlen(Tracks[i].Name) + 20; char tmp[len]; snprintf(tmp, len, "%d %s\n", Tracks[i].Id, Tracks[i].Name); - tracklist[j] = strdup(tmp); - tracklist[j+1] = strdup(Tracks[i].Encoding); - } - tracklist[j] = NULL; + tracklist[j] = strdup(tmp); + tracklist[j + 1] = strdup(Tracks[i].Encoding); + } + tracklist[j] = NULL; } - audio_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, __FUNCTION__, tracklist, j, TrackCount); + audio_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, + __FUNCTION__, tracklist, j, TrackCount); return tracklist; } -static int ManagerDel(Context_t * context) { +static int ManagerDel(Context_t * context) +{ int i = 0; audio_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - if(Tracks != NULL) { - for (i = 0; i < TrackCount; i++) { - freeTrack(&Tracks[i]); - } - free(Tracks); - Tracks = NULL; - } else - { - audio_mgr_err("%s::%s nothing to delete!\n", FILENAME, __FUNCTION__); - return cERR_AUDIO_MGR_ERROR; + if (Tracks != NULL) { + for (i = 0; i < TrackCount; i++) { + freeTrack(&Tracks[i]); + } + free(Tracks); + Tracks = NULL; + } else { + audio_mgr_err("%s::%s nothing to delete!\n", FILENAME, + __FUNCTION__); + return cERR_AUDIO_MGR_ERROR; } TrackCount = 0; CurrentTrack = 0; context->playback->isAudio = 0; - audio_mgr_printf(10, "%s::%s return no error\n", FILENAME, __FUNCTION__); + audio_mgr_printf(10, "%s::%s return no error\n", FILENAME, + __FUNCTION__); return cERR_AUDIO_MGR_NO_ERROR; } -static int Command(void *_context, ManagerCmd_t command, void * argument) { - Context_t *context = (Context_t*) _context; +static int Command(void *_context, ManagerCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_AUDIO_MGR_NO_ERROR; audio_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - switch(command) { - case MANAGER_ADD: { - Track_t * track = argument; + switch (command) { + case MANAGER_ADD:{ + Track_t *track = argument; - ret = ManagerAdd(context, *track); - break; - } - case MANAGER_LIST: { - container_ffmpeg_update_tracks(context, context->playback->uri, 0); - *((char***)argument) = (char **)ManagerList(context); - break; - } - case MANAGER_GET: { - audio_mgr_printf(20, "%s::%s MANAGER_GET\n", FILENAME, __FUNCTION__); + ret = ManagerAdd(context, *track); + break; + } + case MANAGER_LIST:{ + container_ffmpeg_update_tracks(context, context->playback->uri, + 0); + *((char ***) argument) = (char **) ManagerList(context); + break; + } + case MANAGER_GET:{ + audio_mgr_printf(20, "%s::%s MANAGER_GET\n", FILENAME, + __FUNCTION__); - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((int*)argument) = (int)Tracks[CurrentTrack].Id; - else - *((int*)argument) = (int)-1; - break; - } - case MANAGER_GET_TRACK: { - audio_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", FILENAME, __FUNCTION__); + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((int *) argument) = (int) Tracks[CurrentTrack].Id; + else + *((int *) argument) = (int) -1; + break; + } + case MANAGER_GET_TRACK:{ + audio_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", FILENAME, + __FUNCTION__); - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((Track_t**)argument) = (Track_t*) &Tracks[CurrentTrack]; - else - *((Track_t**)argument) = NULL; - break; - } - case MANAGER_GETENCODING: { - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Encoding); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_GETNAME: { - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Name); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_SET: { - int i; - audio_mgr_printf(20, "%s::%s MANAGER_SET id=%d\n", FILENAME, __FUNCTION__, *((int*)argument)); + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((Track_t **) argument) = + (Track_t *) & Tracks[CurrentTrack]; + else + *((Track_t **) argument) = NULL; + break; + } + case MANAGER_GETENCODING:{ + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Encoding); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_GETNAME:{ + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Name); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_SET:{ + int i; + audio_mgr_printf(20, "%s::%s MANAGER_SET id=%d\n", FILENAME, + __FUNCTION__, *((int *) argument)); - for (i = 0; i < TrackCount; i++) - if (Tracks[i].Id == *((int*)argument)) { - CurrentTrack = i; - break; + for (i = 0; i < TrackCount; i++) + if (Tracks[i].Id == *((int *) argument)) { + CurrentTrack = i; + break; } - if (i == TrackCount) { - audio_mgr_err("%s::%s track id %d unknown\n", FILENAME, __FUNCTION__, *((int*)argument)); - ret = cERR_AUDIO_MGR_ERROR; - } - break; - } - case MANAGER_DEL: { - ret = ManagerDel(context); - break; - } - case MANAGER_INIT_UPDATE: { - int i; - for (i = 0; i < TrackCount; i++) + if (i == TrackCount) { + audio_mgr_err("%s::%s track id %d unknown\n", FILENAME, + __FUNCTION__, *((int *) argument)); + ret = cERR_AUDIO_MGR_ERROR; + } + break; + } + case MANAGER_DEL:{ + ret = ManagerDel(context); + break; + } + case MANAGER_INIT_UPDATE:{ + int i; + for (i = 0; i < TrackCount; i++) Tracks[i].pending = 1; - break; - } + break; + } default: - audio_mgr_err("%s::%s ContainerCmd %d not supported!\n", FILENAME, __FUNCTION__, command); - ret = cERR_AUDIO_MGR_ERROR; - break; + audio_mgr_err("%s::%s ContainerCmd %d not supported!\n", FILENAME, + __FUNCTION__, command); + ret = cERR_AUDIO_MGR_ERROR; + break; } - audio_mgr_printf(10, "%s:%s: returning %d\n", FILENAME, __FUNCTION__,ret); + audio_mgr_printf(10, "%s:%s: returning %d\n", FILENAME, __FUNCTION__, + ret); return ret; } diff --git a/libeplayer3/manager/dvbsubtitle.c b/libeplayer3/manager/dvbsubtitle.c index 607d932..aeca21e 100644 --- a/libeplayer3/manager/dvbsubtitle.c +++ b/libeplayer3/manager/dvbsubtitle.c @@ -65,7 +65,7 @@ static const char FILENAME[] = __FILE__; /* Varaibles */ /* ***************************** */ -static Track_t * Tracks = NULL; +static Track_t *Tracks = NULL; static int TrackCount = 0; static int CurrentTrack = -1; @@ -77,191 +77,213 @@ static int CurrentTrack = -1; /* Functions */ /* ***************************** */ -static int ManagerAdd(Context_t *context, Track_t track) { +static int ManagerAdd(Context_t * context, Track_t track) +{ - dvbsubtitle_mgr_printf(10, "%s::%s name=\"%s\" encoding=\"%s\" id=%d\n", FILENAME, __FUNCTION__, track.Name, track.Encoding, track.Id); + dvbsubtitle_mgr_printf(10, + "%s::%s name=\"%s\" encoding=\"%s\" id=%d\n", + FILENAME, __FUNCTION__, track.Name, + track.Encoding, track.Id); if (Tracks == NULL) { - Tracks = malloc(sizeof(Track_t) * TRACKWRAP); + Tracks = malloc(sizeof(Track_t) * TRACKWRAP); int i; for (i = 0; i < TRACKWRAP; i++) - Tracks[i].Id = -1; + Tracks[i].Id = -1; } - if (Tracks == NULL) - { - dvbsubtitle_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return cERR_DVBSUBTITLE_MGR_ERROR; + if (Tracks == NULL) { + dvbsubtitle_mgr_err("%s:%s malloc failed\n", FILENAME, + __FUNCTION__); + return cERR_DVBSUBTITLE_MGR_ERROR; } int i; for (i = 0; i < TRACKWRAP; i++) { if (Tracks[i].Id == track.Id) { - Tracks[i].pending = 0; - return cERR_DVBSUBTITLE_MGR_NO_ERROR; + Tracks[i].pending = 0; + return cERR_DVBSUBTITLE_MGR_NO_ERROR; } } if (TrackCount < TRACKWRAP) { - copyTrack(&Tracks[TrackCount], &track); - TrackCount++; + copyTrack(&Tracks[TrackCount], &track); + TrackCount++; } else { - dvbsubtitle_mgr_err("%s:%s TrackCount out if range %d - %d\n", FILENAME, __FUNCTION__, TrackCount, TRACKWRAP); - return cERR_DVBSUBTITLE_MGR_ERROR; + dvbsubtitle_mgr_err("%s:%s TrackCount out if range %d - %d\n", + FILENAME, __FUNCTION__, TrackCount, TRACKWRAP); + return cERR_DVBSUBTITLE_MGR_ERROR; } if (TrackCount > 0) - context->playback->isDvbSubtitle = 1; + context->playback->isDvbSubtitle = 1; dvbsubtitle_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); return cERR_DVBSUBTITLE_MGR_NO_ERROR; } -static char ** ManagerList(Context_t *context __attribute__((unused))) { +static char **ManagerList(Context_t * context __attribute__ ((unused))) +{ int i = 0, j = 0; - char ** tracklist = NULL; + char **tracklist = NULL; dvbsubtitle_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); if (Tracks != NULL) { - tracklist = malloc(sizeof(char *) * ((TrackCount*2) + 1)); + tracklist = malloc(sizeof(char *) * ((TrackCount * 2) + 1)); - if (tracklist == NULL) - { - dvbsubtitle_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return NULL; - } + if (tracklist == NULL) { + dvbsubtitle_mgr_err("%s:%s malloc failed\n", FILENAME, + __FUNCTION__); + return NULL; + } - for (i = 0, j = 0; i < TrackCount; i++, j+=2) { + for (i = 0, j = 0; i < TrackCount; i++, j += 2) { if (Tracks[i].pending) continue; size_t len = strlen(Tracks[i].Name) + 20; char tmp[len]; snprintf(tmp, len, "%d %s\n", Tracks[i].Id, Tracks[i].Name); - tracklist[j] = strdup(tmp); - tracklist[j+1] = strdup(Tracks[i].Encoding); - } - tracklist[j] = NULL; + tracklist[j] = strdup(tmp); + tracklist[j + 1] = strdup(Tracks[i].Encoding); + } + tracklist[j] = NULL; } - dvbsubtitle_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, __FUNCTION__, tracklist, j, TrackCount); + dvbsubtitle_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, + __FUNCTION__, tracklist, j, TrackCount); return tracklist; } -static int ManagerDel(Context_t * context) { +static int ManagerDel(Context_t * context) +{ int i = 0; dvbsubtitle_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - if(Tracks != NULL) { - for (i = 0; i < TrackCount; i++) { - freeTrack(&Tracks[i]); - } - free(Tracks); - Tracks = NULL; - } else - { - dvbsubtitle_mgr_err("%s::%s nothing to delete!\n", FILENAME, __FUNCTION__); - return cERR_DVBSUBTITLE_MGR_ERROR; + if (Tracks != NULL) { + for (i = 0; i < TrackCount; i++) { + freeTrack(&Tracks[i]); + } + free(Tracks); + Tracks = NULL; + } else { + dvbsubtitle_mgr_err("%s::%s nothing to delete!\n", FILENAME, + __FUNCTION__); + return cERR_DVBSUBTITLE_MGR_ERROR; } TrackCount = 0; CurrentTrack = -1; context->playback->isDvbSubtitle = 0; - dvbsubtitle_mgr_printf(10, "%s::%s return no error\n", FILENAME, __FUNCTION__); + dvbsubtitle_mgr_printf(10, "%s::%s return no error\n", FILENAME, + __FUNCTION__); return cERR_DVBSUBTITLE_MGR_NO_ERROR; } -static int Command(void *_context, ManagerCmd_t command, void * argument) { - Context_t *context = (Context_t*) _context; +static int Command(void *_context, ManagerCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_DVBSUBTITLE_MGR_NO_ERROR; dvbsubtitle_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - switch(command) { - case MANAGER_ADD: { - Track_t * track = argument; + switch (command) { + case MANAGER_ADD:{ + Track_t *track = argument; - ret = ManagerAdd(context, *track); - break; - } - case MANAGER_LIST: { - container_ffmpeg_update_tracks(context, context->playback->uri, 0); - *((char***)argument) = (char **)ManagerList(context); - break; - } - case MANAGER_GET: { - dvbsubtitle_mgr_printf(20, "%s::%s MANAGER_GET\n", FILENAME, __FUNCTION__); + ret = ManagerAdd(context, *track); + break; + } + case MANAGER_LIST:{ + container_ffmpeg_update_tracks(context, context->playback->uri, + 0); + *((char ***) argument) = (char **) ManagerList(context); + break; + } + case MANAGER_GET:{ + dvbsubtitle_mgr_printf(20, "%s::%s MANAGER_GET\n", FILENAME, + __FUNCTION__); - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((int*)argument) = (int)Tracks[CurrentTrack].Id; - else - *((int*)argument) = (int)-1; - break; - } - case MANAGER_GET_TRACK: { - dvbsubtitle_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", FILENAME, __FUNCTION__); + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((int *) argument) = (int) Tracks[CurrentTrack].Id; + else + *((int *) argument) = (int) -1; + break; + } + case MANAGER_GET_TRACK:{ + dvbsubtitle_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", + FILENAME, __FUNCTION__); - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((Track_t**)argument) = (Track_t*) &Tracks[CurrentTrack]; - else - *((Track_t**)argument) = NULL; - break; - } - case MANAGER_GETENCODING: { - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Encoding); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_GETNAME: { - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Name); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_SET: { - int i; - dvbsubtitle_mgr_printf(20, "%s::%s MANAGER_SET id=%d\n", FILENAME, __FUNCTION__, *((int*)argument)); + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((Track_t **) argument) = + (Track_t *) & Tracks[CurrentTrack]; + else + *((Track_t **) argument) = NULL; + break; + } + case MANAGER_GETENCODING:{ + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Encoding); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_GETNAME:{ + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Name); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_SET:{ + int i; + dvbsubtitle_mgr_printf(20, "%s::%s MANAGER_SET id=%d\n", + FILENAME, __FUNCTION__, + *((int *) argument)); - for (i = 0; i < TrackCount; i++) - if (Tracks[i].Id == *((int*)argument)) { - CurrentTrack = i; - break; + for (i = 0; i < TrackCount; i++) + if (Tracks[i].Id == *((int *) argument)) { + CurrentTrack = i; + break; } - if (i == TrackCount) { - dvbsubtitle_mgr_err("%s::%s track id %d unknown\n", FILENAME, __FUNCTION__, *((int*)argument)); - ret = cERR_DVBSUBTITLE_MGR_ERROR; - } - break; - } - case MANAGER_DEL: { - ret = ManagerDel(context); - break; - } - case MANAGER_INIT_UPDATE: { - int i; - for (i = 0; i < TrackCount; i++) + if (i == TrackCount) { + dvbsubtitle_mgr_err("%s::%s track id %d unknown\n", + FILENAME, __FUNCTION__, + *((int *) argument)); + ret = cERR_DVBSUBTITLE_MGR_ERROR; + } + break; + } + case MANAGER_DEL:{ + ret = ManagerDel(context); + break; + } + case MANAGER_INIT_UPDATE:{ + int i; + for (i = 0; i < TrackCount; i++) Tracks[i].pending = 1; - break; - } + break; + } default: - dvbsubtitle_mgr_err("%s::%s ContainerCmd %d not supported!\n", FILENAME, __FUNCTION__, command); - ret = cERR_DVBSUBTITLE_MGR_ERROR; - break; + dvbsubtitle_mgr_err("%s::%s ContainerCmd %d not supported!\n", + FILENAME, __FUNCTION__, command); + ret = cERR_DVBSUBTITLE_MGR_ERROR; + break; } - dvbsubtitle_mgr_printf(10, "%s:%s: returning %d\n", FILENAME, __FUNCTION__,ret); + dvbsubtitle_mgr_printf(10, "%s:%s: returning %d\n", FILENAME, + __FUNCTION__, ret); return ret; } diff --git a/libeplayer3/manager/manager.c b/libeplayer3/manager/manager.c index dfe6eff..25e8067 100644 --- a/libeplayer3/manager/manager.c +++ b/libeplayer3/manager/manager.c @@ -47,9 +47,7 @@ ManagerHandler_t ManagerHandler = { "ManagerHandler", &AudioManager, &VideoManager, - &SubtitleManager - , &DvbSubtitleManager - , &TeletextManager + &SubtitleManager, &DvbSubtitleManager, &TeletextManager }; /* ***************************** */ @@ -59,38 +57,38 @@ ManagerHandler_t ManagerHandler = { /* ***************************** */ /* Functions */ /* ***************************** */ -void copyTrack(Track_t* to, Track_t* from) +void copyTrack(Track_t * to, Track_t * from) { *to = *from; if (from->Name != NULL) - to->Name = strdup(from->Name); + to->Name = strdup(from->Name); else - to->Name = strdup("Unknown"); + to->Name = strdup("Unknown"); if (from->Encoding != NULL) - to->Encoding = strdup(from->Encoding); + to->Encoding = strdup(from->Encoding); else - to->Encoding = strdup("Unknown"); + to->Encoding = strdup("Unknown"); if (from->language != NULL) - to->language = strdup(from->language); + to->language = strdup(from->language); else - to->language = strdup("Unknown"); + to->language = strdup("Unknown"); } -void freeTrack(Track_t* track) +void freeTrack(Track_t * track) { if (track->Name != NULL) - free(track->Name); + free(track->Name); if (track->Encoding != NULL) - free(track->Encoding); + free(track->Encoding); if (track->language != NULL) - free(track->language); + free(track->language); if (track->aacbuf != NULL) - free(track->aacbuf); + free(track->aacbuf); } diff --git a/libeplayer3/manager/subtitle.c b/libeplayer3/manager/subtitle.c index 0494ac5..4841108 100644 --- a/libeplayer3/manager/subtitle.c +++ b/libeplayer3/manager/subtitle.c @@ -64,9 +64,9 @@ static const char FILENAME[] = "subtitle.c"; /* Varaibles */ /* ***************************** */ -static Track_t * Tracks = NULL; +static Track_t *Tracks = NULL; static int TrackCount = 0; -static int CurrentTrack = -1; //no as default. +static int CurrentTrack = -1; //no as default. /* ***************************** */ /* Prototypes */ @@ -76,194 +76,208 @@ static int CurrentTrack = -1; //no as default. /* Functions */ /* ***************************** */ -static int ManagerAdd(Context_t *context, Track_t track) { +static int ManagerAdd(Context_t * context, Track_t track) +{ - subtitle_mgr_printf(10, "%s::%s %s %s %d\n", FILENAME, __FUNCTION__, track.Name, track.Encoding, track.Id); + subtitle_mgr_printf(10, "%s::%s %s %s %d\n", FILENAME, __FUNCTION__, + track.Name, track.Encoding, track.Id); if (Tracks == NULL) { - Tracks = malloc(sizeof(Track_t) * TRACKWRAP); + Tracks = malloc(sizeof(Track_t) * TRACKWRAP); int i; for (i = 0; i < TRACKWRAP; i++) - Tracks[i].Id = -1; + Tracks[i].Id = -1; } - if (Tracks == NULL) - { - subtitle_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return cERR_SUBTITLE_MGR_ERROR; + if (Tracks == NULL) { + subtitle_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); + return cERR_SUBTITLE_MGR_ERROR; } int i; for (i = 0; i < TRACKWRAP; i++) { if (Tracks[i].Id == track.Id) { - Tracks[i].pending = 0; - return cERR_SUBTITLE_MGR_NO_ERROR; + Tracks[i].pending = 0; + return cERR_SUBTITLE_MGR_NO_ERROR; } } if (TrackCount < TRACKWRAP) { - copyTrack(&Tracks[TrackCount], &track); - TrackCount++; + copyTrack(&Tracks[TrackCount], &track); + TrackCount++; } else { - subtitle_mgr_err("%s:%s TrackCount out if range %d - %d\n", FILENAME, __FUNCTION__, TrackCount, TRACKWRAP); - return cERR_SUBTITLE_MGR_ERROR; + subtitle_mgr_err("%s:%s TrackCount out if range %d - %d\n", + FILENAME, __FUNCTION__, TrackCount, TRACKWRAP); + return cERR_SUBTITLE_MGR_ERROR; } if (TrackCount > 0) - context->playback->isSubtitle = 1; + context->playback->isSubtitle = 1; subtitle_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); return cERR_SUBTITLE_MGR_NO_ERROR; } -static char ** ManagerList(Context_t *context __attribute__((unused))) { - char ** tracklist = NULL; +static char **ManagerList(Context_t * context __attribute__ ((unused))) +{ + char **tracklist = NULL; int i = 0, j = 0; subtitle_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); if (Tracks != NULL) { - tracklist = malloc(sizeof(char *) * ((TrackCount*2) + 1)); + tracklist = malloc(sizeof(char *) * ((TrackCount * 2) + 1)); - if (tracklist == NULL) - { - subtitle_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return NULL; - } + if (tracklist == NULL) { + subtitle_mgr_err("%s:%s malloc failed\n", FILENAME, + __FUNCTION__); + return NULL; + } - for (i = 0, j = 0; i < TrackCount; i++, j+=2) { + for (i = 0, j = 0; i < TrackCount; i++, j += 2) { if (Tracks[i].pending) continue; size_t len = strlen(Tracks[i].Name) + 20; char tmp[len]; snprintf(tmp, len, "%d %s\n", Tracks[i].Id, Tracks[i].Name); - tracklist[j] = strdup(tmp); - tracklist[j+1] = strdup(Tracks[i].Encoding); - } + tracklist[j] = strdup(tmp); + tracklist[j + 1] = strdup(Tracks[i].Encoding); + } - tracklist[j] = NULL; + tracklist[j] = NULL; } - subtitle_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, __FUNCTION__, tracklist, j, TrackCount); + subtitle_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, + __FUNCTION__, tracklist, j, TrackCount); return tracklist; } -static int ManagerDel(Context_t * context) { +static int ManagerDel(Context_t * context) +{ int i = 0; subtitle_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - if(Tracks != NULL) { - for (i = 0; i < TrackCount; i++) { - freeTrack(&Tracks[i]); - } + if (Tracks != NULL) { + for (i = 0; i < TrackCount; i++) { + freeTrack(&Tracks[i]); + } - free(Tracks); - Tracks = NULL; - } else - { - subtitle_mgr_err("%s::%s nothing to delete!\n", FILENAME, __FUNCTION__); - return cERR_SUBTITLE_MGR_ERROR; + free(Tracks); + Tracks = NULL; + } else { + subtitle_mgr_err("%s::%s nothing to delete!\n", FILENAME, + __FUNCTION__); + return cERR_SUBTITLE_MGR_ERROR; } TrackCount = 0; CurrentTrack = -1; context->playback->isSubtitle = 0; - subtitle_mgr_printf(10, "%s::%s return no error\n", FILENAME, __FUNCTION__); + subtitle_mgr_printf(10, "%s::%s return no error\n", FILENAME, + __FUNCTION__); return cERR_SUBTITLE_MGR_NO_ERROR; } -static int Command(void *_context, ManagerCmd_t command, void * argument) { - Context_t *context = (Context_t*) _context; +static int Command(void *_context, ManagerCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_SUBTITLE_MGR_NO_ERROR; - subtitle_mgr_printf(50, "%s::%s %d\n", FILENAME, __FUNCTION__, command); + subtitle_mgr_printf(50, "%s::%s %d\n", FILENAME, __FUNCTION__, + command); - switch(command) { - case MANAGER_ADD: { - Track_t * track = argument; - ret = ManagerAdd(context, *track); - break; - } - case MANAGER_LIST: { - container_ffmpeg_update_tracks(context, context->playback->uri, 0); - *((char***)argument) = (char **)ManagerList(context); - break; - } - case MANAGER_GET: { - if (TrackCount > 0 && CurrentTrack >= 0) - *((int*)argument) = (int)Tracks[CurrentTrack].Id; - else - *((int*)argument) = (int)-1; - break; - } - case MANAGER_GET_TRACK: { - //subtitle_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", FILENAME, __FUNCTION__); + switch (command) { + case MANAGER_ADD:{ + Track_t *track = argument; + ret = ManagerAdd(context, *track); + break; + } + case MANAGER_LIST:{ + container_ffmpeg_update_tracks(context, context->playback->uri, + 0); + *((char ***) argument) = (char **) ManagerList(context); + break; + } + case MANAGER_GET:{ + if (TrackCount > 0 && CurrentTrack >= 0) + *((int *) argument) = (int) Tracks[CurrentTrack].Id; + else + *((int *) argument) = (int) -1; + break; + } + case MANAGER_GET_TRACK:{ + //subtitle_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", FILENAME, __FUNCTION__); - if ((TrackCount > 0) && (CurrentTrack >=0)) - { - subtitle_mgr_printf(120, "return %d, %p\n", CurrentTrack, &Tracks[CurrentTrack]); - *((Track_t**)argument) = (Track_t*) &Tracks[CurrentTrack]; - } - else - { - subtitle_mgr_printf(20, "return NULL\n"); - *((Track_t**)argument) = NULL; - } - break; - } - case MANAGER_GETENCODING: { - if (TrackCount > 0 && CurrentTrack >= 0) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Encoding); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_GETNAME: { - if (TrackCount > 0 && CurrentTrack >= 0) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Name); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_SET: { - int i; - subtitle_mgr_printf(20, "%s::%s MANAGER_SET id=%d\n", FILENAME, __FUNCTION__, *((int*)argument)); + if ((TrackCount > 0) && (CurrentTrack >= 0)) { + subtitle_mgr_printf(120, "return %d, %p\n", CurrentTrack, + &Tracks[CurrentTrack]); + *((Track_t **) argument) = + (Track_t *) & Tracks[CurrentTrack]; + } else { + subtitle_mgr_printf(20, "return NULL\n"); + *((Track_t **) argument) = NULL; + } + break; + } + case MANAGER_GETENCODING:{ + if (TrackCount > 0 && CurrentTrack >= 0) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Encoding); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_GETNAME:{ + if (TrackCount > 0 && CurrentTrack >= 0) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Name); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_SET:{ + int i; + subtitle_mgr_printf(20, "%s::%s MANAGER_SET id=%d\n", FILENAME, + __FUNCTION__, *((int *) argument)); - for (i = 0; i < TrackCount; i++) - if (Tracks[i].Id == *((int*)argument)) { - CurrentTrack = i; - break; + for (i = 0; i < TrackCount; i++) + if (Tracks[i].Id == *((int *) argument)) { + CurrentTrack = i; + break; } - if (i == TrackCount) { - subtitle_mgr_err("%s::%s track id %d unknown\n", FILENAME, __FUNCTION__, *((int*)argument)); - ret = cERR_SUBTITLE_MGR_ERROR; - } - break; - } - case MANAGER_DEL: { - ret = ManagerDel(context); - break; - } - case MANAGER_INIT_UPDATE: { - int i; - for (i = 0; i < TrackCount; i++) + if (i == TrackCount) { + subtitle_mgr_err("%s::%s track id %d unknown\n", FILENAME, + __FUNCTION__, *((int *) argument)); + ret = cERR_SUBTITLE_MGR_ERROR; + } + break; + } + case MANAGER_DEL:{ + ret = ManagerDel(context); + break; + } + case MANAGER_INIT_UPDATE:{ + int i; + for (i = 0; i < TrackCount; i++) Tracks[i].pending = 1; - break; - } + break; + } default: - subtitle_mgr_err("%s:%s: ConatinerCmd not supported!", FILENAME, __FUNCTION__); - ret = cERR_SUBTITLE_MGR_ERROR; - break; + subtitle_mgr_err("%s:%s: ConatinerCmd not supported!", FILENAME, + __FUNCTION__); + ret = cERR_SUBTITLE_MGR_ERROR; + break; } - subtitle_mgr_printf(50, "%s:%s: returning %d\n", FILENAME, __FUNCTION__,ret); + subtitle_mgr_printf(50, "%s:%s: returning %d\n", FILENAME, + __FUNCTION__, ret); return ret; } diff --git a/libeplayer3/manager/teletext.c b/libeplayer3/manager/teletext.c index acebb77..69c29fc 100644 --- a/libeplayer3/manager/teletext.c +++ b/libeplayer3/manager/teletext.c @@ -65,7 +65,7 @@ static const char FILENAME[] = __FILE__; /* Varaibles */ /* ***************************** */ -static Track_t * Tracks = NULL; +static Track_t *Tracks = NULL; static int TrackCount = 0; static int CurrentTrack = -1; @@ -77,191 +77,209 @@ static int CurrentTrack = -1; /* Functions */ /* ***************************** */ -static int ManagerAdd(Context_t *context, Track_t track) { +static int ManagerAdd(Context_t * context, Track_t track) +{ - teletext_mgr_printf(10, "%s::%s name=\"%s\" encoding=\"%s\" id=%d\n", FILENAME, __FUNCTION__, track.Name, track.Encoding, track.Id); + teletext_mgr_printf(10, "%s::%s name=\"%s\" encoding=\"%s\" id=%d\n", + FILENAME, __FUNCTION__, track.Name, track.Encoding, + track.Id); if (Tracks == NULL) { - Tracks = malloc(sizeof(Track_t) * TRACKWRAP); + Tracks = malloc(sizeof(Track_t) * TRACKWRAP); int i; for (i = 0; i < TRACKWRAP; i++) - Tracks[i].Id = -1; + Tracks[i].Id = -1; } - if (Tracks == NULL) - { - teletext_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return cERR_TELETEXT_MGR_ERROR; + if (Tracks == NULL) { + teletext_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); + return cERR_TELETEXT_MGR_ERROR; } int i; for (i = 0; i < TRACKWRAP; i++) { if (Tracks[i].Id == track.Id) { - Tracks[i].pending = 0; - return cERR_TELETEXT_MGR_NO_ERROR; + Tracks[i].pending = 0; + return cERR_TELETEXT_MGR_NO_ERROR; } } if (TrackCount < TRACKWRAP) { - copyTrack(&Tracks[TrackCount], &track); - TrackCount++; + copyTrack(&Tracks[TrackCount], &track); + TrackCount++; } else { - teletext_mgr_err("%s:%s TrackCount out if range %d - %d\n", FILENAME, __FUNCTION__, TrackCount, TRACKWRAP); - return cERR_TELETEXT_MGR_ERROR; + teletext_mgr_err("%s:%s TrackCount out if range %d - %d\n", + FILENAME, __FUNCTION__, TrackCount, TRACKWRAP); + return cERR_TELETEXT_MGR_ERROR; } if (TrackCount > 0) - context->playback->isTeletext = 1; + context->playback->isTeletext = 1; teletext_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); return cERR_TELETEXT_MGR_NO_ERROR; } -static char ** ManagerList(Context_t *context __attribute__((unused))) { +static char **ManagerList(Context_t * context __attribute__ ((unused))) +{ int i = 0, j = 0; - char ** tracklist = NULL; + char **tracklist = NULL; teletext_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); if (Tracks != NULL) { - tracklist = malloc(sizeof(char *) * ((TrackCount*2) + 1)); + tracklist = malloc(sizeof(char *) * ((TrackCount * 2) + 1)); - if (tracklist == NULL) - { - teletext_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return NULL; - } + if (tracklist == NULL) { + teletext_mgr_err("%s:%s malloc failed\n", FILENAME, + __FUNCTION__); + return NULL; + } - for (i = 0, j = 0; i < TrackCount; i++, j+=2) { + for (i = 0, j = 0; i < TrackCount; i++, j += 2) { if (Tracks[i].pending) continue; size_t len = strlen(Tracks[i].Name) + 20; char tmp[len]; snprintf(tmp, len, "%d %s\n", Tracks[i].Id, Tracks[i].Name); - tracklist[j] = strdup(tmp); - tracklist[j+1] = strdup(Tracks[i].Encoding); - } - tracklist[j] = NULL; + tracklist[j] = strdup(tmp); + tracklist[j + 1] = strdup(Tracks[i].Encoding); + } + tracklist[j] = NULL; } - teletext_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, __FUNCTION__, tracklist, j, TrackCount); + teletext_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, + __FUNCTION__, tracklist, j, TrackCount); return tracklist; } -static int ManagerDel(Context_t * context) { +static int ManagerDel(Context_t * context) +{ int i = 0; teletext_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - if(Tracks != NULL) { - for (i = 0; i < TrackCount; i++) { - freeTrack(&Tracks[i]); - } - free(Tracks); - Tracks = NULL; - } else - { - teletext_mgr_err("%s::%s nothing to delete!\n", FILENAME, __FUNCTION__); - return cERR_TELETEXT_MGR_ERROR; + if (Tracks != NULL) { + for (i = 0; i < TrackCount; i++) { + freeTrack(&Tracks[i]); + } + free(Tracks); + Tracks = NULL; + } else { + teletext_mgr_err("%s::%s nothing to delete!\n", FILENAME, + __FUNCTION__); + return cERR_TELETEXT_MGR_ERROR; } TrackCount = 0; CurrentTrack = -1; context->playback->isTeletext = 0; - teletext_mgr_printf(10, "%s::%s return no error\n", FILENAME, __FUNCTION__); + teletext_mgr_printf(10, "%s::%s return no error\n", FILENAME, + __FUNCTION__); return cERR_TELETEXT_MGR_NO_ERROR; } -static int Command(void *_context, ManagerCmd_t command, void * argument) { - Context_t *context = (Context_t*) _context; +static int Command(void *_context, ManagerCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_TELETEXT_MGR_NO_ERROR; teletext_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - switch(command) { - case MANAGER_ADD: { - Track_t * track = argument; + switch (command) { + case MANAGER_ADD:{ + Track_t *track = argument; - ret = ManagerAdd(context, *track); - break; - } - case MANAGER_LIST: { - container_ffmpeg_update_tracks(context, context->playback->uri, 0); - *((char***)argument) = (char **)ManagerList(context); - break; - } - case MANAGER_GET: { - teletext_mgr_printf(20, "%s::%s MANAGER_GET\n", FILENAME, __FUNCTION__); + ret = ManagerAdd(context, *track); + break; + } + case MANAGER_LIST:{ + container_ffmpeg_update_tracks(context, context->playback->uri, + 0); + *((char ***) argument) = (char **) ManagerList(context); + break; + } + case MANAGER_GET:{ + teletext_mgr_printf(20, "%s::%s MANAGER_GET\n", FILENAME, + __FUNCTION__); - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((int*)argument) = (int)Tracks[CurrentTrack].Id; - else - *((int*)argument) = (int)-1; - break; - } - case MANAGER_GET_TRACK: { - teletext_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", FILENAME, __FUNCTION__); + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((int *) argument) = (int) Tracks[CurrentTrack].Id; + else + *((int *) argument) = (int) -1; + break; + } + case MANAGER_GET_TRACK:{ + teletext_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", FILENAME, + __FUNCTION__); - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((Track_t**)argument) = (Track_t*) &Tracks[CurrentTrack]; - else - *((Track_t**)argument) = NULL; - break; - } - case MANAGER_GETENCODING: { - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Encoding); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_GETNAME: { - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Name); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_SET: { - int i; - teletext_mgr_printf(20, "%s::%s MANAGER_SET id=%d\n", FILENAME, __FUNCTION__, *((int*)argument)); + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((Track_t **) argument) = + (Track_t *) & Tracks[CurrentTrack]; + else + *((Track_t **) argument) = NULL; + break; + } + case MANAGER_GETENCODING:{ + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Encoding); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_GETNAME:{ + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Name); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_SET:{ + int i; + teletext_mgr_printf(20, "%s::%s MANAGER_SET id=%d\n", FILENAME, + __FUNCTION__, *((int *) argument)); - for (i = 0; i < TrackCount; i++) - if (Tracks[i].Id == *((int*)argument)) { - CurrentTrack = i; - break; + for (i = 0; i < TrackCount; i++) + if (Tracks[i].Id == *((int *) argument)) { + CurrentTrack = i; + break; } - if (i == TrackCount) { - teletext_mgr_err("%s::%s track id %d unknown\n", FILENAME, __FUNCTION__, *((int*)argument)); - ret = cERR_TELETEXT_MGR_ERROR; - } - break; - } - case MANAGER_DEL: { - ret = ManagerDel(context); - break; - } - case MANAGER_INIT_UPDATE: { - int i; - for (i = 0; i < TrackCount; i++) + if (i == TrackCount) { + teletext_mgr_err("%s::%s track id %d unknown\n", FILENAME, + __FUNCTION__, *((int *) argument)); + ret = cERR_TELETEXT_MGR_ERROR; + } + break; + } + case MANAGER_DEL:{ + ret = ManagerDel(context); + break; + } + case MANAGER_INIT_UPDATE:{ + int i; + for (i = 0; i < TrackCount; i++) Tracks[i].pending = 1; - break; - } + break; + } default: - teletext_mgr_err("%s::%s ContainerCmd %d not supported!\n", FILENAME, __FUNCTION__, command); - ret = cERR_TELETEXT_MGR_ERROR; - break; + teletext_mgr_err("%s::%s ContainerCmd %d not supported!\n", + FILENAME, __FUNCTION__, command); + ret = cERR_TELETEXT_MGR_ERROR; + break; } - teletext_mgr_printf(10, "%s:%s: returning %d\n", FILENAME, __FUNCTION__,ret); + teletext_mgr_printf(10, "%s:%s: returning %d\n", FILENAME, + __FUNCTION__, ret); return ret; } diff --git a/libeplayer3/manager/video.c b/libeplayer3/manager/video.c index c815143..801f98b 100644 --- a/libeplayer3/manager/video.c +++ b/libeplayer3/manager/video.c @@ -64,9 +64,9 @@ static const char FILENAME[] = "video.c"; /* Varaibles */ /* ***************************** */ -static Track_t * Tracks = NULL; +static Track_t *Tracks = NULL; static int TrackCount = 0; -static int CurrentTrack = 0; //TRACK[0] as default. +static int CurrentTrack = 0; //TRACK[0] as default. /* ***************************** */ /* Prototypes */ @@ -76,186 +76,198 @@ static int CurrentTrack = 0; //TRACK[0] as default. /* Functions */ /* ***************************** */ -static int ManagerAdd(Context_t *context, Track_t track) { +static int ManagerAdd(Context_t * context, Track_t track) +{ video_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); if (Tracks == NULL) { - Tracks = malloc(sizeof(Track_t) * TRACKWRAP); + Tracks = malloc(sizeof(Track_t) * TRACKWRAP); int i; for (i = 0; i < TRACKWRAP; i++) - Tracks[i].Id = -1; + Tracks[i].Id = -1; } - if (Tracks == NULL) - { - video_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return cERR_VIDEO_MGR_ERROR; + if (Tracks == NULL) { + video_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); + return cERR_VIDEO_MGR_ERROR; } int i; for (i = 0; i < TRACKWRAP; i++) { if (Tracks[i].Id == track.Id) { - Tracks[i].pending = 0; - return cERR_VIDEO_MGR_NO_ERROR; + Tracks[i].pending = 0; + return cERR_VIDEO_MGR_NO_ERROR; } } if (TrackCount < TRACKWRAP) { - copyTrack(&Tracks[TrackCount], &track); + copyTrack(&Tracks[TrackCount], &track); - TrackCount++; + TrackCount++; } else { - video_mgr_err("%s:%s TrackCount out if range %d - %d\n", FILENAME, __FUNCTION__, TrackCount, TRACKWRAP); - return cERR_VIDEO_MGR_ERROR; + video_mgr_err("%s:%s TrackCount out if range %d - %d\n", FILENAME, + __FUNCTION__, TrackCount, TRACKWRAP); + return cERR_VIDEO_MGR_ERROR; } if (TrackCount > 0) - context->playback->isVideo = 1; + context->playback->isVideo = 1; video_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); return cERR_VIDEO_MGR_NO_ERROR; } -static char ** ManagerList(Context_t *context __attribute__((unused))) { +static char **ManagerList(Context_t * context __attribute__ ((unused))) +{ int i = 0, j = 0; - char ** tracklist = NULL; + char **tracklist = NULL; video_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); if (Tracks != NULL) { - tracklist = malloc(sizeof(char *) * ((TrackCount*2) + 1)); + tracklist = malloc(sizeof(char *) * ((TrackCount * 2) + 1)); - if (tracklist == NULL) - { - video_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); - return NULL; - } + if (tracklist == NULL) { + video_mgr_err("%s:%s malloc failed\n", FILENAME, __FUNCTION__); + return NULL; + } - for (i = 0, j = 0; i < TrackCount; i++, j+=2) { + for (i = 0, j = 0; i < TrackCount; i++, j += 2) { if (Tracks[i].pending) continue; size_t len = strlen(Tracks[i].Name) + 20; char tmp[len]; snprintf(tmp, len, "%d %s\n", Tracks[i].Id, Tracks[i].Name); - tracklist[j] = strdup(tmp); - tracklist[j+1] = strdup(Tracks[i].Encoding); - } - tracklist[j] = NULL; + tracklist[j] = strdup(tmp); + tracklist[j + 1] = strdup(Tracks[i].Encoding); + } + tracklist[j] = NULL; } - video_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, __FUNCTION__, tracklist, j, TrackCount); + video_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME, + __FUNCTION__, tracklist, j, TrackCount); return tracklist; } -static int ManagerDel(Context_t * context) { +static int ManagerDel(Context_t * context) +{ int i = 0; video_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - if(Tracks != NULL) { - for (i = 0; i < TrackCount; i++) { - freeTrack(&Tracks[i]); - } - free(Tracks); - Tracks = NULL; - } else - { - video_mgr_err("%s::%s nothing to delete!\n", FILENAME, __FUNCTION__); - return cERR_VIDEO_MGR_ERROR; + if (Tracks != NULL) { + for (i = 0; i < TrackCount; i++) { + freeTrack(&Tracks[i]); + } + free(Tracks); + Tracks = NULL; + } else { + video_mgr_err("%s::%s nothing to delete!\n", FILENAME, + __FUNCTION__); + return cERR_VIDEO_MGR_ERROR; } TrackCount = 0; CurrentTrack = 0; context->playback->isVideo = 0; - video_mgr_printf(10, "%s::%s return no error\n", FILENAME, __FUNCTION__); + video_mgr_printf(10, "%s::%s return no error\n", FILENAME, + __FUNCTION__); return cERR_VIDEO_MGR_NO_ERROR; } -static int Command(void *_context, ManagerCmd_t command, void * argument) { - Context_t *context = (Context_t*) _context; +static int Command(void *_context, ManagerCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_VIDEO_MGR_NO_ERROR; video_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); - switch(command) { - case MANAGER_ADD: { - Track_t * track = argument; - ret = ManagerAdd(context, *track); - break; - } - case MANAGER_LIST: { - container_ffmpeg_update_tracks(context, context->playback->uri, 0); - *((char***)argument) = (char **)ManagerList(context); - break; - } - case MANAGER_GET: { - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((int*)argument) = (int)Tracks[CurrentTrack].Id; - else - *((int*)argument) = (int)-1; - break; - } - case MANAGER_GET_TRACK: { - video_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", FILENAME, __FUNCTION__); + switch (command) { + case MANAGER_ADD:{ + Track_t *track = argument; + ret = ManagerAdd(context, *track); + break; + } + case MANAGER_LIST:{ + container_ffmpeg_update_tracks(context, context->playback->uri, + 0); + *((char ***) argument) = (char **) ManagerList(context); + break; + } + case MANAGER_GET:{ + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((int *) argument) = (int) Tracks[CurrentTrack].Id; + else + *((int *) argument) = (int) -1; + break; + } + case MANAGER_GET_TRACK:{ + video_mgr_printf(20, "%s::%s MANAGER_GET_TRACK\n", FILENAME, + __FUNCTION__); - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((Track_t**)argument) = (Track_t*) &Tracks[CurrentTrack]; - else - *((Track_t**)argument) = NULL; - break; - } - case MANAGER_GETENCODING: { - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Encoding); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_GETNAME: { - if ((TrackCount > 0) && (CurrentTrack >=0)) - *((char**)argument) = (char *)strdup(Tracks[CurrentTrack].Name); - else - *((char**)argument) = (char *)strdup(""); - break; - } - case MANAGER_SET: { - int i; + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((Track_t **) argument) = + (Track_t *) & Tracks[CurrentTrack]; + else + *((Track_t **) argument) = NULL; + break; + } + case MANAGER_GETENCODING:{ + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Encoding); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_GETNAME:{ + if ((TrackCount > 0) && (CurrentTrack >= 0)) + *((char **) argument) = + (char *) strdup(Tracks[CurrentTrack].Name); + else + *((char **) argument) = (char *) strdup(""); + break; + } + case MANAGER_SET:{ + int i; - for (i = 0; i < TrackCount; i++) - if (Tracks[i].Id == *((int*)argument)) { - CurrentTrack = i; - break; + for (i = 0; i < TrackCount; i++) + if (Tracks[i].Id == *((int *) argument)) { + CurrentTrack = i; + break; } - if (i == TrackCount) - { - video_mgr_err("%s::%s track id %d unknown\n", FILENAME, __FUNCTION__, *((int*)argument)); - ret = cERR_VIDEO_MGR_ERROR; - } - break; - } - case MANAGER_DEL: { - ret = ManagerDel(context); - break; - } - case MANAGER_INIT_UPDATE: { - int i; - for (i = 0; i < TrackCount; i++) + if (i == TrackCount) { + video_mgr_err("%s::%s track id %d unknown\n", FILENAME, + __FUNCTION__, *((int *) argument)); + ret = cERR_VIDEO_MGR_ERROR; + } + break; + } + case MANAGER_DEL:{ + ret = ManagerDel(context); + break; + } + case MANAGER_INIT_UPDATE:{ + int i; + for (i = 0; i < TrackCount; i++) Tracks[i].pending = 1; - break; - } + break; + } default: - video_mgr_err("%s::%s ContainerCmd %d not supported!\n", FILENAME, __FUNCTION__, command); - ret = cERR_VIDEO_MGR_ERROR; - break; + video_mgr_err("%s::%s ContainerCmd %d not supported!\n", FILENAME, + __FUNCTION__, command); + ret = cERR_VIDEO_MGR_ERROR; + break; } - video_mgr_printf(10, "%s:%s: returning %d\n", FILENAME, __FUNCTION__,ret); + video_mgr_printf(10, "%s:%s: returning %d\n", FILENAME, __FUNCTION__, + ret); return ret; } diff --git a/libeplayer3/output/linuxdvb.c b/libeplayer3/output/linuxdvb.c index cf3f15e..eef2266 100644 --- a/libeplayer3/output/linuxdvb.c +++ b/libeplayer3/output/linuxdvb.c @@ -69,11 +69,11 @@ if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x ); #define cERR_LINUXDVB_NO_ERROR 0 #define cERR_LINUXDVB_ERROR -1 -static const char VIDEODEV[] = "/dev/dvb/adapter0/video0"; -static const char AUDIODEV[] = "/dev/dvb/adapter0/audio0"; +static const char VIDEODEV[] = "/dev/dvb/adapter0/video0"; +static const char AUDIODEV[] = "/dev/dvb/adapter0/audio0"; -static int videofd = -1; -static int audiofd = -1; +static int videofd = -1; +static int audiofd = -1; unsigned long long int sCURRENT_PTS = 0; @@ -82,13 +82,17 @@ pthread_mutex_t LinuxDVBmutex; /* ***************************** */ /* Prototypes */ /* ***************************** */ -int LinuxDvbStop(Context_t *context, char * type); +int LinuxDvbStop(Context_t * context, char *type); /* ***************************** */ /* MISC Functions */ /* ***************************** */ -void getLinuxDVBMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused))) { +void getLinuxDVBMutex(const char *filename + __attribute__ ((unused)), const char *function + __attribute__ ((unused)), int line + __attribute__ ((unused))) +{ linuxdvb_printf(250, "requesting mutex\n"); @@ -97,90 +101,97 @@ void getLinuxDVBMutex(const char *filename __attribute__((unused)), const char * linuxdvb_printf(250, "received mutex\n"); } -void releaseLinuxDVBMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused))) { +void releaseLinuxDVBMutex(const char *filename + __attribute__ ((unused)), const char *function + __attribute__ ((unused)), int line + __attribute__ ((unused))) +{ pthread_mutex_unlock(&LinuxDVBmutex); linuxdvb_printf(250, "released mutex\n"); } -int LinuxDvbOpen(Context_t *context __attribute__((unused)), char * type) { +int LinuxDvbOpen(Context_t * context __attribute__ ((unused)), char *type) +{ unsigned char video = !strcmp("video", type); unsigned char audio = !strcmp("audio", type); linuxdvb_printf(10, "v%d a%d\n", video, audio); if (video && videofd < 0) { - videofd = open(VIDEODEV, O_RDWR); + videofd = open(VIDEODEV, O_RDWR); - if (videofd < 0) - { - linuxdvb_err("failed to open %s - errno %d\n", VIDEODEV, errno); - linuxdvb_err("%s\n", strerror(errno)); - return cERR_LINUXDVB_ERROR; - } + if (videofd < 0) { + linuxdvb_err("failed to open %s - errno %d\n", VIDEODEV, + errno); + linuxdvb_err("%s\n", strerror(errno)); + return cERR_LINUXDVB_ERROR; + } - if (ioctl( videofd, VIDEO_CLEAR_BUFFER) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); - } + if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); + } - if (ioctl( videofd, VIDEO_SELECT_SOURCE, (void*)VIDEO_SOURCE_MEMORY) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SELECT_SOURCE: %s\n", strerror(errno)); - } + if (ioctl + (videofd, VIDEO_SELECT_SOURCE, + (void *) VIDEO_SOURCE_MEMORY) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_SELECT_SOURCE: %s\n", strerror(errno)); + } - if (ioctl( videofd, VIDEO_SET_STREAMTYPE, (void*)STREAM_TYPE_PROGRAM) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SET_STREAMTYPE: %s\n", strerror(errno)); - } + if (ioctl + (videofd, VIDEO_SET_STREAMTYPE, + (void *) STREAM_TYPE_PROGRAM) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_SET_STREAMTYPE: %s\n", strerror(errno)); + } - if (ioctl(videofd, VIDEO_SET_SPEED, DVB_SPEED_NORMAL_PLAY) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SET_SPEED: %s\n", strerror(errno)); - } + if (ioctl(videofd, VIDEO_SET_SPEED, DVB_SPEED_NORMAL_PLAY) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_SET_SPEED: %s\n", strerror(errno)); + } } if (audio && audiofd < 0) { - audiofd = open(AUDIODEV, O_RDWR); + audiofd = open(AUDIODEV, O_RDWR); - if (audiofd < 0) - { - linuxdvb_err("failed to open %s - errno %d\n", AUDIODEV, errno); - linuxdvb_err("%s\n", strerror(errno)); + if (audiofd < 0) { + linuxdvb_err("failed to open %s - errno %d\n", AUDIODEV, + errno); + linuxdvb_err("%s\n", strerror(errno)); - if (videofd < 0) - close(videofd); - return cERR_LINUXDVB_ERROR; - } + if (videofd < 0) + close(videofd); + return cERR_LINUXDVB_ERROR; + } - if (ioctl( audiofd, AUDIO_CLEAR_BUFFER) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); - } + if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); + } - if (ioctl( audiofd, AUDIO_SELECT_SOURCE, (void*)AUDIO_SOURCE_MEMORY) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_SELECT_SOURCE: %s\n", strerror(errno)); - } + if (ioctl + (audiofd, AUDIO_SELECT_SOURCE, + (void *) AUDIO_SOURCE_MEMORY) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_SELECT_SOURCE: %s\n", strerror(errno)); + } - if (ioctl( audiofd, AUDIO_SET_STREAMTYPE, (void*)STREAM_TYPE_PROGRAM) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_SET_STREAMTYPE: %s\n", strerror(errno)); - } + if (ioctl + (audiofd, AUDIO_SET_STREAMTYPE, + (void *) STREAM_TYPE_PROGRAM) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_SET_STREAMTYPE: %s\n", strerror(errno)); + } } return cERR_LINUXDVB_NO_ERROR; } -int LinuxDvbClose(Context_t *context, char * type) { +int LinuxDvbClose(Context_t * context, char *type) +{ unsigned char video = !strcmp("video", type); unsigned char audio = !strcmp("audio", type); @@ -192,24 +203,25 @@ int LinuxDvbClose(Context_t *context, char * type) { */ LinuxDvbStop(context, type); - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); if (video && videofd != -1) { - close(videofd); - videofd = -1; + close(videofd); + videofd = -1; } if (audio && audiofd != -1) { - close(audiofd); - audiofd = -1; + close(audiofd); + audiofd = -1; } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); return cERR_LINUXDVB_NO_ERROR; } -int LinuxDvbPlay(Context_t *context, char * type) { +int LinuxDvbPlay(Context_t * context, char *type) +{ int ret = cERR_LINUXDVB_NO_ERROR; - Writer_t* writer; + Writer_t *writer; unsigned char video = !strcmp("video", type); unsigned char audio = !strcmp("audio", type); @@ -217,168 +229,170 @@ int LinuxDvbPlay(Context_t *context, char * type) { linuxdvb_printf(10, "v%d a%d\n", video, audio); if (video && videofd != -1) { - char * Encoding = NULL; - context->manager->video->Command(context, MANAGER_GETENCODING, &Encoding); + char *Encoding = NULL; + context->manager->video->Command(context, MANAGER_GETENCODING, + &Encoding); - linuxdvb_printf(10, "V %s\n", Encoding); + linuxdvb_printf(10, "V %s\n", Encoding); - writer = getWriter(Encoding); + writer = getWriter(Encoding); - if (writer == NULL) - { - linuxdvb_err("cannot found writer for encoding %s using default\n", Encoding); - if (ioctl( videofd, VIDEO_SET_ENCODING, (void*) VIDEO_ENCODING_AUTO) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SET_ENCODING: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } else - { - linuxdvb_printf(20, "found writer %s for encoding %s\n", writer->caps->name, Encoding); - if (ioctl( videofd, VIDEO_SET_ENCODING, (void*) writer->caps->dvbEncoding) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SET_ENCODING: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } + if (writer == NULL) { + linuxdvb_err + ("cannot found writer for encoding %s using default\n", + Encoding); + if (ioctl + (videofd, VIDEO_SET_ENCODING, + (void *) VIDEO_ENCODING_AUTO) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_SET_ENCODING: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } else { + linuxdvb_printf(20, "found writer %s for encoding %s\n", + writer->caps->name, Encoding); + if (ioctl + (videofd, VIDEO_SET_ENCODING, + (void *) writer->caps->dvbEncoding) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_SET_ENCODING: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } - if (ioctl(videofd, VIDEO_PLAY, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_PLAY: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - free(Encoding); + if (ioctl(videofd, VIDEO_PLAY, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_PLAY: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + free(Encoding); } if (audio && audiofd != -1) { - char * Encoding = NULL; - context->manager->audio->Command(context, MANAGER_GETENCODING, &Encoding); + char *Encoding = NULL; + context->manager->audio->Command(context, MANAGER_GETENCODING, + &Encoding); - linuxdvb_printf(20, "0 A %s\n", Encoding); + linuxdvb_printf(20, "0 A %s\n", Encoding); - writer = getWriter(Encoding); + writer = getWriter(Encoding); - if (writer == NULL) - { - linuxdvb_err("cannot found writer for encoding %s using default\n", Encoding); - if (ioctl( audiofd, AUDIO_SET_ENCODING, (void*)AUDIO_ENCODING_MP3) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_SET_ENCODING: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } else - { - linuxdvb_printf(20, "found writer %s for encoding %s\n", writer->caps->name, Encoding); - if (ioctl( audiofd, AUDIO_SET_ENCODING, (void*) writer->caps->dvbEncoding) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_SET_ENCODING: %s\n", strerror(errno)); - ret = -1; - } - } + if (writer == NULL) { + linuxdvb_err + ("cannot found writer for encoding %s using default\n", + Encoding); + if (ioctl + (audiofd, AUDIO_SET_ENCODING, + (void *) AUDIO_ENCODING_MP3) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_SET_ENCODING: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } else { + linuxdvb_printf(20, "found writer %s for encoding %s\n", + writer->caps->name, Encoding); + if (ioctl + (audiofd, AUDIO_SET_ENCODING, + (void *) writer->caps->dvbEncoding) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_SET_ENCODING: %s\n", strerror(errno)); + ret = -1; + } + } - if (ioctl(audiofd, AUDIO_PLAY, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - free(Encoding); + if (ioctl(audiofd, AUDIO_PLAY, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + free(Encoding); } return ret; } -int LinuxDvbStop(Context_t *context __attribute__((unused)), char * type) { +int LinuxDvbStop(Context_t * context __attribute__ ((unused)), char *type) +{ int ret = cERR_LINUXDVB_NO_ERROR; unsigned char video = !strcmp("video", type); unsigned char audio = !strcmp("audio", type); linuxdvb_printf(10, "v%d a%d\n", video, audio); - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); if (video && videofd != -1) { - if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); - } + if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); + } - /* set back to normal speed (end trickmodes) */ - if (ioctl(videofd, VIDEO_SET_SPEED, DVB_SPEED_NORMAL_PLAY) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SET_SPEED: %s\n", strerror(errno)); - } - if (ioctl(videofd, VIDEO_STOP, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_STOP: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + /* set back to normal speed (end trickmodes) */ + if (ioctl(videofd, VIDEO_SET_SPEED, DVB_SPEED_NORMAL_PLAY) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_SET_SPEED: %s\n", strerror(errno)); + } + if (ioctl(videofd, VIDEO_STOP, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_STOP: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } } if (audio && audiofd != -1) { - if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); - } + if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); + } - /* set back to normal speed (end trickmodes) */ - if (ioctl(audiofd, AUDIO_SET_SPEED, DVB_SPEED_NORMAL_PLAY) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_SET_SPEED: %s\n", strerror(errno)); - } - if (ioctl(audiofd, AUDIO_STOP, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + /* set back to normal speed (end trickmodes) */ + if (ioctl(audiofd, AUDIO_SET_SPEED, DVB_SPEED_NORMAL_PLAY) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_SET_SPEED: %s\n", strerror(errno)); + } + if (ioctl(audiofd, AUDIO_STOP, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); return ret; } -int LinuxDvbPause(Context_t *context __attribute__((unused)), char * type) { +int LinuxDvbPause(Context_t * context __attribute__ ((unused)), char *type) +{ int ret = cERR_LINUXDVB_NO_ERROR; unsigned char video = !strcmp("video", type); unsigned char audio = !strcmp("audio", type); linuxdvb_printf(10, "v%d a%d\n", video, audio); - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); if (video && videofd != -1) { - if (ioctl(videofd, VIDEO_FREEZE, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_FREEZE: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + if (ioctl(videofd, VIDEO_FREEZE, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_FREEZE: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } } if (audio && audiofd != -1) { - if (ioctl(audiofd, AUDIO_PAUSE, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_PAUSE: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + if (ioctl(audiofd, AUDIO_PAUSE, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_PAUSE: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); return ret; } -int LinuxDvbContinue(Context_t *context __attribute__((unused)), char * type) { +int LinuxDvbContinue(Context_t * context + __attribute__ ((unused)), char *type) +{ int ret = cERR_LINUXDVB_NO_ERROR; unsigned char video = !strcmp("video", type); unsigned char audio = !strcmp("audio", type); @@ -386,20 +400,18 @@ int LinuxDvbContinue(Context_t *context __attribute__((unused)), char * type) { linuxdvb_printf(10, "v%d a%d\n", video, audio); if (video && videofd != -1) { - if (ioctl(videofd, VIDEO_CONTINUE, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_CONTINUE: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + if (ioctl(videofd, VIDEO_CONTINUE, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_CONTINUE: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } } if (audio && audiofd != -1) { - if (ioctl(audiofd, AUDIO_CONTINUE, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_CONTINUE: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + if (ioctl(audiofd, AUDIO_CONTINUE, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_CONTINUE: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } } linuxdvb_printf(10, "exiting\n"); @@ -408,16 +420,17 @@ int LinuxDvbContinue(Context_t *context __attribute__((unused)), char * type) { return ret; } -int LinuxDvbReverseDiscontinuity(Context_t *context __attribute__((unused)), int* surplus) { +int LinuxDvbReverseDiscontinuity(Context_t * context + __attribute__ ((unused)), int *surplus) +{ int ret = cERR_LINUXDVB_NO_ERROR; int dis_type = VIDEO_DISCONTINUITY_CONTINUOUS_REVERSE | *surplus; - + linuxdvb_printf(50, "\n"); - if (ioctl( videofd, VIDEO_DISCONTINUITY, (void*) dis_type) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_DISCONTINUITY: %s\n", strerror(errno)); + if (ioctl(videofd, VIDEO_DISCONTINUITY, (void *) dis_type) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_DISCONTINUITY: %s\n", strerror(errno)); } linuxdvb_printf(50, "exiting\n"); @@ -425,36 +438,33 @@ int LinuxDvbReverseDiscontinuity(Context_t *context __attribute__((unused)), in return ret; } -int LinuxDvbAudioMute(Context_t *context __attribute__((unused)), char *flag) { +int LinuxDvbAudioMute(Context_t * context + __attribute__ ((unused)), char *flag) +{ int ret = cERR_LINUXDVB_NO_ERROR; linuxdvb_printf(10, "\n"); if (audiofd != -1) { - if(*flag == '1') - { - //AUDIO_SET_MUTE has no effect with new player - //if (ioctl(audiofd, AUDIO_SET_MUTE, 1) == -1) - if (ioctl(audiofd, AUDIO_STOP, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - //linuxdvb_err("AUDIO_SET_MUTE: %s\n", strerror(errno)); - linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } - else - { - //AUDIO_SET_MUTE has no effect with new player - //if (ioctl(audiofd, AUDIO_SET_MUTE, 0) == -1) - if (ioctl(audiofd, AUDIO_PLAY, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - //linuxdvb_err("AUDIO_SET_MUTE: %s\n", strerror(errno)); - linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } + if (*flag == '1') { + //AUDIO_SET_MUTE has no effect with new player + //if (ioctl(audiofd, AUDIO_SET_MUTE, 1) == -1) + if (ioctl(audiofd, AUDIO_STOP, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + //linuxdvb_err("AUDIO_SET_MUTE: %s\n", strerror(errno)); + linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } else { + //AUDIO_SET_MUTE has no effect with new player + //if (ioctl(audiofd, AUDIO_SET_MUTE, 0) == -1) + if (ioctl(audiofd, AUDIO_PLAY, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + //linuxdvb_err("AUDIO_SET_MUTE: %s\n", strerror(errno)); + linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } } linuxdvb_printf(10, "exiting\n"); @@ -463,32 +473,31 @@ int LinuxDvbAudioMute(Context_t *context __attribute__((unused)), char *flag) { } -int LinuxDvbFlush(Context_t *context __attribute__((unused)), char * type) { +int LinuxDvbFlush(Context_t * context __attribute__ ((unused)), char *type) +{ unsigned char video = !strcmp("video", type); unsigned char audio = !strcmp("audio", type); linuxdvb_printf(10, "v%d a%d\n", video, audio); - if ( (video && videofd != -1) || (audio && audiofd != -1) ) { - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + if ((video && videofd != -1) || (audio && audiofd != -1)) { + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); - if (video && videofd != -1) { - if (ioctl(videofd, VIDEO_FLUSH, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_FLUSH: %s\n", strerror(errno)); - } - } + if (video && videofd != -1) { + if (ioctl(videofd, VIDEO_FLUSH, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_FLUSH: %s\n", strerror(errno)); + } + } - if (audio && audiofd != -1) { - if (ioctl(audiofd, AUDIO_FLUSH, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_FLUSH: %s\n", strerror(errno)); - } - } + if (audio && audiofd != -1) { + if (ioctl(audiofd, AUDIO_FLUSH, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_FLUSH: %s\n", strerror(errno)); + } + } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); } linuxdvb_printf(10, "exiting\n"); @@ -497,28 +506,30 @@ int LinuxDvbFlush(Context_t *context __attribute__((unused)), char * type) { } #ifndef use_set_speed_instead_ff -int LinuxDvbFastForward(Context_t *context, char * type) { +int LinuxDvbFastForward(Context_t * context, char *type) +{ int ret = cERR_LINUXDVB_NO_ERROR; unsigned char video = !strcmp("video", type); unsigned char audio = !strcmp("audio", type); - linuxdvb_printf(10, "v%d a%d speed %d\n", video, audio, context->playback->Speed); + linuxdvb_printf(10, "v%d a%d speed %d\n", video, audio, + context->playback->Speed); if (video && videofd != -1) { - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); - /* konfetti comment: speed is a value given in skipped frames */ + /* konfetti comment: speed is a value given in skipped frames */ - if (ioctl(videofd, VIDEO_FAST_FORWARD, context->playback->Speed) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_FAST_FORWARD: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + if (ioctl(videofd, VIDEO_FAST_FORWARD, context->playback->Speed) == + -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_FAST_FORWARD: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); } linuxdvb_printf(10, "exiting with value %d\n", ret); @@ -527,15 +538,15 @@ int LinuxDvbFastForward(Context_t *context, char * type) { } #else -static unsigned int SpeedList[] = -{ - 1000, 1100, 1200, 1300, 1500, - 2000, 3000, 4000, 5000, 8000, - 12000, 16000, +static unsigned int SpeedList[] = { + 1000, 1100, 1200, 1300, 1500, + 2000, 3000, 4000, 5000, 8000, + 12000, 16000, 125, 250, 500, 700, 800, 900 }; -int LinuxDvbFastForward(Context_t *context, char * type) { +int LinuxDvbFastForward(Context_t * context, char *type) +{ int ret = cERR_LINUXDVB_NO_ERROR; int speedIndex; unsigned char video = !strcmp("video", type); @@ -545,38 +556,38 @@ int LinuxDvbFastForward(Context_t *context, char * type) { if (video && videofd != -1) { - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); - speedIndex = context->playback->Speed % (sizeof (SpeedList) / sizeof (int)); + speedIndex = + context->playback->Speed % (sizeof(SpeedList) / sizeof(int)); - linuxdvb_printf(1, "speedIndex %d\n", speedIndex); + linuxdvb_printf(1, "speedIndex %d\n", speedIndex); - if (ioctl(videofd, VIDEO_SET_SPEED, SpeedList[speedIndex]) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SET_SPEED: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + if (ioctl(videofd, VIDEO_SET_SPEED, SpeedList[speedIndex]) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_SET_SPEED: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); } if (audio && audiofd != -1) { - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); - speedIndex = context->playback->Speed % (sizeof (SpeedList) / sizeof (int)); + speedIndex = + context->playback->Speed % (sizeof(SpeedList) / sizeof(int)); - linuxdvb_printf(1, "speedIndex %d\n", speedIndex); + linuxdvb_printf(1, "speedIndex %d\n", speedIndex); - if (ioctl(audiofd, AUDIO_SET_SPEED, SpeedList[speedIndex]) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_SET_SPEED: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + if (ioctl(audiofd, AUDIO_SET_SPEED, SpeedList[speedIndex]) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_SET_SPEED: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); } linuxdvb_printf(10, "exiting with value %d\n", ret); @@ -586,12 +597,16 @@ int LinuxDvbFastForward(Context_t *context, char * type) { #endif -int LinuxDvbReverse(Context_t *context __attribute__((unused)), char * type __attribute__((unused))) { +int LinuxDvbReverse(Context_t * context + __attribute__ ((unused)), char *type + __attribute__ ((unused))) +{ int ret = cERR_LINUXDVB_NO_ERROR; return ret; } -int LinuxDvbSlowMotion(Context_t *context, char * type) { +int LinuxDvbSlowMotion(Context_t * context, char *type) +{ int ret = cERR_LINUXDVB_NO_ERROR; unsigned char video = !strcmp("video", type); @@ -599,19 +614,20 @@ int LinuxDvbSlowMotion(Context_t *context, char * type) { linuxdvb_printf(10, "v%d a%d\n", video, audio); - if ( (video && videofd != -1) || (audio && audiofd != -1) ) { - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + if ((video && videofd != -1) || (audio && audiofd != -1)) { + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); - if (video && videofd != -1) { - if (ioctl(videofd, VIDEO_SLOWMOTION, context->playback->SlowMotion) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SLOWMOTION: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } + if (video && videofd != -1) { + if (ioctl + (videofd, VIDEO_SLOWMOTION, + context->playback->SlowMotion) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_SLOWMOTION: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); } linuxdvb_printf(10, "exiting with value %d\n", ret); @@ -619,7 +635,9 @@ int LinuxDvbSlowMotion(Context_t *context, char * type) { return ret; } -int LinuxDvbAVSync(Context_t *context, char * type __attribute__((unused))) { +int LinuxDvbAVSync(Context_t * context, char *type + __attribute__ ((unused))) +{ int ret = cERR_LINUXDVB_NO_ERROR; /* konfetti: this one is dedicated to audiofd so we * are ignoring what is given by type! I think we should @@ -628,49 +646,48 @@ int LinuxDvbAVSync(Context_t *context, char * type __attribute__((unused))) { * using a variable inside the structure. */ if (audiofd != -1) { - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); - if (ioctl(audiofd, AUDIO_SET_AV_SYNC, context->playback->AVSync) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_SET_AV_SYNC: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } + if (ioctl(audiofd, AUDIO_SET_AV_SYNC, context->playback->AVSync) == + -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_SET_AV_SYNC: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); } return ret; } -int LinuxDvbClear(Context_t *context __attribute__((unused)), char * type) { +int LinuxDvbClear(Context_t * context __attribute__ ((unused)), char *type) +{ int ret = cERR_LINUXDVB_NO_ERROR; unsigned char video = !strcmp("video", type); unsigned char audio = !strcmp("audio", type); linuxdvb_printf(10, "v%d a%d\n", video, audio); - if ( (video && videofd != -1) || (audio && audiofd != -1) ) { - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + if ((video && videofd != -1) || (audio && audiofd != -1)) { + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); - if (video && videofd != -1) { - if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } - if (audio && audiofd != -1) { - if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } + if (video && videofd != -1) { + if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } + if (audio && audiofd != -1) { + if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); } linuxdvb_printf(10, "exiting\n"); @@ -678,192 +695,210 @@ int LinuxDvbClear(Context_t *context __attribute__((unused)), char * type) { return ret; } -int LinuxDvbPts(Context_t *context __attribute__((unused)), unsigned long long int* pts) { +int LinuxDvbPts(Context_t * context + __attribute__ ((unused)), unsigned long long int *pts) +{ int ret = cERR_LINUXDVB_ERROR; - + linuxdvb_printf(50, "\n"); // pts is a non writting requests and can be done in parallel to other requests //getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); - if (videofd > -1 && !ioctl(videofd, VIDEO_GET_PTS, (void*)&sCURRENT_PTS)) + if (videofd > -1 + && !ioctl(videofd, VIDEO_GET_PTS, (void *) &sCURRENT_PTS)) ret = cERR_LINUXDVB_NO_ERROR; else linuxdvb_err("VIDEO_GET_PTS: %d (%s)\n", errno, strerror(errno)); if (ret != cERR_LINUXDVB_NO_ERROR) { - if (audiofd > -1 && !ioctl(audiofd, AUDIO_GET_PTS, (void*)&sCURRENT_PTS)) - ret = cERR_LINUXDVB_NO_ERROR; + if (audiofd > -1 + && !ioctl(audiofd, AUDIO_GET_PTS, (void *) &sCURRENT_PTS)) + ret = cERR_LINUXDVB_NO_ERROR; else - linuxdvb_err("AUDIO_GET_PTS: %d (%s)\n", errno, strerror(errno)); + linuxdvb_err("AUDIO_GET_PTS: %d (%s)\n", errno, + strerror(errno)); } if (ret != cERR_LINUXDVB_NO_ERROR) - sCURRENT_PTS = 0; + sCURRENT_PTS = 0; - *((unsigned long long int *)pts)=(unsigned long long int)sCURRENT_PTS; + *((unsigned long long int *) pts) = + (unsigned long long int) sCURRENT_PTS; //releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); return ret; } -int LinuxDvbGetFrameCount(Context_t *context __attribute__((unused)), unsigned long long int* frameCount) { +int LinuxDvbGetFrameCount(Context_t * context + __attribute__ ((unused)), + unsigned long long int *frameCount) +{ int ret = cERR_LINUXDVB_NO_ERROR; dvb_play_info_t playInfo; linuxdvb_printf(50, "\n"); - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); - if (videofd != -1) - { - if (ioctl(videofd, VIDEO_GET_PLAY_INFO, (void*)&playInfo) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_GET_PLAY_INFO: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - else linuxdvb_err("V: %llu\n", playInfo.frame_count); - } - else if (audiofd != -1) - { - if (ioctl(audiofd, AUDIO_GET_PLAY_INFO, (void*)&playInfo) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_GET_PLAY_INFO: %s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - else linuxdvb_err("A: %llu\n", playInfo.frame_count); - } - else { - ret = cERR_LINUXDVB_ERROR; + if (videofd != -1) { + if (ioctl(videofd, VIDEO_GET_PLAY_INFO, (void *) &playInfo) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_GET_PLAY_INFO: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } else + linuxdvb_err("V: %llu\n", playInfo.frame_count); + } else if (audiofd != -1) { + if (ioctl(audiofd, AUDIO_GET_PLAY_INFO, (void *) &playInfo) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_GET_PLAY_INFO: %s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } else + linuxdvb_err("A: %llu\n", playInfo.frame_count); + } else { + ret = cERR_LINUXDVB_ERROR; } - if(ret == cERR_LINUXDVB_NO_ERROR) - *((unsigned long long int *)frameCount) = playInfo.frame_count; + if (ret == cERR_LINUXDVB_NO_ERROR) + *((unsigned long long int *) frameCount) = playInfo.frame_count; - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); return ret; } -int LinuxDvbSwitch(Context_t *context, char * type) { +int LinuxDvbSwitch(Context_t * context, char *type) +{ unsigned char audio = !strcmp("audio", type); unsigned char video = !strcmp("video", type); - Writer_t* writer; + Writer_t *writer; linuxdvb_printf(10, "v%d a%d\n", video, audio); - if ( (video && videofd != -1) || (audio && audiofd != -1) ) { - getLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + if ((video && videofd != -1) || (audio && audiofd != -1)) { + getLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); - if (audio && audiofd != -1) { - char * Encoding = NULL; - if (context && context->manager && context->manager->audio) { - context->manager->audio->Command(context, MANAGER_GETENCODING, &Encoding); + if (audio && audiofd != -1) { + char *Encoding = NULL; + if (context && context->manager && context->manager->audio) { + context->manager->audio->Command(context, + MANAGER_GETENCODING, + &Encoding); - linuxdvb_printf(10, "A %s\n", Encoding); + linuxdvb_printf(10, "A %s\n", Encoding); - writer = getWriter(Encoding); + writer = getWriter(Encoding); - if (ioctl(audiofd, AUDIO_STOP ,NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno)); + if (ioctl(audiofd, AUDIO_STOP, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_STOP: %s\n", strerror(errno)); - } + } - if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", strerror(errno)); + if (ioctl(audiofd, AUDIO_CLEAR_BUFFER) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_CLEAR_BUFFER: %s\n", + strerror(errno)); - } + } - if (writer == NULL) - { - linuxdvb_err("cannot found writer for encoding %s using default\n", Encoding); - if (ioctl( audiofd, AUDIO_SET_ENCODING, (void*) AUDIO_ENCODING_MP3) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_SET_ENCODING: %s\n", strerror(errno)); - } - } else - { - linuxdvb_printf(10, "found writer %s for encoding %s\n", writer->caps->name, Encoding); - if (ioctl( audiofd, AUDIO_SET_ENCODING, (void*) writer->caps->dvbEncoding) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_SET_ENCODING: %s\n", strerror(errno)); - } - } + if (writer == NULL) { + linuxdvb_err + ("cannot found writer for encoding %s using default\n", + Encoding); + if (ioctl + (audiofd, AUDIO_SET_ENCODING, + (void *) AUDIO_ENCODING_MP3) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", + errno); + linuxdvb_err("AUDIO_SET_ENCODING: %s\n", + strerror(errno)); + } + } else { + linuxdvb_printf(10, + "found writer %s for encoding %s\n", + writer->caps->name, Encoding); + if (ioctl + (audiofd, AUDIO_SET_ENCODING, + (void *) writer->caps->dvbEncoding) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", + errno); + linuxdvb_err("AUDIO_SET_ENCODING: %s\n", + strerror(errno)); + } + } - if (ioctl(audiofd, AUDIO_PLAY, NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno)); - } - free(Encoding); - } - else - linuxdvb_printf(20, "no context for Audio\n"); - } + if (ioctl(audiofd, AUDIO_PLAY, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("AUDIO_PLAY: %s\n", strerror(errno)); + } + free(Encoding); + } else + linuxdvb_printf(20, "no context for Audio\n"); + } - if (video && videofd != -1) { - char * Encoding = NULL; - if (context && context->manager && context->manager->video) { - context->manager->video->Command(context, MANAGER_GETENCODING, &Encoding); + if (video && videofd != -1) { + char *Encoding = NULL; + if (context && context->manager && context->manager->video) { + context->manager->video->Command(context, + MANAGER_GETENCODING, + &Encoding); - if (ioctl(videofd, VIDEO_STOP ,NULL) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_STOP: %s\n", strerror(errno)); - } + if (ioctl(videofd, VIDEO_STOP, NULL) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_STOP: %s\n", strerror(errno)); + } - if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", strerror(errno)); - } + if (ioctl(videofd, VIDEO_CLEAR_BUFFER) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_CLEAR_BUFFER: %s\n", + strerror(errno)); + } - linuxdvb_printf(10, "V %s\n", Encoding); + linuxdvb_printf(10, "V %s\n", Encoding); - writer = getWriter(Encoding); + writer = getWriter(Encoding); - if (writer == NULL) - { - linuxdvb_err("cannot found writer for encoding %s using default\n", Encoding); - if (ioctl( videofd, VIDEO_SET_ENCODING, (void*) VIDEO_ENCODING_AUTO) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SET_ENCODING: %s\n", strerror(errno)); - } - } else - { - linuxdvb_printf(10, "found writer %s for encoding %s\n", writer->caps->name, Encoding); - if (ioctl( videofd, VIDEO_SET_ENCODING, (void*) writer->caps->dvbEncoding) == -1) - { - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_SET_ENCODING: %s\n", strerror(errno)); - } - } + if (writer == NULL) { + linuxdvb_err + ("cannot found writer for encoding %s using default\n", + Encoding); + if (ioctl + (videofd, VIDEO_SET_ENCODING, + (void *) VIDEO_ENCODING_AUTO) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", + errno); + linuxdvb_err("VIDEO_SET_ENCODING: %s\n", + strerror(errno)); + } + } else { + linuxdvb_printf(10, + "found writer %s for encoding %s\n", + writer->caps->name, Encoding); + if (ioctl + (videofd, VIDEO_SET_ENCODING, + (void *) writer->caps->dvbEncoding) == -1) { + linuxdvb_err("ioctl failed with errno %d\n", + errno); + linuxdvb_err("VIDEO_SET_ENCODING: %s\n", + strerror(errno)); + } + } - if (ioctl(videofd, VIDEO_PLAY, NULL) == -1) - { - /* konfetti: fixme: think on this, I think we should - * return an error here and stop the playback mode - */ - linuxdvb_err("ioctl failed with errno %d\n", errno); - linuxdvb_err("VIDEO_PLAY: %s\n", strerror(errno)); - } - free(Encoding); - } - else - linuxdvb_printf(20, "no context for Video\n"); - } + if (ioctl(videofd, VIDEO_PLAY, NULL) == -1) { + /* konfetti: fixme: think on this, I think we should + * return an error here and stop the playback mode + */ + linuxdvb_err("ioctl failed with errno %d\n", errno); + linuxdvb_err("VIDEO_PLAY: %s\n", strerror(errno)); + } + free(Encoding); + } else + linuxdvb_printf(20, "no context for Video\n"); + } - releaseLinuxDVBMutex(FILENAME, __FUNCTION__,__LINE__); + releaseLinuxDVBMutex(FILENAME, __FUNCTION__, __LINE__); } @@ -872,153 +907,150 @@ int LinuxDvbSwitch(Context_t *context, char * type) { return cERR_LINUXDVB_NO_ERROR; } -static int Write(void *_context, void* _out) +static int Write(void *_context, void *_out) { - Context_t *context = (Context_t *) _context; - AudioVideoOut_t *out = (AudioVideoOut_t*) _out; - int ret = cERR_LINUXDVB_NO_ERROR; - int res = 0; - unsigned char video = 0; - unsigned char audio = 0; - Writer_t* writer; + Context_t *context = (Context_t *) _context; + AudioVideoOut_t *out = (AudioVideoOut_t *) _out; + int ret = cERR_LINUXDVB_NO_ERROR; + int res = 0; + unsigned char video = 0; + unsigned char audio = 0; + Writer_t *writer; WriterAVCallData_t call; - if (out == NULL) - { - linuxdvb_err("null pointer passed\n"); - return cERR_LINUXDVB_ERROR; + if (out == NULL) { + linuxdvb_err("null pointer passed\n"); + return cERR_LINUXDVB_ERROR; } - + video = !strcmp("video", out->type); audio = !strcmp("audio", out->type); - - linuxdvb_printf(20, "DataLength=%u PrivateLength=%u Pts=%llu FrameRate=%f\n", - out->len, out->extralen, out->pts, out->frameRate); + + linuxdvb_printf(20, + "DataLength=%u PrivateLength=%u Pts=%llu FrameRate=%f\n", + out->len, out->extralen, out->pts, out->frameRate); linuxdvb_printf(20, "v%d a%d\n", video, audio); if (video) { - char * Encoding = NULL; - context->manager->video->Command(context, MANAGER_GETENCODING, &Encoding); + char *Encoding = NULL; + context->manager->video->Command(context, MANAGER_GETENCODING, + &Encoding); - linuxdvb_printf(20, "Encoding = %s\n", Encoding); + linuxdvb_printf(20, "Encoding = %s\n", Encoding); - writer = getWriter(Encoding); + writer = getWriter(Encoding); - if (writer == NULL) - { - linuxdvb_printf(20, "searching default writer ... %s\n", Encoding); - writer = getDefaultVideoWriter(); - } + if (writer == NULL) { + linuxdvb_printf(20, "searching default writer ... %s\n", + Encoding); + writer = getDefaultVideoWriter(); + } - if (writer == NULL) - { - linuxdvb_err("unknown video codec and no default writer %s\n",Encoding); - ret = cERR_LINUXDVB_ERROR; - } else - { - call.fd = videofd; - call.data = out->data; - call.len = out->len; - call.Pts = out->pts; - call.private_data = out->extradata; - call.private_size = out->extralen; - call.FrameRate = out->frameRate; - call.FrameScale = out->timeScale; - call.Width = out->width; - call.Height = out->height; - call.Version = 0; // is unsingned char + if (writer == NULL) { + linuxdvb_err("unknown video codec and no default writer %s\n", + Encoding); + ret = cERR_LINUXDVB_ERROR; + } else { + call.fd = videofd; + call.data = out->data; + call.len = out->len; + call.Pts = out->pts; + call.private_data = out->extradata; + call.private_size = out->extralen; + call.FrameRate = out->frameRate; + call.FrameScale = out->timeScale; + call.Width = out->width; + call.Height = out->height; + call.Version = 0; // is unsingned char - if (writer->writeData) - res = writer->writeData(&call); + if (writer->writeData) + res = writer->writeData(&call); - if (res < 0) - { - linuxdvb_err("failed to write data %d - %d\n", res, errno); - linuxdvb_err("%s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } + if (res < 0) { + linuxdvb_err("failed to write data %d - %d\n", res, errno); + linuxdvb_err("%s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } - free(Encoding); + free(Encoding); } else if (audio) { - char * Encoding = NULL; - context->manager->audio->Command(context, MANAGER_GETENCODING, &Encoding); + char *Encoding = NULL; + context->manager->audio->Command(context, MANAGER_GETENCODING, + &Encoding); - linuxdvb_printf(20, "%s::%s Encoding = %s\n", FILENAME, __FUNCTION__, Encoding); + linuxdvb_printf(20, "%s::%s Encoding = %s\n", FILENAME, + __FUNCTION__, Encoding); - writer = getWriter(Encoding); + writer = getWriter(Encoding); - if (writer == NULL) - { - linuxdvb_printf(20, "searching default writer ... %s\n", Encoding); - writer = getDefaultAudioWriter(); - } + if (writer == NULL) { + linuxdvb_printf(20, "searching default writer ... %s\n", + Encoding); + writer = getDefaultAudioWriter(); + } - if (writer == NULL) - { - linuxdvb_err("unknown audio codec %s and no default writer\n",Encoding); - ret = cERR_LINUXDVB_ERROR; - } else - { - call.fd = audiofd; - call.data = out->data; - call.len = out->len; - call.Pts = out->pts; - call.private_data = out->extradata; - call.private_size = out->extralen; - call.FrameRate = out->frameRate; - call.FrameScale = out->timeScale; - call.Version = 0; /* -1; unsigned char cannot be negative */ + if (writer == NULL) { + linuxdvb_err("unknown audio codec %s and no default writer\n", + Encoding); + ret = cERR_LINUXDVB_ERROR; + } else { + call.fd = audiofd; + call.data = out->data; + call.len = out->len; + call.Pts = out->pts; + call.private_data = out->extradata; + call.private_size = out->extralen; + call.FrameRate = out->frameRate; + call.FrameScale = out->timeScale; + call.Version = 0; /* -1; unsigned char cannot be negative */ - if (writer->writeData) - res = writer->writeData(&call); + if (writer->writeData) + res = writer->writeData(&call); - if (res < 0) - { - linuxdvb_err("failed to write data %d - %d\n", res, errno); - linuxdvb_err("%s\n", strerror(errno)); - ret = cERR_LINUXDVB_ERROR; - } - } + if (res < 0) { + linuxdvb_err("failed to write data %d - %d\n", res, errno); + linuxdvb_err("%s\n", strerror(errno)); + ret = cERR_LINUXDVB_ERROR; + } + } - free(Encoding); + free(Encoding); } return ret; } -static int reset(Context_t *context) +static int reset(Context_t * context) { int ret = cERR_LINUXDVB_NO_ERROR; - Writer_t* writer; - char * Encoding = NULL; + Writer_t *writer; + char *Encoding = NULL; - context->manager->video->Command(context, MANAGER_GETENCODING, &Encoding); + context->manager->video->Command(context, MANAGER_GETENCODING, + &Encoding); writer = getWriter(Encoding); - if (writer == NULL) - { - linuxdvb_err("unknown video codec %s\n",Encoding); - ret = cERR_LINUXDVB_ERROR; - } else - { - writer->reset(); + if (writer == NULL) { + linuxdvb_err("unknown video codec %s\n", Encoding); + ret = cERR_LINUXDVB_ERROR; + } else { + writer->reset(); } free(Encoding); - context->manager->audio->Command(context, MANAGER_GETENCODING, &Encoding); + context->manager->audio->Command(context, MANAGER_GETENCODING, + &Encoding); writer = getWriter(Encoding); - if (writer == NULL) - { - linuxdvb_err("unknown video codec %s\n",Encoding); - ret = cERR_LINUXDVB_ERROR; - } else - { - writer->reset(); + if (writer == NULL) { + linuxdvb_err("unknown video codec %s\n", Encoding); + ret = cERR_LINUXDVB_ERROR; + } else { + writer->reset(); } free(Encoding); @@ -1026,98 +1058,101 @@ static int reset(Context_t *context) return ret; } -static int Command(void *_context, OutputCmd_t command, void * argument) { - Context_t* context = (Context_t*) _context; +static int Command(void *_context, OutputCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_LINUXDVB_NO_ERROR; - + linuxdvb_printf(50, "Command %d\n", command); - switch(command) { - case OUTPUT_OPEN: { - ret = LinuxDvbOpen(context, (char*)argument); - break; - } - case OUTPUT_CLOSE: { - ret = LinuxDvbClose(context, (char*)argument); - reset(context); - sCURRENT_PTS = 0; - break; - } - case OUTPUT_PLAY: { // 4 - sCURRENT_PTS = 0; - ret = LinuxDvbPlay(context, (char*)argument); - break; - } - case OUTPUT_STOP: { - reset(context); - ret = LinuxDvbStop(context, (char*)argument); - sCURRENT_PTS = 0; - break; - } - case OUTPUT_FLUSH: { - ret = LinuxDvbFlush(context, (char*)argument); - reset(context); - sCURRENT_PTS = 0; - break; - } - case OUTPUT_PAUSE: { - ret = LinuxDvbPause(context, (char*)argument); - break; - } - case OUTPUT_CONTINUE: { - ret = LinuxDvbContinue(context, (char*)argument); - break; - } - case OUTPUT_FASTFORWARD: { - return LinuxDvbFastForward(context, (char*)argument); - break; - } - case OUTPUT_REVERSE: { - return LinuxDvbReverse(context, (char*)argument); - break; - } - case OUTPUT_AVSYNC: { - ret = LinuxDvbAVSync(context, (char*)argument); - break; - } - case OUTPUT_CLEAR: { - ret = LinuxDvbClear(context, (char*)argument); - reset(context); - sCURRENT_PTS = 0; - break; - } - case OUTPUT_PTS: { - unsigned long long int pts = 0; - ret = LinuxDvbPts(context, &pts); - *((unsigned long long int*)argument) = (unsigned long long int)pts; - break; - } - case OUTPUT_SWITCH: { - ret = LinuxDvbSwitch(context, (char*)argument); - break; - } - case OUTPUT_SLOWMOTION: { - return LinuxDvbSlowMotion(context, (char*)argument); - break; - } - case OUTPUT_AUDIOMUTE: { - return LinuxDvbAudioMute(context, (char*)argument); - break; - } - case OUTPUT_DISCONTINUITY_REVERSE: { - return LinuxDvbReverseDiscontinuity(context, (int*)argument); - break; - } - case OUTPUT_GET_FRAME_COUNT: { - unsigned long long int frameCount = 0; - ret = LinuxDvbGetFrameCount(context, &frameCount); - *((unsigned long long int*)argument) = (unsigned long long int)frameCount; - break; - } + switch (command) { + case OUTPUT_OPEN:{ + ret = LinuxDvbOpen(context, (char *) argument); + break; + } + case OUTPUT_CLOSE:{ + ret = LinuxDvbClose(context, (char *) argument); + reset(context); + sCURRENT_PTS = 0; + break; + } + case OUTPUT_PLAY:{ // 4 + sCURRENT_PTS = 0; + ret = LinuxDvbPlay(context, (char *) argument); + break; + } + case OUTPUT_STOP:{ + reset(context); + ret = LinuxDvbStop(context, (char *) argument); + sCURRENT_PTS = 0; + break; + } + case OUTPUT_FLUSH:{ + ret = LinuxDvbFlush(context, (char *) argument); + reset(context); + sCURRENT_PTS = 0; + break; + } + case OUTPUT_PAUSE:{ + ret = LinuxDvbPause(context, (char *) argument); + break; + } + case OUTPUT_CONTINUE:{ + ret = LinuxDvbContinue(context, (char *) argument); + break; + } + case OUTPUT_FASTFORWARD:{ + return LinuxDvbFastForward(context, (char *) argument); + break; + } + case OUTPUT_REVERSE:{ + return LinuxDvbReverse(context, (char *) argument); + break; + } + case OUTPUT_AVSYNC:{ + ret = LinuxDvbAVSync(context, (char *) argument); + break; + } + case OUTPUT_CLEAR:{ + ret = LinuxDvbClear(context, (char *) argument); + reset(context); + sCURRENT_PTS = 0; + break; + } + case OUTPUT_PTS:{ + unsigned long long int pts = 0; + ret = LinuxDvbPts(context, &pts); + *((unsigned long long int *) argument) = + (unsigned long long int) pts; + break; + } + case OUTPUT_SWITCH:{ + ret = LinuxDvbSwitch(context, (char *) argument); + break; + } + case OUTPUT_SLOWMOTION:{ + return LinuxDvbSlowMotion(context, (char *) argument); + break; + } + case OUTPUT_AUDIOMUTE:{ + return LinuxDvbAudioMute(context, (char *) argument); + break; + } + case OUTPUT_DISCONTINUITY_REVERSE:{ + return LinuxDvbReverseDiscontinuity(context, (int *) argument); + break; + } + case OUTPUT_GET_FRAME_COUNT:{ + unsigned long long int frameCount = 0; + ret = LinuxDvbGetFrameCount(context, &frameCount); + *((unsigned long long int *) argument) = + (unsigned long long int) frameCount; + break; + } default: - linuxdvb_err("ContainerCmd %d not supported!\n", command); - ret = cERR_LINUXDVB_ERROR; - break; + linuxdvb_err("ContainerCmd %d not supported!\n", command); + ret = cERR_LINUXDVB_ERROR; + break; } linuxdvb_printf(50, "exiting with value %d\n", ret); diff --git a/libeplayer3/output/output.c b/libeplayer3/output/output.c index 435a279..75becc8 100644 --- a/libeplayer3/output/output.c +++ b/libeplayer3/output/output.c @@ -53,7 +53,7 @@ if (debug_level >= level) fprintf(stderr, x); } while (0) #define cERR_OUTPUT_NO_ERROR 0 #define cERR_OUTPUT_INTERNAL_ERROR -1 -static const char* FILENAME = "output.c"; +static const char *FILENAME = "output.c"; /* ***************************** */ /* Types */ @@ -63,7 +63,7 @@ static const char* FILENAME = "output.c"; /* Varaibles */ /* ***************************** */ -static Output_t * AvailableOutput[] = { +static Output_t *AvailableOutput[] = { &LinuxDvbOutput, &SubtitleOutput, &PipeOutput, @@ -78,18 +78,19 @@ static Output_t * AvailableOutput[] = { /* MISC Functions */ /* ***************************** */ -static void printOutputCapabilities() { +static void printOutputCapabilities() +{ int i, j; output_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); output_printf(10, "Capabilities:\n"); - for (i = 0; AvailableOutput[i] != NULL; i++) { - output_printf(10, "\t%s : ", AvailableOutput[i]->Name); + for (i = 0; AvailableOutput[i] != NULL; i++) { + output_printf(10, "\t%s : ", AvailableOutput[i]->Name); - for (j = 0; AvailableOutput[i]->Capabilities[j] != NULL; j++) - output_printf(10, "%s ", AvailableOutput[i]->Capabilities[j]); - output_printf(10, "\n"); + for (j = 0; AvailableOutput[i]->Capabilities[j] != NULL; j++) + output_printf(10, "%s ", AvailableOutput[i]->Capabilities[j]); + output_printf(10, "\n"); } } @@ -97,301 +98,451 @@ static void printOutputCapabilities() { /* Output Functions */ /* ***************************** */ -static void OutputAdd(Context_t *context, char * port) { +static void OutputAdd(Context_t * context, char *port) +{ int i, j; output_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); for (i = 0; AvailableOutput[i] != NULL; i++) - for (j = 0; AvailableOutput[i]->Capabilities[j] != NULL; j++) - if (!strcmp(AvailableOutput[i]->Capabilities[j], port)) { - if (!strcmp("audio", port)) { - context->output->audio = AvailableOutput[i]; + for (j = 0; AvailableOutput[i]->Capabilities[j] != NULL; j++) + if (!strcmp(AvailableOutput[i]->Capabilities[j], port)) { + if (!strcmp("audio", port)) { + context->output->audio = AvailableOutput[i]; return; } - if (!strcmp("video", port)) { - context->output->video = AvailableOutput[i]; + if (!strcmp("video", port)) { + context->output->video = AvailableOutput[i]; return; } - if (!strcmp("subtitle", port)) { - context->output->subtitle = AvailableOutput[i]; + if (!strcmp("subtitle", port)) { + context->output->subtitle = AvailableOutput[i]; return; } - if (!strcmp("dvbsubtitle", port)) { - context->output->dvbsubtitle = AvailableOutput[i]; + if (!strcmp("dvbsubtitle", port)) { + context->output->dvbsubtitle = AvailableOutput[i]; return; } - if (!strcmp("teletext", port)) { - context->output->teletext = AvailableOutput[i]; + if (!strcmp("teletext", port)) { + context->output->teletext = AvailableOutput[i]; return; } - } + } } -static void OutputDel(Context_t *context, char * port) { +static void OutputDel(Context_t * context, char *port) +{ output_printf(10, "%s::%s\n", FILENAME, __FUNCTION__); if (!strcmp("audio", port)) - context->output->audio = NULL; + context->output->audio = NULL; else if (!strcmp("video", port)) - context->output->video = NULL; + context->output->video = NULL; else if (!strcmp("subtitle", port)) - context->output->subtitle = NULL; + context->output->subtitle = NULL; else if (!strcmp("dvbsubtitle", port)) - context->output->dvbsubtitle = NULL; + context->output->dvbsubtitle = NULL; else if (!strcmp("teletext", port)) - context->output->teletext = NULL; + context->output->teletext = NULL; } -static int Command(void *_context, OutputCmd_t command, void * argument) { - Context_t *context = (Context_t*) _context; +static int Command(void *_context, OutputCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_OUTPUT_NO_ERROR; - output_printf(10, "%s::%s Command %d\n", FILENAME, __FUNCTION__, command); + output_printf(10, "%s::%s Command %d\n", FILENAME, __FUNCTION__, + command); - switch(command) { - case OUTPUT_OPEN: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_OPEN, "video"); - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_OPEN, "audio"); - if (context->playback->isSubtitle) - ret |= context->output->subtitle->Command(context, OUTPUT_OPEN, "subtitle"); - if (context->playback->isDvbSubtitle) - ret |= context->output->dvbsubtitle->Command(context, command, "dvbsubtitle"); - if (context->playback->isTeletext) - ret |= context->output->teletext->Command(context, command, "teletext"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_CLOSE: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_CLOSE, "video"); - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_CLOSE, "audio"); - if (context->playback->isSubtitle) - ret |= context->output->subtitle->Command(context, OUTPUT_CLOSE, "subtitle"); - if (context->playback->isDvbSubtitle) - ret |= context->output->dvbsubtitle->Command(context, command, "dvbsubtitle"); - if (context->playback->isTeletext) - ret |= context->output->teletext->Command(context, command, "teletext"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_ADD: { - OutputAdd(context, (char*) argument); - break; - } - case OUTPUT_DEL: { - OutputDel(context, (char*) argument); - break; - } - case OUTPUT_CAPABILITIES: { - printOutputCapabilities(); - break; - } - case OUTPUT_PLAY: { // 4 - if (context && context->playback ) { - if (context->playback->isVideo) - ret = context->output->video->Command(context, OUTPUT_PLAY, "video"); - - if (!ret) { // success or not executed, dunn care - if (context->playback->isAudio) - ret = context->output->audio->Command(context, OUTPUT_PLAY, "audio"); - - if (!ret) { // success or not executed, dunn care - if (context->playback->isSubtitle) - ret = context->output->subtitle->Command(context, OUTPUT_PLAY, "subtitle"); - } + switch (command) { + case OUTPUT_OPEN:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_OPEN, + "video"); + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_OPEN, + "audio"); + if (context->playback->isSubtitle) + ret |= + context->output->subtitle->Command(context, + OUTPUT_OPEN, + "subtitle"); if (context->playback->isDvbSubtitle) - ret |= context->output->dvbsubtitle->Command(context, command, "dvbsubtitle"); + ret |= + context->output->dvbsubtitle->Command(context, + command, + "dvbsubtitle"); if (context->playback->isTeletext) - ret |= context->output->teletext->Command(context, command, "teletext"); - } - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_STOP: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_STOP, "video"); - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_STOP, "audio"); - if (context->playback->isSubtitle) - ret |= context->output->subtitle->Command(context, OUTPUT_STOP, "subtitle"); - if (context->playback->isDvbSubtitle) - ret |= context->output->dvbsubtitle->Command(context, command, "dvbsubtitle"); - if (context->playback->isTeletext) - ret |= context->output->teletext->Command(context, command, "teletext"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_FLUSH: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_FLUSH, "video"); - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_FLUSH, "audio"); - //if (context->playback->isSubtitle) - // ret |= context->output->subtitle->Command(context, OUTPUT_FLUSH, "subtitle"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_PAUSE: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_PAUSE, "video"); - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_PAUSE, "audio"); - //if (context->playback->isSubtitle) - // ret |= context->output->subtitle->Command(context, OUTPUT_PAUSE, "subtitle"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_FASTFORWARD: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_FASTFORWARD, "video"); - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_FASTFORWARD, "audio"); - //if (context->playback->isSubtitle) - // ret |= context->output->subtitle->Command(context, OUTPUT_PAUSE, "subtitle"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_REVERSE: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_REVERSE, "video"); - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_REVERSE, "audio"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_CONTINUE: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_CONTINUE, "video"); - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_CONTINUE, "audio"); - //if (context->playback->isSubtitle) - // ret |= context->output->subtitle->Command(context, OUTPUT_CONTINUE, "subtitle"); - if (context->playback->isDvbSubtitle) - ret |= context->output->dvbsubtitle->Command(context, command, "dvbsubtitle"); - if (context->playback->isTeletext) - ret |= context->output->teletext->Command(context, command, "teletext"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_AVSYNC: { - if (context && context->playback ) { - if (context->playback->isVideo && context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_AVSYNC, "audio"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_CLEAR: { - if (context && context->playback ) { - if (context->playback->isVideo && (argument == NULL || *(char *) argument == 'v')) - ret |= context->output->video->Command(context, OUTPUT_CLEAR, "video"); - if (context->playback->isAudio && (argument == NULL || *(char *) argument == 'a')) - ret |= context->output->audio->Command(context, OUTPUT_CLEAR, "audio"); - //if (context->playback->isSubtitle && (argument == NULL || *(char *) argument == 's')) - // ret |= context->output->subtitle->Command(context, OUTPUT_CLEAR, "subtitle"); - if (context->playback->isDvbSubtitle) - ret |= context->output->dvbsubtitle->Command(context, command, "dvbsubtitle"); - if (context->playback->isTeletext) - ret |= context->output->teletext->Command(context, command, "teletext"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_PTS: { - if (context && context->playback ) { - if (context->playback->isVideo) - return context->output->video->Command(context, OUTPUT_PTS, argument); - if (context->playback->isAudio) - return context->output->audio->Command(context, OUTPUT_PTS, argument); - //if (context->playback->isSubtitle) - // return context->output->subtitle->Command(context, OUTPUT_PTS, "subtitle"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_SWITCH: { - if (context && context->playback ) { - if (context->playback->isAudio) - return context->output->audio->Command(context, OUTPUT_SWITCH, "audio"); - if (context->playback->isVideo) - return context->output->video->Command(context, OUTPUT_SWITCH, "video"); - if (context->playback->isDvbSubtitle) - ret |= context->output->dvbsubtitle->Command(context, command, "dvbsubtitle"); - if (context->playback->isTeletext) - ret |= context->output->teletext->Command(context, command, "teletext"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_SLOWMOTION: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_SLOWMOTION, "video"); - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_SLOWMOTION, "audio"); - //if (context->playback->isSubtitle) - // ret |= context->output->subtitle->Command(context, OUTPUT_PAUSE, "subtitle"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_AUDIOMUTE: { - if (context && context->playback ) { - if (context->playback->isAudio) - ret |= context->output->audio->Command(context, OUTPUT_AUDIOMUTE, (char*) argument); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_DISCONTINUITY_REVERSE: { - if (context && context->playback ) { - if (context->playback->isVideo) - ret |= context->output->video->Command(context, OUTPUT_DISCONTINUITY_REVERSE, (void*) argument); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } - case OUTPUT_GET_FRAME_COUNT: { - if (context && context->playback ) { - if (context->playback->isVideo) - return context->output->video->Command(context, OUTPUT_GET_FRAME_COUNT, argument); - if (context->playback->isAudio) - return context->output->audio->Command(context, OUTPUT_GET_FRAME_COUNT, argument); - //if (context->playback->isSubtitle) - // return context->output->subtitle->Command(context, OUTPUT_GET_FRAME_COUNT, "subtitle"); - } else - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; - } + ret |= + context->output->teletext->Command(context, + command, + "teletext"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_CLOSE:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_CLOSE, + "video"); + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_CLOSE, + "audio"); + if (context->playback->isSubtitle) + ret |= + context->output->subtitle->Command(context, + OUTPUT_CLOSE, + "subtitle"); + if (context->playback->isDvbSubtitle) + ret |= + context->output->dvbsubtitle->Command(context, + command, + "dvbsubtitle"); + if (context->playback->isTeletext) + ret |= + context->output->teletext->Command(context, + command, + "teletext"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_ADD:{ + OutputAdd(context, (char *) argument); + break; + } + case OUTPUT_DEL:{ + OutputDel(context, (char *) argument); + break; + } + case OUTPUT_CAPABILITIES:{ + printOutputCapabilities(); + break; + } + case OUTPUT_PLAY:{ // 4 + if (context && context->playback) { + if (context->playback->isVideo) + ret = + context->output->video->Command(context, + OUTPUT_PLAY, + "video"); + + if (!ret) { // success or not executed, dunn care + if (context->playback->isAudio) + ret = + context->output->audio->Command(context, + OUTPUT_PLAY, + "audio"); + + if (!ret) { // success or not executed, dunn care + if (context->playback->isSubtitle) + ret = + context->output->subtitle->Command(context, + OUTPUT_PLAY, + "subtitle"); + } + if (context->playback->isDvbSubtitle) + ret |= + context->output->dvbsubtitle->Command(context, + command, + "dvbsubtitle"); + if (context->playback->isTeletext) + ret |= + context->output->teletext->Command(context, + command, + "teletext"); + } + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_STOP:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_STOP, + "video"); + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_STOP, + "audio"); + if (context->playback->isSubtitle) + ret |= + context->output->subtitle->Command(context, + OUTPUT_STOP, + "subtitle"); + if (context->playback->isDvbSubtitle) + ret |= + context->output->dvbsubtitle->Command(context, + command, + "dvbsubtitle"); + if (context->playback->isTeletext) + ret |= + context->output->teletext->Command(context, + command, + "teletext"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_FLUSH:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_FLUSH, + "video"); + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_FLUSH, + "audio"); + //if (context->playback->isSubtitle) + // ret |= context->output->subtitle->Command(context, OUTPUT_FLUSH, "subtitle"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_PAUSE:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_PAUSE, + "video"); + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_PAUSE, + "audio"); + //if (context->playback->isSubtitle) + // ret |= context->output->subtitle->Command(context, OUTPUT_PAUSE, "subtitle"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_FASTFORWARD:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_FASTFORWARD, + "video"); + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_FASTFORWARD, + "audio"); + //if (context->playback->isSubtitle) + // ret |= context->output->subtitle->Command(context, OUTPUT_PAUSE, "subtitle"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_REVERSE:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_REVERSE, + "video"); + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_REVERSE, + "audio"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_CONTINUE:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_CONTINUE, + "video"); + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_CONTINUE, + "audio"); + //if (context->playback->isSubtitle) + // ret |= context->output->subtitle->Command(context, OUTPUT_CONTINUE, "subtitle"); + if (context->playback->isDvbSubtitle) + ret |= + context->output->dvbsubtitle->Command(context, + command, + "dvbsubtitle"); + if (context->playback->isTeletext) + ret |= + context->output->teletext->Command(context, + command, + "teletext"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_AVSYNC:{ + if (context && context->playback) { + if (context->playback->isVideo + && context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_AVSYNC, + "audio"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_CLEAR:{ + if (context && context->playback) { + if (context->playback->isVideo + && (argument == NULL || *(char *) argument == 'v')) + ret |= + context->output->video->Command(context, + OUTPUT_CLEAR, + "video"); + if (context->playback->isAudio + && (argument == NULL || *(char *) argument == 'a')) + ret |= + context->output->audio->Command(context, + OUTPUT_CLEAR, + "audio"); + //if (context->playback->isSubtitle && (argument == NULL || *(char *) argument == 's')) + // ret |= context->output->subtitle->Command(context, OUTPUT_CLEAR, "subtitle"); + if (context->playback->isDvbSubtitle) + ret |= + context->output->dvbsubtitle->Command(context, + command, + "dvbsubtitle"); + if (context->playback->isTeletext) + ret |= + context->output->teletext->Command(context, + command, + "teletext"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_PTS:{ + if (context && context->playback) { + if (context->playback->isVideo) + return context->output->video->Command(context, + OUTPUT_PTS, + argument); + if (context->playback->isAudio) + return context->output->audio->Command(context, + OUTPUT_PTS, + argument); + //if (context->playback->isSubtitle) + // return context->output->subtitle->Command(context, OUTPUT_PTS, "subtitle"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_SWITCH:{ + if (context && context->playback) { + if (context->playback->isAudio) + return context->output->audio->Command(context, + OUTPUT_SWITCH, + "audio"); + if (context->playback->isVideo) + return context->output->video->Command(context, + OUTPUT_SWITCH, + "video"); + if (context->playback->isDvbSubtitle) + ret |= + context->output->dvbsubtitle->Command(context, + command, + "dvbsubtitle"); + if (context->playback->isTeletext) + ret |= + context->output->teletext->Command(context, + command, + "teletext"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_SLOWMOTION:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_SLOWMOTION, + "video"); + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_SLOWMOTION, + "audio"); + //if (context->playback->isSubtitle) + // ret |= context->output->subtitle->Command(context, OUTPUT_PAUSE, "subtitle"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_AUDIOMUTE:{ + if (context && context->playback) { + if (context->playback->isAudio) + ret |= + context->output->audio->Command(context, + OUTPUT_AUDIOMUTE, + (char *) argument); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_DISCONTINUITY_REVERSE:{ + if (context && context->playback) { + if (context->playback->isVideo) + ret |= + context->output->video->Command(context, + OUTPUT_DISCONTINUITY_REVERSE, + (void *) argument); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } + case OUTPUT_GET_FRAME_COUNT:{ + if (context && context->playback) { + if (context->playback->isVideo) + return context->output->video->Command(context, + OUTPUT_GET_FRAME_COUNT, + argument); + if (context->playback->isAudio) + return context->output->audio->Command(context, + OUTPUT_GET_FRAME_COUNT, + argument); + //if (context->playback->isSubtitle) + // return context->output->subtitle->Command(context, OUTPUT_GET_FRAME_COUNT, "subtitle"); + } else + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; + } default: - output_err("%s::%s OutputCmd %d not supported!\n", FILENAME, __FUNCTION__, command); - ret = cERR_OUTPUT_INTERNAL_ERROR; - break; + output_err("%s::%s OutputCmd %d not supported!\n", FILENAME, + __FUNCTION__, command); + ret = cERR_OUTPUT_INTERNAL_ERROR; + break; } - output_printf(10, "%s::%s exiting with value %d\n", FILENAME, __FUNCTION__, ret); + output_printf(10, "%s::%s exiting with value %d\n", FILENAME, + __FUNCTION__, ret); return ret; } @@ -401,7 +552,7 @@ OutputHandler_t OutputHandler = { NULL, NULL, NULL, - NULL, // dvbsubtitle - NULL, // teletext + NULL, // dvbsubtitle + NULL, // teletext &Command }; diff --git a/libeplayer3/output/output_pipe.c b/libeplayer3/output/output_pipe.c index bfe1231..0116310 100644 --- a/libeplayer3/output/output_pipe.c +++ b/libeplayer3/output/output_pipe.c @@ -70,24 +70,28 @@ if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x ); #define cERR_PIPE_NO_ERROR 0 #define cERR_PIPE_ERROR -1 -static const char TELETEXTPIPE[] = "/tmp/.eplayer3_teletext"; -static const char DVBSUBTITLEPIPE[] = "/tmp/.eplayer3_dvbsubtitle"; +static const char TELETEXTPIPE[] = "/tmp/.eplayer3_teletext"; +static const char DVBSUBTITLEPIPE[] = "/tmp/.eplayer3_dvbsubtitle"; -static int teletextfd = -1; -static int dvbsubtitlefd = -1; +static int teletextfd = -1; +static int dvbsubtitlefd = -1; pthread_mutex_t Pipemutex; /* ***************************** */ /* Prototypes */ /* ***************************** */ -int PipeStop(Context_t *context, char * type); +int PipeStop(Context_t * context, char *type); /* ***************************** */ /* MISC Functions */ /* ***************************** */ -void getPipeMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused))) { +void getPipeMutex(const char *filename + __attribute__ ((unused)), const char *function + __attribute__ ((unused)), int line + __attribute__ ((unused))) +{ pipe_printf(250, "requesting mutex\n"); @@ -96,46 +100,52 @@ void getPipeMutex(const char *filename __attribute__((unused)), const char *func pipe_printf(250, "received mutex\n"); } -void releasePipeMutex(const char *filename __attribute__((unused)), const char *function __attribute__((unused)), int line __attribute__((unused))) { +void releasePipeMutex(const char *filename + __attribute__ ((unused)), const char *function + __attribute__ ((unused)), int line + __attribute__ ((unused))) +{ pthread_mutex_unlock(&Pipemutex); pipe_printf(250, "released mutex\n"); } -int PipeOpen(Context_t *context __attribute__((unused)), char * type) { +int PipeOpen(Context_t * context __attribute__ ((unused)), char *type) +{ unsigned char teletext = !strcmp("teletext", type); unsigned char dvbsubtitle = !strcmp("dvbsubtitle", type); pipe_printf(10, "t%d d%d\n", teletext, dvbsubtitle); if (teletext && teletextfd == -1) { - mkfifo(TELETEXTPIPE, 0644); - teletextfd = open(TELETEXTPIPE, O_RDWR | O_NONBLOCK); + mkfifo(TELETEXTPIPE, 0644); + teletextfd = open(TELETEXTPIPE, O_RDWR | O_NONBLOCK); - if (teletextfd < 0) - { - pipe_err("failed to open %s - errno %d\n", TELETEXTPIPE, errno); - pipe_err("%s\n", strerror(errno)); - return cERR_PIPE_ERROR; - } + if (teletextfd < 0) { + pipe_err("failed to open %s - errno %d\n", TELETEXTPIPE, + errno); + pipe_err("%s\n", strerror(errno)); + return cERR_PIPE_ERROR; + } } if (dvbsubtitle && dvbsubtitlefd == -1) { - mkfifo(DVBSUBTITLEPIPE, 0644); - dvbsubtitlefd = open(DVBSUBTITLEPIPE, O_RDWR | O_NONBLOCK); + mkfifo(DVBSUBTITLEPIPE, 0644); + dvbsubtitlefd = open(DVBSUBTITLEPIPE, O_RDWR | O_NONBLOCK); - if (dvbsubtitlefd < 0) - { - pipe_err("failed to open %s - errno %d\n", DVBSUBTITLEPIPE, errno); - pipe_err("%s\n", strerror(errno)); - return cERR_PIPE_ERROR; - } + if (dvbsubtitlefd < 0) { + pipe_err("failed to open %s - errno %d\n", DVBSUBTITLEPIPE, + errno); + pipe_err("%s\n", strerror(errno)); + return cERR_PIPE_ERROR; + } } return cERR_PIPE_NO_ERROR; } -int PipeClose(Context_t *context, char * type) { +int PipeClose(Context_t * context, char *type) +{ unsigned char dvbsubtitle = !strcmp("dvbsubtitle", type); unsigned char teletext = !strcmp("teletext", type); @@ -147,22 +157,24 @@ int PipeClose(Context_t *context, char * type) { */ PipeStop(context, type); - getPipeMutex(FILENAME, __FUNCTION__,__LINE__); + getPipeMutex(FILENAME, __FUNCTION__, __LINE__); if (dvbsubtitle && dvbsubtitlefd != -1) { - close(dvbsubtitlefd); - dvbsubtitlefd = -1; + close(dvbsubtitlefd); + dvbsubtitlefd = -1; } if (teletext && teletextfd != -1) { - close(teletextfd); - teletextfd = -1; + close(teletextfd); + teletextfd = -1; } - releasePipeMutex(FILENAME, __FUNCTION__,__LINE__); + releasePipeMutex(FILENAME, __FUNCTION__, __LINE__); return cERR_PIPE_NO_ERROR; } -int PipePlay(Context_t *context __attribute__((unused)), char * type __attribute__((unused))) { +int PipePlay(Context_t * context __attribute__ ((unused)), char *type + __attribute__ ((unused))) +{ int ret = cERR_PIPE_NO_ERROR; #if 0 @@ -179,7 +191,9 @@ int PipePlay(Context_t *context __attribute__((unused)), char * type __attribut return ret; } -int PipeStop(Context_t *context __attribute__((unused)), char * type __attribute__((unused))) { +int PipeStop(Context_t * context __attribute__ ((unused)), char *type + __attribute__ ((unused))) +{ int ret = cERR_PIPE_NO_ERROR; #if 0 @@ -188,38 +202,40 @@ int PipeStop(Context_t *context __attribute__((unused)), char * type __attribut pipe_printf(10, "t%d d%d\n", teletext, dvbsubtitle); - getPipeMutex(FILENAME, __FUNCTION__,__LINE__); + getPipeMutex(FILENAME, __FUNCTION__, __LINE__); if (dvbsubtitle && dvbsubtitlefd != -1) { } if (teletext && teletextfd != -1) { } - releasePipeMutex(FILENAME, __FUNCTION__,__LINE__); + releasePipeMutex(FILENAME, __FUNCTION__, __LINE__); #endif return ret; } -int PipeFlush(Context_t *context __attribute__((unused)), char * type) { +int PipeFlush(Context_t * context __attribute__ ((unused)), char *type) +{ unsigned char dvbsubtitle = !strcmp("dvbsubtitle", type); unsigned char teletext = !strcmp("teletext", type); pipe_printf(10, "t%d d%d\n", teletext, dvbsubtitle); - if ( (dvbsubtitle && dvbsubtitlefd != -1) || (teletext && teletextfd != -1) ) { - getPipeMutex(FILENAME, __FUNCTION__,__LINE__); + if ((dvbsubtitle && dvbsubtitlefd != -1) + || (teletext && teletextfd != -1)) { + getPipeMutex(FILENAME, __FUNCTION__, __LINE__); if (dvbsubtitle && dvbsubtitlefd != -1) { char buf[65536]; - while(0 < read(dvbsubtitlefd, buf, sizeof(buf))); + while (0 < read(dvbsubtitlefd, buf, sizeof(buf))); } if (teletext && teletextfd != -1) { char buf[65536]; - while(0 < read(teletextfd, buf, sizeof(buf))); + while (0 < read(teletextfd, buf, sizeof(buf))); } - releasePipeMutex(FILENAME, __FUNCTION__,__LINE__); + releasePipeMutex(FILENAME, __FUNCTION__, __LINE__); } pipe_printf(10, "exiting\n"); @@ -227,26 +243,28 @@ int PipeFlush(Context_t *context __attribute__((unused)), char * type) { return cERR_PIPE_NO_ERROR; } -int PipeClear(Context_t *context __attribute__((unused)), char * type) { +int PipeClear(Context_t * context __attribute__ ((unused)), char *type) +{ int ret = cERR_PIPE_NO_ERROR; unsigned char dvbsubtitle = !strcmp("dvbsubtitle", type); unsigned char teletext = !strcmp("teletext", type); pipe_printf(10, "v%d a%d\n", dvbsubtitle, teletext); - if ( (dvbsubtitle && dvbsubtitlefd != -1) || (teletext && teletextfd != -1) ) { - getPipeMutex(FILENAME, __FUNCTION__,__LINE__); + if ((dvbsubtitle && dvbsubtitlefd != -1) + || (teletext && teletextfd != -1)) { + getPipeMutex(FILENAME, __FUNCTION__, __LINE__); if (dvbsubtitle && dvbsubtitlefd != -1) { char buf[65536]; - while(0 < read(dvbsubtitlefd, buf, sizeof(buf))); + while (0 < read(dvbsubtitlefd, buf, sizeof(buf))); } if (teletext && teletextfd != -1) { char buf[65536]; - while(0 < read(teletextfd, buf, sizeof(buf))); + while (0 < read(teletextfd, buf, sizeof(buf))); } - releasePipeMutex(FILENAME, __FUNCTION__,__LINE__); + releasePipeMutex(FILENAME, __FUNCTION__, __LINE__); } pipe_printf(10, "exiting\n"); @@ -254,23 +272,26 @@ int PipeClear(Context_t *context __attribute__((unused)), char * type) { return ret; } -int PipeSwitch(Context_t *context __attribute__((unused)), char * type __attribute__((unused))) { +int PipeSwitch(Context_t * context __attribute__ ((unused)), char *type + __attribute__ ((unused))) +{ #if 0 unsigned char dvbsubtitle = !strcmp("dvbsubtitle", type); unsigned char teletext = !strcmp("teletext", type); pipe_printf(10, "v%d a%d\n", dvbsubtitle, teletext); - if ( (dvbsubtitle && dvbsubtitlefd != -1) || (teletext && teletextfd != -1) ) { - getPipeMutex(FILENAME, __FUNCTION__,__LINE__); + if ((dvbsubtitle && dvbsubtitlefd != -1) + || (teletext && teletextfd != -1)) { + getPipeMutex(FILENAME, __FUNCTION__, __LINE__); - if (teletext && teletextfd != -1) { - } + if (teletext && teletextfd != -1) { + } - if (dvbsubtitle && dvbsubtitlefd != -1) { - } + if (dvbsubtitle && dvbsubtitlefd != -1) { + } - releasePipeMutex(FILENAME, __FUNCTION__,__LINE__); + releasePipeMutex(FILENAME, __FUNCTION__, __LINE__); } @@ -279,11 +300,12 @@ int PipeSwitch(Context_t *context __attribute__((unused)), char * type __attrib return cERR_PIPE_NO_ERROR; } -static int writePESDataTeletext(int fd, unsigned char *data, size_t data_len) +static int writePESDataTeletext(int fd, unsigned char *data, + size_t data_len) { unsigned int len = 0; if (data_len > 0) { - len = data_len + 39; + len = data_len + 39; char header[45]; memset(header, 0, sizeof(header)); header[2] = 0x01; @@ -299,17 +321,18 @@ static int writePESDataTeletext(int fd, unsigned char *data, size_t data_len) if (len != iov[0].iov_len + iov[1].iov_len) { // writing to pipe failed, clear it. char buf[65536]; - while(0 < read(fd, buf, sizeof(buf))); + while (0 < read(fd, buf, sizeof(buf))); } } return len; } -static int writePESDataDvbsubtitle(int fd, unsigned char *data, size_t data_len, int64_t pts) +static int writePESDataDvbsubtitle(int fd, unsigned char *data, + size_t data_len, int64_t pts) { int len = 0; if (data_len > 0) { - len = data_len + 10; + len = data_len + 10; char header[16]; memset(header, 0, sizeof(header)); header[2] = 0x01; @@ -318,16 +341,16 @@ static int writePESDataDvbsubtitle(int fd, unsigned char *data, size_t data_len, header[5] = len & 0xff; if (pts) { - header[7] = 0x80; - header[13] = 0x01 | ((pts << 1) & 0xff); - pts >>= 7; - header[12] = pts & 0xff; - pts >>=8; - header[11] = 0x01 | ((pts << 1) & 0xff); - pts >>= 7; - header[10] = pts & 0xff; - pts >>=8; - header[9] = 0x21 | ((pts << 1) & 0xff); + header[7] = 0x80; + header[13] = 0x01 | ((pts << 1) & 0xff); + pts >>= 7; + header[12] = pts & 0xff; + pts >>= 8; + header[11] = 0x01 | ((pts << 1) & 0xff); + pts >>= 7; + header[10] = pts & 0xff; + pts >>= 8; + header[9] = 0x21 | ((pts << 1) & 0xff); } header[8] = 14 - 9; header[14] = 0x20; @@ -337,104 +360,105 @@ static int writePESDataDvbsubtitle(int fd, unsigned char *data, size_t data_len, iov[1].iov_base = data; iov[1].iov_len = data_len; len = writev(fd, iov, 2); - if (len != (int)(iov[0].iov_len + iov[1].iov_len)) { + if (len != (int) (iov[0].iov_len + iov[1].iov_len)) { // writing to pipe failed, clear it. char buf[65536]; - while(0 < read(fd, buf, sizeof(buf))); + while (0 < read(fd, buf, sizeof(buf))); } } return len; } -static int Write(void *_context __attribute__((unused)), void* _out) +static int Write(void *_context __attribute__ ((unused)), void *_out) { - AudioVideoOut_t *out = (AudioVideoOut_t*) _out; - int ret = cERR_PIPE_NO_ERROR; - int res = 0; - unsigned char dvbsubtitle; - unsigned char teletext; + AudioVideoOut_t *out = (AudioVideoOut_t *) _out; + int ret = cERR_PIPE_NO_ERROR; + int res = 0; + unsigned char dvbsubtitle; + unsigned char teletext; - if (out == NULL) - { - pipe_err("null pointer passed\n"); - return cERR_PIPE_ERROR; + if (out == NULL) { + pipe_err("null pointer passed\n"); + return cERR_PIPE_ERROR; } - + dvbsubtitle = !strcmp("dvbsubtitle", out->type); teletext = !strcmp("teletext", out->type); - - pipe_printf(20, "DataLength=%u PrivateLength=%u Pts=%llu FrameRate=%f\n", - out->len, out->extralen, out->pts, out->frameRate); + + pipe_printf(20, + "DataLength=%u PrivateLength=%u Pts=%llu FrameRate=%f\n", + out->len, out->extralen, out->pts, out->frameRate); pipe_printf(20, "v%d a%d\n", dvbsubtitle, teletext); if (dvbsubtitle) { - res = writePESDataDvbsubtitle(dvbsubtitlefd, out->data, out->len, out->pts); + res = + writePESDataDvbsubtitle(dvbsubtitlefd, out->data, out->len, + out->pts); - if (res <= 0) - { - ret = cERR_PIPE_ERROR; - } + if (res <= 0) { + ret = cERR_PIPE_ERROR; + } } else if (teletext) { res = writePESDataTeletext(teletextfd, out->data, out->len); - if (res <= 0) - { - ret = cERR_PIPE_ERROR; - } + if (res <= 0) { + ret = cERR_PIPE_ERROR; + } } return ret; } -static int reset(Context_t *context __attribute__((unused))) +static int reset(Context_t * context __attribute__ ((unused))) { int ret = cERR_PIPE_NO_ERROR; return ret; } -static int Command(void *_context, OutputCmd_t command, void * argument) { - Context_t* context = (Context_t*) _context; +static int Command(void *_context, OutputCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_PIPE_NO_ERROR; - + pipe_printf(50, "Command %d\n", command); - switch(command) { - case OUTPUT_OPEN: { - ret = PipeOpen(context, (char*)argument); - break; - } - case OUTPUT_CLOSE: { - ret = PipeClose(context, (char*)argument); - reset(context); - break; - } - case OUTPUT_PLAY: { // 4 - ret = PipePlay(context, (char*)argument); - break; - } - case OUTPUT_STOP: { - reset(context); - ret = PipeStop(context, (char*)argument); - break; - } - case OUTPUT_FLUSH: { - ret = PipeFlush(context, (char*)argument); - reset(context); - break; - } - case OUTPUT_CLEAR: { - ret = PipeClear(context, (char*)argument); - break; - } - case OUTPUT_SWITCH: { - ret = PipeSwitch(context, (char*)argument); - break; - } + switch (command) { + case OUTPUT_OPEN:{ + ret = PipeOpen(context, (char *) argument); + break; + } + case OUTPUT_CLOSE:{ + ret = PipeClose(context, (char *) argument); + reset(context); + break; + } + case OUTPUT_PLAY:{ // 4 + ret = PipePlay(context, (char *) argument); + break; + } + case OUTPUT_STOP:{ + reset(context); + ret = PipeStop(context, (char *) argument); + break; + } + case OUTPUT_FLUSH:{ + ret = PipeFlush(context, (char *) argument); + reset(context); + break; + } + case OUTPUT_CLEAR:{ + ret = PipeClear(context, (char *) argument); + break; + } + case OUTPUT_SWITCH:{ + ret = PipeSwitch(context, (char *) argument); + break; + } default: - pipe_err("ContainerCmd %d not supported!\n", command); - ret = cERR_PIPE_ERROR; - break; + pipe_err("ContainerCmd %d not supported!\n", command); + ret = cERR_PIPE_ERROR; + break; } pipe_printf(50, "exiting with value %d\n", ret); diff --git a/libeplayer3/output/output_subtitle.c b/libeplayer3/output/output_subtitle.c index 9d75166..11ef0dd 100644 --- a/libeplayer3/output/output_subtitle.c +++ b/libeplayer3/output/output_subtitle.c @@ -81,9 +81,9 @@ Number, Style, Name,, MarginL, MarginR, MarginV, Effect,, Text /* ***************************** */ struct sub_t { - char * text; + char *text; unsigned long long int pts; - unsigned long int milliDuration; + unsigned long int milliDuration; }; @@ -95,19 +95,19 @@ static pthread_mutex_t mutex; static pthread_t thread_sub; -void* clientData = NULL; -void (*clientFunction) (long int, size_t, char *, void *); +void *clientData = NULL; +void (*clientFunction) (long int, size_t, char *, void *); static struct sub_t subPuffer[PUFFERSIZE]; static int readPointer = 0; static int writePointer = 0; static int hasThreadStarted = 0; static int isSubtitleOpened = 0; -static int screen_width = 0; -static int screen_height = 0; -static int destStride = 0; -static void (*framebufferBlit) = NULL; -static uint32_t *destination = NULL; +static int screen_width = 0; +static int screen_height = 0; +static int destStride = 0; +static void (*framebufferBlit) = NULL; +static uint32_t *destination = NULL; /* ***************************** */ /* Prototypes */ @@ -116,7 +116,8 @@ static uint32_t *destination = NULL; /* ***************************** */ /* MISC Functions */ /* ***************************** */ -static void getMutex(int line) { +static void getMutex(int line) +{ subtitle_printf(100, "%d requesting mutex\n", line); pthread_mutex_lock(&mutex); @@ -124,75 +125,77 @@ static void getMutex(int line) { subtitle_printf(100, "%d received mutex\n", line); } -static void releaseMutex(int line) { +static void releaseMutex(int line) +{ pthread_mutex_unlock(&mutex); subtitle_printf(100, "%d released mutex\n", line); } -void replace_all(char ** string, char * search, char * replace) { +void replace_all(char **string, char *search, char *replace) +{ int len = 0; - char * ptr = NULL; + char *ptr = NULL; char tempString[512]; char newString[512]; newString[0] = '\0'; - if ((string == NULL) || (*string == NULL) || (search == NULL) || (replace == NULL)) - { - subtitle_err("null pointer passed\n"); - return; + if ((string == NULL) || (*string == NULL) || (search == NULL) + || (replace == NULL)) { + subtitle_err("null pointer passed\n"); + return; } - + strncpy(tempString, *string, 511); tempString[511] = '\0'; free(*string); while ((ptr = strstr(tempString, search)) != NULL) { - len = ptr - tempString; - strncpy(newString, tempString, len); - newString[len] = '\0'; - strcat(newString, replace); + len = ptr - tempString; + strncpy(newString, tempString, len); + newString[len] = '\0'; + strcat(newString, replace); - len += strlen(search); - strcat(newString, tempString+len); + len += strlen(search); + strcat(newString, tempString + len); - strcpy(tempString, newString); + strcpy(tempString, newString); } subtitle_printf(20, "strdup in line %d\n", __LINE__); - if(newString[0] != '\0') - *string = strdup(newString); + if (newString[0] != '\0') + *string = strdup(newString); else - *string = strdup(tempString); + *string = strdup(tempString); } -int subtitle_ParseASS (char **Line) { - char* Text; - int i; - char* ptr1; +int subtitle_ParseASS(char **Line) +{ + char *Text; + int i; + char *ptr1; - if ((Line == NULL) || (*Line == NULL)) - { - subtitle_err("null pointer passed\n"); - return cERR_SUBTITLE_ERROR; + if ((Line == NULL) || (*Line == NULL)) { + subtitle_err("null pointer passed\n"); + return cERR_SUBTITLE_ERROR; } - + Text = strdup(*Line); subtitle_printf(10, "-> Text = %s\n", *Line); ptr1 = Text; - - for (i=0; i < 9 && *ptr1 != '\0'; ptr1++) { - subtitle_printf(20, "%s",ptr1); + for (i = 0; i < 9 && *ptr1 != '\0'; ptr1++) { - if (*ptr1 == ',') - i++; + subtitle_printf(20, "%s", ptr1); + + if (*ptr1 == ',') + i++; } free(*Line); @@ -210,12 +213,12 @@ int subtitle_ParseASS (char **Line) { return cERR_SUBTITLE_NO_ERROR; } -int subtitle_ParseSRT (char **Line) { +int subtitle_ParseSRT(char **Line) +{ - if ((Line == NULL) || (*Line == NULL)) - { - subtitle_err("null pointer passed\n"); - return cERR_SUBTITLE_ERROR; + if ((Line == NULL) || (*Line == NULL)) { + subtitle_err("null pointer passed\n"); + return cERR_SUBTITLE_ERROR; } subtitle_printf(20, "-> Text=%s\n", *Line); @@ -237,12 +240,12 @@ int subtitle_ParseSRT (char **Line) { return cERR_SUBTITLE_NO_ERROR; } -int subtitle_ParseSSA (char **Line) { +int subtitle_ParseSSA(char **Line) +{ - if ((Line == NULL) || (*Line == NULL)) - { - subtitle_err("null pointer passed\n"); - return cERR_SUBTITLE_ERROR; + if ((Line == NULL) || (*Line == NULL)) { + subtitle_err("null pointer passed\n"); + return cERR_SUBTITLE_ERROR; } subtitle_printf(20, "-> Text=%s\n", *Line); @@ -264,79 +267,76 @@ int subtitle_ParseSSA (char **Line) { return cERR_SUBTITLE_NO_ERROR; } -void addSub(Context_t *context, char * text, unsigned long long int pts, unsigned long int milliDuration) { +void addSub(Context_t * context, char *text, unsigned long long int pts, + unsigned long int milliDuration) +{ int count = 20; - + subtitle_printf(50, "index %d\n", writePointer); - if(context && context->playback && !context->playback->isPlaying) - { - subtitle_err("1. aborting ->no playback\n"); - return; - } - - if (text == NULL) - { - subtitle_err("null pointer passed\n"); - return; + if (context && context->playback && !context->playback->isPlaying) { + subtitle_err("1. aborting ->no playback\n"); + return; } - if (pts == 0) - { - subtitle_err("pts 0\n"); - return; + if (text == NULL) { + subtitle_err("null pointer passed\n"); + return; } - if (milliDuration == 0) - { - subtitle_err("duration 0\n"); - return; + if (pts == 0) { + subtitle_err("pts 0\n"); + return; } - + + if (milliDuration == 0) { + subtitle_err("duration 0\n"); + return; + } + while (subPuffer[writePointer].text != NULL) { - //List is full, wait till we got some free space + //List is full, wait till we got some free space - if(context && context->playback && !context->playback->isPlaying) - { - subtitle_err("2. aborting ->no playback\n"); - return; - } + if (context && context->playback && !context->playback->isPlaying) { + subtitle_err("2. aborting ->no playback\n"); + return; + } /* konfetti: we dont want to block forever here. if no buffer * is available we start ring from the beginning and loose some stuff * which is acceptable! */ - subtitle_printf(10, "waiting on free buffer %d - %d (%d) ...\n", writePointer, readPointer, count); - usleep(10000); - count--; - - if (count == 0) - { - subtitle_err("abort waiting on buffer...\n"); - break; - } + subtitle_printf(10, "waiting on free buffer %d - %d (%d) ...\n", + writePointer, readPointer, count); + usleep(10000); + count--; + + if (count == 0) { + subtitle_err("abort waiting on buffer...\n"); + break; + } } - - subtitle_printf(20, "from mkv: %s pts:%lld milliDuration:%lud\n",text,pts,milliDuration); + + subtitle_printf(20, "from mkv: %s pts:%lld milliDuration:%lud\n", text, + pts, milliDuration); getMutex(__LINE__); - if (count == 0) - { - int i; - subtitle_err("freeing not delivered data\n"); - - //Reset all - readPointer = 0; - writePointer = 0; + if (count == 0) { + int i; + subtitle_err("freeing not delivered data\n"); - for (i = 0; i < PUFFERSIZE; i++) { - if (subPuffer[i].text != NULL) - free(subPuffer[i].text); - subPuffer[i].text = NULL; - subPuffer[i].pts = 0; - subPuffer[i].milliDuration = 0; - } + //Reset all + readPointer = 0; + writePointer = 0; + + for (i = 0; i < PUFFERSIZE; i++) { + if (subPuffer[i].text != NULL) + free(subPuffer[i].text); + subPuffer[i].text = NULL; + subPuffer[i].pts = 0; + subPuffer[i].milliDuration = 0; + } } subPuffer[writePointer].text = strdup(text); @@ -344,17 +344,16 @@ void addSub(Context_t *context, char * text, unsigned long long int pts, unsign subPuffer[writePointer].milliDuration = milliDuration; writePointer++; - - if (writePointer == PUFFERSIZE) - writePointer = 0; - if (writePointer == readPointer) - { - /* this should not happen, and means that there is nor reader or - * the reader has performance probs ;) - * the recovery is done at startup of this function - but next time - */ - subtitle_err("ups something went wrong. no more readers? \n"); + if (writePointer == PUFFERSIZE) + writePointer = 0; + + if (writePointer == readPointer) { + /* this should not happen, and means that there is nor reader or + * the reader has performance probs ;) + * the recovery is done at startup of this function - but next time + */ + subtitle_err("ups something went wrong. no more readers? \n"); } releaseMutex(__LINE__); @@ -362,28 +361,28 @@ void addSub(Context_t *context, char * text, unsigned long long int pts, unsign subtitle_printf(10, "<\n"); } -int getNextSub(char ** text, unsigned long long int * pts, long int * milliDuration) { +int getNextSub(char **text, unsigned long long int *pts, + long int *milliDuration) +{ subtitle_printf(50, "index %d\n", readPointer); - if (text == NULL) - { - subtitle_err("null pointer passed\n"); - return cERR_SUBTITLE_ERROR; + if (text == NULL) { + subtitle_err("null pointer passed\n"); + return cERR_SUBTITLE_ERROR; } getMutex(__LINE__); - if (subPuffer[readPointer].text == NULL) - { - /* this is acutally not an error, because it may happen - * that there is no subtitle for a while - */ - subtitle_printf(200, "null in subPuffer\n"); - releaseMutex(__LINE__); - return cERR_SUBTITLE_ERROR; + if (subPuffer[readPointer].text == NULL) { + /* this is acutally not an error, because it may happen + * that there is no subtitle for a while + */ + subtitle_printf(200, "null in subPuffer\n"); + releaseMutex(__LINE__); + return cERR_SUBTITLE_ERROR; } - + *text = strdup(subPuffer[readPointer].text); free(subPuffer[readPointer].text); subPuffer[readPointer].text = NULL; @@ -397,20 +396,20 @@ int getNextSub(char ** text, unsigned long long int * pts, long int * milliDurat readPointer++; if (readPointer == PUFFERSIZE) - readPointer = 0; + readPointer = 0; - if (writePointer == readPointer) - { - /* this may happen, in normal case the reader is ones ahead the - * writer. So this is the normal case that we eat the data - * and have the reader reached. - */ - subtitle_printf(20, "ups something went wrong. no more writers? \n"); + if (writePointer == readPointer) { + /* this may happen, in normal case the reader is ones ahead the + * writer. So this is the normal case that we eat the data + * and have the reader reached. + */ + subtitle_printf(20, + "ups something went wrong. no more writers? \n"); } releaseMutex(__LINE__); - subtitle_printf(20, "readPointer %d\n",readPointer); + subtitle_printf(20, "readPointer %d\n", readPointer); subtitle_printf(10, "<\n"); return cERR_SUBTITLE_NO_ERROR; @@ -420,98 +419,103 @@ int getNextSub(char ** text, unsigned long long int * pts, long int * milliDurat /* Worker Thread */ /* **************************** */ -static void* SubtitleThread(void* data) { - Context_t *context = (Context_t*) data; - char * subText = NULL; - long int subMilliDuration = 0; - unsigned long long int subPts = 0; - unsigned long long int Pts = 0; +static void *SubtitleThread(void *data) +{ + Context_t *context = (Context_t *) data; + char *subText = NULL; + long int subMilliDuration = 0; + unsigned long long int subPts = 0; + unsigned long long int Pts = 0; subtitle_printf(10, "\n"); - while ( context->playback->isCreationPhase ) { - subtitle_err("Thread waiting for end of init phase...\n"); - usleep(1000); + while (context->playback->isCreationPhase) { + subtitle_err("Thread waiting for end of init phase...\n"); + usleep(1000); } subtitle_printf(10, "done\n"); - while ( context && - context->playback && - context->playback->isPlaying) { + while (context && context->playback && context->playback->isPlaying) { - int curtrackid = -1; - - if (context && context->manager && context->manager->subtitle) - context->manager->subtitle->Command(context, MANAGER_GET, &curtrackid); + int curtrackid = -1; - subtitle_printf(50, "curtrackid %d\n", curtrackid); + if (context && context->manager && context->manager->subtitle) + context->manager->subtitle->Command(context, MANAGER_GET, + &curtrackid); - if (curtrackid >= 0) { - if (getNextSub(&subText, &subPts, &subMilliDuration) != 0) { - usleep(500000); - continue; - } + subtitle_printf(50, "curtrackid %d\n", curtrackid); - if (context && context->playback) - context->playback->Command(context, PLAYBACK_PTS, &Pts); - else return NULL; + if (curtrackid >= 0) { + if (getNextSub(&subText, &subPts, &subMilliDuration) != 0) { + usleep(500000); + continue; + } - if(Pts > subPts) { - subtitle_printf(10,"subtitle is to late, ignoring\n"); - if(subText != NULL) - free(subText); - continue; - } + if (context && context->playback) + context->playback->Command(context, PLAYBACK_PTS, &Pts); + else + return NULL; - subtitle_printf(20, "Pts:%llu < subPts%llu duration %ld\n", Pts, subPts,subMilliDuration); + if (Pts > subPts) { + subtitle_printf(10, "subtitle is to late, ignoring\n"); + if (subText != NULL) + free(subText); + continue; + } - while ( context && - context->playback && - context->playback->isPlaying && - Pts < subPts) { + subtitle_printf(20, "Pts:%llu < subPts%llu duration %ld\n", + Pts, subPts, subMilliDuration); - unsigned long int diff = subPts - Pts; - diff = (diff*1000)/90.0; + while (context && + context->playback && + context->playback->isPlaying && Pts < subPts) { - subtitle_printf(50, "DIFF: %lud\n", diff); + unsigned long int diff = subPts - Pts; + diff = (diff * 1000) / 90.0; - if(diff > 100) - usleep(diff); + subtitle_printf(50, "DIFF: %lud\n", diff); - if (context && context->playback) - context->playback->Command(context, PLAYBACK_PTS, &Pts); - else - { - subtitle_err("no playback ? terminated?\n"); - break; - } - subtitle_printf(20, "cur: %llu wanted: %llu\n", Pts, subPts); - } + if (diff > 100) + usleep(diff); - if ( context && - context->playback && - context->playback->isPlaying && - subText != NULL ) { + if (context && context->playback) + context->playback->Command(context, PLAYBACK_PTS, + &Pts); + else { + subtitle_err("no playback ? terminated?\n"); + break; + } + subtitle_printf(20, "cur: %llu wanted: %llu\n", Pts, + subPts); + } - if(clientFunction != NULL) - clientFunction(subMilliDuration, strlen(subText), subText, clientData); - else - subtitle_printf(10, "writing Sub failed (%ld) (%d) \"%s\"\n", subMilliDuration, strlen(subText), subText); + if (context && + context->playback && + context->playback->isPlaying && subText != NULL) { - free(subText); - } + if (clientFunction != NULL) + clientFunction(subMilliDuration, strlen(subText), + subText, clientData); + else + subtitle_printf(10, + "writing Sub failed (%ld) (%d) \"%s\"\n", + subMilliDuration, strlen(subText), + subText); - } /* trackID >= 0 */ - else //Wait - usleep(500000); + free(subText); + } + + } /* trackID >= 0 */ + else //Wait + usleep(500000); + + } /* outer while */ - } /* outer while */ - subtitle_printf(0, "has ended\n"); - + hasThreadStarted = 0; - + return NULL; } @@ -519,74 +523,72 @@ static void* SubtitleThread(void* data) { /* Functions */ /* ***************************** */ -static int Write(void* _context, void *data) { - Context_t * context = (Context_t *) _context; - char * Encoding = NULL; - char * Text; - SubtitleOut_t * out; +static int Write(void *_context, void *data) +{ + Context_t *context = (Context_t *) _context; + char *Encoding = NULL; + char *Text; + SubtitleOut_t *out; int DataLength; unsigned long long int Pts; float Duration; - + subtitle_printf(10, "\n"); - if (data == NULL) - { - subtitle_err("null pointer passed\n"); - return cERR_SUBTITLE_ERROR; + if (data == NULL) { + subtitle_err("null pointer passed\n"); + return cERR_SUBTITLE_ERROR; } - out = (SubtitleOut_t*) data; - - if (out->type == eSub_Txt) - { - Text = strdup((const char*) out->u.text.data); - } else - { + out = (SubtitleOut_t *) data; + + if (out->type == eSub_Txt) { + Text = strdup((const char *) out->u.text.data); + } else { /* fixme handle gfx subs from container_ass and send it to * the callback. this must be implemented also in e2/neutrino * then. - */ - subtitle_err("subtitle gfx currently not handled\n"); - return cERR_SUBTITLE_ERROR; - } + */ + subtitle_err("subtitle gfx currently not handled\n"); + return cERR_SUBTITLE_ERROR; + } DataLength = out->u.text.len; Pts = out->pts; Duration = out->duration; - - context->manager->subtitle->Command(context, MANAGER_GETENCODING, &Encoding); - if (Encoding == NULL) - { - subtitle_err("encoding unknown\n"); - free(Text); - return cERR_SUBTITLE_ERROR; - } - - subtitle_printf(20, "Encoding:%s Text:%s Len:%d\n", Encoding,Text, DataLength); + context->manager->subtitle->Command(context, MANAGER_GETENCODING, + &Encoding); - if ( !strncmp("S_TEXT/SSA", Encoding, 10) || - !strncmp("S_SSA", Encoding, 5)) - subtitle_ParseSSA(&Text); - - else if(!strncmp("S_TEXT/ASS", Encoding, 10) || - !strncmp("S_AAS", Encoding, 5)) - subtitle_ParseASS(&Text); - - else if(!strncmp("S_TEXT/SRT", Encoding, 10) || - !strncmp("S_SRT", Encoding, 5)) - subtitle_ParseSRT(&Text); - else - { - subtitle_err("unknown encoding %s\n", Encoding); - return cERR_SUBTITLE_ERROR; + if (Encoding == NULL) { + subtitle_err("encoding unknown\n"); + free(Text); + return cERR_SUBTITLE_ERROR; } - - subtitle_printf(10, "Text:%s Duration:%f\n", Text,Duration); + + subtitle_printf(20, "Encoding:%s Text:%s Len:%d\n", Encoding, Text, + DataLength); + + if (!strncmp("S_TEXT/SSA", Encoding, 10) || + !strncmp("S_SSA", Encoding, 5)) + subtitle_ParseSSA(&Text); + + else if (!strncmp("S_TEXT/ASS", Encoding, 10) || + !strncmp("S_AAS", Encoding, 5)) + subtitle_ParseASS(&Text); + + else if (!strncmp("S_TEXT/SRT", Encoding, 10) || + !strncmp("S_SRT", Encoding, 5)) + subtitle_ParseSRT(&Text); + else { + subtitle_err("unknown encoding %s\n", Encoding); + return cERR_SUBTITLE_ERROR; + } + + subtitle_printf(10, "Text:%s Duration:%f\n", Text, Duration); addSub(context, Text, Pts, Duration * 1000); - + free(Text); free(Encoding); @@ -595,15 +597,15 @@ static int Write(void* _context, void *data) { return cERR_SUBTITLE_NO_ERROR; } -static int subtitle_Open(Context_t* context __attribute__((unused))) { +static int subtitle_Open(Context_t * context __attribute__ ((unused))) +{ int i; subtitle_printf(10, "\n"); - if (isSubtitleOpened == 1) - { - subtitle_err("already opened! ignoring\n"); - return cERR_SUBTITLE_ERROR; + if (isSubtitleOpened == 1) { + subtitle_err("already opened! ignoring\n"); + return cERR_SUBTITLE_ERROR; } getMutex(__LINE__); @@ -613,9 +615,9 @@ static int subtitle_Open(Context_t* context __attribute__((unused))) { writePointer = 0; for (i = 0; i < PUFFERSIZE; i++) { - subPuffer[i].text = NULL; - subPuffer[i].pts = 0; - subPuffer[i].milliDuration = 0; + subPuffer[i].text = NULL; + subPuffer[i].pts = 0; + subPuffer[i].milliDuration = 0; } isSubtitleOpened = 1; @@ -627,7 +629,8 @@ static int subtitle_Open(Context_t* context __attribute__((unused))) { return cERR_SUBTITLE_NO_ERROR; } -static int subtitle_Close(Context_t* context __attribute__((unused))) { +static int subtitle_Close(Context_t * context __attribute__ ((unused))) +{ int i; subtitle_printf(10, "\n"); @@ -639,12 +642,12 @@ static int subtitle_Close(Context_t* context __attribute__((unused))) { writePointer = 0; for (i = 0; i < PUFFERSIZE; i++) { - if (subPuffer[i].text != NULL) - free(subPuffer[i].text); + if (subPuffer[i].text != NULL) + free(subPuffer[i].text); - subPuffer[i].text = NULL; - subPuffer[i].pts = 0; - subPuffer[i].milliDuration = 0; + subPuffer[i].text = NULL; + subPuffer[i].pts = 0; + subPuffer[i].milliDuration = 0; } isSubtitleOpened = 0; @@ -656,31 +659,28 @@ static int subtitle_Close(Context_t* context __attribute__((unused))) { return cERR_SUBTITLE_NO_ERROR; } -static int subtitle_Play(Context_t* context) { +static int subtitle_Play(Context_t * context) +{ subtitle_printf(10, "\n"); - if (hasThreadStarted == 0) - { - pthread_attr_t attr; - - pthread_attr_init(&attr); - - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - - if (pthread_create (&thread_sub, &attr, &SubtitleThread, (void*) context) != 0) - { - subtitle_err("Error creating thread\n"); - hasThreadStarted = 0; - } else - { - subtitle_printf(10, "Created thread\n"); - hasThreadStarted = 1; - } - } - else - { - subtitle_err("thread already created.\n"); - return cERR_SUBTITLE_ERROR; + if (hasThreadStarted == 0) { + pthread_attr_t attr; + + pthread_attr_init(&attr); + + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + if (pthread_create + (&thread_sub, &attr, &SubtitleThread, (void *) context) != 0) { + subtitle_err("Error creating thread\n"); + hasThreadStarted = 0; + } else { + subtitle_printf(10, "Created thread\n"); + hasThreadStarted = 1; + } + } else { + subtitle_err("thread already created.\n"); + return cERR_SUBTITLE_ERROR; } subtitle_printf(10, "<\n"); @@ -688,23 +688,26 @@ static int subtitle_Play(Context_t* context) { return cERR_SUBTITLE_NO_ERROR; } -static int subtitle_Stop(Context_t* context __attribute__((unused))) { +static int subtitle_Stop(Context_t * context __attribute__ ((unused))) +{ int wait_time = 20; int i; - + subtitle_printf(10, "\n"); - while ( (hasThreadStarted != 0) && (--wait_time) > 0 ) { - subtitle_printf(10, "Waiting for subtitle thread to terminate itself, will try another %d times\n", wait_time); - usleep(100000); + while ((hasThreadStarted != 0) && (--wait_time) > 0) { + subtitle_printf(10, + "Waiting for subtitle thread to terminate itself, will try another %d times\n", + wait_time); + usleep(100000); } if (wait_time == 0) { - subtitle_err("Timeout waiting for thread!\n"); + subtitle_err("Timeout waiting for thread!\n"); - return cERR_SUBTITLE_ERROR; + return cERR_SUBTITLE_ERROR; } - + hasThreadStarted = 0; /* konfetti: thread has ended, so nobody will eat the date... @@ -718,12 +721,12 @@ static int subtitle_Stop(Context_t* context __attribute__((unused))) { writePointer = 0; for (i = 0; i < PUFFERSIZE; i++) { - if (subPuffer[i].text != NULL) - free(subPuffer[i].text); + if (subPuffer[i].text != NULL) + free(subPuffer[i].text); - subPuffer[i].text = NULL; - subPuffer[i].pts = 0; - subPuffer[i].milliDuration = 0; + subPuffer[i].text = NULL; + subPuffer[i].pts = 0; + subPuffer[i].milliDuration = 0; } releaseMutex(__LINE__); @@ -740,87 +743,88 @@ void subtitle_SignalConnect(void (*fkt) (long int, size_t, char *, void *)) clientFunction = fkt; } -void subtitle_SignalConnectBuffer(void* data) +void subtitle_SignalConnectBuffer(void *data) { subtitle_printf(10, "%p\n", data); clientData = data; } -static int Command(void *_context, OutputCmd_t command, void * argument) { - Context_t *context = (Context_t*) _context; +static int Command(void *_context, OutputCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; int ret = cERR_SUBTITLE_NO_ERROR; subtitle_printf(50, "%d\n", command); - switch(command) { - case OUTPUT_OPEN: { - ret = subtitle_Open(context); - break; - } - case OUTPUT_CLOSE: { - ret = subtitle_Close(context); - break; - } - case OUTPUT_PLAY: { - ret = subtitle_Play(context); - break; - } - case OUTPUT_STOP: { - ret = subtitle_Stop(context); - break; - } - case OUTPUT_SWITCH: { - subtitle_err("Subtitle Switch not implemented\n"); - ret = cERR_SUBTITLE_ERROR; - break; - } - case OUTPUT_GET_SUBTITLE_OUTPUT: { - SubtitleOutputDef_t* out = (SubtitleOutputDef_t*)argument; - out->screen_width = screen_width; - out->screen_height = screen_height; - out->framebufferBlit = framebufferBlit; - out->destination = destination; - out->destStride = destStride; - break; - } - case OUTPUT_SET_SUBTITLE_OUTPUT: { - SubtitleOutputDef_t* out = (SubtitleOutputDef_t*)argument; - screen_width = out->screen_width; - screen_height = out->screen_height; - framebufferBlit = out->framebufferBlit; - destination = out->destination; - destStride = out->destStride; - break; - } - case OUTPUT_SUBTITLE_REGISTER_FUNCTION: { - subtitle_SignalConnect(argument); - break; - } - case OUTPUT_SUBTITLE_REGISTER_BUFFER: { - subtitle_SignalConnectBuffer(argument); - break; - } - case OUTPUT_FLUSH: { - subtitle_err("Subtitle Flush not implemented\n"); - ret = cERR_SUBTITLE_ERROR; - break; - } - case OUTPUT_PAUSE: { - subtitle_err("Subtitle Pause not implemented\n"); - ret = cERR_SUBTITLE_ERROR; - break; - } - case OUTPUT_CONTINUE: { - subtitle_err("Subtitle Continue not implemented\n"); - ret = cERR_SUBTITLE_ERROR; - break; - } + switch (command) { + case OUTPUT_OPEN:{ + ret = subtitle_Open(context); + break; + } + case OUTPUT_CLOSE:{ + ret = subtitle_Close(context); + break; + } + case OUTPUT_PLAY:{ + ret = subtitle_Play(context); + break; + } + case OUTPUT_STOP:{ + ret = subtitle_Stop(context); + break; + } + case OUTPUT_SWITCH:{ + subtitle_err("Subtitle Switch not implemented\n"); + ret = cERR_SUBTITLE_ERROR; + break; + } + case OUTPUT_GET_SUBTITLE_OUTPUT:{ + SubtitleOutputDef_t *out = (SubtitleOutputDef_t *) argument; + out->screen_width = screen_width; + out->screen_height = screen_height; + out->framebufferBlit = framebufferBlit; + out->destination = destination; + out->destStride = destStride; + break; + } + case OUTPUT_SET_SUBTITLE_OUTPUT:{ + SubtitleOutputDef_t *out = (SubtitleOutputDef_t *) argument; + screen_width = out->screen_width; + screen_height = out->screen_height; + framebufferBlit = out->framebufferBlit; + destination = out->destination; + destStride = out->destStride; + break; + } + case OUTPUT_SUBTITLE_REGISTER_FUNCTION:{ + subtitle_SignalConnect(argument); + break; + } + case OUTPUT_SUBTITLE_REGISTER_BUFFER:{ + subtitle_SignalConnectBuffer(argument); + break; + } + case OUTPUT_FLUSH:{ + subtitle_err("Subtitle Flush not implemented\n"); + ret = cERR_SUBTITLE_ERROR; + break; + } + case OUTPUT_PAUSE:{ + subtitle_err("Subtitle Pause not implemented\n"); + ret = cERR_SUBTITLE_ERROR; + break; + } + case OUTPUT_CONTINUE:{ + subtitle_err("Subtitle Continue not implemented\n"); + ret = cERR_SUBTITLE_ERROR; + break; + } default: - subtitle_err("OutputCmd %d not supported!\n", command); - ret = cERR_SUBTITLE_ERROR; - break; + subtitle_err("OutputCmd %d not supported!\n", command); + ret = cERR_SUBTITLE_ERROR; + break; } subtitle_printf(50, "exiting with value %d\n", ret); diff --git a/libeplayer3/output/writer/aac.c b/libeplayer3/output/writer/aac.c index 1b20fdc..381eddd 100644 --- a/libeplayer3/output/writer/aac.c +++ b/libeplayer3/output/writer/aac.c @@ -190,11 +190,12 @@ else */ -static unsigned char DefaultAACHeader[] = { +static unsigned char DefaultAACHeader[] = { 0xff, 0xf1, - /*0x00, 0x00*/0x50, //((Profile & 0x03) << 6) | (SampleIndex << 2) | ((Channels >> 2) & 0x01);s - 0x80, //(Channels & 0x03) << 6; + /*0x00, 0x00 */ 0x50, + //((Profile & 0x03) << 6) | (SampleIndex << 2) | ((Channels >> 2) & 0x01);s + 0x80, //(Channels & 0x03) << 6; 0x00, 0x1f, 0xfc @@ -212,51 +213,48 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; unsigned char PesHeader[PES_MAX_HEADER_SIZE]; unsigned char ExtraData[AAC_HEADER_LENGTH]; - unsigned int PacketLength; + unsigned int PacketLength; aac_printf(10, "\n"); - if (call == NULL) - { - aac_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + aac_err("call data is NULL...\n"); + return 0; } aac_printf(10, "AudioPts %lld\n", call->Pts); - PacketLength = call->len + AAC_HEADER_LENGTH; + PacketLength = call->len + AAC_HEADER_LENGTH; - if ((call->data == NULL) || (call->len <= 0)) - { - aac_err("parsing NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + aac_err("parsing NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - aac_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + aac_err("file pointer < 0. ignoring ...\n"); + return 0; } - if (call->private_data == NULL) - { - aac_printf(10, "private_data = NULL\n"); - memcpy (ExtraData, DefaultAACHeader, AAC_HEADER_LENGTH); - } - else - memcpy (ExtraData, call->private_data, AAC_HEADER_LENGTH); + if (call->private_data == NULL) { + aac_printf(10, "private_data = NULL\n"); + memcpy(ExtraData, DefaultAACHeader, AAC_HEADER_LENGTH); + } else + memcpy(ExtraData, call->private_data, AAC_HEADER_LENGTH); - ExtraData[3] |= (PacketLength >> 11) & 0x3; - ExtraData[4] = (PacketLength >> 3) & 0xff; - ExtraData[5] |= (PacketLength << 5) & 0xe0; + ExtraData[3] |= (PacketLength >> 11) & 0x3; + ExtraData[4] = (PacketLength >> 3) & 0xff; + ExtraData[5] |= (PacketLength << 5) & 0xe0; - unsigned int HeaderLength = InsertPesHeader (PesHeader, PacketLength, AAC_AUDIO_PES_START_CODE, call->Pts, 0); + unsigned int HeaderLength = + InsertPesHeader(PesHeader, PacketLength, AAC_AUDIO_PES_START_CODE, + call->Pts, 0); struct iovec iov[3]; iov[0].iov_base = PesHeader; diff --git a/libeplayer3/output/writer/ac3.c b/libeplayer3/output/writer/ac3.c index a2e062b..6675084 100644 --- a/libeplayer3/output/writer/ac3.c +++ b/libeplayer3/output/writer/ac3.c @@ -92,38 +92,37 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; ac3_printf(10, "\n"); - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; - if (call == NULL) - { - ac3_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + ac3_err("call data is NULL...\n"); + return 0; } ac3_printf(10, "AudioPts %lld\n", call->Pts); - if ((call->data == NULL) || (call->len <= 0)) - { - ac3_err("parsing NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + ac3_err("parsing NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - ac3_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + ac3_err("file pointer < 0. ignoring ...\n"); + return 0; } struct iovec iov[2]; iov[0].iov_base = PesHeader; - iov[0].iov_len = InsertPesHeader (PesHeader, call->len, PRIVATE_STREAM_1_PES_START_CODE, call->Pts, 0); + iov[0].iov_len = + InsertPesHeader(PesHeader, call->len, + PRIVATE_STREAM_1_PES_START_CODE, call->Pts, 0); iov[1].iov_base = call->data; iov[1].iov_len = call->len; diff --git a/libeplayer3/output/writer/divx.c b/libeplayer3/output/writer/divx.c index dd84612..8199f84 100644 --- a/libeplayer3/output/writer/divx.c +++ b/libeplayer3/output/writer/divx.c @@ -92,38 +92,34 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; - unsigned char FakeHeaders[64]; // 64bytes should be enough to make the fake headers - unsigned int FakeHeaderLength; - unsigned char Version = 5; - unsigned int FakeStartCode = (Version << 8) | PES_VERSION_FAKE_START_CODE; - unsigned int usecPerFrame = 41708; /* Hellmaster1024: default value */ - BitPacker_t ld = {FakeHeaders, 0, 32}; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + unsigned char FakeHeaders[64]; // 64bytes should be enough to make the fake headers + unsigned int FakeHeaderLength; + unsigned char Version = 5; + unsigned int FakeStartCode = + (Version << 8) | PES_VERSION_FAKE_START_CODE; + unsigned int usecPerFrame = 41708; /* Hellmaster1024: default value */ + BitPacker_t ld = { FakeHeaders, 0, 32 }; divx_printf(10, "\n"); - if (call == NULL) - { - divx_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + divx_err("call data is NULL...\n"); + return 0; } - divx_printf(10, "AudioPts %lld\n", call->Pts); - - if ((call->data == NULL) || (call->len <= 0)) - { - divx_err("parsing NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + divx_err("parsing NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - divx_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + divx_err("file pointer < 0. ignoring ...\n"); + return 0; } usecPerFrame = 1000000000 / call->FrameRate; @@ -137,27 +133,30 @@ static int writeData(void* _call) PutBits(&ld, 0x0, 8); PutBits(&ld, 0x0, 8); */ - PutBits(&ld, 0x1b0, 32); // startcode - PutBits(&ld, 0, 8); // profile = reserved - PutBits(&ld, 0x1b2, 32); // startcode (user data) - PutBits(&ld, 0x53545443, 32); // STTC - an embedded ST timecode from an avi file - PutBits(&ld, usecPerFrame , 32); + PutBits(&ld, 0x1b0, 32); // startcode + PutBits(&ld, 0, 8); // profile = reserved + PutBits(&ld, 0x1b2, 32); // startcode (user data) + PutBits(&ld, 0x53545443, 32); // STTC - an embedded ST timecode from an avi file + PutBits(&ld, usecPerFrame, 32); // microseconds per frame FlushBits(&ld); - FakeHeaderLength = (ld.Ptr - (FakeHeaders)); + FakeHeaderLength = (ld.Ptr - (FakeHeaders)); struct iovec iov[4]; int ic = 0; iov[ic].iov_base = PesHeader; - iov[ic++].iov_len = InsertPesHeader (PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, FakeStartCode); + iov[ic++].iov_len = + InsertPesHeader(PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, + call->Pts, FakeStartCode); iov[ic].iov_base = FakeHeaders; iov[ic++].iov_len = FakeHeaderLength; if (initialHeader) { iov[ic].iov_base = call->private_data; iov[ic++].iov_len = call->private_size; - initialHeader = 0; + + initialHeader = 0; } iov[ic].iov_base = call->data; iov[ic++].iov_len = call->len; diff --git a/libeplayer3/output/writer/dts.c b/libeplayer3/output/writer/dts.c index 1de496f..1496902 100644 --- a/libeplayer3/output/writer/dts.c +++ b/libeplayer3/output/writer/dts.c @@ -50,10 +50,10 @@ /* ***************************** */ /* Makros/Constants */ /* ***************************** */ -#define PES_AUDIO_PRIVATE_HEADER_SIZE 16 // consider maximum private header size. +#define PES_AUDIO_PRIVATE_HEADER_SIZE 16 // consider maximum private header size. #define PES_AUDIO_HEADER_SIZE (32 + PES_AUDIO_PRIVATE_HEADER_SIZE) #define PES_AUDIO_PACKET_SIZE 2028 -#define SPDIF_AUDIO_PACKET_SIZE (1024 * sizeof(unsigned int) * 2) // stereo 32bit samples. +#define SPDIF_AUDIO_PACKET_SIZE (1024 * sizeof(unsigned int) * 2) // stereo 32bit samples. #define DTS_DEBUG @@ -94,52 +94,51 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; - unsigned char PesHeader[PES_AUDIO_HEADER_SIZE]; + unsigned char PesHeader[PES_AUDIO_HEADER_SIZE]; dts_printf(10, "\n"); - if (call == NULL) - { - dts_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + dts_err("call data is NULL...\n"); + return 0; } dts_printf(10, "AudioPts %lld\n", call->Pts); - if ((call->data == NULL) || (call->len <= 0)) - { - dts_err("parsing NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + dts_err("parsing NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - dts_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + dts_err("file pointer < 0. ignoring ...\n"); + return 0; } - // #define DO_BYTESWAP #ifdef DO_BYTESWAP unsigned char *Data = (unsigned char *) malloc(call->len); memcpy(Data, call->data, call->len); /* 16-bit byte swap all data before injecting it */ - for (i=0; i< call->len; i+=2) - { - unsigned char Tmp = Data[i]; - Data[i] = Data[i+1]; - Data[i+1] = Tmp; + for (i = 0; i < call->len; i += 2) { + unsigned char Tmp = Data[i]; + Data[i] = Data[i + 1]; + Data[i + 1] = Tmp; } #endif struct iovec iov[2]; iov[0].iov_base = PesHeader; - iov[0].iov_len = InsertPesHeader (PesHeader, call->len, MPEG_AUDIO_PES_START_CODE/*PRIVATE_STREAM_1_PES_START_CODE*/, call->Pts, 0); + iov[0].iov_len = + InsertPesHeader(PesHeader, call->len, + MPEG_AUDIO_PES_START_CODE + /*PRIVATE_STREAM_1_PES_START_CODE */ , call->Pts, + 0); #ifdef DO_BYTESPWAP iov[1].iov_base = Data; #else diff --git a/libeplayer3/output/writer/flac.c b/libeplayer3/output/writer/flac.c index 4585d12..bd0f6b1 100644 --- a/libeplayer3/output/writer/flac.c +++ b/libeplayer3/output/writer/flac.c @@ -90,37 +90,36 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; flac_printf(10, "\n"); - if (call == NULL) - { - flac_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + flac_err("call data is NULL...\n"); + return 0; } flac_printf(10, "AudioPts %lld\n", call->Pts); - if ((call->data == NULL) || (call->len <= 0)) - { - flac_err("parsing NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + flac_err("parsing NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - flac_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + flac_err("file pointer < 0. ignoring ...\n"); + return 0; } struct iovec iov[2]; iov[0].iov_base = PesHeader; - iov[0].iov_len = InsertPesHeader (PesHeader, call->len , MPEG_AUDIO_PES_START_CODE, call->Pts, 0); + iov[0].iov_len = + InsertPesHeader(PesHeader, call->len, MPEG_AUDIO_PES_START_CODE, + call->Pts, 0); iov[1].iov_base = call->data; iov[1].iov_len = call->len; @@ -138,7 +137,7 @@ static WriterCaps_t caps_flac = { "flac", eAudio, "A_FLAC", - AUDIO_ENCODING_LPCM //AUDIO_ENCODING_FLAC + AUDIO_ENCODING_LPCM //AUDIO_ENCODING_FLAC }; struct Writer_s WriterAudioFLAC = { diff --git a/libeplayer3/output/writer/framebuffer.c b/libeplayer3/output/writer/framebuffer.c index 738fb6e..c136271 100644 --- a/libeplayer3/output/writer/framebuffer.c +++ b/libeplayer3/output/writer/framebuffer.c @@ -96,95 +96,93 @@ if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x); static int reset() { - return 0; + return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - int res = 0; + int res = 0; - WriterFBCallData_t* call = (WriterFBCallData_t*) _call; + WriterFBCallData_t *call = (WriterFBCallData_t *) _call; - fb_printf(100, "\n"); + fb_printf(100, "\n"); - if (!call) - { - fb_err("call data is NULL...\n"); - return 0; + if (!call) { + fb_err("call data is NULL...\n"); + return 0; + } + + if (!call->destination) { + fb_err("frame buffer == NULL. ignoring ...\n"); + return 0; + } + + int dst_stride = call->destStride / sizeof(uint32_t); + int dst_delta = dst_stride - call->Width; + uint32_t *dst = call->destination + call->y * dst_stride + call->x; + + if (call->data) { + int src_delta = call->Stride - call->Width; + unsigned char *src = call->data; + static uint32_t last_color = 0, colortable[256]; + + if (last_color != call->color) { + // call->color is rgba, our spark frame buffer is argb + uint32_t c = call->color >> 8, a = 255 - (call->color & 0xff); + int i; + for (i = 0; i < 256; i++) { + uint32_t k = (a * i) >> 8; + colortable[i] = k ? (c | (k << 24)) : 0; + } + last_color = call->color; } - if (!call->destination) - { - fb_err("frame buffer == NULL. ignoring ...\n"); - return 0; + fb_printf(100, "x %d\n", call->x); + fb_printf(100, "y %d\n", call->y); + fb_printf(100, "width %d\n", call->Width); + fb_printf(100, "height %d\n", call->Height); + fb_printf(100, "stride %d\n", call->Stride); + fb_printf(100, "color 0x%.8x\n", call->color); + fb_printf(100, "data %p\n", call->data); + fb_printf(100, "dest %p\n", call->destination); + fb_printf(100, "dest.stride %d\n", call->destStride); + + unsigned char *src_final = src + call->Height * call->Width; + for (; src < src_final; dst += dst_delta, src += src_delta) { + u_char *src_end = src + call->Width; + for (; src < src_end; dst++, src++) { + uint32_t c = colortable[*src]; + if (c) + *dst = c; + } } - - int dst_stride = call->destStride/sizeof(uint32_t); - int dst_delta = dst_stride - call->Width; - uint32_t *dst = call->destination + call->y * dst_stride + call->x; - - if (call->data) - { - int src_delta = call->Stride - call->Width; - unsigned char *src = call->data; - static uint32_t last_color = 0, colortable[256]; - - if (last_color != call->color) { - // call->color is rgba, our spark frame buffer is argb - uint32_t c = call->color >> 8, a = 255 - (call->color & 0xff); - int i; - for (i = 0; i < 256; i++) { - uint32_t k = (a * i) >> 8; - colortable[i] = k ? (c | (k << 24)) : 0; - } - last_color = call->color; - } - - fb_printf(100, "x %d\n", call->x); - fb_printf(100, "y %d\n", call->y); - fb_printf(100, "width %d\n", call->Width); - fb_printf(100, "height %d\n", call->Height); - fb_printf(100, "stride %d\n", call->Stride); - fb_printf(100, "color 0x%.8x\n", call->color); - fb_printf(100, "data %p\n", call->data); - fb_printf(100, "dest %p\n", call->destination); - fb_printf(100, "dest.stride %d\n", call->destStride); - - unsigned char *src_final = src + call->Height * call->Width; - for (; src < src_final; dst += dst_delta, src += src_delta) { - u_char *src_end = src + call->Width; - for (; src < src_end; dst++, src++) { - uint32_t c = colortable[*src]; - if (c) - *dst = c; - } - } - } else { - uint32_t *dst_final = dst + call->Width + call->Height * dst_stride; - for (; dst < dst_final; dst += dst_delta) { - uint32_t *dst_end = dst + call->Width; - for (; dst < dst_end; dst++) - *dst = 0; - } + } else { + uint32_t *dst_final = + dst + call->Width + call->Height * dst_stride; + for (; dst < dst_final; dst += dst_delta) { + uint32_t *dst_end = dst + call->Width; + for (; dst < dst_end; dst++) + *dst = 0; } + } - fb_printf(100, "< %d\n", res); - return res; + fb_printf(100, "< %d\n", res); + return res; } /* ***************************** */ /* Writer Definition */ /* ***************************** */ static WriterCaps_t caps = { - "framebuffer", - eGfx, - "framebuffer", - 0 + "framebuffer", + eGfx, + "framebuffer", + 0 }; struct Writer_s WriterFramebuffer = { - &reset, - &writeData, - NULL, - &caps + &reset, + &writeData, + NULL, + &caps }; diff --git a/libeplayer3/output/writer/h263.c b/libeplayer3/output/writer/h263.c index f3eeed1..d109877 100644 --- a/libeplayer3/output/writer/h263.c +++ b/libeplayer3/output/writer/h263.c @@ -89,47 +89,49 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; unsigned char PesHeader[PES_MAX_HEADER_SIZE]; int len = 0; h263_printf(10, "\n"); - if (call == NULL) - { - h263_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + h263_err("call data is NULL...\n"); + return 0; } h263_printf(10, "VideoPts %lld\n", call->Pts); - if ((call->data == NULL) || (call->len <= 0)) - { - h263_err("NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + h263_err("NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - h263_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + h263_err("file pointer < 0. ignoring ...\n"); + return 0; } - int HeaderLength = InsertPesHeader(PesHeader, call->len, H263_VIDEO_PES_START_CODE, call->Pts,0); + int HeaderLength = + InsertPesHeader(PesHeader, call->len, H263_VIDEO_PES_START_CODE, + call->Pts, 0); - int PrivateHeaderLength = InsertVideoPrivateDataHeader (&PesHeader[HeaderLength], call->len); + int PrivateHeaderLength = + InsertVideoPrivateDataHeader(&PesHeader[HeaderLength], call->len); - int PesLength = PesHeader[PES_LENGTH_BYTE_0] + (PesHeader[PES_LENGTH_BYTE_1] << 8) + PrivateHeaderLength; + int PesLength = + PesHeader[PES_LENGTH_BYTE_0] + + (PesHeader[PES_LENGTH_BYTE_1] << 8) + PrivateHeaderLength; - PesHeader[PES_LENGTH_BYTE_0] = PesLength & 0xff; - PesHeader[PES_LENGTH_BYTE_1] = (PesLength >> 8) & 0xff; + PesHeader[PES_LENGTH_BYTE_0] = PesLength & 0xff; + PesHeader[PES_LENGTH_BYTE_1] = (PesLength >> 8) & 0xff; PesHeader[PES_HEADER_DATA_LENGTH_BYTE] += PrivateHeaderLength; - PesHeader[PES_FLAGS_BYTE] |= PES_EXTENSION_DATA_PRESENT; + PesHeader[PES_FLAGS_BYTE] |= PES_EXTENSION_DATA_PRESENT; - HeaderLength += PrivateHeaderLength; + HeaderLength += PrivateHeaderLength; struct iovec iov[2]; iov[0].iov_base = PesHeader; diff --git a/libeplayer3/output/writer/h264.c b/libeplayer3/output/writer/h264.c index 6731111..f76f4a6 100644 --- a/libeplayer3/output/writer/h264.c +++ b/libeplayer3/output/writer/h264.c @@ -76,24 +76,24 @@ if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x); /* ***************************** */ /* Types */ /* ***************************** */ -typedef struct avcC_s -{ - unsigned char Version; /* configurationVersion */ - unsigned char Profile; /* AVCProfileIndication */ - unsigned char Compatibility; /* profile_compatibility */ - unsigned char Level; /* AVCLevelIndication */ - unsigned char NalLengthMinusOne; /* held in bottom two bits */ - unsigned char NumParamSets; /* held in bottom 5 bits */ - unsigned char Params[1]; /* {length,params}{length,params}...sequence then picture*/ +typedef struct avcC_s { + unsigned char Version; /* configurationVersion */ + unsigned char Profile; /* AVCProfileIndication */ + unsigned char Compatibility; /* profile_compatibility */ + unsigned char Level; /* AVCLevelIndication */ + unsigned char NalLengthMinusOne; /* held in bottom two bits */ + unsigned char NumParamSets; /* held in bottom 5 bits */ + unsigned char Params[1]; /* {length,params}{length,params}...sequence then picture */ } avcC_t; /* ***************************** */ /* Varaibles */ /* ***************************** */ -const unsigned char Head[] = {0, 0, 0, 1}; +const unsigned char Head[] = { 0, 0, 0, 1 }; + static int initialHeader = 1; -static unsigned int NalLengthBytes = 1; +static unsigned int NalLengthBytes = 1; /* ***************************** */ /* Prototypes */ @@ -109,271 +109,309 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; - unsigned long long int VideoPts; - unsigned int TimeDelta; - unsigned int TimeScale; - int len = 0; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + unsigned long long int VideoPts; + unsigned int TimeDelta; + unsigned int TimeScale; + int len = 0; int ic = 0; struct iovec iov[128]; h264_printf(10, "\n"); - if (call == NULL) - { - h264_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + h264_err("call data is NULL...\n"); + return 0; } TimeDelta = call->FrameRate; TimeScale = call->FrameScale; - VideoPts = call->Pts; + VideoPts = call->Pts; - h264_printf(10, "VideoPts %lld - %d %d\n", call->Pts, TimeDelta, TimeScale); + h264_printf(10, "VideoPts %lld - %d %d\n", call->Pts, TimeDelta, + TimeScale); - if ((call->data == NULL) || (call->len <= 0)) - { - h264_err("NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + h264_err("NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - h264_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + h264_err("file pointer < 0. ignoring ...\n"); + return 0; } - if((call->len > 3) && ((call->data[0] == 0x00 && call->data[1] == 0x00 && call->data[2] == 0x00 && call->data[3] == 0x01) || - (call->data[0] == 0xff && call->data[1] == 0xff && call->data[2] == 0xff && call->data[3] == 0xff))) - { + if ((call->len > 3) + && + ((call->data[0] == 0x00 && call->data[1] == 0x00 + && call->data[2] == 0x00 && call->data[3] == 0x01) + || (call->data[0] == 0xff && call->data[1] == 0xff + && call->data[2] == 0xff && call->data[3] == 0xff))) { unsigned int PacketLength = 0; - unsigned int FakeStartCode = (call->Version << 8) | PES_VERSION_FAKE_START_CODE; + unsigned int FakeStartCode = + (call->Version << 8) | PES_VERSION_FAKE_START_CODE; iov[ic++].iov_base = PesHeader; if (initialHeader) { - initialHeader = 0; - iov[ic].iov_base = call->private_data; - iov[ic++].iov_len = call->private_size; - PacketLength += call->private_size; + initialHeader = 0; + iov[ic].iov_base = call->private_data; + iov[ic++].iov_len = call->private_size; + PacketLength += call->private_size; } iov[ic].iov_base = call->data; iov[ic++].iov_len = call->len; PacketLength += call->len; - /*Hellmaster1024: some packets will only be accepted by the player if we send one byte more than - data is available. The content of this byte does not matter. It will be ignored - by the player */ + /*Hellmaster1024: some packets will only be accepted by the player if we send one byte more than + data is available. The content of this byte does not matter. It will be ignored + by the player */ iov[ic].iov_base = ""; iov[ic++].iov_len = 1; - iov[0].iov_len = InsertPesHeader(PesHeader, PacketLength, MPEG_VIDEO_PES_START_CODE, call->Pts, FakeStartCode); + iov[0].iov_len = + InsertPesHeader(PesHeader, PacketLength, + MPEG_VIDEO_PES_START_CODE, call->Pts, + FakeStartCode); return writev(call->fd, iov, ic); } - if (initialHeader) - { - avcC_t* avcCHeader = (avcC_t*)call->private_data; - unsigned int i; - unsigned int ParamSets; - unsigned int ParamOffset; - unsigned int InitialHeaderLength = 0; - unsigned int ParametersLength; + if (initialHeader) { + avcC_t *avcCHeader = (avcC_t *) call->private_data; + unsigned int i; + unsigned int ParamSets; + unsigned int ParamOffset; + unsigned int InitialHeaderLength = 0; + unsigned int ParametersLength; - if (avcCHeader == NULL) { - h264_err("private_data NULL\n"); - return -1; - } + if (avcCHeader == NULL) { + h264_err("private_data NULL\n"); + return -1; + } - if (avcCHeader->Version != 1) - h264_err("Error unknown avcC version (%x). Expect problems.\n", avcCHeader->Version); + if (avcCHeader->Version != 1) + h264_err("Error unknown avcC version (%x). Expect problems.\n", + avcCHeader->Version); - ParametersLength = 0; + ParametersLength = 0; - unsigned char HeaderData[19]; - HeaderData[ParametersLength++] = 0x00; // Start code - HeaderData[ParametersLength++] = 0x00; - HeaderData[ParametersLength++] = 0x01; - HeaderData[ParametersLength++] = NALU_TYPE_PLAYER2_CONTAINER_PARAMETERS; - // Container message version - changes when/if we vary the format of the message - HeaderData[ParametersLength++] = CONTAINER_PARAMETERS_VERSION; - HeaderData[ParametersLength++] = 0xff; // Field separator + unsigned char HeaderData[19]; + HeaderData[ParametersLength++] = 0x00; // Start code + HeaderData[ParametersLength++] = 0x00; + HeaderData[ParametersLength++] = 0x01; + HeaderData[ParametersLength++] = + NALU_TYPE_PLAYER2_CONTAINER_PARAMETERS; + // Container message version - changes when/if we vary the format of the message + HeaderData[ParametersLength++] = CONTAINER_PARAMETERS_VERSION; + HeaderData[ParametersLength++] = 0xff; // Field separator - if( TimeDelta == 0xffffffff ) - TimeDelta = (TimeScale > 1000) ? 1001 : 1; + if (TimeDelta == 0xffffffff) + TimeDelta = (TimeScale > 1000) ? 1001 : 1; - HeaderData[ParametersLength++] = (TimeScale >> 24) & 0xff; // Output the timescale - HeaderData[ParametersLength++] = (TimeScale >> 16) & 0xff; - HeaderData[ParametersLength++] = 0xff; - HeaderData[ParametersLength++] = (TimeScale >> 8) & 0xff; - HeaderData[ParametersLength++] = TimeScale & 0xff; - HeaderData[ParametersLength++] = 0xff; + HeaderData[ParametersLength++] = (TimeScale >> 24) & 0xff; // Output the timescale + HeaderData[ParametersLength++] = (TimeScale >> 16) & 0xff; + HeaderData[ParametersLength++] = 0xff; + HeaderData[ParametersLength++] = (TimeScale >> 8) & 0xff; + HeaderData[ParametersLength++] = TimeScale & 0xff; + HeaderData[ParametersLength++] = 0xff; - HeaderData[ParametersLength++] = (TimeDelta >> 24) & 0xff; // Output frame period - HeaderData[ParametersLength++] = (TimeDelta >> 16) & 0xff; - HeaderData[ParametersLength++] = 0xff; - HeaderData[ParametersLength++] = (TimeDelta >> 8) & 0xff; - HeaderData[ParametersLength++] = TimeDelta & 0xff; - HeaderData[ParametersLength++] = 0xff; - HeaderData[ParametersLength++] = 0x80; // Rsbp trailing bits + HeaderData[ParametersLength++] = (TimeDelta >> 24) & 0xff; // Output frame period + HeaderData[ParametersLength++] = (TimeDelta >> 16) & 0xff; + HeaderData[ParametersLength++] = 0xff; + HeaderData[ParametersLength++] = (TimeDelta >> 8) & 0xff; + HeaderData[ParametersLength++] = TimeDelta & 0xff; + HeaderData[ParametersLength++] = 0xff; + HeaderData[ParametersLength++] = 0x80; // Rsbp trailing bits assert(ParametersLength <= sizeof(HeaderData)); ic = 0; iov[ic].iov_base = PesHeader; - iov[ic++].iov_len = InsertPesHeader (PesHeader, ParametersLength, MPEG_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0); + iov[ic++].iov_len = + InsertPesHeader(PesHeader, ParametersLength, + MPEG_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, + 0); iov[ic].iov_base = HeaderData; iov[ic++].iov_len = ParametersLength; len = writev(call->fd, iov, ic); if (len < 0) - return len; + return len; - NalLengthBytes = (avcCHeader->NalLengthMinusOne & 0x03) + 1; - ParamSets = avcCHeader->NumParamSets & 0x1f; + NalLengthBytes = (avcCHeader->NalLengthMinusOne & 0x03) + 1; + ParamSets = avcCHeader->NumParamSets & 0x1f; - h264_printf(20, "avcC contents:\n"); - h264_printf(20, " version: %d\n", avcCHeader->Version); - h264_printf(20, " profile: %d\n", avcCHeader->Profile); - h264_printf(20, " profile compatibility: %d\n", avcCHeader->Compatibility); - h264_printf(20, " level: %d\n", avcCHeader->Level); - h264_printf(20, " nal length bytes: %d\n", NalLengthBytes); - h264_printf(20, " number of sequence param sets: %d\n", ParamSets); + h264_printf(20, "avcC contents:\n"); + h264_printf(20, " version: %d\n", + avcCHeader->Version); + h264_printf(20, " profile: %d\n", + avcCHeader->Profile); + h264_printf(20, " profile compatibility: %d\n", + avcCHeader->Compatibility); + h264_printf(20, " level: %d\n", + avcCHeader->Level); + h264_printf(20, " nal length bytes: %d\n", + NalLengthBytes); + h264_printf(20, " number of sequence param sets: %d\n", + ParamSets); - ParamOffset = 0; + ParamOffset = 0; ic = 0; iov[ic++].iov_base = PesHeader; - for (i = 0; i < ParamSets; i++) { - unsigned int PsLength = (avcCHeader->Params[ParamOffset] << 8) + avcCHeader->Params[ParamOffset+1]; + for (i = 0; i < ParamSets; i++) { + unsigned int PsLength = + (avcCHeader->Params[ParamOffset] << 8) + + avcCHeader->Params[ParamOffset + 1]; - h264_printf(20, " sps %d has length %d\n", i, PsLength); - - iov[ic].iov_base = (char *)Head; - iov[ic++].iov_len = sizeof(Head); - InitialHeaderLength += sizeof(Head); - iov[ic].iov_base = &avcCHeader->Params[ParamOffset+2]; - iov[ic++].iov_len = PsLength; - InitialHeaderLength += PsLength; - ParamOffset += PsLength+2; - } - - ParamSets = avcCHeader->Params[ParamOffset]; - - h264_printf(20, " number of picture param sets: %d\n", ParamSets); - - ParamOffset++; - for (i = 0; i < ParamSets; i++) { - unsigned int PsLength = (avcCHeader->Params[ParamOffset] << 8) + avcCHeader->Params[ParamOffset+1]; - - h264_printf (20, " pps %d has length %d\n", i, PsLength); + h264_printf(20, " sps %d has length %d\n", i, + PsLength); iov[ic].iov_base = (char *) Head; iov[ic++].iov_len = sizeof(Head); - InitialHeaderLength += sizeof(Head); - iov[ic].iov_base = &avcCHeader->Params[ParamOffset+2]; + InitialHeaderLength += sizeof(Head); + iov[ic].iov_base = &avcCHeader->Params[ParamOffset + 2]; iov[ic++].iov_len = PsLength; - InitialHeaderLength += PsLength; - ParamOffset += PsLength+2; - } + InitialHeaderLength += PsLength; + ParamOffset += PsLength + 2; + } - iov[0].iov_len = InsertPesHeader (PesHeader, InitialHeaderLength, MPEG_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0); + ParamSets = avcCHeader->Params[ParamOffset]; + + h264_printf(20, " number of picture param sets: %d\n", + ParamSets); + + ParamOffset++; + for (i = 0; i < ParamSets; i++) { + unsigned int PsLength = + (avcCHeader->Params[ParamOffset] << 8) + + avcCHeader->Params[ParamOffset + 1]; + + h264_printf(20, " pps %d has length %d\n", i, + PsLength); + + iov[ic].iov_base = (char *) Head; + iov[ic++].iov_len = sizeof(Head); + InitialHeaderLength += sizeof(Head); + iov[ic].iov_base = &avcCHeader->Params[ParamOffset + 2]; + iov[ic++].iov_len = PsLength; + InitialHeaderLength += PsLength; + ParamOffset += PsLength + 2; + } + + iov[0].iov_len = + InsertPesHeader(PesHeader, InitialHeaderLength, + MPEG_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, + 0); ssize_t l = writev(call->fd, iov, ic); if (l < 0) - return l; + return l; len += l; - initialHeader = 0; + initialHeader = 0; } - unsigned int SampleSize = call->len; - unsigned int NalStart = 0; + unsigned int SampleSize = call->len; + unsigned int NalStart = 0; unsigned int VideoPosition = 0; do { - unsigned int NalLength; - unsigned char NalData[4]; - int NalPresent = 1; + unsigned int NalLength; + unsigned char NalData[4]; + int NalPresent = 1; - memcpy (NalData, call->data + VideoPosition, NalLengthBytes); - VideoPosition += NalLengthBytes; - NalStart += NalLengthBytes; - switch(NalLengthBytes) { - case 1: NalLength = (NalData[0]); break; - case 2: NalLength = (NalData[0] << 8) | (NalData[1]); break; - case 3: NalLength = (NalData[0] << 16) | (NalData[1] << 8) | (NalData[2]); break; - default: NalLength = (NalData[0] << 24) | (NalData[1] << 16) | (NalData[2] << 8) | (NalData[3]); break; - } + memcpy(NalData, call->data + VideoPosition, NalLengthBytes); + VideoPosition += NalLengthBytes; + NalStart += NalLengthBytes; + switch (NalLengthBytes) { + case 1: + NalLength = (NalData[0]); + break; + case 2: + NalLength = (NalData[0] << 8) | (NalData[1]); + break; + case 3: + NalLength = + (NalData[0] << 16) | (NalData[1] << 8) | (NalData[2]); + break; + default: + NalLength = + (NalData[0] << 24) | (NalData[1] << 16) | (NalData[2] << 8) + | (NalData[3]); + break; + } - h264_printf(20, "NalStart = %u + NalLength = %u > SampleSize = %u\n", NalStart, NalLength, SampleSize); + h264_printf(20, + "NalStart = %u + NalLength = %u > SampleSize = %u\n", + NalStart, NalLength, SampleSize); - if (NalStart + NalLength > SampleSize) { - h264_printf(20, "nal length past end of buffer - size %u frame offset %u left %u\n", - NalLength, NalStart , SampleSize - NalStart ); + if (NalStart + NalLength > SampleSize) { + h264_printf(20, + "nal length past end of buffer - size %u frame offset %u left %u\n", + NalLength, NalStart, SampleSize - NalStart); - NalStart = SampleSize; - } else { - NalStart += NalLength; - ic = 0; - iov[ic++].iov_base = PesHeader; + NalStart = SampleSize; + } else { + NalStart += NalLength; + ic = 0; + iov[ic++].iov_base = PesHeader; - if (NalPresent) { - NalPresent = 0; - iov[ic].iov_base = (char *)Head; - iov[ic++].iov_len = sizeof(Head); - } + if (NalPresent) { + NalPresent = 0; + iov[ic].iov_base = (char *) Head; + iov[ic++].iov_len = sizeof(Head); + } - iov[ic].iov_base = call->data + VideoPosition; - iov[ic++].iov_len = NalLength; - VideoPosition += NalLength; + iov[ic].iov_base = call->data + VideoPosition; + iov[ic++].iov_len = NalLength; + VideoPosition += NalLength; - h264_printf (20, " pts=%llu\n", VideoPts); + h264_printf(20, " pts=%llu\n", VideoPts); - iov[0].iov_len = InsertPesHeader (PesHeader, NalLength, MPEG_VIDEO_PES_START_CODE, VideoPts, 0); - ssize_t l = writev(call->fd, iov, ic); - if (l < 0) - return l; - len += l; + iov[0].iov_len = + InsertPesHeader(PesHeader, NalLength, + MPEG_VIDEO_PES_START_CODE, VideoPts, 0); + ssize_t l = writev(call->fd, iov, ic); + if (l < 0) + return l; + len += l; - VideoPts = INVALID_PTS_VALUE; - } + VideoPts = INVALID_PTS_VALUE; + } } while (NalStart < SampleSize); - if (len < 0) - { - h264_err("error writing data errno = %d\n", errno); - h264_err("%s\n", strerror(errno)); + if (len < 0) { + h264_err("error writing data errno = %d\n", errno); + h264_err("%s\n", strerror(errno)); } - h264_printf (10, "< len %d\n", len); + h264_printf(10, "< len %d\n", len); return len; } -static int writeReverseData(void* _call) +static int writeReverseData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; h264_printf(10, "\n"); - if (call == NULL) - { - h264_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + h264_err("call data is NULL...\n"); + return 0; } h264_printf(10, "VideoPts %lld\n", call->Pts); - if ((call->data == NULL) || (call->len <= 0)) - { - h264_err("NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + h264_err("NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - h264_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + h264_err("file pointer < 0. ignoring ...\n"); + return 0; } return 0; } + /* ***************************** */ /* Writer Definition */ /* ***************************** */ diff --git a/libeplayer3/output/writer/misc.c b/libeplayer3/output/writer/misc.c index cdf9ba4..9cce499 100644 --- a/libeplayer3/output/writer/misc.c +++ b/libeplayer3/output/writer/misc.c @@ -72,35 +72,33 @@ void PutBits(BitPacker_t * ld, unsigned int code, unsigned int length) #ifdef DEBUG_PUTBITS if (ld->debug) - dprintf("code = %d, length = %d, bit_buf = 0x%x, bit_left = %d\n", code, length, bit_buf, bit_left); -#endif /* DEBUG_PUTBITS */ + dprintf("code = %d, length = %d, bit_buf = 0x%x, bit_left = %d\n", + code, length, bit_buf, bit_left); +#endif /* DEBUG_PUTBITS */ - if (length < bit_left) - { - /* fits into current buffer */ - bit_buf = (bit_buf << length) | code; - bit_left -= length; - } - else - { - /* doesn't fit */ - bit_buf <<= bit_left; - bit_buf |= code >> (length - bit_left); - ld->Ptr[0] = (char)(bit_buf >> 24); - ld->Ptr[1] = (char)(bit_buf >> 16); - ld->Ptr[2] = (char)(bit_buf >> 8); - ld->Ptr[3] = (char)bit_buf; - ld->Ptr += 4; - length -= bit_left; - bit_buf = code & ((1 << length) - 1); - bit_left = 32 - length; - bit_buf = code; + if (length < bit_left) { + /* fits into current buffer */ + bit_buf = (bit_buf << length) | code; + bit_left -= length; + } else { + /* doesn't fit */ + bit_buf <<= bit_left; + bit_buf |= code >> (length - bit_left); + ld->Ptr[0] = (char) (bit_buf >> 24); + ld->Ptr[1] = (char) (bit_buf >> 16); + ld->Ptr[2] = (char) (bit_buf >> 8); + ld->Ptr[3] = (char) bit_buf; + ld->Ptr += 4; + length -= bit_left; + bit_buf = code & ((1 << length) - 1); + bit_left = 32 - length; + bit_buf = code; } #ifdef DEBUG_PUTBITS if (ld->debug) - dprintf("bit_left = %d, bit_buf = 0x%x\n", bit_left, bit_buf); -#endif /* DEBUG_PUTBITS */ + dprintf("bit_left = %d, bit_buf = 0x%x\n", bit_left, bit_buf); +#endif /* DEBUG_PUTBITS */ /* writeback */ ld->BitBuffer = bit_buf; @@ -110,15 +108,14 @@ void PutBits(BitPacker_t * ld, unsigned int code, unsigned int length) void FlushBits(BitPacker_t * ld) { ld->BitBuffer <<= ld->Remaining; - while (ld->Remaining < 32) - { + while (ld->Remaining < 32) { #ifdef DEBUG_PUTBITS - if (ld->debug) - dprintf("flushing 0x%2.2x\n", ld->BitBuffer >> 24); -#endif /* DEBUG_PUTBITS */ - *ld->Ptr++ = ld->BitBuffer >> 24; - ld->BitBuffer <<= 8; - ld->Remaining += 8; + if (ld->debug) + dprintf("flushing 0x%2.2x\n", ld->BitBuffer >> 24); +#endif /* DEBUG_PUTBITS */ + *ld->Ptr++ = ld->BitBuffer >> 24; + ld->BitBuffer <<= 8; + ld->Remaining += 8; } ld->Remaining = 32; ld->BitBuffer = 0; diff --git a/libeplayer3/output/writer/mp3.c b/libeplayer3/output/writer/mp3.c index 9f92f1d..b91d5f6 100644 --- a/libeplayer3/output/writer/mp3.c +++ b/libeplayer3/output/writer/mp3.c @@ -90,37 +90,36 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; mp3_printf(10, "\n"); - if (call == NULL) - { - mp3_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + mp3_err("call data is NULL...\n"); + return 0; } mp3_printf(10, "AudioPts %lld\n", call->Pts); - if ((call->data == NULL) || (call->len <= 0)) - { - mp3_err("parsing NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + mp3_err("parsing NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - mp3_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + mp3_err("file pointer < 0. ignoring ...\n"); + return 0; } struct iovec iov[2]; iov[0].iov_base = PesHeader; - iov[0].iov_len = InsertPesHeader (PesHeader, call->len , MPEG_AUDIO_PES_START_CODE, call->Pts, 0); + iov[0].iov_len = + InsertPesHeader(PesHeader, call->len, MPEG_AUDIO_PES_START_CODE, + call->Pts, 0); iov[1].iov_base = call->data; iov[1].iov_len = call->len; diff --git a/libeplayer3/output/writer/mpeg2.c b/libeplayer3/output/writer/mpeg2.c index 7340b00..1b9367a 100644 --- a/libeplayer3/output/writer/mpeg2.c +++ b/libeplayer3/output/writer/mpeg2.c @@ -91,59 +91,58 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; int len = 0; unsigned int Position = 0; mpeg2_printf(10, "\n"); - if (call == NULL) - { - mpeg2_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + mpeg2_err("call data is NULL...\n"); + return 0; } mpeg2_printf(10, "VideoPts %lld\n", call->Pts); - if ((call->data == NULL) || (call->len <= 0)) - { - mpeg2_err("parsing NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + mpeg2_err("parsing NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - mpeg2_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + mpeg2_err("file pointer < 0. ignoring ...\n"); + return 0; } - while(Position < call->len) { - int PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ? - (call->len - Position) : MAX_PES_PACKET_SIZE; + while (Position < call->len) { + int PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ? + (call->len - Position) : MAX_PES_PACKET_SIZE; - int Remaining = call->len - Position - PacketLength; + int Remaining = call->len - Position - PacketLength; - mpeg2_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", PacketLength, Remaining, Position); + mpeg2_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", + PacketLength, Remaining, Position); struct iovec iov[2]; iov[0].iov_base = PesHeader; - iov[0].iov_len = InsertPesHeader (PesHeader, PacketLength, 0xe0, call->Pts, 0); + iov[0].iov_len = + InsertPesHeader(PesHeader, PacketLength, 0xe0, call->Pts, 0); iov[1].iov_base = call->data + Position; iov[1].iov_len = PacketLength; - ssize_t l = writev(call->fd, iov, 2); + ssize_t l = writev(call->fd, iov, 2); if (l < 0) { - len = l; - break; + len = l; + break; } len += l; - Position += PacketLength; - call->Pts = INVALID_PTS_VALUE; + Position += PacketLength; + call->Pts = INVALID_PTS_VALUE; } mpeg2_printf(10, "< len %d\n", len); diff --git a/libeplayer3/output/writer/pcm.c b/libeplayer3/output/writer/pcm.c index cc4a4c3..b944a23 100644 --- a/libeplayer3/output/writer/pcm.c +++ b/libeplayer3/output/writer/pcm.c @@ -84,18 +84,18 @@ static unsigned int SubFrameLen = 0; static unsigned int SubFramesPerPES = 0; // reference: search for TypeLpcmDVDAudio in player/frame_parser/frame_parser_audio_lpcm.cpp -static const unsigned char clpcm_prv[14] = { 0xA0, //sub_stream_id - 0, 0, //resvd and UPC_EAN_ISRC stuff, unused - 0x0A, //private header length - 0, 9, //first_access_unit_pointer - 0x00, //emph,rsvd,stereo,downmix - 0x0F, //quantisation word length 1,2 - 0x0F, //audio sampling freqency 1,2 - 0, //resvd, multi channel type - 0, //bit shift on channel GR2, assignment - 0x80, //dynamic range control - 0, 0 //resvd for copyright management - }; +static const unsigned char clpcm_prv[14] = { 0xA0, //sub_stream_id + 0, 0, //resvd and UPC_EAN_ISRC stuff, unused + 0x0A, //private header length + 0, 9, //first_access_unit_pointer + 0x00, //emph,rsvd,stereo,downmix + 0x0F, //quantisation word length 1,2 + 0x0F, //audio sampling freqency 1,2 + 0, //resvd, multi channel type + 0, //bit shift on channel GR2, assignment + 0x80, //dynamic range control + 0, 0 //resvd for copyright management +}; static unsigned char lpcm_prv[14]; static unsigned char breakBuffer[8192]; @@ -109,184 +109,199 @@ static unsigned int breakBufferFillSize = 0; /* MISC Functions */ /* ***************************** */ -static int prepareClipPlay(int uNoOfChannels, int uSampleRate, int uBitsPerSample, int bLittleEndian __attribute__((unused))) +static int prepareClipPlay(int uNoOfChannels, int uSampleRate, + int uBitsPerSample, int bLittleEndian + __attribute__ ((unused))) { - printf("rate: %d ch: %d bits: %d (%d bps)\n", - uSampleRate/*Format->dwSamplesPerSec*/, - uNoOfChannels/*Format->wChannels*/, - uBitsPerSample/*Format->wBitsPerSample*/, - (uBitsPerSample/*Format->wBitsPerSample*/ / 8) + printf("rate: %d ch: %d bits: %d (%d bps)\n", + uSampleRate /*Format->dwSamplesPerSec */ , + uNoOfChannels /*Format->wChannels */ , + uBitsPerSample /*Format->wBitsPerSample */ , + (uBitsPerSample /*Format->wBitsPerSample */ / 8) ); - SubFrameLen = 0; - SubFramesPerPES = 0; - breakBufferFillSize = 0; + SubFrameLen = 0; + SubFramesPerPES = 0; + breakBufferFillSize = 0; - memcpy(lpcm_prv, clpcm_prv, sizeof(lpcm_prv)); + memcpy(lpcm_prv, clpcm_prv, sizeof(lpcm_prv)); - //figure out size of subframe - //and set up sample rate - switch(uSampleRate) { - case 48000: SubFrameLen = 40; - break; - case 96000: lpcm_prv[8] |= 0x10; - SubFrameLen = 80; - break; - case 192000: lpcm_prv[8] |= 0x20; - SubFrameLen = 160; - break; - case 44100: lpcm_prv[8] |= 0x80; - SubFrameLen = 40; - break; - case 88200: lpcm_prv[8] |= 0x90; - SubFrameLen = 80; - break; - case 176400: lpcm_prv[8] |= 0xA0; - SubFrameLen = 160; - break; - default: break; - } + //figure out size of subframe + //and set up sample rate + switch (uSampleRate) { + case 48000: + SubFrameLen = 40; + break; + case 96000: + lpcm_prv[8] |= 0x10; + SubFrameLen = 80; + break; + case 192000: + lpcm_prv[8] |= 0x20; + SubFrameLen = 160; + break; + case 44100: + lpcm_prv[8] |= 0x80; + SubFrameLen = 40; + break; + case 88200: + lpcm_prv[8] |= 0x90; + SubFrameLen = 80; + break; + case 176400: + lpcm_prv[8] |= 0xA0; + SubFrameLen = 160; + break; + default: + break; + } - SubFrameLen *= uNoOfChannels; - SubFrameLen *= (uBitsPerSample / 8); + SubFrameLen *= uNoOfChannels; + SubFrameLen *= (uBitsPerSample / 8); - //rewrite PES size to have as many complete subframes per PES as we can - // FIXME: PES header size was hardcoded to 18 in previous code. Actual size returned by InsertPesHeader is 14. - SubFramesPerPES = ((2048 - 18) - sizeof(lpcm_prv))/SubFrameLen; - SubFrameLen *= SubFramesPerPES; + //rewrite PES size to have as many complete subframes per PES as we can + // FIXME: PES header size was hardcoded to 18 in previous code. Actual size returned by InsertPesHeader is 14. + SubFramesPerPES = ((2048 - 18) - sizeof(lpcm_prv)) / SubFrameLen; + SubFrameLen *= SubFramesPerPES; - //set number of channels - lpcm_prv[10] = uNoOfChannels - 1; + //set number of channels + lpcm_prv[10] = uNoOfChannels - 1; - switch(uBitsPerSample) { - case 24: - lpcm_prv[7] |= 0x20; - case 16: - break; - default: - printf("inappropriate bits per sample (%d) - must be 16 or 24\n",uBitsPerSample); - return 1; - } + switch (uBitsPerSample) { + case 24: + lpcm_prv[7] |= 0x20; + case 16: + break; + default: + printf("inappropriate bits per sample (%d) - must be 16 or 24\n", + uBitsPerSample); + return 1; + } - return 0; + return 0; } static int reset() { - initialHeader = 1; - return 0; + initialHeader = 1; + return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; - pcm_printf(10, "\n"); + pcm_printf(10, "\n"); - if (!call) { - pcm_err("call data is NULL...\n"); - return 0; + if (!call) { + pcm_err("call data is NULL...\n"); + return 0; + } + + pcm_printf(10, "AudioPts %lld\n", call->Pts); + + if (!call->data || (call->len <= 0)) { + pcm_err("parsing NULL Data. ignoring...\n"); + return 0; + } + + if (call->fd < 0) { + pcm_err("file pointer < 0. ignoring ...\n"); + return 0; + } + + pcmPrivateData_t *pcmPrivateData = + (pcmPrivateData_t *) call->private_data; + + if (initialHeader) { + initialHeader = 0; + prepareClipPlay(pcmPrivateData->uNoOfChannels, + pcmPrivateData->uSampleRate, + pcmPrivateData->uBitsPerSample, + pcmPrivateData->bLittleEndian); + } + + unsigned char *buffer = call->data; + unsigned int size = call->len; + + unsigned int n; + unsigned char *injectBuffer = (unsigned char *) malloc(SubFrameLen); + unsigned int pos; + + for (pos = 0; pos < size;) { + //printf("PCM %s - Position=%d\n", __FUNCTION__, pos); + if ((size - pos) < SubFrameLen) { + breakBufferFillSize = size - pos; + memcpy(breakBuffer, &buffer[pos], + sizeof(unsigned char) * breakBufferFillSize); + //printf("PCM %s - Unplayed=%d\n", __FUNCTION__, breakBufferFillSize); + break; + } + //get first PES's worth + if (breakBufferFillSize > 0) { + memcpy(injectBuffer, breakBuffer, + sizeof(unsigned char) * breakBufferFillSize); + memcpy(&injectBuffer[breakBufferFillSize], &buffer[pos], + sizeof(unsigned char) * (SubFrameLen - + breakBufferFillSize)); + pos += (SubFrameLen - breakBufferFillSize); + breakBufferFillSize = 0; + } else { + memcpy(injectBuffer, &buffer[pos], + sizeof(unsigned char) * SubFrameLen); + pos += SubFrameLen; } - pcm_printf(10, "AudioPts %lld\n", call->Pts); + struct iovec iov[3]; + iov[0].iov_base = PesHeader; + iov[1].iov_base = lpcm_prv; + iov[1].iov_len = sizeof(lpcm_prv); - if (!call->data || (call->len <= 0)) { - pcm_err("parsing NULL Data. ignoring...\n"); - return 0; + iov[2].iov_base = injectBuffer; + iov[2].iov_len = SubFrameLen; + + //write the PCM data + if (pcmPrivateData->uBitsPerSample == 16) { + for (n = 0; n < SubFrameLen; n += 2) { + unsigned char tmp; + tmp = injectBuffer[n]; + injectBuffer[n] = injectBuffer[n + 1]; + injectBuffer[n + 1] = tmp; + } + } else { + // 0 1 2 3 4 5 6 7 8 9 10 11 + // A1c A1b A1a-B1c B1b B1a-A2c A2b A2a-B2c B2b B2a + // to A1a A1b B1a B1b.A2a A2b B2a B2b-A1c B1c A2c B2c + for (n = 0; n < SubFrameLen; n += 12) { + unsigned char t, *p = &injectBuffer[n]; + t = p[0]; + p[0] = p[2]; + p[2] = p[5]; + p[5] = p[7]; + p[7] = p[11]; + p[11] = p[9]; + p[9] = p[3]; + p[3] = p[4]; + p[4] = p[8]; + p[8] = t; + } } - if (call->fd < 0) { - pcm_err("file pointer < 0. ignoring ...\n"); - return 0; - } + //increment err... subframe count? + lpcm_prv[1] = ((lpcm_prv[1] + SubFramesPerPES) & 0x1F); - pcmPrivateData_t* pcmPrivateData = (pcmPrivateData_t*)call->private_data; + iov[0].iov_len = + InsertPesHeader(PesHeader, iov[1].iov_len + iov[2].iov_len, + PCM_PES_START_CODE, call->Pts, 0); + int len = writev(call->fd, iov, 3); + if (len < 0) + break; + } + free(injectBuffer); - if (initialHeader) { - initialHeader = 0; - prepareClipPlay(pcmPrivateData->uNoOfChannels, pcmPrivateData->uSampleRate, - pcmPrivateData->uBitsPerSample, pcmPrivateData->bLittleEndian); - } - - unsigned char * buffer = call->data; - unsigned int size = call->len; - - unsigned int n; - unsigned char * injectBuffer = (unsigned char *)malloc(SubFrameLen); - unsigned int pos; - - for(pos = 0; pos < size; ) - { - //printf("PCM %s - Position=%d\n", __FUNCTION__, pos); - if((size - pos) < SubFrameLen) - { - breakBufferFillSize = size - pos; - memcpy(breakBuffer, &buffer[pos], sizeof(unsigned char) * breakBufferFillSize); - //printf("PCM %s - Unplayed=%d\n", __FUNCTION__, breakBufferFillSize); - break; - } - - //get first PES's worth - if(breakBufferFillSize > 0) - { - memcpy(injectBuffer, breakBuffer, sizeof(unsigned char)*breakBufferFillSize); - memcpy(&injectBuffer[breakBufferFillSize], &buffer[pos], sizeof(unsigned char)*(SubFrameLen - breakBufferFillSize)); - pos += (SubFrameLen - breakBufferFillSize); - breakBufferFillSize = 0; - } else - { - memcpy(injectBuffer, &buffer[pos], sizeof(unsigned char)*SubFrameLen); - pos += SubFrameLen; - } - - struct iovec iov[3]; - iov[0].iov_base = PesHeader; - iov[1].iov_base = lpcm_prv; - iov[1].iov_len = sizeof(lpcm_prv); - - iov[2].iov_base = injectBuffer; - iov[2].iov_len = SubFrameLen; - - //write the PCM data - if(pcmPrivateData->uBitsPerSample == 16) { - for(n=0; nPts, 0); - int len = writev(call->fd, iov, 3); - if (len < 0) - break; - } - free(injectBuffer); - - return size; + return size; } /* ***************************** */ @@ -294,29 +309,29 @@ static int writeData(void* _call) /* ***************************** */ static WriterCaps_t caps_pcm = { - "pcm", - eAudio, - "A_PCM", - AUDIO_ENCODING_LPCMA + "pcm", + eAudio, + "A_PCM", + AUDIO_ENCODING_LPCMA }; struct Writer_s WriterAudioPCM = { - &reset, - &writeData, - NULL, - &caps_pcm + &reset, + &writeData, + NULL, + &caps_pcm }; static WriterCaps_t caps_ipcm = { - "ipcm", - eAudio, - "A_IPCM", - AUDIO_ENCODING_LPCMA + "ipcm", + eAudio, + "A_IPCM", + AUDIO_ENCODING_LPCMA }; struct Writer_s WriterAudioIPCM = { - &reset, - &writeData, - NULL, - &caps_ipcm + &reset, + &writeData, + NULL, + &caps_ipcm }; diff --git a/libeplayer3/output/writer/pes.c b/libeplayer3/output/writer/pes.c index 370912c..58a13c3 100644 --- a/libeplayer3/output/writer/pes.c +++ b/libeplayer3/output/writer/pes.c @@ -69,84 +69,83 @@ int InsertVideoPrivateDataHeader(unsigned char *data, int payload_size) { - BitPacker_t ld2 = {data, 0, 32}; - int i; + BitPacker_t ld2 = { data, 0, 32 }; + int i; - PutBits (&ld2, PES_PRIVATE_DATA_FLAG, 8); - PutBits (&ld2, payload_size & 0xff, 8); - PutBits (&ld2, (payload_size >> 8) & 0xff, 8); - PutBits (&ld2, (payload_size >> 16) & 0xff, 8); + PutBits(&ld2, PES_PRIVATE_DATA_FLAG, 8); + PutBits(&ld2, payload_size & 0xff, 8); + PutBits(&ld2, (payload_size >> 8) & 0xff, 8); + PutBits(&ld2, (payload_size >> 16) & 0xff, 8); - for (i = 4; i < (PES_PRIVATE_DATA_LENGTH+1); i++) - PutBits (&ld2, 0, 8); + for (i = 4; i < (PES_PRIVATE_DATA_LENGTH + 1); i++) + PutBits(&ld2, 0, 8); - FlushBits (&ld2); + FlushBits(&ld2); return PES_PRIVATE_DATA_LENGTH + 1; } -int InsertPesHeader (unsigned char *data, int size, unsigned char stream_id, unsigned long long int pts, int pic_start_code) +int InsertPesHeader(unsigned char *data, int size, unsigned char stream_id, + unsigned long long int pts, int pic_start_code) { - BitPacker_t ld2 = {data, 0, 32}; + BitPacker_t ld2 = { data, 0, 32 }; if (size > MAX_PES_PACKET_SIZE) - size = 0; // unbounded + size = 0; // unbounded - PutBits(&ld2,0x0 ,8); - PutBits(&ld2,0x0 ,8); - PutBits(&ld2,0x1 ,8); // Start Code - PutBits(&ld2,stream_id ,8); // Stream_id = Audio Stream + PutBits(&ld2, 0x0, 8); + PutBits(&ld2, 0x0, 8); + PutBits(&ld2, 0x1, 8); // Start Code + PutBits(&ld2, stream_id, 8); // Stream_id = Audio Stream //4 - PutBits(&ld2,size + 3 + (pts != INVALID_PTS_VALUE ? 5:0) + (pic_start_code ? (5) : 0),16); // PES_packet_length + PutBits(&ld2, size + 3 + (pts != INVALID_PTS_VALUE ? 5 : 0) + (pic_start_code ? (5) : 0), 16); // PES_packet_length //6 = 4+2 - PutBits(&ld2,0x2 ,2); // 10 - PutBits(&ld2,0x0 ,2); // PES_Scrambling_control - PutBits(&ld2,0x0 ,1); // PES_Priority - PutBits(&ld2,0x0 ,1); // data_alignment_indicator - PutBits(&ld2,0x0 ,1); // Copyright - PutBits(&ld2,0x0 ,1); // Original or Copy + PutBits(&ld2, 0x2, 2); // 10 + PutBits(&ld2, 0x0, 2); // PES_Scrambling_control + PutBits(&ld2, 0x0, 1); // PES_Priority + PutBits(&ld2, 0x0, 1); // data_alignment_indicator + PutBits(&ld2, 0x0, 1); // Copyright + PutBits(&ld2, 0x0, 1); // Original or Copy //7 = 6+1 - if (pts!=INVALID_PTS_VALUE) - PutBits(&ld2,0x2 ,2); + if (pts != INVALID_PTS_VALUE) + PutBits(&ld2, 0x2, 2); else - PutBits(&ld2,0x0 ,2); // PTS_DTS flag + PutBits(&ld2, 0x0, 2); // PTS_DTS flag - PutBits(&ld2,0x0 ,1); // ESCR_flag - PutBits(&ld2,0x0 ,1); // ES_rate_flag - PutBits(&ld2,0x0 ,1); // DSM_trick_mode_flag - PutBits(&ld2,0x0 ,1); // additional_copy_ingo_flag - PutBits(&ld2,0x0 ,1); // PES_CRC_flag - PutBits(&ld2,0x0 ,1); // PES_extension_flag + PutBits(&ld2, 0x0, 1); // ESCR_flag + PutBits(&ld2, 0x0, 1); // ES_rate_flag + PutBits(&ld2, 0x0, 1); // DSM_trick_mode_flag + PutBits(&ld2, 0x0, 1); // additional_copy_ingo_flag + PutBits(&ld2, 0x0, 1); // PES_CRC_flag + PutBits(&ld2, 0x0, 1); // PES_extension_flag //8 = 7+1 - if (pts!=INVALID_PTS_VALUE) - PutBits(&ld2,0x5,8); + if (pts != INVALID_PTS_VALUE) + PutBits(&ld2, 0x5, 8); else - PutBits(&ld2,0x0 ,8); // PES_header_data_length + PutBits(&ld2, 0x0, 8); // PES_header_data_length //9 = 8+1 - if (pts!=INVALID_PTS_VALUE) - { - PutBits(&ld2,0x2,4); - PutBits(&ld2,(pts>>30) & 0x7,3); - PutBits(&ld2,0x1,1); - PutBits(&ld2,(pts>>15) & 0x7fff,15); - PutBits(&ld2,0x1,1); - PutBits(&ld2,pts & 0x7fff,15); - PutBits(&ld2,0x1,1); + if (pts != INVALID_PTS_VALUE) { + PutBits(&ld2, 0x2, 4); + PutBits(&ld2, (pts >> 30) & 0x7, 3); + PutBits(&ld2, 0x1, 1); + PutBits(&ld2, (pts >> 15) & 0x7fff, 15); + PutBits(&ld2, 0x1, 1); + PutBits(&ld2, pts & 0x7fff, 15); + PutBits(&ld2, 0x1, 1); } //14 = 9+5 - if (pic_start_code) - { - PutBits(&ld2,0x0 ,8); - PutBits(&ld2,0x0 ,8); - PutBits(&ld2,0x1 ,8); // Start Code - PutBits(&ld2,pic_start_code & 0xff ,8); // 00, for picture start - PutBits(&ld2,(pic_start_code >> 8 )&0xff,8); // For any extra information (like in mpeg4p2, the pic_start_code) - //14 + 4 = 18 + if (pic_start_code) { + PutBits(&ld2, 0x0, 8); + PutBits(&ld2, 0x0, 8); + PutBits(&ld2, 0x1, 8); // Start Code + PutBits(&ld2, pic_start_code & 0xff, 8); // 00, for picture start + PutBits(&ld2, (pic_start_code >> 8) & 0xff, 8); // For any extra information (like in mpeg4p2, the pic_start_code) + //14 + 4 = 18 } FlushBits(&ld2); diff --git a/libeplayer3/output/writer/vc1.c b/libeplayer3/output/writer/vc1.c index 2818dc6..253defe 100644 --- a/libeplayer3/output/writer/vc1.c +++ b/libeplayer3/output/writer/vc1.c @@ -86,20 +86,20 @@ if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x); /* Types */ /* ***************************** */ -static const unsigned char SequenceLayerStartCode[] = {0x00, 0x00, 0x01, VC1_SEQUENCE_LAYER_METADATA_START_CODE}; +static const unsigned char SequenceLayerStartCode[] = + { 0x00, 0x00, 0x01, VC1_SEQUENCE_LAYER_METADATA_START_CODE }; -static const unsigned char Metadata[] = -{ - 0x00, 0x00, 0x00, 0xc5, - 0x04, 0x00, 0x00, 0x00, - 0xc0, 0x00, 0x00, 0x00, /* Struct C set for for advanced profile*/ - 0x00, 0x00, 0x00, 0x00, /* Struct A */ - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, - 0x60, 0x00, 0x00, 0x00, /* Struct B */ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 +static const unsigned char Metadata[] = { + 0x00, 0x00, 0x00, 0xc5, + 0x04, 0x00, 0x00, 0x00, + 0xc0, 0x00, 0x00, 0x00, /* Struct C set for for advanced profile */ + 0x00, 0x00, 0x00, 0x00, /* Struct A */ + 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, /* Struct B */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }; /* ***************************** */ @@ -122,9 +122,9 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; int len = 0; @@ -152,81 +152,94 @@ static int writeData(void* _call) if (initialHeader) { - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; - unsigned char PesPayload[128]; - unsigned char* PesPtr; - unsigned int crazyFramerate = 0; - struct iovec iov[2]; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + unsigned char PesPayload[128]; + unsigned char *PesPtr; + unsigned int crazyFramerate = 0; + struct iovec iov[2]; vc1_printf(10, "Framerate: %u\n", call->FrameRate); - vc1_printf(10, "biWidth: %d\n", call->Width); - vc1_printf(10, "biHeight: %d\n", call->Height); + vc1_printf(10, "biWidth: %d\n", call->Width); + vc1_printf(10, "biHeight: %d\n", call->Height); crazyFramerate = ((10000000.0 / call->FrameRate) * 1000.0); vc1_printf(10, "crazyFramerate: %u\n", crazyFramerate); memset(PesPayload, 0, sizeof(PesPayload)); - PesPtr = PesPayload; + PesPtr = PesPayload; - memcpy (PesPtr, SequenceLayerStartCode, sizeof(SequenceLayerStartCode)); - PesPtr += sizeof(SequenceLayerStartCode); + memcpy(PesPtr, SequenceLayerStartCode, + sizeof(SequenceLayerStartCode)); + PesPtr += sizeof(SequenceLayerStartCode); - memcpy (PesPtr, Metadata, sizeof(Metadata)); + memcpy(PesPtr, Metadata, sizeof(Metadata)); PesPtr += METADATA_STRUCT_C_START; PesPtr += WMV3_PRIVATE_DATA_LENGTH; /* Metadata Header Struct A */ - *PesPtr++ = (call->Height >> 0) & 0xff; - *PesPtr++ = (call->Height >> 8) & 0xff; + *PesPtr++ = (call->Height >> 0) & 0xff; + *PesPtr++ = (call->Height >> 8) & 0xff; *PesPtr++ = (call->Height >> 16) & 0xff; - *PesPtr++ = call->Height >> 24; - *PesPtr++ = (call->Width >> 0) & 0xff; - *PesPtr++ = (call->Width >> 8) & 0xff; - *PesPtr++ = (call->Width >> 16) & 0xff; - *PesPtr++ = call->Width >> 24; + *PesPtr++ = call->Height >> 24; + *PesPtr++ = (call->Width >> 0) & 0xff; + *PesPtr++ = (call->Width >> 8) & 0xff; + *PesPtr++ = (call->Width >> 16) & 0xff; + *PesPtr++ = call->Width >> 24; - PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */ + PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */ - *PesPtr++ = (crazyFramerate >> 0) & 0xff; - *PesPtr++ = (crazyFramerate >> 8) & 0xff; + *PesPtr++ = (crazyFramerate >> 0) & 0xff; + *PesPtr++ = (crazyFramerate >> 8) & 0xff; *PesPtr++ = (crazyFramerate >> 16) & 0xff; - *PesPtr++ = crazyFramerate >> 24; + *PesPtr++ = crazyFramerate >> 24; iov[0].iov_base = PesHeader; iov[1].iov_base = PesPayload; iov[1].iov_len = PesPtr - PesPayload; - iov[0].iov_len = InsertPesHeader (PesHeader, iov[1].iov_len, VC1_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0); + iov[0].iov_len = + InsertPesHeader(PesHeader, iov[1].iov_len, + VC1_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, + 0); len = writev(call->fd, iov, 2); /* For VC1 the codec private data is a standard vc1 sequence header so we just copy it to the output */ iov[0].iov_base = PesHeader; iov[1].iov_base = call->private_data; iov[1].iov_len = call->private_size; - iov[0].iov_len = InsertPesHeader (PesHeader, iov[1].iov_len, VC1_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0); + iov[0].iov_len = + InsertPesHeader(PesHeader, iov[1].iov_len, + VC1_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, + 0); len = writev(call->fd, iov, 2); initialHeader = 0; } - if(call->len > 0 && call->data) { + if (call->len > 0 && call->data) { unsigned int Position = 0; unsigned char insertSampleHeader = 1; - while(Position < call->len) { + while (Position < call->len) { - int PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ? - (call->len - Position) : MAX_PES_PACKET_SIZE; + int PacketLength = + (call->len - Position) <= + MAX_PES_PACKET_SIZE ? (call->len - + Position) : MAX_PES_PACKET_SIZE; int Remaining = call->len - Position - PacketLength; - vc1_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", PacketLength, Remaining, Position); + vc1_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", + PacketLength, Remaining, Position); - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; - int HeaderLength = InsertPesHeader (PesHeader, PacketLength, VC1_VIDEO_PES_START_CODE, call->Pts, 0); + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + int HeaderLength = + InsertPesHeader(PesHeader, PacketLength, + VC1_VIDEO_PES_START_CODE, call->Pts, 0); - if(insertSampleHeader) { - const unsigned char Vc1FrameStartCode[] = {0, 0, 1, VC1_FRAME_START_CODE}; + if (insertSampleHeader) { + const unsigned char Vc1FrameStartCode[] = + { 0, 0, 1, VC1_FRAME_START_CODE }; /* vc1_printf(10, "Data Start: {00 00 01 0d} - "); @@ -235,13 +248,14 @@ static int writeData(void* _call) vc1_printf(10, "\n"); */ - if (!FrameHeaderSeen && (call->len > 3) && (memcmp (call->data, Vc1FrameStartCode, 4) == 0)) - FrameHeaderSeen = 1; - if (!FrameHeaderSeen) - { - memcpy (&PesHeader[HeaderLength], Vc1FrameStartCode, sizeof(Vc1FrameStartCode)); - HeaderLength += sizeof(Vc1FrameStartCode); - } + if (!FrameHeaderSeen && (call->len > 3) + && (memcmp(call->data, Vc1FrameStartCode, 4) == 0)) + FrameHeaderSeen = 1; + if (!FrameHeaderSeen) { + memcpy(&PesHeader[HeaderLength], Vc1FrameStartCode, + sizeof(Vc1FrameStartCode)); + HeaderLength += sizeof(Vc1FrameStartCode); + } insertSampleHeader = 0; } diff --git a/libeplayer3/output/writer/wma.c b/libeplayer3/output/writer/wma.c index ca4e0da..dd13237 100644 --- a/libeplayer3/output/writer/wma.c +++ b/libeplayer3/output/writer/wma.c @@ -94,72 +94,71 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; int len = 0; wma_printf(10, "\n"); - if (call == NULL) - { - wma_err("call data is NULL...\n"); - return 0; + if (call == NULL) { + wma_err("call data is NULL...\n"); + return 0; } wma_printf(10, "AudioPts %lld\n", call->Pts); - if ((call->data == NULL) || (call->len <= 0)) - { - wma_err("parsing NULL Data. ignoring...\n"); - return 0; + if ((call->data == NULL) || (call->len <= 0)) { + wma_err("parsing NULL Data. ignoring...\n"); + return 0; } - if (call->fd < 0) - { - wma_err("file pointer < 0. ignoring ...\n"); - return 0; + if (call->fd < 0) { + wma_err("file pointer < 0. ignoring ...\n"); + return 0; } if (initialHeader) { - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; - if ((call->private_size <= 0) || (call->private_data == NULL)) - { - wma_err("private NULL.\n"); - return -1; - } + if ((call->private_size <= 0) || (call->private_data == NULL)) { + wma_err("private NULL.\n"); + return -1; + } struct iovec iov[2]; iov[0].iov_base = PesHeader; - iov[0].iov_len = InsertPesHeader (PesHeader, call->private_size, MPEG_AUDIO_PES_START_CODE, 0, 0); + iov[0].iov_len = + InsertPesHeader(PesHeader, call->private_size, + MPEG_AUDIO_PES_START_CODE, 0, 0); iov[1].iov_base = call->private_data; iov[1].iov_len = call->private_size; - len = writev(call->fd, iov, 2); + len = writev(call->fd, iov, 2); - initialHeader = 0; + initialHeader = 0; } - if (len > -1 && call->len > 0 && call->data) - { - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + if (len > -1 && call->len > 0 && call->data) { + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; struct iovec iov[2]; iov[0].iov_base = PesHeader; - iov[0].iov_len = InsertPesHeader (PesHeader, call->len, MPEG_AUDIO_PES_START_CODE, call->Pts, 0); + iov[0].iov_len = + InsertPesHeader(PesHeader, call->len, + MPEG_AUDIO_PES_START_CODE, call->Pts, 0); iov[1].iov_base = call->data; iov[1].iov_len = call->len; - ssize_t l = writev(call->fd, iov, 2); + ssize_t l = writev(call->fd, iov, 2); if (l > -1) - len += l; + len += l; else - len = l; + len = l; } wma_printf(10, "wma < %d\n", len); diff --git a/libeplayer3/output/writer/wmv.c b/libeplayer3/output/writer/wmv.c index da24d46..c3a2486 100644 --- a/libeplayer3/output/writer/wmv.c +++ b/libeplayer3/output/writer/wmv.c @@ -82,25 +82,23 @@ if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x); /* Types */ /* ***************************** */ -typedef struct -{ - unsigned char privateData[WMV3_PRIVATE_DATA_LENGTH]; - unsigned int width; - unsigned int height; - unsigned int framerate; +typedef struct { + unsigned char privateData[WMV3_PRIVATE_DATA_LENGTH]; + unsigned int width; + unsigned int height; + unsigned int framerate; } awmv_t; -static const unsigned char Metadata[] = -{ - 0x00, 0x00, 0x00, 0xc5, - 0x04, 0x00, 0x00, 0x00, - 0xc0, 0x00, 0x00, 0x00, /* Struct C set for for advanced profile*/ - 0x00, 0x00, 0x00, 0x00, /* Struct A */ - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, - 0x60, 0x00, 0x00, 0x00, /* Struct B */ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 +static const unsigned char Metadata[] = { + 0x00, 0x00, 0x00, 0xc5, + 0x04, 0x00, 0x00, 0x00, + 0xc0, 0x00, 0x00, 0x00, /* Struct C set for for advanced profile */ + 0x00, 0x00, 0x00, 0x00, /* Struct A */ + 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, /* Struct B */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }; /* ***************************** */ @@ -121,9 +119,9 @@ static int reset() return 0; } -static int writeData(void* _call) +static int writeData(void *_call) { - WriterAVCallData_t* call = (WriterAVCallData_t*) _call; + WriterAVCallData_t *call = (WriterAVCallData_t *) _call; awmv_t private_data; int len = 0; @@ -131,25 +129,27 @@ static int writeData(void* _call) wmv_printf(10, "\n"); if (call == NULL) { - wmv_err("call data is NULL...\n"); - return 0; + wmv_err("call data is NULL...\n"); + return 0; } if ((call->data == NULL) || (call->len <= 0)) { - wmv_err("parsing NULL Data. ignoring...\n"); - return 0; + wmv_err("parsing NULL Data. ignoring...\n"); + return 0; } if (call->fd < 0) { - wmv_err("file pointer < 0. ignoring ...\n"); - return 0; + wmv_err("file pointer < 0. ignoring ...\n"); + return 0; } wmv_printf(10, "VideoPts %lld\n", call->Pts); wmv_printf(10, "Got Private Size %d\n", call->private_size); memcpy(private_data.privateData, call->private_data, - call->private_size>WMV3_PRIVATE_DATA_LENGTH?WMV3_PRIVATE_DATA_LENGTH:call->private_size); + call->private_size > + WMV3_PRIVATE_DATA_LENGTH ? WMV3_PRIVATE_DATA_LENGTH : call-> + private_size); private_data.width = call->Width; private_data.height = call->Height; @@ -157,97 +157,110 @@ static int writeData(void* _call) #define PES_MIN_HEADER_SIZE 9 if (initialHeader) { - unsigned char PesPacket[PES_MIN_HEADER_SIZE+128]; - unsigned char* PesPtr; - unsigned int MetadataLength; - unsigned int crazyFramerate = 0; + unsigned char PesPacket[PES_MIN_HEADER_SIZE + 128]; + unsigned char *PesPtr; + unsigned int MetadataLength; + unsigned int crazyFramerate = 0; - wmv_printf(10, "Framerate: %u\n", private_data.framerate); - wmv_printf(10, "biWidth: %d\n", private_data.width); - wmv_printf(10, "biHeight: %d\n", private_data.height); + wmv_printf(10, "Framerate: %u\n", private_data.framerate); + wmv_printf(10, "biWidth: %d\n", private_data.width); + wmv_printf(10, "biHeight: %d\n", private_data.height); - crazyFramerate = ((10000000.0 / private_data.framerate) * 1000.0); - wmv_printf(10, "crazyFramerate: %u\n", crazyFramerate); + crazyFramerate = ((10000000.0 / private_data.framerate) * 1000.0); + wmv_printf(10, "crazyFramerate: %u\n", crazyFramerate); - PesPtr = &PesPacket[PES_MIN_HEADER_SIZE]; + PesPtr = &PesPacket[PES_MIN_HEADER_SIZE]; - memcpy (PesPtr, Metadata, sizeof(Metadata)); - PesPtr += METADATA_STRUCT_C_START; + memcpy(PesPtr, Metadata, sizeof(Metadata)); + PesPtr += METADATA_STRUCT_C_START; - memcpy (PesPtr, private_data.privateData, WMV3_PRIVATE_DATA_LENGTH); - PesPtr += WMV3_PRIVATE_DATA_LENGTH; + memcpy(PesPtr, private_data.privateData, WMV3_PRIVATE_DATA_LENGTH); + PesPtr += WMV3_PRIVATE_DATA_LENGTH; - /* Metadata Header Struct A */ - *PesPtr++ = (private_data.height >> 0) & 0xff; - *PesPtr++ = (private_data.height >> 8) & 0xff; - *PesPtr++ = (private_data.height >> 16) & 0xff; - *PesPtr++ = private_data.height >> 24; - *PesPtr++ = (private_data.width >> 0) & 0xff; - *PesPtr++ = (private_data.width >> 8) & 0xff; - *PesPtr++ = (private_data.width >> 16) & 0xff; - *PesPtr++ = private_data.width >> 24; + /* Metadata Header Struct A */ + *PesPtr++ = (private_data.height >> 0) & 0xff; + *PesPtr++ = (private_data.height >> 8) & 0xff; + *PesPtr++ = (private_data.height >> 16) & 0xff; + *PesPtr++ = private_data.height >> 24; + *PesPtr++ = (private_data.width >> 0) & 0xff; + *PesPtr++ = (private_data.width >> 8) & 0xff; + *PesPtr++ = (private_data.width >> 16) & 0xff; + *PesPtr++ = private_data.width >> 24; - PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */ + PesPtr += 12; /* Skip flag word and Struct B first 8 bytes */ - *PesPtr++ = (crazyFramerate >> 0) & 0xff; - *PesPtr++ = (crazyFramerate >> 8) & 0xff; - *PesPtr++ = (crazyFramerate >> 16) & 0xff; - *PesPtr++ = crazyFramerate >> 24; + *PesPtr++ = (crazyFramerate >> 0) & 0xff; + *PesPtr++ = (crazyFramerate >> 8) & 0xff; + *PesPtr++ = (crazyFramerate >> 16) & 0xff; + *PesPtr++ = crazyFramerate >> 24; - MetadataLength = PesPtr - &PesPacket[PES_MIN_HEADER_SIZE]; + MetadataLength = PesPtr - &PesPacket[PES_MIN_HEADER_SIZE]; - int HeaderLength = InsertPesHeader (PesPacket, MetadataLength, VC1_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, 0); + int HeaderLength = + InsertPesHeader(PesPacket, MetadataLength, + VC1_VIDEO_PES_START_CODE, INVALID_PTS_VALUE, + 0); - len = write(call->fd,PesPacket, HeaderLength + MetadataLength); + len = write(call->fd, PesPacket, HeaderLength + MetadataLength); - initialHeader = 0; + initialHeader = 0; } - if(call->len > 0 && call->data) { - unsigned int Position = 0; - unsigned char insertSampleHeader = 1; - while(Position < call->len) { + if (call->len > 0 && call->data) { + unsigned int Position = 0; + unsigned char insertSampleHeader = 1; + while (Position < call->len) { - int PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ? - (call->len - Position) : MAX_PES_PACKET_SIZE; + int PacketLength = + (call->len - Position) <= + MAX_PES_PACKET_SIZE ? (call->len - + Position) : MAX_PES_PACKET_SIZE; - int Remaining = call->len - Position - PacketLength; + int Remaining = call->len - Position - PacketLength; - wmv_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", PacketLength, Remaining, Position); + wmv_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", + PacketLength, Remaining, Position); - unsigned char PesHeader[PES_MAX_HEADER_SIZE]; - memset (PesHeader, '0', PES_MAX_HEADER_SIZE); - int HeaderLength = InsertPesHeader (PesHeader, PacketLength, VC1_VIDEO_PES_START_CODE, call->Pts, 0); - unsigned char* PacketStart; + unsigned char PesHeader[PES_MAX_HEADER_SIZE]; + memset(PesHeader, '0', PES_MAX_HEADER_SIZE); + int HeaderLength = + InsertPesHeader(PesHeader, PacketLength, + VC1_VIDEO_PES_START_CODE, call->Pts, 0); + unsigned char *PacketStart; - if(insertSampleHeader) { - unsigned int PesLength; - unsigned int PrivateHeaderLength; + if (insertSampleHeader) { + unsigned int PesLength; + unsigned int PrivateHeaderLength; - PrivateHeaderLength = InsertVideoPrivateDataHeader (&PesHeader[HeaderLength], - call->len); - /* Update PesLength */ - PesLength = PesHeader[PES_LENGTH_BYTE_0] + - (PesHeader[PES_LENGTH_BYTE_1] << 8) + PrivateHeaderLength; - PesHeader[PES_LENGTH_BYTE_0] = PesLength & 0xff; - PesHeader[PES_LENGTH_BYTE_1] = (PesLength >> 8) & 0xff; - PesHeader[PES_HEADER_DATA_LENGTH_BYTE] += PrivateHeaderLength; - PesHeader[PES_FLAGS_BYTE] |= PES_EXTENSION_DATA_PRESENT; + PrivateHeaderLength = + InsertVideoPrivateDataHeader(&PesHeader[HeaderLength], + call->len); + /* Update PesLength */ + PesLength = PesHeader[PES_LENGTH_BYTE_0] + + (PesHeader[PES_LENGTH_BYTE_1] << 8) + + PrivateHeaderLength; + PesHeader[PES_LENGTH_BYTE_0] = PesLength & 0xff; + PesHeader[PES_LENGTH_BYTE_1] = (PesLength >> 8) & 0xff; + PesHeader[PES_HEADER_DATA_LENGTH_BYTE] += + PrivateHeaderLength; + PesHeader[PES_FLAGS_BYTE] |= PES_EXTENSION_DATA_PRESENT; - HeaderLength += PrivateHeaderLength; - insertSampleHeader = 0; - } + HeaderLength += PrivateHeaderLength; + insertSampleHeader = 0; + } - PacketStart = malloc(call->len + HeaderLength); - memcpy (PacketStart, PesHeader, HeaderLength); - memcpy (PacketStart + HeaderLength, call->data + Position, PacketLength); + PacketStart = malloc(call->len + HeaderLength); + memcpy(PacketStart, PesHeader, HeaderLength); + memcpy(PacketStart + HeaderLength, call->data + Position, + PacketLength); - len = write(call->fd, PacketStart, PacketLength + HeaderLength); - free(PacketStart); + len = + write(call->fd, PacketStart, PacketLength + HeaderLength); + free(PacketStart); - Position += PacketLength; - call->Pts = INVALID_PTS_VALUE; - } + Position += PacketLength; + call->Pts = INVALID_PTS_VALUE; + } } wmv_printf(10, "< %d\n", len); diff --git a/libeplayer3/output/writer/writer.c b/libeplayer3/output/writer/writer.c index 8ad6c91..c439873 100644 --- a/libeplayer3/output/writer/writer.c +++ b/libeplayer3/output/writer/writer.c @@ -58,7 +58,7 @@ if (debug_level >= level) printf(x); } while (0) /* Varaibles */ /* ***************************** */ -static Writer_t * AvailableWriter[] = { +static Writer_t *AvailableWriter[] = { &WriterAudioIPCM, &WriterAudioPCM, &WriterAudioMP3, @@ -93,35 +93,35 @@ static Writer_t * AvailableWriter[] = { /* Functions */ /* ***************************** */ -Writer_t* getWriter(char* encoding) +Writer_t *getWriter(char *encoding) { int i; - for (i = 0; AvailableWriter[i] != NULL; i++) - { - if (strcmp(AvailableWriter[i]->caps->textEncoding, encoding) == 0) - { - writer_printf(50, "%s: found writer \"%s\" for \"%s\"\n", __func__, AvailableWriter[i]->caps->name, encoding); - return AvailableWriter[i]; - } + for (i = 0; AvailableWriter[i] != NULL; i++) { + if (strcmp(AvailableWriter[i]->caps->textEncoding, encoding) == 0) { + writer_printf(50, "%s: found writer \"%s\" for \"%s\"\n", + __func__, AvailableWriter[i]->caps->name, + encoding); + return AvailableWriter[i]; + } } - writer_printf(1, "%s: no writer found for \"%s\"\n", __func__, encoding); + writer_printf(1, "%s: no writer found for \"%s\"\n", __func__, + encoding); return NULL; } -Writer_t* getDefaultVideoWriter() +Writer_t *getDefaultVideoWriter() { int i; - for (i = 0; AvailableWriter[i] != NULL; i++) - { - if (strcmp(AvailableWriter[i]->caps->textEncoding, "V_MPEG2") == 0) - { - writer_printf(50, "%s: found writer \"%s\"\n", __func__, AvailableWriter[i]->caps->name); - return AvailableWriter[i]; - } + for (i = 0; AvailableWriter[i] != NULL; i++) { + if (strcmp(AvailableWriter[i]->caps->textEncoding, "V_MPEG2") == 0) { + writer_printf(50, "%s: found writer \"%s\"\n", __func__, + AvailableWriter[i]->caps->name); + return AvailableWriter[i]; + } } writer_printf(1, "%s: no writer found\n", __func__); @@ -129,17 +129,16 @@ Writer_t* getDefaultVideoWriter() return NULL; } -Writer_t* getDefaultAudioWriter() +Writer_t *getDefaultAudioWriter() { int i; - for (i = 0; AvailableWriter[i] != NULL; i++) - { - if (strcmp(AvailableWriter[i]->caps->textEncoding, "A_MP3") == 0) - { - writer_printf(50, "%s: found writer \"%s\"\n", __func__, AvailableWriter[i]->caps->name); - return AvailableWriter[i]; - } + for (i = 0; AvailableWriter[i] != NULL; i++) { + if (strcmp(AvailableWriter[i]->caps->textEncoding, "A_MP3") == 0) { + writer_printf(50, "%s: found writer \"%s\"\n", __func__, + AvailableWriter[i]->caps->name); + return AvailableWriter[i]; + } } writer_printf(1, "%s: no writer found\n", __func__); @@ -147,18 +146,18 @@ Writer_t* getDefaultAudioWriter() return NULL; } -Writer_t* getDefaultFramebufferWriter() +Writer_t *getDefaultFramebufferWriter() { int i; - for (i = 0; AvailableWriter[i] != NULL; i++) - { - writer_printf(10, "%s\n", AvailableWriter[i]->caps->textEncoding); - if (strcmp(AvailableWriter[i]->caps->textEncoding, "framebuffer") == 0) - { - writer_printf(50, "%s: found writer \"%s\"\n", __func__, AvailableWriter[i]->caps->name); - return AvailableWriter[i]; - } + for (i = 0; AvailableWriter[i] != NULL; i++) { + writer_printf(10, "%s\n", AvailableWriter[i]->caps->textEncoding); + if (strcmp(AvailableWriter[i]->caps->textEncoding, "framebuffer") + == 0) { + writer_printf(50, "%s: found writer \"%s\"\n", __func__, + AvailableWriter[i]->caps->name); + return AvailableWriter[i]; + } } writer_printf(1, "%s: no writer found\n", __func__); diff --git a/libeplayer3/playback/playback.c b/libeplayer3/playback/playback.c index 1d0fdc3..e2c9c37 100644 --- a/libeplayer3/playback/playback.c +++ b/libeplayer3/playback/playback.c @@ -48,8 +48,8 @@ if (debug_level >= level) printf("[%s:%s] " fmt, FILENAME, __FUNCTION__, ## x); #define cERR_PLAYBACK_NO_ERROR 0 #define cERR_PLAYBACK_ERROR -1 -#define cMaxSpeed_ff 128 /* fixme: revise */ -#define cMaxSpeed_fr -320 /* fixme: revise */ +#define cMaxSpeed_ff 128 /* fixme: revise */ +#define cMaxSpeed_fr -320 /* fixme: revise */ /* ***************************** */ /* Varaibles */ @@ -61,7 +61,7 @@ static int hasThreadStarted = 0; /* ***************************** */ /* Prototypes */ /* ***************************** */ -static int PlaybackTerminate(Context_t *context); +static int PlaybackTerminate(Context_t * context); /* ***************************** */ /* MISC Functions */ @@ -71,88 +71,95 @@ static int PlaybackTerminate(Context_t *context); /* Supervisor Thread */ /* **************************** */ -static void SupervisorThread(Context_t *context) { +static void SupervisorThread(Context_t * context) +{ int status = 0, lastStatus = 0; long long int playPts = -1; long long int lastPts = -1; int dieNow = 0; int count = 0; - + playback_printf(10, ">\n"); - while ( context && context->playback && context->playback->isPlaying ) - { - if (context->container->selectedContainer != NULL) - context->container->selectedContainer->Command(context, CONTAINER_STATUS, &status); + while (context && context->playback && context->playback->isPlaying) { + if (context->container->selectedContainer != NULL) + context->container->selectedContainer->Command(context, + CONTAINER_STATUS, + &status); else - dieNow = 1; + dieNow = 1; - if (context->container->selectedContainer != NULL) - context->container->selectedContainer->Command(context, CONTAINER_LAST_PTS, &lastPts); + if (context->container->selectedContainer != NULL) + context->container->selectedContainer->Command(context, + CONTAINER_LAST_PTS, + &lastPts); #ifdef FRAMECOUNT_WORKS // This is a good place to implement buffer managment -long long int frameCount = -1; -int ret = context->playback->Command(context, PLAYBACK_GET_FRAME_COUNT, &frameCount); -playback_printf(1, "Framecount = %ull\n", frameCount); -status = 1; + long long int frameCount = -1; + int ret = + context->playback->Command(context, PLAYBACK_GET_FRAME_COUNT, + &frameCount); + playback_printf(1, "Framecount = %ull\n", frameCount); + status = 1; #endif - if ((status == 0) && (status != lastStatus)) - { - playback_printf(1, "container has ended, syncing to playback pts ...\n"); + if ((status == 0) && (status != lastStatus)) { + playback_printf(1, + "container has ended, syncing to playback pts ...\n"); #define FLUSH_AFTER_CONTAINER_ENDED #ifdef FLUSH_AFTER_CONTAINER_ENDED - // These means that we have injected everything we got, so flush it. - // As this is a thread, the call should block the thread as long as frames are beeing played. - // The main thread should not be blocked by this. - // This also helps for files which dont have any pts at all - if (context->output->Command(context, OUTPUT_FLUSH, NULL) < 0) - { - playback_err("failed to flush output.\n"); - } + // These means that we have injected everything we got, so flush it. + // As this is a thread, the call should block the thread as long as frames are beeing played. + // The main thread should not be blocked by this. + // This also helps for files which dont have any pts at all + if (context->output->Command(context, OUTPUT_FLUSH, NULL) < 0) { + playback_err("failed to flush output.\n"); + } #endif - while (!dieNow) - { - if (context && context->playback && context->playback->abortRequested) + while (!dieNow) { + if (context && context->playback + && context->playback->abortRequested) + dieNow = 1; + else if (context && context->playback + && context->playback->isPlaying) { + int ret = + context->playback->Command(context, PLAYBACK_PTS, + &playPts); + + playback_err + ("playbackPts %lld ->lastPts %lld ret %d\n", + playPts, lastPts, ret); + + if (ret != cERR_PLAYBACK_NO_ERROR + || playPts + (2 * 90000) >= lastPts) dieNow = 1; - else if (context && context->playback && context->playback->isPlaying) - { - int ret = context->playback->Command(context, PLAYBACK_PTS, &playPts); - playback_err("playbackPts %lld ->lastPts %lld ret %d\n", playPts, lastPts, ret); - - if (ret != cERR_PLAYBACK_NO_ERROR || playPts + (2 * 90000) >= lastPts) - dieNow = 1; - - } - else - { - playback_err("playback already died ?\n"); - dieNow = 1; - } - - count++; - - if (count == 200) - { + } else { + playback_err("playback already died ?\n"); + dieNow = 1; + } + + count++; + + if (count == 200) { // playback_err("something went wrong, expect end but never reached?\n"); - dieNow = 1; - } - usleep(10000); - } - } - - lastStatus = status; + dieNow = 1; + } + usleep(10000); + } + } - if (dieNow) - break; - - usleep(10000); + lastStatus = status; - } /* while */ + if (dieNow) + break; + + usleep(10000); + + } /* while */ playback_printf(10, "<\n"); @@ -166,20 +173,21 @@ status = 1; /* Functions */ /* ***************************** */ -static int PlaybackStop(Context_t *context); +static int PlaybackStop(Context_t * context); -static int PlaybackOpen(Context_t *context, char * uri) { +static int PlaybackOpen(Context_t * context, char *uri) +{ if (context->playback->isPlaying) PlaybackStop(context); playback_printf(10, "URI=%s\n", uri); - if (context->playback->isPlaying) { // shouldn't happen - playback_err("playback already running\n"); - return cERR_PLAYBACK_ERROR; + if (context->playback->isPlaying) { // shouldn't happen + playback_err("playback already running\n"); + return cERR_PLAYBACK_ERROR; } - char * extension = NULL; + char *extension = NULL; context->playback->uri = strdup(uri); @@ -187,46 +195,58 @@ static int PlaybackOpen(Context_t *context, char * uri) { 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); - context->playback->noprobe = 1; - } else - context->playback->noprobe = 0; + context->playback->isFile = 1; + if (!strncmp("myts://", uri, 7)) { + memcpy(context->playback->uri, "file", 4); + context->playback->noprobe = 1; + } else + context->playback->noprobe = 0; - extension = getExtension(context->playback->uri+7); - if(!extension) - return cERR_PLAYBACK_ERROR; + extension = getExtension(context->playback->uri + 7); + if (!extension) + return cERR_PLAYBACK_ERROR; - //CHECK FOR SUBTITLES - if (context->container && context->container->textSrtContainer) - context->container->textSrtContainer->Command(context, CONTAINER_INIT, context->playback->uri+7); + //CHECK FOR SUBTITLES + if (context->container && context->container->textSrtContainer) + context->container->textSrtContainer->Command(context, + CONTAINER_INIT, + context-> + playback->uri + + 7); - if (context->container && context->container->textSsaContainer) - context->container->textSsaContainer->Command(context, CONTAINER_INIT, context->playback->uri+7); + if (context->container && context->container->textSsaContainer) + 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); + if (context->container && context->container->assContainer) + context->container->assContainer->Command(context, + CONTAINER_INIT, + NULL); } else if (strstr(uri, "://")) { - context->playback->isHttp = 1; - 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, "mmst", 4); - free(context->playback->uri); - context->playback->uri = tUri; - } + context->playback->isHttp = 1; + 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, "mmst", 4); + free(context->playback->uri); + context->playback->uri = tUri; + } } else { playback_err("Unknown stream (%s)\n", uri); 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)) + 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"); @@ -234,21 +254,23 @@ static int PlaybackOpen(Context_t *context, char * uri) { return cERR_PLAYBACK_NO_ERROR; } -static int PlaybackClose(Context_t *context) { +static int PlaybackClose(Context_t * context) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "\n"); - if (context->container->Command(context, CONTAINER_DEL, NULL) < 0) - { - playback_err("container delete failed\n"); + if (context->container->Command(context, CONTAINER_DEL, NULL) < 0) { + playback_err("container delete failed\n"); } if (context->container && context->container->textSrtContainer) - context->container->textSrtContainer->Command(context, CONTAINER_DEL, NULL); + context->container->textSrtContainer->Command(context, + CONTAINER_DEL, NULL); if (context->container && context->container->textSsaContainer) - context->container->textSsaContainer->Command(context, CONTAINER_DEL, NULL); + context->container->textSsaContainer->Command(context, + CONTAINER_DEL, NULL); context->manager->audio->Command(context, MANAGER_DEL, NULL); context->manager->video->Command(context, MANAGER_DEL, NULL); @@ -256,13 +278,13 @@ static int PlaybackClose(Context_t *context) { context->manager->dvbsubtitle->Command(context, MANAGER_DEL, NULL); context->manager->teletext->Command(context, MANAGER_DEL, NULL); - context->playback->isPaused = 0; - context->playback->isPlaying = 0; + context->playback->isPaused = 0; + context->playback->isPlaying = 0; context->playback->isForwarding = 0; - context->playback->BackWard = 0; - context->playback->SlowMotion = 0; - context->playback->Speed = 0; - if(context->playback->uri) { + context->playback->BackWard = 0; + context->playback->SlowMotion = 0; + context->playback->Speed = 0; + if (context->playback->uri) { free(context->playback->uri); context->playback->uri = NULL; } @@ -272,70 +294,76 @@ static int PlaybackClose(Context_t *context) { return ret; } -static int PlaybackPlay(Context_t *context) { +static int PlaybackPlay(Context_t * context) +{ pthread_attr_t attr; int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "\n"); if (!context->playback->isPlaying) { - context->playback->AVSync = 1; - context->output->Command(context, OUTPUT_AVSYNC, NULL); + context->playback->AVSync = 1; + context->output->Command(context, OUTPUT_AVSYNC, NULL); - context->playback->isCreationPhase = 1; // allows the created thread to go into wait mode - ret = context->output->Command(context, OUTPUT_PLAY, NULL); + context->playback->isCreationPhase = 1; // allows the created thread to go into wait mode + ret = context->output->Command(context, OUTPUT_PLAY, NULL); - if (ret != 0) { - playback_err("OUTPUT_PLAY failed!\n"); - playback_err("clearing isCreationPhase!\n"); + if (ret != 0) { + playback_err("OUTPUT_PLAY failed!\n"); + playback_err("clearing isCreationPhase!\n"); - context->playback->isCreationPhase = 0; // allow thread to go into next state - } else { - context->playback->isPlaying = 1; - context->playback->isPaused = 0; - context->playback->isForwarding = 0; - if (context->playback->BackWard) { - context->playback->BackWard = 0; - context->output->Command(context, OUTPUT_AUDIOMUTE, "0"); + context->playback->isCreationPhase = 0; // allow thread to go into next state + } else { + context->playback->isPlaying = 1; + context->playback->isPaused = 0; + context->playback->isForwarding = 0; + if (context->playback->BackWard) { + context->playback->BackWard = 0; + context->output->Command(context, OUTPUT_AUDIOMUTE, "0"); } - context->playback->SlowMotion = 0; - context->playback->Speed = 1; + context->playback->SlowMotion = 0; + context->playback->Speed = 1; - if (hasThreadStarted == 0) { - int error; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + if (hasThreadStarted == 0) { + int error; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, + PTHREAD_CREATE_DETACHED); - if((error = pthread_create(&supervisorThread, &attr, (void *)&SupervisorThread, context)) != 0) - { - playback_printf(10, "Error creating thread, error:%d:%s\n", error,strerror(error)); + if ((error = + pthread_create(&supervisorThread, &attr, + (void *) &SupervisorThread, + context)) != 0) { + playback_printf(10, + "Error creating thread, error:%d:%s\n", + error, strerror(error)); - hasThreadStarted = 0; - ret = cERR_PLAYBACK_ERROR; - } - else - { - playback_printf(10, "Created thread\n"); + hasThreadStarted = 0; + ret = cERR_PLAYBACK_ERROR; + } else { + playback_printf(10, "Created thread\n"); - hasThreadStarted = 1; - } - } + hasThreadStarted = 1; + } + } - playback_printf(10, "clearing isCreationPhase!\n"); + playback_printf(10, "clearing isCreationPhase!\n"); - context->playback->isCreationPhase = 0; // allow thread to go into next state + context->playback->isCreationPhase = 0; // allow thread to go into next state - ret = context->container->selectedContainer->Command(context, CONTAINER_PLAY, NULL); - if (ret != 0) { - playback_err("CONTAINER_PLAY failed!\n"); - } + ret = + context->container->selectedContainer->Command(context, + CONTAINER_PLAY, + NULL); + if (ret != 0) { + playback_err("CONTAINER_PLAY failed!\n"); + } - } + } - } else - { - playback_err("playback already running\n"); - ret = cERR_PLAYBACK_ERROR; + } else { + playback_err("playback already running\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(10, "exiting with value %d\n", ret); @@ -343,31 +371,31 @@ static int PlaybackPlay(Context_t *context) { return ret; } -static int PlaybackPause(Context_t *context) { +static int PlaybackPause(Context_t * context) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "\n"); if (context->playback->isPlaying && !context->playback->isPaused) { - if(context->playback->SlowMotion) - context->output->Command(context, OUTPUT_CLEAR, NULL); + if (context->playback->SlowMotion) + context->output->Command(context, OUTPUT_CLEAR, NULL); - context->output->Command(context, OUTPUT_PAUSE, NULL); + context->output->Command(context, OUTPUT_PAUSE, NULL); - context->playback->isPaused = 1; - //context->playback->isPlaying = 1; - context->playback->isForwarding = 0; + context->playback->isPaused = 1; + //context->playback->isPlaying = 1; + context->playback->isForwarding = 0; if (context->playback->BackWard) { - context->playback->BackWard = 0; + context->playback->BackWard = 0; context->output->Command(context, OUTPUT_AUDIOMUTE, "0"); } - context->playback->SlowMotion = 0; - context->playback->Speed = 1; - } else - { - playback_err("playback not playing or already in pause mode\n"); - ret = cERR_PLAYBACK_ERROR; + context->playback->SlowMotion = 0; + context->playback->Speed = 1; + } else { + playback_err("playback not playing or already in pause mode\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(10, "exiting with value %d\n", ret); @@ -375,32 +403,34 @@ static int PlaybackPause(Context_t *context) { return ret; } -static int PlaybackContinue(Context_t *context) { +static int PlaybackContinue(Context_t * context) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "\n"); if (context->playback->isPlaying && - (context->playback->isPaused || context->playback->isForwarding || context->playback->BackWard || context->playback->SlowMotion)) { + (context->playback->isPaused || context->playback->isForwarding + || context->playback->BackWard + || context->playback->SlowMotion)) { - if(context->playback->SlowMotion) - context->output->Command(context, OUTPUT_CLEAR, NULL); + if (context->playback->SlowMotion) + context->output->Command(context, OUTPUT_CLEAR, NULL); - context->output->Command(context, OUTPUT_CONTINUE, NULL); + context->output->Command(context, OUTPUT_CONTINUE, NULL); - context->playback->isPaused = 0; - //context->playback->isPlaying = 1; - context->playback->isForwarding = 0; + context->playback->isPaused = 0; + //context->playback->isPlaying = 1; + context->playback->isForwarding = 0; if (context->playback->BackWard) { - context->playback->BackWard = 0; + context->playback->BackWard = 0; context->output->Command(context, OUTPUT_AUDIOMUTE, "0"); } - context->playback->SlowMotion = 0; - context->playback->Speed = 1; - } else - { - playback_err("continue not possible\n"); - ret = cERR_PLAYBACK_ERROR; + context->playback->SlowMotion = 0; + context->playback->Speed = 1; + } else { + playback_err("continue not possible\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(10, "exiting with value %d\n", ret); @@ -408,7 +438,8 @@ static int PlaybackContinue(Context_t *context) { return ret; } -static int PlaybackStop(Context_t *context) { +static int PlaybackStop(Context_t * context) +{ int ret = cERR_PLAYBACK_NO_ERROR; int wait_time = 20; @@ -416,35 +447,38 @@ static int PlaybackStop(Context_t *context) { if (context && context->playback && context->playback->isPlaying) { - context->playback->isPaused = 0; - context->playback->isPlaying = 0; - context->playback->isForwarding = 0; + context->playback->isPaused = 0; + context->playback->isPlaying = 0; + context->playback->isForwarding = 0; if (context->playback->BackWard) { - context->playback->BackWard = 0; + context->playback->BackWard = 0; context->output->Command(context, OUTPUT_AUDIOMUTE, "0"); } - context->playback->SlowMotion = 0; - context->playback->Speed = 0; + context->playback->SlowMotion = 0; + context->playback->Speed = 0; - context->output->Command(context, OUTPUT_STOP, NULL); - context->container->selectedContainer->Command(context, CONTAINER_STOP, NULL); + context->output->Command(context, OUTPUT_STOP, NULL); + context->container->selectedContainer->Command(context, + CONTAINER_STOP, + NULL); - } else - { - playback_err("stop not possible\n"); - ret = cERR_PLAYBACK_ERROR; + } else { + playback_err("stop not possible\n"); + ret = cERR_PLAYBACK_ERROR; } - while ( (hasThreadStarted != 0) && (--wait_time) > 0 ) { - playback_printf(10, "Waiting for supervisor thread to terminate itself, will try another %d times\n", wait_time); + while ((hasThreadStarted != 0) && (--wait_time) > 0) { + playback_printf(10, + "Waiting for supervisor thread to terminate itself, will try another %d times\n", + wait_time); - usleep(100000); + usleep(100000); } if (wait_time == 0) { - playback_err( "Timeout waiting for thread!\n"); + playback_err("Timeout waiting for thread!\n"); - ret = cERR_PLAYBACK_ERROR; + ret = cERR_PLAYBACK_ERROR; } playback_printf(10, "exiting with value %d\n", ret); @@ -452,49 +486,54 @@ static int PlaybackStop(Context_t *context) { return ret; } -static int PlaybackTerminate(Context_t *context) { +static int PlaybackTerminate(Context_t * context) +{ int ret = cERR_PLAYBACK_NO_ERROR; int wait_time = 20; playback_printf(20, "\n"); - if ( context && context->playback && context->playback->isPlaying ) { - //First Flush and than delete container, else e2 cant read length of file anymore + if (context && context->playback && context->playback->isPlaying) { + //First Flush and than delete container, else e2 cant read length of file anymore - if (context->output->Command(context, OUTPUT_FLUSH, NULL) < 0) - { - playback_err("failed to flush output.\n"); - } + if (context->output->Command(context, OUTPUT_FLUSH, NULL) < 0) { + playback_err("failed to flush output.\n"); + } - ret = context->container->selectedContainer->Command(context, CONTAINER_STOP, NULL); + ret = + context->container->selectedContainer->Command(context, + CONTAINER_STOP, + NULL); - context->playback->isPaused = 0; - context->playback->isPlaying = 0; - context->playback->isForwarding = 0; - context->playback->BackWard = 0; - context->playback->SlowMotion = 0; - context->playback->Speed = 0; + context->playback->isPaused = 0; + context->playback->isPlaying = 0; + context->playback->isForwarding = 0; + context->playback->BackWard = 0; + context->playback->SlowMotion = 0; + context->playback->Speed = 0; - } else - { - playback_err("%p %p %d\n", context, context->playback, context->playback->isPlaying); + } else { + playback_err("%p %p %d\n", context, context->playback, + context->playback->isPlaying); - /* fixme: konfetti: we should return an error here but this seems to be a condition which - * can happen and is not a real error, which leads to a dead neutrino. should investigate - * here later. - */ + /* fixme: konfetti: we should return an error here but this seems to be a condition which + * can happen and is not a real error, which leads to a dead neutrino. should investigate + * here later. + */ } - while ( (hasThreadStarted != 0) && (--wait_time) > 0 ) { - playback_printf(10, "Waiting for supervisor thread to terminate itself, will try another %d times\n", wait_time); + while ((hasThreadStarted != 0) && (--wait_time) > 0) { + playback_printf(10, + "Waiting for supervisor thread to terminate itself, will try another %d times\n", + wait_time); - usleep(100000); + usleep(100000); } if (wait_time == 0) { - playback_err( "Timeout waiting for thread!\n"); + playback_err("Timeout waiting for thread!\n"); - ret = cERR_PLAYBACK_ERROR; + ret = cERR_PLAYBACK_ERROR; } playback_printf(20, "exiting with value %d\n", ret); @@ -502,30 +541,34 @@ static int PlaybackTerminate(Context_t *context) { return ret; } -static int PlaybackFastForward(Context_t *context, int* speed) { +static int PlaybackFastForward(Context_t * context, int *speed) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "speed %d\n", *speed); /* Audio only forwarding not supported */ - if (context->playback->isVideo && !context->playback->isHttp && !context->playback->BackWard && (!context->playback->isPaused || context->playback->isPlaying)) { + if (context->playback->isVideo && !context->playback->isHttp + && !context->playback->BackWard && (!context->playback->isPaused + || context->playback-> + isPlaying)) { - if ((*speed <= 0) || (*speed > cMaxSpeed_ff)) - { - playback_err("speed %d out of range (1 - %d) \n", *speed, cMaxSpeed_ff); - return cERR_PLAYBACK_ERROR; - } + if ((*speed <= 0) || (*speed > cMaxSpeed_ff)) { + playback_err("speed %d out of range (1 - %d) \n", *speed, + cMaxSpeed_ff); + return cERR_PLAYBACK_ERROR; + } - context->playback->isForwarding = 1; - context->playback->Speed = *speed; + context->playback->isForwarding = 1; + context->playback->Speed = *speed; - playback_printf(20, "Speed: %d x {%d}\n", *speed, context->playback->Speed); + playback_printf(20, "Speed: %d x {%d}\n", *speed, + context->playback->Speed); - context->output->Command(context, OUTPUT_FASTFORWARD, NULL); - } else - { - playback_err("fast forward not possible\n"); - ret = cERR_PLAYBACK_ERROR; + context->output->Command(context, OUTPUT_FASTFORWARD, NULL); + } else { + playback_err("fast forward not possible\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(10, "exiting with value %d\n", ret); @@ -533,85 +576,87 @@ static int PlaybackFastForward(Context_t *context, int* speed) { return ret; } -static int PlaybackFastBackward(Context_t *context,int* speed) { +static int PlaybackFastBackward(Context_t * context, int *speed) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "speed = %d\n", *speed); /* Audio only reverse play not supported */ - if (context->playback->isVideo && !context->playback->isForwarding && (!context->playback->isPaused || context->playback->isPlaying)) { + if (context->playback->isVideo && !context->playback->isForwarding + && (!context->playback->isPaused + || context->playback->isPlaying)) { - if ((*speed > 0) || (*speed < cMaxSpeed_fr)) - { - playback_err("speed %d out of range (0 - %d) \n", *speed, cMaxSpeed_fr); - return cERR_PLAYBACK_ERROR; - } + if ((*speed > 0) || (*speed < cMaxSpeed_fr)) { + playback_err("speed %d out of range (0 - %d) \n", *speed, + cMaxSpeed_fr); + return cERR_PLAYBACK_ERROR; + } - if (*speed == 0) - { - context->playback->BackWard = 0; - context->playback->Speed = 0; /* reverse end */ - } else - { - context->playback->isSeeking = 1; - context->playback->Speed = *speed; - context->playback->BackWard = 1; - - playback_printf(1, "S %d B %d\n", context->playback->Speed, context->playback->BackWard); - } + if (*speed == 0) { + context->playback->BackWard = 0; + context->playback->Speed = 0; /* reverse end */ + } else { + context->playback->isSeeking = 1; + context->playback->Speed = *speed; + context->playback->BackWard = 1; - context->output->Command(context, OUTPUT_CLEAR, NULL); - if (context->output->Command(context, OUTPUT_REVERSE, NULL) < 0) - { - playback_err("OUTPUT_REVERSE failed\n"); - context->playback->BackWard = 0; - context->playback->Speed = 1; - context->playback->isSeeking = 0; - ret = cERR_PLAYBACK_ERROR; - } - } else - { - playback_err("fast backward not possible\n"); - ret = cERR_PLAYBACK_ERROR; + playback_printf(1, "S %d B %d\n", context->playback->Speed, + context->playback->BackWard); + } + + context->output->Command(context, OUTPUT_CLEAR, NULL); + if (context->output->Command(context, OUTPUT_REVERSE, NULL) < 0) { + playback_err("OUTPUT_REVERSE failed\n"); + context->playback->BackWard = 0; + context->playback->Speed = 1; + context->playback->isSeeking = 0; + ret = cERR_PLAYBACK_ERROR; + } + } else { + playback_err("fast backward not possible\n"); + ret = cERR_PLAYBACK_ERROR; } if (context->playback->BackWard) - context->output->Command(context, OUTPUT_AUDIOMUTE, "1"); + context->output->Command(context, OUTPUT_AUDIOMUTE, "1"); context->playback->isSeeking = 0; playback_printf(10, "exiting with value %d\n", ret); return ret; } -static int PlaybackSlowMotion(Context_t *context,int* speed) { +static int PlaybackSlowMotion(Context_t * context, int *speed) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "\n"); //Audio only forwarding not supported - if (context->playback->isVideo && !context->playback->isHttp && context->playback->isPlaying) { - if(context->playback->isPaused) - PlaybackContinue(context); + if (context->playback->isVideo && !context->playback->isHttp + && context->playback->isPlaying) { + if (context->playback->isPaused) + PlaybackContinue(context); - switch(*speed) { - case 2: - context->playback->SlowMotion = 2; - break; - case 4: - context->playback->SlowMotion = 4; - break; - case 8: - context->playback->SlowMotion = 8; - break; - } + switch (*speed) { + case 2: + context->playback->SlowMotion = 2; + break; + case 4: + context->playback->SlowMotion = 4; + break; + case 8: + context->playback->SlowMotion = 8; + break; + } - playback_printf(20, "SlowMotion: %d x {%d}\n", *speed, context->playback->SlowMotion); + playback_printf(20, "SlowMotion: %d x {%d}\n", *speed, + context->playback->SlowMotion); - context->output->Command(context, OUTPUT_SLOWMOTION, NULL); - } else - { - playback_err("slowmotion not possible\n"); - ret = cERR_PLAYBACK_ERROR; + context->output->Command(context, OUTPUT_SLOWMOTION, NULL); + } else { + playback_err("slowmotion not possible\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(10, "exiting with value %d\n", ret); @@ -619,27 +664,33 @@ static int PlaybackSlowMotion(Context_t *context,int* speed) { return ret; } -static int PlaybackSeek(Context_t *context, float * pos, int absolute) { +static int PlaybackSeek(Context_t * context, float *pos, int absolute) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "pos: %f\n", *pos); - if (context->playback->isPlaying && !context->playback->isForwarding && !context->playback->BackWard && !context->playback->SlowMotion && !context->playback->isPaused) { - context->playback->isSeeking = 1; + if (context->playback->isPlaying && !context->playback->isForwarding + && !context->playback->BackWard && !context->playback->SlowMotion + && !context->playback->isPaused) { + context->playback->isSeeking = 1; - context->output->Command(context, OUTPUT_CLEAR, NULL); + context->output->Command(context, OUTPUT_CLEAR, NULL); if (absolute) - context->container->selectedContainer->Command(context, CONTAINER_SEEK_ABS, pos); + context->container->selectedContainer->Command(context, + CONTAINER_SEEK_ABS, + pos); else - context->container->selectedContainer->Command(context, CONTAINER_SEEK, pos); + context->container->selectedContainer->Command(context, + CONTAINER_SEEK, + pos); - context->playback->isSeeking = 0; + context->playback->isSeeking = 0; - } else - { - playback_err("not possible\n"); - ret = cERR_PLAYBACK_ERROR; + } else { + playback_err("not possible\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(10, "exiting with value %d\n", ret); @@ -647,7 +698,8 @@ static int PlaybackSeek(Context_t *context, float * pos, int absolute) { return ret; } -static int PlaybackPts(Context_t *context, unsigned long long int* pts) { +static int PlaybackPts(Context_t * context, unsigned long long int *pts) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(20, "\n"); @@ -655,11 +707,10 @@ static int PlaybackPts(Context_t *context, unsigned long long int* pts) { *pts = 0; if (context->playback->isPlaying) { - ret = context->output->Command(context, OUTPUT_PTS, pts); - } else - { - playback_err("not possible\n"); - ret = cERR_PLAYBACK_ERROR; + ret = context->output->Command(context, OUTPUT_PTS, pts); + } else { + playback_err("not possible\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(20, "exiting with value %d\n", ret); @@ -667,7 +718,9 @@ static int PlaybackPts(Context_t *context, unsigned long long int* pts) { return ret; } -static int PlaybackGetFrameCount(Context_t *context, unsigned long long int* frameCount) { +static int PlaybackGetFrameCount(Context_t * context, + unsigned long long int *frameCount) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(20, "\n"); @@ -675,11 +728,12 @@ static int PlaybackGetFrameCount(Context_t *context, unsigned long long int* fr *frameCount = 0; if (context->playback->isPlaying) { - ret = context->output->Command(context, OUTPUT_GET_FRAME_COUNT, frameCount); - } else - { - playback_err("not possible\n"); - ret = cERR_PLAYBACK_ERROR; + ret = + context->output->Command(context, OUTPUT_GET_FRAME_COUNT, + frameCount); + } else { + playback_err("not possible\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(20, "exiting with value %d\n", ret); @@ -687,7 +741,8 @@ static int PlaybackGetFrameCount(Context_t *context, unsigned long long int* fr return ret; } -static int PlaybackLength(Context_t *context, double* length) { +static int PlaybackLength(Context_t * context, double *length) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(20, "\n"); @@ -695,12 +750,13 @@ static int PlaybackLength(Context_t *context, double* length) { *length = -1; if (context->playback->isPlaying) { - if (context->container && context->container->selectedContainer) - context->container->selectedContainer->Command(context, CONTAINER_LENGTH, length); - } else - { - playback_err("not possible\n"); - ret = cERR_PLAYBACK_ERROR; + if (context->container && context->container->selectedContainer) + context->container->selectedContainer->Command(context, + CONTAINER_LENGTH, + length); + } else { + playback_err("not possible\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(20, "exiting with value %d\n", ret); @@ -708,7 +764,8 @@ static int PlaybackLength(Context_t *context, double* length) { return ret; } -static int PlaybackSwitchAudio(Context_t *context, int* track) { +static int PlaybackSwitchAudio(Context_t * context, int *track) +{ int ret = cERR_PLAYBACK_NO_ERROR; int curtrackid = 0; int nextrackid = 0; @@ -716,28 +773,33 @@ static int PlaybackSwitchAudio(Context_t *context, int* track) { playback_printf(10, "\n"); if (context->playback->isPlaying) { - if (context->manager && context->manager->audio) { - context->manager->audio->Command(context, MANAGER_GET, &curtrackid); - context->manager->audio->Command(context, MANAGER_SET, track); - context->manager->audio->Command(context, MANAGER_GET, &nextrackid); - } + if (context->manager && context->manager->audio) { + context->manager->audio->Command(context, MANAGER_GET, + &curtrackid); + context->manager->audio->Command(context, MANAGER_SET, track); + context->manager->audio->Command(context, MANAGER_GET, + &nextrackid); + } - if(nextrackid != curtrackid) { + if (nextrackid != curtrackid) { - //PlaybackPause(context); + //PlaybackPause(context); - if (context->output && context->output->audio) - context->output->audio->Command(context, OUTPUT_SWITCH, (void*)"audio"); + if (context->output && context->output->audio) + context->output->audio->Command(context, OUTPUT_SWITCH, + (void *) "audio"); - if (context->container && context->container->selectedContainer) - context->container->selectedContainer->Command(context, CONTAINER_SWITCH_AUDIO, &nextrackid); + if (context->container + && context->container->selectedContainer) + context->container->selectedContainer->Command(context, + CONTAINER_SWITCH_AUDIO, + &nextrackid); - //PlaybackContinue(context); - } - } else - { - playback_err("switch audio not possible\n"); - ret = cERR_PLAYBACK_ERROR; + //PlaybackContinue(context); + } + } else { + playback_err("switch audio not possible\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(10, "exiting with value %d\n", ret); @@ -745,62 +807,80 @@ static int PlaybackSwitchAudio(Context_t *context, int* track) { return ret; } -static int PlaybackSwitchSubtitle(Context_t *context, int* track) { +static int PlaybackSwitchSubtitle(Context_t * context, int *track) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "Track: %d\n", *track); - if (context && context->playback && context->playback->isPlaying ) { - if (context->manager && context->manager->subtitle) { - int trackid; - - if (context->manager->subtitle->Command(context, MANAGER_SET, track) < 0) - { - playback_err("manager set track failed\n"); - } + if (context && context->playback && context->playback->isPlaying) { + if (context->manager && context->manager->subtitle) { + int trackid; + + if (context->manager->subtitle-> + Command(context, MANAGER_SET, track) < 0) { + playback_err("manager set track failed\n"); + } #if 0 if (*track < 0) { //CHECK FOR SUBTITLES - if (context->container && context->container->textSrtContainer) - context->container->textSrtContainer->Command(context, CONTAINER_INIT, context->playback->uri+7); + if (context->container + && context->container->textSrtContainer) + context->container->textSrtContainer->Command(context, + CONTAINER_INIT, + context-> + playback-> + uri + 7); - if (context->container && context->container->textSsaContainer) - context->container->textSsaContainer->Command(context, CONTAINER_INIT, context->playback->uri+7); + if (context->container + && context->container->textSsaContainer) + 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); + context->container->assContainer->Command(context, + CONTAINER_INIT, + NULL); } #endif - context->manager->subtitle->Command(context, MANAGER_GET, &trackid); + context->manager->subtitle->Command(context, MANAGER_GET, + &trackid); /* konfetti: I make this hack a little bit nicer, * but its still a hack in my opinion ;) */ - if (context->container && context->container->assContainer) - context->container->assContainer->Command(context, CONTAINER_SWITCH_SUBTITLE, &trackid); + if (context->container && context->container->assContainer) + context->container->assContainer->Command(context, + CONTAINER_SWITCH_SUBTITLE, + &trackid); - if (trackid >= TEXTSRTOFFSET) - { - if (context->container && context->container->textSrtContainer) - context->container->textSrtContainer->Command(context, CONTAINER_SWITCH_SUBTITLE, &trackid); - } - if (trackid >= TEXTSSAOFFSET) - { - if (context->container && context->container->textSsaContainer) - context->container->textSsaContainer->Command(context, CONTAINER_SWITCH_SUBTITLE, &trackid); - } - - - - } else - { - ret = cERR_PLAYBACK_ERROR; - playback_err("no subtitle\n"); - } - } else - { - playback_err("not possible\n"); - ret = cERR_PLAYBACK_ERROR; + if (trackid >= TEXTSRTOFFSET) { + if (context->container + && context->container->textSrtContainer) + context->container->textSrtContainer->Command(context, + CONTAINER_SWITCH_SUBTITLE, + &trackid); + } + if (trackid >= TEXTSSAOFFSET) { + if (context->container + && context->container->textSsaContainer) + context->container->textSsaContainer->Command(context, + CONTAINER_SWITCH_SUBTITLE, + &trackid); + } + + + + } else { + ret = cERR_PLAYBACK_ERROR; + playback_err("no subtitle\n"); + } + } else { + playback_err("not possible\n"); + ret = cERR_PLAYBACK_ERROR; } playback_printf(10, "exiting with value %d\n", ret); @@ -808,39 +888,21 @@ static int PlaybackSwitchSubtitle(Context_t *context, int* track) { return ret; } -static int PlaybackSwitchDVBSubtitle(Context_t *context, int* pid) { +static int PlaybackSwitchDVBSubtitle(Context_t * context, int *pid) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "Track: %d\n", *pid); - if (context && context->manager && context->manager->dvbsubtitle ) { - if (context->manager->dvbsubtitle->Command(context, *pid < 0 ? MANAGER_DEL : MANAGER_SET, pid) < 0) { - playback_err("dvbsub manager set track failed\n"); - ret = cERR_PLAYBACK_ERROR; - } - } else - playback_err("no dvbsubtitle\n"); - - if (*pid < 0) - container_ffmpeg_update_tracks(context, context->playback->uri, 0); - - playback_printf(10, "exiting with value %d\n", ret); - - return ret; -} - -static int PlaybackSwitchTeletext(Context_t *context, int* pid) { - int ret = cERR_PLAYBACK_NO_ERROR; - - playback_printf(10, "Track: %d\n", *pid); - - if (context && context->manager && context->manager->teletext ) { - if (context->manager->teletext->Command(context, *pid < 0 ? MANAGER_DEL : MANAGER_SET, pid)) { - playback_err("ttxsub manager set track failed\n"); - ret = cERR_PLAYBACK_ERROR; + if (context && context->manager && context->manager->dvbsubtitle) { + if (context->manager->dvbsubtitle-> + Command(context, *pid < 0 ? MANAGER_DEL : MANAGER_SET, + pid) < 0) { + playback_err("dvbsub manager set track failed\n"); + ret = cERR_PLAYBACK_ERROR; } } else - playback_err("no ttxsubtitle\n"); + playback_err("no dvbsubtitle\n"); if (*pid < 0) container_ffmpeg_update_tracks(context, context->playback->uri, 0); @@ -850,7 +912,31 @@ static int PlaybackSwitchTeletext(Context_t *context, int* pid) { return ret; } -static int PlaybackInfo(Context_t *context, char** infoString) { +static int PlaybackSwitchTeletext(Context_t * context, int *pid) +{ + int ret = cERR_PLAYBACK_NO_ERROR; + + playback_printf(10, "Track: %d\n", *pid); + + if (context && context->manager && context->manager->teletext) { + if (context->manager->teletext-> + Command(context, *pid < 0 ? MANAGER_DEL : MANAGER_SET, pid)) { + playback_err("ttxsub manager set track failed\n"); + ret = cERR_PLAYBACK_ERROR; + } + } else + playback_err("no ttxsubtitle\n"); + + if (*pid < 0) + container_ffmpeg_update_tracks(context, context->playback->uri, 0); + + playback_printf(10, "exiting with value %d\n", ret); + + return ret; +} + +static int PlaybackInfo(Context_t * context, char **infoString) +{ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(10, "\n"); @@ -862,115 +948,122 @@ static int PlaybackInfo(Context_t *context, char** infoString) { */ if (context->container && context->container->selectedContainer) - context->container->selectedContainer->Command(context, CONTAINER_INFO, infoString); + context->container->selectedContainer->Command(context, + CONTAINER_INFO, + infoString); playback_printf(10, "exiting with value %d\n", ret); return ret; } -static int Command(void* _context, PlaybackCmd_t command, void * argument) { - Context_t* context = (Context_t*) _context; /* to satisfy compiler */ +static int Command(void *_context, PlaybackCmd_t command, void *argument) +{ + Context_t *context = (Context_t *) _context; /* to satisfy compiler */ int ret = cERR_PLAYBACK_NO_ERROR; playback_printf(20, "Command %d\n", command); - switch(command) { - case PLAYBACK_OPEN: { - ret = PlaybackOpen(context, (char*)argument); - break; - } - case PLAYBACK_CLOSE: { - ret = PlaybackClose(context); - break; - } - case PLAYBACK_PLAY: { - ret = PlaybackPlay(context); - break; - } - case PLAYBACK_STOP: { - ret = PlaybackStop(context); - break; - } - case PLAYBACK_PAUSE: { // 4 - ret = PlaybackPause(context); - break; - } - case PLAYBACK_CONTINUE: { - ret = PlaybackContinue(context); - break; - } - case PLAYBACK_TERM: { - ret = PlaybackTerminate(context); - break; - } - case PLAYBACK_FASTFORWARD: { - ret = PlaybackFastForward(context,(int*)argument); - break; - } - case PLAYBACK_SEEK: { - ret = PlaybackSeek(context, (float*)argument, 0); - break; - } - case PLAYBACK_SEEK_ABS: { - ret = PlaybackSeek(context, (float*)argument, -1); - break; - } - case PLAYBACK_PTS: { // 10 - ret = PlaybackPts(context, (unsigned long long int*)argument); - break; - } - case PLAYBACK_LENGTH: { // 11 - ret = PlaybackLength(context, (double*)argument); - break; - } - case PLAYBACK_SWITCH_AUDIO: { - ret = PlaybackSwitchAudio(context, (int*)argument); - break; - } - case PLAYBACK_SWITCH_SUBTITLE: { - ret = PlaybackSwitchSubtitle(context, (int*)argument); - break; - } - case PLAYBACK_INFO: { - ret = PlaybackInfo(context, (char**)argument); - break; - } - case PLAYBACK_SLOWMOTION: { - ret = PlaybackSlowMotion(context,(int*)argument); - break; - } - case PLAYBACK_FASTBACKWARD: { - ret = PlaybackFastBackward(context,(int*)argument); - break; - } - case PLAYBACK_GET_FRAME_COUNT: { // 10 - ret = PlaybackGetFrameCount(context, (unsigned long long int*)argument); - break; - } - case PLAYBACK_SWITCH_DVBSUBTITLE: { - ret = PlaybackSwitchDVBSubtitle(context, (int*)argument); - break; - } - case PLAYBACK_SWITCH_TELETEXT: { - ret = PlaybackSwitchTeletext(context, (int*)argument); - break; - } - case PLAYBACK_FRAMEBUFFER_LOCK: { - context->playback->mayWriteToFramebuffer = 0; - ret = cERR_PLAYBACK_NO_ERROR; - break; - } - case PLAYBACK_FRAMEBUFFER_UNLOCK: { - context->playback->mayWriteToFramebuffer = 1; - ret = cERR_PLAYBACK_NO_ERROR; - break; - } + switch (command) { + case PLAYBACK_OPEN:{ + ret = PlaybackOpen(context, (char *) argument); + break; + } + case PLAYBACK_CLOSE:{ + ret = PlaybackClose(context); + break; + } + case PLAYBACK_PLAY:{ + ret = PlaybackPlay(context); + break; + } + case PLAYBACK_STOP:{ + ret = PlaybackStop(context); + break; + } + case PLAYBACK_PAUSE:{ // 4 + ret = PlaybackPause(context); + break; + } + case PLAYBACK_CONTINUE:{ + ret = PlaybackContinue(context); + break; + } + case PLAYBACK_TERM:{ + ret = PlaybackTerminate(context); + break; + } + case PLAYBACK_FASTFORWARD:{ + ret = PlaybackFastForward(context, (int *) argument); + break; + } + case PLAYBACK_SEEK:{ + ret = PlaybackSeek(context, (float *) argument, 0); + break; + } + case PLAYBACK_SEEK_ABS:{ + ret = PlaybackSeek(context, (float *) argument, -1); + break; + } + case PLAYBACK_PTS:{ // 10 + ret = + PlaybackPts(context, (unsigned long long int *) argument); + break; + } + case PLAYBACK_LENGTH:{ // 11 + ret = PlaybackLength(context, (double *) argument); + break; + } + case PLAYBACK_SWITCH_AUDIO:{ + ret = PlaybackSwitchAudio(context, (int *) argument); + break; + } + case PLAYBACK_SWITCH_SUBTITLE:{ + ret = PlaybackSwitchSubtitle(context, (int *) argument); + break; + } + case PLAYBACK_INFO:{ + ret = PlaybackInfo(context, (char **) argument); + break; + } + case PLAYBACK_SLOWMOTION:{ + ret = PlaybackSlowMotion(context, (int *) argument); + break; + } + case PLAYBACK_FASTBACKWARD:{ + ret = PlaybackFastBackward(context, (int *) argument); + break; + } + case PLAYBACK_GET_FRAME_COUNT:{ + // 10 + ret = + PlaybackGetFrameCount(context, + (unsigned long long int *) argument); + break; + } + case PLAYBACK_SWITCH_DVBSUBTITLE:{ + ret = PlaybackSwitchDVBSubtitle(context, (int *) argument); + break; + } + case PLAYBACK_SWITCH_TELETEXT:{ + ret = PlaybackSwitchTeletext(context, (int *) argument); + break; + } + case PLAYBACK_FRAMEBUFFER_LOCK:{ + context->playback->mayWriteToFramebuffer = 0; + ret = cERR_PLAYBACK_NO_ERROR; + break; + } + case PLAYBACK_FRAMEBUFFER_UNLOCK:{ + context->playback->mayWriteToFramebuffer = 1; + ret = cERR_PLAYBACK_NO_ERROR; + break; + } default: - playback_err("PlaybackCmd %d not supported!\n", command); - ret = cERR_PLAYBACK_ERROR; - break; + playback_err("PlaybackCmd %d not supported!\n", command); + ret = cERR_PLAYBACK_ERROR; + break; } playback_printf(20, "exiting with value %d\n", ret); diff --git a/libeplayer3/tools/eplayer2.c b/libeplayer3/tools/eplayer2.c index 75d3aa8..de1e634 100644 --- a/libeplayer3/tools/eplayer2.c +++ b/libeplayer3/tools/eplayer2.c @@ -29,579 +29,676 @@ #include "common.h" #include "subtitle.h" -extern OutputHandler_t OutputHandler; -extern PlaybackHandler_t PlaybackHandler; -extern ContainerHandler_t ContainerHandler; -extern ManagerHandler_t ManagerHandler; +extern OutputHandler_t OutputHandler; +extern PlaybackHandler_t PlaybackHandler; +extern ContainerHandler_t ContainerHandler; +extern ManagerHandler_t ManagerHandler; -Context_t * player = NULL; +Context_t *player = NULL; /* ******************************************** */ /* Framebuffer for subtitle */ /* ******************************************** */ -static int fd = -1; -static unsigned char* lfb = NULL; +static int fd = -1; +static unsigned char *lfb = NULL; struct fb_fix_screeninfo fix; struct fb_var_screeninfo screeninfo, oldscreen; -static int stride = 0; -static int xRes = 0; -static int yRes = 0; -static int bpp = 0; +static int stride = 0; +static int xRes = 0; +static int yRes = 0; +static int bpp = 0; -int kbhit(void) { - struct timeval tv; - fd_set read_fd; +int kbhit(void) +{ + struct timeval tv; + fd_set read_fd; - tv.tv_sec=1; - tv.tv_usec=0; + tv.tv_sec = 1; + tv.tv_usec = 0; - FD_ZERO(&read_fd); - FD_SET(0,&read_fd); + FD_ZERO(&read_fd); + FD_SET(0, &read_fd); - if(select(1, &read_fd, NULL, NULL, &tv) == -1) - return 0; + if (select(1, &read_fd, NULL, NULL, &tv) == -1) + return 0; - if(FD_ISSET(0,&read_fd)) - return 1; + if (FD_ISSET(0, &read_fd)) + return 1; - return 0; + return 0; } void framebuffer_init() { - int available = 0; + int available = 0; - fd = open("/dev/fb0", O_RDWR); + fd = open("/dev/fb0", O_RDWR); - if (fd < 0) - { - perror("/dev/fb0"); - return; - } + if (fd < 0) { + perror("/dev/fb0"); + return; + } - if (ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo) < 0) - { - perror("FBIOGET_VSCREENINFO"); - return; - } + if (ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo) < 0) { + perror("FBIOGET_VSCREENINFO"); + return; + } - memcpy(&oldscreen, &screeninfo, sizeof(screeninfo)); + memcpy(&oldscreen, &screeninfo, sizeof(screeninfo)); - ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo); - - printf("mode %d, %d, %d\n", screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel); + ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo); - if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0) - { - perror("FBIOGET_FSCREENINFO"); - printf("fb failed\n"); - } + printf("mode %d, %d, %d\n", screeninfo.xres, screeninfo.yres, + screeninfo.bits_per_pixel); - stride = fix.line_length; - xRes = screeninfo.xres; - yRes = screeninfo.yres; - bpp = screeninfo.bits_per_pixel; + if (ioctl(fd, FBIOGET_FSCREENINFO, &fix) < 0) { + perror("FBIOGET_FSCREENINFO"); + printf("fb failed\n"); + } - printf("stride = %d, width %d\n", stride, xRes); + stride = fix.line_length; + xRes = screeninfo.xres; + yRes = screeninfo.yres; + bpp = screeninfo.bits_per_pixel; - available = fix.smem_len; + printf("stride = %d, width %d\n", stride, xRes); - printf("%dk video mem\n", available/1024); + available = fix.smem_len; - lfb = (unsigned char*) mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0); + printf("%dk video mem\n", available / 1024); - if (lfb == NULL) - { - perror("mmap"); - return; - } + lfb = + (unsigned char *) mmap(0, available, PROT_WRITE | PROT_READ, + MAP_SHARED, fd, 0); + + if (lfb == NULL) { + perror("mmap"); + return; + } memset(lfb, 0, available); } -int main(int argc,char* argv[]) { +int main(int argc, char *argv[]) +{ SubtitleOutputDef_t out; int showInfos = 0, noinput = 0; - char file[255] = {""}; + char file[255] = { "" }; int speed = 0, speedmap = 0; printf("%s >\n", __FILE__); - if (argc < 2) - { - printf("give me a filename please\n"); - exit(1); + if (argc < 2) { + printf("give me a filename please\n"); + exit(1); } - if (strstr(argv[1], "://") == NULL) - { - strcpy(file, "file://"); + if (strstr(argv[1], "://") == NULL) { + strcpy(file, "file://"); } strcat(file, argv[1]); /* debug helper */ - if(argc == 3 && !strcmp(argv[2], "-d")) - { - showInfos = 1; + if (argc == 3 && !strcmp(argv[2], "-d")) { + showInfos = 1; } - if(argc == 3 && !strcmp(argv[2], "-n")) - noinput = 1; + if (argc == 3 && !strcmp(argv[2], "-n")) + noinput = 1; player = malloc(sizeof(Context_t)); - player->playback = &PlaybackHandler; - player->output = &OutputHandler; - player->container = &ContainerHandler; - player->manager = &ManagerHandler; + player->playback = &PlaybackHandler; + player->output = &OutputHandler; + player->container = &ContainerHandler; + player->manager = &ManagerHandler; printf("%s\n", player->output->Name); //Registrating output devices - player->output->Command(player,OUTPUT_ADD, "audio"); - player->output->Command(player,OUTPUT_ADD, "video"); - player->output->Command(player,OUTPUT_ADD, "subtitle"); + player->output->Command(player, OUTPUT_ADD, "audio"); + player->output->Command(player, OUTPUT_ADD, "video"); + player->output->Command(player, OUTPUT_ADD, "subtitle"); framebuffer_init(); /* for testing ass subtitles */ out.screen_width = xRes; out.screen_height = yRes; - out.destination = (uint32_t *)lfb; - out.destStride = stride; + out.destination = (uint32_t *) lfb; + out.destStride = stride; - player->output->subtitle->Command(player, (OutputCmd_t)OUTPUT_SET_SUBTITLE_OUTPUT, (void*) &out); + player->output->subtitle->Command(player, + (OutputCmd_t) + OUTPUT_SET_SUBTITLE_OUTPUT, + (void *) &out); - if(player->playback->Command(player, PLAYBACK_OPEN, file) < 0) - return 10; + if (player->playback->Command(player, PLAYBACK_OPEN, file) < 0) + return 10; { - char ** TrackList = NULL; - player->manager->audio->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) { - printf("AudioTrack List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i+=2) { - printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); - free(TrackList[i]); - free(TrackList[i+1]); - } - free(TrackList); - } + char **TrackList = NULL; + player->manager->audio->Command(player, MANAGER_LIST, &TrackList); + if (TrackList != NULL) { + printf("AudioTrack List\n"); + int i = 0; + for (i = 0; TrackList[i] != NULL; i += 2) { + printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); + free(TrackList[i]); + free(TrackList[i + 1]); + } + free(TrackList); + } - player->manager->video->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) { - printf("VideoTrack List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i+=2) { - printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); - free(TrackList[i]); - free(TrackList[i+1]); - } - free(TrackList); - } + player->manager->video->Command(player, MANAGER_LIST, &TrackList); + if (TrackList != NULL) { + printf("VideoTrack List\n"); + int i = 0; + for (i = 0; TrackList[i] != NULL; i += 2) { + printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); + free(TrackList[i]); + free(TrackList[i + 1]); + } + free(TrackList); + } - player->manager->subtitle->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) { - printf("SubtitleTrack List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i+=2) { - printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); - free(TrackList[i]); - free(TrackList[i+1]); - } - free(TrackList); - } + player->manager->subtitle->Command(player, MANAGER_LIST, + &TrackList); + if (TrackList != NULL) { + printf("SubtitleTrack List\n"); + int i = 0; + for (i = 0; TrackList[i] != NULL; i += 2) { + printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]); + free(TrackList[i]); + free(TrackList[i + 1]); + } + free(TrackList); + } } { - int AudioTrackId = -1; - char * AudioTrackEncoding = NULL; - char * AudioTrackName = NULL; - player->manager->audio->Command(player, MANAGER_GET, &AudioTrackId); - player->manager->audio->Command(player, MANAGER_GETENCODING, &AudioTrackEncoding); - player->manager->audio->Command(player, MANAGER_GETNAME, &AudioTrackName); - printf("Current Audio Track : %d %s %s\n", AudioTrackId, AudioTrackEncoding, AudioTrackName); - free(AudioTrackEncoding); - free(AudioTrackName); - AudioTrackEncoding = NULL; - AudioTrackName = NULL; + int AudioTrackId = -1; + char *AudioTrackEncoding = NULL; + char *AudioTrackName = NULL; + player->manager->audio->Command(player, MANAGER_GET, + &AudioTrackId); + player->manager->audio->Command(player, MANAGER_GETENCODING, + &AudioTrackEncoding); + player->manager->audio->Command(player, MANAGER_GETNAME, + &AudioTrackName); + printf("Current Audio Track : %d %s %s\n", AudioTrackId, + AudioTrackEncoding, AudioTrackName); + free(AudioTrackEncoding); + free(AudioTrackName); + AudioTrackEncoding = NULL; + AudioTrackName = NULL; - player->manager->video->Command(player, MANAGER_GET, &AudioTrackId); - player->manager->video->Command(player, MANAGER_GETENCODING, &AudioTrackEncoding); - player->manager->video->Command(player, MANAGER_GETNAME, &AudioTrackName); - printf("Current Video Track : %d %s %s\n", AudioTrackId, AudioTrackEncoding, AudioTrackName); - free(AudioTrackEncoding); - free(AudioTrackName); - AudioTrackEncoding = NULL; - AudioTrackName = NULL; + player->manager->video->Command(player, MANAGER_GET, + &AudioTrackId); + player->manager->video->Command(player, MANAGER_GETENCODING, + &AudioTrackEncoding); + player->manager->video->Command(player, MANAGER_GETNAME, + &AudioTrackName); + printf("Current Video Track : %d %s %s\n", AudioTrackId, + AudioTrackEncoding, AudioTrackName); + free(AudioTrackEncoding); + free(AudioTrackName); + AudioTrackEncoding = NULL; + AudioTrackName = NULL; - player->manager->subtitle->Command(player, MANAGER_GET, &AudioTrackId); - player->manager->subtitle->Command(player, MANAGER_GETENCODING, &AudioTrackEncoding); - player->manager->subtitle->Command(player, MANAGER_GETNAME, &AudioTrackName); - printf("Current Subtitle Track : %d %s %s\n", AudioTrackId, AudioTrackEncoding, AudioTrackName); - free(AudioTrackEncoding); - free(AudioTrackName); - AudioTrackEncoding = NULL; - AudioTrackName = NULL; + player->manager->subtitle->Command(player, MANAGER_GET, + &AudioTrackId); + player->manager->subtitle->Command(player, MANAGER_GETENCODING, + &AudioTrackEncoding); + player->manager->subtitle->Command(player, MANAGER_GETNAME, + &AudioTrackName); + printf("Current Subtitle Track : %d %s %s\n", AudioTrackId, + AudioTrackEncoding, AudioTrackName); + free(AudioTrackEncoding); + free(AudioTrackName); + AudioTrackEncoding = NULL; + AudioTrackName = NULL; - /* player->manager->audio->Command(player, MANAGER_SET, 2); - player->manager->audio->Command(player, MANAGER_GET, &AudioTrackId); - player->manager->audio->Command(player, MANAGER_GETNAME, &AudioTrackName); - free(AudioTrackName); - AudioTrackName = NULL;*/ + /* player->manager->audio->Command(player, MANAGER_SET, 2); + player->manager->audio->Command(player, MANAGER_GET, &AudioTrackId); + player->manager->audio->Command(player, MANAGER_GETNAME, &AudioTrackName); + free(AudioTrackName); + AudioTrackName = NULL; */ } { - player->output->Command(player, OUTPUT_OPEN, NULL); + player->output->Command(player, OUTPUT_OPEN, NULL); - if (showInfos == 1) - { - char *tags[] = - { - "Title", - "Artist", - "Album", - "Year", - "Genre", - "Comment", - "Track", - "Copyright", - "TestLibEplayer", - NULL - }; - int i = 0; - while (tags[i] != NULL) - { - char* tag = tags[i]; - player->playback->Command(player, PLAYBACK_INFO, &tag); + if (showInfos == 1) { + char *tags[] = { + "Title", + "Artist", + "Album", + "Year", + "Genre", + "Comment", + "Track", + "Copyright", + "TestLibEplayer", + NULL + }; + int i = 0; + while (tags[i] != NULL) { + char *tag = tags[i]; + player->playback->Command(player, PLAYBACK_INFO, &tag); #if !defined(VDR1722) - if (tag != NULL) - printf("\t%s:\t%s\n",tags[i], tag); - else - printf("\t%s:\tNULL\n",tags[i]); + if (tag != NULL) + printf("\t%s:\t%s\n", tags[i], tag); + else + printf("\t%s:\tNULL\n", tags[i]); #endif - i++; - } + i++; + } - player->output->Command(player, OUTPUT_CLOSE, NULL); + player->output->Command(player, OUTPUT_CLOSE, NULL); - exit(1); - } else - player->playback->Command(player, PLAYBACK_PLAY, NULL); + exit(1); + } else + player->playback->Command(player, PLAYBACK_PLAY, NULL); - /*{ - int pid = 0; - player->playback->Command(player, PLAYBACK_SWITCH_SUBTITLE, (void*)&pid); - }*/ + /*{ + int pid = 0; + player->playback->Command(player, PLAYBACK_SWITCH_SUBTITLE, (void*)&pid); + } */ - while(player->playback->isPlaying) { - int Key = 0; + while (player->playback->isPlaying) { + int Key = 0; - if(kbhit()) - if(noinput == 0) - Key = getchar(); + if (kbhit()) + if (noinput == 0) + Key = getchar(); - if(!player->playback->isPlaying) { - break; - } + if (!player->playback->isPlaying) { + break; + } - if(Key == 0) - continue; + if (Key == 0) + continue; - switch (Key) { - case 'a': { - int Key2 = getchar(); - switch (Key2) { - case 'l': { - char ** TrackList = NULL; - player->manager->audio->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) { - printf("AudioTrack List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i+=2) { - printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); - free(TrackList[i]); - free(TrackList[i+1]); - } - free(TrackList); - } - break; - } - case 'c': { - int AudioTrackId = -1; - char * AudioTrackEncoding = NULL; - char * AudioTrackName = NULL; - player->manager->audio->Command(player, MANAGER_GET, &AudioTrackId); - player->manager->audio->Command(player, MANAGER_GETENCODING, &AudioTrackEncoding); - player->manager->audio->Command(player, MANAGER_GETNAME, &AudioTrackName); - printf("Current Audio Track : %d %s %s\n", AudioTrackId, AudioTrackEncoding, AudioTrackName); - free(AudioTrackEncoding); - free(AudioTrackName); - AudioTrackEncoding = NULL; - AudioTrackName = NULL; - - break; - } - default: { - Key2 -= 0x30; - if(Key2 >= 0 && Key2 <= 9) { - player->playback->Command(player, PLAYBACK_SWITCH_AUDIO, (void*)&Key2); - } - - } - } - break; - } - - case 's': { - int Key2 = getchar(); - switch (Key2) { - case 'l': { - char ** TrackList = NULL; - player->manager->subtitle->Command(player, MANAGER_LIST, &TrackList); - if (TrackList != NULL) { - printf("SubtitleTrack List\n"); - int i = 0; - for (i = 0; TrackList[i] != NULL; i+=2) { - printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); - free(TrackList[i]); - free(TrackList[i+1]); - } - free(TrackList); - } - break; - } - case 'c': { - int SubtitleTrackId = -1; - char * SubtitleTrackEncoding = NULL; - char * SubtitleTrackName = NULL; - player->manager->subtitle->Command(player, MANAGER_GET, &SubtitleTrackId); - player->manager->subtitle->Command(player, MANAGER_GETENCODING, &SubtitleTrackEncoding); - player->manager->subtitle->Command(player, MANAGER_GETNAME, &SubtitleTrackName); - printf("Current Subtitle Track : %d %s %s\n", SubtitleTrackId, SubtitleTrackEncoding, SubtitleTrackName); - free(SubtitleTrackEncoding); - free(SubtitleTrackName); - SubtitleTrackEncoding = NULL; - SubtitleTrackName = NULL; - - break; - } - default: { - Key2 -= 0x30; - if(Key2 >= 0 && Key2 <= 9) { - player->playback->Command(player, PLAYBACK_SWITCH_SUBTITLE, (void*)&Key2); - } - - } - } - break; - } - - - case 'q': - player->playback->Command(player, PLAYBACK_STOP, NULL); - break; - - case 'c': - player->playback->Command(player, PLAYBACK_CONTINUE, NULL); - break; - - case 'p': - player->playback->Command(player, PLAYBACK_PAUSE, NULL); - break; - - case 'f': { - - if (speed < 0) - speed = 0; - - speed++; - - if (speed > 7) - speed = 1; - - switch(speed) - { - case 1: speedmap = 1; break; - case 2: speedmap = 3; break; - case 3: speedmap = 7; break; - case 4: speedmap = 15; break; - case 5: speedmap = 31; break; - case 6: speedmap = 63; break; - case 7: speedmap = 127; break; - } - - player->playback->Command(player, PLAYBACK_FASTFORWARD, &speedmap); - break; - } - - case 'b': { - if (speed > 0) - speed = 0; - - speed--; - - if (speed < -7) - speed = -1; - - switch(speed) - { - case -1: speedmap = -5; break; - case -2: speedmap = -10; break; - case -3: speedmap = -20; break; - case -4: speedmap = -40; break; - case -5: speedmap = -80; break; - case -6: speedmap = -160; break; - case -7: speedmap = -320; break; - } - - player->playback->Command(player, PLAYBACK_FASTBACKWARD, &speedmap); - break; - } -#if defined(VDR1722) - case 'g': { - char gotoString [256]; - gets (gotoString); - int gotoPos = atoi(gotoString); - - double length = 0; - float sec; - - printf("gotoPos %i\n", gotoPos); - if (player->container && player->container->selectedContainer) - player->container->selectedContainer->Command(player, CONTAINER_LENGTH, &length); - - if(gotoPos <= 0){ - printf("kleiner als erlaubt\n"); - sec = 0.0; - }else if(gotoPos >= ((int)length - 10)){ - printf("laenger als erlaubt\n"); - sec = (int)length - 10; - }else{ - printf("normal action\n"); - sec = gotoPos; + switch (Key) { + case 'a':{ + int Key2 = getchar(); + switch (Key2) { + case 'l':{ + char **TrackList = NULL; + player->manager->audio->Command(player, + MANAGER_LIST, + &TrackList); + if (TrackList != NULL) { + printf("AudioTrack List\n"); + int i = 0; + for (i = 0; TrackList[i] != NULL; i += 2) { + printf("\t%s - %s\n", TrackList[i], + TrackList[i + 1]); + free(TrackList[i]); + free(TrackList[i + 1]); } + free(TrackList); + } + break; + } + case 'c':{ + int AudioTrackId = -1; + char *AudioTrackEncoding = NULL; + char *AudioTrackName = NULL; + player->manager->audio->Command(player, + MANAGER_GET, + &AudioTrackId); + player->manager->audio->Command(player, + MANAGER_GETENCODING, + &AudioTrackEncoding); + player->manager->audio->Command(player, + MANAGER_GETNAME, + &AudioTrackName); + printf("Current Audio Track : %d %s %s\n", + AudioTrackId, AudioTrackEncoding, + AudioTrackName); + free(AudioTrackEncoding); + free(AudioTrackName); + AudioTrackEncoding = NULL; + AudioTrackName = NULL; - player->playback->Command(player, PLAYBACK_SEEK, (void*)&sec); - printf("goto postion (%i sec)\n", sec); - break; - } -#endif - case 'k': { -#if !defined(VDR1722) - int Key2 = getchar() - 48; - float sec=0.0; - printf("seconds %d \n", Key2); - switch (Key2) { - case 1: sec=-15.0;break; - case 4: sec=-60.0;break; - case 7: sec=-300.0;break; - case 3: sec= 15.0;break; - case 6: sec= 60.0;break; - case 9: sec= 300.0;break; - } -#else - char seek [256]; - gets (seek); - unsigned int seekTo = atoi(seek); - double length = 0; - float sec; - - unsigned long long int CurrentPTS = 0; - player->playback->Command(player, PLAYBACK_PTS, &CurrentPTS); - if (player->container && player->container->selectedContainer) - player->container->selectedContainer->Command(player, CONTAINER_LENGTH, &length); - - int CurrentSec = CurrentPTS / 90000; - printf("CurrentSec = %i, seekTo = %i, abs(seekTo) = %i seekTo + CurrentSec %i\n", CurrentSec, seekTo, abs(seekTo), (seekTo + CurrentSec)); - int ergSec = CurrentSec + seekTo; - if(ergSec < 0){ - printf("kleiner als erlaubt\n"); - sec = 0.0; - }else if((CurrentSec + seekTo) >= ((int)length - 10)){ - printf("laenger als erlaubt\n"); - sec = (int)length - 10; - }else{ - printf("normal action\n"); - sec = seekTo + CurrentSec; + break; + } + default:{ + Key2 -= 0x30; + if (Key2 >= 0 && Key2 <= 9) { + player->playback->Command(player, + PLAYBACK_SWITCH_AUDIO, + (void *) &Key2); + } + + } + } + break; } - printf("springe %i \n", (int)sec); + case 's':{ + int Key2 = getchar(); + switch (Key2) { + case 'l':{ + char **TrackList = NULL; + player->manager->subtitle->Command(player, + MANAGER_LIST, + &TrackList); + if (TrackList != NULL) { + printf("SubtitleTrack List\n"); + int i = 0; + for (i = 0; TrackList[i] != NULL; i += 2) { + printf("\t%s - %s\n", TrackList[i], + TrackList[i + 1]); + free(TrackList[i]); + free(TrackList[i + 1]); + } + free(TrackList); + } + break; + } + case 'c':{ + int SubtitleTrackId = -1; + char *SubtitleTrackEncoding = NULL; + char *SubtitleTrackName = NULL; + player->manager->subtitle->Command(player, + MANAGER_GET, + &SubtitleTrackId); + player->manager->subtitle->Command(player, + MANAGER_GETENCODING, + &SubtitleTrackEncoding); + player->manager->subtitle->Command(player, + MANAGER_GETNAME, + &SubtitleTrackName); + printf("Current Subtitle Track : %d %s %s\n", + SubtitleTrackId, SubtitleTrackEncoding, + SubtitleTrackName); + free(SubtitleTrackEncoding); + free(SubtitleTrackName); + SubtitleTrackEncoding = NULL; + SubtitleTrackName = NULL; + + break; + } + default:{ + Key2 -= 0x30; + if (Key2 >= 0 && Key2 <= 9) { + player->playback->Command(player, + PLAYBACK_SWITCH_SUBTITLE, + (void *) &Key2); + } + + } + } + break; + } + + + case 'q': + player->playback->Command(player, PLAYBACK_STOP, NULL); + break; + + case 'c': + player->playback->Command(player, PLAYBACK_CONTINUE, NULL); + break; + + case 'p': + player->playback->Command(player, PLAYBACK_PAUSE, NULL); + break; + + case 'f':{ + + if (speed < 0) + speed = 0; + + speed++; + + if (speed > 7) + speed = 1; + + switch (speed) { + case 1: + speedmap = 1; + break; + case 2: + speedmap = 3; + break; + case 3: + speedmap = 7; + break; + case 4: + speedmap = 15; + break; + case 5: + speedmap = 31; + break; + case 6: + speedmap = 63; + break; + case 7: + speedmap = 127; + break; + } + + player->playback->Command(player, PLAYBACK_FASTFORWARD, + &speedmap); + break; + } + + case 'b':{ + if (speed > 0) + speed = 0; + + speed--; + + if (speed < -7) + speed = -1; + + switch (speed) { + case -1: + speedmap = -5; + break; + case -2: + speedmap = -10; + break; + case -3: + speedmap = -20; + break; + case -4: + speedmap = -40; + break; + case -5: + speedmap = -80; + break; + case -6: + speedmap = -160; + break; + case -7: + speedmap = -320; + break; + } + + player->playback->Command(player, + PLAYBACK_FASTBACKWARD, + &speedmap); + break; + } +#if defined(VDR1722) + case 'g':{ + char gotoString[256]; + gets(gotoString); + int gotoPos = atoi(gotoString); + + double length = 0; + float sec; + + printf("gotoPos %i\n", gotoPos); + if (player->container + && player->container->selectedContainer) + player->container->selectedContainer-> + Command(player, CONTAINER_LENGTH, &length); + + if (gotoPos <= 0) { + printf("kleiner als erlaubt\n"); + sec = 0.0; + } else if (gotoPos >= ((int) length - 10)) { + printf("laenger als erlaubt\n"); + sec = (int) length - 10; + } else { + printf("normal action\n"); + sec = gotoPos; + } + + player->playback->Command(player, PLAYBACK_SEEK, + (void *) &sec); + printf("goto postion (%i sec)\n", sec); + break; + } #endif - player->playback->Command(player, PLAYBACK_SEEK, (void*)&sec); - break; - } + case 'k':{ +#if !defined(VDR1722) + int Key2 = getchar() - 48; + float sec = 0.0; + printf("seconds %d \n", Key2); + switch (Key2) { + case 1: + sec = -15.0; + break; + case 4: + sec = -60.0; + break; + case 7: + sec = -300.0; + break; + case 3: + sec = 15.0; + break; + case 6: + sec = 60.0; + break; + case 9: + sec = 300.0; + break; + } +#else + char seek[256]; + gets(seek); + unsigned int seekTo = atoi(seek); + double length = 0; + float sec; - case 'l': { - double length = 0; - if (player->container && player->container->selectedContainer) - player->container->selectedContainer->Command(player, CONTAINER_LENGTH, &length); - printf("Length = %02d:%02d:%02d (%.4f sec)\n", (int)((length/60)/60)%60, (int)(length/60)%60, (int)length%60, length); - break; - } - case 'j': { - unsigned long long int pts = 0; - player->playback->Command(player, PLAYBACK_PTS, &pts); - unsigned long long int sec = pts / 90000; - printf("Pts = %02d:%02d:%02d (%llu.0000 sec)\n", (int)((sec/60)/60)%60, (int)(sec/60)%60, (int)sec%60, sec); - break; - } + unsigned long long int CurrentPTS = 0; + player->playback->Command(player, PLAYBACK_PTS, + &CurrentPTS); + if (player->container + && player->container->selectedContainer) + player->container->selectedContainer-> + Command(player, CONTAINER_LENGTH, &length); - case 'i': - { - char *tags[] = - { - "Title", - "Artist", - "Album", - "Year", - "Genre", - "Comment", - "Track", - "Copyright", - "TestLibEplayer", - NULL - }; - int i = 0; - while (tags[i] != NULL) - { - char* tag = tags[i]; - player->playback->Command(player, PLAYBACK_INFO, &tag); + int CurrentSec = CurrentPTS / 90000; + printf + ("CurrentSec = %i, seekTo = %i, abs(seekTo) = %i seekTo + CurrentSec %i\n", + CurrentSec, seekTo, abs(seekTo), + (seekTo + CurrentSec)); + int ergSec = CurrentSec + seekTo; + if (ergSec < 0) { + printf("kleiner als erlaubt\n"); + sec = 0.0; + } else if ((CurrentSec + seekTo) >= + ((int) length - 10)) { + printf("laenger als erlaubt\n"); + sec = (int) length - 10; + } else { + printf("normal action\n"); + sec = seekTo + CurrentSec; + } - if (tag != NULL) - printf("\t%s:\t%s\n",tags[i], tag); - else - printf("\t%s:\tNULL\n",tags[i]); - i++; - } - break; - } - default: { - printf("Control:\n"); - printf("al: List audio tracks\n"); - printf("ac: List current audio track\n"); - printf("a[id] Select audio track\n"); - printf("sl: List subtitles\n"); - printf("sc: List current subtitle\n"); - printf("s[id] Select subtitles\n"); - printf("q: Stop\n"); - printf("c: Continue\n"); - printf("p: Pause\n"); - printf("f: Increase speed (Fast forward) (stepwise)\n"); - printf("b: Decrease speed (Fast reverse) (stepwise)\n"); - printf("l: Print duration\n"); - printf("j: Print current PTS\n"); - printf("k[1,4,7]: Jump back [15,60,300] seconds\n"); - printf("k[3,6,9]: Jump forward [15,60,300] seconds\n"); - printf("i: Print Info\n"); - break; - } - } - } + printf("springe %i \n", (int) sec); +#endif + player->playback->Command(player, PLAYBACK_SEEK, + (void *) &sec); + break; + } - player->output->Command(player, OUTPUT_CLOSE, NULL); + case 'l':{ + double length = 0; + if (player->container + && player->container->selectedContainer) + player->container->selectedContainer-> + Command(player, CONTAINER_LENGTH, &length); + printf("Length = %02d:%02d:%02d (%.4f sec)\n", + (int) ((length / 60) / 60) % 60, + (int) (length / 60) % 60, (int) length % 60, + length); + break; + } + case 'j':{ + unsigned long long int pts = 0; + player->playback->Command(player, PLAYBACK_PTS, &pts); + unsigned long long int sec = pts / 90000; + printf("Pts = %02d:%02d:%02d (%llu.0000 sec)\n", + (int) ((sec / 60) / 60) % 60, + (int) (sec / 60) % 60, (int) sec % 60, sec); + break; + } + + case 'i': + { + char *tags[] = { + "Title", + "Artist", + "Album", + "Year", + "Genre", + "Comment", + "Track", + "Copyright", + "TestLibEplayer", + NULL + }; + int i = 0; + while (tags[i] != NULL) { + char *tag = tags[i]; + player->playback->Command(player, PLAYBACK_INFO, + &tag); + + if (tag != NULL) + printf("\t%s:\t%s\n", tags[i], tag); + else + printf("\t%s:\tNULL\n", tags[i]); + i++; + } + break; + } + default:{ + printf("Control:\n"); + printf("al: List audio tracks\n"); + printf("ac: List current audio track\n"); + printf("a[id] Select audio track\n"); + printf("sl: List subtitles\n"); + printf("sc: List current subtitle\n"); + printf("s[id] Select subtitles\n"); + printf("q: Stop\n"); + printf("c: Continue\n"); + printf("p: Pause\n"); + printf + ("f: Increase speed (Fast forward) (stepwise)\n"); + printf + ("b: Decrease speed (Fast reverse) (stepwise)\n"); + printf("l: Print duration\n"); + printf("j: Print current PTS\n"); + printf("k[1,4,7]: Jump back [15,60,300] seconds\n"); + printf("k[3,6,9]: Jump forward [15,60,300] seconds\n"); + printf("i: Print Info\n"); + break; + } + } + } + + player->output->Command(player, OUTPUT_CLOSE, NULL); } //printOutputCapabilities(); diff --git a/libeplayer3/tools/meta.c b/libeplayer3/tools/meta.c index 59526ac..eef98e6 100644 --- a/libeplayer3/tools/meta.c +++ b/libeplayer3/tools/meta.c @@ -12,31 +12,31 @@ #include #include -static AVFormatContext* avContext = NULL; +static AVFormatContext *avContext = NULL; void dump_metadata() { AVDictionaryEntry *tag = NULL; - while ((tag = av_dict_get(avContext->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) - printf("%s: %s\n", tag->key, tag->value); + while ((tag = + av_dict_get(avContext->metadata, "", tag, + AV_DICT_IGNORE_SUFFIX))) + printf("%s: %s\n", tag->key, tag->value); } -int main(int argc,char* argv[]) +int main(int argc, char *argv[]) { - char file[255] = {""}; + char file[255] = { "" }; unsigned int i; - int err; + int err; - if (argc < 2) - { - printf("give me a filename please\n"); - return -1; + if (argc < 2) { + printf("give me a filename please\n"); + return -1; } - if (strstr(argv[1], "://") == NULL) - { - strcpy(file, "file://"); + if (strstr(argv[1], "://") == NULL) { + strcpy(file, "file://"); } strcat(file, argv[1]); @@ -44,35 +44,34 @@ int main(int argc,char* argv[]) av_register_all(); if ((err = avformat_open_input(&avContext, file, NULL, 0)) != 0) { - char error[512]; + char error[512]; - printf("avformat_open_input failed %d (%s)\n", err, file); - av_strerror(err, error, 512); - printf("Cause: %s\n", error); + printf("avformat_open_input failed %d (%s)\n", err, file); + av_strerror(err, error, 512); + printf("Cause: %s\n", error); - return -1; + return -1; } - if (avformat_find_stream_info(avContext, NULL) < 0) - { - printf("Error avformat_find_stream_info\n"); + if (avformat_find_stream_info(avContext, NULL) < 0) { + printf("Error avformat_find_stream_info\n"); } printf("\n***\n"); dump_metadata(); printf("\nstream specific metadata:\n"); - for (i = 0; i < avContext->nb_streams; i++) - { - AVStream* stream = avContext->streams[i]; + for (i = 0; i < avContext->nb_streams; i++) { + AVStream *stream = avContext->streams[i]; - if (stream) - { - AVDictionaryEntry *tag = NULL; - if (stream->metadata != NULL) - while ((tag = av_dict_get(stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) - printf("%s: %s\n", tag->key, tag->value); - } + if (stream) { + AVDictionaryEntry *tag = NULL; + if (stream->metadata != NULL) + while ((tag = + av_dict_get(stream->metadata, "", tag, + AV_DICT_IGNORE_SUFFIX))) + printf("%s: %s\n", tag->key, tag->value); + } } return 0;