Embedded topics: s5pv210-MPEG4 decoding (MFC)

Source: Internet
Author: User

Decoding is easier than encoding. The only worry is that the head data generated by the encoder is used for initialization. That is to say, during encoding, a head data is generated, which is used for decoding.

 

# 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. 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 ("Fai Led to open MFC device! \ N "); Return-1;} printf (" = ssbsipmfcdecopen OK \ n "); int maxframesize = 256*1024; /* obtain the 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: you do not need to set * // int configvalue = 2; // the number that you want to delay // ssbsipmfcdecs Etconfig (handle, mfc_dec_setconf_display_delay, // & configvalue);/* read the initialization data to the input buffer, which is generated during 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 whether Initialization is successful */timed out; ssbsip_mfc_dec_outbuf_status status = ssbsipmfcdecgetoutbuf (handle, & out); If (Out. img_width <= 0 | out. img_height <= 0) {printf ("bad image size, shocould init again! \ N "); Return-1 ;}/ * Check the 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) \ 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_ B Ottom_offset); printf ("------------------------------- \ n"); int COUNT = 0; while (count ++ <2) {/* Open the input data: encoded MPEG4 data */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) \ 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 // store as NV12-Tif (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 // storage is yuv420pif (1) {// tile-> linearint 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 0if (0) {// tile to rgbint 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 ;}


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.