mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-27 15:33:00 +02:00
libeplayer3: c++ adjustments
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <map>
|
||||
|
||||
#include "manager.h"
|
||||
#include "common.h"
|
||||
@@ -30,7 +31,6 @@
|
||||
/* ***************************** */
|
||||
/* Makros/Constants */
|
||||
/* ***************************** */
|
||||
#define TRACKWRAP 20
|
||||
|
||||
#define SUBTITLE_MGR_DEBUG
|
||||
|
||||
@@ -64,9 +64,8 @@ static const char FILENAME[] = __FILE__;
|
||||
/* Varaibles */
|
||||
/* ***************************** */
|
||||
|
||||
static Track_t *Tracks = NULL;
|
||||
static int TrackCount = 0;
|
||||
static int CurrentTrack = -1; //no as default.
|
||||
static std::map<int,Track_t> Tracks;
|
||||
static int CurrentPid = -1;
|
||||
|
||||
/* ***************************** */
|
||||
/* Prototypes */
|
||||
@@ -78,184 +77,85 @@ static int CurrentTrack = -1; //no as default.
|
||||
|
||||
static int ManagerAdd(Context_t * context __attribute__((unused)), Track_t track)
|
||||
{
|
||||
Tracks[track.Id] = track;
|
||||
context->playback->isAudio = 1;
|
||||
|
||||
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);
|
||||
int i;
|
||||
for (i = 0; i < TRACKWRAP; i++)
|
||||
Tracks[i].Id = -1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (TrackCount < TRACKWRAP) {
|
||||
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_printf(10, "%s::%s\n", FILENAME, __FUNCTION__);
|
||||
|
||||
return cERR_SUBTITLE_MGR_NO_ERROR;
|
||||
return cERR_SUBTITLE_MGR_NO_ERROR;
|
||||
}
|
||||
|
||||
static char **ManagerList(Context_t * context __attribute__ ((unused)))
|
||||
{
|
||||
char **tracklist = NULL;
|
||||
int i = 0, j = 0;
|
||||
int j = 0;
|
||||
char **tracklist = (char **) malloc(sizeof(char *) * ((Tracks.size() * 2) + 1));
|
||||
|
||||
subtitle_mgr_printf(10, "%s::%s\n", FILENAME, __FUNCTION__);
|
||||
|
||||
if (Tracks != NULL) {
|
||||
tracklist = malloc(sizeof(char *) * ((TrackCount * 2) + 1));
|
||||
|
||||
if (tracklist == NULL) {
|
||||
subtitle_mgr_err("%s:%s malloc failed\n", FILENAME,
|
||||
__FUNCTION__);
|
||||
return NULL;
|
||||
for(std::map<int,Track_t>::iterator it = Tracks.begin(); it != Tracks.end(); ++it)
|
||||
{
|
||||
size_t len = it->second.Name.length() + 20;
|
||||
char tmp[len];
|
||||
snprintf(tmp, len, "%d %s\n", it->second.Id, it->second.Name.c_str());
|
||||
tracklist[j] = strdup(tmp);
|
||||
tracklist[j + 1] = strdup(it->second.Encoding);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
subtitle_mgr_printf(10, "%s::%s return %p (%d - %d)\n", FILENAME,
|
||||
__FUNCTION__, tracklist, j, TrackCount);
|
||||
|
||||
return tracklist;
|
||||
}
|
||||
|
||||
static int ManagerDel(Context_t * context __attribute__((unused)))
|
||||
{
|
||||
|
||||
int i = 0;
|
||||
|
||||
subtitle_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 {
|
||||
subtitle_mgr_err("%s::%s nothing to delete!\n", FILENAME,
|
||||
__FUNCTION__);
|
||||
return cERR_SUBTITLE_MGR_ERROR;
|
||||
}
|
||||
|
||||
TrackCount = 0;
|
||||
CurrentTrack = -1;
|
||||
|
||||
subtitle_mgr_printf(10, "%s::%s return no error\n", FILENAME,
|
||||
__FUNCTION__);
|
||||
|
||||
return cERR_SUBTITLE_MGR_NO_ERROR;
|
||||
Tracks.clear();
|
||||
CurrentPid = -1;
|
||||
return cERR_SUBTITLE_MGR_NO_ERROR;
|
||||
}
|
||||
|
||||
static int Command(Context_t *context, ManagerCmd_t command, void *argument)
|
||||
{
|
||||
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;
|
||||
Track_t *track = (Track_t *) argument;
|
||||
ret = ManagerAdd(context, *track);
|
||||
break;
|
||||
}
|
||||
case MANAGER_LIST:{
|
||||
container_ffmpeg_update_tracks(context, context->playback->uri);
|
||||
container_ffmpeg_update_tracks(context, context->playback->uri.c_str());
|
||||
*((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;
|
||||
*((int *) argument) = (int) CurrentPid;
|
||||
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;
|
||||
}
|
||||
if (CurrentPid > -1)
|
||||
*((Track_t **) argument) = &Tracks[CurrentPid];
|
||||
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;
|
||||
if (CurrentPid > -1)
|
||||
*((char **) argument) = strdup(Tracks[CurrentPid].Encoding);
|
||||
else
|
||||
*((char **) argument) = strdup("");
|
||||
break;
|
||||
}
|
||||
case MANAGER_GETNAME:{
|
||||
if (TrackCount > 0 && CurrentTrack >= 0)
|
||||
*((char **) argument) =
|
||||
(char *) strdup(Tracks[CurrentTrack].Name);
|
||||
else
|
||||
*((char **) argument) = (char *) strdup("");
|
||||
break;
|
||||
if (CurrentPid > -1)
|
||||
*((char **) argument) = strdup(Tracks[CurrentPid].Name.c_str());
|
||||
else
|
||||
*((char **) argument) = strdup("");
|
||||
break;
|
||||
}
|
||||
case MANAGER_SET:{
|
||||
int i;
|
||||
subtitle_mgr_printf(20, "%s::%s MANAGER_SET id=%d\n", FILENAME,
|
||||
__FUNCTION__, *((int *) argument));
|
||||
|
||||
if (*((int *) argument) < 0) {
|
||||
CurrentTrack = -1;
|
||||
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;
|
||||
}
|
||||
std::map<int,Track_t>::iterator it = Tracks.find(*((int *) argument));
|
||||
if (it != Tracks.end())
|
||||
CurrentPid = *((int *) argument);
|
||||
else
|
||||
ret = cERR_SUBTITLE_MGR_ERROR;
|
||||
break;
|
||||
}
|
||||
case MANAGER_DEL:{
|
||||
@@ -263,21 +163,17 @@ static int Command(Context_t *context, ManagerCmd_t command, void *argument)
|
||||
break;
|
||||
}
|
||||
case MANAGER_INIT_UPDATE:{
|
||||
int i;
|
||||
for (i = 0; i < TrackCount; i++)
|
||||
if (!Tracks[i].is_static)
|
||||
Tracks[i].pending = 1;
|
||||
for (std::map<int,Track_t>::iterator it = Tracks.begin(); it != Tracks.end(); ++it)
|
||||
it->second.pending = 1;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
subtitle_mgr_err("%s:%s: ConatinerCmd not supported!", FILENAME,
|
||||
__FUNCTION__);
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user