PlayMpeg PSP Port: It gives error....

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ardatan
Posts: 44
Joined: Sat Jan 12, 2008 8:47 am

PlayMpeg PSP Port: It gives error....

Post by ardatan »

I'm trying to port PlayMpeg to PSP... Plaympeg uses smpeg-psp library...
But when i try build it,
Toolchain shows this error...

Code: Select all

psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include  -O2 -Wall -g `/usr/local/pspdev
/psp/bin/sdl-config --cflags` -D_PSP_FW_VERSION=150   -c -o plaympeg.o plaympeg.
c
plaympeg.c: In function 'SDL_main':
plaympeg.c:507: warning: 'screen' may be used uninitialized in this function
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include  -O2 -Wall -g `/usr/local/pspdev
/psp/bin/sdl-config --cflags` -D_PSP_FW_VERSION=150  -L. -L/usr/local/pspdev/psp
/sdk/lib   plaympeg.o -lsmpeg -lSDL -lpsphprm -lpspgu -lpspgum -lpspaudio -lstdc
++ -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_
inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o play
mpeg.elf
/usr/local/pspdev/lib/gcc/psp/4.3.1/../../../../psp/lib/crt0.o: In function `_ma
in':
/home/ardatan/trunk/psptoolchain/build/pspsdk/src/startup/crt0.c:86: undefined r
eference to `main'
collect2: ld returned 1 exit status
make: *** [plaympeg.elf] Error 1

plaympeg.c

Code: Select all

/*
   plaympeg - Sample MPEG player using the SMPEG library
   Copyright (C) 1999 Loki Entertainment Software
   
   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 <pspsdk.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <psploadexec_kernel.h>
#include <kubridge.h>
#include <systemctrl.h>
#include <systemctrl_se.h>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#ifdef unix
#include <unistd.h>

#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/time.h>

#define NET_SUPPORT  /* General network support */
#define RAW_SUPPORT  /* Raw data transport support */
#define HTTP_SUPPORT /* HTTP support */
#define FTP_SUPPORT  /* FTP support */
#ifdef linux
#define VCD_SUPPORT  /* Video CD support */
#endif
#endif

#ifdef NET_SUPPORT
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#endif

#ifdef VCD_SUPPORT
#include <signal.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <linux/cdrom.h>
#endif

#include "smpeg.h"

PSP_MODULE_INFO&#40;"playMpeg", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;

PSP_HEAP_SIZE_MAX&#40;&#41;;

#define printf    pspDebugScreenPrintf

void usage&#40;char *argv0&#41;
&#123;
    printf&#40;
"Usage&#58; %s &#91;options&#93; file ...\n"
"Where the options are one of&#58;\n"
"	--noaudio	     Don't play audio stream\n"
"	--novideo	     Don't play video stream\n"
"	--fullscreen	     Play MPEG in fullscreen mode\n"
"	--double or -2	     Play MPEG at double size\n"
"	--loop or -l	     Play MPEG over and over\n"
"	--bilinear	     Use software bilinear filtering\n"
"	--volume N or -v N   Set audio volume to N &#40;0-100&#41;\n"
"	--title T or -t T  Set window's title to T\n"
"	--scale wxh or -s wxh  Play MPEG at given resolution\n"
"	--seek N or -S N     Skip N bytes\n"
#ifdef USE_SYSTEM_TIMESTAMP
"	--skip N or -k N     Skip N seconds\n"
#endif
"	--help or -h\n"
"	--version or -V\n"
"Specifying - as filename will use stdin for input\n", argv0&#41;;
&#125;

#ifdef NET_SUPPORT
int is_address_multicast&#40;unsigned long address&#41;
&#123;
  if&#40;&#40;address & 255&#41; >= 224 && &#40;address & 255&#41; <= 239&#41; return&#40;1&#41;;
  return&#40;0&#41;;
&#125;

int tcp_open&#40;char * address, int port&#41;
&#123;
  struct sockaddr_in stAddr;
  struct hostent * host;
  int sock;
  struct linger l;

  memset&#40;&stAddr,0,sizeof&#40;stAddr&#41;&#41;;
  stAddr.sin_family = AF_INET ;
  stAddr.sin_port = htons&#40;port&#41;;

  if&#40;&#40;host = gethostbyname&#40;address&#41;&#41; == NULL&#41; return&#40;0&#41;;

  stAddr.sin_addr = *&#40;&#40;struct in_addr *&#41; host->h_addr_list&#91;0&#93;&#41; ;

  if&#40;&#40;sock = socket&#40;AF_INET, SOCK_STREAM, IPPROTO_TCP&#41;&#41; < 0&#41; return&#40;0&#41;;

  l.l_onoff = 1; l.l_linger = 5;
  if&#40;setsockopt&#40;sock, SOL_SOCKET, SO_LINGER, &#40;char*&#41; &l, sizeof&#40;l&#41;&#41; < 0&#41; return&#40;0&#41;;

  if&#40;connect&#40;sock, &#40;struct sockaddr *&#41; &stAddr, sizeof&#40;stAddr&#41;&#41; < 0&#41; return&#40;0&#41;;

  return&#40;sock&#41;;
&#125;

int udp_open&#40;char * address, int port&#41;
&#123;
  int enable = 1L;
  struct sockaddr_in stAddr;
  struct sockaddr_in stLclAddr;
  struct ip_mreq stMreq;
  struct hostent * host;
  int sock;

  stAddr.sin_family = AF_INET; 
  stAddr.sin_port = htons&#40;port&#41;;

  if&#40;&#40;host = gethostbyname&#40;address&#41;&#41; == NULL&#41; return&#40;0&#41;;

  stAddr.sin_addr = *&#40;&#40;struct in_addr *&#41; host->h_addr_list&#91;0&#93;&#41; ;

  /* Create a UDP socket */
  if&#40;&#40;sock = socket&#40;AF_INET, SOCK_DGRAM, 0&#41;&#41; < 0&#41; return&#40;0&#41;;
	    
  /* Allow multiple instance of the client to share the same address and port */
  if&#40;setsockopt&#40;sock, SOL_SOCKET, SO_REUSEADDR, &#40;char *&#41; &enable, sizeof&#40;unsigned long int&#41;&#41; < 0&#41; return&#40;0&#41;;
  
  /* If the address is multicast, register to the multicast group */
  if&#40;is_address_multicast&#40;stAddr.sin_addr.s_addr&#41;&#41;
  &#123;
    /* Bind the socket to port */
    stLclAddr.sin_family      = AF_INET;
    stLclAddr.sin_addr.s_addr = htonl&#40;INADDR_ANY&#41;;
    stLclAddr.sin_port        = stAddr.sin_port;
    if&#40;bind&#40;sock, &#40;struct sockaddr*&#41; & stLclAddr, sizeof&#40;stLclAddr&#41;&#41; < 0&#41; return&#40;0&#41;;
      
    /* Register to a multicast address */
    stMreq.imr_multiaddr.s_addr = stAddr.sin_addr.s_addr;
    stMreq.imr_interface.s_addr = INADDR_ANY;
    if&#40;setsockopt&#40;sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &#40;char *&#41; & stMreq, sizeof&#40;stMreq&#41;&#41; < 0&#41; return&#40;0&#41;;
  &#125;
  else
  &#123;
    /* Bind the socket to port */
    stLclAddr.sin_family      = AF_INET;
    stLclAddr.sin_addr.s_addr = htonl&#40;INADDR_ANY&#41;;
    stLclAddr.sin_port        = htons&#40;0&#41;;
    if&#40;bind&#40;sock, &#40;struct sockaddr*&#41; & stLclAddr, sizeof&#40;stLclAddr&#41;&#41; < 0&#41; return&#40;0&#41;;
  &#125;
  
  return&#40;sock&#41;;
&#125;

#ifdef RAW_SUPPORT
int raw_open&#40;char * arg&#41;
&#123;
  char * host;
  int port;
  int sock;

  /* Check for URL syntax */
  if&#40;strncmp&#40;arg, "raw&#58;//", strlen&#40;"raw&#58;//"&#41;&#41;&#41; return&#40;0&#41;;

  /* Parse URL */
  port = 0;
  host = arg + strlen&#40;"raw&#58;//"&#41;;
  if&#40;strchr&#40;host, '&#58;'&#41; != NULL&#41; /* port is specified */
  &#123;
    port = atoi&#40;strchr&#40;host, '&#58;'&#41; + 1&#41;;
    *strchr&#40;host, '&#58;'&#41; = 0;
  &#125;

  /* Open a UDP socket */
  if&#40;!&#40;sock = udp_open&#40;host, port&#41;&#41;&#41;
    perror&#40;"raw_open"&#41;;
  
  return&#40;sock&#41;;
&#125;
#endif

#ifdef HTTP_SUPPORT
int http_open&#40;char * arg&#41;
&#123;
  char * host;
  int port;
  char * request;
  int tcp_sock;
  char http_request&#91;1024&#93;;
  char c;

  /* Check for URL syntax */
  if&#40;strncmp&#40;arg, "http&#58;//", strlen&#40;"http&#58;//"&#41;&#41;&#41; return&#40;0&#41;;

  /* Parse URL */
  port = 80;
  host = arg + strlen&#40;"http&#58;//"&#41;;
  if&#40;&#40;request = strchr&#40;host, '/'&#41;&#41; == NULL&#41; return&#40;0&#41;;
  *request++ = 0;
  if&#40;strchr&#40;host, '&#58;'&#41; != NULL&#41; /* port is specified */
  &#123;
    port = atoi&#40;strchr&#40;host, '&#58;'&#41; + 1&#41;;
    *strchr&#40;host, '&#58;'&#41; = 0;
  &#125; 

  /* Open a TCP socket */
  if&#40;!&#40;tcp_sock = tcp_open&#40;host, port&#41;&#41;&#41;
  &#123;
    perror&#40;"http_open"&#41;;
    return&#40;0&#41;;
  &#125;

  /* Send HTTP GET request */
  sprintf&#40;http_request, 
	  "GET /%s HTTP/1.0\r\n"
	  "User-Agent&#58; Mozilla/2.0 &#40;Win95; I&#41;\r\n"
	  "Pragma&#58; no-cache\r\n"
	  "Host&#58; %s\r\n"
	  "Accept&#58; */*\r\n"
	  "\r\n",
	  request, host&#41;;
  send&#40;tcp_sock, http_request, strlen&#40;http_request&#41;, 0&#41;;
  
  /* Parse server reply */
  do read&#40;tcp_sock, &c, sizeof&#40;char&#41;&#41;; while&#40;c != ' '&#41;;
  read&#40;tcp_sock, http_request, 4*sizeof&#40;char&#41;&#41;;
  http_request&#91;4&#93; = 0;
  if&#40;strcmp&#40;http_request, "200 "&#41;&#41;
  &#123;
    fprintf&#40;stderr, "http_open&#58; "&#41;;
    do &#123; 
      read&#40;tcp_sock, &c, sizeof&#40;char&#41;&#41;;
      fprintf&#40;stderr, "%c", c&#41;; 
    &#125;
    while&#40;c != '\r'&#41;;
    fprintf&#40;stderr, "\n"&#41;;
    return&#40;0&#41;;
  &#125;
  
  return&#40;tcp_sock&#41;;
