libeplayer3: implement Playback and Input classes

This commit is contained in:
martii
2014-04-07 21:01:02 +02:00
parent 6c1f7c13bd
commit cba7a708be
12 changed files with 707 additions and 1191 deletions

View File

@@ -1,38 +0,0 @@
#ifndef CONTAINER_H_
#define CONTAINER_H_
#include <stdio.h>
typedef enum {
CONTAINER_INIT,
CONTAINER_ADD,
CONTAINER_PLAY,
CONTAINER_STOP,
CONTAINER_SEEK,
CONTAINER_SEEK_ABS,
CONTAINER_LENGTH,
CONTAINER_DEL,
CONTAINER_SWITCH_AUDIO,
CONTAINER_SWITCH_SUBTITLE,
CONTAINER_SWITCH_TELETEXT,
CONTAINER_METADATA,
} ContainerCmd_t;
struct Player;
typedef struct Container_s {
const char *Name;
int (*Command) (Player *, ContainerCmd_t, const char *);
const char **Capabilities;
} Container_t;
extern Container_t FFMPEGContainer;
typedef struct ContainerHandler_s {
const char *Name;
Container_t *selectedContainer;
int (*Command) (Player *, ContainerCmd_t, const char *);
} ContainerHandler_t;
#endif

View File

@@ -0,0 +1,64 @@
#ifndef __INPUT_H__
#define __INPUT_H__
#include <stdint.h>
#include <string>
#include <vector>
#include <map>
#include <OpenThreads/ScopedLock>
#include <OpenThreads/Thread>
#include <OpenThreads/Condition>
extern "C" {
#include <libavutil/avutil.h>
#include <libavutil/time.h>
#include <libavformat/avformat.h>
#include <libswresample/swresample.h>
#include <libavutil/opt.h>
}
class Player;
class Track;
class Input
{
friend class Player;
private:
Track *videoTrack;
Track *audioTrack;
Track *subtitleTrack;
Track *teletextTrack;
int hasPlayThreadStarted;
float seek_sec_abs;
float seek_sec_rel;
bool isContainerRunning;
bool terminating;
Player *context;
AVFormatContext *avfc;
uint64_t readCount;
public:
Input();
~Input();
bool ReadSubtitle(const char *filename, const char *format, int pid);
bool ReadSubtitles(const char *filename);
bool Init(const char *filename);
bool UpdateTracks();
bool Play();
bool Stop();
bool Seek(float sec, bool absolute);
bool GetDuration(double &duration);
bool SwitchAudio(Track *track);
bool SwitchSubtitle(Track *track);
bool SwitchTeletext(Track *track);
bool SwitchVideo(Track *track);
bool GetMetadata(std::vector<std::string> &keys, std::vector<std::string> &values);
bool GetReadCount(uint64_t &readcount);
};
#endif

View File

