big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / Video-EmbedSquareTest.c
blob1fea05adaa9ad9afe181e36cb6c10eacfffb8042
1 /*
2 * Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
20 * Plays video stored internal in the SWF.
21 * Should be used with the MovieTester to test if the video decoder works.
23 * TODO:
25 * Test all codecs:
27 * - VIDEO_CODEC_H263 (id: 2) [ in square.flv ]
28 * - VIDEO_CODEC_SCREEN (id: 3)
29 * - VIDEO_CODEC_VP6 (id: 4)
30 * - VIDEO_CODEC_VP6A (id: 5)
31 * - VIDEO_CODEC_SCREEN2 (id: 6)
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <ming.h>
41 #include "ming_utils.h"
43 #define OUTPUT_VERSION 7
44 #define OUTPUT_FILENAME "Video-EmbedSquareTest.swf"
46 const char* mediadir=".";
48 int
49 main(int argc, char** argv)
51 SWFMovie mo;
52 int frames;
53 SWFVideoStream stream;
54 SWFDisplayItem item;
55 SWFMovieClip dejagnuclip;
56 FILE *flv, *font_file;
57 SWFFont font;
58 char filename[256];
59 char fdbfont[1024];
61 if ( argc>1 ) mediadir=argv[1];
62 else
64 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
65 return 1;
69 sprintf(filename, "%s/square.flv", mediadir);
70 flv = fopen(filename, "rb");
71 if (flv == NULL) {
72 perror(filename);
73 return -1;
76 sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", mediadir);
77 font_file = fopen(fdbfont, "r");
78 if ( font_file == NULL )
80 perror(fdbfont);
81 exit(1);
84 Ming_init();
85 Ming_useSWFVersion (OUTPUT_VERSION);
87 font = loadSWFFontFromFile(font_file);
89 mo = newSWFMovie();
90 SWFMovie_setDimension(mo, 320, 96);
92 if (mo == NULL) return -1;
94 SWFMovie_setRate(mo, 5);
96 dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 200, 200);
97 item = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
98 SWFDisplayItem_setDepth(item, 200);
99 SWFDisplayItem_move(item, 140, 0);
101 stream = newSWFVideoStream_fromFile(flv);
102 item = SWFMovie_add(mo, (SWFBlock)stream);
103 SWFDisplayItem_setName(item, "vid");
105 // A bug in Ming prevents this from working the
106 // way I liked it to. It was useful to try this
107 // out as it exposed a bad bug in gnash eating up
108 // all memory and a few other issues.
110 // In order to keep the test *runner* untouched
111 // this will be commented out for now. When Ming
112 // is fixed I'll like to have two instances of
113 // the definition playing one near the other,
114 // both playing all frames.
116 //item = SWFMovie_add(mo, (SWFBlock)stream);
117 //SWFDisplayItem_move(item, 150, 0);
119 // Mouse clicks toggle play/stop
120 add_actions(mo,
121 "_root.onMouseDown = function() {"
122 " if (stopped) { play(); stopped=false; }"
123 " else { stop(); stopped=true; }"
124 "};");
126 // Pressing a number jumps to the specified frame
127 add_actions(mo,
128 "_root.onKeyDown = function() {"
129 " var fnum = Key.getAscii() - 47;"
130 //" trace('going to frame '+fnum);"
131 " _root.gotoAndPlay(fnum);"
132 "}; Key.addListener(_root);");
134 // TODO: dynamic frame rate adjust
135 frames = SWFVideoStream_getNumFrames(stream);
136 for(; frames > 0; frames--)
138 SWFMovie_nextFrame(mo);
141 /// Video.clear() should not work on embedded Videos.
142 add_actions(mo, "stop(); vid.clear(); trace(vid);");
143 add_actions(mo, "note('You should still see the video frame."
144 " Click to replay');"
145 "o = {};"
146 "o.onMouseDown = function() { _root.play(); };"
147 "Mouse.addListener(o);"
150 SWFMovie_nextFrame(mo);
152 //Output movie
153 puts("Saving " OUTPUT_FILENAME );
154 SWFMovie_save(mo, OUTPUT_FILENAME);
156 return 0;