&#125;
#endif
#ifdef FTP_SUPPORT
int ftp_get_reply&#40;int tcp_sock&#41;
&#123;
  int i;
  char c;
  char answer&#91;1024&#93;;

  do &#123;
    /* Read a line */
    for&#40;i = 0, c = 0; i < 1024 && c != '\n'; i++&#41;
    &#123;
      read&#40;tcp_sock, &c, sizeof&#40;char&#41;&#41;;
      answer&#91;i&#93; = c;
    &#125;
    answer&#91;i&#93; = 0;
    fprintf&#40;stderr, answer + 4&#41;;
  &#125;
  while&#40;answer&#91;3&#93; == '-'&#41;;

  answer&#91;3&#93; = 0;

  return&#40;atoi&#40;answer&#41;&#41;;
&#125;

int ftp_open&#40;char * arg&#41;
&#123;
  char * host;
  int port;
  char * dir;
  char * file;
  int tcp_sock;
  int data_sock;
  char ftp_request&#91;1024&#93;;
  struct sockaddr_in stLclAddr;
  socklen_t namelen;
  int i;

  /* Check for URL syntax */
  if&#40;strncmp&#40;arg, "ftp&#58;//", strlen&#40;"ftp&#58;//"&#41;&#41;&#41; return&#40;0&#41;;

  /* Parse URL */
  port = 21;
  host = arg + strlen&#40;"ftp&#58;//"&#41;;
  if&#40;&#40;dir = strchr&#40;host, '/'&#41;&#41; == NULL&#41; return&#40;0&#41;;
  *dir++ = 0;
  if&#40;&#40;file = strrchr&#40;dir, '/'&#41;&#41; == NULL&#41; &#123;
    file = dir;
    dir = NULL;
  &#125; else
    *file++ = 0;

  if&#40;strchr&#40;host, '&#58;'&#41; != NULL&#41; /* port is specified */
  &#123;
    port = atoi&#40;strchr&#40;host, '&#58;'&#41; + 1&#41;;
    *strchr&#40;host, '&#58;'&#41; = 0;
  &#125;

  /* Open a TCP socket */
  if&#40;!&#40;tcp_sock = tcp_open&#40;host, port&#41;&#41;&#41;
  &#123;
    perror&#40;"ftp_open"&#41;;
    return&#40;0&#41;;
  &#125;

  /* Send FTP USER and PASS request */
  ftp_get_reply&#40;tcp_sock&#41;;
  sprintf&#40;ftp_request, "USER anonymous\r\n"&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 331&#41; return&#40;0&#41;;
  sprintf&#40;ftp_request, "PASS smpeguser@\r\n"&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 230&#41; return&#40;0&#41;;
  sprintf&#40;ftp_request, "TYPE I\r\n"&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 200&#41; return&#40;0&#41;;
  if&#40;dir != NULL&#41;
  &#123;
    sprintf&#40;ftp_request, "CWD %s\r\n", dir&#41;;
    send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
    if&#40;ftp_get_reply&#40;tcp_sock&#41; != 250&#41; return&#40;0&#41;;
  &#125;
    
  /* Get interface address */
  namelen = sizeof&#40;stLclAddr&#41;;
  if&#40;getsockname&#40;tcp_sock, &#40;struct sockaddr *&#41; &stLclAddr, &namelen&#41; < 0&#41;
    return&#40;0&#41;;

  /* Open data socket */
  if &#40;&#40;data_sock = socket&#40;PF_INET, SOCK_STREAM, 0&#41;&#41; < 0&#41; return&#40;0&#41;;

  stLclAddr.sin_family = AF_INET;

  /* Get the first free port */
  for&#40;i = 0; i < 0xC000; i++&#41; &#123;
    stLclAddr.sin_port = htons&#40;0x4000 + i&#41;;
    if&#40;bind&#40;data_sock, &#40;struct sockaddr *&#41; &stLclAddr, sizeof&#40;stLclAddr&#41;&#41; >= 0&#41; break;
  &#125;
  port = 0x4000 + i;

  if&#40;listen&#40;data_sock, 1&#41; < 0&#41; return&#40;0&#41;;

  i = ntohl&#40;stLclAddr.sin_addr.s_addr&#41;;
  sprintf&#40;ftp_request, "PORT %d,%d,%d,%d,%d,%d\r\n",
	    &#40;i >> 24&#41; & 0xFF, &#40;i >> 16&#41; & 0xFF,
	    &#40;i >> 8&#41; & 0xFF, i & 0xFF,
	    &#40;port >> 8&#41; & 0xFF, port & 0xFF&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 200&#41; return&#40;0&#41;;

  sprintf&#40;ftp_request, "RETR %s\r\n", file&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 150&#41; return&#40;0&#41;;

  return&#40;accept&#40;data_sock, NULL, NULL&#41;&#41;;
&#125;
#endif
#endif

#ifdef VCD_SUPPORT
int vcd_read&#40;int fd, int lba, unsigned char *buf&#41;
&#123;
    struct cdrom_msf *msf;

    msf = &#40;struct cdrom_msf*&#41; buf;
    msf->cdmsf_min0   = &#40;lba + CD_MSF_OFFSET&#41; / CD_FRAMES / CD_SECS; 
    msf->cdmsf_sec0   = &#40;lba + CD_MSF_OFFSET&#41; / CD_FRAMES % CD_SECS;
    msf->cdmsf_frame0 = &#40;lba + CD_MSF_OFFSET&#41; % CD_FRAMES;
    return&#40;ioctl&#40;fd, CDROMREADMODE2, buf&#41;&#41;;
&#125;

int vcd_open&#40;char * arg&#41;
&#123;
  struct stat buf;
  struct cdrom_tocentry toc;
  char *pip;
  int track;
  int pipe_fd&#91;2&#93;;
  int fd;
  int pid, parent;
  unsigned char * buffer;
  
  /* Track defaults to 02, unless requested otherwise */
  track = 02;
  pip = strrchr&#40;arg, '&#58;'&#41;;
  if &#40; pip &#41; &#123;
    *pip = '\0';
    track = atoi&#40;pip+1&#41; + 1;
  &#125;

  /* See if the CD-ROM device file exists */
  if &#40; &#40;stat&#40;arg, &buf&#41; < 0&#41; || !S_ISBLK&#40;buf.st_mode&#41; &#41; &#123;
    if &#40; pip &#41; &#123;
      *pip = '&#58;';
    &#125;
    return&#40;0&#41;;
  &#125;

  fd = open&#40;arg, O_RDONLY, 0&#41;;
  if &#40; fd < 0 &#41; &#123;
    if &#40; pip &#41; &#123;
      *pip = '&#58;';
    &#125;
    return&#40;0&#41;;
  &#125;

  /* Track 02 &#40;changed to 'track'&#41; contains MPEG data */
  if &#40; track < 2 &#41; &#123;
    printf&#40;"Warning&#58; VCD data normally starts on track 2\n"&#41;;
  &#125;
  toc.cdte_track  = track; 
  toc.cdte_format = CDROM_LBA;
  if&#40;ioctl&#40;fd, CDROMREADTOCENTRY, &toc&#41; < 0&#41; return&#40;0&#41;;

  if&#40;pipe&#40;pipe_fd&#41; < 0&#41; return&#40;0&#41;;

  parent = getpid&#40;&#41;;
  pid = fork&#40;&#41;;

  if&#40;pid < 0&#41; return&#40;0&#41;;

  if&#40;!pid&#41;
  &#123;
    /* Child process fills the pipe */
    int pos;
    struct timeval timeout;
    fd_set fdset;

    buffer = &#40;unsigned char *&#41; malloc&#40;CD_FRAMESIZE_RAW0&#41;;

    for&#40;pos = toc.cdte_addr.lba; vcd_read&#40;fd, pos, buffer&#41; >= 0; pos ++&#41;
    &#123;
      if&#40;kill&#40;parent, 0&#41; < 0&#41; break;

      FD_ZERO&#40;&fdset&#41;;
      FD_SET&#40;pipe_fd&#91;1&#93;, &fdset&#41;;
      timeout.tv_sec = 10;
      timeout.tv_usec = 0;
      if&#40;select&#40;pipe_fd&#91;1&#93;+1, NULL, &fdset, NULL, &timeout&#41; <= 0&#41; break;
      if&#40;write&#40;pipe_fd&#91;1&#93;, buffer, CD_FRAMESIZE_RAW0&#41; < 0&#41; break;
    &#125;

    free&#40;buffer&#41;;
    exit&#40;0&#41;;
  &#125;
  
  return&#40;pipe_fd&#91;0&#93;&#41;;
&#125;
#endif

void update&#40;SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h&#41;
&#123;
    if &#40; screen->flags & SDL_DOUBLEBUF &#41; &#123;
        SDL_Flip&#40;screen&#41;;
    &#125;
&#125;

/* Flag telling the UI that the movie or song should be skipped */
int done;

void next_movie&#40;int sig&#41;
&#123;
	done = 1;
&#125;

