/*
 * osdout.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include <vdr/plugin.h>
#include <vdr/device.h>
#include "softosd.h"

static const char *VERSION        = "0.0.1";
static const char *DESCRIPTION    = "Osd Output over FB";
static const char *MAINMENUENTRY  = NULL;

class cPluginOsdout : public cPlugin {
private:
  // Add any member variables or functions you may need here.
public:
  cPluginOsdout(void);
  virtual ~cPluginOsdout();
  virtual const char *Version(void) { return VERSION; }
  virtual const char *Description(void) { return DESCRIPTION; }
  virtual const char *CommandLineHelp(void);
  virtual bool ProcessArgs(int argc, char *argv[]);
  virtual bool Initialize(void);
  virtual bool Start(void);
  virtual void Housekeeping(void);
  virtual const char *MainMenuEntry(void) { return MAINMENUENTRY; }
  virtual cOsdObject *MainMenuAction(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);
};

// -------------------------------------------------------------------------
class cSoftDevice : public cDevice {
private:
	FbRenderer* _out;
public:
  cSoftDevice();
  ~cSoftDevice();
  virtual void MakePrimaryDevice(bool On);
  virtual cOsd * GetOsd(int Left, int Top);
  virtual bool HasDecoder(void) const {return true;}
  virtual bool CanReplay(void) const {return false;}
  virtual bool SetPlayMode(ePlayMode PlayMode){return false;}
  virtual void TrickSpeed(int Speed){;}
  virtual void Clear(void){;}
  virtual void Play(void){;}
  virtual void Freeze(void){;}
  virtual void Mute(void){;}
  virtual void SetVolumeDevice (int Volume){;}
  virtual void StillPicture(const uchar *Data, int Length){;}
  virtual bool Poll(cPoller &Poller, int TimeoutMs = 0){return false;}
  virtual int PlayVideo(const uchar *Data, int Length){return 0;}
  virtual int ProvidesCa(const cChannel *Channel) const{return 0;}
};

cSoftDevice::cSoftDevice()
{
	_out = new FbRenderer();
	_out->init(0);
}

cSoftDevice::~cSoftDevice()
{
	if (_out){
		 _out->deinit();
		delete(_out);
	}
}

void cSoftDevice::MakePrimaryDevice(bool On)
{
	new cSoftOsdProvider(_out);
}

cOsd * cSoftDevice::GetOsd(int Left, int Top)
{
	return new cSoftOsd(_out,Left,Top);
}

//----------------------------------------------------------------------

cPluginOsdout::cPluginOsdout(void)
{
  // Initialize any member variables here.
  // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
  // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
}

cPluginOsdout::~cPluginOsdout()
{
  // Clean up after yourself!
}

const char *cPluginOsdout::CommandLineHelp(void)
{
  // Return a string that describes all known command line options.
  return NULL;
}

bool cPluginOsdout::ProcessArgs(int argc, char *argv[])
{
  // Implement command line argument processing here if applicable.
  return true;
}

bool cPluginOsdout::Initialize(void)
{
  // Initialize any background activities the plugin shall perform.
  new cSoftDevice();
  return true;
}

bool cPluginOsdout::Start(void)
{
  // Start any background activities the plugin shall perform.
  return true;
}

void cPluginOsdout::Housekeeping(void)
{
  // Perform any cleanup or other regular tasks.
}

cOsdObject *cPluginOsdout::MainMenuAction(void)
{
  // Perform the action when selected from the main VDR menu.
  return NULL;
}

cMenuSetupPage *cPluginOsdout::SetupMenu(void)
{
  // Return a setup menu in case the plugin supports one.
  return NULL;
}

bool cPluginOsdout::SetupParse(const char *Name, const char *Value)
{
  // Parse your own setup parameters and store their values.
  return false;
}

VDRPLUGINCREATOR(cPluginOsdout); // Don't touch this!