@@ -1,11 +1,10 @@
#ifndef MANAGER_H_
#define MANAGER_H_
#ifndef __MANAGER_H__
#define __MANAGER_H__
#include <stdio.h>
#include <stdint.h>
#include <string>
#include <map>
#include <vector>
#include <map>
#include <OpenThreads/ScopedLock>
#include <OpenThreads/Thread>
@@ -19,16 +18,7 @@ extern "C" {
#include <libavutil/opt.h>
}
typedef enum {
MANAGER_ADD,
MANAGER_LIST,
MANAGER_GET,
MANAGER_GETNAME,
MANAGER_SET,
MANAGER_DEL,
MANAGER_GET_TRACK,
MANAGER_INIT_UPDATE
} ManagerCmd_t;
class Player;
struct Track
{
@@ -49,12 +39,15 @@ struct Track
int ac3flags;
int type, mag, page; // for teletext
Track() : pid(-1), duration(-1), avfc(NULL), stream(NULL), inactive(0), is_static(0), ac3flags(-1) {}
Track() : pid(-1), duration(-1), avfc(NULL), stream(NULL), inactive(0), is_static(0), ac3flags(0) {}
};
class Manager
{
friend class Player;
private:
Player *context;
OpenThreads::Mutex mutex;
std::map<int,Track *> videoTracks, audioTracks, subtitleTracks, teletextTracks;
public:

View File

@@ -1,9 +1,10 @@
#ifndef OUTPUT_H_
#define OUTPUT_H_
#ifndef __OUTPUT_H__
#define __OUTPUT_H__
#include <stdio.h>
#include <stdint.h>
#include <string>
#include <vector>
#include <map>
#include <OpenThreads/ScopedLock>
#include <OpenThreads/Thread>
@@ -19,14 +20,19 @@ extern "C" {
#include "writer.h"
class Player;
class Output
{
friend class Player;
private:
int videofd;
int audiofd;
Writer *videoWriter, *audioWriter;
OpenThreads::Mutex audioMutex, videoMutex;
AVStream *audioStream, *videoStream;
Player *context;
public:
Output();
~Output();

View File

@@ -1,45 +1,82 @@
#ifndef PLAYBACK_H_
#define PLAYBACK_H_
#include <sys/types.h>
#ifndef __PLAYBACK_H__
#define __PLAYBACK_H__
#include <stdint.h>
#include <string>
#include <vector>
#include <map>
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_METADATA, PLAYBACK_SLOWMOTION,
PLAYBACK_FASTBACKWARD, PLAYBACK_GET_FRAME_COUNT,
PLAYBACK_SWITCH_TELETEXT
} PlaybackCmd_t;
#include <OpenThreads/ScopedLock>
#include <OpenThreads/Thread>
#include <OpenThreads/Condition>
struct Player;
extern "C" {
#include <libavutil/avutil.h>
#include <libavutil/time.h>
#include <libavformat/avformat.h>
#include <libswresample/swresample.h>
#include <libavutil/opt.h>
}
typedef struct PlaybackHandler_s {
const char *Name;
class Player;
class Input;
int fd;
class Playback {
friend class Player;
friend class Input;
unsigned char isHttp;
private:
Player *context;
unsigned char isPlaying;
unsigned char isPaused;
unsigned char isForwarding;
unsigned char isCreationPhase;
bool isHttp;
bool isPaused;
bool isCreationPhase;
int BackWard;
int SlowMotion;
int Speed;
int AVSync;
bool isSlowMotion;
int Speed;
int AVSync;
bool isVideo;
bool isAudio;
std::string url;
bool noprobe; /* hack: only minimal probing in av_find_stream_info */
int hasThreadStarted;
public:
bool isForwarding;
bool isBackWard;
bool isPlaying;
bool abortPlayback;
bool abortRequested;
uint64_t readCount;
bool SwitchAudio(int pid);
bool SwitchVideo(int pid);
bool SwitchTeletext(int pid);
bool SwitchSubtitle(int pid);
bool GetPts(int64_t &pts);
bool GetFrameCount(int64_t &framecount);
bool GetDuration(double &duration);
bool GetMetadata(std::vector<std::string> &keys, std::vector<std::string> &values);
bool SlowMotion(int repeats);
bool FastBackward(int speed);
bool FastForward(int speed);
bool Open(const char *Url);
bool Close();
bool Play();
bool Pause();
bool Continue();
bool Stop();
bool Seek(float pos, bool absolute);
bool Terminate();
static void* SupervisorThread(void*);
Playback();
};
unsigned char isVideo;
unsigned char isAudio;
unsigned char abortRequested;
unsigned char abortPlayback;
int (*Command) ( Player *, PlaybackCmd_t, void *);
std::string uri;
unsigned char noprobe; /* hack: only minimal probing in av_find_stream_info */
unsigned long long readCount;
} PlaybackHandler_t;
#endif

View File

@@ -1,25 +1,63 @@
#ifndef COMMON_H_
#define COMMON_H_
#ifndef __PLAYER_H__
#define __PLAYER_H__
#include <OpenThreads/ScopedLock>
#include <OpenThreads/Thread>
#include <OpenThreads/Condition>
extern "C" {
#include <libavutil/avutil.h>
#include <libavutil/time.h>
#include <libavformat/avformat.h>
#include <libswresample/swresample.h>
#include <libavutil/opt.h>
}
#include "container.h"
#include "output.h"
#include "manager.h"
#include "playback.h"
#include <pthread.h>
#include <stdint.h>
class Player {
public: //FIXME
PlaybackHandler_t *playback;
ContainerHandler_t *container;
int64_t *currentAudioPtsP;
public:
Player();
~Player();
#include <string>
#include <vector>
#include <map>
Output output;
Manager manager;
#include "input.h"
#include "output.h"
#include "manager.h"
#include "playback.h"
#include "player.h"
struct Chapter
{
std::string title;
double start;
double end;
};
int container_ffmpeg_update_tracks(Player * context, const char *filename);
class Player {
friend class Input;
friend class Output;
friend class Manager;
friend class Playback;
friend class cPlayback;
private:
Input input;
Output output;
Manager manager;
Playback playback;
OpenThreads::Mutex chapterMutex;
std::vector<Chapter> chapters;
public: //FIXME
int64_t *currentAudioPtsP;
public:
Player()
{
input.context = this;
output.context = this;
playback.context = this;
manager.context = this;
}
bool GetChapters(std::vector<int> &positions, std::vector<std::string> &titles);
void SetChapters(std::vector<Chapter> &Chapters);
};
#endif