⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libmpeg2test.c

📁 au1200 linux2.6.11 硬件解码mae驱动和maiplayer播放器源码
💻 C
字号:
/* <LIC_AMD_STD> * Copyright (c) 2005 Advanced Micro Devices, Inc. *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *  * The full GNU General Public License is included in this distribution in the * file called COPYING * </LIC_AMD_STD>  *//* <CTL_AMD_STD> * </CTL_AMD_STD>  *//* <DOC_AMD_STD> * </DOC_AMD_STD>  *//*  * libmpeg2test - sample mpeg2 decode test app (with no video display)*/#include <stdio.h>#include <stdlib.h>#include <inttypes.h>#include <sys/time.h>#include <signal.h>#include "mpeg2.h"#define BUFFER_SIZE 	8192	#define I_FRAMES_ONLY	1#define IP_FRAMES_ONLY  2#define P_FRAMES_ONLY   3mpeg2dec_t * decoder;mpeg2_state_t state;static void print_fps(int);static void init (){    decoder = mpeg2_init (1,0,0,0);    if (decoder == NULL) {        fprintf (stderr, "Could not allocate a decoder object.\n");        exit (1);    }}static void close (){    mpeg2_close (decoder);}static void decode(FILE *mpgfile){  unsigned char buffer[BUFFER_SIZE];  size_t size;  unsigned int print=0;    print_fps(0);    size = (size_t)-1;    do {	state = mpeg2_parse (decoder);		switch (state) {	case STATE_BUFFER:      size = fread (buffer, sizeof(unsigned char), BUFFER_SIZE, mpgfile);      mpeg2_buffer (decoder, buffer, buffer + size);	    break;	case STATE_SLICE:	case STATE_END:	case STATE_INVALID_END:	    /* finished decoding all slices for the current picture               good time to update the stats */	      print++;	      print_fps (print);	    break;		default:	    break;	}    } while (size);}int setmode (unsigned int uiMode){    unsigned int uiDecodeMode;                                                                                                                      /* translate mode */    switch (uiMode)    {        case I_FRAMES_ONLY:            uiDecodeMode= DECODE_I_ONLY;            break;                                                                                                                          case P_FRAMES_ONLY:            uiDecodeMode = DECODE_P_ONLY;            break;                                                                                                                          case IP_FRAMES_ONLY:            uiDecodeMode = DECODE_IP_ONLY;            break;                                                                                                                          default:            uiDecodeMode = DECODE_NORMAL;            break;    }    /* set mode */    mpeg2_setmode (decoder, uiDecodeMode);    return 0;}static void SignalHandler (int iSignal){    exit (1);}void print_fps (int frames){  static struct timeval tv_start;  struct timeval tv_end;  float fps, elapsed;  static int num=0;  gettimeofday (&tv_end, NULL);  if (!frames) {    tv_start = tv_end;    return;  }  if (++num < 15)   return;   num = 0;  elapsed = (tv_end.tv_sec - tv_start.tv_sec) * 100 + (tv_end.tv_usec - tv_start.tv_usec) / 10000;  fps     = (float)(frames * 100.0) / elapsed;//  if (!(frames % 20)) {    fprintf (stderr, "\n%d frames in %.2f sec (%.2f fps)",          frames, elapsed / 100.0, fps         );//  }}int main (int argc, char ** argv){    FILE * mpgfile;    unsigned char ucBuffer[BUFFER_SIZE];    unsigned long ulBufferSize;    unsigned long mode;    if (argc > 1)    {	if (argc == 3)        {	    mode = atol (argv[2]);	    setmode (mode);        }	mpgfile = fopen (argv[1], "rb");	if (!mpgfile) {	    fprintf (stderr, "Could not open file \"%s\".\n", argv[1]);	    exit (1);	}        init ();    }    else    {        printf ("\n USAGE : libmpeg2test <filename> <mode>\n mode : 1 for I frames only\n2 for IP frames only\n3 for P frames only\ndefault is IPB");   	exit (1);     }    signal (SIGINT, &SignalHandler);    /* read the input file and keep sending buffers to the decoder */    decode (mpgfile);    close ();    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -