2004-08-23 00:15:46 +00:00
//mp3 menu and track selector.
//was origonally an mp3 track selector, now handles lots of media specific stuff - like q3 films!
//should rename to m_media.c
# include "quakedef.h"
2004-09-20 23:25:38 +00:00
# ifdef RGLQUAKE
2004-08-23 00:15:46 +00:00
# include "glquake.h"//fixme
2004-09-20 23:25:38 +00:00
# endif
2004-08-23 00:15:46 +00:00
2007-10-11 14:47:11 +00:00
# if !defined(NOMEDIA)
2004-08-23 00:15:46 +00:00
# include "winquake.h"
# ifdef _WIN32
# define WINAMP
# endif
# ifdef WINAMP
# include "winamp.h"
HWND hwnd_winamp ;
# endif
qboolean Media_EvaluateNextTrack ( void ) ;
typedef struct mediatrack_s {
char filename [ 128 ] ;
char nicename [ 128 ] ;
int length ;
struct mediatrack_s * next ;
} mediatrack_t ;
static mediatrack_t currenttrack ;
int lasttrackplayed ;
int media_playing = true ; //try to continue from the standard playlist
2006-02-11 02:09:43 +00:00
cvar_t media_shuffle = SCVAR ( " media_shuffle " , " 1 " ) ;
cvar_t media_repeat = SCVAR ( " media_repeat " , " 1 " ) ;
2004-08-23 00:15:46 +00:00
# ifdef WINAMP
2006-02-11 02:09:43 +00:00
cvar_t media_hijackwinamp = SCVAR ( " media_hijackwinamp " , " 0 " ) ;
2004-08-23 00:15:46 +00:00
# endif
int selectedoption = - 1 ;
int numtracks ;
int nexttrack = - 1 ;
mediatrack_t * tracks ;
char media_iofilename [ MAX_OSPATH ] = " " ;
int loadedtracknames ;
# ifdef WINAMP
qboolean WinAmp_GetHandle ( void )
{
if ( ( hwnd_winamp = FindWindow ( " Winamp " , NULL ) ) )
return true ;
if ( ( hwnd_winamp = FindWindow ( " Winamp v1.x " , NULL ) ) )
return true ;
* currenttrack . nicename = ' \0 ' ;
return false ;
}
qboolean WinAmp_StartTune ( char * name )
{
int trys ;
int pos ;
COPYDATASTRUCT cds ;
if ( ! WinAmp_GetHandle ( ) )
return false ;
//FIXME: extract from fs if it's in a pack.
//FIXME: always give absolute path
cds . dwData = IPC_PLAYFILE ;
cds . lpData = ( void * ) name ;
cds . cbData = strlen ( ( char * ) cds . lpData ) + 1 ; // include space for null char
SendMessage ( hwnd_winamp , WM_WA_IPC , 0 , IPC_DELETE ) ;
SendMessage ( hwnd_winamp , WM_COPYDATA , ( WPARAM ) NULL , ( LPARAM ) & cds ) ;
SendMessage ( hwnd_winamp , WM_WA_IPC , ( WPARAM ) 0 , IPC_STARTPLAY ) ;
2005-11-26 02:09:25 +00:00
2004-08-23 00:15:46 +00:00
for ( trys = 1000 ; trys ; trys - - )
{
pos = SendMessage ( hwnd_winamp , WM_WA_IPC , 0 , IPC_GETOUTPUTTIME ) ;
if ( pos > 100 & & SendMessage ( hwnd_winamp , WM_WA_IPC , 0 , IPC_GETOUTPUTTIME ) > = 0 ) //tune has started
break ;
Sleep ( 10 ) ; //give it a chance.
if ( ! WinAmp_GetHandle ( ) )
break ;
}
return true ;
}
void WinAmp_Think ( void )
{
int pos ;
int len ;
if ( ! WinAmp_GetHandle ( ) )
2005-11-26 02:09:25 +00:00
return ;
2004-08-23 00:15:46 +00:00
pos = bgmvolume . value * 255 ;
if ( pos > 255 ) pos = 255 ;
if ( pos < 0 ) pos = 0 ;
PostMessage ( hwnd_winamp , WM_WA_IPC , pos , IPC_SETVOLUME ) ;
//optimise this to reduce calls?
pos = SendMessage ( hwnd_winamp , WM_WA_IPC , 0 , IPC_GETOUTPUTTIME ) ;
len = SendMessage ( hwnd_winamp , WM_WA_IPC , 1 , IPC_GETOUTPUTTIME ) * 1000 ;
if ( ( pos > len | | pos < = 100 ) & & len ! = - 1 )
if ( Media_EvaluateNextTrack ( ) )
WinAmp_StartTune ( currenttrack . filename ) ;
}
# endif
void Media_Seek ( float time )
2005-11-26 02:09:25 +00:00
{
2004-08-23 00:15:46 +00:00
# ifdef WINAMP
if ( media_hijackwinamp . value )
{
int pos ;
if ( WinAmp_GetHandle ( ) )
{
pos = SendMessage ( hwnd_winamp , WM_WA_IPC , 0 , IPC_GETOUTPUTTIME ) ;
pos + = time * 1000 ;
PostMessage ( hwnd_winamp , WM_WA_IPC , pos , IPC_JUMPTOTIME ) ;
WinAmp_Think ( ) ;
}
}
# endif
2009-04-01 22:03:56 +00:00
S_Music_Seek ( time ) ;
2004-08-23 00:15:46 +00:00
}
void Media_FForward_f ( void )
{
float time = atoi ( Cmd_Argv ( 1 ) ) ;
if ( ! time )
time = 15 ;
Media_Seek ( time ) ;
}
void Media_Rewind_f ( void )
{
float time = atoi ( Cmd_Argv ( 1 ) ) ;
if ( ! time )
time = 15 ;
Media_Seek ( - time ) ;
}
qboolean Media_EvaluateNextTrack ( void )
{
mediatrack_t * track ;
int trnum ;
if ( ! tracks )
return false ;
if ( nexttrack > = 0 )
{
trnum = nexttrack ;
for ( track = tracks ; track ; track = track - > next )
{
if ( ! trnum )
{
memcpy ( & currenttrack , track - > filename , sizeof ( mediatrack_t ) ) ;
lasttrackplayed = nexttrack ;
break ;
}
trnum - - ;
}
nexttrack = - 1 ;
}
else
{
if ( media_shuffle . value )
nexttrack = ( ( float ) ( rand ( ) & 0x7fff ) / 0x7fff ) * numtracks ;
else
{
nexttrack = lasttrackplayed + 1 ;
if ( nexttrack > = numtracks )
{
if ( media_repeat . value )
nexttrack = 0 ;
else
{
* currenttrack . filename = ' \0 ' ;
* currenttrack . nicename = ' \0 ' ;
nexttrack = - 1 ;
media_playing = false ;
return false ;
}
}
}
trnum = nexttrack ;
for ( track = tracks ; track ; track = track - > next )
{
if ( ! trnum )
{
memcpy ( & currenttrack , track - > filename , sizeof ( mediatrack_t ) ) ;
lasttrackplayed = nexttrack ;
break ;
}
trnum - - ;
}
nexttrack = - 1 ;
}
return true ;
}
//flushes music channel on all soundcards, and the tracks that arn't decoded yet.
void Media_Clear ( void )
{
2009-04-01 22:03:56 +00:00
S_Music_Clear ( NULL ) ;
2004-08-23 00:15:46 +00:00
}
2005-05-26 12:55:34 +00:00
qboolean fakecdactive ;
void Media_FakeTrack ( int i , qboolean loop )
{
char trackname [ 512 ] ;
2009-04-01 22:03:56 +00:00
if ( i > 999 | | i < 0 )
{
fakecdactive = false ;
return ;
}
2005-05-26 12:55:34 +00:00
sprintf ( trackname , " sound/cdtracks/track%03i.ogg " , i ) ;
if ( COM_FCheckExists ( trackname ) )
{
Media_Clear ( ) ;
strcpy ( currenttrack . filename , trackname + 6 ) ;
fakecdactive = true ;
media_playing = true ;
}
2009-04-01 22:03:56 +00:00
else
fakecdactive = false ;
2005-05-26 12:55:34 +00:00
}
2004-08-23 00:15:46 +00:00
//actually, this func just flushes and states that it should be playing. the ambientsound func actually changes the track.
void Media_Next_f ( void )
{
Media_Clear ( ) ;
media_playing = true ;
# ifdef WINAMP
if ( media_hijackwinamp . value )
{
if ( WinAmp_GetHandle ( ) )
if ( Media_EvaluateNextTrack ( ) )
WinAmp_StartTune ( currenttrack . filename ) ;
}
# endif
}
void M_Menu_Media_f ( void ) {
key_dest = key_menu ;
m_state = m_media ;
}
void Media_LoadTrackNames ( char * listname ) ;
# define MEDIA_MIN -8
# define MEDIA_VOLUME -8
# define MEDIA_REWIND -7
# define MEDIA_FASTFORWARD -6
# define MEDIA_CLEARLIST -5
# define MEDIA_ADDTRACK -4
# define MEDIA_ADDLIST -3
# define MEDIA_SHUFFLE -2
# define MEDIA_REPEAT -1
void M_Media_Draw ( void )
{
2004-12-24 08:45:56 +00:00
mpic_t * p ;
2004-08-23 00:15:46 +00:00
mediatrack_t * track ;
int y ;
int op , i ;
# define MP_Hightlight(x,y,text,hl) (hl?M_PrintWhite(x, y, text):M_Print(x, y, text))
2006-04-02 08:11:17 +00:00
p = Draw_SafeCachePic ( " gfx/p_option.lmp " ) ;
if ( p )
M_DrawPic ( ( 320 - p - > width ) / 2 , 4 , p ) ;
2005-11-26 02:09:25 +00:00
if ( ! bgmvolume . value )
2004-08-23 00:15:46 +00:00
M_Print ( 12 , 32 , " Not playing - no volume " ) ;
2005-11-26 02:09:25 +00:00
else if ( ! * currenttrack . nicename )
2004-08-23 00:15:46 +00:00
{
2005-11-26 02:09:25 +00:00
if ( ! tracks )
M_Print ( 12 , 32 , " Not playing - no track to play " ) ;
else
{
2004-08-23 00:15:46 +00:00
# ifdef WINAMP
if ( ! WinAmp_GetHandle ( ) )
M_Print ( 12 , 32 , " Please start WinAmp 2 " ) ;
else
# endif
M_Print ( 12 , 32 , " Not playing - switched off " ) ;
2005-11-26 02:09:25 +00:00
}
2004-08-23 00:15:46 +00:00
}
else
{
M_Print ( 12 , 32 , " Currently playing: " ) ;
M_Print ( 12 , 40 , currenttrack . nicename ) ;
2005-11-26 02:09:25 +00:00
}
2004-08-23 00:15:46 +00:00
op = selectedoption - ( vid . height - 52 ) / 16 ;
if ( op + ( vid . height - 52 ) / 8 > numtracks )
op = numtracks - ( vid . height - 52 ) / 8 ;
if ( op < MEDIA_MIN )
op = MEDIA_MIN ;
2005-11-26 02:09:25 +00:00
y = 52 ;
2004-08-23 00:15:46 +00:00
while ( op < 0 )
{
switch ( op )
{
case MEDIA_VOLUME :
MP_Hightlight ( 12 , y , " Volume " , op = = selectedoption ) ;
y + = 8 ;
break ;
case MEDIA_CLEARLIST :
MP_Hightlight ( 12 , y , " Clear all " , op = = selectedoption ) ;
y + = 8 ;
break ;
case MEDIA_FASTFORWARD :
MP_Hightlight ( 12 , y , " >> Fast Forward " , op = = selectedoption ) ;
y + = 8 ;
break ;
case MEDIA_REWIND :
MP_Hightlight ( 12 , y , " << Rewind " , op = = selectedoption ) ;
y + = 8 ;
break ;
case MEDIA_ADDTRACK :
MP_Hightlight ( 12 , y , " Add Track " , op = = selectedoption ) ;
if ( op = = selectedoption )
M_PrintWhite ( 12 + 9 * 8 , y , media_iofilename ) ;
y + = 8 ;
break ;
case MEDIA_ADDLIST :
MP_Hightlight ( 12 , y , " Add List " , op = = selectedoption ) ;
if ( op = = selectedoption )
M_PrintWhite ( 12 + 9 * 8 , y , media_iofilename ) ;
y + = 8 ;
break ;
case MEDIA_SHUFFLE :
if ( media_shuffle . value )
MP_Hightlight ( 12 , y , " Shuffle on " , op = = selectedoption ) ;
else
MP_Hightlight ( 12 , y , " Shuffle off " , op = = selectedoption ) ;
y + = 8 ;
break ;
case MEDIA_REPEAT :
if ( media_shuffle . value )
{
if ( media_repeat . value )
MP_Hightlight ( 12 , y , " Repeat on " , op = = selectedoption ) ;
else
2005-11-26 02:09:25 +00:00
MP_Hightlight ( 12 , y , " Repeat off " , op = = selectedoption ) ;
2004-08-23 00:15:46 +00:00
}
else
{
if ( media_repeat . value )
MP_Hightlight ( 12 , y , " (Repeat on) " , op = = selectedoption ) ;
else
2005-11-26 02:09:25 +00:00
MP_Hightlight ( 12 , y , " (Repeat off) " , op = = selectedoption ) ;
2004-08-23 00:15:46 +00:00
}
y + = 8 ;
break ;
}
op + + ;
}
for ( track = tracks , i = 0 ; track & & i < op ; track = track - > next , i + + ) ;
for ( ; track ; track = track - > next , y + = 8 , op + + )
{
if ( op = = selectedoption )
M_PrintWhite ( 12 , y , track - > nicename ) ;
else
M_Print ( 12 , y , track - > nicename ) ;
}
}
char compleatenamepath [ MAX_OSPATH ] ;
char compleatenamename [ MAX_OSPATH ] ;
qboolean compleatenamemultiple ;
2009-04-01 22:03:56 +00:00
int Com_CompleatenameCallback ( const char * name , int size , void * data )
2004-08-23 00:15:46 +00:00
{
if ( * compleatenamename )
compleatenamemultiple = true ;
2009-04-01 22:03:56 +00:00
Q_strncpyz ( compleatenamename , name , sizeof ( compleatenamename ) ) ;
2004-08-23 00:15:46 +00:00
return true ;
}
void Com_CompleateOSFileName ( char * name )
2005-11-26 02:09:25 +00:00
{
2004-08-23 00:15:46 +00:00
char * ending ;
compleatenamemultiple = false ;
strcpy ( compleatenamepath , name ) ;
ending = COM_SkipPath ( compleatenamepath ) ;
if ( compleatenamepath ! = ending )
ending [ - 1 ] = ' \0 ' ; //strip a slash
* compleatenamename = ' \0 ' ;
Sys_EnumerateFiles ( NULL , va ( " %s* " , name ) , Com_CompleatenameCallback , NULL ) ;
Sys_EnumerateFiles ( NULL , va ( " %s*.* " , name ) , Com_CompleatenameCallback , NULL ) ;
if ( * compleatenamename )
strcpy ( name , compleatenamename ) ;
}
void M_Media_Key ( int key )
{
2005-11-26 02:09:25 +00:00
int dir ;
2004-08-23 00:15:46 +00:00
if ( key = = K_ESCAPE )
M_Menu_Main_f ( ) ;
else if ( key = = K_RIGHTARROW | | key = = K_LEFTARROW )
{
if ( key = = K_RIGHTARROW )
dir = 1 ;
else dir = - 1 ;
switch ( selectedoption )
{
case MEDIA_VOLUME :
bgmvolume . value + = dir * 0.1 ;
if ( bgmvolume . value < 0 )
bgmvolume . value = 0 ;
if ( bgmvolume . value > 1 )
bgmvolume . value = 1 ;
Cvar_SetValue ( & bgmvolume , bgmvolume . value ) ;
break ;
default :
if ( selectedoption > = 0 )
Media_Next_f ( ) ;
break ;
}
}
else if ( key = = K_DOWNARROW )
{
selectedoption + + ;
if ( selectedoption > = numtracks )
selectedoption = numtracks - 1 ;
}
else if ( key = = K_PGDN )
{
selectedoption + = 10 ;
if ( selectedoption > = numtracks )
selectedoption = numtracks - 1 ;
}
else if ( key = = K_UPARROW )
{
selectedoption - - ;
if ( selectedoption < MEDIA_MIN )
selectedoption = MEDIA_MIN ;
}
else if ( key = = K_PGUP )
{
selectedoption - = 10 ;
if ( selectedoption < MEDIA_MIN )
selectedoption = MEDIA_MIN ;
}
else if ( key = = K_DEL )
{
if ( selectedoption > = 0 )
{
mediatrack_t * prevtrack = NULL , * tr ;
int num = 0 ;
tr = tracks ;
while ( tr )
{
if ( num = = selectedoption )
{
if ( prevtrack )
prevtrack - > next = tr - > next ;
else
tracks = tr - > next ;
Z_Free ( tr ) ;
numtracks - - ;
break ;
}
prevtrack = tr ;
tr = tr - > next ;
num + + ;
}
}
}
else if ( key = = K_ENTER )
{
switch ( selectedoption )
{
case MEDIA_FASTFORWARD :
Media_Seek ( 15 ) ;
break ;
case MEDIA_REWIND :
Media_Seek ( - 15 ) ;
break ;
case MEDIA_CLEARLIST :
{
mediatrack_t * prevtrack ;
while ( tracks )
{
prevtrack = tracks ;
tracks = tracks - > next ;
Z_Free ( prevtrack ) ;
numtracks - - ;
}
if ( numtracks ! = 0 )
{
numtracks = 0 ;
Con_SafePrintf ( " numtracks should be 0 \n " ) ;
}
}
break ;
case MEDIA_ADDTRACK :
if ( * media_iofilename )
{
mediatrack_t * newtrack ;
newtrack = Z_Malloc ( sizeof ( mediatrack_t ) ) ;
Q_strncpyz ( newtrack - > filename , media_iofilename , sizeof ( newtrack - > filename ) ) ;
Q_strncpyz ( newtrack - > nicename , COM_SkipPath ( media_iofilename ) , sizeof ( newtrack - > filename ) ) ;
newtrack - > length = 0 ;
newtrack - > next = tracks ;
tracks = newtrack ;
numtracks + + ;
}
break ;
case MEDIA_ADDLIST :
if ( * media_iofilename )
Media_LoadTrackNames ( media_iofilename ) ;
2005-11-26 02:09:25 +00:00
break ;
2004-08-23 00:15:46 +00:00
case MEDIA_SHUFFLE :
Cvar_Set ( & media_shuffle , media_shuffle . value ? " 0 " : " 1 " ) ;
break ;
case MEDIA_REPEAT :
Cvar_Set ( & media_repeat , media_repeat . value ? " 0 " : " 1 " ) ;
break ;
default :
if ( selectedoption > = 0 )
{
media_playing = true ;
nexttrack = selectedoption ;
2005-11-26 02:09:25 +00:00
Media_Next_f ( ) ;
2004-08-23 00:15:46 +00:00
}
break ;
}
}
else
{
if ( selectedoption = = MEDIA_ADDLIST | | selectedoption = = MEDIA_ADDTRACK )
{
if ( key = = K_TAB )
Com_CompleateOSFileName ( media_iofilename ) ;
else if ( key = = K_BACKSPACE )
2005-11-26 02:09:25 +00:00
{
2004-08-23 00:15:46 +00:00
dir = strlen ( media_iofilename ) ;
if ( dir )
media_iofilename [ dir - 1 ] = ' \0 ' ;
}
else if ( ( key > = ' a ' & & key < = ' z ' ) | | ( key > = ' 0 ' & & key < = ' 9 ' ) | | key = = ' / ' | | key = = ' _ ' | | key = = ' . ' | | key = = ' : ' )
{
dir = strlen ( media_iofilename ) ;
media_iofilename [ dir ] = key ;
media_iofilename [ dir + 1 ] = ' \0 ' ;
}
}
else if ( selectedoption > = 0 )
{
mediatrack_t * prevtrack , * tr ;
int num = 0 ;
tr = tracks ;
while ( tr )
{
2005-11-26 02:09:25 +00:00
if ( num = = selectedoption )
break ;
2004-08-23 00:15:46 +00:00
prevtrack = tr ;
tr = tr - > next ;
num + + ;
}
if ( ! tr )
return ;
if ( key = = K_BACKSPACE )
2005-11-26 02:09:25 +00:00
{
2004-08-23 00:15:46 +00:00
dir = strlen ( tr - > nicename ) ;
if ( dir )
tr - > nicename [ dir - 1 ] = ' \0 ' ;
}
else if ( ( key > = ' a ' & & key < = ' z ' ) | | ( key > = ' 0 ' & & key < = ' 9 ' ) | | key = = ' / ' | | key = = ' _ ' | | key = = ' . ' | | key = = ' : ' | | key = = ' & ' | | key = = ' | ' | | key = = ' # ' | | key = = ' \' ' | | key = = ' \" ' | | key = = ' \\ ' | | key = = ' * ' | | key = = ' @ ' | | key = = ' ! ' | | key = = ' ( ' | | key = = ' ) ' | | key = = ' % ' | | key = = ' ^ ' | | key = = ' ? ' | | key = = ' [ ' | | key = = ' ] ' | | key = = ' ; ' | | key = = ' : ' | | key = = ' + ' | | key = = ' - ' | | key = = ' = ' )
{
dir = strlen ( tr - > nicename ) ;
tr - > nicename [ dir ] = key ;
tr - > nicename [ dir + 1 ] = ' \0 ' ;
}
}
}
}
//safeprints only.
void Media_LoadTrackNames ( char * listname )
2005-11-26 02:09:25 +00:00
{
2004-08-23 00:15:46 +00:00
char * lineend ;
char * len ;
char * filename ;
char * trackname ;
mediatrack_t * newtrack ;
char * data = COM_LoadTempFile ( listname ) ;
loadedtracknames = true ;
if ( ! data )
return ;
if ( ! Q_strncasecmp ( data , " #extm3u " , 7 ) )
{
data = strchr ( data , ' \n ' ) + 1 ;
for ( ; ; )
{
lineend = strchr ( data , ' \n ' ) ;
if ( Q_strncasecmp ( data , " #extinf: " , 8 ) )
{
if ( ! lineend )
return ;
Con_SafePrintf ( " Bad m3u file \n " ) ;
return ;
}
len = data + 8 ;
trackname = strchr ( data , ' , ' ) + 1 ;
if ( ! trackname )
return ;
lineend [ - 1 ] = ' \0 ' ;
filename = data = lineend + 1 ;
lineend = strchr ( data , ' \n ' ) ;
if ( lineend )
{
lineend [ - 1 ] = ' \0 ' ;
data = lineend + 1 ;
}
newtrack = Z_Malloc ( sizeof ( mediatrack_t ) ) ;
# ifndef _WIN32 //crossplatform - lcean up any dos names
if ( filename [ 1 ] = = ' : ' )
{
snprintf ( newtrack - > filename , sizeof ( newtrack - > filename ) - 1 , " /mnt/%c/%s " , filename [ 0 ] - ' A ' + ' a ' , filename + 3 ) ;
while ( ( filename = strchr ( newtrack - > filename , ' \\ ' ) ) )
* filename = ' / ' ;
2005-11-26 02:09:25 +00:00
2004-08-23 00:15:46 +00:00
}
else
# endif
Q_strncpyz ( newtrack - > filename , filename , sizeof ( newtrack - > filename ) ) ;
Q_strncpyz ( newtrack - > nicename , trackname , sizeof ( newtrack - > filename ) ) ;
newtrack - > length = atoi ( len ) ;
newtrack - > next = tracks ;
tracks = newtrack ;
numtracks + + ;
if ( ! lineend )
return ;
}
}
else
{
for ( ; ; )
{
trackname = filename = data ;
lineend = strchr ( data , ' \n ' ) ;
if ( ! lineend & & ! * data )
break ;
2005-11-26 02:09:25 +00:00
lineend [ - 1 ] = ' \0 ' ;
2004-08-23 00:15:46 +00:00
data = lineend + 1 ;
newtrack = Z_Malloc ( sizeof ( mediatrack_t ) ) ;
Q_strncpyz ( newtrack - > filename , filename , sizeof ( newtrack - > filename ) ) ;
Q_strncpyz ( newtrack - > nicename , COM_SkipPath ( trackname ) , sizeof ( newtrack - > filename ) ) ;
newtrack - > length = 0 ;
newtrack - > next = tracks ;
tracks = newtrack ;
numtracks + + ;
if ( ! lineend )
break ;
}
}
}
//safeprints only.
2009-04-01 22:03:56 +00:00
char * Media_NextTrack ( int musicchannelnum )
2004-08-23 00:15:46 +00:00
{
# ifdef WINAMP
if ( media_hijackwinamp . value )
{
WinAmp_Think ( ) ;
return NULL ;
}
# endif
if ( bgmvolume . value < = 0 | | ! media_playing )
return NULL ;
if ( ! loadedtracknames )
Media_LoadTrackNames ( " sound/media.m3u " ) ;
2005-05-26 12:55:34 +00:00
if ( ! tracks & & ! fakecdactive )
2004-08-23 00:15:46 +00:00
{
* currenttrack . filename = ' \0 ' ;
* currenttrack . nicename = ' \0 ' ;
lasttrackplayed = - 1 ;
media_playing = false ;
return NULL ;
}
// if (cursndcard == sndcardinfo) //figure out the next track (primary sound card, we could actually get different tracks on different cards (and unfortunatly do))
// {
Media_EvaluateNextTrack ( ) ;
// }
return currenttrack . filename ;
}
//Avi files are specific to windows. Bit of a bummer really.
2005-01-13 16:29:20 +00:00
# if defined(_WIN32) && !defined(__GNUC__)
2006-11-03 15:53:04 +00:00
# define WINAVI
2004-08-23 00:15:46 +00:00
# endif
# undef dwFlags
# undef lpFormat
# undef lpData
# undef cbData
# undef lTime
2008-11-09 22:29:28 +00:00
# ifdef OFFSCREENGECKO
# include "offscreengecko/embedding.h"
# include "offscreengecko/browser.h"
# endif
2004-08-23 00:15:46 +00:00
///temporary residence for media handling
# include "roq.h"
# ifdef WINAVI
# undef CDECL //windows is stupid at times.
# define CDECL __cdecl
# include <vfw.h>
int aviinited ;
# pragma comment( lib, "vfw32.lib" )
# endif
# define MFT_CAPTURE 5 //fixme
2006-03-06 01:41:09 +00:00
typedef enum {
MFT_NONE ,
MFT_STATIC , //non-moving, PCX, no sound
MFT_ROQ ,
MFT_AVI ,
2008-11-09 22:29:28 +00:00
MFT_CIN ,
MFT_OFSGECKO
2006-03-06 01:41:09 +00:00
} media_filmtype_t ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
typedef enum {
MOT_NONE ,
MOT_PALETTE ,
MOT_RGBA ,
MOT_BGRA ,
MOT_BGR_FLIP
} media_outputtype_t ;
2006-03-06 21:14:14 +00:00
struct cin_s {
2004-08-23 00:15:46 +00:00
2006-03-06 01:41:09 +00:00
//these are the outputs (not always power of two!)
2008-11-09 22:29:28 +00:00
media_outputtype_t outtype ;
2006-03-06 01:41:09 +00:00
int outwidth ;
int outheight ;
qbyte * outdata ;
qbyte * outpalette ;
int outunchanged ;
2008-11-09 22:29:28 +00:00
qboolean ( * decodeframe ) ( cin_t * cin , qboolean nosound ) ;
void ( * doneframe ) ( cin_t * cin ) ;
void ( * shutdown ) ( cin_t * cin ) ; //warning: don't free cin_t
//these are any interactivity functions you might want...
void ( * cursormove ) ( struct cin_s * cin , float posx , float posy ) ; //pos is 0-1
2009-07-25 11:05:06 +00:00
void ( * key ) ( struct cin_s * cin , int code , int unicode , int event ) ;
2008-11-09 22:29:28 +00:00
qboolean ( * setsize ) ( struct cin_s * cin , int width , int height ) ;
void ( * getsize ) ( struct cin_s * cin , int * width , int * height ) ;
void ( * changestream ) ( struct cin_s * cin , char * streamname ) ;
2006-03-06 01:41:09 +00:00
//
media_filmtype_t filmtype ;
# ifdef WINAVI
struct {
AVISTREAMINFO psi ; // Pointer To A Structure Containing Stream Info
PAVISTREAM pavivideo ;
PAVISTREAM pavisound ;
PAVIFILE pavi ;
PGETFRAME pgf ;
LPWAVEFORMAT pWaveFormat ;
2008-11-09 22:29:28 +00:00
//sound stuff
int soundpos ;
//source info
float filmfps ;
int num_frames ;
2006-03-06 01:41:09 +00:00
} avi ;
# endif
2008-11-09 22:29:28 +00:00
# ifdef OFFSCREENGECKO
struct {
OSGK_Browser * gbrowser ;
int bwidth ;
int bheight ;
} gecko ;
# endif
2006-03-06 01:41:09 +00:00
struct {
qbyte * filmimage ; //rgba
int imagewidth ;
int imageheight ;
} image ;
struct {
roq_info * roqfilm ;
} roq ;
float filmstarttime ;
float nextframetime ;
2006-03-11 03:12:10 +00:00
float filmlasttime ;
2006-03-06 01:41:09 +00:00
int currentframe ; //last frame in buffer
qbyte * framedata ; //Z_Malloced buffer
2006-03-06 21:14:14 +00:00
} ;
2006-03-06 01:41:09 +00:00
cin_t * fullscreenvid ;
2008-11-09 22:29:28 +00:00
//////////////////////////////////////////////////////////////////////////////////
//AVI Support (windows)
# ifdef WINAVI
void Media_WINAVI_Shutdown ( struct cin_s * cin )
2006-03-06 01:41:09 +00:00
{
2008-11-09 22:29:28 +00:00
AVIStreamGetFrameClose ( cin - > avi . pgf ) ;
AVIStreamEndStreaming ( cin - > avi . pavivideo ) ;
AVIStreamRelease ( cin - > avi . pavivideo ) ;
//we don't need to free the file (we freed it immediatly after getting the stream handles)
2006-03-06 01:41:09 +00:00
}
2008-11-09 22:29:28 +00:00
qboolean Media_WinAvi_DecodeFrame ( cin_t * cin , qboolean nosound )
2004-08-23 00:15:46 +00:00
{
2008-11-09 22:29:28 +00:00
LPBITMAPINFOHEADER lpbi ; // Holds The Bitmap Header Information
float newframe ;
int newframei ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
float curtime = Sys_DoubleTime ( ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
newframe = ( curtime - cin - > filmstarttime ) * cin - > avi . filmfps ;
newframei = newframe ;
if ( newframe = = cin - > currentframe )
2006-03-06 01:41:09 +00:00
{
2008-11-09 22:29:28 +00:00
cin - > outunchanged = true ;
return true ;
2006-03-06 01:41:09 +00:00
}
2008-11-09 22:29:28 +00:00
if ( cin - > currentframe < newframei - 1 )
Con_DPrintf ( " Dropped %i frame(s) \n " , ( newframei - cin - > currentframe ) - 1 ) ;
cin - > currentframe = newframei ;
Con_DPrintf ( " %i \n " , newframei ) ;
if ( cin - > currentframe > = cin - > avi . num_frames )
2006-03-06 01:41:09 +00:00
{
2008-11-09 22:29:28 +00:00
return false ;
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
lpbi = ( LPBITMAPINFOHEADER ) AVIStreamGetFrame ( cin - > avi . pgf , cin - > currentframe ) ; // Grab Data From The AVI Stream
cin - > currentframe + + ;
if ( ! lpbi | | lpbi - > biBitCount ! = 24 ) //oops
{
SCR_SetUpToDrawConsole ( ) ;
2009-04-06 00:34:32 +00:00
Draw_ConsoleBackground ( 0 , vid . height , true ) ;
2008-11-09 22:29:28 +00:00
Draw_String ( 0 , 0 , " Video stream is corrupt \n " ) ;
}
else
{
cin - > outtype = MOT_BGR_FLIP ;
cin - > outwidth = lpbi - > biWidth ;
cin - > outheight = lpbi - > biHeight ;
cin - > outdata = ( char * ) lpbi + lpbi - > biSize ;
}
if ( cin - > avi . pavisound )
{
LONG lSize ;
LPBYTE pBuffer ;
LONG samples ;
AVIStreamRead ( cin - > avi . pavisound , 0 , AVISTREAMREAD_CONVENIENT ,
NULL , 0 , & lSize , & samples ) ;
cin - > avi . soundpos + = samples ;
pBuffer = cin - > framedata ;
AVIStreamRead ( cin - > avi . pavisound , cin - > avi . soundpos , AVISTREAMREAD_CONVENIENT , pBuffer , lSize , NULL , & samples ) ;
S_RawAudio ( - 1 , pBuffer , cin - > avi . pWaveFormat - > nSamplesPerSec , samples , cin - > avi . pWaveFormat - > nChannels , 2 ) ;
}
return true ;
}
cin_t * Media_WinAvi_TryLoad ( char * name )
{
cin_t * cin ;
PAVIFILE pavi ;
if ( ! aviinited )
{
aviinited = true ;
AVIFileInit ( ) ;
}
if ( ! AVIFileOpen ( & pavi , name , OF_READ , NULL ) ) //!AVIStreamOpenFromFile(&pavi, name, streamtypeVIDEO, 0, OF_READ, NULL))
{
int filmwidth ;
int filmheight ;
cin = Z_Malloc ( sizeof ( cin_t ) ) ;
cin - > filmtype = MFT_AVI ;
cin - > avi . pavi = pavi ;
if ( AVIFileGetStream ( cin - > avi . pavi , & cin - > avi . pavivideo , streamtypeVIDEO , 0 ) ) //retrieve video stream
{
AVIFileRelease ( pavi ) ;
Con_Printf ( " %s contains no video stream \n " , name ) ;
return NULL ;
}
if ( AVIFileGetStream ( cin - > avi . pavi , & cin - > avi . pavisound , streamtypeAUDIO , 0 ) ) //retrieve audio stream
{
Con_DPrintf ( " %s contains no audio stream \n " , name ) ;
cin - > avi . pavisound = NULL ;
}
AVIFileRelease ( cin - > avi . pavi ) ;
//play with video
AVIStreamInfo ( cin - > avi . pavivideo , & cin - > avi . psi , sizeof ( cin - > avi . psi ) ) ;
filmwidth = cin - > avi . psi . rcFrame . right - cin - > avi . psi . rcFrame . left ; // Width Is Right Side Of Frame Minus Left
filmheight = cin - > avi . psi . rcFrame . bottom - cin - > avi . psi . rcFrame . top ; // Height Is Bottom Of Frame Minus Top
cin - > framedata = BZ_Malloc ( filmwidth * filmheight * 4 ) ;
cin - > avi . num_frames = AVIStreamLength ( cin - > avi . pavivideo ) ; // The Last Frame Of The Stream
cin - > avi . filmfps = 1000.0f * ( float ) cin - > avi . num_frames / ( float ) AVIStreamSampleToTime ( cin - > avi . pavivideo , cin - > avi . num_frames ) ; // Calculate Rough Milliseconds Per Frame
AVIStreamBeginStreaming ( cin - > avi . pavivideo , 0 , cin - > avi . num_frames , 100 ) ;
cin - > avi . pgf = AVIStreamGetFrameOpen ( cin - > avi . pavivideo , NULL ) ;
cin - > currentframe = 0 ;
cin - > filmstarttime = Sys_DoubleTime ( ) ;
cin - > avi . soundpos = 0 ;
//play with sound
if ( cin - > avi . pavisound )
{
LONG lSize ;
LPBYTE pChunk ;
AVIStreamRead ( cin - > avi . pavisound , 0 , AVISTREAMREAD_CONVENIENT , NULL , 0 , & lSize , NULL ) ;
if ( ! lSize )
cin - > avi . pWaveFormat = NULL ;
else
{
pChunk = BZ_Malloc ( sizeof ( qbyte ) * lSize ) ;
if ( AVIStreamReadFormat ( cin - > avi . pavisound , AVIStreamStart ( cin - > avi . pavisound ) , pChunk , & lSize ) )
{
// error
Con_Printf ( " Failiure reading sound info \n " ) ;
}
cin - > avi . pWaveFormat = ( LPWAVEFORMAT ) pChunk ;
}
if ( ! cin - > avi . pWaveFormat )
{
Con_Printf ( " VFW is broken \n " ) ;
AVIStreamRelease ( cin - > avi . pavisound ) ;
cin - > avi . pavisound = NULL ;
}
else if ( cin - > avi . pWaveFormat - > wFormatTag ! = 1 )
{
Con_Printf ( " Audio stream is not PCM \n " ) ; //FIXME: so that it no longer is...
AVIStreamRelease ( cin - > avi . pavisound ) ;
cin - > avi . pavisound = NULL ;
}
}
cin - > filmtype = MFT_AVI ;
cin - > decodeframe = Media_WinAvi_DecodeFrame ;
cin - > shutdown = Media_WINAVI_Shutdown ;
return cin ;
}
return NULL ;
}
2004-08-23 00:15:46 +00:00
2004-09-13 04:16:52 +00:00
# else
2008-11-09 22:29:28 +00:00
cin_t * Media_WinAvi_TryLoad ( char * name )
{
return NULL ;
}
2004-08-23 00:15:46 +00:00
# endif
2008-11-09 22:29:28 +00:00
//AVI Support (windows)
//////////////////////////////////////////////////////////////////////////////////
//Quake3 RoQ Support
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
void Media_Roq_Shutdown ( struct cin_s * cin )
{
roq_close ( cin - > roq . roqfilm ) ;
cin - > roq . roqfilm = NULL ;
}
2004-09-13 04:16:52 +00:00
2008-11-09 22:29:28 +00:00
qboolean Media_Roq_DecodeFrame ( cin_t * cin , qboolean nosound )
{
float curtime = Sys_DoubleTime ( ) ;
if ( ( int ) ( cin - > filmlasttime * 30 ) = = ( int ) ( ( float ) realtime * 30 ) )
{
cin - > outunchanged = ! ! cin - > outtype ;
return true ;
2004-08-23 00:15:46 +00:00
}
2008-11-09 22:29:28 +00:00
else if ( curtime < cin - > nextframetime | | roq_read_frame ( cin - > roq . roqfilm ) = = 1 ) //0 if end, -1 if error, 1 if success
{
//#define LIMIT(x) ((x)<0xFFFF)?(x)>>16:0xFF;
# define LIMIT(x) ((((x) > 0xffffff) ? 0xff0000 : (((x) <= 0xffff) ? 0 : (x) & 0xff0000)) >> 16)
unsigned char * pa = cin - > roq . roqfilm - > y [ 0 ] ;
unsigned char * pb = cin - > roq . roqfilm - > u [ 0 ] ;
unsigned char * pc = cin - > roq . roqfilm - > v [ 0 ] ;
int pix = 0 ;
int num_columns = ( cin - > roq . roqfilm - > width ) > > 1 ;
int num_rows = cin - > roq . roqfilm - > height ;
int y ;
int x ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
qbyte * framedata ;
cin - > filmlasttime = ( float ) realtime ;
if ( ! ( curtime < cin - > nextframetime ) ) //roq file was read properly
{
cin - > nextframetime + = 1 / 30.0 ; //add a little bit of extra speed so we cover up a little bit of glitchy sound... :o)
if ( cin - > nextframetime < curtime )
cin - > nextframetime = curtime ;
framedata = cin - > framedata ;
for ( y = 0 ; y < num_rows ; + + y ) //roq playing doesn't give nice data. It's still fairly raw.
{ //convert it properly.
for ( x = 0 ; x < num_columns ; + + x )
{
int r , g , b , y1 , y2 , u , v , t ;
y1 = * ( pa + + ) ; y2 = * ( pa + + ) ;
u = pb [ x ] - 128 ;
v = pc [ x ] - 128 ;
y1 < < = 16 ;
y2 < < = 16 ;
r = 91881 * v ;
g = - 22554 * u + - 46802 * v ;
b = 116130 * u ;
t = r + y1 ;
framedata [ pix ] = ( unsigned char ) LIMIT ( t ) ;
t = g + y1 ;
framedata [ pix + 1 ] = ( unsigned char ) LIMIT ( t ) ;
t = b + y1 ;
framedata [ pix + 2 ] = ( unsigned char ) LIMIT ( t ) ;
t = r + y2 ;
framedata [ pix + 4 ] = ( unsigned char ) LIMIT ( t ) ;
t = g + y2 ;
framedata [ pix + 5 ] = ( unsigned char ) LIMIT ( t ) ;
t = b + y2 ;
framedata [ pix + 6 ] = ( unsigned char ) LIMIT ( t ) ;
pix + = 8 ;
}
if ( y & 0x01 ) { pb + = num_columns ; pc + = num_columns ; }
}
}
cin - > outunchanged = false ;
cin - > outtype = MOT_RGBA ;
cin - > outwidth = cin - > roq . roqfilm - > width ;
cin - > outheight = cin - > roq . roqfilm - > height ;
cin - > outdata = cin - > framedata ;
if ( ! nosound )
2009-04-01 22:03:56 +00:00
if ( cin - > roq . roqfilm - > audio_channels & & S_HaveOutput ( ) & & cin - > roq . roqfilm - > aud_pos < cin - > roq . roqfilm - > vid_pos )
2008-11-09 22:29:28 +00:00
if ( roq_read_audio ( cin - > roq . roqfilm ) > 0 )
{
/* FILE *f;
char wav [ ] = " \x52 \x49 \x46 \x46 \xea \x5f \x04 \x00 \x57 \x41 \x56 \x45 \x66 \x6d \x74 \x20 \x12 \x00 \x00 \x00 \x01 \x00 \x02 \x00 \x22 \x56 \x00 \x00 \x88 \x58 \x01 \x00 \x04 \x00 \x10 \x00 \x00 \x00 \x66 \x61 \x63 \x74 \x04 \x00 \x00 \x00 \xee \x17 \x01 \x00 \x64 \x61 \x74 \x61 \xb8 \x5f \x04 \x00 " ;
int size ;
f = fopen ( " d:/quake/id1/sound/raw.wav " , " r+b " ) ;
if ( ! f )
f = fopen ( " d:/quake/id1/sound/raw.wav " , " w+b " ) ;
fseek ( f , 0 , SEEK_SET ) ;
fwrite ( & wav , sizeof ( wav ) , 1 , f ) ;
fseek ( f , 0 , SEEK_END ) ;
fwrite ( roqfilm - > audio , roqfilm - > audio_size , 2 , f ) ;
size = ftell ( f ) - sizeof ( wav ) ;
fseek ( f , 54 , SEEK_SET ) ;
fwrite ( & size , sizeof ( size ) , 1 , f ) ;
fclose ( f ) ;
*/
S_RawAudio ( - 1 , cin - > roq . roqfilm - > audio , 22050 , cin - > roq . roqfilm - > audio_size / cin - > roq . roqfilm - > audio_channels , cin - > roq . roqfilm - > audio_channels , 2 ) ;
}
return true ;
}
else
2005-08-03 23:14:59 +00:00
{
2008-11-09 22:29:28 +00:00
cin - > roq . roqfilm - > frame_num = 0 ;
cin - > roq . roqfilm - > aud_pos = cin - > roq . roqfilm - > roq_start ;
cin - > roq . roqfilm - > vid_pos = cin - > roq . roqfilm - > roq_start ;
2005-08-03 23:14:59 +00:00
}
2008-11-09 22:29:28 +00:00
return false ;
2006-03-06 01:41:09 +00:00
}
2008-11-09 22:29:28 +00:00
cin_t * Media_RoQ_TryLoad ( char * name )
{
cin_t * cin ;
roq_info * roqfilm ;
if ( ( roqfilm = roq_open ( name ) ) )
{
cin = Z_Malloc ( sizeof ( cin_t ) ) ;
cin - > filmtype = MFT_ROQ ;
cin - > decodeframe = Media_Roq_DecodeFrame ;
cin - > shutdown = Media_Roq_Shutdown ;
cin - > roq . roqfilm = roqfilm ;
cin - > nextframetime = Sys_DoubleTime ( ) ;
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
cin - > framedata = BZ_Malloc ( roqfilm - > width * roqfilm - > height * 4 ) ;
return cin ;
}
return NULL ;
}
//Quake3 RoQ Support
//////////////////////////////////////////////////////////////////////////////////
//Static Image Support
void Media_Static_Shutdown ( struct cin_s * cin )
2006-03-06 01:41:09 +00:00
{
2008-11-09 22:29:28 +00:00
BZ_Free ( cin - > image . filmimage ) ;
cin - > image . filmimage = NULL ;
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
qboolean Media_Static_DecodeFrame ( cin_t * cin , qboolean nosound )
{
cin - > outunchanged = cin - > outtype = = MOT_RGBA ? true : false ; //handy
cin - > outtype = MOT_RGBA ;
cin - > outwidth = cin - > image . imagewidth ;
cin - > outheight = cin - > image . imageheight ;
cin - > outdata = cin - > image . filmimage ;
return true ;
}
cin_t * Media_Static_TryLoad ( char * name )
{
cin_t * cin ;
char * dot = strrchr ( name , ' . ' ) ;
2004-08-23 00:15:46 +00:00
if ( dot & & ( ! strcmp ( dot , " .pcx " ) | | ! strcmp ( dot , " .tga " ) | | ! strcmp ( dot , " .png " ) | | ! strcmp ( dot , " .jpg " ) ) )
{
2006-03-06 01:41:09 +00:00
qbyte * staticfilmimage ;
int imagewidth ;
int imageheight ;
2009-05-24 10:11:17 +00:00
int fsize ;
2004-08-23 00:15:46 +00:00
char fullname [ MAX_QPATH ] ;
qbyte * file ;
2006-03-06 01:41:09 +00:00
sprintf ( fullname , " %s " , name ) ;
2009-05-24 10:11:17 +00:00
fsize = FS_LoadFile ( fullname , & file ) ;
2004-08-23 00:15:46 +00:00
if ( ! file )
2006-03-06 01:41:09 +00:00
{
sprintf ( fullname , " pics/%s " , name ) ;
2009-05-24 10:11:17 +00:00
fsize = FS_LoadFile ( fullname , & file ) ;
2006-03-06 01:41:09 +00:00
if ( ! file )
return NULL ;
}
2004-08-23 00:15:46 +00:00
2009-05-24 10:11:17 +00:00
if ( ( staticfilmimage = ReadPCXFile ( file , fsize , & imagewidth , & imageheight ) ) | | //convert to 32 rgba if not corrupt
( staticfilmimage = ReadTargaFile ( file , fsize , & imagewidth , & imageheight , false ) ) | |
2004-08-23 00:15:46 +00:00
# ifdef AVAIL_JPEGLIB
2009-05-24 10:11:17 +00:00
( staticfilmimage = ReadJPEGFile ( file , fsize , & imagewidth , & imageheight ) ) | |
2004-08-23 00:15:46 +00:00
# endif
# ifdef AVAIL_PNGLIB
2009-05-24 10:11:17 +00:00
( staticfilmimage = ReadPNGFile ( file , fsize , & imagewidth , & imageheight , fullname ) ) | |
2004-08-23 00:15:46 +00:00
# endif
0 )
{
2009-05-24 10:11:17 +00:00
FS_FreeFile ( file ) ; //got image data
2004-08-23 00:15:46 +00:00
}
else
{
2009-05-24 10:11:17 +00:00
FS_FreeFile ( file ) ; //got image data
2004-08-23 00:15:46 +00:00
Con_Printf ( " Static cinematic format not supported. \n " ) ; //not supported format
2006-03-06 01:41:09 +00:00
return NULL ;
2004-08-23 00:15:46 +00:00
}
2006-03-06 01:41:09 +00:00
cin = Z_Malloc ( sizeof ( cin_t ) ) ;
cin - > filmtype = MFT_STATIC ;
2008-11-09 22:29:28 +00:00
cin - > decodeframe = Media_Static_DecodeFrame ;
cin - > shutdown = Media_Static_Shutdown ;
2006-03-06 01:41:09 +00:00
cin - > image . filmimage = staticfilmimage ;
cin - > image . imagewidth = imagewidth ;
cin - > image . imageheight = imageheight ;
return cin ;
2004-08-23 00:15:46 +00:00
}
2008-11-09 22:29:28 +00:00
return NULL ;
}
//Static Image Support
//////////////////////////////////////////////////////////////////////////////////
//Quake2 CIN Support
void Media_Cin_Shutdown ( struct cin_s * cin )
{
CIN_FinishCinematic ( ) ;
}
qboolean Media_Cin_DecodeFrame ( cin_t * cin , qboolean nosound )
{
//FIXME!
if ( CIN_RunCinematic ( ) )
{
CIN_DrawCinematic ( ) ;
return true ;
}
return false ;
}
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
cin_t * Media_Cin_TryLoad ( char * name )
{
cin_t * cin ;
char * dot = strrchr ( name , ' . ' ) ;
2006-03-06 01:41:09 +00:00
2004-08-23 00:15:46 +00:00
if ( dot & & ( ! strcmp ( dot , " .cin " ) ) )
{
if ( CIN_PlayCinematic ( name ) )
2006-03-06 01:41:09 +00:00
{
cin = Z_Malloc ( sizeof ( cin_t ) ) ;
cin - > filmtype = MFT_CIN ;
2008-11-09 22:29:28 +00:00
cin - > decodeframe = Media_Cin_DecodeFrame ;
cin - > shutdown = Media_Cin_Shutdown ;
return cin ;
2006-03-06 01:41:09 +00:00
}
2004-08-23 00:15:46 +00:00
}
2005-12-21 03:07:33 +00:00
2008-11-09 22:29:28 +00:00
return NULL ;
}
2005-08-03 23:14:59 +00:00
2008-11-09 22:29:28 +00:00
//Quake2 CIN Support
//////////////////////////////////////////////////////////////////////////////////
//Gecko Support
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
# ifdef OFFSCREENGECKO
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
int ( * posgk_release ) ( OSGK_BaseObject * obj ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
OSGK_Browser * ( * posgk_browser_create ) ( OSGK_Embedding * embedding , int width , int height ) ;
void ( * posgk_browser_resize ) ( OSGK_Browser * browser , int width , int height ) ;
void ( * posgk_browser_navigate ) ( OSGK_Browser * browser , const char * uri ) ;
const unsigned char * ( * posgk_browser_lock_data ) ( OSGK_Browser * browser , int * isDirty ) ;
void ( * posgk_browser_unlock_data ) ( OSGK_Browser * browser , const unsigned char * data ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
void ( * posgk_browser_event_mouse_move ) ( OSGK_Browser * browser , int x , int y ) ;
void ( * posgk_browser_event_mouse_button ) ( OSGK_Browser * browser , OSGK_MouseButton button , OSGK_MouseButtonEventType eventType ) ;
int ( * posgk_browser_event_key ) ( OSGK_Browser * browser , unsigned int key , OSGK_KeyboardEventType eventType ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
OSGK_EmbeddingOptions * ( * posgk_embedding_options_create ) ( void ) ;
OSGK_Embedding * ( * posgk_embedding_create2 ) ( unsigned int apiVer , OSGK_EmbeddingOptions * options , OSGK_GeckoResult * geckoResult ) ;
void ( * posgk_embedding_options_set_profile_dir ) ( OSGK_EmbeddingOptions * options , const char * profileDir , const char * localProfileDir ) ;
void ( * posgk_embedding_options_add_search_path ) ( OSGK_EmbeddingOptions * options , const char * path ) ;
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
dllhandle_t geckodll ;
dllfunction_t gecko_functions [ ] =
{
{ ( void * * ) & posgk_release , " osgk_release " } ,
{ ( void * * ) & posgk_browser_create , " osgk_browser_create " } ,
{ ( void * * ) & posgk_browser_resize , " osgk_browser_resize " } ,
{ ( void * * ) & posgk_browser_navigate , " osgk_browser_navigate " } ,
{ ( void * * ) & posgk_browser_lock_data , " osgk_browser_lock_data " } ,
{ ( void * * ) & posgk_browser_unlock_data , " osgk_browser_unlock_data " } ,
{ ( void * * ) & posgk_browser_event_mouse_move , " osgk_browser_event_mouse_move " } ,
{ ( void * * ) & posgk_browser_event_mouse_move , " osgk_browser_event_mouse_move " } ,
{ ( void * * ) & posgk_browser_event_mouse_button , " osgk_browser_event_mouse_button " } ,
{ ( void * * ) & posgk_browser_event_key , " osgk_browser_event_key " } ,
{ ( void * * ) & posgk_embedding_options_create , " osgk_embedding_options_create " } ,
{ ( void * * ) & posgk_embedding_create2 , " osgk_embedding_create2 " } ,
{ ( void * * ) & posgk_embedding_options_set_profile_dir , " osgk_embedding_options_set_profile_dir " } ,
{ ( void * * ) & posgk_embedding_options_add_search_path , " osgk_embedding_options_add_search_path " } ,
{ NULL }
} ;
OSGK_Embedding * gecko_embedding ;
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
void Media_Gecko_Shutdown ( struct cin_s * cin )
{
posgk_release ( & cin - > gecko . gbrowser - > baseobj ) ;
}
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
qboolean Media_Gecko_DecodeFrame ( cin_t * cin , qboolean nosound )
{
cin - > outdata = ( char * ) posgk_browser_lock_data ( cin - > gecko . gbrowser , & cin - > outunchanged ) ;
cin - > outwidth = cin - > gecko . bwidth ;
cin - > outheight = cin - > gecko . bheight ;
cin - > outtype = MOT_BGRA ;
return ! ! cin - > gecko . gbrowser ;
}
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
void Media_Gecko_DoneFrame ( cin_t * cin )
{
posgk_browser_unlock_data ( cin - > gecko . gbrowser , cin - > outdata ) ;
cin - > outdata = NULL ;
}
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
void Media_Gecko_MoveCursor ( struct cin_s * cin , float posx , float posy )
{
posgk_browser_event_mouse_move ( cin - > gecko . gbrowser , posx * cin - > gecko . bwidth , posy * cin - > gecko . bheight ) ;
}
void Media_Gecko_KeyPress ( struct cin_s * cin , int code , int event )
{
if ( code > = K_MOUSE1 & & code < K_MOUSE10 )
{
posgk_browser_event_mouse_button ( cin - > gecko . gbrowser , code - K_MOUSE1 , ( event = = 3 ) ? 2 : event ) ;
}
else
{
switch ( code )
2004-08-23 00:15:46 +00:00
{
2008-11-09 22:29:28 +00:00
case K_BACKSPACE :
code = OSGKKey_Backspace ;
break ;
case K_TAB :
code = OSGKKey_Tab ;
break ;
case K_ENTER :
code = OSGKKey_Return ;
break ;
case K_SHIFT :
code = OSGKKey_Shift ;
break ;
case K_CTRL :
code = OSGKKey_Control ;
break ;
case K_ALT :
code = OSGKKey_Alt ;
break ;
case K_CAPSLOCK :
code = OSGKKey_CapsLock ;
break ;
case K_ESCAPE :
code = OSGKKey_Escape ;
break ;
case K_SPACE :
code = OSGKKey_Space ;
break ;
case K_PGUP :
code = OSGKKey_PageUp ;
break ;
case K_PGDN :
code = OSGKKey_PageDown ;
break ;
case K_END :
code = OSGKKey_End ;
break ;
case K_HOME :
code = OSGKKey_Home ;
break ;
case K_LEFTARROW :
code = OSGKKey_Left ;
break ;
case K_UPARROW :
code = OSGKKey_Up ;
break ;
case K_RIGHTARROW :
code = OSGKKey_Right ;
break ;
case K_DOWNARROW :
code = OSGKKey_Down ;
break ;
case K_INS :
code = OSGKKey_Insert ;
break ;
case K_DEL :
code = OSGKKey_Delete ;
break ;
case K_F1 :
code = OSGKKey_F1 ;
break ;
case K_F2 :
code = OSGKKey_F2 ;
break ;
case K_F3 :
code = OSGKKey_F3 ;
break ;
case K_F4 :
code = OSGKKey_F4 ;
break ;
case K_F5 :
code = OSGKKey_F5 ;
break ;
case K_F6 :
code = OSGKKey_F6 ;
break ;
case K_F7 :
code = OSGKKey_F7 ;
break ;
case K_F8 :
code = OSGKKey_F8 ;
break ;
case K_F9 :
code = OSGKKey_F9 ;
break ;
case K_F10 :
code = OSGKKey_F10 ;
break ;
case K_F11 :
code = OSGKKey_F11 ;
break ;
case K_F12 :
code = OSGKKey_F12 ;
break ;
case K_KP_NUMLOCK :
code = OSGKKey_NumLock ;
break ;
case K_SCRLCK :
code = OSGKKey_ScrollLock ;
break ;
case K_LWIN :
code = OSGKKey_Meta ;
break ;
2004-08-23 00:15:46 +00:00
}
2008-11-09 22:29:28 +00:00
Con_Printf ( " Sending %c \n " , code ) ;
posgk_browser_event_key ( cin - > gecko . gbrowser , code , kePress ) ;
//posgk_browser_event_key(cin->gecko.gbrowser, code, event);
}
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
qboolean Media_Gecko_SetSize ( struct cin_s * cin , int width , int height )
{
if ( width < 4 | | height < 4 )
return false ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
posgk_browser_resize ( cin - > gecko . gbrowser , width , height ) ;
cin - > gecko . bwidth = width ;
cin - > gecko . bheight = height ;
return true ;
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
void Media_Gecko_GetSize ( struct cin_s * cin , int * width , int * height )
{
* width = cin - > gecko . bwidth ;
* height = cin - > gecko . bheight ;
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
void Media_Gecko_ChangeStream ( struct cin_s * cin , char * streamname )
{
posgk_browser_navigate ( cin - > gecko . gbrowser , streamname ) ;
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
cin_t * Media_Gecko_TryLoad ( char * name )
{
2009-04-01 22:03:56 +00:00
char xulprofiledir [ MAX_OSPATH ] ;
2008-11-09 22:29:28 +00:00
cin_t * cin ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( ! strncmp ( name , " http:// " , 7 ) )
{
OSGK_GeckoResult result ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
OSGK_EmbeddingOptions * opts ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( ! gecko_embedding )
{
geckodll = Sys_LoadLibrary ( " OffscreenGecko " , gecko_functions ) ;
if ( ! geckodll )
2004-08-23 00:15:46 +00:00
{
2008-11-09 22:29:28 +00:00
Con_Printf ( " OffscreenGecko not installed \n " ) ;
return NULL ;
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
opts = posgk_embedding_options_create ( ) ;
if ( ! opts )
return NULL ;
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
posgk_embedding_options_add_search_path ( opts , " ./xulrunner/ " ) ;
2009-04-01 22:03:56 +00:00
if ( FS_NativePath ( " xulrunner_profile/ " , FS_GAMEONLY , xulprofiledir , sizeof ( xulprofiledir ) ) ;
posgk_embedding_options_set_profile_dir ( opts , xulprofiledir , 0 ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
gecko_embedding = posgk_embedding_create2 ( OSGK_API_VERSION , opts , & result ) ;
posgk_release ( & opts - > baseobj ) ;
if ( ! gecko_embedding )
return NULL ;
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
cin = Z_Malloc ( sizeof ( cin_t ) ) ;
cin - > filmtype = MFT_OFSGECKO ;
cin - > decodeframe = Media_Gecko_DecodeFrame ;
cin - > doneframe = Media_Gecko_DoneFrame ;
cin - > shutdown = Media_Gecko_Shutdown ;
cin - > cursormove = Media_Gecko_MoveCursor ;
cin - > key = Media_Gecko_KeyPress ;
cin - > setsize = Media_Gecko_SetSize ;
cin - > getsize = Media_Gecko_GetSize ;
cin - > changestream = Media_Gecko_ChangeStream ;
cin - > gecko . bwidth = 1024 ;
cin - > gecko . bheight = 1024 ;
cin - > gecko . gbrowser = posgk_browser_create ( gecko_embedding , cin - > gecko . bwidth , cin - > gecko . bheight ) ;
if ( ! cin - > gecko . gbrowser )
{
Z_Free ( cin ) ;
return NULL ;
2004-08-23 00:15:46 +00:00
}
2008-11-09 22:29:28 +00:00
posgk_browser_navigate ( cin - > gecko . gbrowser , name ) ;
return cin ;
2004-08-23 00:15:46 +00:00
}
2006-03-06 01:41:09 +00:00
return NULL ;
2004-08-23 00:15:46 +00:00
}
2008-11-09 22:29:28 +00:00
# else
cin_t * Media_Gecko_TryLoad ( char * name )
2004-08-23 00:15:46 +00:00
{
2008-11-09 22:29:28 +00:00
return NULL ;
}
# endif
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
//Gecko Support
//////////////////////////////////////////////////////////////////////////////////
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
qboolean Media_PlayingFullScreen ( void )
{
return fullscreenvid ! = NULL ;
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
void Media_ShutdownCin ( cin_t * cin )
{
if ( ! cin )
return ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( cin - > shutdown )
cin - > shutdown ( cin ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( cin - > framedata )
{
BZ_Free ( cin - > framedata ) ;
cin - > framedata = NULL ;
}
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
Z_Free ( cin ) ;
}
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
cin_t * Media_StartCin ( char * name )
{
cin_t * cin = NULL ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( ! name | | ! * name ) //clear only.
return NULL ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( ! cin )
cin = Media_Gecko_TryLoad ( name ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( ! cin )
cin = Media_Static_TryLoad ( name ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( ! cin )
cin = Media_Cin_TryLoad ( name ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( ! cin )
cin = Media_RoQ_TryLoad ( name ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( ! cin )
cin = Media_WinAvi_TryLoad ( name ) ;
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
return cin ;
2006-03-06 01:41:09 +00:00
}
2008-11-09 22:29:28 +00:00
qboolean Media_DecodeFrame ( cin_t * cin , qboolean nosound )
{
return cin - > decodeframe ( cin , nosound ) ;
}
2006-03-06 01:41:09 +00:00
qboolean Media_PlayFilm ( char * name )
{
Media_ShutdownCin ( fullscreenvid ) ;
fullscreenvid = Media_StartCin ( name ) ;
if ( fullscreenvid )
{
Con_ClearNotify ( ) ;
2006-07-18 21:07:39 +00:00
if ( key_dest = = key_menu )
{
key_dest = key_game ;
m_state = m_none ;
}
2006-03-06 01:41:09 +00:00
if ( key_dest ! = key_console )
scr_con_current = 0 ;
return true ;
}
else
return false ;
}
qboolean Media_ShowFilm ( void )
{
if ( ! fullscreenvid )
return false ;
2006-03-11 03:12:10 +00:00
if ( ! Media_DecodeFrame ( fullscreenvid , false ) )
2006-03-06 01:41:09 +00:00
{
Media_ShutdownCin ( fullscreenvid ) ;
fullscreenvid = NULL ;
return false ;
}
switch ( fullscreenvid - > outtype )
{
2008-11-09 22:29:28 +00:00
case MOT_RGBA :
2006-03-06 01:41:09 +00:00
Media_ShowFrameRGBA_32 ( fullscreenvid - > outdata , fullscreenvid - > outwidth , fullscreenvid - > outheight ) ;
2004-09-13 04:16:52 +00:00
break ;
2008-11-09 22:29:28 +00:00
case MOT_PALETTE :
2006-03-06 01:41:09 +00:00
Media_ShowFrame8bit ( fullscreenvid - > outdata , fullscreenvid - > outwidth , fullscreenvid - > outheight , fullscreenvid - > outpalette ) ;
2004-08-23 00:15:46 +00:00
break ;
2008-11-09 22:29:28 +00:00
case MOT_BGR_FLIP :
2006-03-06 01:41:09 +00:00
Media_ShowFrameBGR_24_Flip ( fullscreenvid - > outdata , fullscreenvid - > outwidth , fullscreenvid - > outheight ) ;
break ;
2008-11-09 22:29:28 +00:00
case MOT_BGRA :
# pragma message("Media_ShowFilm: BGRA comes out as RGBA")
// Media_ShowFrameBGRA_32
Media_ShowFrameRGBA_32 ( fullscreenvid - > outdata , fullscreenvid - > outwidth , fullscreenvid - > outheight ) ;
break ;
2006-03-06 01:41:09 +00:00
}
2004-08-23 00:15:46 +00:00
2008-11-09 22:29:28 +00:00
if ( fullscreenvid - > doneframe )
fullscreenvid - > doneframe ( fullscreenvid ) ;
2006-03-06 01:41:09 +00:00
return true ;
}
# ifdef RGLQUAKE
int Media_UpdateForShader ( int texnum , cin_t * cin )
{
if ( ! cin )
return 0 ;
2006-03-11 03:12:10 +00:00
if ( ! Media_DecodeFrame ( cin , true ) )
2006-03-06 01:41:09 +00:00
{
return 0 ;
}
2006-03-11 03:12:10 +00:00
if ( ! cin - > outunchanged )
2006-03-06 01:41:09 +00:00
{
2006-03-11 03:12:10 +00:00
GL_Bind ( texnum ) ;
switch ( cin - > outtype )
{
2008-11-09 22:29:28 +00:00
case MOT_RGBA :
2006-03-11 03:12:10 +00:00
GL_Upload32 ( " cin " , ( unsigned int * ) cin - > outdata , cin - > outwidth , cin - > outheight , false , false ) ;
break ;
2008-11-09 22:29:28 +00:00
case MOT_PALETTE :
2006-03-11 03:12:10 +00:00
GL_Upload8 ( " cin " , cin - > outdata , cin - > outwidth , cin - > outheight , false , false ) ;
break ;
2008-11-09 22:29:28 +00:00
case MOT_BGR_FLIP :
2006-03-11 03:12:10 +00:00
GL_Upload24BGR_Flip ( " cin " , cin - > outdata , cin - > outwidth , cin - > outheight , false , false ) ;
break ;
2008-11-09 22:29:28 +00:00
case MOT_BGRA :
GL_Upload32_BGRA ( " cin " , ( unsigned int * ) cin - > outdata , cin - > outwidth , cin - > outheight , false , false ) ;
break ;
2006-03-11 03:12:10 +00:00
}
2004-08-23 00:15:46 +00:00
}
2006-03-06 01:41:09 +00:00
2008-11-09 22:29:28 +00:00
if ( cin - > doneframe )
cin - > doneframe ( cin ) ;
2006-03-06 01:41:09 +00:00
2006-03-11 03:12:10 +00:00
return texnum ;
2004-08-23 00:15:46 +00:00
}
2006-03-06 01:41:09 +00:00
# endif
2008-11-09 22:29:28 +00:00
void Media_Send_Command ( cin_t * cin , char * command )
{
if ( ! cin )
cin = fullscreenvid ;
if ( ! cin | | ! cin - > key )
return ;
cin - > changestream ( cin , command ) ;
}
2009-07-25 11:05:06 +00:00
void Media_Send_KeyEvent ( cin_t * cin , int button , int unicode , int event )
2008-11-09 22:29:28 +00:00
{
if ( ! cin )
cin = fullscreenvid ;
if ( ! cin | | ! cin - > key )
return ;
2009-07-25 11:05:06 +00:00
cin - > key ( cin , button , unicode , event ) ;
2008-11-09 22:29:28 +00:00
}
void Media_Send_MouseMove ( cin_t * cin , float x , float y )
{
if ( ! cin )
cin = fullscreenvid ;
if ( ! cin | | ! cin - > key )
return ;
cin - > cursormove ( cin , x , y ) ;
}
void Media_Send_Resize ( cin_t * cin , int x , int y )
{
cin - > setsize ( cin , x , y ) ;
}
void Media_Send_GetSize ( cin_t * cin , int * x , int * y )
{
if ( ! cin )
cin = fullscreenvid ;
if ( ! cin | | ! cin - > key )
return ;
cin - > getsize ( cin , x , y ) ;
}
2006-03-06 01:41:09 +00:00
2004-08-23 00:15:46 +00:00
void Media_PlayFilm_f ( void )
{
if ( Cmd_Argc ( ) < 2 )
{
Con_Printf ( " playfilm <filename> " ) ;
}
if ( ! strcmp ( Cmd_Argv ( 0 ) , " cinematic " ) )
Media_PlayFilm ( va ( " video/%s " , Cmd_Argv ( 1 ) ) ) ;
else
Media_PlayFilm ( Cmd_Argv ( 1 ) ) ;
}
2006-03-06 01:41:09 +00:00
2006-09-17 00:59:22 +00:00
# if defined(RGLQUAKE)
# if defined(WINAVI)
2004-08-23 00:15:46 +00:00
# define WINAVIRECORDING
PAVIFILE recordavi_file ;
# define recordavi_video_stream (recordavi_codec_fourcc?recordavi_compressed_video_stream:recordavi_uncompressed_video_stream)
PAVISTREAM recordavi_uncompressed_video_stream ;
PAVISTREAM recordavi_compressed_video_stream ;
PAVISTREAM recordavi_uncompressed_audio_stream ;
WAVEFORMATEX recordavi_wave_format ;
unsigned long recordavi_codec_fourcc ;
2006-11-22 01:08:46 +00:00
# endif /* WINAVI */
2006-09-17 00:59:22 +00:00
soundcardinfo_t * capture_fakesounddevice ;
2004-08-23 00:15:46 +00:00
int recordavi_video_frame_counter ;
int recordavi_audio_frame_counter ;
2006-11-03 15:53:04 +00:00
float recordavi_frametime ; //length of a frame in fractional seconds
2004-08-23 00:15:46 +00:00
float recordavi_videotime ;
float recordavi_audiotime ;
int capturesize ;
int capturewidth ;
char * capturevideomem ;
2009-07-25 11:05:06 +00:00
vfsfile_t * captureaudiorawfile ;
2006-09-17 00:59:22 +00:00
//short *captureaudiomem;
2004-08-23 00:15:46 +00:00
int captureaudiosamples ;
2006-09-17 00:59:22 +00:00
int captureframe ;
qboolean capturepaused ;
2006-02-11 02:09:43 +00:00
cvar_t capturerate = SCVAR ( " capturerate " , " 15 " ) ;
2006-09-17 00:59:22 +00:00
# if defined(WINAVI)
2006-02-11 02:09:43 +00:00
cvar_t capturecodec = SCVAR ( " capturecodec " , " divx " ) ;
2006-09-17 00:59:22 +00:00
# else
cvar_t capturecodec = SCVAR ( " capturecodec " , " tga " ) ;
# endif
2006-02-11 02:09:43 +00:00
cvar_t capturesound = SCVAR ( " capturesound " , " 1 " ) ;
2006-09-17 00:59:22 +00:00
cvar_t capturesoundchannels = SCVAR ( " capturesoundchannels " , " 1 " ) ;
cvar_t capturesoundbits = SCVAR ( " capturesoundbits " , " 8 " ) ;
2006-02-11 02:09:43 +00:00
cvar_t capturemessage = SCVAR ( " capturemessage " , " " ) ;
2004-08-23 00:15:46 +00:00
qboolean recordingdemo ;
2004-10-13 07:24:59 +00:00
enum {
CT_NONE ,
CT_AVI ,
CT_SCREENSHOT
} capturetype ;
char capturefilenameprefix [ MAX_QPATH ] ;
2005-12-21 03:07:33 +00:00
2006-09-17 00:59:22 +00:00
qboolean Media_Capturing ( void )
{
if ( ! capturetype )
return false ;
return true ;
}
void Media_CapturePause_f ( void )
{
capturepaused = ! capturepaused ;
}
2005-12-21 03:07:33 +00:00
qboolean Media_PausedDemo ( void )
{
//capturedemo doesn't record any frames when the console is visible
//but that's okay, as we don't load any demo frames either.
2007-10-11 14:47:11 +00:00
if ( ( cls . demoplayback & & Media_Capturing ( ) ) | | capturepaused )
2009-07-25 11:05:06 +00:00
if ( key_dest ! = key_game | | scr_con_current > 0 | | ! cl . validsequence | | capturepaused )
2005-12-21 03:07:33 +00:00
return true ;
return false ;
}
2006-11-03 15:53:04 +00:00
double Media_TweekCaptureFrameTime ( double time )
{
2009-07-25 11:05:06 +00:00
if ( cls . demoplayback & & Media_Capturing ( ) & & recordavi_frametime )
2006-11-03 15:53:04 +00:00
{
return time = recordavi_frametime ;
}
return time ;
}
2004-08-23 00:15:46 +00:00
void Media_RecordFrame ( void )
{
2004-10-13 07:24:59 +00:00
if ( ! capturetype )
2004-08-23 00:15:46 +00:00
return ;
2005-12-21 03:07:33 +00:00
if ( Media_PausedDemo ( ) )
2006-09-17 00:59:22 +00:00
{
int y = vid . height - 32 - 16 ;
if ( y < scr_con_current ) y = scr_con_current ;
if ( y > vid . height - 8 )
y = vid . height - 8 ;
qglColor4f ( 1 , 0 , 0 , sin ( realtime * 4 ) / 4 + 0.75 ) ;
qglEnable ( GL_BLEND ) ;
qglDisable ( GL_ALPHA_TEST ) ;
GL_TexEnv ( GL_MODULATE ) ;
qglBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ;
Draw_String ( ( strlen ( capturemessage . string ) + 1 ) * 8 , y , " PAUSED " ) ;
2005-12-21 03:07:33 +00:00
return ;
2006-09-17 00:59:22 +00:00
}
2005-12-21 03:07:33 +00:00
if ( cls . findtrack )
return ; //skip until we're tracking the right player.
2004-08-23 00:15:46 +00:00
//overlay this on the screen, so it appears in the film
2004-10-13 07:24:59 +00:00
if ( * capturemessage . string )
{
int y = vid . height - 32 - 16 ;
if ( y < scr_con_current ) y = scr_con_current ;
if ( y > vid . height - 8 )
y = vid . height - 8 ;
Draw_String ( 0 , y , capturemessage . string ) ;
}
2004-08-23 00:15:46 +00:00
//time for annother frame?
2006-11-03 15:53:04 +00:00
if ( recordavi_videotime > realtime + 1 )
recordavi_videotime = realtime ; //urm, wrapped?..
if ( recordavi_videotime > realtime )
goto skipframe ;
recordavi_videotime + = recordavi_frametime ;
//audio is mixed to match the video times
2004-08-23 00:15:46 +00:00
2004-10-13 07:24:59 +00:00
switch ( capturetype )
{
case CT_AVI :
2007-10-11 14:47:11 +00:00
# if defined(WINAVI)
2004-10-13 07:24:59 +00:00
{
2006-09-17 00:59:22 +00:00
HRESULT hr ;
char * framebuffer = capturevideomem ;
qbyte temp ;
int i , c ;
if ( ! framebuffer )
{
Con_Printf ( " framebuffer = NULL with AVI capture type (this shouldn't happen) \n " ) ;
return ;
}
//ask gl for it
qglReadPixels ( glx , gly , glwidth , glheight , GL_RGB , GL_UNSIGNED_BYTE , framebuffer ) ;
// swap rgb to bgr
c = glwidth * glheight * 3 ;
for ( i = 0 ; i < c ; i + = 3 )
{
temp = framebuffer [ i ] ;
framebuffer [ i ] = framebuffer [ i + 2 ] ;
framebuffer [ i + 2 ] = temp ;
}
//write it
hr = AVIStreamWrite ( recordavi_video_stream , captureframe + + , 1 , framebuffer , glwidth * glheight * 3 , ( ( captureframe % 15 ) = = 0 ) ? AVIIF_KEYFRAME : 0 , NULL , NULL ) ;
if ( FAILED ( hr ) ) Con_Printf ( " Recoring error \n " ) ;
2004-10-13 07:24:59 +00:00
}
2006-11-22 01:08:46 +00:00
# endif /* WINAVI */
2007-10-11 14:47:11 +00:00
break ;
2004-10-13 07:24:59 +00:00
case CT_SCREENSHOT :
{
char filename [ MAX_OSPATH ] ;
2005-11-30 01:20:53 +00:00
sprintf ( filename , " %s/%8.8i.%s " , capturefilenameprefix , captureframe + + , capturecodec . string ) ;
2004-10-13 07:24:59 +00:00
SCR_ScreenShot ( filename ) ;
}
break ;
case CT_NONE : //non issue.
;
2004-08-23 00:15:46 +00:00
}
//this is drawn to the screen and not the film
skipframe :
{
int y = vid . height - 32 - 16 ;
if ( y < scr_con_current ) y = scr_con_current ;
if ( y > vid . height - 8 )
y = vid . height - 8 ;
2005-01-13 16:29:20 +00:00
qglColor4f ( 1 , 0 , 0 , sin ( realtime * 4 ) / 4 + 0.75 ) ;
qglEnable ( GL_BLEND ) ;
qglDisable ( GL_ALPHA_TEST ) ;
2004-11-17 18:08:31 +00:00
GL_TexEnv ( GL_MODULATE ) ;
2005-01-13 16:29:20 +00:00
qglBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ;
2004-08-23 00:15:46 +00:00
Draw_String ( ( strlen ( capturemessage . string ) + 1 ) * 8 , y , " RECORDING " ) ;
}
}
2006-09-17 00:59:22 +00:00
static void MSD_SetUnderWater ( soundcardinfo_t * sc , qboolean underwater )
2004-08-23 00:15:46 +00:00
{
2006-09-17 00:59:22 +00:00
}
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
static void * MSD_Lock ( soundcardinfo_t * sc )
{
return sc - > sn . buffer ;
}
static void MSD_Unlock ( soundcardinfo_t * sc , void * buffer )
{
}
static int MSD_GetDMAPos ( soundcardinfo_t * sc )
{
int s ;
s = captureframe * ( snd_speed * recordavi_frametime ) ;
2004-10-13 07:24:59 +00:00
2006-05-09 07:26:14 +00:00
2006-09-17 00:59:22 +00:00
// s >>= (sc->sn.samplebits/8) - 1;
s * = sc - > sn . numchannels ;
return s ;
}
static void MSD_Submit ( soundcardinfo_t * sc )
{
//Fixme: support outputting to wav
//http://www.borg.com/~jglatt/tech/wave.htm
int lastpos ;
int newpos ;
int samplestosubmit ;
int offset ;
int bytespersample ;
lastpos = sc - > snd_completed ;
newpos = sc - > paintedtime ;
samplestosubmit = newpos - lastpos ;
if ( samplestosubmit < ( snd_speed * recordavi_frametime ) )
2004-08-23 00:15:46 +00:00
return ;
2006-09-17 00:59:22 +00:00
bytespersample = sc - > sn . numchannels * sc - > sn . samplebits / 8 ;
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
sc - > snd_completed = newpos ;
offset = ( lastpos % ( sc - > sn . samples / sc - > sn . numchannels ) ) ;
2005-11-30 01:20:53 +00:00
2006-09-17 00:59:22 +00:00
//we could just use a buffer size equal to the number of samples in each frame
//but that isn't as robust when it comes to floating point imprecisions
//namly: that it would loose a sample each frame with most framerates.
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
switch ( capturetype )
{
case CT_AVI :
2007-10-11 14:47:11 +00:00
# if defined(WINAVI)
2006-09-17 00:59:22 +00:00
if ( ( sc - > snd_completed % ( sc - > sn . samples / sc - > sn . numchannels ) ) < offset )
{
2007-10-11 14:47:11 +00:00
int partialsamplestosubmit ;
2006-09-17 00:59:22 +00:00
//wraped, two chunks to send
partialsamplestosubmit = ( ( sc - > sn . samples / sc - > sn . numchannels ) ) - offset ;
AVIStreamWrite ( recordavi_uncompressed_audio_stream , recordavi_audio_frame_counter + + , 1 , sc - > sn . buffer + offset * bytespersample , partialsamplestosubmit * bytespersample , AVIIF_KEYFRAME , NULL , NULL ) ;
samplestosubmit - = partialsamplestosubmit ;
offset = 0 ;
}
AVIStreamWrite ( recordavi_uncompressed_audio_stream , recordavi_audio_frame_counter + + , 1 , sc - > sn . buffer + offset * bytespersample , samplestosubmit * bytespersample , AVIIF_KEYFRAME , NULL , NULL ) ;
2006-11-22 01:08:46 +00:00
# endif /* WINAVI */
2007-10-11 14:47:11 +00:00
break ;
case CT_NONE :
break ;
case CT_SCREENSHOT :
2009-07-25 11:05:06 +00:00
if ( ( sc - > snd_completed % ( sc - > sn . samples / sc - > sn . numchannels ) ) < offset )
{
int partialsamplestosubmit ;
//wraped, two chunks to send
partialsamplestosubmit = ( ( sc - > sn . samples / sc - > sn . numchannels ) ) - offset ;
VFS_WRITE ( captureaudiorawfile , sc - > sn . buffer + offset * bytespersample , partialsamplestosubmit * bytespersample ) ;
samplestosubmit - = partialsamplestosubmit ;
offset = 0 ;
}
VFS_WRITE ( captureaudiorawfile , sc - > sn . buffer + offset * bytespersample , samplestosubmit * bytespersample ) ;
2007-10-11 14:47:11 +00:00
break ;
2006-09-17 00:59:22 +00:00
}
}
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
static void MSD_Shutdown ( soundcardinfo_t * sc )
{
Z_Free ( sc - > sn . buffer ) ;
capture_fakesounddevice = NULL ;
}
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
void Media_InitFakeSoundDevice ( int channels , int samplebits )
{
soundcardinfo_t * sc ;
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
if ( capture_fakesounddevice )
2004-08-23 00:15:46 +00:00
return ;
2006-09-17 00:59:22 +00:00
sc = Z_Malloc ( sizeof ( soundcardinfo_t ) ) ;
sc - > snd_sent = 0 ;
sc - > snd_completed = 0 ;
sc - > sn . samples = snd_speed * 0.5 ;
sc - > sn . speed = snd_speed ;
sc - > sn . samplebits = samplebits ;
sc - > sn . samplepos = 0 ;
sc - > sn . numchannels = channels ;
sc - > inactive_sound = true ;
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
sc - > sn . buffer = ( unsigned char * ) BZ_Malloc ( sc - > sn . samples * sc - > sn . numchannels * ( sc - > sn . samplebits / 8 ) ) ;
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
sc - > Lock = MSD_Lock ;
sc - > Unlock = MSD_Unlock ;
sc - > SetWaterDistortion = MSD_SetUnderWater ;
sc - > Submit = MSD_Submit ;
sc - > Shutdown = MSD_Shutdown ;
sc - > GetDMAPos = MSD_GetDMAPos ;
sc - > next = sndcardinfo ;
sndcardinfo = sc ;
capture_fakesounddevice = sc ;
S_DefaultSpeakerConfiguration ( sc ) ;
2004-08-23 00:15:46 +00:00
}
2006-09-17 00:59:22 +00:00
2004-08-23 00:15:46 +00:00
void Media_StopRecordFilm_f ( void )
{
2006-09-17 00:59:22 +00:00
# if defined(WINAVI)
2004-08-23 00:15:46 +00:00
if ( recordavi_uncompressed_video_stream ) AVIStreamRelease ( recordavi_uncompressed_video_stream ) ;
if ( recordavi_compressed_video_stream ) AVIStreamRelease ( recordavi_compressed_video_stream ) ;
if ( recordavi_uncompressed_audio_stream ) AVIStreamRelease ( recordavi_uncompressed_audio_stream ) ;
2005-11-26 02:09:25 +00:00
if ( recordavi_file ) AVIFileRelease ( recordavi_file ) ;
2004-08-23 00:15:46 +00:00
recordavi_uncompressed_video_stream = NULL ;
recordavi_compressed_video_stream = NULL ;
recordavi_uncompressed_audio_stream = NULL ;
recordavi_file = NULL ;
2006-11-22 01:08:46 +00:00
# endif /* WINAVI */
2006-09-17 00:59:22 +00:00
2009-07-25 11:05:06 +00:00
if ( capturevideomem )
BZ_Free ( capturevideomem ) ;
capturevideomem = NULL ;
if ( capture_fakesounddevice )
S_ShutdownCard ( capture_fakesounddevice ) ;
capture_fakesounddevice = NULL ;
2006-09-17 00:59:22 +00:00
2009-07-25 11:05:06 +00:00
if ( captureaudiorawfile )
VFS_CLOSE ( captureaudiorawfile ) ;
captureaudiorawfile = NULL ;
2006-09-17 00:59:22 +00:00
2004-08-23 00:15:46 +00:00
capturevideomem = NULL ;
recordingdemo = false ;
2004-10-13 07:24:59 +00:00
capturetype = CT_NONE ;
2004-08-23 00:15:46 +00:00
}
void Media_RecordFilm_f ( void )
{
char * fourcc = capturecodec . string ;
if ( Cmd_Argc ( ) ! = 2 )
{
Con_Printf ( " capture <filename> \n Records video output in an avi file. \n Use capturerate and capturecodec to configure. \n " ) ;
return ;
}
2006-09-17 00:59:22 +00:00
if ( Cmd_IsInsecure ( ) ) //err... don't think so sonny.
2004-10-13 07:24:59 +00:00
return ;
2004-08-23 00:15:46 +00:00
Media_StopRecordFilm_f ( ) ;
recordavi_video_frame_counter = 0 ;
recordavi_audio_frame_counter = 0 ;
if ( capturerate . value < = 0 )
{
Con_Printf ( " Invalid capturerate \n " ) ;
capturerate . value = 15 ;
}
recordavi_frametime = 1 / capturerate . value ;
2009-07-25 11:05:06 +00:00
if ( recordavi_frametime < 0.001 )
recordavi_frametime = 0.001 ; //no more than 1000 images per second.
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
captureframe = 0 ;
2005-11-30 01:20:53 +00:00
if ( * fourcc )
2004-08-23 00:15:46 +00:00
{
2004-10-13 07:24:59 +00:00
if ( ! strcmp ( fourcc , " tga " ) | |
! strcmp ( fourcc , " png " ) | |
! strcmp ( fourcc , " jpg " ) | |
! strcmp ( fourcc , " pcx " ) )
{
capturetype = CT_SCREENSHOT ;
2006-11-03 15:53:04 +00:00
Q_strncpyz ( capturefilenameprefix , Cmd_Argv ( 1 ) , sizeof ( capturefilenameprefix ) ) ;
2004-10-13 07:24:59 +00:00
}
else
{
capturetype = CT_AVI ;
}
2004-08-23 00:15:46 +00:00
}
2004-10-13 07:24:59 +00:00
else
2004-08-23 00:15:46 +00:00
{
2004-10-13 07:24:59 +00:00
capturetype = CT_AVI ; //uncompressed avi
2004-08-23 00:15:46 +00:00
}
2004-09-24 04:41:15 +00:00
2006-09-17 00:59:22 +00:00
if ( capturetype = = CT_NONE )
{
}
else if ( capturetype = = CT_SCREENSHOT )
2004-10-13 07:24:59 +00:00
{
2009-07-25 11:05:06 +00:00
if ( capturesound . value & & capturesoundchannels . value > = 1 )
{
char filename [ MAX_OSPATH ] ;
int chans = capturesoundchannels . value ;
int sbits = capturesoundbits . value ;
if ( sbits < 8 )
sbits = 8 ;
if ( sbits ! = 8 )
sbits = 16 ;
if ( chans > 6 )
chans = 6 ;
sprintf ( filename , " %s/audio_%ichan_%ikhz_%ib.raw " , capturefilenameprefix , chans , snd_speed / 1000 , sbits ) ;
captureaudiorawfile = FS_OpenVFS ( filename , " wb " , FS_GAMEONLY ) ;
if ( captureaudiorawfile )
Media_InitFakeSoundDevice ( chans , sbits ) ;
}
2006-09-17 00:59:22 +00:00
}
# if defined(WINAVI)
else if ( capturetype = = CT_AVI )
{
HRESULT hr ;
BITMAPINFOHEADER bitmap_info_header ;
AVISTREAMINFO stream_header ;
FILE * f ;
char filename [ 256 ] ;
if ( strlen ( fourcc ) = = 4 )
recordavi_codec_fourcc = mmioFOURCC ( * ( fourcc + 0 ) , * ( fourcc + 1 ) , * ( fourcc + 2 ) , * ( fourcc + 3 ) ) ;
else
recordavi_codec_fourcc = 0 ;
if ( ! aviinited )
{
aviinited = true ;
AVIFileInit ( ) ;
}
2006-11-03 15:53:04 +00:00
snprintf ( filename , sizeof ( filename ) - 5 , " %s%s " , com_quakedir , Cmd_Argv ( 1 ) ) ;
2006-03-11 03:12:10 +00:00
COM_StripExtension ( filename , filename , sizeof ( filename ) ) ;
COM_DefaultExtension ( filename , " .avi " , sizeof ( filename ) ) ;
2004-10-13 07:24:59 +00:00
//wipe it.
f = fopen ( filename , " rb " ) ;
if ( f )
{
fclose ( f ) ;
unlink ( filename ) ;
}
2004-08-23 00:15:46 +00:00
2004-10-13 07:24:59 +00:00
hr = AVIFileOpen ( & recordavi_file , filename , OF_WRITE | OF_CREATE , NULL ) ;
if ( FAILED ( hr ) )
{
Con_Printf ( " Failed to open \n " ) ;
return ;
}
2004-09-24 04:41:15 +00:00
2004-08-23 00:15:46 +00:00
2004-10-13 07:24:59 +00:00
memset ( & bitmap_info_header , 0 , sizeof ( BITMAPINFOHEADER ) ) ;
bitmap_info_header . biSize = 40 ;
bitmap_info_header . biWidth = glwidth ;
bitmap_info_header . biHeight = glheight ;
bitmap_info_header . biPlanes = 1 ;
bitmap_info_header . biBitCount = 24 ;
bitmap_info_header . biCompression = BI_RGB ;
bitmap_info_header . biSizeImage = glwidth * glheight * 3 ;
2004-08-23 00:15:46 +00:00
2004-10-13 07:24:59 +00:00
memset ( & stream_header , 0 , sizeof ( stream_header ) ) ;
stream_header . fccType = streamtypeVIDEO ;
stream_header . fccHandler = recordavi_codec_fourcc ;
stream_header . dwScale = 100 ;
stream_header . dwRate = ( unsigned long ) ( 0.5 + 100.0 / recordavi_frametime ) ;
2005-11-26 02:09:25 +00:00
SetRect ( & stream_header . rcFrame , 0 , 0 , glwidth , glheight ) ;
2004-10-13 07:24:59 +00:00
hr = AVIFileCreateStream ( recordavi_file , & recordavi_uncompressed_video_stream , & stream_header ) ;
if ( FAILED ( hr ) )
2004-08-23 00:15:46 +00:00
{
2004-10-13 07:24:59 +00:00
Con_Printf ( " Couldn't initialise the stream \n " ) ;
2004-08-23 00:15:46 +00:00
Media_StopRecordFilm_f ( ) ;
return ;
}
2004-10-13 07:24:59 +00:00
if ( recordavi_codec_fourcc )
{
AVICOMPRESSOPTIONS opts ;
AVICOMPRESSOPTIONS * aopts [ 1 ] = { & opts } ;
2005-11-26 02:09:25 +00:00
memset ( & opts , 0 , sizeof ( opts ) ) ;
2004-10-13 07:24:59 +00:00
opts . fccType = stream_header . fccType ;
opts . fccHandler = recordavi_codec_fourcc ;
// Make the stream according to compression
hr = AVIMakeCompressedStream ( & recordavi_compressed_video_stream , recordavi_uncompressed_video_stream , & opts , NULL ) ;
if ( FAILED ( hr ) )
{
Con_Printf ( " Failed to init compressor \n " ) ;
Media_StopRecordFilm_f ( ) ;
return ;
}
}
2005-11-26 02:09:25 +00:00
2004-08-23 00:15:46 +00:00
2004-10-13 07:24:59 +00:00
hr = AVIStreamSetFormat ( recordavi_video_stream , 0 , & bitmap_info_header , sizeof ( BITMAPINFOHEADER ) ) ;
if ( FAILED ( hr ) )
{
Con_Printf ( " Failed to set format \n " ) ;
Media_StopRecordFilm_f ( ) ;
return ;
}
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
if ( capturesoundbits . value ! = 8 & & capturesoundbits . value ! = 16 )
Cvar_Set ( & capturesoundbits , " 8 " ) ;
if ( capturesoundchannels . value < 1 & & capturesoundchannels . value > 6 )
Cvar_Set ( & capturesoundchannels , " 1 " ) ;
2004-10-13 07:24:59 +00:00
if ( capturesound . value )
{
memset ( & recordavi_wave_format , 0 , sizeof ( WAVEFORMATEX ) ) ;
2005-11-26 02:09:25 +00:00
recordavi_wave_format . wFormatTag = WAVE_FORMAT_PCM ;
2006-09-17 00:59:22 +00:00
recordavi_wave_format . nChannels = capturesoundchannels . value ;
recordavi_wave_format . nSamplesPerSec = snd_speed ;
recordavi_wave_format . wBitsPerSample = capturesoundbits . value ;
2005-11-26 02:09:25 +00:00
recordavi_wave_format . nBlockAlign = recordavi_wave_format . wBitsPerSample / 8 * recordavi_wave_format . nChannels ;
recordavi_wave_format . nAvgBytesPerSec = recordavi_wave_format . nSamplesPerSec * recordavi_wave_format . nBlockAlign ;
recordavi_wave_format . cbSize = 0 ;
2004-08-23 00:15:46 +00:00
2005-11-26 02:09:25 +00:00
2004-10-13 07:24:59 +00:00
memset ( & stream_header , 0 , sizeof ( stream_header ) ) ;
stream_header . fccType = streamtypeAUDIO ;
stream_header . dwScale = recordavi_wave_format . nBlockAlign ;
stream_header . dwRate = stream_header . dwScale * ( unsigned long ) recordavi_wave_format . nSamplesPerSec ;
stream_header . dwSampleSize = recordavi_wave_format . nBlockAlign ;
2004-08-23 00:15:46 +00:00
2004-10-13 07:24:59 +00:00
hr = AVIFileCreateStream ( recordavi_file , & recordavi_uncompressed_audio_stream , & stream_header ) ;
if ( FAILED ( hr ) ) return ;
hr = AVIStreamSetFormat ( recordavi_uncompressed_audio_stream , 0 , & recordavi_wave_format , sizeof ( WAVEFORMATEX ) ) ;
if ( FAILED ( hr ) ) return ;
2006-09-17 00:59:22 +00:00
Media_InitFakeSoundDevice ( recordavi_wave_format . nChannels , recordavi_wave_format . wBitsPerSample ) ;
2004-10-13 07:24:59 +00:00
}
2004-08-23 00:15:46 +00:00
2004-10-13 07:24:59 +00:00
recordavi_videotime = realtime ;
recordavi_audiotime = realtime ;
2004-08-23 00:15:46 +00:00
2006-09-17 00:59:22 +00:00
// if (recordavi_wave_format.nSamplesPerSec)
// captureaudiomem = BZ_Malloc(recordavi_wave_format.nSamplesPerSec*2);
2004-10-13 07:24:59 +00:00
capturevideomem = BZ_Malloc ( glwidth * glheight * 3 ) ;
}
2006-11-22 01:08:46 +00:00
# endif /* WINAVI */
2006-09-17 00:59:22 +00:00
else
{
Con_Printf ( " That sort of video capturing is not supported in this build \n " ) ;
2006-11-03 15:53:04 +00:00
capturetype = CT_NONE ;
2006-09-17 00:59:22 +00:00
}
2004-08-23 00:15:46 +00:00
}
void Media_CaptureDemoEnd ( void )
{
if ( recordingdemo )
Media_StopRecordFilm_f ( ) ;
}
void Media_RecordDemo_f ( void )
{
CL_PlayDemo_f ( ) ;
Media_RecordFilm_f ( ) ;
scr_con_current = 0 ;
key_dest = key_game ;
2005-11-30 01:20:53 +00:00
if ( capturetype ! = CT_NONE )
2004-08-23 00:15:46 +00:00
recordingdemo = true ;
2006-11-03 15:53:04 +00:00
else
CL_Stopdemo_f ( ) ; //capturing failed for some reason
2004-08-23 00:15:46 +00:00
}
2006-11-22 01:08:46 +00:00
# else /* RGLQUAKE */
2004-08-23 00:15:46 +00:00
void Media_CaptureDemoEnd ( void ) { }
void Media_RecordAudioFrame ( short * sample_buffer , int samples ) { }
2006-11-22 01:08:46 +00:00
double Media_TweekCaptureFrameTime ( double time ) { return time ; }
2004-08-23 00:15:46 +00:00
void Media_RecordFrame ( void ) { }
2006-02-12 22:38:39 +00:00
qboolean Media_PausedDemo ( void ) { return false ; } //should not return a value
2006-11-22 01:08:46 +00:00
# endif /* RGLQUAKE */
2004-08-23 00:15:46 +00:00
void Media_Init ( void )
{
Cmd_AddCommand ( " playfilm " , Media_PlayFilm_f ) ;
Cmd_AddCommand ( " cinematic " , Media_PlayFilm_f ) ;
Cmd_AddCommand ( " music_fforward " , Media_FForward_f ) ;
Cmd_AddCommand ( " music_rewind " , Media_Rewind_f ) ;
Cmd_AddCommand ( " music_next " , Media_Next_f ) ;
2006-09-17 02:42:18 +00:00
# if defined(RGLQUAKE)
2004-08-23 00:15:46 +00:00
Cmd_AddCommand ( " capture " , Media_RecordFilm_f ) ;
Cmd_AddCommand ( " capturedemo " , Media_RecordDemo_f ) ;
Cmd_AddCommand ( " capturestop " , Media_StopRecordFilm_f ) ;
2006-09-17 00:59:22 +00:00
Cmd_AddCommand ( " capturepause " , Media_CapturePause_f ) ;
2004-08-23 00:15:46 +00:00
Cvar_Register ( & capturemessage , " AVI capture controls " ) ;
Cvar_Register ( & capturesound , " AVI capture controls " ) ;
Cvar_Register ( & capturerate , " AVI capture controls " ) ;
Cvar_Register ( & capturecodec , " AVI capture controls " ) ;
2006-09-17 00:59:22 +00:00
# if defined(WINAVI)
Cvar_Register ( & capturesoundbits , " AVI capture controls " ) ;
Cvar_Register ( & capturesoundchannels , " AVI capture controls " ) ;
2004-08-23 00:15:46 +00:00
# endif
2007-03-28 13:27:35 +00:00
# endif
2004-08-23 00:15:46 +00:00
# ifdef WINAMP
Cvar_Register ( & media_hijackwinamp , " Media player things " ) ;
# endif
Cvar_Register ( & media_shuffle , " Media player things " ) ;
Cvar_Register ( & media_repeat , " Media player things " ) ;
2005-11-25 12:38:34 +00:00
}
2004-08-23 00:15:46 +00:00
2005-11-26 02:09:25 +00:00
2004-08-23 00:15:46 +00:00
# else
void Media_Init ( void ) { }
void M_Media_Draw ( void ) { }
void M_Media_Key ( int key ) { }
qboolean Media_ShowFilm ( void ) { return false ; }
qboolean Media_PlayFilm ( char * name ) { return false ; }
2006-11-22 01:08:46 +00:00
double Media_TweekCaptureFrameTime ( double time ) { return time ; }
2004-08-23 00:15:46 +00:00
void Media_RecordFrame ( void ) { }
void Media_CaptureDemoEnd ( void ) { }
void Media_RecordDemo_f ( void ) { }
void Media_RecordAudioFrame ( short * sample_buffer , int samples ) { }
void Media_StopRecordFilm_f ( void ) { }
void Media_RecordFilm_f ( void ) { }
void M_Menu_Media_f ( void ) { }
2006-03-11 04:39:16 +00:00
2009-07-25 11:05:06 +00:00
char * Media_NextTrack ( int musicchannelnum ) { return NULL ; }
2005-12-21 03:07:33 +00:00
qboolean Media_PausedDemo ( void ) { return false ; }
2006-03-11 04:39:16 +00:00
qboolean Media_PlayingFullScreen ( void ) { return false ; }
2004-08-23 00:15:46 +00:00
int filmtexture ;
# endif