Example #1
0
sound::InputStream*
Sound_as::attachAuxStreamerIfNeeded()
{
    media::AudioInfo* audioInfo =  _mediaParser->getAudioInfo();
    if (!audioInfo) return 0;

    // the following may throw an exception
    _audioDecoder.reset(_mediaHandler->createAudioDecoder(*audioInfo).release());

    // start playing ASAP, a call to ::start will just change _startTime
#ifdef GNASH_DEBUG_SOUND_AS
    log_debug("Attaching the aux streamer");
#endif
    return _soundHandler->attach_aux_streamer(getAudioWrapper, (void*) this);
}
Example #2
0
void
Sound_as::probeAudio()
{
#ifdef USE_SOUND
    if ( ! externalSound ) {
        // Only probe for sound complete
        assert(_soundHandler);
        assert(!_soundCompleted);
        if (!_soundHandler->isSoundPlaying(soundId)) {
            stopProbeTimer();
            // dispatch onSoundComplete 
            callMethod(&owner(), NSV::PROP_ON_SOUND_COMPLETE);
        }
        return;
    }

    if (!_mediaParser) return; // nothing to do here w/out a media parser

    if ( ! _soundLoaded ) {
#ifdef GNASH_DEBUG_SOUND_AS
        log_debug("Probing audio for load");
#endif
        if (_mediaParser->parsingCompleted()) {

            _soundLoaded = true;

            if (!isStreaming) {
                stopProbeTimer(); // will be re-started on Sound.start()
            }
            bool success = _mediaParser->getAudioInfo() != 0;
            callMethod(&owner(), NSV::PROP_ON_LOAD, success);

            // TODO: check if this should be called anyway.
            if (success) handleId3Data(_mediaParser->getId3Info(), owner());
        }

        // If this is an event sound, we are done. Otherwise, if there is
        // any data available, we should start playback.
        if (!isStreaming || _mediaParser->isBufferEmpty()) {
            return; 
        }
    }

    if (isAttached()) {
#ifdef GNASH_DEBUG_SOUND_AS
        log_debug("Probing audio for end");
#endif

        boost::mutex::scoped_lock lock(_soundCompletedMutex);
        if (_soundCompleted) {
            // when _soundCompleted is true we're NOT attached !
            // MediaParser may be still needed,
            // if this is a non-streaming sound
            if ( isStreaming ) {
                _mediaParser.reset(); // no use for this anymore...
            }
            _inputStream = 0;
            _soundCompleted = false;
            stopProbeTimer();

            // dispatch onSoundComplete 
            callMethod(&owner(), NSV::PROP_ON_SOUND_COMPLETE);
        }
    }
    else {
#ifdef GNASH_DEBUG_SOUND_AS
        log_debug("Probing audio for start");
#endif

        bool parsingCompleted = _mediaParser->parsingCompleted();
        try {
            log_debug("Attaching aux streamer");
            _inputStream = attachAuxStreamerIfNeeded();
        } 
        catch (const MediaException& e) {
            assert(!_inputStream);
            assert(!_audioDecoder.get());
            log_error(_("Could not create audio decoder: %s"), e.what());
            _mediaParser.reset(); // no use for this anymore...
            stopProbeTimer();
            return;
        }

        if ( ! _inputStream ) {
            if ( parsingCompleted ) {
                log_error(_("No audio in Sound input."));
                stopProbeTimer();
                _mediaParser.reset(); // no use for this anymore...
            } else {
                // keep probing
            }
        } else {
            // An audio decoder was constructed, good!
            assert(_audioDecoder.get());
        }
    }
#endif  // USE_SOUND
}