 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
cooleyes
Joined: 18 May 2006 Posts: 125
|
|
| Back to top |
|
 |
cooleyes
Joined: 18 May 2006 Posts: 125
|
Posted: Sat Aug 25, 2007 11:54 am Post subject: |
|
|
| Code: |
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <psppower.h>
#include <stdio.h>
#include <stdlib.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <psppower.h>
#include <pspdebug.h>
#include <psprtc.h>
#include <pspsdk.h>
#include <pspaudiocodec.h>
#include <pspaudio.h>
#include <string.h>
#include <malloc.h>
#include <pspmpeg.h>
#include "pspvideocodec.h"
int SetupCallbacks();
PSP_MODULE_INFO("videocodec test", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
__attribute__ ((constructor))
void loaderInit(){
pspKernelSetKernelPC();
pspSdkInstallNoDeviceCheckPatch();
pspSdkInstallNoPlainModuleCheckPatch();
pspSdkInstallKernelLoadModulePatch();
}
SceCtrlData input;
unsigned long Video_Codec_BufferMP4V[96] __attribute__((aligned(64)));
unsigned long Video_Codec_BufferAVC1[96] __attribute__((aligned(64)));
unsigned long Video_YCrCbCopy_SrcBufferMP4V[24] __attribute__((aligned(64)));
unsigned long Video_YCrCbCopy_DestBufferMP4V[24] __attribute__((aligned(64)));
unsigned char YBuffer[512*512] __attribute__((aligned(64)));
unsigned char CrBuffer[512*128] __attribute__((aligned(64)));
unsigned char CbBuffer[512*128] __attribute__((aligned(64)));
int main(void)
{
SetupCallbacks();
pspDebugScreenInit();
pspDebugScreenSetXY(0, 2);
//scePowerSetClockFrequency(120,120,60);
//scePowerSetCpuClockFrequency(120);
//scePowerSetBusClockFrequency(60);
u32 cpu = scePowerGetCpuClockFrequency();
u32 bus = scePowerGetBusClockFrequency();
pspDebugScreenPrintf("cpu=%d, bus=%d\n", cpu, bus);
pspDebugScreenPrintf("Press any key to exit.\n");
int result;
result = pspSdkLoadStartModule("flash0:/kd/me_for_vsh.prx", PSP_MEMORY_PARTITION_KERNEL);
if (result < 0 ) goto wait;
result = pspSdkLoadStartModule("flash0:/kd/videocodec.prx", PSP_MEMORY_PARTITION_KERNEL);
if (result < 0 ) goto wait;
result = pspSdkLoadStartModule("flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL);
if (result < 0 ) goto wait;
result = pspSdkLoadStartModule("flash0:/kd/mpegbase.prx", PSP_MEMORY_PARTITION_KERNEL);
if (result < 0 ) goto wait;
result = pspSdkLoadStartModule("flash0:/kd/mpeg_vsh.prx", PSP_MEMORY_PARTITION_USER);
if (result < 0 ) goto wait;
pspSdkFixupImports(result);
sceMpegInit();
FILE* fp = fopen("ms0:/Test1.dat", "rb");
fseek(fp, 0, PSP_SEEK_END);
long fsize = ftell(fp);
long buffer_size = fsize;
int mod_64 = buffer_size & 0x3f;
if (mod_64 != 0) buffer_size += 64 - mod_64;
unsigned char* file_buffer = memalign(64, buffer_size);
fseek(fp, 0, PSP_SEEK_SET);
fread(file_buffer, fsize, 1, fp);
fclose(fp);
memset(Video_Codec_BufferMP4V, 0, sizeof(Video_Codec_BufferMP4V));
int res ;
int i;
//---------------------------------------------------------------------------------//
Video_Codec_BufferMP4V[4] = (unsigned long)(((void*)Video_Codec_BufferMP4V) + 128 );
Video_Codec_BufferMP4V[11] = 512;
Video_Codec_BufferMP4V[12] = 512;
Video_Codec_BufferMP4V[13] = 512*512;
fp = fopen("ms0:/sceVideocodecOpen(mp4v).dat", "wb");
for(i=0;i<96;i++) {
fwrite( &Video_Codec_BufferMP4V[i], sizeof(unsigned int), 1, fp);
}
fclose(fp);
if ( (res = sceVideocodecOpen(Video_Codec_BufferMP4V, 0x1)) < 0 ) {
pspDebugScreenPrintf("sceVideocodecOpen=0x%08X\n", res);
goto wait;
}
pspDebugScreenPrintf("sceVideocodecOpen=0x%08X\n", res);
//---------------------------------------------------------------------------------//
Video_Codec_BufferMP4V[7] = 16384;
fp = fopen("ms0:/sceVideocodecGetEDRAM(mp4v).dat", "wb");
for(i=0;i<96;i++) {
fwrite( &Video_Codec_BufferMP4V[i], sizeof(unsigned int), 1, fp);
}
fclose(fp);
if ( (res = sceVideocodecGetEDRAM(Video_Codec_BufferMP4V, 0x1)) < 0 ) {
pspDebugScreenPrintf("sceVideocodecGetEDRAM=0x%08X\n", res);
goto wait;
}
pspDebugScreenPrintf("sceVideocodecGetEDRAM=0x%08X\n", res);
//---------------------------------------------------------------------------------//
fp = fopen("ms0:/sceVideocodecInit(mp4v).dat", "wb");
for(i=0;i<96;i++) {
fwrite( &Video_Codec_BufferMP4V[i], sizeof(unsigned int), 1, fp);
}
fclose(fp);
if ( (res = sceVideocodecInit(Video_Codec_BufferMP4V, 0x1)) < 0 ) {
pspDebugScreenPrintf("sceVideocodecInit=0x%08X\n", res);
goto wait;
}
pspDebugScreenPrintf("sceVideocodecInit=0x%08X\n", res);
//---------------------------------------------------------------------------------//
Video_Codec_BufferMP4V[34] = 7;
Video_Codec_BufferMP4V[36] = 0;
fp = fopen("ms0:/sceVideocodecStop(mp4v).dat", "wb");
for(i=0;i<96;i++) {
fwrite( &Video_Codec_BufferMP4V[i], sizeof(unsigned int), 1, fp);
}
fclose(fp);
if ( (res = sceVideocodecStop(Video_Codec_BufferMP4V, 0x1)) < 0 ) {
pspDebugScreenPrintf("sceVideocodecStop=0x%08X\n", res);
goto wait;
}
pspDebugScreenPrintf("sceVideocodecStop=0x%08X\n", res);
//---------------------------------------------------------------------------------//
Video_Codec_BufferMP4V[9] = file_buffer;
Video_Codec_BufferMP4V[10] = fsize;
Video_Codec_BufferMP4V[14] = 7;
fp = fopen("ms0:/sceVideocodecDecode(mp4v).dat", "wb");
for(i=0;i<96;i++) {
fwrite( &Video_Codec_BufferMP4V[i], sizeof(unsigned int), 1, fp);
}
fclose(fp);
if ( (res = sceVideocodecDecode(Video_Codec_BufferMP4V, 0x1)) < 0 ) {
pspDebugScreenPrintf("sceVideocodecDecode=0x%08X\n", res);
goto wait;
}
pspDebugScreenPrintf("sceVideocodecDecode=0x%08X\n", res);
/****************************************************************************
Video_Codec_BufferMP4V[44] : frame width
Video_Codec_BufferMP4V[45] : frame height
Video_Codec_BufferMP4V[53] : maybe Ybuffer start address in ME ram
Video_Codec_BufferMP4V[54] : maybe CrBuffer start address in ME ram
Video_Codec_BufferMP4V[55] : maybe CbBuffer start address in ME ram
Video_Codec_BufferMP4V[56] : frame padding width
Video_Codec_BufferMP4V[57] : (frame padding width) >> 1
*****************************************************************************/
Video_YCrCbCopy_SrcBufferMP4V[0] = (Video_Codec_BufferMP4V[45]+15) & 0xFFFFFFF0;
Video_YCrCbCopy_SrcBufferMP4V[1] = (Video_Codec_BufferMP4V[44]+15) & 0xFFFFFFF0;
Video_YCrCbCopy_SrcBufferMP4V[2] = 0;
Video_YCrCbCopy_SrcBufferMP4V[3] = 1;
Video_YCrCbCopy_SrcBufferMP4V[4] = Video_Codec_BufferMP4V[53];
Video_YCrCbCopy_SrcBufferMP4V[5] = Video_YCrCbCopy_SrcBufferMP4V[4] + (Video_Codec_BufferMP4V[56] * (Video_YCrCbCopy_SrcBufferMP4V[0] >> 1));
Video_YCrCbCopy_SrcBufferMP4V[6] = Video_Codec_BufferMP4V[54];
Video_YCrCbCopy_SrcBufferMP4V[7] = Video_Codec_BufferMP4V[55];
Video_YCrCbCopy_SrcBufferMP4V[8] = Video_YCrCbCopy_SrcBufferMP4V[6] + (Video_Codec_BufferMP4V[57] * (Video_YCrCbCopy_SrcBufferMP4V[0] >> 2));
Video_YCrCbCopy_SrcBufferMP4V[9] = Video_YCrCbCopy_SrcBufferMP4V[7] + (Video_Codec_BufferMP4V[57] * (Video_YCrCbCopy_SrcBufferMP4V[0] >> 2));
Video_YCrCbCopy_SrcBufferMP4V[10] = 0;
Video_YCrCbCopy_SrcBufferMP4V[11] = 0;
Video_YCrCbCopy_DestBufferMP4V[0] = (Video_Codec_BufferMP4V[45]+15) >> 4;
Video_YCrCbCopy_DestBufferMP4V[1] = (Video_Codec_BufferMP4V[56]+15) >> 4;
Video_YCrCbCopy_DestBufferMP4V[4] = YBuffer;
Video_YCrCbCopy_DestBufferMP4V[5] = (unsigned long)(((void*)YBuffer) + (Video_Codec_BufferMP4V[56] * (Video_YCrCbCopy_SrcBufferMP4V[0] >> 1)) );
Video_YCrCbCopy_DestBufferMP4V[6] = CrBuffer;
Video_YCrCbCopy_DestBufferMP4V[7] = CbBuffer;
Video_YCrCbCopy_DestBufferMP4V[8] = (unsigned long)(((void*)CrBuffer) + (Video_Codec_BufferMP4V[57] * (Video_YCrCbCopy_SrcBufferMP4V[0] >> 2)) );
Video_YCrCbCopy_DestBufferMP4V[9] = (unsigned long)(((void*)CbBuffer) + (Video_Codec_BufferMP4V[57] * (Video_YCrCbCopy_SrcBufferMP4V[0] >> 2)) );
Video_YCrCbCopy_DestBufferMP4V[10] = Video_Codec_BufferMP4V[45];
Video_YCrCbCopy_DestBufferMP4V[11] = Video_Codec_BufferMP4V[44];
Video_YCrCbCopy_DestBufferMP4V[12] = 512;
fp = fopen("ms0:/sceMpegBaseYCrCbCopyVme(mp4v).dat", "wb");
for(i=0;i<12;i++) {
fwrite( &Video_YCrCbCopy_SrcBufferMP4V[i], sizeof(unsigned int), 1, fp);
}
for(i=0;i<12;i++) {
fwrite( &Video_YCrCbCopy_DestBufferMP4V[i], sizeof(unsigned int), 1, fp);
}
fclose(fp);
res = sceMpegBaseYCrCbCopyVme(Video_YCrCbCopy_DestBufferMP4V, Video_YCrCbCopy_SrcBufferMP4V, 3);
pspDebugScreenPrintf("sceMpegBaseYCrCbCopyVme=0x%08X\n", res);
fp = fopen("ms0:/YBuffer(mp4v).dat", "wb");
fwrite( YBuffer, 512*512 , 1, fp);
fclose(fp);
fp = fopen("ms0:/CrBuffer(mp4v).dat", "wb");
fwrite( CrBuffer, 512*128 , 1, fp);
fclose(fp);
fp = fopen("ms0:/CbBuffer(mp4v).dat", "wb");
fwrite( CbBuffer, 512*128 , 1, fp);
fclose(fp);
//---------------------------------------------------------------------------------//
sceCtrlReadBufferPositive(&input, 1);
while(!(input.Buttons & PSP_CTRL_TRIANGLE))
{
sceKernelDelayThread(10000); // wait 10 milliseconds
sceCtrlReadBufferPositive(&input, 1);
}
fp = fopen("ms0:/mp4vend.dat", "wb");
for(i=0;i<96;i++) {
pspDebugScreenPrintf("0x%08X ", Video_Codec_BufferMP4V[i]);
fwrite( &Video_Codec_BufferMP4V[i], sizeof(unsigned int), 1, fp);
}
pspDebugScreenPrintf("\n");
fclose(fp);
wait:
sceCtrlReadBufferPositive(&input, 1);
while(!(input.Buttons & PSP_CTRL_TRIANGLE))
{
sceKernelDelayThread(10000); // wait 10 milliseconds
sceCtrlReadBufferPositive(&input, 1);
}
sceKernelExitGame();
return 0;
}
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
|
Last edited by cooleyes on Mon Aug 27, 2007 1:23 pm; edited 1 time in total |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Sat Aug 25, 2007 12:01 pm Post subject: |
|
|
cooleyes man you are the FUCKING Man ! :)
ahh now you just gotta figure out where the SYNC calls are :)
but thanx alot this saves me alot of bloat from xvidcore
keep it up man ...already i am forever in your debt
PS> did you ever figure the address of where me_for_vsh looks
up for its audio DEMUXing ability / Digital Signal Processor / for synthesis processing ???
PISS> why did you add sceMpegBaseYCrCbCopyVme to videocodec ?
thanx alot again
ADD to PSPSDK SVN _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
cools
Joined: 04 Mar 2006 Posts: 46
|
Posted: Sat Aug 25, 2007 2:00 pm Post subject: |
|
|
| This is pretty cool! Well im glad that xvid/divx can be decoded! this will probably lead to further developments. |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Sat Aug 25, 2007 2:22 pm Post subject: |
|
|
Wow!, you don't stop do you?
Thanks a lot :)
Art. |
|
| Back to top |
|
 |
