big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / EmbeddedSoundTest.c
blobd74e16ef7cd3cf80751100b92bebc4bdeb87b072
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 * 2011 Free Software Foundation, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <ming.h>
24 #include <errno.h>
26 #include "ming_utils.h"
28 #define OUTPUT_VERSION 8
29 #define OUTPUT_FILENAME "EmbeddedSoundTest.swf"
31 void addSoundExport(SWFMovie mo);
33 void
34 addSoundExport(SWFMovie mo)
36 SWFSound soundMP3a;
37 SWFSound soundMP3b;
38 SWFSound soundMP3c;
39 SWFSound soundMP3d;
41 FILE* f;
42 FILE* f2;
44 f = fopen(MEDIADIR"/mono44.mp2", "r");
46 if (!f)
48 perror(MEDIADIR"/mono44.mp2");
49 exit(EXIT_FAILURE);
51 soundMP3a = newSWFSound(f, SWF_SOUND_MP3_COMPRESSED |
52 SWF_SOUND_44KHZ |
53 SWF_SOUND_16BITS |
54 SWF_SOUND_MONO);
56 soundMP3b = newSWFSound(f, SWF_SOUND_MP3_COMPRESSED |
57 SWF_SOUND_22KHZ |
58 SWF_SOUND_16BITS |
59 SWF_SOUND_STEREO);
62 f2 = fopen(MEDIADIR"/stereo8.mp3", "r");
63 if (f2 == NULL)
65 perror(MEDIADIR"/stereo8.mp3");
66 exit(EXIT_FAILURE);
69 soundMP3c = newSWFSound(f2, SWF_SOUND_MP3_COMPRESSED |
70 SWF_SOUND_44KHZ |
71 SWF_SOUND_16BITS |
72 SWF_SOUND_MONO);
74 soundMP3d = newSWFSound(f2, SWF_SOUND_MP3_COMPRESSED |
75 SWF_SOUND_5KHZ |
76 SWF_SOUND_16BITS |
77 SWF_SOUND_STEREO);
79 SWFMovie_addExport(mo, (SWFBlock)soundMP3a, "mono22_mp2");
80 SWFMovie_addExport(mo, (SWFBlock)soundMP3b, "mono22_mp2b");
81 SWFMovie_addExport(mo, (SWFBlock)soundMP3c, "stereo8_mp3");
82 SWFMovie_addExport(mo, (SWFBlock)soundMP3d, "stereo8_mp3b");
84 SWFMovie_writeExports(mo);
87 int
88 main(int argc, char** argv)
90 SWFMovie mo;
91 const char *srcdir=".";
92 SWFMovieClip dejagnuclip;
93 SWFDisplayItem it;
96 /*********************************************
98 * Initialization
100 *********************************************/
102 if ( argc>1 ) srcdir=argv[1];
103 else
105 fprintf(stderr, "Usage: %s\n", argv[0]);
106 return 1;
109 puts("Setting things up");
111 Ming_init();
112 Ming_useSWFVersion (OUTPUT_VERSION);
113 Ming_setScale(20.0); /* let's talk pixels */
115 mo = newSWFMovie();
116 SWFMovie_setRate(mo, 1.33);
117 SWFMovie_setDimension(mo, 640, 400);
119 /*********************************************
121 * Body
123 *********************************************/
125 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 80, 800, 600);
126 it = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
127 addSoundExport(mo);
129 SWFMovie_nextFrame(mo); /* end of frame1 */
131 // Tracker variables for calls to onSoundComplete
132 add_actions(mo, "c_soundComplete = 0;");
133 add_actions(mo, "d_soundComplete = 0;");
134 add_actions(mo, "e_soundComplete = 0;");
136 add_actions(mo, "a = new Sound();");
137 check_equals(mo, "a.duration", "undefined");
138 add_actions(mo, "a.attachSound('mono22_mp2');");
139 check_equals(mo, "a.duration", "13740");
141 add_actions(mo, "b = new Sound(); b.attachSound('mono22_mp2b');");
142 add_actions(mo, "c = new Sound(); c.attachSound('stereo8_mp3');");
144 // Two different Sounds with the same exported sound.
145 add_actions(mo, "d = new Sound(); d.attachSound('stereo8_mp3b');");
146 add_actions(mo, "e = new Sound(); e.attachSound('stereo8_mp3b');");
148 add_actions(mo, "check_equals(a.getBytesTotal(), undefined);");
149 add_actions(mo, "check_equals(a.getBytesLoaded(), undefined);");
150 add_actions(mo, "check_equals(a.id3, undefined);");
151 check_equals(mo, "a.position", "0");
152 add_actions(mo, "a.start();");
153 // This isn't very consistent either. Please re-enable when it is.
154 //check_equals(mo, "a.position", "0");
156 check_equals(mo, "b.duration", "13740");
157 check_equals(mo, "b.position", "0");
158 add_actions(mo, "b.start();");
160 // Here, gst gives 46, ffmpeg 0.
161 //check_equals(mo, "b.position", "0");
163 check_equals(mo, "c.duration", "5224");
164 check_equals(mo, "c.position", "0");
165 // Play twice (loop).
166 add_actions(mo, "c.start(0, 2);");
167 check_equals(mo, "c.position", "0");
169 check_equals(mo, "d.duration", "5224");
170 check_equals(mo, "d.position", "0");
171 // Start twice.
172 add_actions(mo, "d.start();");
173 add_actions(mo, "d.start(4);");
174 check_equals(mo, "d.position", "0");
176 add_actions(mo, "e.start();");
178 SWFMovie_nextFrame(mo);
180 add_actions(mo, "stop();"
181 "note('will wait for onSoundComplete to finish the test (about "
182 "13 seconds).');");
184 // This is the longest sound, so the test should end when this is called.
185 add_actions(mo, "a.onSoundComplete = function() {"
186 "check_equals(arguments.length, 0);"
187 "check_equals(a.position, 13740, 'a.position at a.onSoundComplete time');"
188 "check_equals(c_soundComplete, 1, 'c_soundComplete at a.onSoundComplete time');"
189 "check_equals(d_soundComplete, 1, 'd_soundComplete at a.onSoundComplete time');"
190 "check_equals(e_soundComplete, 2, 'e_soundComplete at a.onSoundComplete time');"
191 "totals(26); "
192 "finished = true;"
193 "};");
195 // Check position of b, c, d, and e after the first loop of c.
196 add_actions(mo, "c.onSoundComplete = function() {"
197 // I'm not sure how reliable this is:
198 "check_equals(b.position, 10472, 'b.position at c.onSoundComplete time');"
199 "check_equals(c.position, 5224, 'c.position at c.onSoundComplete time');"
200 "check_equals(d.position, 5224, 'd.position at c.onSoundComplete time');"
201 "check_equals(e.position, 5224, 'e.position at c.onSoundComplete time');"
202 "c_soundComplete++;"
203 "note('c.onSoundComplete() called '+c_soundComplete+' time(s).');"
204 "};");
206 add_actions(mo, "d.onSoundComplete = function() {"
207 "check_equals(d.position, 5224, 'd.position at d.onSoundComplete time');"
208 "d_soundComplete++;"
209 "note('d.onSoundComplete() called '+d_soundComplete+' time(s).');"
210 "};");
212 // This starts e again. It should run twice before the longest
213 // sound stops.
214 add_actions(mo, "e.onSoundComplete = function() {"
215 "check_equals(e.position, 5224, 'e.position at e.onSoundComplete time');"
216 "e_soundComplete++;"
217 "note('e.onSoundComplete() called '+e_soundComplete+' time(s).');"
218 "if ( e_soundComplete < 2 ) e.start();"
219 "};");
222 /*****************************************************
224 * Output movie
226 *****************************************************/
228 puts("Saving " OUTPUT_FILENAME );
230 SWFMovie_save(mo, OUTPUT_FILENAME);
232 return 0;