1 /*
2 * by kf701 2008-08-25
3 *
4 * test for swfdec 0.6.8
5 */
6
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 #include
21 #include
22 #include
23 #include
24 #include
25 #include
26 #include
27 #include
28
29 int dlp_width, dlp_height;
30
31 int has_fb = 1, has_oss = 1;
32
33 int main(int argc, char **argv)
34 {
35 int fps = 15;
36 int width = 320, height = 240;
37 int blk_size = 0;
38 long diff, sleep_time;
39 SwfdecPlayer *player;
40 unsigned char *imgbuf, *sbuf;
41 cairo_surface_t *surface;
42 cairo_t *cr;
43
44 if( argc < 2 )
45 {
46 printf("Usage: swf-player xxxx.swf\n");
47 exit(0);
48 }
49
50 swfdec_init ();
51
52 SwfdecURL *url = swfdec_url_new_from_input( argv[1] );
53 player = swfdec_player_new( NULL );
54 swfdec_player_set_url (player, url);
55 swfdec_url_free (url);
56
57 diff = swfdec_player_get_next_event (player);
58 while (diff >= 0 && !swfdec_player_is_initialized (player))
59 {
60 swfdec_player_advance (player, diff);
61 diff = swfdec_player_get_next_event (player);
62 }
63
64 fps = swfdec_player_get_rate( player );
65 swfdec_player_get_default_size (player, &width, &height);
66
67 printf("fps: %d, width: %d, height: %d\n", fps, width, height);
68
69 dlp_width = width;
70 dlp_height = height;
71
72 if( fb_init() < 0 )
73 {
74 has_fb = 0;
75 printf("fb_init error\n");
76 }
77
78 if( oss_init() < 0 )
79 {
80 has_oss = 0;
81 printf("oss init error\n");
82 }
83
84 imgbuf = malloc( width*height*4 );
85 memset( imgbuf, 0, width*height*4 );
86 surface = cairo_image_surface_create_for_data (imgbuf, CAIRO_FORMAT_ARGB32, width, height, width*4);
87 cr = cairo_create (surface);
88
89 sleep_time = 1000000 / fps;
90
91 while(1)
92 {
93 diff = swfdec_player_get_next_event(player);
94 swfdec_player_advance(player, diff);
95 swfdec_player_render(player, cr, 0, 0, width, height);
96
97 if( has_fb )
98 fb_display( imgbuf );
99
100 if( has_oss )
101 {
102 blk_size = oss_get_size();
103 if( blk_size > 0 )
104 {
105 sbuf = malloc( blk_size );
106 memset( sbuf, 0, blk_size );
107 swfdec_player_render_audio(player, sbuf, 0, blk_size/4);
108 oss_write( sbuf, blk_size );
109 free( sbuf );
110 }
111 }
112
113 usleep( sleep_time );
114 }
115
116 return 0;
117 }
阅读(2485) | 评论(0) | 转发(0) |