/*
*
*    ___                       __  ___       ___
*   / _ \___ _    _____ ____  /  |/  /__ ___/ (_)__ _
*  / ___/ _ \ |/|/ / -_) __/ / /|_/ / -_) _  / / _ `/
* /_/   \___/__,__/\__/_/   /_/  /_/\__/\_,_/_/\_,_/
*
*   Original Code by John Garrison
*   Written October 25-27, 1999
*   To be released under the LGPL
*
*   MPEG routines based on Loki's SMPEG
*
*   See LICENSE.TXT for more LGPL info
*/

#ifdef USE_MPEG

#include <malloc.h>
#include <smpeg.h>

#include "powermedia.h"
#include "mpeg.h"


///////////////////////////////////////////////
//          MPEG CREATION FUNCTIONS          //
///////////////////////////////////////////////

PM_Mpeg *PM_CreateMpeg(char *File)
{
   PM_Mpeg *mpeg;

   mpeg->Mpeg = SMPEG_new(File, &mpeg->Info, 1);
   if ( SMPEG_error(mpeg->Mpeg) ){
       fprintf(stderr, "%s: %s\n", File, SMPEG_error(mpeg->Mpeg));
       SMPEG_delete(mpeg->Mpeg);
       exit(0);
   }

   return (mpeg);
}



int PM_DestroyMpeg(PM_Mpeg *Mpeg)
{
   SMPEG_delete(Mpeg->Mpeg);
   free(Mpeg);

   return 0;
}



/////////////////////////////////////////////////
//          MPEG PROPERTIES FUNCTIONS          //
/////////////////////////////////////////////////

int PM_ToggleMpegAudio(PM_Mpeg *Mpeg, int State)
{
   Mpeg->AudioState = State;
   SMPEG_enableaudio(Mpeg->Mpeg, Mpeg->AudioState);

   return 0;
}



int PM_ToggleMpegVideo(PM_Mpeg *Mpeg, int State)
{
   Mpeg->VideoState = State;
   SMPEG_enablevideo(Mpeg->Mpeg, Mpeg->VideoState);

   return 0;
}



int PM_ToggleMpegLoop(PM_Mpeg *Mpeg, int State)
{
   Mpeg->LoopState = State;
   SMPEG_loop(Mpeg->Mpeg, Mpeg->LoopState);

   return 0;
}



int PM_SetMpegVolume(PM_Mpeg *Mpeg, int Volume)
{
   Mpeg->Volume = Volume;
   SMPEG_setvolume(Mpeg->Mpeg, Mpeg->Volume);

   return 0;
}



/*int PM_ToggleMpegDouble(PM_Mpeg *Mpeg, int State)
{
   Mpeg->DoubleState = State;
   SMPEG_double(Mpeg->Mpeg, State);
   if (State==1){
      Mpeg->Info.width *= 2;
      Mpeg->Info.height *= 2;
   }
   if (State==0){
      Mpeg->Info.width /= 2;
      Mpeg->Info.height /= 2;
   }

   return 0;
}
*/


//////////////////////////////////////////////
//          MPEG PLAYING FUNCTIONS          //
//////////////////////////////////////////////

int PM_StartMpeg(PD_Surface *Surface, PM_Mpeg *Mpeg, int X, int Y)
{
   SMPEG_setdisplay(Mpeg->Mpeg, Surface, NULL, NULL);
   SMPEG_move(Mpeg->Mpeg, X, Y);
   SMPEG_play(Mpeg->Mpeg);

   return 0;
}



int PM_StopMpeg(PM_Mpeg *Mpeg)
{
   SMPEG_stop(Mpeg->Mpeg);

   return 0;
}



int PM_RewindMpeg(PM_Mpeg *Mpeg)
{
   SMPEG_rewind(Mpeg->Mpeg);

   return 0;
}


int PM_MoveMpeg(PM_Mpeg *Mpeg, int X, int Y)
{
   SMPEG_move(Mpeg->Mpeg, X, Y);

   return 0;
}



int PM_PauseMpeg(PM_Mpeg *Mpeg)
{
   SMPEG_pause(Mpeg->Mpeg);

   return 0;
}



