/*****************************************************************************/

/*
 *      handlemedia.c -- REALmagic Media Player interface primitives
 *
 *      Copyright (C) 2001 Sigma Designs
 *                    written by Pascal Cannenterre <pascal_cannenterre@sdesigns.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*****************************************************************************/
#include "osthread.h"
#include "handlemedia.h"
#include "handledisc.h"
#include "handlefile.h"
#include "remote.h"
#include "osdsupport.h"
#include "osdcontrol.h"

#ifdef _VOD_
#include "handlestreaming.h"
#endif

HDTV_PARAMS Hdtv_Params[] = {
// HSync VSync VidH  VidV  TotH PreH ActH PostH TotV PreV ActV PostV PixF Interlaced
{ 31500,  6000, 2160,  480,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},
{ 37800,  7200, 1080,  480,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},
{ 50400,  9600, 1440,  480,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},
{ 63000, 12000,  720,  480,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},
{ 45000,  6000,  720,  720,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},
{ 54000,  7200,  720,  720,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},
{ 72000,  9600,  720,  720,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},
{ 63000,  6000,  720,  960,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},
{ 75600,  7200,  720,  960,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0}
};

HDTV_PARAMS Hdtv_Params_Init = { 31500,  6000,  720,  480,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0 };

HDTV_PARAMS Hdtv_Params1[] = {
// HSync VSync VidH  VidV  TotH PreH ActH PostH TotV PreV ActV PostV PixF Interlaced
{ 31469, 5994,  640,  480,  800,  59, 16,  85 , 525, 6,  9, 30, 0, 0},	// 0
{ 31500, 6000,  640,  480,  800,  59, 16,  85 , 525, 6,  9, 30, 0, 0},	// 1
{ 45000, 6000,  720,  720,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},	// 7
{ 31469, 5994, 1440,  480,    0,   0,  0,   0 ,   0, 0,  0,  0, 0, 0},	//15
};


DWORD MPEGon(INFO * info)
{
  DWORD errtype = FMPE_OK;

  if(info->bDiscType == LOCALFILE)
    {
      /* initialize_info_structure_file(info); */
     errtype = MPEGDriverEntry(NO_DRIVE);
    }
  else if(info->bDiscType == RTSPURL)
    {
      errtype = MPEGDriverEntry(NO_DRIVE);
    }
  else
    {
      /* initialize_info_structure_disc(info); */
      errtype = MPEGDriverEntry(DRIVE_NUMBER);
    }
  
  if(start_listening_to_remote(info))
    spawnRemoteListener(info);
  
  initOSD(info);

  return errtype;
}

void MPEGoff(INFO * info)
{
  if(info->playing != CLOSED)
    {
      handle_Stop_Close(info);
      handle_Stop_Close(info);
    }
  stopRemoteListener(info);
  
  if(info->pIRma != NULL)
    {
      stopOSD(info);
      info->pIRma = NULL;
      info->pIOsd = NULL;
    }
  
  MPEGDriverUnload();
}

void handle_Stop_Close(INFO *info)
{
  if(info->bDiscType == LOCALFILE)
    handle_Stop_Close_file(info);
  else if(info->bDiscType == RTSPURL)
    {
#ifdef _VOD_
      handle_Stop_Close_rtsp(info);
#endif
    }
  else
    handle_Stop_Close_disc(info);
}

void handle_Play_Pause(INFO *info)
{
  if(info->bDiscType == LOCALFILE)
    handle_Play_Pause_file(info);
  else if(info->bDiscType == RTSPURL)
    {
#ifdef _VOD_    
      handle_Play_Pause_rtsp(info);
#endif      
    }
  else
    handle_Play_Pause_disc(info);
}

void handle_FForward(INFO *info)
{
  if(info->bDiscType == LOCALFILE)
    handle_FForward_file(info);
  else if(info->bDiscType == RTSPURL)
    {
#ifdef _VOD_     
      handle_FForward_rtsp(info);
#endif    
    }
  else
    handle_FForward_disc(info);
  
}

void handle_FRewind(INFO *info)
{
  if(info->bDiscType == LOCALFILE)
    handle_FRewind_file(info);
  else if(info->bDiscType == RTSPURL)
    {
#ifdef _VOD_
      handle_FRewind_rtsp(info);
#endif
    }
  else
    handle_FRewind_disc(info);
  
}

void handle_Prev_Track(INFO *info)
{
  if(info->bDiscType == LOCALFILE)
    handle_Prev_Track_file(info);
  else if(info->bDiscType == RTSPURL)
    {
#ifdef _VOD_
      handle_Prev_Track_rtsp(info);
#endif
    }
  else
    handle_Prev_Track_disc(info);
}


void handle_Next_Track(INFO *info)
{
  if(info->bDiscType == LOCALFILE)
    handle_Next_Track_file(info);
  else if(info->bDiscType == RTSPURL)
    {
#ifdef _VOD_
      handle_Next_Track_rtsp(info);
#endif
    }
  else
    handle_Next_Track_disc(info);
}

void handle_Time_Search(INFO *info)
{
  if(info->bDiscType == RTSPURL)
    {
#ifdef _VOD_
      handle_Time_Search_rtsp(info);
#endif
    }
  else if(info->bDiscType == LOCALFILE)
    {
      
    }
  else
    handle_Time_Search_disc(info);
}

void retrieveInfo(INFO *info)
{
  if(info->bDiscType == RTSPURL)
    {
#ifdef _VOD_
      retrieveInfo_rtsp(info);
#endif
    }
  else if(info->bDiscType == LOCALFILE)
    {
      
    }
  else if (info->bDiscType == FMPC_DVD_VIDEO)
    retrieveInfo_dvd(info);
  else if (info->bDiscType == FMPC_CDDA)
    retrieveInfo_cdda(info);
}
