Projects
Essentials
lightspark
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 123
View file
lightspark.spec
Changed
@@ -20,7 +20,7 @@ %bcond_without librtmp Name: lightspark -Version: 0.7.2.99+git20161029.1519 +Version: 0.7.2.99+git20161106.1119 Release: 0 Summary: Modern, free, open-source flash player implementation License: LGPL-3.0+
View file
lightspark.tar.xz/src/backends/audio.cpp
Changed
@@ -25,6 +25,7 @@ #include <SDL2/SDL_mixer.h> #include <sys/time.h> +#define LIGHTSPARK_AUDIO_SDL_BUFFERSIZE 8192 using namespace lightspark; using namespace std; @@ -115,9 +116,9 @@ AudioStream::~AudioStream() { - manager->streams.remove(this); if (mixer_channel != -1) Mix_HaltChannel(mixer_channel); + manager->removeStream(this); } AudioManager::AudioManager():muteAllStreams(false),sdl_available(0),mixeropened(0) @@ -131,6 +132,7 @@ } void AudioManager::muteAll() { + Locker l(streamMutex); muteAllStreams = true; for ( stream_iterator it = streams.begin();it != streams.end(); ++it ) { @@ -139,6 +141,7 @@ } void AudioManager::unmuteAll() { + Locker l(streamMutex); muteAllStreams = false; for ( stream_iterator it = streams.begin();it != streams.end(); ++it ) { @@ -146,13 +149,25 @@ } } +void AudioManager::removeStream(AudioStream *s) +{ + Locker l(streamMutex); + streams.remove(s); + if (streams.empty()) + { + Mix_CloseAudio(); + mixeropened = false; + } +} + AudioStream* AudioManager::createStream(AudioDecoder* decoder, bool startpaused) { + Locker l(streamMutex); if (!sdl_available) return NULL; if (!mixeropened) { - if (Mix_OpenAudio (LIGHTSPARK_AUDIO_SDL_SAMPLERATE, AUDIO_S16, 2, LIGHTSPARK_AUDIO_SDL_BUFFERSIZE) < 0) + if (Mix_OpenAudio (MIX_DEFAULT_FREQUENCY, AUDIO_S16, 2, LIGHTSPARK_AUDIO_SDL_BUFFERSIZE) < 0) { LOG(LOG_ERROR,"Couldn't open SDL_mixer"); sdl_available = 0; @@ -180,6 +195,7 @@ AudioManager::~AudioManager() { + Locker l(streamMutex); for (stream_iterator it = streams.begin(); it != streams.end(); ++it) { delete *it; }
View file
lightspark.tar.xz/src/backends/audio.h
Changed
@@ -27,9 +27,6 @@ namespace lightspark { -#define LIGHTSPARK_AUDIO_SDL_BUFFERSIZE 4096 -#define LIGHTSPARK_AUDIO_SDL_SAMPLERATE 44100 - class AudioStream; class AudioManager @@ -41,6 +38,7 @@ int mixeropened; std::list<AudioStream *> streams; typedef std::list<AudioStream *>::iterator stream_iterator; + Mutex streamMutex; public: AudioManager(); @@ -50,9 +48,7 @@ bool allMuted() { return muteAllStreams; } void muteAll(); void unmuteAll(); - int forcedSampleRate() const { return LIGHTSPARK_AUDIO_SDL_SAMPLERATE;} - int forcedChannelLayout() const { return AV_CH_LAYOUT_STEREO;} - + void removeStream(AudioStream* s); ~AudioManager(); };
View file
lightspark.tar.xz/src/backends/decoder.cpp
Changed
@@ -25,6 +25,7 @@ #include "platforms/fastpaths.h" #include "swf.h" #include "backends/rendering.h" +#include "SDL2/SDL_mixer.h" #if LIBAVUTIL_VERSION_MAJOR < 51 #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO @@ -318,7 +319,7 @@ { if(datalen==0) return false; -#if HAVE_AVCODEC_SEND_PACKET && HAVE_AVCODEC_RECEIVE_FRAME +#if defined HAVE_AVCODEC_SEND_PACKET && defined HAVE_AVCODEC_RECEIVE_FRAME AVPacket pkt; av_init_packet(&pkt); pkt.data=data; @@ -378,7 +379,7 @@ bool FFMpegVideoDecoder::decodePacket(AVPacket* pkt, uint32_t time) { -#if HAVE_AVCODEC_SEND_PACKET && HAVE_AVCODEC_RECEIVE_FRAME +#if defined HAVE_AVCODEC_SEND_PACKET && defined HAVE_AVCODEC_RECEIVE_FRAME int ret = avcodec_send_packet(codecContext, pkt); while (ret == 0) { @@ -570,6 +571,9 @@ #ifdef ENABLE_LIBAVCODEC FFMpegAudioDecoder::FFMpegAudioDecoder(LS_AUDIO_CODEC audioCodec, uint8_t* initdata, uint32_t datalen):ownedContext(true) +#ifdef HAVE_LIBAVRESAMPLE + ,resamplecontext(NULL) +#endif { switchCodec(audioCodec,initdata,datalen); #if HAVE_AVCODEC_DECODE_AUDIO4 @@ -580,6 +584,10 @@ { if (codecContext) avcodec_close(codecContext); +#ifdef HAVE_LIBAVRESAMPLE + if (resamplecontext) + avresample_free(&resamplecontext); +#endif AVCodec* codec=avcodec_find_decoder(LSToFFMpegCodec(audioCodec)); assert(codec); @@ -609,6 +617,9 @@ } FFMpegAudioDecoder::FFMpegAudioDecoder(LS_AUDIO_CODEC lscodec, int sampleRate, int channels, bool):ownedContext(true) +#ifdef HAVE_LIBAVRESAMPLE + ,resamplecontext(NULL) +#endif { status=INIT; @@ -629,13 +640,16 @@ if(fillDataAndCheckValidity()) status=VALID; -#if HAVE_AVCODEC_DECODE_AUDIO4 +#ifdef HAVE_AVCODEC_DECODE_AUDIO4 frameIn=av_frame_alloc(); #endif } #if LIBAVFORMAT_VERSION_MAJOR > 56 FFMpegAudioDecoder::FFMpegAudioDecoder(AVCodecID codecID):ownedContext(true),codecContext(NULL) +#ifdef HAVE_LIBAVRESAMPLE + ,resamplecontext(NULL) +#endif { status=INIT; AVCodec* codec=avcodec_find_decoder(codecID); @@ -655,12 +669,15 @@ if(fillDataAndCheckValidity()) status=VALID; -#if HAVE_AVCODEC_DECODE_AUDIO4 +#ifdef HAVE_AVCODEC_DECODE_AUDIO4 frameIn=av_frame_alloc(); #endif } #else FFMpegAudioDecoder::FFMpegAudioDecoder(AVCodecContext* _c):ownedContext(false),codecContext(_c) +#ifdef HAVE_LIBAVRESAMPLE + ,resamplecontext(NULL) +#endif { status=INIT; AVCodec* codec=avcodec_find_decoder(codecContext->codec_id); @@ -689,6 +706,10 @@ #if HAVE_AVCODEC_DECODE_AUDIO4 av_free(frameIn); #endif +#ifdef HAVE_LIBAVRESAMPLE + if (resamplecontext) + avresample_free(&resamplecontext); +#endif } CodecID FFMpegAudioDecoder::LSToFFMpegCodec(LS_AUDIO_CODEC LSCodec) @@ -737,7 +758,7 @@ uint32_t FFMpegAudioDecoder::decodeData(uint8_t* data, int32_t datalen, uint32_t time) { -#if HAVE_AVCODEC_SEND_PACKET && HAVE_AVCODEC_RECEIVE_FRAME +#if defined HAVE_AVCODEC_SEND_PACKET && defined HAVE_AVCODEC_RECEIVE_FRAME AVPacket pkt; av_init_packet(&pkt); @@ -801,7 +822,7 @@ #else FrameSamples& curTail=samplesBuffer.acquireLast(); int maxLen=AVCODEC_MAX_AUDIO_FRAME_SIZE; -#if HAVE_AVCODEC_DECODE_AUDIO3 || HAVE_AVCODEC_DECODE_AUDIO4 +#if defined HAVE_AVCODEC_DECODE_AUDIO3 || defined HAVE_AVCODEC_DECODE_AUDIO4 AVPacket pkt; av_init_packet(&pkt); @@ -822,7 +843,7 @@ pkt.size = combinedBuffer.size(); overflowBuffer.clear(); } -#if HAVE_AVCODEC_DECODE_AUDIO4 +#ifdef HAVE_AVCODEC_DECODE_AUDIO4 av_frame_unref(frameIn); int frameOk=0; int32_t ret=avcodec_decode_audio4(codecContext, frameIn, &frameOk, &pkt); @@ -869,7 +890,7 @@ uint32_t FFMpegAudioDecoder::decodePacket(AVPacket* pkt, uint32_t time) { -#if HAVE_AVCODEC_SEND_PACKET && HAVE_AVCODEC_RECEIVE_FRAME +#if defined HAVE_AVCODEC_SEND_PACKET && defined HAVE_AVCODEC_RECEIVE_FRAME av_frame_unref(frameIn); int ret = avcodec_send_packet(codecContext, pkt); int maxLen = 0; @@ -943,12 +964,13 @@ return maxLen; #endif } -#if HAVE_AVCODEC_DECODE_AUDIO4 || (HAVE_AVCODEC_SEND_PACKET && HAVE_AVCODEC_RECEIVE_FRAME) +#if defined HAVE_AVCODEC_DECODE_AUDIO4 || (defined HAVE_AVCODEC_SEND_PACKET && defined HAVE_AVCODEC_RECEIVE_FRAME) int FFMpegAudioDecoder::resampleFrameToS16(FrameSamples& curTail) { - int sample_rate = getSys()->audioManager->forcedSampleRate() == -1 ? codecContext->sample_rate : getSys()->audioManager->forcedSampleRate(); - unsigned int channel_layout = getSys()->audioManager->forcedChannelLayout() == -1 ? frameIn->channel_layout : getSys()->audioManager->forcedChannelLayout(); - if(frameIn->format == AV_SAMPLE_FMT_S16 && sample_rate == codecContext->sample_rate && channel_layout == frameIn->channel_layout) + int sample_rate = MIX_DEFAULT_FREQUENCY; + unsigned int channel_layout = AV_CH_LAYOUT_STEREO; + int framesamplerate = av_frame_get_sample_rate(frameIn); + if(frameIn->format == AV_SAMPLE_FMT_S16 && sample_rate == framesamplerate && channel_layout == frameIn->channel_layout) { //This is suboptimal but equivalent to what libavcodec //does for the compatibility version of avcodec_decode_audio3 @@ -957,22 +979,25 @@ } int maxLen; #ifdef HAVE_LIBAVRESAMPLE - AVAudioResampleContext * avr = avresample_alloc_context(); - av_opt_set_int(avr, "in_channel_layout", frameIn->channel_layout, 0); - av_opt_set_int(avr, "out_channel_layout", channel_layout, 0); - av_opt_set_int(avr, "in_sample_rate", codecContext->sample_rate, 0); - av_opt_set_int(avr, "out_sample_rate", sample_rate, 0); - av_opt_set_int(avr, "in_sample_fmt", frameIn->format, 0); - av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); - avresample_open(avr); + if (!resamplecontext) + { + resamplecontext = avresample_alloc_context(); + av_opt_set_int(resamplecontext, "in_channel_layout", frameIn->channel_layout, 0); + av_opt_set_int(resamplecontext, "out_channel_layout", channel_layout, 0); + av_opt_set_int(resamplecontext, "in_sample_rate", framesamplerate, 0); + av_opt_set_int(resamplecontext, "out_sample_rate", sample_rate, 0); + av_opt_set_int(resamplecontext, "in_sample_fmt", frameIn->format, 0); + av_opt_set_int(resamplecontext, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); + avresample_open(resamplecontext); + } uint8_t *output; int out_linesize; - int out_samples = avresample_available(avr) + av_rescale_rnd(avresample_get_delay(avr) + frameIn->linesize[0], sample_rate, sample_rate, AV_ROUND_UP); + int out_samples = avresample_available(resamplecontext) + av_rescale_rnd(avresample_get_delay(resamplecontext) + frameIn->linesize[0], sample_rate, sample_rate, AV_ROUND_UP); int res = av_samples_alloc(&output, &out_linesize, frameIn->nb_samples, out_samples, AV_SAMPLE_FMT_S16, 0); if (res >= 0) { - maxLen = avresample_convert(avr, &output, out_linesize, out_samples, frameIn->extended_data, frameIn->linesize[0], frameIn->nb_samples)*2*av_get_channel_layout_nb_channels(channel_layout); // 2 bytes in AV_SAMPLE_FMT_S16 + maxLen = avresample_convert(resamplecontext, &output, out_linesize, out_samples, frameIn->extended_data, frameIn->linesize[0], frameIn->nb_samples)*2*av_get_channel_layout_nb_channels(channel_layout); // 2 bytes in AV_SAMPLE_FMT_S16 memcpy(curTail.samples, output, maxLen); av_freep(&output); } @@ -982,8 +1007,6 @@ memset(curTail.samples, 0, frameIn->linesize[0]); maxLen = frameIn->linesize[0]; } - - avresample_free(&avr); #else
View file
lightspark.tar.xz/src/backends/decoder.h
Changed
@@ -61,6 +61,15 @@ // "Audio coding formats" from Chapter 11 in SWF documentation enum LS_AUDIO_CODEC { CODEC_NONE=-1, LINEAR_PCM_PLATFORM_ENDIAN=0, ADPCM=1, MP3=2, LINEAR_PCM_LE=3, AAC=10 }; +class AudioFormat +{ +public: + AudioFormat(LS_AUDIO_CODEC co, int sr, int ch):codec(co),sampleRate(sr),channels(ch) {} + LS_AUDIO_CODEC codec; + int sampleRate; + int channels; +}; + class Decoder { protected: @@ -305,10 +314,13 @@ private: bool ownedContext; AVCodecContext* codecContext; +#ifdef HAVE_LIBAVRESAMPLE + AVAudioResampleContext* resamplecontext; +#endif std::vector<uint8_t> overflowBuffer; bool fillDataAndCheckValidity(); CodecID LSToFFMpegCodec(LS_AUDIO_CODEC lscodec); -#if HAVE_AVCODEC_DECODE_AUDIO4 +#ifdef HAVE_AVCODEC_DECODE_AUDIO4 AVFrame* frameIn; int resampleFrameToS16(FrameSamples& curTail); #endif @@ -330,7 +342,6 @@ uint32_t decodePacket(AVPacket* pkt, uint32_t time); void switchCodec(LS_AUDIO_CODEC audioCodec, uint8_t* initdata, uint32_t datalen); uint32_t decodeData(uint8_t* data, int32_t datalen, uint32_t time); - uint32_t decodeStreamSomePackets(std::istream& s, uint32_t time, IThreadJob *callingthread); }; #endif @@ -363,7 +374,7 @@ FFMpegAudioDecoder* customAudioDecoder; FFMpegVideoDecoder* customVideoDecoder; //Helpers for custom I/O of libavformat - uint8_t avioBuffer[4096]; + uint8_t* avioBuffer; static int avioReadPacket(void* t, uint8_t* buf, int buf_size); //NOTE: this will become AVIOContext in FFMpeg 0.7 #if LIBAVUTIL_VERSION_MAJOR < 51 @@ -371,8 +382,9 @@ #else AVIOContext* avioContext; #endif + int availablestreamlength; public: - FFMpegStreamDecoder(std::istream& s); + FFMpegStreamDecoder(std::istream& s, AudioFormat* format = NULL, int streamsize = -1); ~FFMpegStreamDecoder(); bool decodeNextFrame(); };
View file
lightspark.tar.xz/src/scripting/flash/display/flashdisplay.cpp
Changed
@@ -2011,10 +2011,7 @@ if(it1==th->dynamicDisplayList.end() || it2==th->dynamicDisplayList.end()) throw Class<ArgumentError>::getInstanceS(obj->getSystemState(),"Argument is not child of this object", 2025); - th->dynamicDisplayList.insert(it1, child2); - th->dynamicDisplayList.insert(it2, child1); - th->dynamicDisplayList.erase(it1); - th->dynamicDisplayList.erase(it2); + std::iter_swap(it1, it2); } return NULL;
View file
lightspark.tar.xz/src/scripting/flash/media/flashmedia.cpp
Changed
@@ -464,10 +464,7 @@ void SoundChannel::execute() { - if (format.codec == CODEC_NONE) - playStream(); - else - playRaw(); + playStream(); } void SoundChannel::playStream() @@ -475,7 +472,7 @@ assert(!stream.isNull()); std::streambuf *sbuf = stream->createReader(); istream s(sbuf); - s.exceptions ( istream::eofbit | istream::failbit | istream::badbit ); + s.exceptions ( istream::failbit | istream::badbit ); bool waitForFlush=true; StreamDecoder* streamDecoder=NULL; @@ -483,7 +480,7 @@ try { #ifdef ENABLE_LIBAVCODEC - streamDecoder=new FFMpegStreamDecoder(s); + streamDecoder=new FFMpegStreamDecoder(s,&format,stream->hasTerminated() ? stream->getReceivedLength() : -1); if(!streamDecoder->isValid()) threadAbort(); @@ -497,7 +494,7 @@ audioDecoder=streamDecoder->audioDecoder; if(audioStream==NULL && audioDecoder && audioDecoder->isValid()) - audioStream=getSys()->audioManager->createStream(audioDecoder,false); + audioStream=getSystemState()->audioManager->createStream(audioDecoder,false); // TODO: check the position only when the getter is called if(audioStream) @@ -548,45 +545,6 @@ } } -void SoundChannel::playRaw() -{ - assert(!stream.isNull()); -#ifdef ENABLE_LIBAVCODEC - FFMpegAudioDecoder *decoder = new FFMpegAudioDecoder(format.codec, - format.sampleRate, - format.channels, - true); - if (!decoder) - return; - - AudioStream *audioStream = NULL; - std::streambuf *sbuf = stream->createReader(); - istream stream(sbuf); - do - { - decoder->decodeStreamSomePackets(stream, 0,this); - if (decoder->isValid() && (audioStream == NULL)) - audioStream=getSys()->audioManager->createStream(decoder,false); - if(threadAborting) - break; - } - while (!ACQUIRE_READ(stopped) && !stream.eof() && !stream.fail() && !stream.bad()); - - decoder->setFlushing(); - decoder->waitFlushed(); - sleep(1); - - delete audioStream; - delete decoder; - delete sbuf; - - if (!ACQUIRE_READ(stopped)) - { - incRef(); - getVm(getSystemState())->addEvent(_MR(this),_MR(Class<Event>::getInstanceS(getSystemState(),"soundComplete"))); - } -#endif //ENABLE_LIBAVCODEC -} void SoundChannel::jobFence() {
View file
lightspark.tar.xz/src/scripting/flash/media/flashmedia.h
Changed
@@ -36,15 +36,6 @@ class NetStream; class StreamCache; -class AudioFormat -{ -public: - AudioFormat(LS_AUDIO_CODEC co, int sr, int ch):codec(co),sampleRate(sr),channels(ch) {} - LS_AUDIO_CODEC codec; - int sampleRate; - int channels; -}; - class Sound: public EventDispatcher, public ILoadable { private: @@ -102,7 +93,6 @@ ASPROPERTY_GETTER_SETTER(_NR<SoundTransform>,soundTransform); void validateSoundTransform(_NR<SoundTransform>); void playStream(); - void playRaw(); public: SoundChannel(Class_base* c, _NR<StreamCache> stream=NullRef, AudioFormat format=AudioFormat(CODEC_NONE,0,0)); ~SoundChannel();
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.