cooleyes
Joined: 18 May 2006 Posts: 125
|
Posted: Mon Aug 27, 2007 1:27 pm Post subject: |
|
|
hehe, I had updated some code.
after call sceMpegBaseYCrCbCopyVme
we can get a three buffer( Y, Cr, Cb)
and the data is stored as YV12 format
so we can do a CSC, change it to RGB format, to draw |
|
| Back to top |
|
 |
jockyw2001
Joined: 29 Sep 2005 Posts: 339
|
Posted: Mon Aug 27, 2007 10:24 pm Post subject: |
|
|
Whopper! Definitely useful.
Great work once again cooleyes :) |
|
| Back to top |
|
 |
Matrixdub
Joined: 13 May 2005 Posts: 60
|
Posted: Mon Oct 01, 2007 2:38 am Post subject: |
|
|
I'm sorry for bumping this with no useful information, but I am wondering if an application has materialised from this code. If not, is it even feasible? Would the PSP be able to decode XviD at 480p at 30fps?
There are other applications that decode Xvid avis but nnowhere near 272p at 30fps. |
|
| Back to top |
|
 |
jockyw2001
Joined: 29 Sep 2005 Posts: 339
|
Posted: Mon Oct 01, 2007 5:27 am Post subject: |
|
|
| Matrixdub wrote: | I'm sorry for bumping this with no useful information, but I am wondering if an application has materialised from this code. If not, is it even feasible? Would the PSP be able to decode XviD at 480p at 30fps?
There are other applications that decode Xvid avis but nnowhere near 272p at 30fps. |
When my other zillion of projects are coming to an end I'll deploy this in PMPVLC and my upcoming PSP Gnash port. |
|
| Back to top |
|
 |
