#include <sys/ioctl.h>
#include <linux/dvb/audio.h>
#include <vdr/channels.h>
#include "mystatusmonitor.h"

void cMyStatusMonitor::ChannelSwitch(const cDevice *Device, int ChannelNumber)
{
   if (ChannelNumber)
   {
//      printf("\nmonochannel: Channel switched to %d on DVB %d\n",
//               ChannelNumber, Device->CardIndex());
      AudioChannelSelect(Device, ChannelNumber);
   }

}

/*
void cMyStatusMonitor::Recording(const cDevice *Device, const char *Name)
{
   if(!ChannelNumber)
   {  // Stop recording (otherwise it would be Start recording)
      ChannelNumber = Device->PrimaryDevice()->CurrentChannel();
//      printf("\nmonochannel: Stopped recording, switch back to channel %d\n",
//                  ChannelNumber);
   }
   else
   {
//      printf("\nmonochannel: Started recording on channel %d\n",
//                  ChannelNumber);
   }
   if(ChannelNumber)
   {
      AudioChannelSelect(Device, ChannelNumber);
   }
}
*/

void cMyStatusMonitor::AudioChannelSelect(const cDevice *Device,
                 const int ChannelNumber)
{
//   printf("\nmonochannel: AudioChannelSelect %d %d\n",
//            Device->CardIndex(), ChannelNumber);

   cChannel *Channel = Channels.GetByNumber(ChannelNumber);
   tChannelID ChannelID = Channel->GetChannelID();

   if(ChannelID == tChannelID::FromString("S1.0W-65535-512-408"))
   {  // Fox Kids
      ((cDevice*)Device)->SetAudioChannel(AUDIO_MONO_LEFT);
//      printf("\nTEST:\tAUDIO_CHANNEL_SELECT set to AUDIO_MONO_LEFT\n");
   }
   else if((ChannelID == tChannelID::FromString("S1.0W-65535-512-402"))
         || (ChannelID == tChannelID::FromString("S1.0W-65535-5376-905")))
   {  // Cartoon Network or Eurosport respectively
      ((cDevice*)Device)->SetAudioChannel(AUDIO_MONO_RIGHT);
//      printf("\nTEST:\tAUDIO_CHANNEL_SELECT set to AUDIO_MONO_RIGHT\n");
   }
   else
   {
      ((cDevice*)Device)->SetAudioChannel(AUDIO_STEREO);
//      printf("\nTEST:\tAUDIO_CHANNEL_SELECT set to AUDIO_STEREO\n");
   }
}