int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	printf&#40;"Press X to run homebrew at ms0&#58;/PSP/GAME/HOMEBREW/EBOOT.PBP\n"&#41;;
    int use_audio, use_video;
    int fullscreen;
    int scalesize;
    int scale_width, scale_height;
    int loop_play;
    int i, pause;
    int volume;
    Uint32 seek;
    float skip;
    int bilinear_filtering;
    SDL_Surface *screen;
    SMPEG *mpeg;
    SMPEG_Info info;
    char *basefile;
    const char *title = NULL;
    SDL_version sdlver;
    SMPEG_version smpegver;
    int fd;
    char buf&#91;32&#93;;
    int status;

    /* Get the command line options */
    use_audio = 1;
    use_video = 1;
    fullscreen = 0;
    scalesize = 1;
    scale_width = 0;
    scale_height = 0;
    loop_play = 0;
    volume = 100;
    seek = 0;
    skip = 0;
    bilinear_filtering = 0;
    fd = 0;
	
    for &#40; i=1; argv&#91;i&#93; && &#40;argv&#91;i&#93;&#91;0&#93; == '-'&#41; && &#40;argv&#91;i&#93;&#91;1&#93; != 0&#41;; ++i &#41; &#123;
        if &#40; &#40;strcmp&#40;argv&#91;i&#93;, "--noaudio"&#41; == 0&#41; ||
             &#40;strcmp&#40;argv&#91;i&#93;, "--nosound"&#41; == 0&#41; &#41; &#123;
            use_audio = 0;
        &#125; else
        if &#40; strcmp&#40;argv&#91;i&#93;, "--novideo"&#41; == 0 &#41; &#123;
            use_video = 0;
        &#125; else
        if &#40; strcmp&#40;argv&#91;i&#93;, "--fullscreen"&#41; == 0 &#41; &#123;
            fullscreen = 1;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--double"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-2"&#41; == 0&#41;&#41; &#123;
            scalesize = 2;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--loop"&#41; == 0&#41; || &#40;strcmp&#40;argv&#91;i&#93;, "-l"&#41; == 0&#41;&#41; &#123;
            loop_play = 1;
        &#125; else
        if &#40; strcmp&#40;argv&#91;i&#93;, "--bilinear"&#41; == 0 &#41; &#123;
            bilinear_filtering = 1;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--seek"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-S"&#41; == 0&#41;&#41; &#123;
            ++i;
            if &#40; argv&#91;i&#93; &#41; &#123;
                seek = atol&#40;argv&#91;i&#93;&#41;;
            &#125;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--skip"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-k"&#41; == 0&#41;&#41; &#123;
            ++i;
            if &#40; argv&#91;i&#93; &#41; &#123;
                skip = &#40;float&#41;atof&#40;argv&#91;i&#93;&#41;;
            &#125;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--volume"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-v"&#41; == 0&#41;&#41; &#123;
            ++i;
	    if &#40;i >= argc&#41;
	      &#123;
		fprintf&#40;stderr, "Please specify volume when using --volume or -v\n"&#41;;
		return&#40;1&#41;;
	      &#125;
            if &#40; argv&#91;i&#93; &#41; &#123;
                volume = atoi&#40;argv&#91;i&#93;&#41;;
            &#125;
	    if &#40; &#40; volume < 0 &#41; || &#40; volume > 100 &#41; &#41; &#123;
	      fprintf&#40;stderr, "Volume must be between 0 and 100\n"&#41;;
	      volume = 100;
	    &#125;
	&#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--title"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-t"&#41; == 0&#41;&#41; &#123;
            ++i;
	    if &#40;i >= argc&#41;
	      &#123;
		fprintf&#40;stderr, "Please specify title when using --title or -t\n"&#41;;
		return&#40;1&#41;;
	      &#125;
            if &#40; argv&#91;i&#93; &#41; &#123;
                title = argv&#91;i&#93;;
            &#125;
	&#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--version"&#41; == 0&#41; ||
	    &#40;strcmp&#40;argv&#91;i&#93;, "-V"&#41; == 0&#41;&#41; &#123;
            sdlver = *SDL_Linked_Version&#40;&#41;;
            SMPEG_VERSION&#40;&smpegver&#41;;
	    printf&#40;"SDL version&#58; %d.%d.%d\n"
                   "SMPEG version&#58; %d.%d.%d\n",
		   sdlver.major, sdlver.minor, sdlver.patch,
		   smpegver.major, smpegver.minor, smpegver.patch&#41;;
            return&#40;0&#41;;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--scale"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-s"&#41; == 0&#41;&#41; &#123;
            ++i;
            if &#40; argv&#91;i&#93; &#41; &#123;
                sscanf&#40;argv&#91;i&#93;, "%dx%d", &scale_width, &scale_height&#41;;
            &#125;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--help"&#41; == 0&#41; || &#40;strcmp&#40;argv&#91;i&#93;, "-h"&#41; == 0&#41;&#41; &#123;
            usage&#40;argv&#91;0&#93;&#41;;
            return&#40;0&#41;;
        &#125; else &#123;
            fprintf&#40;stderr, "Warning&#58; Unknown option&#58; %s\n", argv&#91;i&#93;&#41;;
        &#125;
    &#125;
    /* If there were no arguments just print the usage */
    if &#40;argc == 1&#41; &#123;
        usage&#40;argv&#91;0&#93;&#41;;
        return&#40;0&#41;;
    &#125;

#if defined&#40;linux&#41; || defined&#40;__FreeBSD__&#41; /* Plaympeg doesn't need a mouse */
    putenv&#40;"SDL_NOMOUSE=1"&#41;;
#endif

    /* Play the mpeg files! */
    status = 0;
    for &#40; ; argv&#91;i&#93;; ++i &#41; &#123;
	/* Initialize SDL */
	if &#40; use_video &#41; &#123;
	  if &#40;&#40;SDL_Init&#40;SDL_INIT_VIDEO&#41; < 0&#41; || !SDL_VideoDriverName&#40;buf, 1&#41;&#41; &#123;
	    fprintf&#40;stderr, "Warning&#58; Couldn't init SDL video&#58; %s\n",
		    SDL_GetError&#40;&#41;&#41;;
	    fprintf&#40;stderr, "Will ignore video stream\n"&#41;;
	    use_video = 0;
	  &#125;
	&#125;
	
	if &#40; use_audio &#41; &#123;
	  if &#40;&#40;SDL_Init&#40;SDL_INIT_AUDIO&#41; < 0&#41; || !SDL_AudioDriverName&#40;buf, 1&#41;&#41; &#123;
	    fprintf&#40;stderr, "Warning&#58; Couldn't init SDL audio&#58; %s\n",
		    SDL_GetError&#40;&#41;&#41;;
	    fprintf&#40;stderr, "Will ignore audio stream\n"&#41;;
	    use_audio = 0;
	  &#125;
	&#125;

	/* Allow Ctrl-C when there's no video output */
	signal&#40;SIGINT, next_movie&#41;;
	
        /* Create the MPEG stream */
#ifdef NET_SUPPORT
#ifdef RAW_SUPPORT
        /* Check if source is an IP address and port*/
        if&#40;&#40;fd = raw_open&#40;argv&#91;i&#93;&#41;&#41; != 0&#41;
	  mpeg = SMPEG_new_descr&#40;fd, &info, use_audio&#41;;
	else
#endif
#ifdef HTTP_SUPPORT
        /* Check if source is an http URL */
        if&#40;&#40;fd = http_open&#40;argv&#91;i&#93;&#41;&#41; != 0&#41;
	  mpeg = SMPEG_new_descr&#40;fd, &info, use_audio&#41;;
	else
#endif
#ifdef FTP_SUPPORT
        /* Check if source is an http URL */
        if&#40;&#40;fd = ftp_open&#40;argv&#91;i&#93;&#41;&#41; != 0&#41;
	  mpeg = SMPEG_new_descr&#40;fd, &info, use_audio&#41;;
	else
#endif
#endif
#ifdef VCD_SUPPORT
	/* Check if source is a CDROM device */
	if&#40;&#40;fd = vcd_open&#40;argv&#91;i&#93;&#41;&#41; != 0&#41;
	  mpeg = SMPEG_new_descr&#40;fd, &info, use_audio&#41;;
	else
