[libarmbox] playback_libeplayer3.cpp code format

This commit is contained in:
max_10
2018-08-29 12:13:43 +02:00
committed by Thilo Graf
parent 477bbc064c
commit 5402933900

View File

@@ -47,33 +47,41 @@ bool cPlayback::Open(playmode_t PlayMode)
last_size = 0; last_size = 0;
nPlaybackSpeed = 0; nPlaybackSpeed = 0;
init_jump = -1; init_jump = -1;
if (player) if (player)
free(player); free(player);
player = NULL; player = NULL;
player = (Context_t *) malloc(sizeof(Context_t)); player = (Context_t *) malloc(sizeof(Context_t));
if (player) if (player)
{ {
player->playback = &PlaybackHandler; player->playback = &PlaybackHandler;
player->output = &OutputHandler; player->output = &OutputHandler;
player->container = &ContainerHandler; player->container = &ContainerHandler;
player->manager = &ManagerHandler; player->manager = &ManagerHandler;
lt_info("%s - player output name: %s PlayMode: %s\n", __func__, player->output->Name, aPLAYMODE[PlayMode]); lt_info("%s - player output name: %s PlayMode: %s\n", __func__, player->output->Name, aPLAYMODE[PlayMode]);
} }
//Registration of output devices //Registration of output devices
if (player && player->output) if (player && player->output)
{ {
player->output->Command(player, OUTPUT_ADD, (void *)"audio"); player->output->Command(player, OUTPUT_ADD, (void *)"audio");
player->output->Command(player, OUTPUT_ADD, (void *)"video"); player->output->Command(player, OUTPUT_ADD, (void *)"video");
} }
return 0; return 0;
} }
void cPlayback::Close(void) void cPlayback::Close(void)
{ {
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
//Dagobert: movieplayer does not call stop, it calls close ;) //Dagobert: movieplayer does not call stop, it calls close ;)
if(playing) if(playing)
Stop(); Stop();
if (decoders_closed) if (decoders_closed)
{ {
audioDecoder->openDevice(); audioDecoder->openDevice();
@@ -92,7 +100,9 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in
bool ret = false; bool ret = false;
bool isHTTP = false; bool isHTTP = false;
no_probe = false; no_probe = false;
lt_info("%s - filename=%s vpid=%u vtype=%d apid=%u ac3=%d\n", __func__, filename, vpid, vtype, apid, ac3); lt_info("%s - filename=%s vpid=%u vtype=%d apid=%u ac3=%d\n", __func__, filename, vpid, vtype, apid, ac3);
init_jump = -1; init_jump = -1;
//create playback path //create playback path
mAudioStream = 0; mAudioStream = 0;
@@ -100,11 +110,14 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in
mTeletextStream = -1; mTeletextStream = -1;
unlink("/tmp/.id3coverart"); unlink("/tmp/.id3coverart");
std::string file; std::string file;
if (*filename == '/') if (*filename == '/')
file = "file://"; file = "file://";
file += filename; file += filename;
if ((file.find(":31339/id=") != std::string::npos) || (file.find(":10000") != std::string::npos) || (file.find(":8001/") != std::string::npos)) // for LocalTV and Entertain-TV streaming if ((file.find(":31339/id=") != std::string::npos) || (file.find(":10000") != std::string::npos) || (file.find(":8001/") != std::string::npos)) // for LocalTV and Entertain-TV streaming
no_probe = true; no_probe = true;
if (file.substr(0, 7) == "file://") if (file.substr(0, 7) == "file://")
{ {
if (file.substr(file.length() - 3) == ".ts") if (file.substr(file.length() - 3) == ".ts")
@@ -117,6 +130,7 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in
} }
else else
isHTTP = true; isHTTP = true;
PlayFiles_t playbackFiles = { (char *) file.c_str(), NULL, NULL, NULL, 0, 0, 0, 0}; PlayFiles_t playbackFiles = { (char *) file.c_str(), NULL, NULL, NULL, 0, 0, 0, 0};
if (player->playback->Command(player, PLAYBACK_OPEN, &playbackFiles) == 0) if (player->playback->Command(player, PLAYBACK_OPEN, &playbackFiles) == 0)
{ {
@@ -140,15 +154,16 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in
{ {
printf("AudioTrack List\n"); printf("AudioTrack List\n");
int i = 0; int i = 0;
for (i = 0; TrackList[i] != NULL; i+=2) for (i = 0; TrackList[i] != NULL; i += 2)
{ {
printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]);
free(TrackList[i]); free(TrackList[i]);
free(TrackList[i+1]); free(TrackList[i + 1]);
} }
free(TrackList); free(TrackList);
} }
} }
//SUB //SUB
if (player && player->manager && player->manager->subtitle) if (player && player->manager && player->manager->subtitle)
{ {
@@ -160,13 +175,14 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in
int i = 0; int i = 0;
for (i = 0; TrackList[i] != NULL; i+=2) for (i = 0; TrackList[i] != NULL; i+=2)
{ {
printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]);
free(TrackList[i]); free(TrackList[i]);
free(TrackList[i+1]); free(TrackList[i + 1]);
} }
free(TrackList); free(TrackList);
} }
} }
/* /*
//Teletext //Teletext
if (player && player->manager && player->manager->teletext) if (player && player->manager && player->manager->teletext)
@@ -177,15 +193,16 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in
{ {
printf("TeletextTrack List\n"); printf("TeletextTrack List\n");
int i = 0; int i = 0;
for (i = 0; TrackList[i] != NULL; i+=2) for (i = 0; TrackList[i] != NULL; i += 2)
{ {
printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]);
free(TrackList[i]); free(TrackList[i]);
free(TrackList[i+1]); free(TrackList[i + 1]);
} }
free(TrackList); free(TrackList);
} }
} }
*/ */
//Chapters //Chapters
if (player && player->manager && player->manager->chapter) if (player && player->manager && player->manager->chapter)
@@ -196,19 +213,21 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in
{ {
printf("Chapter List\n"); printf("Chapter List\n");
int i = 0; int i = 0;
for (i = 0; TrackList[i] != NULL; i+=2) for (i = 0; TrackList[i] != NULL; i += 2)
{ {
printf("\t%s - %s\n", TrackList[i], TrackList[i+1]); printf("\t%s - %s\n", TrackList[i], TrackList[i + 1]);
free(TrackList[i]); free(TrackList[i]);
free(TrackList[i+1]); free(TrackList[i + 1]);
} }
free(TrackList); free(TrackList);
} }
} }
playing = true; playing = true;
first = true; first = true;
player->output->Command(player, OUTPUT_OPEN, NULL); player->output->Command(player, OUTPUT_OPEN, NULL);
ret = (player->playback->Command(player, PLAYBACK_PLAY, NULL) == 0); ret = (player->playback->Command(player, PLAYBACK_PLAY, NULL) == 0);
if (ret && !isHTTP) if (ret && !isHTTP)
playing = ret = (player->playback->Command(player, PLAYBACK_PAUSE, NULL) == 0); playing = ret = (player->playback->Command(player, PLAYBACK_PAUSE, NULL) == 0);
} }
@@ -219,17 +238,22 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, in
bool cPlayback::Stop(void) bool cPlayback::Stop(void)
{ {
lt_info("%s playing %d\n", __func__, playing); lt_info("%s playing %d\n", __func__, playing);
if (player && player->playback) if (player && player->playback)
player->playback->Command(player, PLAYBACK_STOP, NULL); player->playback->Command(player, PLAYBACK_STOP, NULL);
if (player && player->output) if (player && player->output)
player->output->Command(player, OUTPUT_CLOSE, NULL); player->output->Command(player, OUTPUT_CLOSE, NULL);
if (player && player->output) if (player && player->output)
{ {
player->output->Command(player, OUTPUT_DEL, (void *)"audio"); player->output->Command(player, OUTPUT_DEL, (void *)"audio");
player->output->Command(player, OUTPUT_DEL, (void *)"video"); player->output->Command(player, OUTPUT_DEL, (void *)"video");
} }
if (player && player->playback) if (player && player->playback)
player->playback->Command(player, PLAYBACK_CLOSE, NULL); player->playback->Command(player, PLAYBACK_CLOSE, NULL);
playing = false; playing = false;
return true; return true;
} }
@@ -238,6 +262,7 @@ bool cPlayback::SetAPid(int pid, bool /* ac3 */)
{ {
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
int i = pid; int i = pid;
if (pid != mAudioStream) if (pid != mAudioStream)
{ {
if (player && player->playback) if (player && player->playback)
@@ -257,6 +282,7 @@ bool cPlayback::SetSubtitlePid(int pid)
{ {
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
int i = pid; int i = pid;
if (pid != mSubtitleStream) if (pid != mSubtitleStream)
{ {
if (player && player->playback) if (player && player->playback)
@@ -269,11 +295,13 @@ bool cPlayback::SetSubtitlePid(int pid)
bool cPlayback::SetTeletextPid(int pid) bool cPlayback::SetTeletextPid(int pid)
{ {
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
//int i = pid; //int i = pid;
if (pid != mTeletextStream) if (pid != mTeletextStream)
{ {
//if(player && player->playback) //if (player && player->playback)
//player->playback->Command(player, PLAYBACK_SWITCH_TELETEXT, (void*)&i); // player->playback->Command(player, PLAYBACK_SWITCH_TELETEXT, (void*)&i);
mTeletextStream = pid; mTeletextStream = pid;
} }
return true; return true;
@@ -282,6 +310,7 @@ bool cPlayback::SetTeletextPid(int pid)
bool cPlayback::SetSpeed(int speed) bool cPlayback::SetSpeed(int speed)
{ {
lt_info("%s playing %d speed %d\n", __func__, playing, speed); lt_info("%s playing %d speed %d\n", __func__, playing, speed);
if (!decoders_closed) if (!decoders_closed)
{ {
audioDecoder->closeDevice(); audioDecoder->closeDevice();
@@ -295,12 +324,15 @@ bool cPlayback::SetSpeed(int speed)
playing = true; playing = true;
} }
} }
if (!playing) if (!playing)
return false; return false;
if (player && player->playback) if (player && player->playback)
{ {
int result = 0; int result = 0;
nPlaybackSpeed = speed; nPlaybackSpeed = speed;
if (speed > 1) if (speed > 1)
{ {
/* direction switch ? */ /* direction switch ? */
@@ -337,11 +369,13 @@ bool cPlayback::SetSpeed(int speed)
{ {
result = player->playback->Command(player, PLAYBACK_CONTINUE, NULL); result = player->playback->Command(player, PLAYBACK_CONTINUE, NULL);
} }
if (init_jump > -1) if (init_jump > -1)
{ {
SetPosition(init_jump); SetPosition(init_jump);
init_jump = -1; init_jump = -1;
} }
if (result != 0) if (result != 0)
{ {
printf("returning false\n"); printf("returning false\n");
@@ -369,6 +403,7 @@ bool cPlayback::GetPosition(int &position, int &duration)
{ {
bool got_duration = false; bool got_duration = false;
lt_debug("%s %d %d\n", __func__, position, duration); lt_debug("%s %d %d\n", __func__, position, duration);
/* hack: if the file is growing (timeshift), then determine its length /* hack: if the file is growing (timeshift), then determine its length
* by comparing the mtime with the mtime of the xml file */ * by comparing the mtime with the mtime of the xml file */
if (pm == PLAYMODE_TS) if (pm == PLAYMODE_TS)
@@ -390,17 +425,21 @@ bool cPlayback::GetPosition(int &position, int &duration)
} }
} }
} }
if (!playing) if (!playing)
return false; return false;
if (player && player->playback && !player->playback->isPlaying) if (player && player->playback && !player->playback->isPlaying)
{ {
lt_info("%s !!!!EOF!!!! < -1\n", __func__); lt_info("%s !!!!EOF!!!! < -1\n", __func__);
position = duration + 1000; position = duration + 1000;
return false; return false;
} }
int64_t vpts = 0; int64_t vpts = 0;
if (player && player->playback) if (player && player->playback)
player->playback->Command(player, PLAYBACK_PTS, &vpts); player->playback->Command(player, PLAYBACK_PTS, &vpts);
if (vpts <= 0) if (vpts <= 0)
{ {
//printf("ERROR: vpts==0"); //printf("ERROR: vpts==0");
@@ -410,21 +449,31 @@ bool cPlayback::GetPosition(int &position, int &duration)
/* len is in nanoseconds. we have 90 000 pts per second. */ /* len is in nanoseconds. we have 90 000 pts per second. */
position = vpts / 90; position = vpts / 90;
} }
if (got_duration) if (got_duration)
return true; return true;
int64_t length = 0; int64_t length = 0;
if (player && player->playback) if (player && player->playback)
player->playback->Command(player, PLAYBACK_LENGTH, &length); player->playback->Command(player, PLAYBACK_LENGTH, &length);
if (length <= 0) if (length <= 0)
{
duration = duration + 1000; duration = duration + 1000;
}
else else
{
duration = length * 1000; duration = length * 1000;
}
return true; return true;
} }
bool cPlayback::SetPosition(int position, bool absolute) bool cPlayback::SetPosition(int position, bool absolute)
{ {
lt_info("%s %d\n", __func__, position); lt_info("%s %d\n", __func__, position);
if (playing && first) if (playing && first)
{ {
/* the calling sequence is: /* the calling sequence is:
@@ -437,9 +486,12 @@ bool cPlayback::SetPosition(int position, bool absolute)
first = false; first = false;
return false; return false;
} }
int64_t pos = (position / 1000.0); int64_t pos = (position / 1000.0);
if (player && player->playback) if (player && player->playback)
player->playback->Command(player, absolute ? PLAYBACK_SEEK_ABS : PLAYBACK_SEEK, (void *)&pos); player->playback->Command(player, absolute ? PLAYBACK_SEEK_ABS : PLAYBACK_SEEK, (void *)&pos);
return true; return true;
} }
@@ -448,6 +500,7 @@ void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *nu
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
int max_numpida = *numpida; int max_numpida = *numpida;
*numpida = 0; *numpida = 0;
if (player && player->manager && player->manager->audio) if (player && player->manager && player->manager->audio)
{ {
char **TrackList = NULL; char **TrackList = NULL;
@@ -467,9 +520,9 @@ void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *nu
{ {
apids[j] = _pid; apids[j] = _pid;
// atUnknown, atMPEG, atMP3, atAC3, atDTS, atAAC, atPCM, atOGG, atFLAC // atUnknown, atMPEG, atMP3, atAC3, atDTS, atAAC, atPCM, atOGG, atFLAC
if (!strncmp("A_MPEG/L3", TrackList[i + 1], 9)) if (!strncmp("A_MPEG/L3", TrackList[i + 1], 9))
ac3flags[j] = 3; ac3flags[j] = 3;
if (!strncmp("A_MP3", TrackList[i + 1], 5)) if (!strncmp("A_MP3", TrackList[i + 1], 5))
ac3flags[j] = 4; ac3flags[j] = 4;
else if (!strncmp("A_AC3", TrackList[i + 1], 5)) else if (!strncmp("A_AC3", TrackList[i + 1], 5))
ac3flags[j] = 1; ac3flags[j] = 1;
@@ -502,8 +555,10 @@ void cPlayback::FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *nu
void cPlayback::FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language) void cPlayback::FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language)
{ {
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
int max_numpids = *numpids; int max_numpids = *numpids;
*numpids = 0; *numpids = 0;
if (player && player->manager && player->manager->subtitle) if (player && player->manager && player->manager->subtitle)
{ {
char **TrackList = NULL; char **TrackList = NULL;
@@ -539,8 +594,8 @@ void cPlayback::FindAllTeletextsubtitlePids(int */*pids*/, unsigned int *numpids
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
//int max_numpids = *numpids; //int max_numpids = *numpids;
*numpids = 0; *numpids = 0;
/*
if (player && player->manager && player->manager->teletext) /* if (player && player->manager && player->manager->teletext)
{ {
char **TrackList = NULL; char **TrackList = NULL;
player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); player->manager->teletext->Command(player, MANAGER_LIST, &TrackList);
@@ -569,16 +624,15 @@ void cPlayback::FindAllTeletextsubtitlePids(int */*pids*/, unsigned int *numpids
free(TrackList); free(TrackList);
*numpids = j; *numpids = j;
} }
} } */
*/
} }
int cPlayback::GetTeletextPid(void) int cPlayback::GetTeletextPid(void)
{ {
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
int pid = -1; int pid = -1;
/*
if (player && player->manager && player->manager->teletext) /* if (player && player->manager && player->manager->teletext)
{ {
char **TrackList = NULL; char **TrackList = NULL;
player->manager->teletext->Command(player, MANAGER_LIST, &TrackList); player->manager->teletext->Command(player, MANAGER_LIST, &TrackList);
@@ -602,8 +656,8 @@ int cPlayback::GetTeletextPid(void)
} }
free(TrackList); free(TrackList);
} }
} } */
*/
printf("teletext pid id %d (0x%x)\n", pid, pid); printf("teletext pid id %d (0x%x)\n", pid, pid);
return pid; return pid;
} }
@@ -623,6 +677,7 @@ void cPlayback::GetChapters(std::vector<int> &positions, std::vector<std::string
{ {
positions.clear(); positions.clear();
titles.clear(); titles.clear();
if (player && player->manager && player->manager->chapter) if (player && player->manager && player->manager->chapter)
{ {
char **TrackList = NULL; char **TrackList = NULL;
@@ -690,6 +745,7 @@ cPlayback::cPlayback(int num __attribute__((unused)))
cPlayback::~cPlayback() cPlayback::~cPlayback()
{ {
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
if (player) if (player)
free(player); free(player);
player = NULL; player = NULL;
@@ -736,6 +792,7 @@ void cPlayback::ReleaseAVFormatContext()
bool cPlayback::IsPlaying(void) const bool cPlayback::IsPlaying(void) const
{ {
lt_info("%s\n", __func__); lt_info("%s\n", __func__);
/* konfetti: there is no event/callback mechanism in libeplayer2 /* konfetti: there is no event/callback mechanism in libeplayer2
* so in case of ending playback we have no information on a * so in case of ending playback we have no information on a
* terminated stream currently (or did I oversee it?). * terminated stream currently (or did I oversee it?).
@@ -745,6 +802,7 @@ bool cPlayback::IsPlaying(void) const
{ {
return player->playback->isPlaying; return player->playback->isPlaying;
} }
return playing; return playing;
} }
#endif #endif