PS2 network media player?

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

PS2 network media player?

Post by mountainstorm »

Ive got a PS2, the Sony DVD remote and the network adapter.... and I want to use it to watch video. Now Ive tried the PS2Reality player and whilst its ok, im not overly impressed.

What i want is the equivolent of the Happauge MVP using my PS2 as little more than a network -> TV player and a remote control -> network device. The idea is to make the PC do ALL the work and generate the menus' etc in the format the PS2 can understand (translate). Now converting all my movies into a good format is easily achieved on the PC with Video Lan Client, so i need a video codec for my PS2.

I believe PS2Reality use ffmpeg, but im having limited success trying to compile that with the toolchain. Has anybody managed to get even a limited subset of ffmepg compiled and working on the PS2? Im only looking for a codec which the PS2 will not have problems with - so mabe MPEG2 might be the best choice.... anybody?

Rich
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

PS2Reality claim that they submitted patches to ffmpeg's crew, and that it's available somewhere deeply in ffmpeg's webpage. I haven't suceeded yet finding it. If you can find it, please let me know.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

All PS2Reality did was to change the MMX routines in FFMPEG into MMI routines for the EE. If you get a current snapshot of FFMPEG, you'll find the MMI code for things like IDCT. That's the ONLY change they made for video.

As far as I can tell, PS2Reality is just cobbled together from FFMPEG, libmad, libvorbis, and some PS2 routines. I'm still looking into a conversion of xine for the PS2, but I've been rather busy on other things.
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

Post by mountainstorm »

Well I searched the ffmpeg dev mailing list and apparently they are only using libavcodec rather than libavformat. Ive tried compiling libavcodec with the ee toolchain, after configuring it as a mips machine.... this causes the compile to use the mmi routines in the ps2/ directory.

The only thing which doesn't compile is mpegaudiodec.c IIRC, this causes the compiler to crash! So Ive removed that and it claims it has compiled. Im currently trying to knock up a simple program to prove to myself its working.... its got about a meg of .mpg file embedded in the source file!

Does anybody know which codec requires the least processor power to decode?

Rich
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

Post by mountainstorm »

So Ive got a libavcodec.a file (a good start me thinks). Ive written my small app and tested in on my Mac. Im trying to compile it with the PS2 toolchain but am missing the following symbols.....

sscanf
perror
_ctype_
atof
atoi
strtod

and quite a few other ones that I suspect are related to ffmpeg, are these avaliable and if so where?

Rich
Guest

Post by Guest »

J.F. wrote:All PS2Reality did was to change the MMX routines in FFMPEG into MMI routines for the EE. If you get a current snapshot of FFMPEG, you'll find the MMI code for things like IDCT. That's the ONLY change they made for video.
I can understand using MMI and the EE core to do mpeg2 motion compensation functions, since the IPU does *not* perform that bit, but I
thought that the IPU *does* do IDCT. So PS2Reality is not taking true
advantage of the entire EE (R5900/MMI + IPU) to do mpeg2 video ?
Guest

Post by Guest »

mountainstorm wrote:So Ive got a libavcodec.a file (a good start me thinks). Ive written my small app and tested in on my Mac. Im trying to compile it with the PS2 toolchain but am missing the following symbols.....

sscanf
perror
_ctype_
atof
atoi
strtod

and quite a few other ones that I suspect are related to ffmpeg, are these avaliable and if so where?

Rich
I think you would only find them in the ps2 port of newlib, since ps2sdk
does not offer a full complement of C library routines et al.

Gorim
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Since PS2Reality only plays videos in AVI format, I don't think they bothered with any kind of optimizations for MPEG2.

The IPU can also do colorspace conversion. I'd definitely work that into a video player on the PS2.

If you're looking for something simple to test, you might try a cinepak video. That's what Apple used to use for QT movies years back. It was also popular in games.
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

Code: Select all