Matrixdub
Joined: 13 May 2005 Posts: 60
|
Posted: Mon Oct 01, 2007 5:45 am Post subject: |
|
|
| thank you! |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
Posted: Mon Oct 01, 2007 8:52 am Post subject: |
|
|
| Yep, adding native xvid support to your excellent pmpvlc would be awsome jockyw2001 :) |
|
| Back to top |
|
 |
someone Idiot
Joined: 13 Sep 2005 Posts: 74
|
Posted: Fri Dec 07, 2007 12:43 am Post subject: |
|
|
Any update?
Really want! |
|
| Back to top |
|
 |
Rangu2057
Joined: 23 Jul 2007 Posts: 87 Location: wilmington, NC
|
Posted: Fri Dec 07, 2007 6:15 am Post subject: |
|
|
Good job man, keep up the awesome work _________________ the questions of today are awnswered by the blood and bullets of tomorrow! ---EagleEye--- (Socom FTB2) |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Fri Dec 07, 2007 8:02 am Post subject: |
|
|
Just for notification: I added pspvideocodec and pspmpegbase to the SDK.
Still needs some documentation on the use of the "Video_Codec_BufferMP4V" (best create a matching struct) and Video_YCrCbCopy_Buffer (already created a struct for that - see pspmpegbase.h). _________________ <Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
Alexander Berl |
|
| Back to top |
|
 |
