mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
ffmpeg threadsafety critical bug fixed, display gif time and status / views added, 0.9.18
This commit is contained in:
parent
f2824f79f6
commit
afb40b8289
5 changed files with 51 additions and 29 deletions
|
@ -97,11 +97,6 @@ bool _checkALError() {
|
|||
Q_DECLARE_METATYPE(AudioMsgId);
|
||||
Q_DECLARE_METATYPE(SongMsgId);
|
||||
void audioInit() {
|
||||
if (!audioDevice) {
|
||||
av_register_all();
|
||||
avcodec_register_all();
|
||||
}
|
||||
|
||||
if (!capture) {
|
||||
capture = new AudioCapture();
|
||||
cSetHasAudioCapture(capture->check());
|
||||
|
@ -114,7 +109,7 @@ void audioInit() {
|
|||
LOG(("Audio Error: default sound device not present."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ALCint attributes[] = { ALC_STEREO_SOURCES, 8, 0 };
|
||||
audioContext = alcCreateContext(audioDevice, attributes);
|
||||
alcMakeContextCurrent(audioContext);
|
||||
|
@ -516,7 +511,7 @@ void AudioPlayer::play(const SongMsgId &song, int64 position) {
|
|||
|
||||
bool AudioPlayer::checkCurrentALError(MediaOverviewType type) {
|
||||
if (_checkALError()) return true;
|
||||
|
||||
|
||||
switch (type) {
|
||||
case OverviewAudios:
|
||||
setStoppedState(&_audioData[_audioCurrent], AudioPlayerStoppedAtError);
|
||||
|
@ -1091,7 +1086,7 @@ protected:
|
|||
|
||||
QFile f;
|
||||
int32 dataPos;
|
||||
|
||||
|
||||
bool openFile() {
|
||||
if (data.isEmpty()) {
|
||||
if (f.isOpen()) f.close();
|
||||
|
@ -1884,7 +1879,7 @@ void AudioCaptureInner::onInit() {
|
|||
}
|
||||
|
||||
void AudioCaptureInner::onStart() {
|
||||
|
||||
|
||||
// Start OpenAL Capture
|
||||
const ALCchar *dName = alcGetString(0, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
|
||||
DEBUG_LOG(("Audio Info: Capture device name '%1'").arg(dName));
|
||||
|
@ -1905,7 +1900,7 @@ void AudioCaptureInner::onStart() {
|
|||
// Create encoding context
|
||||
|
||||
d->ioBuffer = (uchar*)av_malloc(AVBlockSize);
|
||||
|
||||
|
||||
d->ioContext = avio_alloc_context(d->ioBuffer, AVBlockSize, 1, static_cast<void*>(d), &AudioCapturePrivate::_read_data, &AudioCapturePrivate::_write_data, &AudioCapturePrivate::_seek_data);
|
||||
int res = 0;
|
||||
char err[AV_ERROR_MAX_STRING_SIZE] = { 0 };
|
||||
|
@ -2390,7 +2385,7 @@ public:
|
|||
QString title() {
|
||||
return _title;
|
||||
}
|
||||
|
||||
|
||||
QString performer() {
|
||||
return _performer;
|
||||
}
|
||||
|
|
|
@ -4596,18 +4596,15 @@ void HistoryGif::draw(Painter &p, const HistoryItem *parent, const QRect &r, boo
|
|||
p.setFont(st::normalFont);
|
||||
p.setPen(st::white);
|
||||
p.drawTextLeft(statusX, statusY, _width, _statusText, statusW - 2 * st::msgDateImgPadding.x());
|
||||
|
||||
// date
|
||||
if (_caption.isEmpty() && parent->getMedia() == this) {
|
||||
int32 fullRight = skipx + width, fullBottom = skipy + height;
|
||||
parent->drawInfo(p, fullRight, fullBottom, 2 * skipx + width, selected, InfoDisplayOverImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!_caption.isEmpty()) {
|
||||
p.setPen(st::black);
|
||||
_caption.draw(p, st::msgPadding.left(), skipy + height + st::mediaPadding.bottom() + st::mediaCaptionSkip, captionw);
|
||||
} else if (parent->getMedia() == this) {
|
||||
int32 fullRight = skipx + width, fullBottom = skipy + height;
|
||||
parent->drawInfo(p, fullRight, fullBottom, 2 * skipx + width, selected, InfoDisplayOverImage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ int main(int argc, char *argv[]) {
|
|||
//signal(SIGSEGV, _sigsegvHandler);
|
||||
#endif
|
||||
|
||||
InitOpenSSL _init;
|
||||
LibrariesInitializer _init;
|
||||
|
||||
settingsParseArgs(argc, argv);
|
||||
for (int32 i = 0; i < argc; ++i) {
|
||||
|
|
|
@ -99,7 +99,7 @@ namespace {
|
|||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
_msgIdMsStart = 1000000000 * uint64(ts.tv_sec) + uint64(ts.tv_nsec);
|
||||
#endif
|
||||
|
||||
|
||||
uint32 msgIdRand;
|
||||
memset_rand(&msgIdRand, sizeof(uint32));
|
||||
_msgIdStart = (((uint64)((uint32)unixtime()) << 32) | (uint64)msgIdRand);
|
||||
|
@ -187,6 +187,32 @@ namespace {
|
|||
delete l;
|
||||
}
|
||||
|
||||
int _ffmpegLockManager(void **mutex, AVLockOp op) {
|
||||
switch (op) {
|
||||
case AV_LOCK_CREATE: {
|
||||
t_assert(*mutex == 0);
|
||||
*mutex = reinterpret_cast<void*>(new QMutex());
|
||||
} break;
|
||||
|
||||
case AV_LOCK_OBTAIN: {
|
||||
t_assert(*mutex != 0);
|
||||
reinterpret_cast<QMutex*>(*mutex)->lock();
|
||||
} break;
|
||||
|
||||
case AV_LOCK_RELEASE: {
|
||||
t_assert(*mutex != 0);
|
||||
reinterpret_cast<QMutex*>(*mutex)->unlock();
|
||||
}; break;
|
||||
|
||||
case AV_LOCK_DESTROY: {
|
||||
t_assert(*mutex != 0);
|
||||
delete reinterpret_cast<QMutex*>(*mutex);
|
||||
*mutex = 0;
|
||||
} break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
float64 _msFreq;
|
||||
float64 _msgIdCoef;
|
||||
int64 _msStart = 0, _msAddToMsStart = 0, _msAddToUnixtime = 0;
|
||||
|
@ -238,7 +264,7 @@ namespace {
|
|||
_MsStarter _msStarter;
|
||||
}
|
||||
|
||||
InitOpenSSL::InitOpenSSL() {
|
||||
LibrariesInitializer::LibrariesInitializer() {
|
||||
if (!RAND_status()) { // should be always inited in all modern OS
|
||||
char buf[16];
|
||||
memcpy(buf, &_msStart, 8);
|
||||
|
@ -262,10 +288,17 @@ InitOpenSSL::InitOpenSSL() {
|
|||
CRYPTO_set_dynlock_lock_callback(_sslLockFunction);
|
||||
CRYPTO_set_dynlock_destroy_callback(_sslDestroyFunction);
|
||||
|
||||
av_register_all();
|
||||
avcodec_register_all();
|
||||
|
||||
av_lockmgr_register(_ffmpegLockManager);
|
||||
|
||||
_sslInited = true;
|
||||
}
|
||||
|
||||
InitOpenSSL::~InitOpenSSL() {
|
||||
LibrariesInitializer::~LibrariesInitializer() {
|
||||
av_lockmgr_register(0);
|
||||
|
||||
delete[] _sslLocks;
|
||||
_sslLocks = 0;
|
||||
}
|
||||
|
@ -640,10 +673,7 @@ char *hashMd5Hex(const int32 *hashmd5, void *dest) {
|
|||
}
|
||||
|
||||
void memset_rand(void *data, uint32 len) {
|
||||
if (!_sslInited) {
|
||||
LOG(("Critical Error: memset_rand() called before OpenSSL init!"));
|
||||
exit(-1);
|
||||
}
|
||||
t_assert(_sslInited);
|
||||
RAND_bytes((uchar*)data, len);
|
||||
}
|
||||
|
||||
|
|
|
@ -133,10 +133,10 @@ inline void mylocaltime(struct tm * _Tm, const time_t * _Time) {
|
|||
#endif
|
||||
}
|
||||
|
||||
class InitOpenSSL {
|
||||
class LibrariesInitializer {
|
||||
public:
|
||||
InitOpenSSL();
|
||||
~InitOpenSSL();
|
||||
LibrariesInitializer();
|
||||
~LibrariesInitializer();
|
||||
};
|
||||
|
||||
bool checkms(); // returns true if time has changed
|
||||
|
@ -144,7 +144,7 @@ uint64 getms(bool checked = false);
|
|||
|
||||
class SingleTimer : public QTimer { // single shot timer with check
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
|
||||
SingleTimer();
|
||||
|
|
Loading…
Add table
Reference in a new issue