#endif
	&#123;
	  if&#40;strcmp&#40;argv&#91;i&#93;, "-"&#41; == 0&#41; /* Use stdin for input */
	    mpeg = SMPEG_new_descr&#40;0, &info, use_audio&#41;;
	  else
	    mpeg = SMPEG_new&#40;argv&#91;i&#93;, &info, use_audio&#41;;
	&#125;

        if &#40; SMPEG_error&#40;mpeg&#41; &#41; &#123;
            fprintf&#40;stderr, "%s&#58; %s\n", argv&#91;i&#93;, SMPEG_error&#40;mpeg&#41;&#41;;
            SMPEG_delete&#40;mpeg&#41;;
            status = -1;
            continue;
        &#125;
        SMPEG_enableaudio&#40;mpeg, use_audio&#41;;
        SMPEG_enablevideo&#40;mpeg, use_video&#41;;
        SMPEG_setvolume&#40;mpeg, volume&#41;;

        /* Enable software bilinear filtering, if desired */
        if &#40; bilinear_filtering &#41; &#123;
            SMPEG_Filter *filter;

            filter = SMPEGfilter_bilinear&#40;&#41;;
            filter = SMPEG_filter&#40; mpeg, filter &#41;;
            filter->destroy&#40;filter&#41;;
        &#125;

        /* Print information about the video */
        basefile = strrchr&#40;argv&#91;i&#93;, '/'&#41;;
        if &#40; basefile &#41; &#123;
            ++basefile;
        &#125; else &#123;
            basefile = argv&#91;i&#93;;
        &#125;
        if &#40; info.has_audio && info.has_video &#41; &#123;
            printf&#40;"%s&#58; MPEG system stream &#40;audio/video&#41;\n", basefile&#41;;
        &#125; else if &#40; info.has_audio &#41; &#123;
            printf&#40;"%s&#58; MPEG audio stream\n", basefile&#41;;
        &#125; else if &#40; info.has_video &#41; &#123;
            printf&#40;"%s&#58; MPEG video stream\n", basefile&#41;;
        &#125;
        if &#40; info.has_video &#41; &#123;
            printf&#40;"\tVideo %dx%d resolution\n", info.width, info.height&#41;;
        &#125;
        if &#40; info.has_audio &#41; &#123;
	    printf&#40;"\tAudio %s\n", info.audio_string&#41;;
        &#125;
        if &#40; info.total_size &#41; &#123;
	    printf&#40;"\tSize&#58; %d\n", info.total_size&#41;;
        &#125;
        if &#40; info.total_time &#41; &#123;
	    printf&#40;"\tTotal time&#58; %f\n", info.total_time&#41;;
        &#125;

        /* Set up video display if needed */
        if &#40; info.has_video && use_video &#41; &#123;
            const SDL_VideoInfo *video_info;
            Uint32 video_flags;
            int video_bpp;
            int width, height;

            /* Get the "native" video mode */
            video_info = SDL_GetVideoInfo&#40;&#41;;
            switch &#40;video_info->vfmt->BitsPerPixel&#41; &#123;
                case 16&#58;
                case 24&#58;
                case 32&#58;
                    video_bpp = video_info->vfmt->BitsPerPixel;
                    break;
                default&#58;
                    video_bpp = 16;
                    break;
            &#125;
            if &#40; scale_width &#41; &#123;
                width = scale_width;
            &#125; else &#123;
                width = info.width;
            &#125;
            width *= scalesize;
            if &#40; scale_height &#41; &#123;
                height = scale_height;
            &#125; else &#123;
                height = info.height;
            &#125;
            height *= scalesize;
            video_flags = SDL_SWSURFACE;
            if &#40; fullscreen &#41; &#123;
                video_flags = SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_HWSURFACE;
            &#125;
            video_flags |= SDL_ASYNCBLIT;
            video_flags |= SDL_RESIZABLE;
            screen = SDL_SetVideoMode&#40;width, height, video_bpp, video_flags&#41;;
            if &#40; screen == NULL &#41; &#123;
                fprintf&#40;stderr, "Unable to set %dx%d video mode&#58; %s\n",
                                	width, height, SDL_GetError&#40;&#41;&#41;;
                continue;
            &#125;
            if &#40;title != NULL&#41; &#123;
                SDL_WM_SetCaption&#40;title, title&#41;;
            &#125; else &#123;
                SDL_WM_SetCaption&#40;argv&#91;i&#93;, "plaympeg"&#41;;
            &#125;
            if &#40; screen->flags & SDL_FULLSCREEN &#41; &#123;
                SDL_ShowCursor&#40;0&#41;;
            &#125;
            SMPEG_setdisplay&#40;mpeg, screen, NULL, update&#41;;
            SMPEG_scaleXY&#40;mpeg, screen->w, screen->h&#41;;
        &#125; else &#123;
            SDL_QuitSubSystem&#40;SDL_INIT_VIDEO&#41;;
        &#125;

        /* Set any special playback parameters */
        if &#40; loop_play &#41; &#123;
            SMPEG_loop&#40;mpeg, 1&#41;;
        &#125;

	/* Seek starting position */
	if&#40;seek&#41; SMPEG_seek&#40;mpeg, seek&#41;;

	/* Skip seconds to starting position */
	if&#40;skip&#41; SMPEG_skip&#40;mpeg, skip&#41;;
	
        /* Play it, and wait for playback to complete */
        SMPEG_play&#40;mpeg&#41;;
        done = 0;
	pause = 0;
        while &#40; ! done && &#40; pause || &#40;SMPEG_status&#40;mpeg&#41; == SMPEG_PLAYING&#41; &#41; &#41; &#123;
            SDL_Event event;

            while &#40; use_video && SDL_PollEvent&#40;&event&#41; &#41; &#123;
                switch &#40;event.type&#41; &#123;
                    case SDL_VIDEORESIZE&#58; &#123;
                        SDL_Surface *old_screen = screen;
                        SMPEG_pause&#40;mpeg&#41;;
                        screen = SDL_SetVideoMode&#40;event.resize.w, event.resize.h, screen->format->BitsPerPixel, screen->flags&#41;;
			if &#40; old_screen != screen &#41; &#123;
                            SMPEG_setdisplay&#40;mpeg, screen, NULL, update&#41;;
                        &#125;
                        SMPEG_scaleXY&#40;mpeg, screen->w, screen->h&#41;;
                        SMPEG_pause&#40;mpeg&#41;;
                    &#125; break;
                    case SDL_KEYDOWN&#58;
                        if &#40; &#40;event.key.keysym.sym == SDLK_ESCAPE&#41; || &#40;event.key.keysym.sym == SDLK_q&#41; &#41; &#123;
			  // Quit
			  done = 1;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_RETURN &#41; &#123;
			  // toggle fullscreen
			  if &#40; event.key.keysym.mod & KMOD_ALT &#41; &#123;
                            SDL_WM_ToggleFullScreen&#40;screen&#41;;
                            fullscreen = &#40;screen->flags & SDL_FULLSCREEN&#41;;
                            SDL_ShowCursor&#40;!fullscreen&#41;; 
                          &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_UP &#41; &#123;
			  // Volume up
			  if &#40; volume < 100 &#41; &#123;
			    if &#40; event.key.keysym.mod & KMOD_SHIFT &#41; &#123;   // 10+
			      volume += 10;
			    &#125; else if &#40; event.key.keysym.mod & KMOD_CTRL &#41; &#123; // 100+
			      volume = 100;
			    &#125; else &#123;                                     // 1+
			      volume++;
			    &#125;
			    if &#40; volume > 100 &#41; 
			      volume = 100;
			    SMPEG_setvolume&#40;mpeg, volume&#41;;
			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_DOWN &#41; &#123;
			  // Volume down
			  if &#40; volume > 0 &#41; &#123;
			    if &#40; event.key.keysym.mod & KMOD_SHIFT &#41; &#123;
			      volume -= 10;
			    &#125; else if &#40; event.key.keysym.mod & KMOD_CTRL &#41; &#123;
			      volume = 0;
			    &#125; else &#123;
			      volume--;
			    &#125;
			    if &#40; volume < 0 &#41; 
			      volume = 0;
			    SMPEG_setvolume&#40;mpeg, volume&#41;;
			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_PAGEUP &#41; &#123;
			  // Full volume
			  volume = 100;
			  SMPEG_setvolume&#40;mpeg, volume&#41;;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_PAGEDOWN &#41; &#123;
			  // Volume off
			  volume = 0;
			  SMPEG_setvolume&#40;mpeg, volume&#41;;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_SPACE &#41; &#123;
			  // Toggle play / pause
			  if &#40; SMPEG_status&#40;mpeg&#41; == SMPEG_PLAYING &#41; &#123;
			    SMPEG_pause&#40;mpeg&#41;;
			    pause = 1;
			  &#125; else &#123;
			    SMPEG_play&#40;mpeg&#41;;
			    pause = 0;
			  &#125;
			&#125; else if &#40; event.key.keysym.sym == SDLK_RIGHT &#41; &#123;
			  // Forward
			  if &#40; event.key.keysym.mod & KMOD_SHIFT &#41; &#123;
			    SMPEG_skip&#40;mpeg, 100&#41;;
			  &#125; else if &#40; event.key.keysym.mod & KMOD_CTRL &#41; &#123;
			    SMPEG_skip&#40;mpeg, 50&#41;;
			  &#125; else &#123;
			    SMPEG_skip&#40;mpeg, 5&#41;;
			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_LEFT &#41; &#123;
			  // Reverse
			  if &#40; event.key.keysym.mod & KMOD_SHIFT &#41; &#123;

			  &#125; else if &#40; event.key.keysym.mod & KMOD_CTRL &#41; &#123;

			  &#125; else &#123;

			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_KP_MINUS &#41; &#123;
			  // Scale minus
			  if &#40; scalesize > 1 &#41; &#123;
			    scalesize--;
			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_KP_PLUS &#41; &#123;
			  // Scale plus
			  scalesize++;
			&#125; else if &#40; event.key.keysym.sym == SDLK_f &#41; &#123;
			  // Toggle filtering on/off
			  if &#40; bilinear_filtering &#41; &#123;
			    SMPEG_Filter *filter = SMPEGfilter_null&#40;&#41;;
			    filter = SMPEG_filter&#40; mpeg, filter &#41;;
			    filter->destroy&#40;filter&#41;;
			    bilinear_filtering = 0;
			  &#125; else &#123;
			    SMPEG_Filter *filter = SMPEGfilter_bilinear&#40;&#41;;
			    filter = SMPEG_filter&#40; mpeg, filter &#41;;
			    filter->destroy&#40;filter&#41;;
			    bilinear_filtering = 1;
			  &#125;
			&#125;
                        break;
                    case SDL_QUIT&#58;
                        done = 1;
                        break;
                    default&#58;
                        break;
                &#125;
            &#125;
            SDL_Delay&#40;1000/2&#41;;
        &#125;
        SMPEG_delete&#40;mpeg&#41;;
    &#125;
    SDL_Quit&#40;&#41;;

#if defined&#40;RAW_SUPPORT&#41; || defined&#40;HTTP_SUPPORT&#41; || defined&#40;FTP_SUPPORT&#41; || \
    defined&#40;VCD_SUPPORT&#41;
    if&#40;fd&#41; close&#40;fd&#41;;
#endif

    //return&#40;status&#41;;
	return 0;
&#125;
Makefile:

Code: Select all

TARGET = plaympeg
OBJS = plaympeg.o

INCDIR = 
CFLAGS = $&#40;GLOBAL_CFLAGS&#41; -O2 -Wall -g `$&#40;PSPDEV&#41;/psp/bin/sdl-config --cflags`
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LDFLAGS = 
LIBS = `$&#40;PSPDEV&#41;/psp/bin/sdl-config --libs`

LIBDIR =
LDFLAGS = 
LIBS = -lsmpeg -lSDL -lpsphprm -lpspgu -lpspgum -lpspaudio -lstdc++ -lm

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = playMpeg

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
This is full source code:
http://rapidshare.com/files/167665483/plaympeg.rar.html

SMPEG-PSP Library:
http://code.google.com/p/smpeg-psp/

What should i do?
I'm sorry for my bad English.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Isn't smpeg C++? I've seen issues where people were trying to compile a c++ app with the c compiler, or vice versa.
ardatan
Posts: 44
Joined: Sat Jan 12, 2008 8:47 am

Post by ardatan »

Yes i solved this program with rename plaympeg.c to plaympeg.cpp.. And i edited Makefile. As a result, i compiled it without any errors. For argv variable, i added it to irshell as a plugin. But when i try open a mpeg-1 video(With sound), it only plays sound(for 10 sec) and crash.

plaympeg.cpp

Code: Select all

/*
   plaympeg - Sample MPEG player using the SMPEG library
   Copyright &#40;C&#41; 1999 Loki Entertainment Software
   
   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
   &#40;at your option&#41; 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 <pspsdk.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <psploadexec_kernel.h>
#include <kubridge.h>
#include <systemctrl.h>
#include <systemctrl_se.h>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#ifdef unix
#include <unistd.h>

#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/time.h>

#define NET_SUPPORT  /* General network support */
#define RAW_SUPPORT  /* Raw data transport support */
#define HTTP_SUPPORT /* HTTP support */
#define FTP_SUPPORT  /* FTP support */
#ifdef linux
#define VCD_SUPPORT  /* Video CD support */
#endif
#endif

