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

📄 df-player.c

📁 Flash Animation Decode library
💻 C
字号:
/** * libFAD - Flash Animation Decode library * Copyright (C) 2005-2006 VGSystem Technologies, Inc. * * libFAD is the legal property of its developers, whose names are too numerous * to list here.  Please refer to the COPYRIGHT file distributed with this * source distribution. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library 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 Library 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 * * $Id: df-player.c,v 1.5 2006/03/22 01:44:56 wrxzzj Exp $ */#include <signal.h>#include <error.h>#include <string.h>#include <cairo.h>#include <directfb.h>#include <cairo-directfb.h>#include <sys/time.h>#include "fad.h"#define DIET_FRAMERENDER  0x1000#define DUMP(...) fprintf(stderr, "df-player: "__VA_ARGS__)static IDirectFB *dfb = NULL;static IDirectFBDisplayLayer  *layer;static IDirectFBWindow        *window;static IDirectFBSurface       *cairo_surface;static fad_frame_t frame = {0};static fad_stream_t stream = {0};static FILE *fp = NULL;static void do_frame_render(int signo) {#if 1  if(signo == SIGVTALRM) {    while(frame.sta != FAD_STA_DORENDER && frame.sta != FAD_STA_FINISH) {      fad_frame_decode(&frame, &stream);    }    if(frame.sta == FAD_STA_END)      break;    if(frame.sta == FAD_STA_DORENDER) {      /**set background color for movie*/      cairo_surface->Clear(cairo_surface, frame.r, frame.g, frame.b, 0xff);      /**render vector graphic movie*/      fad_frame_render_movie(&frame);      /**copy image buffer from surface to screen*/      cairo_surface->Flip(cairo_surface, NULL, 0);      /**render audio in frame*/      fad_frame_render_audio(&frame, &stream);    }  }#endif}int main(int argc, char *argv[]) {  int width = 0, height = 0, quit = 0;  DFBGraphicsDeviceDescription desc;  DFBDisplayLayerConfig        config;  IDirectFBEventBuffer *events = NULL;  struct itimerval value;  struct sigaction a;	DFBWindowID                  id;  if(argc != 2) {    printf("\tFlash animation player base on cairo.\n");    printf("\tCopyright (c) 2005 ~ 2006 RuXu W.(wrxzzj@gmail.com)\n");    printf("\n\tUsage: \tfap <Macromedia Flash Animation>.swf\n");    return -1;  }  fp = fopen(argv[1], "rb");  if(fp == NULL) {    DUMP("open %s failure, err = %s.\n", argv[1], strerror(errno));    return -1;  }  /**fad decoder initialize*/  fad_frame_init(&frame);  fad_stream_init(&stream, NULL);  fad_stream_stdio(&stream, fp);  /**decode flash file header*/  fad_frame_decode(&frame, &stream);  if(stream.err != FAD_ERROR_NONE) {    DUMP("decode flash file header failure.\n");    fclose(fp);    return -1;  }  width  = frame.size.x1 - frame.size.x0;  height = frame.size.y1 - frame.size.y0;  /**directFB initialize*/  if(DirectFBInit(&argc, &argv)) {    DUMP("directFB system initialize failure.\n");    goto error;  }  if(DirectFBCreate(&dfb)) {    DUMP("create IDirectFB interface failure.\n");    goto error;  }  dfb->GetDeviceDescription( dfb, &desc );  if(dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer) != DFB_OK) {    DUMP("get displaylayer failure.\n");    goto error;  }	layer->SetCooperativeLevel( layer, DLSCL_ADMINISTRATIVE );	if (!((desc.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&			(desc.blitting_flags & DSBLIT_BLEND_COLORALPHA  )))  {    config.flags = DLCONF_BUFFERMODE;    config.buffermode = DLBM_BACKSYSTEM;    layer->SetConfiguration( layer, &config );  }	layer->GetConfiguration( layer, &config );	layer->EnableCursor ( layer, 1 );  {		DFBWindowDescription desc;    desc.flags  = ( DWDESC_POSX | DWDESC_POSY |        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS );    desc.posx   = 2;    desc.posy   = 2;    desc.width  = width;    desc.height = height;    desc.caps =  DWCAPS_DOUBLEBUFFER|DWCAPS_ALPHACHANNEL;    if(layer->CreateWindow(layer, &desc, &window) != DFB_OK) {      DUMP("create layer window failure.\n");      goto error;    }    window->CreateEventBuffer(window, &events);    window->GetSurface(window, &cairo_surface);    {      cairo_surface_t *mysurface = NULL;      mysurface = cairo_directfb_surface_create(dfb, cairo_surface);      if(mysurface == NULL)        goto error;      frame.render->cr = cairo_create(mysurface);      if(frame.render->cr == NULL)        goto error;      cairo_surface_destroy(mysurface);    }    window->AttachEventBuffer(window,  events);		window->GetID(window, &id);		window->SetOpacity(window, 0xff);  }  window->RequestFocus(window);  window->RaiseToTop(window);  memset(&a, 0, sizeof(struct sigaction));  a.sa_handler = do_frame_render;  a.sa_flags = SA_RESTART;  sigemptyset(&a.sa_mask);  sigaction(SIGVTALRM, &a, NULL);  value.it_value.tv_sec = 0;  value.it_value.tv_usec = 256000/frame.rate;  value.it_interval.tv_sec = 0;  value.it_interval.tv_usec = 256000/frame.rate;  setitimer(ITIMER_VIRTUAL, &value, NULL);  while(! quit) {    DFBWindowEvent evt;    while(events->GetEvent(events, DFB_EVENT(&evt)) == DFB_OK) {      switch(evt.type) {        case DWET_KEYDOWN:          if(evt.key_symbol == DIKS_ESCAPE)            quit = 1;          break;        case DWET_MOTION:          frame.render->mouse_x = evt.cx;          frame.render->mouse_y = evt.cy;          break;        default:          break;      }    } /**GetEvent*/  }error:  if(frame.render->cr)    cairo_destroy(frame.render->cr);  if(events)    events->Release(events);  if(cairo_surface)    cairo_surface->Release(cairo_surface);  if(layer)    layer->Release(layer);  if(window)    window->Release(window);  if(dfb)    dfb->Release(dfb);  return 0;}

⌨️ 快捷键说明

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