13 #define CHUNK_SIZE 4096
15 int main (int argc
, char **argv
)
17 char *fname
= "stream.ogg";
21 TarkinStream
*tarkin_stream
;
31 SDL_Surface
* vid_surface
= NULL
;
35 TarkinVideoLayerDesc
*layer
;
39 } else if (argc
!= 1) {
40 printf ("\n usage: %s <tarkin_stream>\n\n", argv
[0]);
44 if ((fd
= open (fname
, O_RDONLY
)) < 0) {
45 printf ("error opening '%s'\n", fname
);
50 if (SDL_Init(SDL_INIT_VIDEO
)) {
54 tarkin_stream
= tarkin_stream_new (fd
);
56 ogg_stream_init(&os
,1);
57 tarkin_info_init(&ti
);
58 tarkin_comment_init(&tc
);
60 buffer
= ogg_sync_buffer(&oy
, CHUNK_SIZE
);
61 if((nread
= read(fd
, buffer
, CHUNK_SIZE
))>0)
62 ogg_sync_wrote(&oy
, nread
);
64 ogg_sync_wrote(&oy
,0);
66 if(ogg_sync_pageout(&oy
,&og
)){
67 ogg_stream_pagein(&os
,&og
);
68 while(ogg_stream_packetout(&os
,&op
)){
71 if(nheader
<3){ /* 3 first packets to headerin */
72 tarkin_synthesis_headerin(&ti
, &tc
, &op
);
74 tarkin_synthesis_init(tarkin_stream
, &ti
);
78 tarkin_synthesis_packetin(tarkin_stream
, &op
);
79 while(tarkin_synthesis_frameout(tarkin_stream
, &rgb
, 0, &date
)==0){
80 layer
= &tarkin_stream
->layer
->desc
;
82 // if SDL_initialized != true, init sdl stuff
86 printf("initializing sdl surface...");
88 if ((vid_surface
= SDL_SetVideoMode(layer
->width
, layer
->height
, 24, SDL_SWSURFACE
)) == NULL
) {
89 tarkin_synthesis_freeframe(tarkin_stream
, rgb
);
90 tarkin_stream_destroy (tarkin_stream
);
96 if (SDL_MUSTLOCK(vid_surface
))
97 SDL_LockSurface(vid_surface
);
99 memcpy(vid_surface
->pixels
, rgb
, layer
->width
* layer
->height
* 3); //...
101 if (SDL_MUSTLOCK(vid_surface
))
102 SDL_UnlockSurface(vid_surface
);
104 SDL_UpdateRect(vid_surface
, 0, 0, 0, 0);
106 sk : removed this stuff
107 snprintf(ofname, 11, layer->format == TARKIN_GRAYSCALE ? "out%03d.pgm" : "out%03d.ppm", frame);
108 printf ("write '%s' %dx%d\n", ofname, layer->width, layer->height);
109 write_pnm (ofname, rgb, layer->width, layer->height);
111 tarkin_synthesis_freeframe(tarkin_stream
, rgb
);
121 tarkin_stream_destroy (tarkin_stream
);