Decoding is easier than coding, and the only thing to worry about is initializing it with the head data generated by the encoder. That is, when coding, a head data is generated, which is used to decode the data.
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include ". /mfc/ssbsipmfcapi.h "#include". /mfc/mfcconvert.h "#include" Bitmap.h "#include". /mm/mmclock.h "#include".
/vout/vout.h "int test_dec_mpeg4 () {Vout vo; Vo.
Open (640,480, 640, 480);
Ssbsip_mfc_error_code ret = MFC_RET_OK;
Open unsigned int buf_type = CACHE;
void* handle = Ssbsipmfcdecopen ();
if (handle = = NULL) {printf ("Failed to open MFC device!\n");
return-1;
printf ("= = Ssbsipmfcdecopen ok \ \ n");
int maxframesize = 256 * 1024;
/* Get Input buffer information * * void* virinbuf = NULL;
void* phyinbuf = NULL;
Virinbuf = Ssbsipmfcdecgetinbuf (handle, &phyinbuf, maxframesize);
printf ("= = Ssbsipmfcdecgetinbuf OK \ n");
printf ("virinbuf=%08x, phyinbuf=%08x \ n", Virinbuf, Phyinbuf); /* Configuration: No need to set * *//int configvalue = 2; The number that is want to delay//ssbsipmfcdecsetconfig (handle, Mfc_dec_setconf_display_delay,//&CONFIGVA
Lue); /* ReadInitializes the data to the input buffer, which is generated when encoding * * file* fp = fopen ("A00.MPEG4", "RB");
int hdr_size = Fread (virinbuf, 1, MaxFrameSize, FP);
printf ("Init data:%d bytes \ n", hdr_size);
Fclose (FP);
/* Initialize */ret = Ssbsipmfcdecinit (handle, Mpeg4_dec, hdr_size);
if (ret!= mfc_ret_ok) {printf ("Failed to init mfc!\n");
return-1;
else {/* check if initialization succeeded/Ssbsip_mfc_dec_output_info out;
Ssbsip_mfc_dec_outbuf_status STATUS = ssbsipmfcdecgetoutbuf (handle, &out);
if (out.img_width <= 0 | | | out.img_height <= 0) {printf ("Bad image size, should init again!\n");
return-1;
}/* Check output buffer/printf ("= ssbsipmfcdecinit ok \ \ n");
Ssbsip_mfc_dec_output_info out;
Ssbsip_mfc_dec_outbuf_status STATUS;
Status = Ssbsipmfcdecgetoutbuf (handle, &out); printf ("Output:status =%d, image (%dx%d), buf (%dx%d), crop (%d,%d,%d,%d) \ n", status, Out.img_width, Out.img_height , Out.buf_width, Out.buf_height, Out.crop_left_offset, Out.crop_top_offset, Out.crop_right_offset,Out.crop_bottom_offset);
printf ("-------------------------------\ n");
int count = 0;
while (count + + < 2) {/* Open input data: MPEG4 data already encoded/char filename[128];
sprintf (filename, "A%02D.MPEG4", count);
printf (">>> input file:%s \ n", filename);
file* fp = fopen (filename, "RB");
int indatalen = Fread (virinbuf, 1, MaxFrameSize, FP);
Fclose (FP);
/* Decoding/ret = Ssbsipmfcdecexe (handle, Indatalen);
if (ret!= mfc_ret_ok) {printf ("Failed decoding (%d) \ n", ret);
return-1;
}/* Output buffer */Ssbsip_mfc_dec_output_info out;
Ssbsip_mfc_dec_outbuf_status STATUS;
Status = Ssbsipmfcdecgetoutbuf (handle, &out); printf ("<<< output:status =%d, image (%dx%d), buf (%dx%d), crop (%d,%d,%d,%d) \ n", status, Out.img_width, Out.img_height, Out.buf_width, Out.buf_height, Out.crop_left_offset, Out.crop_top_offset, Out.crop_right_offset
, Out.crop_bottom_offset); if (status = = Mfc_getoutbuf_display_decoding | | status = = MFC_getoutbuf_display_only) {printf ("y_addr =%08x, cbcr_addr =%08x \ n", out. Yviraddr, out.
CVIRADDR); Vo. DRAWNV12T (out. Yphyaddr, out.
CPHYADDR); Vo. DRAWNV12T (out. Yviraddr, out.
CVIRADDR);
Sleep (1); #if 0//stored as Nv12-t if (1) {//vo. DRAWNV12T (out. Yphyaddr, out.
CPHYADDR);
int y_size = Out.buf_width * out.buf_height;
int uv_size = Y_SIZE/2;
Char yuvname[128];
sprintf (Yuvname, "t%02d.nv12t", count);
file* fp_y = fopen (Yuvname, "WB"); Fwrite (out.
YVIRADDR, 1, y_size, fp_y); Fwrite (out.
CVIRADDR, 1, uv_size, fp_y);
Fclose (fp_y);
#endif #if 0//stored as yuv420p if (1) {//tile-> linear int y_size = Out.buf_width * out.buf_height;
int uv_size = Y_SIZE/2;
unsigned char* y = new unsigned char[y_size];
unsigned char* UV = new unsigned char[uv_size];
printf ("Y buff:%08x,%d\n", Y, y_size); Tile_to_linenar_y ((char*) out.
Yviraddr, (char*) y, Out.buf_width, out.buf_height); Y_tile_to_linear_4x2 (y, (unsigned char*) out.
Yviraddr, Out.buf_width, out.buf_height); CBCR_TILE_TO_LINEAR_4X2 (UV, (unsigned char*) out.
Cviraddr, Out.buf_width, out.buf_height); Tile_to_linear_64x32_4x2_neon (y, (unsigned char*) out.
Yviraddr, Out.buf_width, out.buf_height); Tile_to_linear_64x32_4x2_uv_neon (UV, (unsigned char*) out.
Cviraddr, Out.buf_width, OUT.BUF_HEIGHT/2); Nv_2_uv ((char*) out.
Cviraddr, (char*) UV, (char*) UV + Y_SIZE/4, out.buf_width, out.buf_height);
Char yuvname[128];
sprintf (Yuvname, "c%02d.yuv420", count);
file* fp_y = fopen (Yuvname, "WB");
Fwrite (Y, 1, y_size, fp_y);
Fwrite (UV, 1, uv_size, fp_y);
Fclose (fp_y);
printf ("haha\n");
delete [] y;
delete [] UV;
#endif #if 0 if (0) {//tile to RGB int width = out.buf_width;
int height = out.buf_height;
Bitmap bmp; Bmp.
Create (width, height, 24); Tile64x32_to_rgb24 ((unsigned char*) out. YVIRADDR, (unsigned char*) out. CviradDr, Bmp.m_data, width, height);
printf ("Write to BMP file \ n");
Char outname[128];
sprintf (Outname, "%s.bmp", filename); Bmp.
SaveToFile (outname);
} #endif} getchar (); Vo.
Close ();
Close Ssbsipmfcdecclose (handle);
return 0;
}