Matrixdub
Joined: 13 May 2005 Posts: 60
|
Posted: Mon Feb 25, 2008 1:12 am Post subject: |
|
|
| Sorry, I've been out of it for a while, can we play avi files natively on the PSP yet? |
|
| Back to top |
|
 |
Matrixdub
Joined: 13 May 2005 Posts: 60
|
Posted: Sat May 03, 2008 9:26 pm Post subject: |
|
|
I'm sorry, can someone please tell me how to load this under the PSP to play XviD files? I don't have any coding experience.
Thank you. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun May 04, 2008 5:09 am Post subject: |
|
|
| Matrixdub wrote: | I'm sorry, can someone please tell me how to load this under the PSP to play XviD files? I don't have any coding experience.
Thank you. |
You clearly don't understand video either. :)
xvid is a method of compressing a video stream. You won't find any files that are xvid, but they might have a video stream that had been compressed using xvid. The file level is the container. Containers are AVI, MKV, OGM, MP4, etc. Within the container, you'll have a number of streams - usually at least one video and one audio stream (multiple audio streams and a subtitle stream are also common).
You can already play "xvid" as long as the dimensions are correct, the encoding was compliant, and it's in a supported container. Generic AVI files are not supported by the PSP. If you are looking for something that can play generic video files (like AVIs with unspecified xvid streams), get PSPTube and put the video files in the favorites drawer. It can play a variety of video files, but expect the higher resolution ones to skip.
Your best bet for playing video on the PSP is still to convert the video into something the PSP can handle using an app like xvid4psp. |
|
| Back to top |
|
 |
Matrixdub
Joined: 13 May 2005 Posts: 60
|
Posted: Tue May 06, 2008 6:19 am Post subject: |
|
|
| I thought this code meant that the PSP could decode "XviD files" faster than simply changing the container to pmp (which works reasonably well). Was I wrong in that aspect? |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Tue May 06, 2008 8:03 am Post subject: |
|
|
| Matrixdub wrote: | | I thought this code meant that the PSP could decode "XviD files" faster than simply changing the container to pmp (which works reasonably well). Was I wrong in that aspect? |
Not entirely. Just as with the hw accelerated h.264, the xvid encoding probably has to follow the same guidelines as the "official" xvid/mp4 files the built-in player handles. The Sony libs don't handle arbitrary streams. For example, the dimensions still need to be divisible by 16. Hopefully the xvid decoder is less constrained than the h.264 decoder. I suppose someone will have try it and see. |
|
| Back to top |
|
 |
Matrixdub
Joined: 13 May 2005 Posts: 60
|
Posted: Sat May 10, 2008 3:34 am Post subject: |
|
|
| J.F. wrote: | | I suppose someone will have try it and see. |
I've looked but I can't find a binary for this. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|