summaryrefslogtreecommitdiff
path: root/FacilityEngine.cpp
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2020-08-11 22:35:12 +0100
committerThomas Preud'homme <robotux@celest.fr>2020-08-11 22:35:12 +0100
commit3ac113857071fc1f225b2e1b42547269e568c6b7 (patch)
tree8b28dd9c44a0d3c7ab8187cd8d8f19d47591d813 /FacilityEngine.cpp
parent9b10c21f5cad0e2ec27d23c59e65af7141a226f3 (diff)
New upstream version 2.2.4.4
Diffstat (limited to 'FacilityEngine.cpp')
-rwxr-xr-x[-rw-r--r--]FacilityEngine.cpp103
1 files changed, 102 insertions, 1 deletions
diff --git a/FacilityEngine.cpp b/FacilityEngine.cpp
index 185492a..b96c932 100644..100755
--- a/FacilityEngine.cpp
+++ b/FacilityEngine.cpp
@@ -13,6 +13,11 @@
#endif
#include <windows.h>
#endif
+#ifndef NOAUDIO
+#include "opusfile/opusfile.h"
+#include <QAudioOutput>
+#include <QCoreApplication>
+#endif
FacilityEngine FacilityEngine::facilityEngine;
@@ -73,6 +78,7 @@ void FacilityEngine::retranslate()
translations["Copying"]=tr("Copying").toStdString();
translations["Listing and copying"]=tr("Listing and copying").toStdString();
translations["Time remaining:"]=tr("Time remaining:").toStdString();
+ translations["Remaining:"]=tr("Remaining:").toStdString();
//for copy engine
translations["Ask"]=tr("Ask").toStdString();
translations["Skip"]=tr("Skip").toStdString();
@@ -230,21 +236,29 @@ std::string FacilityEngine::simplifiedRemainingTime(const uint32_t &seconds) con
/// \brief Return ultimate url, empty is not found or already ultimate
std::string FacilityEngine::ultimateUrl() const
{
+ #ifndef ULTRACOPIER_LITTLE
if(ProductKey::productKey->isUltimate())
return std::string();
else
{
- #if defined(Q_OS_WIN32) || defined(Q_OS_MAC)
+ #if ! defined(Q_OS_LINUX)
return "https://shop.first-world.info/";
#else
return std::string();
#endif
}
+ #else
+ return std::string();
+ #endif
}
bool FacilityEngine::isUltimate() const
{
+ #ifndef ULTRACOPIER_LITTLE
return ProductKey::productKey->isUltimate();
+ #else
+ return true;
+ #endif
}
/// \brief Return the software name
@@ -256,3 +270,90 @@ std::string FacilityEngine::softwareName() const
return "Ultracopier";
#endif
}
+
+/// \brief return audio if created from opus file, nullptr if failed
+void *FacilityEngine::prepareOpusAudio(const std::string &file,QBuffer &buffer) const
+{
+ #ifndef NOAUDIO
+ if(file.empty())
+ return nullptr;
+
+ QAudioOutput* audio;
+ QAudioFormat format;
+ format.setSampleRate(48000);
+ format.setChannelCount(2);
+ format.setSampleSize(16);
+ format.setCodec("audio/pcm");
+ format.setByteOrder(QAudioFormat::LittleEndian);
+ format.setSampleType(QAudioFormat::SignedInt);
+
+ QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
+ if (!info.isFormatSupported(format)) {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"raw audio format not supported by backend, cannot play audio.");
+ return nullptr;
+ }
+ audio = new QAudioOutput(format);
+ buffer.open(QBuffer::ReadWrite);
+
+ int ret;
+ std::string path=file;
+ if(path.find("/") == std::string::npos && path.find("\\") == std::string::npos)
+ {
+ QString appPath=QCoreApplication::applicationDirPath();
+ if(appPath.endsWith("/") || appPath.endsWith("\\"))
+ path=appPath.toStdString()+path;
+ else
+ path=appPath.toStdString()+"/"+path;
+ }
+ OggOpusFile *of=op_open_file(file.c_str(),&ret);
+ if(of==NULL) {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Failed to open file"+file+", "+std::to_string(ret));
+ return nullptr;
+ }
+ ogg_int64_t pcm_offset;
+ ogg_int64_t nsamples;
+ nsamples=0;
+ pcm_offset=op_pcm_tell(of);
+ if(pcm_offset!=0)
+ fprintf(stderr,"Non-zero starting PCM offset: %li\n",(long)pcm_offset);
+ for(;;) {
+ ogg_int64_t next_pcm_offset;
+ opus_int16 pcm[120*48*2];
+ unsigned char out[120*48*2*2];
+ int si;
+ ret=op_read_stereo(of,pcm,sizeof(pcm)/sizeof(*pcm));
+ if(ret==OP_HOLE) {
+ fprintf(stderr,"\nHole detected! Corrupt file segment?\n");
+ continue;
+ }
+ else if(ret<0) {
+ fprintf(stderr,"\nError decoding '%s': %i\n","file.opus",ret);
+ ret=EXIT_FAILURE;
+ break;
+ }
+ next_pcm_offset=op_pcm_tell(of);
+ pcm_offset=next_pcm_offset;
+ if(ret<=0) {
+ ret=EXIT_SUCCESS;
+ break;
+ }
+ for(si=0;si<2*ret;si++) { /// Ensure the data is little-endian before writing it out.
+ out[2*si+0]=(unsigned char)(pcm[si]&0xFF);
+ out[2*si+1]=(unsigned char)(pcm[si]>>8&0xFF);
+ }
+ buffer.write(reinterpret_cast<char *>(out),sizeof(*out)*4*ret);
+ nsamples+=ret;
+ }
+ if(ret==EXIT_SUCCESS)
+ fprintf(stderr,"\nDone: played ");
+ op_free(of);
+
+ buffer.seek(0);
+ return audio;
+ // audio->start(&buffer); -> do out of this function
+ #else
+ (void)file;
+ (void)buffer;
+ return nullptr;
+ #endif
+}