From c09dab2b3aa045d91acc6f552981e103fbf91f2b Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 9 Jan 2017 17:12:53 +0400 Subject: [PATCH] MediaView save message fixed. Sticker pan size updated correctly. --- Telegram/SourceFiles/media/media_audio.cpp | 13 +++++-------- .../SourceFiles/media/media_audio_ffmpeg_loader.cpp | 10 ++++------ .../SourceFiles/media/media_child_ffmpeg_loader.cpp | 4 +--- Telegram/SourceFiles/media/media_clip_ffmpeg.cpp | 6 +++--- Telegram/SourceFiles/mediaview.cpp | 1 - Telegram/SourceFiles/stickers/emoji_pan.cpp | 5 +++-- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/media/media_audio.cpp b/Telegram/SourceFiles/media/media_audio.cpp index c47aefa44..cd1635a25 100644 --- a/Telegram/SourceFiles/media/media_audio.cpp +++ b/Telegram/SourceFiles/media/media_audio.cpp @@ -1604,13 +1604,11 @@ void AudioCaptureInner::onStop(bool needResult) { d->opened = false; } if (d->ioContext) { - av_free(d->ioContext->buffer); - av_free(d->ioContext); - d->ioContext = nullptr; + av_freep(&d->ioContext->buffer); + av_freep(&d->ioContext); d->ioBuffer = nullptr; } else if (d->ioBuffer) { - av_free(d->ioBuffer); - d->ioBuffer = nullptr; + av_freep(&d->ioBuffer); } if (d->fmtContext) { avformat_free_context(d->fmtContext); @@ -1746,9 +1744,8 @@ void AudioCaptureInner::processFrame(int32 offset, int32 framesize) { d->dstSamples = av_rescale_rnd(swr_get_delay(d->swrContext, d->codecContext->sample_rate) + d->srcSamples, d->codecContext->sample_rate, d->codecContext->sample_rate, AV_ROUND_UP); if (d->dstSamples > d->maxDstSamples) { d->maxDstSamples = d->dstSamples; - av_free(d->dstSamplesData[0]); - - if ((res = av_samples_alloc(d->dstSamplesData, 0, d->codecContext->channels, d->dstSamples, d->codecContext->sample_fmt, 0)) < 0) { + av_freep(&d->dstSamplesData[0]); + if ((res = av_samples_alloc(d->dstSamplesData, 0, d->codecContext->channels, d->dstSamples, d->codecContext->sample_fmt, 1)) < 0) { LOG(("Audio Error: Unable to av_samples_alloc for capture, error %1, %2").arg(res).arg(av_make_error_string(err, sizeof(err), res))); onStop(false); emit error(); diff --git a/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp b/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp index 65fd1118a..c612870dc 100644 --- a/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp +++ b/Telegram/SourceFiles/media/media_audio_ffmpeg_loader.cpp @@ -80,10 +80,10 @@ AbstractFFMpegLoader::~AbstractFFMpegLoader() { avformat_close_input(&fmtContext); } if (ioContext) { - av_free(ioContext->buffer); - av_free(ioContext); + av_freep(&ioContext->buffer); + av_freep(&ioContext); } else if (ioBuffer) { - av_free(ioBuffer); + av_freep(&ioBuffer); } if (fmtContext) avformat_free_context(fmtContext); } @@ -294,10 +294,8 @@ AudioPlayerLoader::ReadResult FFMpegLoader::readFromReadyFrame(QByteArray &resul int64_t dstSamples = av_rescale_rnd(swr_get_delay(swrContext, srcRate) + frame->nb_samples, dstRate, srcRate, AV_ROUND_UP); if (dstSamples > maxResampleSamples) { maxResampleSamples = dstSamples; - av_free(dstSamplesData[0]); - + av_freep(&dstSamplesData[0]); if ((res = av_samples_alloc(dstSamplesData, 0, AudioToChannels, maxResampleSamples, AudioToFormat, 1)) < 0) { - dstSamplesData[0] = 0; char err[AV_ERROR_MAX_STRING_SIZE] = { 0 }; LOG(("Audio Error: Unable to av_samples_alloc for file '%1', data size '%2', error %3, %4").arg(file.name()).arg(data.size()).arg(res).arg(av_make_error_string(err, sizeof(err), res))); return ReadResult::Error; diff --git a/Telegram/SourceFiles/media/media_child_ffmpeg_loader.cpp b/Telegram/SourceFiles/media/media_child_ffmpeg_loader.cpp index 20b645721..8894ee0e8 100644 --- a/Telegram/SourceFiles/media/media_child_ffmpeg_loader.cpp +++ b/Telegram/SourceFiles/media/media_child_ffmpeg_loader.cpp @@ -167,10 +167,8 @@ AudioPlayerLoader::ReadResult ChildFFMpegLoader::readFromReadyFrame(QByteArray & int64_t dstSamples = av_rescale_rnd(swr_get_delay(_swrContext, _srcRate) + _frame->nb_samples, _dstRate, _srcRate, AV_ROUND_UP); if (dstSamples > _maxResampleSamples) { _maxResampleSamples = dstSamples; - av_free(_dstSamplesData[0]); - + av_freep(&_dstSamplesData[0]); if ((res = av_samples_alloc(_dstSamplesData, 0, AudioToChannels, _maxResampleSamples, AudioToFormat, 1)) < 0) { - _dstSamplesData[0] = 0; char err[AV_ERROR_MAX_STRING_SIZE] = { 0 }; LOG(("Audio Error: Unable to av_samples_alloc for file '%1', data size '%2', error %3, %4").arg(file.name()).arg(data.size()).arg(res).arg(av_make_error_string(err, sizeof(err), res))); return ReadResult::Error; diff --git a/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp b/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp index b2edae852..fe6d7cdb3 100644 --- a/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp +++ b/Telegram/SourceFiles/media/media_clip_ffmpeg.cpp @@ -468,10 +468,10 @@ FFMpegReaderImplementation::~FFMpegReaderImplementation() { avformat_close_input(&_fmtContext); } if (_ioContext) { - av_free(_ioContext->buffer); - av_free(_ioContext); + av_freep(&_ioContext->buffer); + av_freep(&_ioContext); } else if (_ioBuffer) { - av_free(_ioBuffer); + av_freep(&_ioBuffer); } if (_fmtContext) avformat_free_context(_fmtContext); av_frame_free(&_frame); diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index db0fd7b28..db93672f2 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -616,7 +616,6 @@ void MediaView::clearData() { _photo = _additionalChatPhoto = nullptr; _doc = nullptr; _fullScreenVideo = false; - _saveMsgText.clear(); _caption.clear(); } diff --git a/Telegram/SourceFiles/stickers/emoji_pan.cpp b/Telegram/SourceFiles/stickers/emoji_pan.cpp index a821632a6..846edab15 100644 --- a/Telegram/SourceFiles/stickers/emoji_pan.cpp +++ b/Telegram/SourceFiles/stickers/emoji_pan.cpp @@ -2983,11 +2983,12 @@ int EmojiPan::countBottom() const { void EmojiPan::moveByBottom() { if (inlineResultsShown()) { setOrigin(Ui::PanelAnimation::Origin::BottomLeft); - moveToLeft(0, countBottom() - height()); + moveToLeft(0, y()); } else { setOrigin(Ui::PanelAnimation::Origin::BottomRight); - moveToRight(0, countBottom() - height()); + moveToRight(0, y()); } + updateContentHeight(); } void EmojiPan::enterEvent(QEvent *e) {