Skip to content

Instantly share code, notes, and snippets.

@yne yne/sceAvDecode.c
Created Nov 24, 2017

Embed
What would you like to do?
PsVita sceAv Decode usage
static void vita_setup(int videoFormat, int width, int height) {
int width=960;
int height=544;
char rasm_buff[DECODER_BUFFER_SIZE];
int dbuf_idx = 1;
/* Init display and decoder*/
gs_sps_init();
SceUID displayblock = sceKernelAllocMemBlock("display", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, 2 * FRAMEBUFFER_SIZE, &((SceKernelAllocMemBlockOpt){ sizeof(SceKernelAllocMemBlockOpt), 4, FRAMEBUFFER_ALIGNMENT}));
void *base;
sceKernelGetMemBlockBase(displayblock, &base);
void *framebuffer[2]={base, ((char*)base) + FRAMEBUFFER_SIZE};
sceDisplaySetFrameBuf(&((SceDisplayFrameBuf){ sizeof(framebuf), base, SCREEN_WIDTH, SCE_DISPLAY_PIXELFORMAT_A8B8G8R8, SCREEN_WIDTH, SCREEN_HEIGHT}), 1);
SceAvcdecQueryDecoderInfo decoder_info = {width,height,5};
sceVideodecInitLibrary(0x1001, &((SceVideodecQueryInitInfoHwAvcdec){sizeof(SceVideodecQueryInitInfoHwAvcdec),width,height,5,1}));
SceAvcdecDecoderInfo decoder_info_out = {0};
sceAvcdecQueryDecoderMemSize(0x1001, &decoder_info, &decoder_info_out);
SceAvcdecCtrl decoder = {0};
int decoderblock = sceKernelAllocMemBlock("decoder", SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_NC_RW, decoder.frameBuf.size = (decoder_info_out.frameMemSize + 0xFFFFF) & ~0xFFFFF, NULL);
sceKernelGetMemBlockBase(decoderblock, &decoder.frameBuf.pBuf);
sceAvcdecCreateDecoder(0x1001, &decoder, &decoder_info);
/* Decode the frame */
void* bufferList;
uint32_t fullLength;
SceAvcdecArrayPicture array_picture = {0,1,&{&(SceAvcdecPicture){sizeof(SceAvcdecPicture),{0, LINE_SIZE, SCREEN_WIDTH, SCREEN_HEIGHT}, framebuffer[dbuf_idx]}}};
if (fullLength >= DECODER_BUFFER_SIZE)exit(1);
uint32_t rasm_off = 0;
for (PLENTRY entry = gs_sps_fix(bufferList, 0) ; entry ; rasm_off += entry->length, entry = entry->next)
memcpy(rasm_buff+rasm_off, entry->data, entry->length);
sceAvcdecDecode(&decoder, &((SceAvcdecAu){{~0,~0},{~0,~0},{rasm_buff, fullLength}}), &array_picture);
if (array_picture.numOfOutput == 1)
sceDisplaySetFrameBuf(&(SceDisplayFrameBuf){sizeof(SceDisplayFrameBuf),framebuffer[dbuf_idx++&1],SCREEN_WIDTH,SCE_DISPLAY_PIXELFORMAT_A8B8G8R8, SCREEN_WIDTH, SCREEN_HEIGHT}, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.