#ifdef NET_SUPPORT
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#endif

#ifdef VCD_SUPPORT
#include <signal.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <linux/cdrom.h>
#endif

#include "smpeg.h"

PSP_MODULE_INFO&#40;"playMpeg", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;

PSP_HEAP_SIZE_MAX&#40;&#41;;

#define printf    pspDebugScreenPrintf

int Kapat_GeriBildirim&#40;int param1, int param2, void *ortak&#41; &#123;
sceKernelExitGame&#40;&#41;;
return 0;
&#125;

/* Aç&#305;l&#305;&#351; Geribildirimi */
int AcilisGeriBildirimi&#40;SceSize args, void *argp&#41; &#123;
int gbid; //Geri Bildirim &#304;D&#40;Kimlik numaras&#305;&#41;

gbid = sceKernelCreateCallback&#40;"Kapat Geribildirimi", Kapat_GeriBildirim, NULL&#41;;
sceKernelRegisterExitCallback&#40;gbid&#41;;

sceKernelSleepThreadCB&#40;&#41;;

return 0;
&#125;

// Geri Bildirimlerin Ayarlanmas&#305;, Dönen de&#287;erler &#304;D &#40;Kimliklere Gönderilir&#41;
int GeriBildirimleriAyarla&#40;void&#41; &#123;
int ayid = 0; //Ayarlar &#304;D Kimlik Numaras&#305;

ayid = sceKernelCreateThread&#40;"Yenile", AcilisGeriBildirimi, 0x11, 0xFA0, 0, 0&#41;;
if&#40;ayid >= 0&#41; &#123;
sceKernelStartThread&#40;ayid, 0, 0&#41;;
&#125;

return ayid;
&#125;


void usage&#40;char *argv0&#41;
&#123;
    printf&#40;
"Usage&#58; %s &#91;options&#93; file ...\n"
"Where the options are one of&#58;\n"
"	--noaudio	     Don't play audio stream\n"
"	--novideo	     Don't play video stream\n"
"	--fullscreen	     Play MPEG in fullscreen mode\n"
"	--double or -2	     Play MPEG at double size\n"
"	--loop or -l	     Play MPEG over and over\n"
"	--bilinear	     Use software bilinear filtering\n"
"	--volume N or -v N   Set audio volume to N &#40;0-100&#41;\n"
"	--title T or -t T  Set window's title to T\n"
"	--scale wxh or -s wxh  Play MPEG at given resolution\n"
"	--seek N or -S N     Skip N bytes\n"
#ifdef USE_SYSTEM_TIMESTAMP
"	--skip N or -k N     Skip N seconds\n"
#endif
"	--help or -h\n"
"	--version or -V\n"
"Specifying - as filename will use stdin for input\n", argv0&#41;;
&#125;

#ifdef NET_SUPPORT
int is_address_multicast&#40;unsigned long address&#41;
&#123;
  if&#40;&#40;address & 255&#41; >= 224 && &#40;address & 255&#41; <= 239&#41; return&#40;1&#41;;
  return&#40;0&#41;;
&#125;

int tcp_open&#40;char * address, int port&#41;
&#123;
  struct sockaddr_in stAddr;
  struct hostent * host;
  int sock;
  struct linger l;

  memset&#40;&stAddr,0,sizeof&#40;stAddr&#41;&#41;;
  stAddr.sin_family = AF_INET ;
  stAddr.sin_port = htons&#40;port&#41;;

  if&#40;&#40;host = gethostbyname&#40;address&#41;&#41; == NULL&#41; return&#40;0&#41;;

  stAddr.sin_addr = *&#40;&#40;struct in_addr *&#41; host->h_addr_list&#91;0&#93;&#41; ;

  if&#40;&#40;sock = socket&#40;AF_INET, SOCK_STREAM, IPPROTO_TCP&#41;&#41; < 0&#41; return&#40;0&#41;;

  l.l_onoff = 1; l.l_linger = 5;
  if&#40;setsockopt&#40;sock, SOL_SOCKET, SO_LINGER, &#40;char*&#41; &l, sizeof&#40;l&#41;&#41; < 0&#41; return&#40;0&#41;;

  if&#40;connect&#40;sock, &#40;struct sockaddr *&#41; &stAddr, sizeof&#40;stAddr&#41;&#41; < 0&#41; return&#40;0&#41;;

  return&#40;sock&#41;;
&#125;

int udp_open&#40;char * address, int port&#41;
&#123;
  int enable = 1L;
  struct sockaddr_in stAddr;
  struct sockaddr_in stLclAddr;
  struct ip_mreq stMreq;
  struct hostent * host;
  int sock;

  stAddr.sin_family = AF_INET; 
  stAddr.sin_port = htons&#40;port&#41;;

  if&#40;&#40;host = gethostbyname&#40;address&#41;&#41; == NULL&#41; return&#40;0&#41;;

  stAddr.sin_addr = *&#40;&#40;struct in_addr *&#41; host->h_addr_list&#91;0&#93;&#41; ;

  /* Create a UDP socket */
  if&#40;&#40;sock = socket&#40;AF_INET, SOCK_DGRAM, 0&#41;&#41; < 0&#41; return&#40;0&#41;;
	    
  /* Allow multiple instance of the client to share the same address and port */
  if&#40;setsockopt&#40;sock, SOL_SOCKET, SO_REUSEADDR, &#40;char *&#41; &enable, sizeof&#40;unsigned long int&#41;&#41; < 0&#41; return&#40;0&#41;;
  
  /* If the address is multicast, register to the multicast group */
  if&#40;is_address_multicast&#40;stAddr.sin_addr.s_addr&#41;&#41;
  &#123;
    /* Bind the socket to port */
    stLclAddr.sin_family      = AF_INET;
    stLclAddr.sin_addr.s_addr = htonl&#40;INADDR_ANY&#41;;
    stLclAddr.sin_port        = stAddr.sin_port;
    if&#40;bind&#40;sock, &#40;struct sockaddr*&#41; & stLclAddr, sizeof&#40;stLclAddr&#41;&#41; < 0&#41; return&#40;0&#41;;
      
    /* Register to a multicast address */
    stMreq.imr_multiaddr.s_addr = stAddr.sin_addr.s_addr;
    stMreq.imr_interface.s_addr = INADDR_ANY;
    if&#40;setsockopt&#40;sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &#40;char *&#41; & stMreq, sizeof&#40;stMreq&#41;&#41; < 0&#41; return&#40;0&#41;;
  &#125;
  else
  &#123;
    /* Bind the socket to port */
    stLclAddr.sin_family      = AF_INET;
    stLclAddr.sin_addr.s_addr = htonl&#40;INADDR_ANY&#41;;
    stLclAddr.sin_port        = htons&#40;0&#41;;
    if&#40;bind&#40;sock, &#40;struct sockaddr*&#41; & stLclAddr, sizeof&#40;stLclAddr&#41;&#41; < 0&#41; return&#40;0&#41;;
  &#125;
  
  return&#40;sock&#41;;
&#125;

#ifdef RAW_SUPPORT
int raw_open&#40;char * arg&#41;
&#123;
  char * host;
  int port;
  int sock;

  /* Check for URL syntax */
  if&#40;strncmp&#40;arg, "raw&#58;//", strlen&#40;"raw&#58;//"&#41;&#41;&#41; return&#40;0&#41;;

  /* Parse URL */
  port = 0;
  host = arg + strlen&#40;"raw&#58;//"&#41;;
  if&#40;strchr&#40;host, '&#58;'&#41; != NULL&#41; /* port is specified */
  &#123;
    port = atoi&#40;strchr&#40;host, '&#58;'&#41; + 1&#41;;
    *strchr&#40;host, '&#58;'&#41; = 0;
  &#125;

  /* Open a UDP socket */
  if&#40;!&#40;sock = udp_open&#40;host, port&#41;&#41;&#41;
    perror&#40;"raw_open"&#41;;
  
  return&#40;sock&#41;;
&#125;
#endif

#ifdef HTTP_SUPPORT
int http_open&#40;char * arg&#41;
&#123;
  char * host;
  int port;
  char * request;
  int tcp_sock;
  char http_request&#91;1024&#93;;
  char c;

  /* Check for URL syntax */
  if&#40;strncmp&#40;arg, "http&#58;//", strlen&#40;"http&#58;//"&#41;&#41;&#41; return&#40;0&#41;;

  /* Parse URL */
  port = 80;
  host = arg + strlen&#40;"http&#58;//"&#41;;
  if&#40;&#40;request = strchr&#40;host, '/'&#41;&#41; == NULL&#41; return&#40;0&#41;;
  *request++ = 0;
  if&#40;strchr&#40;host, '&#58;'&#41; != NULL&#41; /* port is specified */
  &#123;
    port = atoi&#40;strchr&#40;host, '&#58;'&#41; + 1&#41;;
    *strchr&#40;host, '&#58;'&#41; = 0;
  &#125; 

  /* Open a TCP socket */
  if&#40;!&#40;tcp_sock = tcp_open&#40;host, port&#41;&#41;&#41;
  &#123;
    perror&#40;"http_open"&#41;;
    return&#40;0&#41;;
  &#125;

  /* Send HTTP GET request */
  sprintf&#40;http_request, 
	  "GET /%s HTTP/1.0\r\n"
	  "User-Agent&#58; Mozilla/2.0 &#40;Win95; I&#41;\r\n"
	  "Pragma&#58; no-cache\r\n"
	  "Host&#58; %s\r\n"
	  "Accept&#58; */*\r\n"
	  "\r\n",
	  request, host&#41;;
  send&#40;tcp_sock, http_request, strlen&#40;http_request&#41;, 0&#41;;
  
  /* Parse server reply */
  do read&#40;tcp_sock, &c, sizeof&#40;char&#41;&#41;; while&#40;c != ' '&#41;;
  read&#40;tcp_sock, http_request, 4*sizeof&#40;char&#41;&#41;;
  http_request&#91;4&#93; = 0;
  if&#40;strcmp&#40;http_request, "200 "&#41;&#41;
  &#123;
    fprintf&#40;stderr, "http_open&#58; "&#41;;
    do &#123; 
      read&#40;tcp_sock, &c, sizeof&#40;char&#41;&#41;;
      fprintf&#40;stderr, "%c", c&#41;; 
    &#125;
    while&#40;c != '\r'&#41;;
    fprintf&#40;stderr, "\n"&#41;;
    return&#40;0&#41;;
  &#125;
  
  return&#40;tcp_sock&#41;;
