~ubuntu-branches/ubuntu/karmic/gnash/karmic

« back to all changes in this revision

Viewing changes to utilities/processor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2008-10-13 14:29:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081013142949-f6qdvnu4mn05ltdc
Tags: 0.8.4~~bzr9980-0ubuntu1
* new upstream release 0.8.4 (LP: #240325)
* ship new lib usr/lib/gnash/libmozsdk.so.* in mozilla-plugin-gnash
  - update debian/mozilla-plugin-gnash.install
* ship new lib usr/lib/gnash/libgnashnet.so.* in gnash-common
  - update debian/gnash-common.install
* add basic debian/build_head script to build latest CVS head packages.
  - add debian/build_head
* new sound architecture requires build depend on libsdl1.2-dev
  - update debian/control
* head build script now has been completely migrated to bzr (upstream +
  ubuntu)
  - update debian/build_head
* disable kde gui until klash/qt4 has been fixed; keep kde packages as empty
  packages for now.
  - update debian/rules
  - debian/klash.install
  - debian/klash.links
  - debian/klash.manpages
  - debian/konqueror-plugin-gnash.install
* drop libkonq5-dev build dependency accordingly
  - update debian/control
* don't install headers manually anymore. gnash doesnt provide a -dev
  package after all
  - update debian/rules
* update libs installed in gnash-common; libgnashserver-*.so is not available
  anymore (removed); in turn we add the new libgnashcore-*.so
  - update debian/gnash-common.install
* use -Os for optimization and properly pass CXXFLAGS=$(CFLAGS) to configure
  - update debian/rules
* touch firefox .autoreg in postinst of mozilla plugin
  - update debian/mozilla-plugin-gnash.postinst
* link gnash in ubufox plugins directory for the plugin alternative switcher
  - add debian/mozilla-plugin-gnash.links
* suggest ubufox accordingly
  - update debian/control
* add new required build-depends on libgif-dev
  - update debian/control
* add Xb-Npp-Description and Xb-Npp-File as new plugin database meta data
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
// along with this program; if not, write to the Free Software
17
17
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 
19
 
/* $Id: processor.cpp,v 1.84.2.1 2008/03/03 16:53:25 strk Exp $ */
20
19
 
21
20
#ifdef HAVE_CONFIG_H
22
21
#include "gnashconfig.h"
23
22
#endif
24
23
 
 
24
#include "NullSoundHandler.h"
 
25
 
25
26
#include <iostream>
26
27
#include <cstdio>
 
28
#include <cstdlib>
27
29
#include <sys/time.h>
28
 
#include <time.h>
 
30
#include <ctime>
29
31
 
30
32
#ifdef ENABLE_NLS
31
 
#include <locale.h>
 
33
#include <locale>
32
34
#endif
33
35
 
34
36
#include "gettext.h"
35
 
#include "tu_file.h"
 
37
#include "ClockTime.h"
36
38
#include "gnash.h"
37
39
#include "movie_definition.h"
38
40
#include "sprite_instance.h"
45
47
#include "VM.h"
46
48
#include "noseek_fd_adapter.h"
47
49
#include "ManualClock.h"
48
 
#include "tu_timer.h"
 
50
#include "StringPredicates.h"
 
51
#include "smart_ptr.h"
 
52
#include "IOChannel.h" // for proper dtor call
 
53
#include "GnashSleep.h" // for usleep comptibility.
49
54
 
50
55
extern "C"{
51
 
        #include <unistd.h>
52
56
#ifdef HAVE_GETOPT_H
53
57
        #include <getopt.h>
54
58
#endif
94
98
 
95
99
struct movie_data
96
100
{
97
 
    gnash::movie_definition*    m_movie;
 
101
    gnash::movie_definition* m_movie;
98
102
    std::string m_filename;
99
103
};
100
104
 
101
 
static gnash::movie_definition* play_movie(const char* filename);
 
105
static boost::intrusive_ptr<gnash::movie_definition>    play_movie(const char* filename);
102
106
 
103
107
static bool s_do_output = false;
104
108
static bool s_stop_on_errors = true;
111
115
void
112
116
resetLastAdvanceTimer()
113
117
{
114
 
        using namespace tu_timer;
115
 
        lastAdvanceTimer = ticks_to_seconds(get_ticks());
 
118
    // clocktime::getTicks() returns milliseconds
 
119
        lastAdvanceTimer = static_cast<double>(clocktime::getTicks()) / 1000.0;
116
120
}
117
121
 
118
122
double
119
123
secondsSinceLastAdvance()
120
124
{
121
 
        using namespace tu_timer;
122
 
        double now = ticks_to_seconds(get_ticks());
 
125
    // clocktime::getTicks() returns milliseconds
 
126
        double now = static_cast<double>(clocktime::getTicks()) / 1000.0;
123
127
        return ( now - lastAdvanceTimer);
124
128
}
125
129
 
128
132
//
129
133
static int quitrequested = false;
130
134
 
131
 
void execFsCommand(sprite_instance* movie, const char* command, const char* args)
132
 
{
133
 
    log_debug(_("fs_callback(%p): %s %s"), (void*)movie, command, args);
134
 
 
135
 
    if ( ! strcasecmp(command, "quit") ) quitrequested=true;
136
 
}
 
135
class FsCommandExecutor: public movie_root::AbstractFsCallback {
 
136
public:
 
137
        void notify(const std::string& command, const std::string& args)
 
138
        {
 
139
            log_debug(_("fs_callback(%p): %s %s"), command, args);
 
140
 
 
141
            StringNoCaseEqual ncasecomp;
 
142
           
 
143
            if ( ncasecomp(command, "quit") ) quitrequested = true;
 
144
        }
 
145
};
 
146
 
 
147
class EventCallback: public movie_root::AbstractIfaceCallback {
 
148
public:
 
149
        std::string call(const std::string& event, const std::string& arg)
 
150
        {
 
151
            log_debug(_("eventCallback: %s %s"), event, arg);
 
152
 
 
153
            static bool mouseShown = true;
 
154
 
 
155
            // These should return "true" if the mouse was visible before
 
156
            // the call.
 
157
            if ( event == "Mouse.hide" ) {
 
158
                bool state = mouseShown;
 
159
                mouseShown = false;
 
160
                return state ? "true" : "false";
 
161
            }
 
162
 
 
163
            if ( event == "Mouse.show" ) {
 
164
                bool state = mouseShown;
 
165
                mouseShown = true;
 
166
                return state ? "true" : "false" ;
 
167
            }
 
168
            
 
169
            // Some fake values for consistent test results.
 
170
            
 
171
            if ( event == "System.capabilities.screenResolutionX" ) {
 
172
                return "800";
 
173
            }
 
174
 
 
175
            if ( event == "System.capabilities.screenResolutionY" ) {
 
176
                return "640";
 
177
            } 
 
178
 
 
179
            if ( event == "System.capabilities.screenDPI" ) {
 
180
                return "72";
 
181
            }        
 
182
 
 
183
            if ( event == "System.capabilities.screenColor" ) {
 
184
                return "Color";
 
185
            } 
 
186
 
 
187
            if ( event == "System.capabilities.playerType" ) {
 
188
                return "StandAlone";
 
189
            } 
 
190
 
 
191
            return "";
 
192
 
 
193
        }
 
194
};
 
195
 
 
196
EventCallback eventCallback;
 
197
FsCommandExecutor execFsCommand;
137
198
 
138
199
int
139
200
main(int argc, char *argv[])
143
204
 
144
205
    // Enable native language support, i.e. internationalization
145
206
#ifdef ENABLE_NLS
146
 
    setlocale (LC_ALL, "");
 
207
    std::setlocale (LC_ALL, "");
147
208
    bindtextdomain (PACKAGE, LOCALEDIR);
148
209
    textdomain (PACKAGE);
149
210
#endif
164
225
 
165
226
    std::vector<const char*> infiles;
166
227
 
167
 
    RcInitFile& rcfile = RcInitFile::getDefaultInstance();
168
 
    rcfile.loadFiles();
 
228
    //RcInitFile& rcfile = RcInitFile::getDefaultInstance();
 
229
    //rcfile.loadFiles();
169
230
    
170
231
    if (rcfile.verbosityLevel() > 0) {
171
232
        dbglogfile.setVerbosity(rcfile.verbosityLevel());
172
233
    }
 
234
 
 
235
    dbglogfile.setLogFilename(rcfile.getDebugLog());
 
236
 
 
237
    if (rcfile.useWriteLog()) {
 
238
        dbglogfile.setWriteDisk(true);
 
239
    }
173
240
    
174
241
    if (rcfile.useActionDump()) {
175
242
        dbglogfile.setActionDump(true);
220
287
              allowed_end_hits = strtol(optarg, NULL, 0);
221
288
              break;
222
289
          case 'd':
223
 
              delay = atoi(optarg)*1000; // delay is in microseconds
 
290
              delay = strtol(optarg, NULL, 0)*1000; // delay is in microseconds
224
291
              // this will be recognized as a request to run at FPS speed
225
292
              if ( delay < 0 ) delay = -1;
226
293
              break;
252
319
        exit(1);
253
320
    }
254
321
 
255
 
    gnash::set_use_cache_files(false);  // don't load old cache files!
 
322
    std::auto_ptr<media::sound_handler> soundHandler(new media::NullSoundHandler());
 
323
    gnash::set_sound_handler(soundHandler.get());
256
324
        
257
325
    std::vector<movie_data>     data;
258
326
 
265
333
        exit(1);
266
334
    }
267
335
 
268
 
    register_fscommand_callback(execFsCommand);
269
 
 
270
336
    // Play through all the movies.
271
337
    for (int i = 0, n = infiles.size(); i < n; i++) {
272
338
 
273
339
        set_base_url(URL(infiles[i]));
274
340
 
275
 
        gnash::movie_definition*        m = play_movie(infiles[i]);
 
341
        boost::intrusive_ptr<gnash::movie_definition> m = play_movie(infiles[i]);
276
342
        if (m == NULL) {
277
343
            if (s_stop_on_errors) {
278
344
                // Fail.
282
348
        }
283
349
        
284
350
        movie_data      md;
285
 
        md.m_movie = m;
 
351
        md.m_movie = m.get();
286
352
        md.m_filename = std::string(infiles[i]);
287
353
        data.push_back(md);
288
354
    }
302
368
// or build font textures again.
303
369
//
304
370
// Return the movie definition.
305
 
gnash::movie_definition*
 
371
boost::intrusive_ptr<gnash::movie_definition>
306
372
play_movie(const char* filename)
307
373
{
308
 
    gnash::movie_definition* md;
 
374
    boost::intrusive_ptr<gnash::movie_definition> md;
309
375
    try
310
376
    {
311
377
      if ( ! strcmp(filename, "-") )
312
378
      {
313
 
         std::auto_ptr<tu_file> in ( noseek_fd_adapter::make_stream(fileno(stdin)) );
 
379
         std::auto_ptr<IOChannel> in ( noseek_fd_adapter::make_stream(fileno(stdin)) );
314
380
         md = gnash::create_movie(in, filename, false);
315
381
      }
316
382
      else
347
413
    long clockAdvance = fpsDelay/1000;
348
414
    long localDelay = delay == -1 ? fpsDelay : delay; // microseconds
349
415
 
350
 
    printf("Will sleep %ld microseconds between iterations - fps is %g, clockAdvance is %lu\n", localDelay, fps, clockAdvance);
 
416
    log_debug("Will sleep %ld microseconds between iterations - "
 
417
            "fps is %g, clockAdvance is %lu", localDelay, fps, clockAdvance);
351
418
 
352
419
    // Use a clock advanced at every iteration to match exact FPS speed.
353
420
    ManualClock cl;
354
421
    gnash::movie_root& m = VM::init(*md, cl).getRoot();
 
422
    
 
423
    // Register processor to receive ActionScript events (Mouse, Stage
 
424
    // System etc).
 
425
    m.registerEventCallback(&eventCallback);
 
426
    m.registerFSCommandCallback(&execFsCommand);
355
427
 
356
428
    md->completeLoad();
357
429
 
364
436
        return md;
365
437
    }
366
438
 
367
 
    printf("iteration, timer: %lu, localDelay: %ld\n", cl.elapsed(), localDelay);
368
 
    usleep(localDelay);
 
439
    log_debug("iteration, timer: %lu, localDelay: %ld\n",
 
440
            cl.elapsed(), localDelay);
 
441
    gnashSleep(localDelay);
369
442
    
370
443
    resetLastAdvanceTimer();
371
444
    int kick_count = 0;
401
474
        ++nadvances;
402
475
        if ( limit_advances && nadvances >= limit_advances)
403
476
        {
404
 
                printf("exiting after " SIZET_FMT " advances\n", nadvances);
 
477
                log_debug("exiting after %d advances", nadvances);
405
478
                break;
406
479
        }
407
480
 
412
485
        {
413
486
                if ( allowed_end_hits && ++end_hitcount >= allowed_end_hits )
414
487
                {
415
 
                        printf("exiting after " SIZET_FMT 
416
 
                               " times last frame was reached\n", end_hitcount);
 
488
                        log_debug("exiting after %d" 
 
489
                               " times last frame was reached", end_hitcount);
417
490
                        break;
418
491
                }
419
492
        }
453
526
            if ( last_frame > latest_frame ) latest_frame = last_frame;
454
527
            if ( ++loop_back_count > allowloopbacks )
455
528
            {
456
 
                    printf(SIZET_FMT " loop backs; jumping one-after "
457
 
                                    "latest frame (" SIZET_FMT ")\n",
 
529
                    log_debug("%d loop backs; jumping one-after "
 
530
                                    "latest frame (%d)",
458
531
                                    loop_back_count, latest_frame+1);
459
532
                    m.goto_frame(latest_frame + 1);
460
533
                    loop_back_count = 0;
467
540
            resetLastAdvanceTimer();
468
541
        }
469
542
 
470
 
        printf("iteration, timer: %lu, localDelay: %ld\n", cl.elapsed(), localDelay);
471
 
        usleep(localDelay);
 
543
        log_debug("iteration, timer: %lu, localDelay: %ld\n",
 
544
            cl.elapsed(), localDelay);
 
545
    gnashSleep(localDelay);
472
546
    }
473
547
    
474
548
    return md;