/*
 * cdda_player.h: The audio player and control interface
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: cdda_player.h,v 1.1.1.4 2005/06/27 13:34:02 cm Exp $
 */

#ifndef __CDDAPLAYER_H
#define __CDDAPLAYER_H

#include <vdr/player.h>
#include <vdr/skins.h>
#include "cdda_conf.h"
#include "cdda_device.h"
#include "cdda_playlist.h"

#define PLAYERBUFSIZE	MEGABYTE(1)

enum eDisplayTimeMode { dtTrack, dtTrackElapsed, dtAll, dtAllElapsed };

class cCddaPlayer : public cPlayer, cThread {
  private:
    int currentFrame;
    bool running, active;
    enum ePlayMode { pmPlay=0, pmPaused, pmStopped, pmBuffered, pmNone };
    ePlayMode playMode;
    eDisplayTimeMode timeMode;
    cFrame *po_readFrame, *po_playFrame;
    cRingBufferFrame *po_ringBufferFrame;
    cCondVar o_playerCond;
    cMutex o_playerMutex;
    cCddaTracks *po_tracks;
    cCddaPlaylist *po_playlist;
    void Clear(void);
    void Reset(void);
    void SetPlayMode(ePlayMode mode);
    void WaitPlayMode(ePlayMode mode);
  protected:
    void Action();
    void Activate(bool On);
  public:
    cCddaPlayer(cCddaPlaylist *playlist);
    ~cCddaPlayer();
    void Play(void);
    void Pause(void);
    void Stop(void);
    int Skip(int offset);
    int Jump(int index, bool force);
    void SkipSeconds(int seconds);
    bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false);;
    bool GetReplayMode(bool &Play, bool &Forward, int &Speed);
    void SetDisplayTimeMode(eDisplayTimeMode mode);
    eDisplayTimeMode GetDisplayTimeMode(void) { return timeMode; };
    int GetPosition(void) { return currentFrame; };
    bool isActive(void) { return active; };
};

class cCddaControl : public cControl {
  private:
    char *p_replayDescription;
    eDisplayInformationView infoView;
    cCddaPlayer *player;
    cCddaPlaylist *po_playlist;
    cSkinDisplayReplay *po_display;
    void ShowProgress(void);
    void ShowJump(int key);
  public:
    cCddaControl(cCddaPlaylist *playlist);
    ~cCddaControl();
    bool isActive(void) { return player->isActive(); };
    void Hide(void);
    eOSState ProcessKey(eKeys Key);
};

#endif
