Projects
Essentials
lightspark
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 130
View file
lightspark.spec
Changed
@@ -20,7 +20,7 @@ %bcond_without librtmp Name: lightspark -Version: 0.7.2.99+git20161230.0848 +Version: 0.7.2.99+git20170104.1157 Release: 0 Summary: Modern, free, open-source flash player implementation License: LGPL-3.0+
View file
lightspark.tar.xz/src/CMakeLists.txt
Changed
@@ -210,8 +210,6 @@ ENDIF() PACK_EXECUTABLE(lightspark) - INSTALL(FILES ${PROJECT_SOURCE_DIR}/src/lightspark.frag DESTINATION ${LSDATADIR}) - INSTALL(FILES ${PROJECT_SOURCE_DIR}/src/lightspark.vert DESTINATION ${LSDATADIR}) INSTALL(TARGETS lightspark RUNTIME DESTINATION ${BINDIR}) IF(UNIX) INSTALL(FILES ${PROJECT_SOURCE_DIR}/docs/man/lightspark.1 DESTINATION ${MANUAL_DIRECTORY}/man1/)
View file
lightspark.tar.xz/src/backends/audio.cpp
Changed
@@ -124,10 +124,13 @@ AudioManager::AudioManager():muteAllStreams(false),sdl_available(0),mixeropened(0) { sdl_available = 0; - if (SDL_WasInit(0)) // some part of SDL already was initialized - sdl_available = !SDL_InitSubSystem ( SDL_INIT_AUDIO ); - else - sdl_available = !SDL_Init ( SDL_INIT_AUDIO ); + if (EngineData::sdl_needinit) + { + if (SDL_WasInit(0)) // some part of SDL already was initialized + sdl_available = !SDL_InitSubSystem ( SDL_INIT_AUDIO ); + else + sdl_available = !SDL_Init ( SDL_INIT_AUDIO ); + } mixeropened = 0; } void AudioManager::muteAll()
View file
lightspark.tar.xz/src/backends/config.cpp
Changed
@@ -121,21 +121,21 @@ #endif //If cache dir doesn't exist, create it - path cacheDirectoryP(cacheDirectory); - if(!is_directory(cacheDirectoryP)) + try { - LOG(LOG_INFO, "Cache directory does not exist, trying to create"); - try + path cacheDirectoryP(cacheDirectory); + if(!is_directory(cacheDirectoryP)) { - create_directories(cacheDirectoryP); - } - catch(const filesystem_error& e) - { - LOG(LOG_INFO, _("Could not create cache directory, falling back to default cache directory: ") << - defaultCacheDirectory); - cacheDirectory = defaultCacheDirectory; + LOG(LOG_INFO, "Cache directory does not exist, trying to create"); + create_directories(cacheDirectoryP); } } + catch(const filesystem_error& e) + { + LOG(LOG_INFO, _("Could not create cache directory, falling back to default cache directory: ") << + defaultCacheDirectory); + cacheDirectory = defaultCacheDirectory; + } #ifdef _WIN32 std::string regGnashPath = readRegistryEntry("GnashPath");
View file
lightspark.tar.xz/src/backends/decoder.cpp
Changed
@@ -1076,6 +1076,7 @@ //NOTE: in FFMpeg 0.7 there is av_probe_input_buffer AVProbeData probeData; probeData.filename="lightspark_stream"; + probeData.mime_type=NULL; probeData.buf=new uint8_t[8192+AVPROBE_PADDING_SIZE]; memset(probeData.buf,0,8192+AVPROBE_PADDING_SIZE); stream.read((char*)probeData.buf,8192); @@ -1083,7 +1084,7 @@ if(read!=8192) LOG(LOG_ERROR,"Not sufficient data is available from the stream:"<<read); probeData.buf_size=read; - + stream.seekg(0); fmt=av_probe_input_format(&probeData,1); delete[] probeData.buf; @@ -1154,7 +1155,7 @@ if(audioFound) { - if (format) + if (format && (format->codec != LS_AUDIO_CODEC::CODEC_NONE)) customAudioDecoder=new FFMpegAudioDecoder(format->codec,format->sampleRate,format->channels,true); else #if LIBAVFORMAT_VERSION_MAJOR > 56
View file
lightspark.tar.xz/src/backends/extscriptobject.cpp
Changed
@@ -377,9 +377,9 @@ if(!synchronous) { func->incRef(); - funcEvent = _MR(new (getSys()->unaccountedMemory) ExternalCallEvent(_MR(func), asArgs, argc, &result, &exceptionThrown, &exception)); + funcEvent = _MR(new (func->getSystemState()->unaccountedMemory) ExternalCallEvent(_MR(func), asArgs, argc, &result, &exceptionThrown, &exception)); // Add the callback function event to the VM event queue - funcWasCalled=getVm(getSys())->addEvent(NullRef,funcEvent); + funcWasCalled=getVm(func->getSystemState())->addEvent(NullRef,funcEvent); if(!funcWasCalled) funcEvent = NullRef; }
View file
lightspark.tar.xz/src/backends/rendering.cpp
Changed
@@ -276,15 +276,11 @@ //Create render program uint32_t f = engineData->exec_glCreateShader_GL_FRAGMENT_SHADER(); - const char *fs = NULL; - fs = dataFileRead("lightspark.frag"); - if(fs==NULL) - { - LOG(LOG_ERROR,_("Shader lightspark.frag not found")); - throw RunTimeException("Fragment shader code not found"); - } + // directly include shader source to avoid filesystem access + const char *fs = +#include "lightspark.frag" +; engineData->exec_glShaderSource(f, 1, &fs,NULL); - free((void*)fs); uint32_t g = engineData->exec_glCreateShader_GL_VERTEX_SHADER(); bool ret=true; @@ -300,14 +296,11 @@ throw RunTimeException("Could not compile fragment shader"); } - fs = dataFileRead("lightspark.vert"); - if(fs==NULL) - { - LOG(LOG_ERROR,_("Shader lightspark.vert not found")); - throw RunTimeException("Vertex shader code not found"); - } - engineData->exec_glShaderSource(g, 1, &fs,NULL); - free((void*)fs); + // directly include shader source to avoid filesystem access + const char *fs2 = +#include "lightspark.vert" +; + engineData->exec_glShaderSource(g, 1, &fs2,NULL); engineData->exec_glGetShaderInfoLog(g,1024,&a,str); LOG(LOG_INFO,_("Vertex shader compilation ") << str);
View file
lightspark.tar.xz/src/backends/streamcache.cpp
Changed
@@ -66,7 +66,6 @@ handleAppend(buffer, length); - if (notifyLoader) { Locker locker(stateMutex); receivedLength += length; @@ -175,6 +174,11 @@ return new MemoryStreamCache::Reader(_MR(this)); } +void MemoryStreamCache::openForWriting() +{ + LOG(LOG_ERROR,"openForWriting not implemented in MemoryStreamCache"); +} + MemoryStreamCache::Reader::Reader(_R<MemoryStreamCache> b) : buffer(b), chunkIndex(0), chunkStartOffset(0) {
View file
lightspark.tar.xz/src/backends/streamcache.h
Changed
@@ -43,7 +43,7 @@ */ class DLL_PUBLIC StreamCache : public RefCountable { protected: - StreamCache() DLL_LOCAL; + StreamCache(); // stateMutex must be held while receivedLength, failed or // terminated are accessed @@ -60,7 +60,7 @@ // Wait until more than currentOffset bytes has been received // or until terminated - void waitForData(size_t currentOffset) DLL_LOCAL; + void waitForData(size_t currentOffset); // Derived class implements this to store received data virtual void handleAppend(const unsigned char* buffer, size_t length)=0; @@ -96,6 +96,8 @@ // thread). Every call returns a new, independent streambuf. // The caller must delete the returned value. virtual std::streambuf *createReader()=0; + + virtual void openForWriting() = 0; }; class MemoryChunk; @@ -151,6 +153,8 @@ virtual void reserve(size_t expectedLength); virtual std::streambuf *createReader(); + + void openForWriting(); }; /*
View file
lightspark.tar.xz/src/lightspark.frag
Changed
@@ -1,3 +1,4 @@ +R"( #ifdef GL_ES precision highp float; #endif @@ -30,3 +31,4 @@ gl_FragColor=(vbase*(1.0-yuv))+(val*yuv); } } +)"
View file
lightspark.tar.xz/src/lightspark.vert
Changed
@@ -1,3 +1,4 @@ +R"( attribute vec4 ls_Color; attribute vec2 ls_Vertex; attribute vec2 ls_TexCoord; @@ -18,3 +19,4 @@ ls_TexCoords[0]=vec4(ls_TexCoord, 0, 1); ls_TexCoords[1]=t; } +)"
View file
lightspark.tar.xz/src/platforms/engineutils.cpp
Changed
@@ -39,6 +39,7 @@ uint32_t EngineData::userevent = (uint32_t)-1; Thread* EngineData::mainLoopThread = NULL; bool EngineData::mainthread_running = false; +bool EngineData::sdl_needinit = true; Semaphore EngineData::mainthread_initialized(0); EngineData::EngineData() : currentPixelBuffer(0),currentPixelBufferOffset(0),currentPixelBufPtr(NULL),pixelBufferWidth(0),pixelBufferHeight(0),widget(0), width(0), height(0),needrenderthread(true),windowID(0),visual(0) { @@ -108,12 +109,16 @@ /* main loop handling */ static void mainloop_runner() { - bool sdl_available = false; - if (SDL_WasInit(0)) // some part of SDL already was initialized - sdl_available = SDL_InitSubSystem ( SDL_INIT_VIDEO ); - else - sdl_available = SDL_Init ( SDL_INIT_VIDEO ); - if (sdl_available) + bool sdl_available = !EngineData::sdl_needinit; + + if (EngineData::sdl_needinit) + { + if (SDL_WasInit(0)) // some part of SDL already was initialized + sdl_available = !SDL_InitSubSystem ( SDL_INIT_VIDEO ); + else + sdl_available = !SDL_Init ( SDL_INIT_VIDEO ); + } + if (!sdl_available) { LOG(LOG_ERROR,"Unable to initialize SDL:"<<SDL_GetError()); EngineData::mainthread_initialized.signal(); @@ -221,6 +226,11 @@ LOG(LOG_ERROR, "copying text to clipboard failed:"<<SDL_GetError()); } +StreamCache *EngineData::createFileStreamCache() +{ + return new FileStreamCache(); +} + bool EngineData::getGLError(uint32_t &errorCode) const { errorCode=glGetError();
View file
lightspark.tar.xz/src/platforms/engineutils.h
Changed
@@ -37,6 +37,8 @@ #define LS_USEREVENT_EXEC EngineData::userevent+1 #define LS_USEREVENT_QUIT EngineData::userevent+2 class SystemState; +class StreamCache; + class DLL_PUBLIC EngineData { friend class RenderThread; @@ -69,7 +71,7 @@ /* you may not call getWindowForGnash and showWindow on the same EngineData! */ virtual uint32_t getWindowForGnash()=0; /* Runs 'func' in the mainLoopThread */ - static void runInMainThread(void (*func) (SystemState*) ) + virtual void runInMainThread(SystemState* sys, void (*func) (SystemState*) ) { SDL_Event event; SDL_zero(event); @@ -88,6 +90,7 @@ virtual void grabFocus()=0; virtual void openPageInBrowser(const tiny_string& url, const tiny_string& window)=0; + static bool sdl_needinit; static bool mainthread_running; static Semaphore mainthread_initialized; static bool startSDLMain(); @@ -102,6 +105,7 @@ virtual void setClipboardText(const std::string txt); virtual bool getScreenData(SDL_DisplayMode* screen) = 0; virtual double getScreenDPI() = 0; + virtual StreamCache* createFileStreamCache(); virtual void SwapBuffers() = 0; virtual void InitOpenGL() = 0;
View file
lightspark.tar.xz/src/plugin_ppapi/plugin.cpp
Changed
@@ -19,9 +19,8 @@ // TODO -// - download // - sound -// - run within sandbox +// - font loading // - register as separate plugin #include "version.h" @@ -34,7 +33,6 @@ #include <algorithm> #include <SDL2/SDL.h> #include "threading.h" -#include "scripting/toplevel/JSON.h" #include "plugin_ppapi/plugin.h" #include "plugin_ppapi/ppextscriptobject.h" @@ -63,6 +61,10 @@ #include "ppapi/c/ppb_graphics_3d.h" #include "ppapi/c/ppb_input_event.h" #include "ppapi/c/private/ppb_flash_clipboard.h" +#include "ppapi/c/ppb_file_io.h" +#include "ppapi/c/ppb_file_ref.h" +#include "ppapi/c/ppb_file_system.h" + #include "GLES2/gl2.h" //The interpretation of texture data change with the endianness @@ -93,7 +95,158 @@ static const PPB_KeyboardInputEvent* g_keyboardinputevent_interface = NULL; static const PPB_WheelInputEvent* g_wheelinputevent_interface = NULL; static const PPB_Flash_Clipboard* g_flashclipboard_interface = NULL; +static const PPB_FileIO* g_fileio_interface = NULL; +static const PPB_FileRef* g_fileref_interface = NULL; +static const PPB_FileSystem* g_filesystem_interface = NULL; + + + +ppFileStreamCache::ppFileStreamCache(ppPluginInstance* instance):cache(0),cacheref(0),writeoffset(0),m_instance(instance) +{ +} + +ppFileStreamCache::~ppFileStreamCache() +{ + if (cache != 0) + { + g_fileio_interface->Close(cache); + g_fileref_interface->Delete(cacheref,PP_MakeCompletionCallback(NULL,NULL)); + } +} + +void ppFileStreamCache::handleAppend(const unsigned char* buffer, size_t length) +{ + if (cache == 0) + openCache(); + + int written = g_fileio_interface->Write(cache,writeoffset,(const char*)buffer,length,PP_MakeCompletionCallback(NULL,NULL)); + if (written < 0) + { + LOG(LOG_ERROR,"writing cache file failed, error code:"<<written); + return; + } + writeoffset += written; +} + +/** + * \brief Creates & opens a temporary cache file + * + * Creates a temporary cache file in /tmp and calls \c openExistingCache() with that file. + * Waits for mutex at start and releases mutex when finished. + * \throw RunTimeException Temporary file could not be created + * \throw RunTimeException Called when the cache is already open + * \see Downloader::openExistingCache() + */ +void ppFileStreamCache::openCache() +{ + if (cache != 0) + { + markFinished(true); + throw RunTimeException("ppFileStreamCache::openCache called twice"); + } + + //Create a temporary file(name) + + cacheref = m_instance->createCacheFileRef(); + cache = g_fileio_interface->Create(m_instance->getFileSystem()); + int res = g_fileio_interface->Open(cache,cacheref,PP_FileOpenFlags::PP_FILEOPENFLAG_READ|PP_FileOpenFlags::PP_FILEOPENFLAG_WRITE,PP_MakeCompletionCallback(NULL,NULL)); + if (res != PP_OK) + { + LOG(LOG_ERROR,"opening cache file failed, error code:"<<res); + cache = 0; + } + +} + +void ppFileStreamCache::openForWriting() +{ + if (cache != 0) + return; + openCache(); +} + +bool ppFileStreamCache::waitForCache() +{ + if (cache != 0) + return true; + + // Cache file will be opened when the first byte is received + waitForData(0); + return cache != 0; +} + +std::streambuf *ppFileStreamCache::createReader() +{ + if (!waitForCache()) + { + LOG(LOG_ERROR,"could not open cache file"); + return NULL; + } + + incRef(); + ppFileStreamCache::ppFileStreamCacheReader *fbuf = new ppFileStreamCache::ppFileStreamCacheReader(_MR(this)); + return fbuf; +} + +ppFileStreamCache::ppFileStreamCacheReader::ppFileStreamCacheReader(_R<ppFileStreamCache> b) : curpos(-1),buffer(b) +{ +} + +int ppFileStreamCache::ppFileStreamCacheReader::underflow() +{ + if (!buffer->hasTerminated()) + buffer->waitForData(seekoff(0, ios_base::cur, ios_base::in)); + + return streambuf::underflow(); +} + +streamsize ppFileStreamCache::ppFileStreamCacheReader::xsgetn(char* s, streamsize n) +{ + streamsize read= g_fileio_interface->Read(buffer->cache,curpos,s,n,PP_MakeCompletionCallback(NULL,NULL)); + curpos += read; + // If not enough data was available, wait for writer + while (read < n) + { + buffer->waitForData(seekoff(0, ios_base::cur, ios_base::in)); + + streamsize b = g_fileio_interface->Read(buffer->cache,curpos,s+read,n-read,PP_MakeCompletionCallback(NULL,NULL)); + curpos += b; + + // No more data after waiting, this must be EOF + if (b == 0) + return read; + + read += b; + } + + return read; +} + +streampos ppFileStreamCache::ppFileStreamCacheReader::seekoff(streamoff off, ios_base::seekdir way, ios_base::openmode which) +{ + switch (way) + { + case ios_base::beg: + curpos = off; + break; + case ios_base::cur: + curpos += off; + break; + case ios_base::end: + curpos = buffer->getReceivedLength() + off; + break; + default: + break; + } + return curpos; +} + +streampos ppFileStreamCache::ppFileStreamCacheReader::seekpos(streampos sp, ios_base::openmode which) +{ + curpos = sp; + return curpos; +} ppVariantObject::ppVariantObject(std::map<int64_t, std::unique_ptr<ExtObject> > &objectsMap, PP_Var& other) @@ -306,7 +459,7 @@ return result; } -ppDownloadManager::ppDownloadManager(PP_Instance _instance, SystemState *sys):instance(_instance),m_sys(sys) +ppDownloadManager::ppDownloadManager(ppPluginInstance *_instance, SystemState *sys):m_instance(_instance),m_sys(sys) { type = NPAPI; } @@ -328,7 +481,7 @@ LOG(LOG_INFO, _("NET: PLUGIN: DownloadManager::download '") << url.getParsedURL() << "'" << (cached ? _(" - cached") : "")); //Register this download - ppDownloader* downloader=new ppDownloader(url.getParsedURL(), cache, instance, owner); + ppDownloader* downloader=new ppDownloader(url.getParsedURL(), cache, m_instance, owner); addDownloader(downloader); return downloader; } @@ -344,7 +497,7 @@ LOG(LOG_INFO, _("NET: PLUGIN: DownloadManager::downloadWithData '") << url.getParsedURL()); //Register this download - ppDownloader* downloader=new ppDownloader(url.getParsedURL(), cache, data, headers, instance, owner); + ppDownloader* downloader=new ppDownloader(url.getParsedURL(), cache, data, headers, m_instance, owner); addDownloader(downloader); return downloader; } @@ -375,6 +528,8 @@ void ppDownloader::dlStartCallback(void* userdata,int result) { ppDownloader* th = (ppDownloader*)userdata; + setTLSSys(th->m_sys); + if (result < 0) { LOG(LOG_ERROR,"download failed:"<<result<<" "<<th->getURL()); @@ -386,7 +541,6 @@ uint32_t len; v = g_urlresponseinfo_interface->GetProperty(response,PP_URLRESPONSEPROPERTY_HEADERS); tiny_string headers = g_var_interface->VarToUtf8(v,&len); - LOG(LOG_INFO,"headers:"<<len<<" "<<headers); th->parseHeaders(headers.raw_buf(),true); if (th->isMainClipDownloader) @@ -400,20 +554,23 @@ th->m_sys->mainClip->setBaseURL(url); } - - struct PP_CompletionCallback cb; - cb.func = dlReadResponseCallback; - cb.flags = 0; - cb.user_data = th; - g_urlloader_interface->ReadResponseBody(th->ppurlloader,th->buffer,4096,cb); + if (th->hasEmptyAnswer()) + { + th->setFinished(); + g_urlloader_interface->Close(th->ppurlloader); + return; + } + g_urlloader_interface->ReadResponseBody(th->ppurlloader,th->buffer,4096,PP_MakeCompletionCallback(dlReadResponseCallback,th)); } void ppDownloader::dlReadResponseCallback(void* userdata,int result) { ppDownloader* th = (ppDownloader*)userdata; + setTLSSys(th->m_sys); if (result < 0) { LOG(LOG_ERROR,"download failed:"<<result<<" "<<th->getURL()<<" "<<th->downloadedlength<<"/"<<th->getLength()); th->setFailed(); + g_urlloader_interface->Close(th->ppurlloader); return; } th->append(th->buffer,result); @@ -421,65 +578,82 @@ th->m_pluginInstance->startMainParser(); th->downloadedlength += result; - if (th->downloadedlength == th->getLength()) + if (result == 0) { th->setFinished(); - LOG(LOG_INFO,"download done:"<<th->getURL()<<" "<<th->downloadedlength<<" "<<th->getLength()); + g_urlloader_interface->Close(th->ppurlloader); + LOG_CALL("download done:"<<th->getURL()<<" "<<th->downloadedlength<<" "<<th->getLength()); return; } - struct PP_CompletionCallback cb; - cb.func = dlReadResponseCallback; - cb.flags = 0; - cb.user_data = th; - g_urlloader_interface->ReadResponseBody(th->ppurlloader,th->buffer,4096,cb); + g_urlloader_interface->ReadResponseBody(th->ppurlloader,th->buffer,4096,PP_MakeCompletionCallback(dlReadResponseCallback,th)); } -ppDownloader::ppDownloader(const lightspark::tiny_string& _url, PP_Instance _instance, lightspark::ILoadable* owner, ppPluginInstance *ppinstance): - Downloader(_url, _MR(new MemoryStreamCache), owner),isMainClipDownloader(true),m_sys(ppinstance->getSystemState()),m_pluginInstance(ppinstance),downloadedlength(0),state(INIT) +void ppDownloader::dlStartDownloadCallback(void* userdata,int result) { - ppurlloader = g_urlloader_interface->Create(_instance); - g_urlloadedtrusted_interface->GrantUniversalAccess(ppurlloader); - PP_Resource pprequest_info = g_urlrequestinfo_interface->Create(_instance); - PP_Var url = g_var_interface->VarFromUtf8(_url.raw_buf(),_url.numBytes()); + ppDownloader* th = (ppDownloader*)userdata; + setTLSSys(th->m_sys); + const tiny_string strurl = th->getURL(); + th->ppurlloader = g_urlloader_interface->Create(th->m_pluginInstance->getppInstance()); + g_urlloadedtrusted_interface->GrantUniversalAccess(th->ppurlloader); + PP_Resource pprequest_info = g_urlrequestinfo_interface->Create(th->m_pluginInstance->getppInstance()); + PP_Var url = g_var_interface->VarFromUtf8(strurl.raw_buf(),strurl.numBytes()); g_urlrequestinfo_interface->SetProperty(pprequest_info,PP_URLREQUESTPROPERTY_URL,url); g_urlrequestinfo_interface->SetProperty(pprequest_info,PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS,PP_MakeBool(PP_TRUE)); - LOG(LOG_INFO,"constructing downloader:"<<_url); - - struct PP_CompletionCallback cb; - cb.func = dlStartCallback; - cb.flags = 0; - cb.user_data = this; - int res = g_urlloader_interface->Open(ppurlloader,pprequest_info,cb); + if (th->data.size() > 0) + { + PP_Var v = g_var_interface->VarFromUtf8("POST",4); + g_urlrequestinfo_interface->SetProperty(pprequest_info,PP_URLREQUESTPROPERTY_METHOD,v); + g_urlrequestinfo_interface->AppendDataToBody(pprequest_info,&th->data.front(),th->data.size()); + } + LOG_CALL("starting download:"<<th->data.size()<<" "<<strurl); + + int res = g_urlloader_interface->Open(th->ppurlloader,pprequest_info,PP_MakeCompletionCallback(dlStartCallback,th)); if (res != PP_OK_COMPLETIONPENDING) - LOG(LOG_ERROR,"url opening failed:"<<res<<" "<<_url); + LOG(LOG_ERROR,"url opening failed:"<<res<<" "<<strurl); +} +void ppDownloader::startDownload() +{ + if (!g_core_interface->IsMainThread()) + g_core_interface->CallOnMainThread(0,PP_MakeCompletionCallback(dlStartDownloadCallback,this),0); + else + dlStartDownloadCallback(this,0); + +} +ppDownloader::ppDownloader(const lightspark::tiny_string& _url, lightspark::ILoadable* owner, ppPluginInstance *ppinstance): + Downloader(_url, _MR(new MemoryStreamCache), owner),isMainClipDownloader(true),m_sys(ppinstance->getSystemState()),m_pluginInstance(ppinstance),downloadedlength(0),state(INIT) +{ + startDownload(); } -ppDownloader::ppDownloader(const lightspark::tiny_string& _url, _R<StreamCache> _cache, PP_Instance _instance, lightspark::ILoadable* owner): - Downloader(_url, _cache, owner),isMainClipDownloader(false),m_sys(NULL),m_pluginInstance(NULL),downloadedlength(0),state(INIT) +ppDownloader::ppDownloader(const lightspark::tiny_string& _url, _R<StreamCache> _cache, ppPluginInstance *ppinstance, lightspark::ILoadable* owner): + Downloader(_url, _cache, owner),isMainClipDownloader(false),m_sys(ppinstance->getSystemState()),m_pluginInstance(ppinstance),downloadedlength(0),state(INIT) { - LOG(LOG_ERROR,"Download constructor2 not implemented"); - ppurlloader = g_urlloader_interface->Create(_instance); + startDownload(); } ppDownloader::ppDownloader(const lightspark::tiny_string& _url, _R<StreamCache> _cache, const std::vector<uint8_t>& _data, - const std::list<tiny_string>& headers, PP_Instance _instance, lightspark::ILoadable* owner): - Downloader(_url, _cache, _data, headers, owner),isMainClipDownloader(false),m_sys(NULL),m_pluginInstance(NULL),downloadedlength(0),state(INIT) + const std::list<tiny_string>& headers, ppPluginInstance *ppinstance, lightspark::ILoadable* owner): + Downloader(_url, _cache, _data, headers, owner),isMainClipDownloader(false),m_sys(ppinstance->getSystemState()),m_pluginInstance(ppinstance),downloadedlength(0),state(INIT) { - LOG(LOG_ERROR,"Download constructor3 not implemented"); - ppurlloader = g_urlloader_interface->Create(_instance); + startDownload(); +} +void openfilesystem_callback(void* userdata,int result) +{ + LOG(LOG_INFO,"filesystem opened"); } - ppPluginInstance::ppPluginInstance(PP_Instance instance, int16_t argc, const char *argn[], const char *argv[]) : m_ppinstance(instance), mainDownloaderStreambuf(NULL),mainDownloaderStream(NULL), mainDownloader(NULL), m_pt(NULL) { + m_cachefilesystem = g_filesystem_interface->Create(instance,PP_FileSystemType::PP_FILESYSTEMTYPE_LOCALTEMPORARY); + m_cachefilename = 0; + g_filesystem_interface->Open(m_cachefilesystem, 1024*1024,PP_MakeCompletionCallback(openfilesystem_callback,NULL)); m_last_size.width = 0; m_last_size.height = 0; m_graphics = 0; - LOG(LOG_INFO, "Lightspark version " << VERSION << " Copyright 2009-2013 Alessandro Pignotti and others"); setTLSSys( NULL ); m_sys=new lightspark::SystemState(0, lightspark::SystemState::FLASH); //Files running in the plugin have REMOTE sandbox @@ -508,10 +682,11 @@ } if (!swffile.empty()) { - m_sys->downloadManager=new ppDownloadManager(m_ppinstance,m_sys); + m_sys->downloadManager=new ppDownloadManager(this,m_sys); - EngineData::startSDLMain(); - mainDownloader=new ppDownloader(swffile,m_ppinstance,m_sys->mainClip->loaderInfo.getPtr(),this); + //EngineData::startSDLMain(); + EngineData::mainthread_running = true; + mainDownloader=new ppDownloader(swffile,m_sys->mainClip->loaderInfo.getPtr(),this); // loader is notified through parsethread mainDownloader->getCache()->setNotifyLoader(false); } @@ -527,6 +702,13 @@ } +PP_Resource ppPluginInstance::createCacheFileRef() +{ + char filenamebuf[100]; + sprintf(filenamebuf,"/tmp%d",++m_cachefilename); + return g_fileref_interface->Create(getFileSystem(),filenamebuf); +} + ppPluginInstance::~ppPluginInstance() { //Shutdown the system @@ -553,12 +735,13 @@ void swapbuffer_callback(void* userdata,int result) { ppPluginEngineData* data = (ppPluginEngineData*)userdata; - RELEASE_WRITE(data->inRendering,false); + data->swapbuffer_rendering.signal(); } void ppPluginInstance::handleResize(PP_Resource view) { + setTLSSys(m_sys); struct PP_Rect position; if (g_view_interface->GetRect(view, &position) == PP_FALSE) { @@ -587,11 +770,6 @@ g_graphics_3d_interface->ResizeBuffers(m_graphics,position.size.width, position.size.height); m_sys->getRenderThread()->SetEngineData(m_sys->getEngineData()); m_sys->getRenderThread()->init(); - struct PP_CompletionCallback cb; - cb.func = swapbuffer_callback; - cb.flags = 0; - cb.user_data = m_sys->getEngineData(); - g_graphics_3d_interface->SwapBuffers(m_graphics,cb); } else { @@ -750,6 +928,7 @@ PP_Bool ppPluginInstance::handleInputEvent(PP_Resource input_event) { + setTLSSys(m_sys); SDL_Event ev; switch (g_inputevent_interface->GetType(input_event)) { @@ -858,14 +1037,11 @@ } void ppPluginInstance::executeScriptAsync(ExtScriptObject::HOST_CALL_DATA *data) { - struct PP_CompletionCallback cb; - cb.func = executescript_callback; - cb.flags = 0; - cb.user_data = data; - g_core_interface->CallOnMainThread(0,cb,0); + g_core_interface->CallOnMainThread(0,PP_MakeCompletionCallback(executescript_callback,data),0); } bool ppPluginInstance::executeScript(const std::string script, const ExtVariant **args, uint32_t argc, ASObject **result) { + setTLSSys(m_sys); PP_Var scr = g_var_interface->VarFromUtf8(script.c_str(),script.length()); PP_Var exception = PP_MakeUndefined(); PP_Var func = g_instance_private_interface->ExecuteScript(m_ppinstance,scr,&exception); @@ -944,6 +1120,8 @@ static bool PPP_Class_HasProperty(void* object,struct PP_Var name,struct PP_Var* exception) { + setTLSSys(((ppExtScriptObject*)object)->getSystemState()); + LOG_CALL("PPP_Class_HasProperty"); uint32_t len; switch (name.type) { @@ -960,6 +1138,8 @@ } static bool PPP_Class_HasMethod(void* object,struct PP_Var name,struct PP_Var* exception) { + setTLSSys(((ppExtScriptObject*)object)->getSystemState()); + LOG_CALL("PPP_Class_Method"); uint32_t len; switch (name.type) { @@ -975,6 +1155,8 @@ } static struct PP_Var PPP_Class_GetProperty(void* object,struct PP_Var name,struct PP_Var* exception) { + setTLSSys(((ppExtScriptObject*)object)->getSystemState()); + LOG_CALL("PPP_Class_GetProperty"); ExtVariant v; uint32_t len; switch (name.type) @@ -996,6 +1178,8 @@ } static void PPP_Class_GetAllPropertyNames(void* object,uint32_t* property_count,struct PP_Var** properties,struct PP_Var* exception) { + setTLSSys(((ppExtScriptObject*)object)->getSystemState()); + LOG_CALL("PPP_Class_GetAllPropertyNames"); ExtIdentifier** ids = NULL; bool success = ((ppExtScriptObject*)object)->enumerate(&ids, property_count); if(success) @@ -1027,6 +1211,8 @@ static void PPP_Class_SetProperty(void* object,struct PP_Var name,struct PP_Var value,struct PP_Var* exception) { + setTLSSys(((ppExtScriptObject*)object)->getSystemState()); + LOG_CALL("PPP_Class_SetProperty"); uint32_t len; std::map<int64_t, std::unique_ptr<ExtObject>> objectsMap; switch (name.type) @@ -1045,6 +1231,8 @@ static void PPP_Class_RemoveProperty(void* object,struct PP_Var name,struct PP_Var* exception) { + setTLSSys(((ppExtScriptObject*)object)->getSystemState()); + LOG_CALL("PPP_Class_RemoveProperty"); uint32_t len; switch (name.type) { @@ -1062,6 +1250,7 @@ static struct PP_Var PPP_Class_Call(void* object,struct PP_Var name,uint32_t argc,struct PP_Var* argv,struct PP_Var* exception) { + setTLSSys(((ppExtScriptObject*)object)->getSystemState()); PP_Var objResult = PP_MakeUndefined(); uint32_t len; ExtIdentifier method_name; @@ -1077,6 +1266,7 @@ LOG(LOG_NOT_IMPLEMENTED,"PPP_Class_Call for method name type "<<(int)name.type); return PP_MakeUndefined(); } + LOG_CALL("PPP_Class_Call:"<<((ppExtScriptObject*)object)->getInstance()->getSystemState()<<" "<< method_name.getString()); std::map<int64_t, std::unique_ptr<ExtObject>> objectsMap; const ExtVariant** objArgs = g_newa(const ExtVariant*,argc); for (uint32_t i = 0; i < argc; i++) @@ -1085,6 +1275,7 @@ } ((ppExtScriptObject*)object)->invoke(method_name,argc,objArgs,&objResult); + LOG_CALL("PPP_Class_Call done:"<<method_name.getString()); return objResult; } @@ -1169,6 +1360,7 @@ Log::redirect(envvar); Log::setLogLevel(log_level); + EngineData::sdl_needinit = false; lightspark::SystemState::staticInit(); LOG(LOG_INFO, "Lightspark version " << VERSION << " Copyright 2009-2013 Alessandro Pignotti and others"); @@ -1190,6 +1382,9 @@ g_keyboardinputevent_interface = (const PPB_KeyboardInputEvent*)get_browser_interface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE); g_wheelinputevent_interface = (const PPB_WheelInputEvent*)get_browser_interface(PPB_WHEEL_INPUT_EVENT_INTERFACE); g_flashclipboard_interface = (const PPB_Flash_Clipboard*)get_browser_interface(PPB_FLASH_CLIPBOARD_INTERFACE); + g_fileio_interface = (const PPB_FileIO*)get_browser_interface(PPB_FILEIO_INTERFACE); + g_fileref_interface = (const PPB_FileRef*)get_browser_interface(PPB_FILEREF_INTERFACE); + g_filesystem_interface = (const PPB_FileSystem*)get_browser_interface(PPB_FILESYSTEM_INTERFACE); if (!g_core_interface || !g_instance_interface || @@ -1207,7 +1402,10 @@ !g_mouseinputevent_interface || !g_keyboardinputevent_interface || !g_wheelinputevent_interface || - !g_flashclipboard_interface) + !g_flashclipboard_interface || + !g_fileio_interface || + !g_fileref_interface || + !g_filesystem_interface) { LOG(LOG_ERROR,"get_browser_interface failed:" << g_core_interface <<" " @@ -1226,7 +1424,10 @@ << g_mouseinputevent_interface<<" " << g_keyboardinputevent_interface<<" " << g_wheelinputevent_interface<<" " - << g_flashclipboard_interface); + << g_flashclipboard_interface<<" " + << g_fileio_interface<<" " + << g_fileref_interface<<" " + << g_filesystem_interface); return PP_ERROR_NOINTERFACE; } return PP_OK; @@ -1272,6 +1473,30 @@ // return instance->mWindow; return 0; } +struct userevent_callbackdata +{ + void (*func) (SystemState*); + SystemState* sys; +}; + +void exec_ppPluginEngineData_callback(void* userdata,int result) +{ + userevent_callbackdata* data= (userevent_callbackdata*)userdata; + data->func(data->sys); + delete data; +} +void ppPluginEngineData::runInMainThread(SystemState* sys, void (*func) (SystemState*) ) +{ + userevent_callbackdata* ue = new userevent_callbackdata; + ue->func=func; + ue->sys=sys; + if (!g_core_interface->IsMainThread()) + { + g_core_interface->CallOnMainThread(0,PP_MakeCompletionCallback(exec_ppPluginEngineData_callback,ue),0); + } + else + exec_ppPluginEngineData_callback(ue,0); +} void ppPluginEngineData::openPageInBrowser(const tiny_string& url, const tiny_string& window) { @@ -1316,28 +1541,23 @@ return 96.0; } +StreamCache *ppPluginEngineData::createFileStreamCache() +{ + return new ppFileStreamCache(instance); +} + void swapbuffer_ppPluginEngineData_callback(void* userdata,int result) { ppPluginEngineData* data = (ppPluginEngineData*)userdata; - if (ACQUIRE_READ(data->inRendering)) - return; - RELEASE_WRITE(data->inRendering,true); - struct PP_CompletionCallback cb; - cb.func = swapbuffer_callback; - cb.flags = 0; - cb.user_data = userdata; - g_graphics_3d_interface->SwapBuffers(data->getGraphics(),cb); + g_graphics_3d_interface->SwapBuffers(data->getGraphics(),PP_MakeCompletionCallback(swapbuffer_callback,userdata)); } void ppPluginEngineData::SwapBuffers() { if (!g_core_interface->IsMainThread()) { - struct PP_CompletionCallback cb; - cb.func = swapbuffer_ppPluginEngineData_callback; - cb.flags = 0; - cb.user_data = this; - g_core_interface->CallOnMainThread(0,cb,0); + g_core_interface->CallOnMainThread(0,PP_MakeCompletionCallback(swapbuffer_ppPluginEngineData_callback,this),0); + swapbuffer_rendering.wait(); } else swapbuffer_ppPluginEngineData_callback(this,0);
View file
lightspark.tar.xz/src/plugin_ppapi/plugin.h
Changed
@@ -4,20 +4,59 @@ #include "swf.h" #include "ppapi/c/ppp_instance.h" #include "ppapi/c/pp_var.h" +#include "ppapi/c/pp_resource.h" namespace lightspark { - class ppDownloader; class ppPluginInstance; + +class ppFileStreamCache : public StreamCache { +private: + class ppFileStreamCacheReader : public std::streambuf { + private: + std::streampos curpos; + _R<ppFileStreamCache> buffer; + virtual int underflow(); + virtual std::streamsize xsgetn(char* s, std::streamsize n); + + std::streampos seekoff (std::streamoff off, std::ios_base::seekdir way,std::ios_base::openmode which); + std::streampos seekpos (std::streampos sp, std::ios_base::openmode which); + public: + ppFileStreamCacheReader(_R<ppFileStreamCache> buffer); + }; + + //Cache filename + PP_Resource cache; + PP_Resource cacheref; + int64_t writeoffset; + ppPluginInstance* m_instance; + + void openCache(); + void openExistingCache(const tiny_string& filename, bool forWriting=true); + + // Block until the cache file is opened by the writer stream + bool waitForCache(); + + virtual void handleAppend(const unsigned char* buffer, size_t length); + +public: + ppFileStreamCache(ppPluginInstance* instance); + virtual ~ppFileStreamCache(); + + virtual std::streambuf *createReader(); + + void openForWriting(); +}; + class ppDownloadManager: public StandaloneDownloadManager { private: - PP_Instance instance; + ppPluginInstance* m_instance; SystemState* m_sys; public: - ppDownloadManager(PP_Instance _instance,SystemState* sys); + ppDownloadManager(ppPluginInstance* _instance,SystemState* sys); Downloader* download(const URLInfo& url, _R<StreamCache> cache, ILoadable* owner); @@ -39,14 +78,16 @@ static void dlStartCallback(void* userdata,int result); static void dlReadResponseCallback(void* userdata,int result); + static void dlStartDownloadCallback(void* userdata,int result); + void startDownload(); public: enum STATE { INIT=0, STREAM_DESTROYED, ASYNC_DESTROY }; STATE state; //Constructor used for the main file - ppDownloader(const tiny_string& _url, PP_Instance _instance, ILoadable* owner, ppPluginInstance* ppinstance); - ppDownloader(const tiny_string& _url, _R<StreamCache> cache, PP_Instance _instance, ILoadable* owner); + ppDownloader(const tiny_string& _url, ILoadable* owner, ppPluginInstance* ppinstance); + ppDownloader(const tiny_string& _url, _R<StreamCache> cache, ppPluginInstance* ppinstance, ILoadable* owner); ppDownloader(const tiny_string& _url, _R<StreamCache> cache, const std::vector<uint8_t>& _data, - const std::list<tiny_string>& headers, PP_Instance _instance, ILoadable* owner); + const std::list<tiny_string>& headers, ppPluginInstance* ppinstance, ILoadable* owner); }; class ppVariantObject : public ExtVariant @@ -72,11 +113,14 @@ PP_Instance m_ppinstance; struct PP_Size m_last_size; PP_Resource m_graphics; + PP_Resource m_cachefilesystem; + ATOMIC_INT32(m_cachefilename); SystemState* m_sys; std::streambuf *mainDownloaderStreambuf; std::istream mainDownloaderStream; ppDownloader* mainDownloader; ParseThread* m_pt; + public: ppPluginInstance(PP_Instance instance, int16_t argc,const char* argn[],const char* argv[]); virtual ~ppPluginInstance(); @@ -87,6 +131,8 @@ SystemState* getSystemState() const { return m_sys;} void startMainParser(); PP_Instance getppInstance() { return m_ppinstance; } + PP_Resource getFileSystem() { return m_cachefilesystem; } + PP_Resource createCacheFileRef(); }; class ppPluginEngineData: public EngineData @@ -95,8 +141,8 @@ ppPluginInstance* instance; public: SystemState* sys; - ACQUIRE_RELEASE_FLAG(inRendering); - ppPluginEngineData(ppPluginInstance* i, uint32_t w, uint32_t h,SystemState* _sys) : EngineData(), instance(i),sys(_sys),inRendering(false) + Semaphore swapbuffer_rendering; + ppPluginEngineData(ppPluginInstance* i, uint32_t w, uint32_t h,SystemState* _sys) : EngineData(), instance(i),sys(_sys),swapbuffer_rendering(0) { width = w; height = h; @@ -106,6 +152,7 @@ void stopMainDownload(); bool isSizable() const { return false; } uint32_t getWindowForGnash(); + void runInMainThread(SystemState* sys, void (*func) (SystemState*) ); /* must be called within mainLoopThread */ SDL_Window* createWidget(uint32_t w,uint32_t h); /* must be called within mainLoopThread */ @@ -114,6 +161,8 @@ void setClipboardText(const std::string txt); bool getScreenData(SDL_DisplayMode* screen); double getScreenDPI(); + StreamCache* createFileStreamCache(); + void SwapBuffers(); void InitOpenGL(); void DeinitOpenGL();
View file
lightspark.tar.xz/src/scripting/flash/net/flashnet.cpp
Changed
@@ -1330,7 +1330,7 @@ // Parameter Null means data is generated by calls to "appendBytes" if (args[0]->is<Null>()) { - th->datagenerationfile = new FileStreamCache; + th->datagenerationfile = th->getSystemState()->getEngineData()->createFileStreamCache(); th->datagenerationfile->openForWriting(); th->streamTime=0; return NULL; @@ -1393,7 +1393,7 @@ } else //The URL is valid so we can start the download and add ourself as a job { - StreamCache *cache = new FileStreamCache; + StreamCache *cache = th->getSystemState()->getEngineData()->createFileStreamCache(); th->downloader=getSys()->downloadManager->download(th->url, _MR(cache), NULL); th->streamTime=0; //To be decreffed in jobFence @@ -1658,7 +1658,7 @@ LOG(LOG_INFO,"resetBegin"); if (th->datagenerationfile) delete th->datagenerationfile; - th->datagenerationfile = new FileStreamCache; + th->datagenerationfile = th->getSystemState()->getEngineData()->createFileStreamCache(); th->datagenerationfile->openForWriting(); th->datagenerationbuffer->setLength(0); th->datagenerationthreadstarted = false;
View file
lightspark.tar.xz/src/scripting/flash/net/flashnet.h
Changed
@@ -264,7 +264,7 @@ AudioDecoder* audioDecoder; AudioStream *audioStream; // only used when in DataGenerationMode - FileStreamCache* datagenerationfile; + StreamCache* datagenerationfile; bool datagenerationthreadstarted; Mutex mutex; Mutex countermutex;
View file
lightspark.tar.xz/src/swf.cpp
Changed
@@ -268,11 +268,14 @@ inputThread=new InputThread(this); EngineData::userevent = SDL_RegisterEvents(3); - SDL_Event event; - SDL_zero(event); - event.type = LS_USEREVENT_INIT; - event.user.data1 = this; - SDL_PushEvent(&event); + if (EngineData::sdl_needinit) + { + SDL_Event event; + SDL_zero(event); + event.type = LS_USEREVENT_INIT; + event.user.data1 = this; + SDL_PushEvent(&event); + } } void SystemState::setDownloadedPath(const tiny_string& p) @@ -782,7 +785,7 @@ } //The engines must be created in the context of the main thread - engineData->runInMainThread(&SystemState::delayedCreation); + engineData->runInMainThread(this,&SystemState::delayedCreation); //Wait for delayedCreation to finish so it is protected by our 'mutex' //Otherwise SystemState::destroy may delete this object before delayedCreation is scheduled. @@ -1395,18 +1398,18 @@ return; } //Check if this clip is the main clip then honour its FileAttributesTag - if(root == getSys()->mainClip) + if(root == root->getSystemState()->mainClip) { - getSys()->needsAVM2(fat->ActionScript3); + root->getSystemState()->needsAVM2(fat->ActionScript3); if(!fat->ActionScript3) { - delete fat; + delete fat; return; /* no more parsing necessary, handled by fallback */ - } + } if(fat->UseNetwork - && getSys()->securityManager->getSandboxType() == SecurityManager::LOCAL_WITH_FILE) + && root->getSystemState()->securityManager->getSandboxType() == SecurityManager::LOCAL_WITH_FILE) { - getSys()->securityManager->setSandboxType(SecurityManager::LOCAL_WITH_NETWORK); + root->getSystemState()->securityManager->setSandboxType(SecurityManager::LOCAL_WITH_NETWORK); LOG(LOG_INFO, _("Switched to local-with-networking sandbox by FileAttributesTag")); } } @@ -1512,7 +1515,7 @@ delete tag; break; } - if(getSys()->shouldTerminate() || threadAborting) + if(root->getSystemState()->shouldTerminate() || threadAborting) break; } } @@ -1961,9 +1964,9 @@ void SystemState::showMouseCursor(bool visible) { if (visible) - EngineData::runInMainThread(&EngineData::showMouseCursor); + engineData->runInMainThread(this,&EngineData::showMouseCursor); else - EngineData::runInMainThread(&EngineData::hideMouseCursor); + engineData->runInMainThread(this,&EngineData::hideMouseCursor); } void SystemState::waitRendering()
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
.