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

📄 decinit.c

📁 This the source release kit for the following system configuration(s): - AMD Alchemy(TM) DBAu1200(
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************
decinit.c
*************************************************************************/

#include <stdio.h>
#include "decinit.h"
#include "diu.h"
#include "driverif.h"
#include "debug.h"  // Debug messages

// Some defines for debugging
//#define DUMP_YUV_DATA

// Frame Timing Debug Info
//#define TIME_FRAMES

#ifdef TIME_FRAMES
int g_StartTime = 0;
#endif

int g_H264TNum = 0;

extern m_u32 g_uiWaitForIFrame;
extern DIUCompHandle_t g_hComp;
extern wrap_context *g_pWrapContext;
extern int g_nFramesSinceI;
extern int g_nIFrameSpacing;
extern int g_nSkipRate;
extern int g_nSkipCount;

#define CODECS_MAX_FOURCC	                32
#define CODECS_MAX_OUTFMT	                16
#define CODECS_MAX_INFMT	                16

#define VDCTRL_QUERY_FORMAT                 3 // test for availabilty of a format
#define VDCTRL_QUERY_MAX_PP_LEVEL           4 // test for postprocessing support (max level)
#define VDCTRL_SET_PP_LEVEL                 5 // set postprocessing level
#define VDCTRL_SET_EQUALIZER                6 // set color options (brightness,contrast etc)
#define VDCTRL_GET_EQUALIZER                7 // get color options (brightness,contrast etc)
#define VDCTRL_RESYNC_STREAM                8 // seeking
#define VDCTRL_QUERY_UNSEEN_FRAMES          9 // current decoder lag
#define MP_MAX_PLANES	                    4
//--------- codec's requirements (filled by the codec/vf) ---------

//--- buffer content restrictions:
// set if buffer content shouldn't be modified:
#define MP_IMGFLAG_PRESERVE                 0x01

// set if buffer content will be READ for next frame's MC: (I/P mpeg frames)
#define MP_IMGFLAG_READABLE                 0x02

//--- buffer width/stride/plane restrictions: (used for direct rendering)
// stride _have_to_ be aligned to MB boundary:  [for DR restrictions]
#define MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE    0x4

// stride should be aligned to MB boundary:     [for buffer allocation]
#define MP_IMGFLAG_PREFER_ALIGNED_STRIDE    0x8

// codec accept any stride (>=width):
#define MP_IMGFLAG_ACCEPT_STRIDE            0x10

// codec accept any width (width*bpp=stride -> stride%bpp==0) (>=width):
#define MP_IMGFLAG_ACCEPT_WIDTH             0x20

//--- for planar formats only: uses only stride[0], and stride[1]=stride[2]=stride[0]>>mpi->chroma_x_shift
#define MP_IMGFLAG_COMMON_STRIDE            0x40

// uses only planes[0], and calculates planes[1,2] from width,height,imgfmt
#define MP_IMGFLAG_COMMON_PLANE             0x80

#define MP_IMGFLAGMASK_RESTRICTIONS         0xFF

//--------- color info (filled by mp_image_setfmt() ) -----------
// set if number of planes > 1
#define MP_IMGFLAG_PLANAR                   0x100

// set if it's YUV colorspace
#define MP_IMGFLAG_YUV                      0x200

// set if it's swapped (BGR or YVU) plane/byteorder
#define MP_IMGFLAG_SWAPPED                  0x400

// using palette for RGB data
#define MP_IMGFLAG_RGB_PALETTE              0x800

#define MP_IMGFLAGMASK_COLORS               0xF00

// codec uses drawing/rendering callbacks (draw_slice()-like thing, DR method 2) [the codec will set this flag if it supports callbacks, and the vo _may_
//  clear it in get_image() if draw_slice() not implemented]
#define MP_IMGFLAG_DRAW_CALLBACK            0x1000

// set if it's in video buffer/memory: [set by vo/vf's get_image() !!!]
#define MP_IMGFLAG_DIRECT                   0x2000

// set if buffer is allocated (used in destination images):
#define MP_IMGFLAG_ALLOCATED                0x4000

// buffer type was printed (do NOT set this flag - it's for INTERNAL USE!!!)
#define MP_IMGFLAG_TYPE_DISPLAYED           0x8000

// codec doesn't support any form of direct rendering - it has own buffer allocation. so we just export its buffer pointers:
#define MP_IMGTYPE_EXPORT                   0

// codec requires a static WO buffer, but it does only partial updates later:
#define MP_IMGTYPE_STATIC                   1

// codec just needs some WO memory, where it writes/copies the whole frame to:
#define MP_IMGTYPE_TEMP                     2

// I+P type, requires 2+ independent static R/W buffers
#define MP_IMGTYPE_IP                       3

// I+P+B type, requires 2+ independent static R/W and 1+ temp WO buffers
#define MP_IMGTYPE_IPB                      4
#define MP_MAX_PLANES	                    4

#define MP_IMGFIELD_ORDERED                 0x01
#define MP_IMGFIELD_TOP_FIRST               0x02
#define MP_IMGFIELD_REPEAT_FIRST            0x04
#define MP_IMGFIELD_TOP                     0x08
#define MP_IMGFIELD_BOTTOM                  0x10
#define MP_IMGFIELD_INTERLACED              0x20

static int lavc_param_error_resilience=2;
static int lavc_param_skip_top=0;
static int lavc_param_skip_bottom=0;
static int lavc_param_fast=0;
static int lavc_param_lowres=0;
static char *lavc_param_lowres_str=NULL;
static int lavc_param_bitexact=0;
int avcodec_inited=0;

typedef struct codecs_st 
{
  unsigned int fourcc[CODECS_MAX_FOURCC];
  unsigned int fourccmap[CODECS_MAX_FOURCC];
  unsigned int outfmt[CODECS_MAX_OUTFMT];
  unsigned char outflags[CODECS_MAX_OUTFMT];
  unsigned int infmt[CODECS_MAX_INFMT];
  unsigned char inflags[CODECS_MAX_INFMT];
  char *name;
  char *info;
  char *comment;
  char *dll;
  char* drv;
  GUID guid;
  //  short driver;
  short flags;
  short status;
  short cpuflags;
} codecs_t;

typedef struct mp_image_s 
{
  unsigned short flags;
  unsigned char type;
  unsigned char bpp;  // bits/pixel. NOT depth! for RGB it will be n*8
  unsigned int imgfmt;
  int width,height;  // stored dimensions
  int x,y,w,h;  // visible dimensions
  unsigned char* planes[MP_MAX_PLANES];
  int stride[MP_MAX_PLANES];
  char * qscale;
  int qstride;
  int pict_type; // 0->unknown, 1->I, 2->P, 3->B
  int fields;
  int num_planes;
  /* these are only used by planar formats Y,U(Cb),V(Cr) */
  int chroma_width;
  int chroma_height;
  int chroma_x_shift; // horizontal
  int chroma_y_shift; // vertical
  /* for private use by filter or vo driver (to store buffer id or dmpi) */
  void* priv;
} mp_image_t;

typedef struct mp_codec_info_s
{
  /* codec long name ("Autodesk FLI/FLC Animation decoder" */
  const char *name;
  /* short name (same as driver name in codecs.conf) ("dshow") */
  const char *short_name;
  /* interface author/maintainer */
  const char *maintainer;
  /* codec author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
  const char *author;
  /* any additional comments */
  const char *comment;
} mp_codec_info_t;
typedef mp_codec_info_t vd_info_t;

/* interface of video decoder drivers */
typedef struct vd_functions_s
{
  vd_info_t *info;
  int (*init)(sh_video_t *sh);
  void (*uninit)(sh_video_t *sh);
  int (*control)(sh_video_t *sh,int cmd,void* arg, ...);
  mp_image_t* (*decode)(sh_video_t *sh,void* data,int len,int flags);
} vd_functions_t;

typedef struct dp_hdr_s 
{
  uint32_t chunks;  // number of chunks
  uint32_t timestamp; // timestamp from packet header
  uint32_t len; // length of actual data
  uint32_t chunktab;  // offset to chunk offset array
} dp_hdr_t;

codecs_t  h264codec={{ 0x34363248, 0x34363268, 0x31637661, 0x10000005, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, /* fourcc */
{ 0x34363248, 0x34363268, 0x31637661, 0x10000005, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* fourccmap */
{ 0x32315659, 0x30323449, 0x56555949, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, /* outfmt */
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* outflags */
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, /* infmt */
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* inflags */
"ffh264", /* name */
"FFmpeg H.264", /* info */
NULL, /* comment */
"h264", /* dll */
"ffmpeg", /* drv */
{ 0x00000000, 0, 0,{ 0, 0, 0, 0, 0, 0, 0, 0 } }, /* GUID */
0 /* flags */, 1 /* status */, 0 /* cpuflags */ };

static vd_info_t info = 
{
  "FFmpeg's libavcodec codec family",
    "ffmpeg",
    "A'rpi",
    "A'rpi, Michael, Alex",
    "native codecs (http://ffmpeg.sf.net/)"
};

STATIC_FUNC int Get_Buffer(AVCodecContext *avctx, AVFrame *pic);
STATIC_FUNC void release_buffer(AVCodecContext *avctx, AVFrame *pic);
int init_video(sh_video_t *sh_video,char* codecname,char* vfm,int status);
void uninit_video(sh_video_t *sh_video);

int H264_Decoder_Init(ibuf_t * pInBuf, int * iDisplayWidth, int * iDisplayHeight)
{
  long len_configcode=pInBuf->size-4;
  int stream_header_len=len_configcode;
  int depth=24;
  
  DP_H264((M_TEXT("==>H264_Decoder_Init, stream_header_len = %d\n"), stream_header_len));

  sh_video.format=mmioFOURCC('a', 'v', 'c', '1');
  sh_video.bih=av_malloc(sizeof(BITMAPINFOHEADER) + stream_header_len);
  memset(sh_video.bih,0,sizeof(BITMAPINFOHEADER) +stream_header_len);
  sh_video.bih->biSize=40  + stream_header_len;
  MEMCPY(((unsigned char *)sh_video.bih)+40,  pInBuf->pbuf, stream_header_len);
  MEMCPY(&(sh_video.disp_h),(unsigned char* )((long)(pInBuf->pbuf)+len_configcode),2);
  MEMCPY(&(sh_video.disp_w),(unsigned char* )((long)(pInBuf->pbuf)+len_configcode+2),2);      
  sh_video.bih->biWidth=sh_video.disp_w;
  sh_video.bih->biHeight=sh_video.disp_h;
  sh_video.bih->biPlanes=0;
  sh_video.bih->biBitCount=depth;
  sh_video.bih->biCompression=sh_video.format;
  sh_video.bih->biSizeImage=sh_video.bih->biWidth*sh_video.bih->biHeight;
  *iDisplayWidth=sh_video.bih->biWidth;
  *iDisplayHeight=sh_video.bih->biHeight;

  DP_H264((M_TEXT("*iDisplayWidth = %d *iDisplayHeight = %d\n"), *iDisplayWidth, *iDisplayHeight));
  init_video(&sh_video,NULL,NULL,0);
  DP_H264((M_TEXT("<==H264_Decoder_Init\n")));
  return DIU_STATUS_OK;
}

void H264_Decoder_CleanUp()
{
  DP_H264((M_TEXT("==>H264_VideoObject_CleanUp\n")));
  uninit_video(&sh_video);
  av_freep(sh_video.bih);
  close_mae_driver();
  DP_H264((M_TEXT("Closing the MAE Driver\n")));
  DP_H264((M_TEXT("<==H264_VideoObject_CleanUp\n")));
}

// to set/get/query special features/parameters
STATIC_FUNC int control(sh_video_t *sh,int cmd,void* arg,...)
{
  return 0;
}

// init driver
STATIC_FUNC int init(sh_video_t *sh)
{
  AVCodecContext *avctx;
  vd_ffmpeg_ctx *ctx;
  AVCodec *lavc_codec;
  int lowres_w=0;
  
  if(!avcodec_inited)
  {
    avcodec_init();
    // avcodec_register_all();
    avcodec_inited=1;
  }
  
  ctx = sh->context = av_malloc(sizeof(vd_ffmpeg_ctx));
  
  if (!ctx)
    return(0);
  
  memset(ctx, 0, sizeof(vd_ffmpeg_ctx));

⌨️ 快捷键说明

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