&#125;
#endif
#ifdef FTP_SUPPORT
int ftp_get_reply&#40;int tcp_sock&#41;
&#123;
  int i;
  char c;
  char answer&#91;1024&#93;;

  do &#123;
    /* Read a line */
    for&#40;i = 0, c = 0; i < 1024 && c != '\n'; i++&#41;
    &#123;
      read&#40;tcp_sock, &c, sizeof&#40;char&#41;&#41;;
      answer&#91;i&#93; = c;
    &#125;
    answer&#91;i&#93; = 0;
    fprintf&#40;stderr, answer + 4&#41;;
  &#125;
  while&#40;answer&#91;3&#93; == '-'&#41;;

  answer&#91;3&#93; = 0;

  return&#40;atoi&#40;answer&#41;&#41;;
&#125;

int ftp_open&#40;char * arg&#41;
&#123;
  char * host;
  int port;
  char * dir;
  char * file;
  int tcp_sock;
  int data_sock;
  char ftp_request&#91;1024&#93;;
  struct sockaddr_in stLclAddr;
  socklen_t namelen;
  int i;

  /* Check for URL syntax */
  if&#40;strncmp&#40;arg, "ftp&#58;//", strlen&#40;"ftp&#58;//"&#41;&#41;&#41; return&#40;0&#41;;

  /* Parse URL */
  port = 21;
  host = arg + strlen&#40;"ftp&#58;//"&#41;;
  if&#40;&#40;dir = strchr&#40;host, '/'&#41;&#41; == NULL&#41; return&#40;0&#41;;
  *dir++ = 0;
  if&#40;&#40;file = strrchr&#40;dir, '/'&#41;&#41; == NULL&#41; &#123;
    file = dir;
    dir = NULL;
  &#125; else
    *file++ = 0;

  if&#40;strchr&#40;host, '&#58;'&#41; != NULL&#41; /* port is specified */
  &#123;
    port = atoi&#40;strchr&#40;host, '&#58;'&#41; + 1&#41;;
    *strchr&#40;host, '&#58;'&#41; = 0;
  &#125;

  /* Open a TCP socket */
  if&#40;!&#40;tcp_sock = tcp_open&#40;host, port&#41;&#41;&#41;
  &#123;
    perror&#40;"ftp_open"&#41;;
    return&#40;0&#41;;
  &#125;

  /* Send FTP USER and PASS request */
  ftp_get_reply&#40;tcp_sock&#41;;
  sprintf&#40;ftp_request, "USER anonymous\r\n"&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 331&#41; return&#40;0&#41;;
  sprintf&#40;ftp_request, "PASS smpeguser@\r\n"&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 230&#41; return&#40;0&#41;;
  sprintf&#40;ftp_request, "TYPE I\r\n"&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 200&#41; return&#40;0&#41;;
  if&#40;dir != NULL&#41;
  &#123;
    sprintf&#40;ftp_request, "CWD %s\r\n", dir&#41;;
    send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
    if&#40;ftp_get_reply&#40;tcp_sock&#41; != 250&#41; return&#40;0&#41;;
  &#125;
    
  /* Get interface address */
  namelen = sizeof&#40;stLclAddr&#41;;
  if&#40;getsockname&#40;tcp_sock, &#40;struct sockaddr *&#41; &stLclAddr, &namelen&#41; < 0&#41;
    return&#40;0&#41;;

  /* Open data socket */
  if &#40;&#40;data_sock = socket&#40;PF_INET, SOCK_STREAM, 0&#41;&#41; < 0&#41; return&#40;0&#41;;

  stLclAddr.sin_family = AF_INET;

  /* Get the first free port */
  for&#40;i = 0; i < 0xC000; i++&#41; &#123;
    stLclAddr.sin_port = htons&#40;0x4000 + i&#41;;
    if&#40;bind&#40;data_sock, &#40;struct sockaddr *&#41; &stLclAddr, sizeof&#40;stLclAddr&#41;&#41; >= 0&#41; break;
  &#125;
  port = 0x4000 + i;

  if&#40;listen&#40;data_sock, 1&#41; < 0&#41; return&#40;0&#41;;

  i = ntohl&#40;stLclAddr.sin_addr.s_addr&#41;;
  sprintf&#40;ftp_request, "PORT %d,%d,%d,%d,%d,%d\r\n",
	    &#40;i >> 24&#41; & 0xFF, &#40;i >> 16&#41; & 0xFF,
	    &#40;i >> 8&#41; & 0xFF, i & 0xFF,
	    &#40;port >> 8&#41; & 0xFF, port & 0xFF&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 200&#41; return&#40;0&#41;;

  sprintf&#40;ftp_request, "RETR %s\r\n", file&#41;;
  send&#40;tcp_sock, ftp_request, strlen&#40;ftp_request&#41;, 0&#41;;
  if&#40;ftp_get_reply&#40;tcp_sock&#41; != 150&#41; return&#40;0&#41;;

  return&#40;accept&#40;data_sock, NULL, NULL&#41;&#41;;
&#125;
#endif
#endif

#ifdef VCD_SUPPORT
int vcd_read&#40;int fd, int lba, unsigned char *buf&#41;
&#123;
    struct cdrom_msf *msf;

    msf = &#40;struct cdrom_msf*&#41; buf;
    msf->cdmsf_min0   = &#40;lba + CD_MSF_OFFSET&#41; / CD_FRAMES / CD_SECS; 
    msf->cdmsf_sec0   = &#40;lba + CD_MSF_OFFSET&#41; / CD_FRAMES % CD_SECS;
    msf->cdmsf_frame0 = &#40;lba + CD_MSF_OFFSET&#41; % CD_FRAMES;
    return&#40;ioctl&#40;fd, CDROMREADMODE2, buf&#41;&#41;;
&#125;

int vcd_open&#40;char * arg&#41;
&#123;
  struct stat buf;
  struct cdrom_tocentry toc;
  char *pip;
  int track;
  int pipe_fd&#91;2&#93;;
  int fd;
  int pid, parent;
  unsigned char * buffer;
  
  /* Track defaults to 02, unless requested otherwise */
  track = 02;
  pip = strrchr&#40;arg, '&#58;'&#41;;
  if &#40; pip &#41; &#123;
    *pip = '\0';
    track = atoi&#40;pip+1&#41; + 1;
  &#125;

  /* See if the CD-ROM device file exists */
  if &#40; &#40;stat&#40;arg, &buf&#41; < 0&#41; || !S_ISBLK&#40;buf.st_mode&#41; &#41; &#123;
    if &#40; pip &#41; &#123;
      *pip = '&#58;';
    &#125;
    return&#40;0&#41;;
  &#125;

  fd = open&#40;arg, O_RDONLY, 0&#41;;
  if &#40; fd < 0 &#41; &#123;
    if &#40; pip &#41; &#123;
      *pip = '&#58;';
    &#125;
    return&#40;0&#41;;
  &#125;

  /* Track 02 &#40;changed to 'track'&#41; contains MPEG data */
  if &#40; track < 2 &#41; &#123;
    printf&#40;"Warning&#58; VCD data normally starts on track 2\n"&#41;;
  &#125;
  toc.cdte_track  = track; 
  toc.cdte_format = CDROM_LBA;
  if&#40;ioctl&#40;fd, CDROMREADTOCENTRY, &toc&#41; < 0&#41; return&#40;0&#41;;

  if&#40;pipe&#40;pipe_fd&#41; < 0&#41; return&#40;0&#41;;

  parent = getpid&#40;&#41;;
  pid = fork&#40;&#41;;

  if&#40;pid < 0&#41; return&#40;0&#41;;

  if&#40;!pid&#41;
  &#123;
    /* Child process fills the pipe */
    int pos;
    struct timeval timeout;
    fd_set fdset;

    buffer = &#40;unsigned char *&#41; malloc&#40;CD_FRAMESIZE_RAW0&#41;;

    for&#40;pos = toc.cdte_addr.lba; vcd_read&#40;fd, pos, buffer&#41; >= 0; pos ++&#41;
    &#123;
      if&#40;kill&#40;parent, 0&#41; < 0&#41; break;

      FD_ZERO&#40;&fdset&#41;;
      FD_SET&#40;pipe_fd&#91;1&#93;, &fdset&#41;;
      timeout.tv_sec = 10;
      timeout.tv_usec = 0;
      if&#40;select&#40;pipe_fd&#91;1&#93;+1, NULL, &fdset, NULL, &timeout&#41; <= 0&#41; break;
      if&#40;write&#40;pipe_fd&#91;1&#93;, buffer, CD_FRAMESIZE_RAW0&#41; < 0&#41; break;
    &#125;

    free&#40;buffer&#41;;
    exit&#40;0&#41;;
  &#125;
  
  return&#40;pipe_fd&#91;0&#93;&#41;;
&#125;
#endif

void update&#40;SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h&#41;
&#123;
    if &#40; screen->flags & SDL_DOUBLEBUF &#41; &#123;
        SDL_Flip&#40;screen&#41;;
    &#125;
&#125;

/* Flag telling the UI that the movie or song should be skipped */
int done;

void next_movie&#40;int sig&#41;
&#123;
	done = 1;
&#125;