///////////////////////////////////////////
//          MPEG INFO FUNCTIONS          //
///////////////////////////////////////////

int PM_GetMpegAudioState(PM_Mpeg *Mpeg)
{
   return Mpeg->AudioState;
}



int PM_GetMpegVideoState(PM_Mpeg *Mpeg)
{
   return Mpeg->VideoState;
}



int PM_GetMpegLoopState(PM_Mpeg *Mpeg)
{
   return Mpeg->LoopState;
}



int PM_GetMpegVolume(PM_Mpeg *Mpeg)
{
   return Mpeg->Volume;
}



int PM_GetMpegDoubleState(PM_Mpeg *Mpeg)
{
   return Mpeg->DoubleState;
}



///////////////////////////////////////////////////
//          MPEG SINGLE FRAME FUNCTIONS          //
///////////////////////////////////////////////////

int PM_RenderMpegFrame (PD_Surface *Surface, PM_Mpeg *Mpeg, int Frame, int X, int Y)
{
   SMPEG_renderFrame(Mpeg->Mpeg, Frame, Surface, X, Y);

   return 0;
}



int PM_RenderMpegFinalFrame (PD_Surface *Surface, PM_Mpeg *Mpeg, int X, int Y)
{
   SMPEG_renderFinal(Mpeg->Mpeg, Surface, X, Y);

   return 0;
}



/////////////////////////////////////////////
//          MPEG STATUS FUNCTIONS          //
/////////////////////////////////////////////

int PM_IsMpegPlaying(PM_Mpeg *Mpeg)
{
   if (SMPEG_status(Mpeg->Mpeg) == SMPEG_PLAYING)
      return 1;
   else return 0;
}



int PM_IsMpegStopped(PM_Mpeg *Mpeg)
{
   if (SMPEG_status(Mpeg->Mpeg) == SMPEG_STOPPED)
      return 1;
   else return 0;
}
#endif

#ifndef USE_MPEG

#include "../PowerDraw/powerdraw.h"

typedef char PM_Mpeg;

PM_Mpeg *PM_CreateMpeg(char *File){PM_Mpeg *mpeg; return (mpeg);}
int PM_DestroyMpeg(PM_Mpeg *Mpeg){return 0;}
int PM_ToggleMpegAudio(PM_Mpeg *Mpeg, int State){return 0;}
int PM_ToggleMpegVideo(PM_Mpeg *Mpeg, int State){return 0;}
int PM_ToggleMpegLoop(PM_Mpeg *Mpeg, int State){return 0;}
int PM_SetMpegVolume(PM_Mpeg *Mpeg, int Volume){return 0;}
int PM_ToggleMpegDouble(PM_Mpeg *Mpeg, int State){return 0;}
int PM_StartMpeg(PD_Surface *Surface, PM_Mpeg *Mpeg, int X, int Y){return 0;}
int PM_StopMpeg(PM_Mpeg *Mpeg){return 0;}
int PM_RewindMpeg(PM_Mpeg *Mpeg){return 0;}
int PM_MoveMpeg(PM_Mpeg *Mpeg, int X, int Y){return 0;}
int PM_PauseMpeg(PM_Mpeg *Mpeg){return 0;}
int PM_GetMpegAudioState(PM_Mpeg *Mpeg){return 0;}
int PM_GetMpegVideoState(PM_Mpeg *Mpeg){return 0;}
int PM_GetMpegLoopState(PM_Mpeg *Mpeg){return 0;}
int PM_GetMpegVolume(PM_Mpeg *Mpeg){return 0;}
int PM_GetMpegDoubleState(PM_Mpeg *Mpeg){return 0;}
int PM_GetMpegPauseState(PM_Mpeg *Mpeg){return 0;}
int PM_RenderMpegFrame (PD_Surface *Surface, PM_Mpeg *Mpeg, int Frame, int X, int Y){return 0;}
int PM_RenderMpegFinalFrame (PD_Surface *Surface, PM_Mpeg *Mpeg, int X, int Y){return 0;}
int PM_IsMpegPlaying(PM_Mpeg *Mpeg){return 0;}
int PM_IsMpegStopped(PM_Mpeg *Mpeg){return 0;}
#endif
