diff --git a/libeplayer3/Makefile.am b/libeplayer3/Makefile.am index 1c45aaa..41f3928 100644 --- a/libeplayer3/Makefile.am +++ b/libeplayer3/Makefile.am @@ -4,8 +4,8 @@ AM_CPPFLAGS = -I$(srcdir)/include AM_CPPFLAGS += -Wall AM_CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE AM_CPPFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -AM_CPPFLAGS += -fno-rtti -#AM_CPPFLAGS += -ggdb +#AM_CPPFLAGS += -fno-rtti +AM_CPPFLAGS += -ggdb libeplayer3_la_SOURCES = \ input.cpp output.cpp manager.cpp player.cpp \ diff --git a/libeplayer3/include/input.h b/libeplayer3/include/input.h index a6cc602..f087b25 100644 --- a/libeplayer3/include/input.h +++ b/libeplayer3/include/input.h @@ -56,7 +56,6 @@ class Input float seek_sec_abs; float seek_sec_rel; bool isContainerRunning; - bool terminating; bool abortPlayback; Player *player; diff --git a/libeplayer3/include/player.h b/libeplayer3/include/player.h index 7539d18..7a8b1f1 100644 --- a/libeplayer3/include/player.h +++ b/libeplayer3/include/player.h @@ -90,6 +90,11 @@ class Player { bool SwitchTeletext(int pid); bool SwitchSubtitle(int pid); + int GetAudioPid(); + int GetVideoPid(); + int GetSubtitlePid(); + int GetTeletextPid(); + bool GetPts(int64_t &pts); bool GetFrameCount(int64_t &framecount); bool GetDuration(double &duration); @@ -98,6 +103,7 @@ class Player { bool SlowMotion(int repeats); bool FastBackward(int speed); bool FastForward(int speed); + bool Open(const char *Url, bool noprobe = false); bool Close(); bool Play(); diff --git a/libeplayer3/input.cpp b/libeplayer3/input.cpp index 3613d52..bbe21c7 100644 --- a/libeplayer3/input.cpp +++ b/libeplayer3/input.cpp @@ -49,7 +49,7 @@ Input::Input() hasPlayThreadStarted = 0; seek_sec_abs = -1.0; seek_sec_rel = 0.0; - terminating = false; + abortPlayback = false; } Input::~Input() @@ -377,8 +377,6 @@ bool Input::Init(const char *filename) return false; } - terminating = false; - bool res = UpdateTracks(); if (!videoTrack && !audioTrack) { @@ -398,19 +396,15 @@ bool Input::Init(const char *filename) bool Input::UpdateTracks() { - if (terminating) + if (abortPlayback) return true; std::vector chapters; for (unsigned int i = 0; i < avfc->nb_chapters; i++) { - AVDictionaryEntry *title = av_dict_get(avfc->metadata, "title", NULL, 0); - if (!title) - continue; AVChapter *ch = avfc->chapters[i]; - if (!ch) - continue; + AVDictionaryEntry* title = av_dict_get(ch->metadata, "title", NULL, 0); Chapter chapter; - chapter.title = title ? title->value : "?"; + chapter.title = title ? title->value : ""; chapter.start = (double) ch->start * av_q2d(ch->time_base) * 1000.0; chapter.end = (double) ch->end * av_q2d(ch->time_base) * 1000.0; chapters.push_back(chapter); @@ -496,11 +490,12 @@ bool Input::UpdateTracks() stream->codec->codec = avcodec_find_decoder(stream->codec->codec_id); if (!stream->codec->codec) fprintf(stderr, "avcodec_find_decoder failed for subtitle track %d\n", n); - else if (avcodec_open2(stream->codec, stream->codec->codec, NULL)) { - fprintf(stderr, "avcodec_open2 failed for subtitle track %d\n", n); - stream->codec->codec = NULL; + else { + int err = avcodec_open2(stream->codec, stream->codec->codec, NULL); + if (averror(err, avcodec_open2)) + stream->codec->codec = NULL; + } } - } if (stream->codec->codec) player->manager.addSubtitleTrack(track); } @@ -522,8 +517,6 @@ bool Input::Stop() while (hasPlayThreadStarted != 0) usleep(100000); - terminating = true; - if (avfc) avformat_close_input(&avfc); diff --git a/libeplayer3/manager.cpp b/libeplayer3/manager.cpp index 37f4893..bb163a4 100644 --- a/libeplayer3/manager.cpp +++ b/libeplayer3/manager.cpp @@ -156,5 +156,5 @@ void Manager::clearTracks() Manager::~Manager() { - clearTracks(); + clearTracks(); } diff --git a/libeplayer3/player.cpp b/libeplayer3/player.cpp index 0fd5751..06a1f5a 100644 --- a/libeplayer3/player.cpp +++ b/libeplayer3/player.cpp @@ -38,6 +38,13 @@ Player::Player() output.player = this; manager.player = this; hasThreadStarted = false; + + isPaused = false; + isPlaying = false; + isForwarding = false; + isBackWard = false; + isSlowMotion = false; + Speed = 0; } void *Player::playthread(void *arg) @@ -337,25 +344,25 @@ bool Player::GetDuration(double &duration) bool Player::SwitchVideo(int pid) { Track *track = manager.getVideoTrack(pid); - return track && input.SwitchVideo(track); + return input.SwitchVideo(track); } bool Player::SwitchAudio(int pid) { Track *track = manager.getAudioTrack(pid); - return track && input.SwitchAudio(track); + return input.SwitchAudio(track); } bool Player::SwitchSubtitle(int pid) { Track *track = manager.getSubtitleTrack(pid); - return track && input.SwitchSubtitle(track); + return input.SwitchSubtitle(track); } bool Player::SwitchTeletext(int pid) { Track *track = manager.getTeletextTrack(pid); - return track && input.SwitchTeletext(track); + return input.SwitchTeletext(track); } bool Player::GetMetadata(std::vector &keys, std::vector &values) @@ -386,3 +393,35 @@ void Player::RequestAbort() { abortRequested = true; } + +int Player::GetVideoPid() +{ + Track *track = input.videoTrack; + if (track) + return track->pid; + return -1; +} + +int Player::GetAudioPid() +{ + Track *track = input.audioTrack; + if (track) + return track->pid; + return -1; +} + +int Player::GetSubtitlePid() +{ + Track *track = input.subtitleTrack; + if (track) + return track->pid; + return -1; +} + +int Player::GetTeletextPid() +{ + Track *track = input.teletextTrack; + if (track) + return track->pid; + return -1; +} diff --git a/libspark/playback_libeplayer3.cpp b/libspark/playback_libeplayer3.cpp index 70ad218..2da26b0 100644 --- a/libspark/playback_libeplayer3.cpp +++ b/libspark/playback_libeplayer3.cpp @@ -11,18 +11,8 @@ #include "playback_libeplayer3.h" -static Player *player = NULL; - extern cAudio *audioDecoder; extern cVideo *videoDecoder; -static bool decoders_closed = false; - -static const char * FILENAME = "playback_libeplayer3.cpp"; -static playmode_t pm; -static std::string fn_ts; -static std::string fn_xml; -static off_t last_size; -static int init_jump; //Used by Fileplay bool cPlayback::Open(playmode_t PlayMode) @@ -32,14 +22,13 @@ bool cPlayback::Open(playmode_t PlayMode) "PLAYMODE_FILE" }; - if (PlayMode != PLAYMODE_TS) - { + if (PlayMode != PLAYMODE_TS) { audioDecoder->closeDevice(); videoDecoder->closeDevice(); decoders_closed = true; } - printf("%s:%s - PlayMode=%s\n", FILENAME, __FUNCTION__, aPLAYMODE[PlayMode]); + printf("%s:%s - PlayMode=%s\n", __FILE__, __func__, aPLAYMODE[PlayMode]); pm = PlayMode; fn_ts = ""; fn_xml = ""; @@ -53,7 +42,7 @@ bool cPlayback::Open(playmode_t PlayMode) //Used by Fileplay void cPlayback::Close(void) { - printf("%s:%s\n", FILENAME, __FUNCTION__); + printf("%s:%s\n", __FILE__, __func__); //Dagobert: movieplayer does not call stop, it calls close ;) Stop(); @@ -66,19 +55,16 @@ void cPlayback::Close(void) } //Used by Fileplay -bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, unsigned int, bool no_probe) +bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, unsigned int) { bool ret = false; bool isHTTP = false; - + no_probe = false; + printf("%s:%s - filename=%s vpid=%u vtype=%d apid=%u ac3=%d, no_probe=%d\n", - FILENAME, __FUNCTION__, filename, vpid, vtype, apid, ac3, no_probe); + __FILE__, __func__, filename, vpid, vtype, apid, ac3, no_probe); init_jump = -1; - //create playback path - mAudioStream=0; - mSubtitleStream=-1; - mTeletextStream=-1; //try to open file if(player && player->Open(filename, no_probe)) { @@ -110,11 +96,13 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, un playing = true; } - printf("%s:%s - return=%d\n", FILENAME, __FUNCTION__, ret); + printf("%s:%s - return=%d\n", __FILE__, __func__, ret); fn_ts = std::string(filename); - if (fn_ts.rfind(".ts") == fn_ts.length() - 3) + if (fn_ts.length() > 3 && fn_ts.rfind(".ts") == fn_ts.length() - 3) { fn_xml = fn_ts.substr(0, fn_ts.length() - 3) + ".xml"; + no_probe = true; + } if (pm == PLAYMODE_TS) { struct stat s; @@ -132,7 +120,7 @@ bool cPlayback::Start(char *filename, int vpid, int vtype, int apid, int ac3, un //Used by Fileplay bool cPlayback::Stop(void) { - printf("%s:%s playing %d\n", FILENAME, __FUNCTION__, playing); + printf("%s:%s playing %d\n", __FILE__, __func__, playing); //if(playing==false) return false; player->Stop(); @@ -143,39 +131,24 @@ bool cPlayback::Stop(void) return true; } -bool cPlayback::SetAPid(int pid, bool ac3 __attribute__((unused))) +bool cPlayback::SetAPid(int pid, bool /* ac3 */) { - printf("%s:%s\n", FILENAME, __FUNCTION__); - if(pid!=mAudioStream){ - player->SwitchAudio(pid); - mAudioStream=pid; - } - return true; + return player->SwitchAudio(pid); } bool cPlayback::SetSubtitlePid(int pid) { - printf("%s:%s\n", FILENAME, __FUNCTION__); - if(pid!=mSubtitleStream){ - player->SwitchSubtitle(pid); - mSubtitleStream = pid; - } - return true; + return player->SwitchSubtitle(pid); } bool cPlayback::SetTeletextPid(int pid) { - printf("%s:%s\n", FILENAME, __FUNCTION__); - if(pid!=mTeletextStream){ - player->SwitchTeletext(pid); - mTeletextStream=pid; - } - return true; + return player->SwitchTeletext(pid); } bool cPlayback::SetSpeed(int speed) { - printf("%s:%s playing %d speed %d\n", FILENAME, __FUNCTION__, playing, speed); + printf("%s:%s playing %d speed %d\n", __FILE__, __func__, playing, speed); if (! decoders_closed) { @@ -230,7 +203,6 @@ bool cPlayback::SetSpeed(int speed) bool cPlayback::GetSpeed(int &speed) const { - //printf("%s:%s\n", FILENAME, __FUNCTION__); speed = nPlaybackSpeed; return true; } @@ -247,8 +219,7 @@ bool cPlayback::GetPosition(int &position, int &duration) /* hack: if the file is growing (timeshift), then determine its length * by comparing the mtime with the mtime of the xml file */ - if (pm == PLAYMODE_TS) - { + if (pm == PLAYMODE_TS) { struct stat s; if (!stat(fn_ts.c_str(), &s)) { @@ -303,7 +274,6 @@ bool cPlayback::GetPosition(int &position, int &duration) bool cPlayback::SetPosition(int position, bool absolute) { - printf("%s:%s %d\n", FILENAME, __FUNCTION__,position); if (playing == false) { /* the calling sequence is: @@ -322,7 +292,6 @@ bool cPlayback::SetPosition(int position, bool absolute) void cPlayback::FindAllPids(int *pids, unsigned int *ac3flags, unsigned int *numpids, std::string *language) { - printf("%s:%s\n", FILENAME, __FUNCTION__); unsigned int i = 0; std::vector tracks = player->manager.getAudioTracks(); @@ -338,7 +307,6 @@ void cPlayback::FindAllPids(int *pids, unsigned int *ac3flags, unsigned int *num void cPlayback::FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language) { - printf("%s:%s\n", FILENAME, __FUNCTION__); unsigned int i = 0; std::vector tracks = player->manager.getSubtitleTracks(); @@ -351,27 +319,26 @@ void cPlayback::FindAllSubtitlePids(int *pids, unsigned int *numpids, std::strin *numpids = i; } -void cPlayback::FindAllTeletextsubtitlePids(int *pids, unsigned int *numpids, std::string *language) +void cPlayback::FindAllTeletextsubtitlePids(int *pids, unsigned int *numpids, std::string *language, int *mags, int *pages) { - printf("%s:%s\n", FILENAME, __FUNCTION__); unsigned int i = 0; std::vector tracks = player->manager.getTeletextTracks(); for (std::vector::iterator it = tracks.begin(); it != tracks.end() && i < *numpids; ++it) { - pids[i] = it->pid; if (it->type != 2 && it->type != 5) // return subtitles only continue; - char tmp[80]; - snprintf(tmp, sizeof(tmp), "%s %d %d %d", it->Name.c_str(), it->type, it->mag, it->page); - language[i] = std::string(tmp); + pids[i] = it->pid; + language[i] = it->Name; + mags[i] = it->mag; + pages[i] = it->page; i++; } + *numpids = i; } -int cPlayback::GetTeletextPid(void) +int cPlayback::GetFirstTeletextPid(void) { - printf("%s:%s\n", FILENAME, __FUNCTION__); std::vector tracks = player->manager.getTeletextTracks(); for (std::vector::iterator it = tracks.begin(); it != tracks.end(); ++it) { if (it->type == 1) @@ -387,21 +354,18 @@ void cPlayback::GetChapters(std::vector &positions, std::vector &keys, std::vector &values) { - printf("%s:%s\n", FILENAME, __FUNCTION__); player->input.GetMetadata(keys, values); } cPlayback::cPlayback(int num __attribute__((unused))) { - printf("%s:%s\n", FILENAME, __FUNCTION__); playing=false; - + decoders_closed = false; player = new Player(); } cPlayback::~cPlayback() { - printf("%s:%s\n", FILENAME, __FUNCTION__); if(player) delete player; } @@ -417,27 +381,28 @@ bool cPlayback::IsPlaying() { return false; } -unsigned long long cPlayback::GetReadCount() { +uint64_t cPlayback::GetReadCount() { if (player) return player->readCount; return 0; } -#if 0 -bool cPlayback::IsPlaying(void) const +int cPlayback::GetAPid(void) { - printf("%s:%s\n", FILENAME, __FUNCTION__); - - /* konfetti: there is no event/callback mechanism in libeplayer2 - * so in case of ending playback we have no information on a - * terminated stream currently (or did I oversee it?). - * So let's ask the player the state. - */ - if (playing) - { - return player->isPlaying; - } - - return playing; + return player->GetAudioPid(); +} + +int cPlayback::GetVPid(void) +{ + return player->GetVideoPid(); +} + +int cPlayback::GetSubtitlePid(void) +{ + return player->GetSubtitlePid(); +} + +int cPlayback::GetTeletextPid(void) +{ + return player->GetTeletextPid(); } -#endif diff --git a/libspark/playback_libeplayer3.h b/libspark/playback_libeplayer3.h index ec60d90..52e5107 100644 --- a/libspark/playback_libeplayer3.h +++ b/libspark/playback_libeplayer3.h @@ -9,30 +9,38 @@ typedef enum { PLAYMODE_FILE } playmode_t; +class Player; + class cPlayback { private: bool enabled; bool playing; + bool no_probe; int nPlaybackSpeed; - int mAudioStream; - int mSubtitleStream; - int mTeletextStream; bool Stop(void); + bool decoders_closed; + playmode_t pm; + std::string fn_ts; + std::string fn_xml; + off_t last_size; + int init_jump; + Player *player; public: cPlayback(int num = 0); ~cPlayback(); bool Open(playmode_t PlayMode); void Close(void); - bool Start(char *filename, int vpid, int vtype, int apid, - int ac3, unsigned int duration, bool no_probe = true); + bool Start(char *filename, int vpid, int vtype, int apid, int ac3, unsigned int duration); bool SetAPid(int pid, bool ac3); bool SetSubtitlePid(int pid); bool SetTeletextPid(int pid); - int GetAPid(void) { return mAudioStream; } - int GetSubtitlePid(void) { return mSubtitleStream; } + int GetAPid(void); + int GetVPid(void); + int GetSubtitlePid(void); int GetTeletextPid(void); + int GetFirstTeletextPid(void); bool SetSpeed(int speed); bool GetSpeed(int &speed) const; bool GetPosition(int &position, int &duration); @@ -40,10 +48,10 @@ class cPlayback bool SetPosition(int position, bool absolute = false); void FindAllPids(int *apids, unsigned int *ac3flags, unsigned int *numpida, std::string *language); void FindAllSubtitlePids(int *pids, unsigned int *numpids, std::string *language); - void FindAllTeletextsubtitlePids(int *pids, unsigned int *numpidt, std::string *tlanguage); + void FindAllTeletextsubtitlePids(int *pids, unsigned int *numpidt, std::string *tlanguage, int *mags, int *pages); void RequestAbort(void); bool IsPlaying(void); - unsigned long long GetReadCount(void); + uint64_t GetReadCount(void); #if 0 void FindAllSubs(uint16_t *pids, unsigned short *supported, uint16_t *numpida, std::string *language); bool SelectSubtitles(int pid);