int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	printf&#40;"PlayMpeg Port for PSP by ArdaTan\n"&#41;;
	GeriBildirimleriAyarla&#40;&#41;;
    int use_audio, use_video;
    int fullscreen;
    int scalesize;
    int scale_width, scale_height;
    int loop_play;
    int i, pause;
    int volume;
    Uint32 seek;
    float skip;
    int bilinear_filtering;
    SDL_Surface *screen;
    SMPEG *mpeg;
    SMPEG_Info info;
    char *basefile;
    const char *title = NULL;
    SDL_version sdlver;
    SMPEG_version smpegver;
    int fd;
    char buf&#91;32&#93;;
    int status;

    /* Get the command line options */
    use_audio = 1;
    use_video = 1;
    fullscreen = 0;
    scalesize = 1;
    scale_width = 0;
    scale_height = 0;
    loop_play = 0;
    volume = 100;
    seek = 0;
    skip = 0;
    bilinear_filtering = 0;
    fd = 0;
	
    for &#40; i=1; argv&#91;i&#93; && &#40;argv&#91;i&#93;&#91;0&#93; == '-'&#41; && &#40;argv&#91;i&#93;&#91;1&#93; != 0&#41;; ++i &#41; &#123;
        if &#40; &#40;strcmp&#40;argv&#91;i&#93;, "--noaudio"&#41; == 0&#41; ||
             &#40;strcmp&#40;argv&#91;i&#93;, "--nosound"&#41; == 0&#41; &#41; &#123;
            use_audio = 0;
        &#125; else
        if &#40; strcmp&#40;argv&#91;i&#93;, "--novideo"&#41; == 0 &#41; &#123;
            use_video = 0;
        &#125; else
        if &#40; strcmp&#40;argv&#91;i&#93;, "--fullscreen"&#41; == 0 &#41; &#123;
            fullscreen = 1;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--double"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-2"&#41; == 0&#41;&#41; &#123;
            scalesize = 2;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--loop"&#41; == 0&#41; || &#40;strcmp&#40;argv&#91;i&#93;, "-l"&#41; == 0&#41;&#41; &#123;
            loop_play = 1;
        &#125; else
        if &#40; strcmp&#40;argv&#91;i&#93;, "--bilinear"&#41; == 0 &#41; &#123;
            bilinear_filtering = 1;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--seek"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-S"&#41; == 0&#41;&#41; &#123;
            ++i;
            if &#40; argv&#91;i&#93; &#41; &#123;
                seek = atol&#40;argv&#91;i&#93;&#41;;
            &#125;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--skip"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-k"&#41; == 0&#41;&#41; &#123;
            ++i;
            if &#40; argv&#91;i&#93; &#41; &#123;
                skip = &#40;float&#41;atof&#40;argv&#91;i&#93;&#41;;
            &#125;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--volume"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-v"&#41; == 0&#41;&#41; &#123;
            ++i;
	    if &#40;i >= argc&#41;
	      &#123;
		fprintf&#40;stderr, "Please specify volume when using --volume or -v\n"&#41;;
		return&#40;1&#41;;
	      &#125;
            if &#40; argv&#91;i&#93; &#41; &#123;
                volume = atoi&#40;argv&#91;i&#93;&#41;;
            &#125;
	    if &#40; &#40; volume < 0 &#41; || &#40; volume > 100 &#41; &#41; &#123;
	      fprintf&#40;stderr, "Volume must be between 0 and 100\n"&#41;;
	      volume = 100;
	    &#125;
	&#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--title"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-t"&#41; == 0&#41;&#41; &#123;
            ++i;
	    if &#40;i >= argc&#41;
	      &#123;
		fprintf&#40;stderr, "Please specify title when using --title or -t\n"&#41;;
		return&#40;1&#41;;
	      &#125;
            if &#40; argv&#91;i&#93; &#41; &#123;
                title = argv&#91;i&#93;;
            &#125;
	&#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--version"&#41; == 0&#41; ||
	    &#40;strcmp&#40;argv&#91;i&#93;, "-V"&#41; == 0&#41;&#41; &#123;
            sdlver = *SDL_Linked_Version&#40;&#41;;
            SMPEG_VERSION&#40;&smpegver&#41;;
	    printf&#40;"SDL version&#58; %d.%d.%d\n"
                   "SMPEG version&#58; %d.%d.%d\n",
		   sdlver.major, sdlver.minor, sdlver.patch,
		   smpegver.major, smpegver.minor, smpegver.patch&#41;;
            return&#40;0&#41;;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--scale"&#41; == 0&#41;||&#40;strcmp&#40;argv&#91;i&#93;, "-s"&#41; == 0&#41;&#41; &#123;
            ++i;
            if &#40; argv&#91;i&#93; &#41; &#123;
                sscanf&#40;argv&#91;i&#93;, "%dx%d", &scale_width, &scale_height&#41;;
            &#125;
        &#125; else
        if &#40;&#40;strcmp&#40;argv&#91;i&#93;, "--help"&#41; == 0&#41; || &#40;strcmp&#40;argv&#91;i&#93;, "-h"&#41; == 0&#41;&#41; &#123;
            usage&#40;argv&#91;0&#93;&#41;;
            return&#40;0&#41;;
        &#125; else &#123;
            fprintf&#40;stderr, "Warning&#58; Unknown option&#58; %s\n", argv&#91;i&#93;&#41;;
        &#125;
    &#125;
    /* If there were no arguments just print the usage */
    if &#40;argc == 1&#41; &#123;
        usage&#40;argv&#91;0&#93;&#41;;
        return&#40;0&#41;;
    &#125;

#if defined&#40;linux&#41; || defined&#40;__FreeBSD__&#41; /* Plaympeg doesn't need a mouse */
    putenv&#40;"SDL_NOMOUSE=1"&#41;;
#endif

    /* Play the mpeg files! */
    status = 0;
    for &#40; ; argv&#91;i&#93;; ++i &#41; &#123;
	/* Initialize SDL */
	if &#40; use_video &#41; &#123;
	  if &#40;&#40;SDL_Init&#40;SDL_INIT_VIDEO&#41; < 0&#41; || !SDL_VideoDriverName&#40;buf, 1&#41;&#41; &#123;
	    fprintf&#40;stderr, "Warning&#58; Couldn't init SDL video&#58; %s\n",
		    SDL_GetError&#40;&#41;&#41;;
	    fprintf&#40;stderr, "Will ignore video stream\n"&#41;;
	    use_video = 0;
	  &#125;
	&#125;
	
	if &#40; use_audio &#41; &#123;
	  if &#40;&#40;SDL_Init&#40;SDL_INIT_AUDIO&#41; < 0&#41; || !SDL_AudioDriverName&#40;buf, 1&#41;&#41; &#123;
	    fprintf&#40;stderr, "Warning&#58; Couldn't init SDL audio&#58; %s\n",
		    SDL_GetError&#40;&#41;&#41;;
	    fprintf&#40;stderr, "Will ignore audio stream\n"&#41;;
	    use_audio = 0;
	  &#125;
	&#125;

	/* Allow Ctrl-C when there's no video output */
	signal&#40;SIGINT, next_movie&#41;;
	
        /* Create the MPEG stream */
#ifdef NET_SUPPORT
#ifdef RAW_SUPPORT
        /* Check if source is an IP address and port*/
        if&#40;&#40;fd = raw_open&#40;argv&#91;i&#93;&#41;&#41; != 0&#41;
	  mpeg = SMPEG_new_descr&#40;fd, &info, use_audio&#41;;
	else
#endif
#ifdef HTTP_SUPPORT
        /* Check if source is an http URL */
        if&#40;&#40;fd = http_open&#40;argv&#91;i&#93;&#41;&#41; != 0&#41;
	  mpeg = SMPEG_new_descr&#40;fd, &info, use_audio&#41;;
	else
#endif
#ifdef FTP_SUPPORT
        /* Check if source is an http URL */
        if&#40;&#40;fd = ftp_open&#40;argv&#91;i&#93;&#41;&#41; != 0&#41;
	  mpeg = SMPEG_new_descr&#40;fd, &info, use_audio&#41;;
	else
#endif
#endif
#ifdef VCD_SUPPORT
	/* Check if source is a CDROM device */
	if&#40;&#40;fd = vcd_open&#40;argv&#91;i&#93;&#41;&#41; != 0&#41;
	  mpeg = SMPEG_new_descr&#40;fd, &info, use_audio&#41;;
	else