ee-gcc -O3 -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -c -o mpegaudiodec.o mpegaudiodec.c
mpegaudiodec.c: In function `dct32':
mpegaudiodec.c:1653: insn does not satisfy its constraints:
(insn 2939 448 2941 (set (reg:DI 2 v0)
        (ashiftrt:DI (reg:DI 66 accum)
            (const_int 32 [0x20]))) 216 {ashrdi3_internal4} (nil)
    (nil))
mpegaudiodec.c:1653: Internal compiler error in reload_cse_simplify_operands, at reload1.c:8338
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL&#58;http&#58;//www.gnu.org/software/gcc/bugs.html> for instructions.
make&#58; *** &#91;mpegaudiodec.o&#93; Error 1
"ouch!" :P (note that removing -O3 helps...)
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Never use -O3 unless you know what you're doing. It turns on automatic function inlining which may be fine for certain files in your project, but is pretty harmful (and broken) overall.
"He was warned..."
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

Post by mountainstorm »

whooo, cheers - well Ive removed the -O3 from config.mak and set CONFIG_ENCODERS to 0 in config.h. Then compiled it up.... and bingo it all worked.

Now with my test program compiled as well (after playing with the library order) unfortunatly the same code works on my PC with an mpeg1 sample (embedded) - on the PS2 causes a segfault. Is there a way to get the segfault on the PC instead of the TV?

So not loosing heart I created a small MPEG4 sample (we know PS2Reality does that) embedded that, setup the width and height (MPEG4 streams dont have that encoded) and tried again. This time it didnt crash, whilst it didnt log the same text as I got on my PC.. it did appear to do 'something'

Next I need to try to get some code to display the output buffer? Anybody fancy trying that?

If you want to give it a go,
* get ffmpeg
* ./configure --cpu=mips --cross-prefix=ee- --disable-ffserver --disable--ffplay
* Mod the config.h and config.mak (see above)
* cd into libavcodec and 'make'
* copy the libavcodec.a and all the header files into your PS2 toolchain
* get my test file (its shambled together from apiexamples.c) from http://www.mountainstorm.co.uk/ps2dev.m ... .uk/main.c
* get the make file http://www.mountainstorm.co.uk/ps2dev.m ... k/Makefile
* make the example, and dump it on your PS2

Feel free to try modifying the example video, or anything and report back if you have any success.

Rich
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

I actually have a "harder" modification. Which should be a little bit faster though, and cleaner. Here are my config.h/mak:

config.h:

Code: Select all

#define ARCH_MIPS 1
#define TUNECPU generic
#define EMULATE_INTTYPES 1
#define EMULATE_FAST_INT 1
#define CONFIG_DECODERS 1
#define CONFIG_MPEGAUDIO_HP 1
#define CONFIG_DV1394 1
#undef  HAVE_MALLOC_H
#undef  HAVE_MEMALIGN
#define SIMPLE_IDCT 1
#define CONFIG_RISKY 1
#define restrict
#define HAVE_MMI 1
config.mak:

Code: Select all

prefix=/usr/local
bindir=/usr/local/bin
mandir=/usr/local/man
MAKE=make
CC=ee-gcc
AR=ee-ar
RANLIB=ee-ranlib
STRIP=ee-strip
LDFLAGS=-Wl,--warn-common -rdynamic
FFSLDFLAGS=-Wl,-E
SHFLAGS=-shared
LIBPREF=lib
LIBSUF=.a
EXESUF=
TARGET_OS=Linux
TARGET_ARCH_MIPS=yes
EXTRALIBS=-lm
VERSION=0.4.9-pre1
CONFIG_DECODERS=yes
CONFIG_DV1394=yes
CONFIG_RISKY=yes
SRC_PATH=/home/pixel/sources/ffmpeg
TARGET_MMI=yes
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

All what I can get (for now) is:

Code: Select all

Video decoding
Codec found
context alloc'd
fame alloced
opend codec - starting loop
..saving frame   0
.saving frame   1
.&#91;mpeg4 @ 3429712&#93;vop not coded
.saving frame   2
.saving frame   3
.&#91;mpeg4 @ 3429712&#93;header damaged
Error while decoding frame 4
(it took me a while to get fully rid of the newlib, and maybe I broke things...)

--edit--

Okaaaaay, got some result here. Now, I am not an ffmpeg wizard at all, and I do not know how to interpret the results (that is, what is the format of the frames ? what shall I do to dump/display them ? etc..)

Anyway, I am way too tired to post anything now, so, I'll go to bed, and we'll see later about that. If in the meanwhile some people have some clues to give me about the format outputted by avcodec_decode_video and what to do with it, that would spare me some time later on.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

Post by mountainstorm »

I think the frame buffer should be in RGB format (but it may be YUV) - the codes stolen from the apiexample.c in libavcodec. In that it writes the buffer into a ppm file. I'll try running that and see what format the buffer is in.

I got a different result when I ran the code, I got 6 framers processed but didnt get any of the [mpg4 @ 578...... lines?

How hard will it be to load the data from the host machine (over pukklink). That would make life easier, I'll use virtual dub tonight and create a 'raw' MPEG4 video file (the embedded data will have an audio stream in as well).

Ill keep you informed.

Rich
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

Post by mountainstorm »

The buffers in RGB, 8bpp
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

mountainstorm wrote: How hard will it be to load the data from the host machine (over pukklink). That would make life easier, I'll use virtual dub tonight and create a 'raw' MPEG4 video file (the embedded data will have an audio stream in as well).
Assuming you haven't reset the IOP...

Code: Select all

inFile = fioOpen&#40;"host&#58;test.mpg", O_RDONLY&#41;; 

...

fioRead&#40;inFile, *buffer, size&#41;;

...

fioClose&#40;inFile&#41;;
Shoot Pixels Not People!
Makeshift Development
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

Weell.... the code goes up to frame 33, then hungs with a damaged header error.

Code: Select all

running decode&#58; size = 653
here&#58; *****frame 33 size=653
bytes=7f 0 0 1
qscale=2
Decoded chunk, len = 106, size goes from 653 to 547
saving frame  32, 512x384, pixel format = 0
open name host&#58;frm-032.pgm flag 202 data 41378
open fd = 2
size = 547
running decode&#58; size = 547
here&#58; *****frame 34 size=547
bytes=ff fb 90 44
&#91;mpeg4 @ 3433040&#93;header damaged
Error while decoding frame 33
Side note: I can't believe mpeg4's output is 8bits rgba... it more likely would be yuv or something similar. It seems the actual "Pixel Format" thingy inside the whole ffmpeg is a bit broken, so, except if it is PIX_FMT_YUV420P, ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples), I can't guess for sure which pixel format this codec gives.

By the way, if I take your code, and try to run it under plain linux, it simply doesn't work :P

Ah, and about debug messages and stuff: I hacked a lot inside ffmpeg, in order to add some more debug messages where I needed them, and to free it from newlib.

--edit--

It seems it IS really PIX_FMT_YUV420P there... okay, let's work it out.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

Duh... of course it can't work! :)

You first need tu demux the input file. That example would work on plain mpg files...
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

Post by mountainstorm »

Ive updated main.c http://www.mountainstorm.co.uk/ps2dev.m ... .uk/main.c and now have a raw mp4 encoded test video stream http://www.mountainstorm.co.uk/ps2dev.m ... k/test.mpg

Ive compiled this on Win2K and it produces 196 pgm files, I was wrong earlier as I was looking at the ppm spec (which is 3x8bpp) ... the pgm's generated are the video's frames and are greyscale 8bpp images.

So im resonably shure the code is now correct'ish :)

So I compile with the toolchain and dump it onto the PS2 using PS2exec. All I get is...

Code: Select all

PS2EXEC.EXE v1.1 &#40;2003 New Creation Interactive.&#41;&#91;Lion&#93;

'' - PC&#58;192.168.0.2 -> PS2&#58;192.168.0.32

PS2Libk / Pukklink...
Execute...
Waiting for PS2 connection before executing
connected ok


****** Console Mode ******

hehe 0
unmounted


hehe 0

hehe 0

hehe 0

The 'hehe 0's continue forever (Ive left it whilst I had my tea), any ideas whats going on? Nothings displayed on the TV or my console (other than the hehe's)

Rich
ole
Posts: 92
Joined: Sat May 08, 2004 11:14 pm
Location: Czech Republic

Post by ole »

I'm afraid that hehe means that connection with ps2link has been lost. I use ps2exec and it happened to me too.
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

This was outputted by the PS2, using more or less our source code: (among other pictures)

http://www.nobis-crew.org/~pixel/frm-049.png

Okay, I don't wanna dig inside libavformat... but now, a demuxer is needed to demux files like avis...

*sigh*

I'll already hit the libavformat so it won't use newlib anymore, and well'see...
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

Post by mountainstorm »

Groovy, any ideas on why I'm loosing my connection to the PS2?

I was planning on just porting the rtp part of libavformat, that way I can run VLC on my PC and get that to do all the hard work.

Cheers for your help, I wouldnt mind seeing your source-code, I might work on getting color next :)

Rich

P.S is there a reason you dont like newlib? What are the alternatives?
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

My source code is essentially removing stuff. I'll of course release it when we'll have something interesting. Until now, it's only some mere hacks put together. I think I am really gonna work on a "mediaplayer" for the PS2 now...

Newlib is bloated. I'll try to make sure to get rid of it sometime in the future. Until now, you have to swap functions like open -> fioOpen, etc, and forget about f* functions, like fopen, fprintf, fgetc, unputc, ... also forget about stderr.

The "alternative" is the built-in 'libc' which is inside ps2sdk. But it lacks lots of "compatibility" functions, which, in the general case, are more or less aliases with a few more checks. Maybe I'll add that later on. I am a bit fed up to "port" pieces of code to ps2sdk, where it could natively work :p
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Unless the codec does colorspace conversion itself, mpeg4 codecs deal only with YUV420 format data. The xvid vfw codec has a variety of colorspace conversion routines that convert the yuv data into whatever mode the ouput bitmap is in when decoding, or vice-versa when encoding. If I remember correctly, the xvidcore only deals with yuv data.
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

Post by mountainstorm »

Your right, the frame we get is in PIX_FMT_YUV420P, and needs conversion.. using some code from http://www.inb.uni-luebeck.de/~boehme/l ... pdate.html Ive nearly got it working, I'll keep you all updated when I do.... I think the codes getting a little messy :)

Ive also move to ps2client and now it actually works, Im even getting it to output its results, but with newlib i.e. fwrite I get zero length files and with fioWrite i get 2Mb files of junk?

Rich
mountainstorm
Posts: 21
Joined: Wed Apr 07, 2004 2:59 am

Post by mountainstorm »

Ive updated the main.c (see an earlier post for the link) it now reads the input stream from the file specified at argv[1], and outputs the frames to the file specified at argv[2] (with a number and .ppm appended).

It reads the stream, decodes it as MPEG4 converts the YUV frame to RGB and then writes it out as a ppm (color pixmap).

Ive tested it under MSVC and it works, it compiles fine under the PS2 toolchain and when run im having the same 'zero length output file' problem i had before. It has alos thrown an error when decoding one of the frames. The decode error might be a problem with my code (its actually a mod'd version of the link i posted in my last post). But does anybody have any ideas about my zero length file issue.

Mabe I need a new version of PS2Link?

Rich
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

I think you shouldn't use the newlib at all. Well, let me hack your code now, I'll make it working, don't worry :p

--edit--

Okay, well, this code still doesn't make any use of the libavformat. So, yeah, this code works great with mpeg files (I decoded your test.mpg yet again), but it won't demux any .avi file.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

So... finally, ps2sdk now come with a small "stdio" support, which should help you get rid of newlib. It doesn't have any sscanf/strtod/atof though. But these are used only in some configuration thingies, so, you can kill the code off. On a side note, if somebody have some simple implementation of sscanf/strtod/atof, that would be some great addictions to the actual ps2sdk's libc.

Now, just changing ffmpeg's makefiles should be enough (that is, put some CFLAGS so they have -I$(PS2SDK)/ee/include and -I$(PS2SDK)/common/include )

So, now, you shouldn't need "newlib's libc" anymore, and should give more stable results. I'll let you do your tests, I have other things to take care of right now, but I'll come back help you a little bit afterward.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
Post Reply