we can use videocodec.prx to decode xvid(divx)
we can use videocodec.prx to decode xvid(divx)
hi, I think I had found out how use videocodec.prx to decode xvid(divx) frame .
heres is my demo src code:
http://www.fx-world.org/cooleyes/downlo ... ectest.rar
and two demo data:
1. Test.dat( just one frame(320*240) encoded by xvid)
http://www.fx-world.org/cooleyes/downloads/Test.dat
2. Test1.dat( just one frame(480*272) encoded by xvid)
http://www.fx-world.org/cooleyes/downloads/Test1.dat
heres is my demo src code:
http://www.fx-world.org/cooleyes/downlo ... ectest.rar
and two demo data:
1. Test.dat( just one frame(320*240) encoded by xvid)
http://www.fx-world.org/cooleyes/downloads/Test.dat
2. Test1.dat( just one frame(480*272) encoded by xvid)
http://www.fx-world.org/cooleyes/downloads/Test1.dat
Code: Select all
#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.
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
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
-
- Posts: 339
- Joined: Thu Sep 29, 2005 4:19 pm
-
- Posts: 339
- Joined: Thu Sep 29, 2005 4:19 pm
When my other zillion of projects are coming to an end I'll deploy this in PMPVLC and my upcoming PSP Gnash port.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.
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).
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
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
Alexander Berl
You clearly don't understand video either. :)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.
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.
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.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?