#endif
	&#123;
	  if&#40;strcmp&#40;argv&#91;i&#93;, "-"&#41; == 0&#41; /* Use stdin for input */
	    mpeg = SMPEG_new_descr&#40;0, &info, use_audio&#41;;
	  else
	    mpeg = SMPEG_new&#40;argv&#91;i&#93;, &info, use_audio&#41;;
	&#125;

        if &#40; SMPEG_error&#40;mpeg&#41; &#41; &#123;
            fprintf&#40;stderr, "%s&#58; %s\n", argv&#91;i&#93;, SMPEG_error&#40;mpeg&#41;&#41;;
            SMPEG_delete&#40;mpeg&#41;;
            status = -1;
            continue;
        &#125;
        SMPEG_enableaudio&#40;mpeg, use_audio&#41;;
        SMPEG_enablevideo&#40;mpeg, use_video&#41;;
        SMPEG_setvolume&#40;mpeg, volume&#41;;

        /* Enable software bilinear filtering, if desired */
        if &#40; bilinear_filtering &#41; &#123;
            SMPEG_Filter *filter;

            filter = SMPEGfilter_bilinear&#40;&#41;;
            filter = SMPEG_filter&#40; mpeg, filter &#41;;
            filter->destroy&#40;filter&#41;;
        &#125;

        /* Print information about the video */
        basefile = strrchr&#40;argv&#91;i&#93;, '/'&#41;;
        if &#40; basefile &#41; &#123;
            ++basefile;
        &#125; else &#123;
            basefile = argv&#91;i&#93;;
        &#125;
        if &#40; info.has_audio && info.has_video &#41; &#123;
            printf&#40;"%s&#58; MPEG system stream &#40;audio/video&#41;\n", basefile&#41;;
        &#125; else if &#40; info.has_audio &#41; &#123;
            printf&#40;"%s&#58; MPEG audio stream\n", basefile&#41;;
        &#125; else if &#40; info.has_video &#41; &#123;
            printf&#40;"%s&#58; MPEG video stream\n", basefile&#41;;
        &#125;
        if &#40; info.has_video &#41; &#123;
            printf&#40;"\tVideo %dx%d resolution\n", info.width, info.height&#41;;
        &#125;
        if &#40; info.has_audio &#41; &#123;
	    printf&#40;"\tAudio %s\n", info.audio_string&#41;;
        &#125;
        if &#40; info.total_size &#41; &#123;
	    printf&#40;"\tSize&#58; %d\n", info.total_size&#41;;
        &#125;
        if &#40; info.total_time &#41; &#123;
	    printf&#40;"\tTotal time&#58; %f\n", info.total_time&#41;;
        &#125;

        /* Set up video display if needed */
        if &#40; info.has_video && use_video &#41; &#123;
            const SDL_VideoInfo *video_info;
            Uint32 video_flags;
            int video_bpp;
            int width, height;

            /* Get the "native" video mode */
            video_info = SDL_GetVideoInfo&#40;&#41;;
            switch &#40;video_info->vfmt->BitsPerPixel&#41; &#123;
                case 16&#58;
                case 24&#58;
                case 32&#58;
                    video_bpp = video_info->vfmt->BitsPerPixel;
                    break;
                default&#58;
                    video_bpp = 16;
                    break;
            &#125;
            if &#40; scale_width &#41; &#123;
                width = scale_width;
            &#125; else &#123;
                width = info.width;
            &#125;
            width *= scalesize;
            if &#40; scale_height &#41; &#123;
                height = scale_height;
            &#125; else &#123;
                height = info.height;
            &#125;
            height *= scalesize;
            video_flags = SDL_SWSURFACE;
            if &#40; fullscreen &#41; &#123;
                video_flags = SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_HWSURFACE;
            &#125;
            video_flags |= SDL_ASYNCBLIT;
            video_flags |= SDL_RESIZABLE;
            screen = SDL_SetVideoMode&#40;420, 272, video_bpp, video_flags&#41;;
            if &#40; screen == NULL &#41; &#123;
                fprintf&#40;stderr, "Unable to set %dx%d video mode&#58; %s\n",
                                	width, height, SDL_GetError&#40;&#41;&#41;;
                continue;
            &#125;
            if &#40;title != NULL&#41; &#123;
                SDL_WM_SetCaption&#40;title, title&#41;;
            &#125; else &#123;
                SDL_WM_SetCaption&#40;argv&#91;i&#93;, "plaympeg"&#41;;
            &#125;
            if &#40; screen->flags & SDL_FULLSCREEN &#41; &#123;
                SDL_ShowCursor&#40;0&#41;;
            &#125;
            SMPEG_setdisplay&#40;mpeg, screen, NULL, update&#41;;
            SMPEG_scaleXY&#40;mpeg, screen->w, screen->h&#41;;
        &#125; else &#123;
            SDL_QuitSubSystem&#40;SDL_INIT_VIDEO&#41;;
        &#125;

        /* Set any special playback parameters */
        if &#40; loop_play &#41; &#123;
            SMPEG_loop&#40;mpeg, 1&#41;;
        &#125;

	/* Seek starting position */
	if&#40;seek&#41; SMPEG_seek&#40;mpeg, seek&#41;;

	/* Skip seconds to starting position */
	if&#40;skip&#41; SMPEG_skip&#40;mpeg, skip&#41;;
	
        /* Play it, and wait for playback to complete */
        SMPEG_play&#40;mpeg&#41;;
        done = 0;
	pause = 0;
        while &#40; ! done && &#40; pause || &#40;SMPEG_status&#40;mpeg&#41; == SMPEG_PLAYING&#41; &#41; &#41; &#123;
            SDL_Event event;

            while &#40; use_video && SDL_PollEvent&#40;&event&#41; &#41; &#123;
                switch &#40;event.type&#41; &#123;
                    case SDL_VIDEORESIZE&#58; &#123;
                        SDL_Surface *old_screen = screen;
                        SMPEG_pause&#40;mpeg&#41;;
                        screen = SDL_SetVideoMode&#40;event.resize.w, event.resize.h, screen->format->BitsPerPixel, screen->flags&#41;;
			if &#40; old_screen != screen &#41; &#123;
                            SMPEG_setdisplay&#40;mpeg, screen, NULL, update&#41;;
                        &#125;
                        SMPEG_scaleXY&#40;mpeg, screen->w, screen->h&#41;;
                        SMPEG_pause&#40;mpeg&#41;;
                    &#125; break;
                    case SDL_KEYDOWN&#58;
                        if &#40; &#40;event.key.keysym.sym == SDLK_ESCAPE&#41; || &#40;event.key.keysym.sym == SDLK_q&#41; &#41; &#123;
			  // Quit
			  done = 1;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_RETURN &#41; &#123;
			  // toggle fullscreen
			  if &#40; event.key.keysym.mod & KMOD_ALT &#41; &#123;
                            SDL_WM_ToggleFullScreen&#40;screen&#41;;
                            fullscreen = &#40;screen->flags & SDL_FULLSCREEN&#41;;
                            SDL_ShowCursor&#40;!fullscreen&#41;; 
                          &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_UP &#41; &#123;
			  // Volume up
			  if &#40; volume < 100 &#41; &#123;
			    if &#40; event.key.keysym.mod & KMOD_SHIFT &#41; &#123;   // 10+
			      volume += 10;
			    &#125; else if &#40; event.key.keysym.mod & KMOD_CTRL &#41; &#123; // 100+
			      volume = 100;
			    &#125; else &#123;                                     // 1+
			      volume++;
			    &#125;
			    if &#40; volume > 100 &#41; 
			      volume = 100;
			    SMPEG_setvolume&#40;mpeg, volume&#41;;
			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_DOWN &#41; &#123;
			  // Volume down
			  if &#40; volume > 0 &#41; &#123;
			    if &#40; event.key.keysym.mod & KMOD_SHIFT &#41; &#123;
			      volume -= 10;
			    &#125; else if &#40; event.key.keysym.mod & KMOD_CTRL &#41; &#123;
			      volume = 0;
			    &#125; else &#123;
			      volume--;
			    &#125;
			    if &#40; volume < 0 &#41; 
			      volume = 0;
			    SMPEG_setvolume&#40;mpeg, volume&#41;;
			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_PAGEUP &#41; &#123;
			  // Full volume
			  volume = 100;
			  SMPEG_setvolume&#40;mpeg, volume&#41;;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_PAGEDOWN &#41; &#123;
			  // Volume off
			  volume = 0;
			  SMPEG_setvolume&#40;mpeg, volume&#41;;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_SPACE &#41; &#123;
			  // Toggle play / pause
			  if &#40; SMPEG_status&#40;mpeg&#41; == SMPEG_PLAYING &#41; &#123;
			    SMPEG_pause&#40;mpeg&#41;;
			    pause = 1;
			  &#125; else &#123;
			    SMPEG_play&#40;mpeg&#41;;
			    pause = 0;
			  &#125;
			&#125; else if &#40; event.key.keysym.sym == SDLK_RIGHT &#41; &#123;
			  // Forward
			  if &#40; event.key.keysym.mod & KMOD_SHIFT &#41; &#123;
			    SMPEG_skip&#40;mpeg, 100&#41;;
			  &#125; else if &#40; event.key.keysym.mod & KMOD_CTRL &#41; &#123;
			    SMPEG_skip&#40;mpeg, 50&#41;;
			  &#125; else &#123;
			    SMPEG_skip&#40;mpeg, 5&#41;;
			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_LEFT &#41; &#123;
			  // Reverse
			  if &#40; event.key.keysym.mod & KMOD_SHIFT &#41; &#123;

			  &#125; else if &#40; event.key.keysym.mod & KMOD_CTRL &#41; &#123;

			  &#125; else &#123;

			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_KP_MINUS &#41; &#123;
			  // Scale minus
			  if &#40; scalesize > 1 &#41; &#123;
			    scalesize--;
			  &#125;
                        &#125; else if &#40; event.key.keysym.sym == SDLK_KP_PLUS &#41; &#123;
			  // Scale plus
			  scalesize++;
			&#125; else if &#40; event.key.keysym.sym == SDLK_f &#41; &#123;
			  // Toggle filtering on/off
			  if &#40; bilinear_filtering &#41; &#123;
			    SMPEG_Filter *filter = SMPEGfilter_null&#40;&#41;;
			    filter = SMPEG_filter&#40; mpeg, filter &#41;;
			    filter->destroy&#40;filter&#41;;
			    bilinear_filtering = 0;
			  &#125; else &#123;
			    SMPEG_Filter *filter = SMPEGfilter_bilinear&#40;&#41;;
			    filter = SMPEG_filter&#40; mpeg, filter &#41;;
			    filter->destroy&#40;filter&#41;;
			    bilinear_filtering = 1;
			  &#125;
			&#125;
                        break;
                    case SDL_QUIT&#58;
                        done = 1;
                        break;
                    default&#58;
                        break;
                &#125;
            &#125;
            SDL_Delay&#40;1000/2&#41;;
        &#125;
        SMPEG_delete&#40;mpeg&#41;;
    &#125;
    SDL_Quit&#40;&#41;;
sceKernelSleepThread&#40;&#41;;
#if defined&#40;RAW_SUPPORT&#41; || defined&#40;HTTP_SUPPORT&#41; || defined&#40;FTP_SUPPORT&#41; || \
    defined&#40;VCD_SUPPORT&#41;
    if&#40;fd&#41; close&#40;fd&#41;;
#endif

    //return&#40;status&#41;;
	return 0;
&#125;
Makefile

Code: Select all

TARGET = plaympeg
OBJS = plaympeg.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS = 
LIBS = -lsmpeg -lSDL -lpsphprm -lpspgu -lpspgum -lpspaudio -lstdc++ -lm

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = playMpeg

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
[/b]
I'm sorry for my bad English.
User avatar
Wally
Posts: 663
Joined: Mon Sep 26, 2005 11:25 am

Post by Wally »

I suggest profiling it via PSPLinkUSB

Please refer to setting up apps for Custom Firmware Kernels (3.xx - 5.xx) before installing PSPLink as PSPLink will not accept ELF files.


Wally
ardatan
Posts: 44
Joined: Sat Jan 12, 2008 8:47 am

Post by ardatan »

With PSPLink, i ran the app for mp3 playing.
it gives this error in psplink shell(pspsh.exe):

Code: Select all

host0&#58;/> assertion "audio->rawdatawriteoffset > len" failed&#58; file "audio/mpegtor
aw.cpp", line 501
Exception - Breakpoint
Thread ID - 0x03B27511
Th Name   - user_main
EPC       - 0x0890078C
Cause     - 0x10000024
BadVAddr  - 0xA8029C01
Status    - 0x20088613
zr&#58;0x00000000 at&#58;0x0008FF00 v0&#58;0x00000000 v1&#58;0x00000000
a0&#58;0x00000001 a1&#58;0x00000000 a2&#58;0x881D94D8 a3&#58;0x00000000
t0&#58;0x00000000 t1&#58;0x0000178C t2&#58;0x20088600 t3&#58;0x882FF200
t4&#58;0x09FBFD00 t5&#58;0x00801E04 t6&#58;0x0890078C t7&#58;0x00088600
s0&#58;0x5A1CAC08 s1&#58;0x08980000 s2&#58;0x00000001 s3&#58;0x0899D150
s4&#58;0x00000001 s5&#58;0x00000064 s6&#58;0x09FBFD08 s7&#58;0x0000001B
t8&#58;0x00000000 t9&#58;0x880107E0 k0&#58;0x09FBFF00 k1&#58;0x00000000
gp&#58;0x08985B80 sp&#58;0x09FBFD00 fp&#58;0x00000071 ra&#58;0x0890078C
0x0890078C&#58; 0x0000004D 'M...' - break      0x1
I'm sorry for my bad English.
Post Reply