diff options
| author | woro <woro@e10066b5-e1e2-0310-b819-94efdf66514b> | 2008-04-14 16:22:35 +0000 |
|---|---|---|
| committer | woro <woro@e10066b5-e1e2-0310-b819-94efdf66514b> | 2008-04-14 16:22:35 +0000 |
| commit | f7a125fe5d8eee969b7a7eceb9f43ee051bd4e7a (patch) | |
| tree | 89528daeafd7cda365d5a78c1fded29f86c1301a | |
| parent | 1b687bca32dd4561b6d3aa53cb338604665e8289 (diff) | |
| download | vdr-plugin-muggle-f7a125fe5d8eee969b7a7eceb9f43ee051bd4e7a.tar.gz vdr-plugin-muggle-f7a125fe5d8eee969b7a7eceb9f43ee051bd4e7a.tar.bz2 | |
convert images in background processes, not sure if this helps
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@1188 e10066b5-e1e2-0310-b819-94efdf66514b
| -rw-r--r-- | mg_image_provider.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/mg_image_provider.c b/mg_image_provider.c index 5ef7449..5766d9e 100644 --- a/mg_image_provider.c +++ b/mg_image_provider.c @@ -109,7 +109,9 @@ mgImageProvider::mgImageProvider(tArea area ) { } mgMpgImageProvider::~mgMpgImageProvider() { + Lock(); m_converted_images.clear(); + Unlock(); } bool mgImageProvider::extractImagesFromDatabase() { @@ -349,22 +351,41 @@ void mgMpgImageProvider::Action() { mgItemGd *cnvItem = currItem; Unlock(); for( unsigned i=0; i < images.size(); i++ ) { - string tmpFile = getCachedMPGFile(cnvItem,images[i]); - char *tmp; - msprintf( &tmp, "%s/scripts/muggle-image-convert \"%s\" \"%s\" %d %d %d %d", the_setup.ConfigDirectory.c_str(), - images[i].c_str(), tmpFile.c_str(), + if (i>0) + // sleep 1 sec: we don't want to start all image conversions simultaneously + usleep(1000*1000); + string cachedFile = getCachedMPGFile(cnvItem,images[i]); + char *cmd; + msprintf( &cmd, "%s/scripts/muggle-image-convert \"%s\" \"%s\" %d %d %d %d &", + the_setup.ConfigDirectory.c_str(), + images[i].c_str(), cachedFile.c_str(), coverarea.x1,coverarea.y1,coverarea.Width(),coverarea.Height() ); - mgDebug(1,"%d %s",system( (const char*) tmp ),tmp); - free(tmp); - // if file can be read by process, add to the list of converted images - if( !access( tmpFile.c_str(), R_OK ) ) { + mgDebug(5,"%d %s",system( (const char*) cmd ),cmd); + free(cmd); + } + int waitcount=0; + while (images.size() && waitcount<20) { // wait up to 20 seconds for all conversions + for( unsigned i=0; i < images.size(); i++ ) { Lock(); - m_converted_images.push_back( tmpFile ); + mgItemGd *expectItem = currItem; Unlock(); + if (expectItem!=cnvItem) { + images.clear(); + break; + } + string cachedFile = getCachedMPGFile(cnvItem,images[i]); + // if file can be read by process, add to the list of converted images + if( !access( cachedFile.c_str(), R_OK ) ) { + Lock(); + m_converted_images.push_back( cachedFile ); + Unlock(); + images.erase(images.begin()+i); + } } - // Check whether we need to continue this!? Next song may be playing already... + // wait 1/2 second + usleep(1000*500); + waitcount++; } - // cout << "Image conversion thread ending." << endl << flush; } void mgImageProvider::fillImageList( string dir ) { |
