/client/AnyVODClient/src/media/MediaPresenter.cpp
C++ | 8316 lines | 6631 code | 1670 blank | 15 comment | 1083 complexity | 4488bebedeed7fa07cfa0faac6f830f4 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*************************************************************************
- Copyright (c) 2011-2017, DongRyeol Cha (chadr@dcple.com)
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>
- *************************************************************************/
- #include <QGlobalStatic>
- #define GL_NV_geometry_program4
- #ifndef Q_OS_WIN
- #define GL_GLEXT_PROTOTYPES
- #endif
- #ifdef Q_OS_WIN
- #ifdef _WIN32_WINNT
- #undef _WIN32_WINNT
- #endif
- #define _WIN32_WINNT 0x0501
- #endif
- #ifndef UNICODE
- #define UNICODE
- #endif
- #ifndef _UNICODE
- #define _UNICODE
- #endif
- #include "MediaPresenter.h"
- #include "MediaState.h"
- #include "core/Utils.h"
- #include "video/Sphere.h"
- #include "media/FrameExtractor.h"
- #if !defined Q_OS_MOBILE
- #include "ui/MainWindow.h"
- #endif
- extern "C"
- {
- #include <libavutil/pixdesc.h>
- #include <libavutil/time.h>
- #include <libavutil/audio_fifo.h>
- #include <libavutil/imgutils.h>
- #include <libswresample/swresample.h>
- #include <libswscale/swscale.h>
- #if !defined Q_OS_MOBILE
- #include <libavdevice/avdevice.h>
- #endif
- }
- #include <ass/ass.h>
- #include <bass/bass_fx.h>
- #include <bass/bassmix.h>
- #ifndef Q_OS_MAC
- #include <omp.h>
- #endif
- #if !defined Q_OS_MOBILE
- #include <MediaInfoDLL/MediaInfoDLL.h>
- #endif
- #if !defined Q_OS_MOBILE
- #include <QApplication>
- #include <QDesktopWidget>
- #endif
- #include <algorithm>
- #include <QStringList>
- #include <QFileInfo>
- #include <qmath.h>
- #include <QTextStream>
- #include <QMutexLocker>
- #include <QRect>
- #include <QPainter>
- #include <QFile>
- #include <QDir>
- #include <QOpenGLFramebufferObject>
- #include <QTemporaryFile>
- #if defined Q_OS_MOBILE
- #include <QOpenGLFunctions>
- #endif
- #include <QDebug>
- #ifdef Q_OS_MAC
- #include <mach/task_info.h>
- #include <mach/task.h>
- #include <mach/mach_init.h>
- #include <mach/mach_traps.h>
- #include <mach/mach_port.h>
- #include <mach/vm_map.h>
- #include <mach/thread_act.h>
- #include <mach/host_info.h>
- #include <mach/mach_host.h>
- #endif
- using namespace std;
- #if !defined Q_OS_MOBILE
- using namespace MediaInfoDLL;
- #endif
- #ifdef Q_OS_WIN
- extern PFNGLBINDBUFFERARBPROC glBindBufferARB;
- extern PFNGLBUFFERDATAARBPROC glBufferDataARB;
- extern PFNGLMAPBUFFERARBPROC glMapBufferARB;
- extern PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB;
- extern PFNGLACTIVETEXTUREPROC glActiveTextureARB;
- #endif
- const int MediaPresenter::DEFAULT_VIRT_SUBTITLE_RATIO = 10;
- const int MediaPresenter::DEFAULT_HORI_SUBTITLE_RATIO = 10;
- const int MediaPresenter::OPTION_DESC_TIME = 3000;
- const QString MediaPresenter::SUBTITLE_CODEC_FORMAT = "%1 (%2)";
- const QPoint MediaPresenter::DEFAULT_3D_SUBTITLE_OFFSET = QPoint(2, 0);
- const QPoint MediaPresenter::DEFAULT_VR_SUBTITLE_OFFSET = QPoint(-4, 0);
- const qreal MediaPresenter::DEFAULT_VIRTUAL_3D_DEPTH = 0.15;
- const AVPixelFormat MediaPresenter::DEFAULT_PIX_FORMAT = AV_PIX_FMT_BGR32;
- VirtualFile MediaPresenter::VIRTUAL_FILE;
- DTVReader MediaPresenter::DTV_READER;
- QDataStream& operator << (QDataStream &out, const MediaPresenter::Range &item)
- {
- out << item.start;
- out << item.end;
- out << item.enable;
- return out;
- }
- QDataStream& operator >> (QDataStream &in, MediaPresenter::Range &item)
- {
- in >> item.start;
- in >> item.end;
- in >> item.enable;
- return in;
- }
- #ifdef Q_OS_ANDROID
- static void ff_log_callback(void*, int level, const char *fmt, va_list vl)
- {
- if (level <= av_log_get_level())
- {
- char buf[1024];
- vsnprintf(buf, sizeof(buf), fmt, vl);
- }
- }
- #endif
- MediaPresenter::MediaPresenter(const int width, const int height) :
- QThread(),
- m_volume(this->getMaxVolume() / 2),
- m_width(width),
- m_height(height),
- m_state(nullptr),
- m_forceExit(false),
- m_format(DEFAULT_PIX_FORMAT),
- m_showDetail(false),
- m_isMute(false),
- m_subtitleFontSize(0),
- m_showSubtitle(true),
- m_showOptionDesc(false),
- m_showingOptionDesc(false),
- m_subtitleSync(0.0),
- m_audioSync(0.0),
- m_isRemoteFile(false),
- m_isRemoteProtocol(false),
- m_fontSize(0),
- m_fontOutlineSize(1),
- m_subtitleOutlineSize(0),
- m_subtitleMaxOutlineSize(0),
- m_lastAudioStream(-1),
- m_lastSubtitleStream(-1),
- m_vertPosition(0),
- m_horiPosition(0),
- m_texInfo(nullptr),
- m_isAudioExt(false),
- m_halign(AnyVODEnums::HAM_NONE),
- m_valign(AnyVODEnums::VAM_NONE),
- m_3dMethod(AnyVODEnums::V3M_NONE),
- m_3dSubtitleMethod(AnyVODEnums::S3M_NONE),
- m_vrInputSource(AnyVODEnums::VRI_NONE),
- m_seekKeyFrame(true),
- m_skipOpening(false),
- m_skipEnding(false),
- m_useSkipRange(false),
- m_subtitleOpaque(1.0f),
- m_subtitleSize(1.0f),
- #if defined Q_OS_MOBILE
- m_useHWDecoder(true),
- #else
- m_useHWDecoder(false),
- #endif
- m_useSPDIF(false),
- m_userSPDIFSampleRate(0),
- m_usePBO(false),
- m_enableSearchSubtitle(false),
- m_enableSearchLyrics(false),
- m_autoSaveSearchLyrics(false),
- m_showAlbumJacket(true),
- #if defined Q_OS_MOBILE
- m_useFrameDrop(true),
- #else
- m_useFrameDrop(false),
- #endif
- m_useBufferingMode(false),
- m_SPIDFEncodingMethod(AnyVODEnums::SEM_NONE),
- m_screenRotationDegree(AnyVODEnums::SRD_NONE),
- m_use3DFull(false),
- m_maxTextureSize(0),
- #if defined Q_OS_MOBILE
- m_useGPUConvert(true),
- #else
- m_useGPUConvert(false),
- #endif
- m_anaglyphFrameBuffer(nullptr),
- m_distortionFrameBuffer(nullptr),
- m_leftDistortionFrameBuffer(nullptr),
- m_rightDistortionFrameBuffer(nullptr),
- m_videoThread(this),
- m_subtitleThread(this),
- m_readThread(this),
- m_refreshThread(this),
- #if defined Q_OS_MOBILE
- m_gl(nullptr),
- #endif
- m_audioDevice(-1),
- m_rotation(0.0),
- m_sensorRotation(0.0),
- m_optionDescY(0),
- m_scheduleRecomputeSubtitleSize(false),
- m_useSubtitleCacheMode(false),
- m_devicePixelRatio(1.0),
- m_captureMode(false),
- m_useLowQualityMode(true),
- m_controlLocker(QMutex::Recursive),
- m_screenOffset(0, 0),
- m_useDistortion(true),
- m_barrelDistortionCoefficients(0.05f, 0.20f),
- m_pincushionDistortionCoefficients(0.075f, -0.005f),
- m_distortionLensCenter(0.0f, 0.0f),
- m_cameraLock(QMutex::Recursive),
- m_distortionAdjustMode(AnyVODEnums::DAM_NONE),
- m_virtual3DDepth(DEFAULT_VIRTUAL_3D_DEPTH),
- m_subtitleType(ST_NONE),
- m_isLive(false),
- m_bluetoothHeadsetConnected(false),
- m_bluetoothHeadsetSync(0.0)
- {
- this->reset3DSubtitleOffset();
- }
- MediaPresenter::~MediaPresenter()
- {
- this->close();
- this->clearFrameBuffers();
- }
- void MediaPresenter::init()
- {
- av_log_set_level(AV_LOG_QUIET);
- #ifdef Q_OS_ANDROID
- av_log_set_callback(ff_log_callback);
- #endif
- ffurl_append_protocol(DTV_READER.getProtocol());
- ffurl_append_protocol(VIRTUAL_FILE.getProtocol());
- #if !defined Q_OS_MOBILE
- avdevice_register_all();
- #endif
- avfilter_register_all();
- avcodec_register_all();
- av_register_all();
- avformat_network_init();
- Sphere::init();
- }
- void MediaPresenter::deInit()
- {
- avformat_network_deinit();
- Sphere::deInit();
- }
- bool MediaPresenter::open(const QString &filePath, const QString &title, const ExtraPlayData &data,
- const QString &fontFamily, const int fontSize, const int subtitleOutlineSize,
- const QString &audioPath)
- {
- this->m_filePath = filePath;
- this->m_audioPath = audioPath;
- this->m_isRemoteFile = Utils::determinRemoteFile(filePath);
- this->m_isRemoteProtocol = Utils::determinRemoteProtocol(filePath);
- this->m_isLive = filePath.startsWith("hls+");
- this->m_realFilePath = Utils::removeFFMpegSeparator(filePath);
- this->m_title = title;
- if (!data.isValid())
- {
- #if !defined Q_OS_MOBILE
- MediaInfo mi;
- bool isDevice = false;
- isDevice = Utils::determinDevice(filePath);
- if (!isDevice && mi.Open(filePath.toStdWString()) == 1)
- {
- QString totalTime = QString::fromStdWString(mi.Get(Stream_General, 0, __T("Duration")));
- QString totalFrame = QString::fromStdWString(mi.Get(Stream_Video, 0, __T("FrameCount")));
- if (totalTime.toDouble() < 0.0)
- this->m_playData.duration = 0.0;
- else
- this->m_playData.duration = totalTime.toDouble() / 1000.0;
- this->m_playData.totalFrame = totalFrame.toUInt();
- if (this->m_playData.totalFrame <= 0)
- {
- QString frameRate = QString::fromStdWString(mi.Get(Stream_Video, 0, __T("FrameRate")));
- if (frameRate.isEmpty())
- frameRate = QString::fromStdWString(mi.Get(Stream_Video, 0, __T("FrameRate_Original")));
- if (frameRate.toDouble() < 0)
- this->m_playData.totalFrame = 0;
- else
- this->m_playData.totalFrame = uint32_t(frameRate.toDouble() * this->m_playData.duration);
- }
- QString rotation = QString::fromStdWString(mi.Get(Stream_Video, 0, __T("Rotation")));
- this->m_rotation = rotation.toDouble();
- mi.Close();
- }
- #endif
- this->m_playData.userData = data.userData;
- }
- else
- {
- this->m_playData = data;
- }
- this->m_fontFamily = fontFamily;
- this->m_fontSize = fontSize * this->m_devicePixelRatio;
- this->m_fontOutlineSize = 1 * this->m_devicePixelRatio;
- this->m_subtitleMaxOutlineSize = subtitleOutlineSize * this->m_devicePixelRatio;
- QFileInfo fileInfo(this->m_realFilePath);
- this->m_isAudioExt = Utils::isExtension(fileInfo.suffix(), Utils::MT_AUDIO);
- return true;
- }
- void MediaPresenter::openRemoteSubtitle(const QString &filePath)
- {
- VIRTUAL_FILE.loadSubtitle(filePath, this);
- }
- bool MediaPresenter::saveSubtitleAs(const QString &filePath)
- {
- bool success = false;
- double sync = -this->m_subtitleSync;
- if (this->m_samiParser.isExist())
- success = this->m_samiParser.save(filePath, sync);
- else if (this->m_srtParser.isExist())
- success = this->m_srtParser.save(filePath, sync);
- else if (this->m_lrcParser.isExist())
- success = this->m_lrcParser.save(filePath, sync);
- else if (this->m_youtubeParser.isExist())
- success = this->m_youtubeParser.save(filePath, sync);
- return success;
- }
- bool MediaPresenter::saveSubtitle()
- {
- return this->saveSubtitleAs(this->m_subtitleFilePath);
- }
- QString MediaPresenter::getSubtitlePath() const
- {
- return this->m_subtitleFilePath;
- }
- bool MediaPresenter::openSubtitle(const QString &filePath, bool isExternal)
- {
- bool success = false;
- QFileInfo info(filePath);
- QString ext = info.suffix().toLower();
- if (ext == "smi" || ext == "sami")
- success = this->openSAMI(filePath) || this->openSRT(filePath);
- else if (ext == "ass" || ext == "ssa")
- success = this->openASS(filePath);
- else if (ext == "srt")
- success = this->openSRT(filePath) || this->openSAMI(filePath);
- else if (ext == "lrc")
- success = this->openLRC(filePath);
- if (!success)
- success = this->openAVParser(filePath);
- if (!success && isExternal)
- success = this->openYouTube(filePath);
- this->m_subtitleFilePath = filePath;
- return success;
- }
- bool MediaPresenter::openSAMI(const QString &filePath)
- {
- if (this->m_samiParser.open(filePath))
- {
- this->m_detail.subtitleCodec = "SAMI Parser";
- this->m_subtitleType = ST_SAMI;
- return true;
- }
- return false;
- }
- bool MediaPresenter::openASS(const QString &filePath)
- {
- if (this->m_assParser.open(filePath))
- {
- QFileInfo info(filePath);
- if (info.suffix().toLower() == "ass")
- this->m_detail.subtitleCodec = "ASS Parser";
- else if (info.suffix().toLower() == "ssa")
- this->m_detail.subtitleCodec = "SSA Parser";
- else
- this->m_detail.subtitleCodec = "Unknown Parser";
- this->m_assParser.setDefaultFont(this->m_assFontFamily);
- this->m_subtitleType = ST_ASS;
- return true;
- }
- return false;
- }
- bool MediaPresenter::openSRT(const QString &filePath)
- {
- if (this->m_srtParser.open(filePath))
- {
- this->m_detail.subtitleCodec = "SRT Parser";
- this->m_subtitleType = ST_SRT;
- return true;
- }
- return false;
- }
- bool MediaPresenter::openYouTube(const QString &id)
- {
- if (this->m_youtubeParser.open(id))
- {
- this->m_detail.subtitleCodec = "YouTube Parser";
- this->m_subtitleType = ST_YOUTUBE;
- return true;
- }
- return false;
- }
- bool MediaPresenter::openLRC(const QString &filePath)
- {
- if (this->m_lrcParser.open(filePath))
- {
- this->m_detail.subtitleCodec = "LRC Parser";
- this->m_subtitleType = ST_LRC;
- return true;
- }
- return false;
- }
- bool MediaPresenter::openAVParser(const QString &filePath)
- {
- QString fontPath;
- this->m_assParser.getFontPath(&fontPath);
- if (this->m_avParser.open(filePath, fontPath, this->m_fontFamily))
- {
- this->m_avParser.setCurrentIndex(0);
- this->m_detail.subtitleCodec = "AV Parser";
- this->m_subtitleType = ST_AV;
- return true;
- }
- return false;
- }
- void MediaPresenter::closeAllExternalSubtitles()
- {
- this->m_assParser.close();
- this->m_samiParser.close();
- this->m_srtParser.close();
- this->m_youtubeParser.close();
- this->m_lrcParser.close();
- this->m_avParser.close();
- this->m_subtitleFilePath.clear();
- this->m_subtitleType = ST_NONE;
- this->m_detail.subtitleBitmap = false;
- this->m_detail.subtitleValidColor = true;
- MediaState *ms = this->m_state;
- if (ms && ms->subtitle.stream.stream)
- {
- const AVCodec *codec = ms->subtitle.stream.ctx->codec;
- this->m_detail.subtitleCodec = QString(SUBTITLE_CODEC_FORMAT).arg(QString(codec->name).toUpper()).arg(codec->long_name);
- }
- }
- void MediaPresenter::close()
- {
- QMutexLocker locker(&this->m_controlLocker);
- this->m_forceExit = true;
- if (this->isRunning())
- this->wait();
- this->closeInternal();
- this->m_playData = ExtraPlayData();
- }
- void MediaPresenter::setDevicePixelRatio(double ratio)
- {
- this->m_devicePixelRatio = ratio;
- }
- void MediaPresenter::closeInternal()
- {
- if (this->m_state)
- this->m_state->quit = true;
- this->m_forceExit = false;
- this->closeStream();
- this->closeAllExternalSubtitles();
- this->callEmptyCallback(false);
- this->m_isRemoteFile = false;
- this->m_audioStreamInfo.clear();
- this->m_subtitleStreamInfo.clear();
- this->m_detail = Detail();
- this->m_repeatRange = Range();
- this->m_GOMSubtitleURL.clear();
- this->m_rotation = 0.0;
- this->m_optionDescY = 0;
- this->m_format = DEFAULT_PIX_FORMAT;
- this->m_scheduleRecomputeSubtitleSize = false;
- this->setSensorRotation(0.0);
- this->scheduleInitTextures();
- }
- #if defined Q_OS_MOBILE
- void MediaPresenter::setGL(QOpenGLFunctions *gl)
- {
- this->m_gl = gl;
- this->m_font.setGL(gl);
- this->m_subtitleFont.setGL(gl);
- }
- #endif
- void MediaPresenter::scheduleInitTextures()
- {
- if (this->m_texInfo)
- {
- for (int i = 0; i < TEX_COUNT; i++)
- {
- for (unsigned int j = 0; j < this->m_texInfo[i].textureCount; j++)
- this->m_texInfo[i].init[j] = false;
- }
- }
- }
- bool MediaPresenter::resetScreen(const int width, const int height, TextureInfo *texInfo, bool inContext)
- {
- this->m_width = width;
- this->m_height = height;
- this->m_texInfo = texInfo;
- this->m_ortho.setToIdentity();
- this->m_ortho.ortho(0.0f, (float)width, (float)height, 0.0f, -1.0f, 1.0f);
- this->m_font.setOrtho(this->m_ortho);
- this->m_subtitleFont.setOrtho(this->m_ortho);
- if (inContext)
- {
- this->initFrameBufferObject(&this->m_distortionFrameBuffer, width, height);
- this->initFrameBufferObject(&this->m_leftDistortionFrameBuffer, width, height);
- this->initFrameBufferObject(&this->m_rightDistortionFrameBuffer, width, height);
- }
- this->scheduleInitTextures();
- if (this->m_state && this->m_state->video.stream.stream)
- {
- this->computeFrameSize();
- return true;
- }
- else
- {
- return false;
- }
- }
- bool MediaPresenter::play()
- {
- QMutexLocker locker(&this->m_controlLocker);
- bool success = false;
- success = this->openStream();
- if (success)
- {
- this->start();
- }
- else
- {
- this->m_state->quit = true;
- this->closeStream();
- }
- return success;
- }
- void MediaPresenter::pause()
- {
- QMutexLocker locker(&this->m_controlLocker);
- MediaState *ms = this->m_state;
- if (ms && !ms->pause.pause)
- {
- ms->pause.pause = true;
- ms->pause.startTime = this->getAbsoluteClock();
- ms->pause.lastPausedTime = ms->frameTimer.lastPTS;
- if (this->m_spdif.isOpened())
- this->m_spdif.pause();
- else
- BASS_Pause();
- }
- }
- void MediaPresenter::resume()
- {
- QMutexLocker locker(&this->m_controlLocker);
- MediaState *ms = this->m_state;
- if (ms && ms->pause.pause)
- {
- ms->pause.driftTime += this->getAbsoluteClock() - ms->pause.startTime;
- ms->pause.pause = false;
- ms->seek.inc = 0.0;
- if (this->m_spdif.isOpened())
- this->m_spdif.resume();
- else
- BASS_Start();
- }
- if (ms)
- ms->willBeEnd = false;
- }
- void MediaPresenter::stop()
- {
- this->close();
- }
- bool MediaPresenter::isPlayUserDataEmpty() const
- {
- return this->m_playData.userData.isEmpty();
- }
- QString MediaPresenter::getTitle() const
- {
- return this->m_title;
- }
- void MediaPresenter::prevFrame(int count)
- {
- QMutexLocker locker(&this->m_controlLocker);
- MediaState *ms = this->m_state;
- if (ms)
- {
- double clock = ms->pause.pause ? ms->pause.lastPausedTime : ms->frameTimer.lastPTS;
- double frameTime = this->getDuration() / this->m_detail.videoTotalFrame;
- double target = clock - (count + 1) * frameTime;
- if (!ms->pause.pause)
- this->pause();
- this->seekStream(target, 0.0, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);
- }
- }
- void MediaPresenter::nextFrame(int count)
- {
- MediaState *ms = this->m_state;
- if (ms)
- {
- ms->seek.requestPauseOnRender = true;
- ms->seek.pauseOnRenderCount = count;
- this->resume();
- }
- }
- bool MediaPresenter::render(ShaderCompositer &shader)
- {
- QMutexLocker locker(&this->m_controlLocker);
- return this->update(shader);
- }
- void MediaPresenter::setSubtitleSync(double value)
- {
- this->m_subtitleSync = value;
- }
- double MediaPresenter::getSubtitleSync() const
- {
- return this->m_subtitleSync;
- }
- void MediaPresenter::audioSync(double value)
- {
- this->m_audioSync = value;
- }
- double MediaPresenter::getAudioSync() const
- {
- return this->m_audioSync;
- }
- void MediaPresenter::showDetail(bool show)
- {
- this->m_showDetail = show;
- }
- bool MediaPresenter::isShowDetail() const
- {
- return this->m_showDetail;
- }
- const MediaPresenter::Detail& MediaPresenter::getDetail() const
- {
- return this->m_detail;
- }
- void MediaPresenter::getAudioDevices(QStringList *ret) const
- {
- BASS_DEVICEINFO info;
- for (int i = 0; BASS_GetDeviceInfo(i, &info); i++)
- ret->append(QString::fromLocal8Bit(info.name));
- }
- bool MediaPresenter::setAudioDevice(int device)
- {
- this->m_audioDevice = device;
- if (!this->m_spdif.isOpened())
- return this->setAudioDeviceAfter();
- else
- return true;
- }
- int MediaPresenter::getCurrentAudioDevice() const
- {
- return this->m_audioDevice;
- }
- bool MediaPresenter::setAudioDeviceAfter()
- {
- if (this->resetAudioStream())
- return true;
- if (this->m_state)
- this->m_state->audio.stream.index = this->m_lastAudioStream;
- return false;
- }
- void MediaPresenter::getSPDIFAudioDevices(QStringList *ret)
- {
- this->m_spdif.getDeviceList(ret);
- }
- bool MediaPresenter::setSPDIFAudioDevice(int device)
- {
- if (this->m_spdif.setDevice(device))
- {
- if (this->m_spdif.isOpened())
- return this->setAudioDeviceAfter();
- else
- return true;
- }
- return false;
- }
- int MediaPresenter::getCurrentSPDIFAudioDevice() const
- {
- return this->m_spdif.getDevice();
- }
- void MediaPresenter::showSubtitle(bool show)
- {
- this->m_showSubtitle = show;
- }
- bool MediaPresenter::isShowSubtitle() const
- {
- return this->m_showSubtitle;
- }
- bool MediaPresenter::existFileSubtitle()
- {
- return this->m_samiParser.isExist() ||
- this->m_srtParser.isExist() ||
- this->m_youtubeParser.isExist() ||
- this->m_lrcParser.isExist();
- }
- bool MediaPresenter::existSubtitle()
- {
- return (this->m_state && this->m_state->subtitle.stream.stream) ||
- this->m_samiParser.isExist() ||
- this->m_assParser.isExist() ||
- this->m_srtParser.isExist() ||
- this->m_youtubeParser.isExist() ||
- this->m_lrcParser.isExist() ||
- this->m_avParser.isExist();
- }
- bool MediaPresenter::existExternalSubtitle()
- {
- return this->m_samiParser.isExist() ||
- this->m_assParser.isExist() ||
- this->m_srtParser.isExist() ||
- this->m_youtubeParser.isExist() ||
- this->m_lrcParser.isExist() ||
- this->m_avParser.isExist();
- }
- double MediaPresenter::getRotation() const
- {
- return this->m_rotation;
- }
- void MediaPresenter::setSensorRotation(double rot)
- {
- QMutexLocker locker(&this->m_cameraLock);
- this->m_sensorRotation = rot;
- }
- double MediaPresenter::getSensorRotation()
- {
- double rot;
- this->m_cameraLock.lock();
- rot = this->m_sensorRotation;
- this->m_cameraLock.unlock();
- return rot;
- }
- bool MediaPresenter::isAlignable()
- {
- return (this->m_state && this->m_state->subtitle.stream.stream &&
- this->m_state->subtitle.stream.ctx->subtitle_header_size <= 0 &&
- this->m_state->subtitle.isBitmap == false) ||
- this->m_samiParser.isExist() ||
- this->m_youtubeParser.isExist() ||
- this->m_srtParser.isExist();
- }
- AnyVODEnums::HAlignMethod MediaPresenter::getHAlign() const
- {
- return this->m_halign;
- }
- void MediaPresenter::setHAlign(AnyVODEnums::HAlignMethod align)
- {
- this->m_halign = align;
- }
- AnyVODEnums::VAlignMethod MediaPresenter::getVAlign() const
- {
- return this->m_valign;
- }
- void MediaPresenter::setVAlign(AnyVODEnums::VAlignMethod align)
- {
- this->m_valign = align;
- }
- bool MediaPresenter::existAudioSubtitle()
- {
- return this->m_lrcParser.isExist();
- }
- bool MediaPresenter::existAudioSubtitleGender() const
- {
- return this->m_lrcParser.isGenderExist();
- }
- void MediaPresenter::setSubtitleURL(const QString &url)
- {
- this->m_GOMSubtitleURL = url;
- }
- void MediaPresenter::getSubtitleURL(QString *ret) const
- {
- *ret = this->m_GOMSubtitleURL;
- }
- void MediaPresenter::setASSFontPath(const QString &path)
- {
- this->m_assParser.setFontPath(path);
- }
- void MediaPresenter::setASSFontFamily(const QString &family)
- {
- this->m_assFontFamily = family;
- }
- void MediaPresenter::getSubtitleClasses(QStringList *classNames)
- {
- if (this->m_samiParser.isExist())
- {
- this->m_samiParser.getClassNames(classNames);
- }
- else if (this->m_youtubeParser.isExist())
- {
- this->m_youtubeParser.getLanguages(classNames);
- }
- else if (this->m_avParser.isExist())
- {
- QVector<SubtitleStreamInfo> infos;
- this->m_avParser.getStreamInfos(&infos);
- for (int i = 0; i < infos.count(); i++)
- classNames->append(infos[i].name);
- }
- else
- {
- for (int i = 0; i < this->m_subtitleStreamInfo.count(); i++)
- classNames->append(this->m_subtitleStreamInfo[i].name);
- }
- }
- void MediaPresenter::getCurrentSubtitleClass(QString *className)
- {
- if (this->m_samiParser.isExist())
- {
- this->m_samiParser.getDefaultClassName(className);
- }
- else if (this->m_youtubeParser.isExist())
- {
- this->m_youtubeParser.getDefaultLanguage(className);
- }
- else if (this->m_avParser.isExist())
- {
- this->m_avParser.getCurrentName(className);
- }
- else
- {
- if (!this->m_state)
- return;
- QString name;
- for (int i = 0; i < this->m_subtitleStreamInfo.count(); i++)
- {
- if (this->m_subtitleStreamInfo[i].index == this->m_state->subtitle.stream.index)
- {
- name = this->m_subtitleStreamInfo[i].name;
- break;
- }
- }
- *className = name;
- }
- }
- bool MediaPresenter::setCurrentSubtitleClass(const QString &className)
- {
- if (this->m_samiParser.isExist())
- {
- this->m_samiParser.setDefaultClassName(className);
- return true;
- }
- else if (this->m_youtubeParser.isExist())
- {
- this->m_youtubeParser.setDefaultLanguage(className);
- return true;
- }
- else if (this->m_avParser.isExist())
- {
- QVector<SubtitleStreamInfo> infos;
- unsigned int index = 0;
- this->m_avParser.getStreamInfos(&infos);
- for (int i = 0; i < infos.count(); i++)
- {
- if (infos[i].name == className)
- {
- index = infos[i].index;
- break;
- }
- }
- this->m_avParser.setCurrentIndex(index);
- return true;
- }
- else
- {
- if (!this->m_state)
- return false;
- int index = -1;
- for (int i = 0; i < this->m_subtitleStreamInfo.count(); i++)
- {
- if (this->m_subtitleStreamInfo[i].name == className)
- {
- index = this->m_subtitleStreamInfo[i].index;
- break;
- }
- }
- Subtitle &subtitle = this->m_state->subtitle;
- subtitle.stream.queue.flush();
- subtitle.requestReleaseQueue = true;
- return this->changeStream(index, subtitle.stream.index, false, &this->m_lastSubtitleStream, &subtitle.threadQuit);
- }
- }
- void MediaPresenter::resetSubtitlePosition()
- {
- this->m_vertPosition = 0;
- this->m_horiPosition = 0;
- }
- void MediaPresenter::setVerticalSubtitlePosition(int pos)
- {
- this->m_vertPosition += pos;
- }
- void MediaPresenter::setHorizontalSubtitlePosition(int pos)
- {
- this->m_horiPosition += pos;
- }
- void MediaPresenter::setVerticalSubtitleAbsolutePosition(int pos)
- {
- this->m_vertPosition = pos;
- }
- void MediaPresenter::setHorizontalSubtitleAbsolutePosition(int pos)
- {
- this->m_horiPosition = pos;
- }
- int MediaPresenter::getVerticalSubtitlePosition() const
- {
- return this->m_vertPosition;
- }
- int MediaPresenter::getHorizontalSubtitlePosition() const
- {
- return this->m_horiPosition;
- }
- void MediaPresenter::reset3DSubtitleOffset()
- {
- if (this->m_vrInputSource == AnyVODEnums::VRI_NONE)
- this->m_3dSubtitleOffset = DEFAULT_3D_SUBTITLE_OFFSET;
- else
- this->m_3dSubtitleOffset = DEFAULT_VR_SUBTITLE_OFFSET;
- }
- void MediaPresenter::setVertical3DSubtitleOffset(int pos)
- {
- this->m_3dSubtitleOffset.ry() += pos;
- }
- void MediaPresenter::setHorizontal3DSubtitleOffset(int pos)
- {
- this->m_3dSubtitleOffset.rx() += pos;
- }
- void MediaPresenter::setVertical3DSubtitleAbsoluteOffset(int pos)
- {
- this->m_3dSubtitleOffset.ry() = pos;
- }
- void MediaPresenter::setHorizontal3DSubtitleAbsoluteOffset(int pos)
- {
- this->m_3dSubtitleOffset.rx() = pos;
- }
- int MediaPresenter::getVertical3DSubtitleOffset() const
- {
- return this->m_3dSubtitleOffset.y();
- }
- int MediaPresenter::getHorizontal3DSubtitleOffset() const
- {
- return this->m_3dSubtitleOffset.x();
- }
- void MediaPresenter::resetVirtual3DDepth()
- {
- this->m_virtual3DDepth = DEFAULT_VIRTUAL_3D_DEPTH;
- }
- void MediaPresenter::setVirtual3DDepth(qreal depth)
- {
- this->m_virtual3DDepth = depth;
- }
- qreal MediaPresenter::getVirtual3DDepth() const
- {
- return this->m_virtual3DDepth;
- }
- void MediaPresenter::setRepeatStart(double start)
- {
- this->m_repeatRange.start = start;
- }
- void MediaPresenter::setRepeatEnd(double end)
- {
- this->m_repeatRange.end = end;
- }
- void MediaPresenter::setRepeatEnable(bool enable)
- {
- this->m_repeatRange.enable = enable;
- }
- bool MediaPresenter::getRepeatEnable() const
- {
- return this->m_repeatRange.enable;
- }
- double MediaPresenter::getRepeatStart() const
- {
- return this->m_repeatRange.start;
- }
- double MediaPresenter::getRepeatEnd() const
- {
- return this->m_repeatRange.end;
- }
- void MediaPresenter::setCaptureMode(bool capture)
- {
- this->m_captureMode = capture;
- }
- bool MediaPresenter::getCaptureMode() const
- {
- return this->m_captureMode;
- }
- void MediaPresenter::setSeekKeyFrame(bool keyFrame)
- {
- this->m_seekKeyFrame = keyFrame;
- }
- bool MediaPresenter::isSeekKeyFrame() const
- {
- return this->m_seekKeyFrame;
- }
- void MediaPresenter::set3DMethod(AnyVODEnums::Video3DMethod method)
- {
- this->m_3dMethod = method;
- this->computeFrameSize();
- }
- AnyVODEnums::Video3DMethod MediaPresenter::get3DMethod() const
- {
- return this->m_3dMethod;
- }
- void MediaPresenter::setSubtitle3DMethod(AnyVODEnums::Subtitle3DMethod method)
- {
- this->m_3dSubtitleMethod = method;
- }
- AnyVODEnums::Subtitle3DMethod MediaPresenter::getSubtitle3DMethod() const
- {
- return this->m_3dSubtitleMethod;
- }
- void MediaPresenter::setVRInputSource(AnyVODEnums::VRInputSource source)
- {
- this->m_vrInputSource = source;
- this->computeFrameSize();
- this->reset3DSubtitleOffset();
- }
- AnyVODEnums::VRInputSource MediaPresenter::getVRInputSource() const
- {
- return this->m_vrInputSource;
- }
- void MediaPresenter::setDistortionAdjustMode(AnyVODEnums::DistortionAdjustMode mode)
- {
- this->m_distortionAdjustMode = mode;
- }
- AnyVODEnums::DistortionAdjustMode MediaPresenter::getDistortionAdjustMode() const
- {
- return this->m_distortionAdjustMode;
- }
- void MediaPresenter::setSkipRanges(const QVector<Range> &ranges)
- {
- this->m_skipRanges = ranges;
- }
- void MediaPresenter::getSkipRanges(QVector<Range> *ret) const
- {
- *ret = this->m_skipRanges;
- }
- void MediaPresenter::setSkipOpening(bool skip)
- {
- this->m_skipOpening = skip;
- }
- bool MediaPresenter::getSkipOpening() const
- {
- return this->m_skipOpening;
- }
- void MediaPresenter::setSkipEnding(bool skip)
- {
- this->m_skipEnding = skip;
- }
- bool MediaPresenter::getSkipEnding() const
- {
- return this->m_skipEnding;
- }
- void MediaPresenter::setUseSkipRange(bool use)
- {
- this->m_useSkipRange = use;
- }
- bool MediaPresenter::getUseSkipRange() const
- {
- return this->m_useSkipRange;
- }
- double MediaPresenter::getOpeningSkipTime() const
- {
- for (int i = 0; i < this->m_skipRanges.count(); i++)
- {
- if (this->m_skipRanges[i].start < 0.0)
- return this->m_skipRanges[i].end;
- }
- return 0.0;
- }
- double MediaPresenter::getEndingSkipTime() const
- {
- for (int i = 0; i < this->m_skipRanges.count(); i++)
- {
- if (this->m_skipRanges[i].end < 0.0)
- return this->m_skipRanges[i].start;
- }
- return 0.0;
- }
- void MediaPresenter::useNormalizer(bool use)
- {
- if (this->m_spdif.isOpened())
- return;
- this->m_audioEffect.useNormalizer = use;
- if (this->m_state && this->m_state->audio.handle)
- {
- if (use)
- this->initNormalizer();
- else
- this->closeNormalizer();
- }
- }
- bool MediaPresenter::isUsingNormalizer() const
- {
- return this->m_audioEffect.useNormalizer;
- }
- void MediaPresenter::useEqualizer(bool use)
- {
- if (this->m_spdif.isOpened())
- return;
- this->m_audioEffect.useEqualizer = use;
- if (this->m_state && this->m_state->audio.handle)
- {
- if (use)
- this->initEqualizer();
- else
- this->closeEqualizer();
- }
- }
- bool MediaPresenter::isUsingEqualizer() const
- {
- return this->m_audioEffect.useEqualizer;
- }
- void MediaPresenter::useLowerVoice(bool use)
- {
- if (this->m_spdif.isOpened())
- return;
- this->m_audioEffect.useLowerVoice = use;
- if (this->m_state && this->m_state->audio.handle)
- {
- if (use)
- this->initLowerVoice();
- else
- this->closeLowerVoice();
- }
- }
- bool MediaPresenter::isUsingLowerVoice() const
- {
- return this->m_audioEffect.useLowerVoice;
- }
- void MediaPresenter::useHigherVoice(bool use)
- {
- if (this->m_spdif.isOpened())
- return;
- this->m_audioEffect.useHigherVoice = use;
- if (this->m_state && this->m_state->audio.handle)
- {
- if (use)
- this->initHigherVoice();
- else
- this->closeHigherVoice();
- }
- }
- bool MediaPresenter::isUsingHigherVoice() const
- {
- return this->m_audioEffect.useHigherVoice;
- }
- void MediaPresenter::useLowerMusic(bool use)
- {
- if (this->m_spdif.isOpened())
- return;
- this->m_audioEffect.useLowerMusic = use;
- if (this->m_state && this->m_state->audio.handle)
- {
- if (use)
- this->initLowerMusic();
- else
- this->closeLowerMusic();
- }
- }
- bool MediaPresenter::isUsingLowerMusic() const
- {
- return this->m_audioEffect.useLowerMusic;
- }
- void MediaPresenter::setSubtitleOpaque(float opaque)
- {
- this->m_subtitleOpaque = opaque;
- }
- float MediaPresenter::getSubtitleOpaque() const
- {
- return this->m_subtitleOpaque;
- }
- void MediaPresenter::setSubtitleSize(float size)
- {
- this->m_subtitleSize = size;
- if (!this->m_scheduleRecomputeSubtitleSize)
- this->computeSubtitleSize();
- }
- float MediaPresenter::getSubtitleSize() const
- {
- return this->m_subtitleSize;
- }
- void MediaPresenter::setScheduleRecomputeSubtitleSize()
- {
- this->m_scheduleRecomputeSubtitleSize = true;
- }
- bool MediaPresenter::setPreAmp(float dB)
- {
- this->m_audioEffect.preampValue = dB;
- if (this->m_audioEffect.preamp && this->m_state && this->m_state->audio.handle)
- {
- BASS_BFX_VOLUME vol;
- vol.lChannel = 0;
- vol.fVolume = BASS_BFX_dB2Linear(dB);
- if (BASS_FXSetParameters(this->m_audioEffect.preamp, &vol) == TRUE)
- return true;
- }
- else
- {
- return true;
- }
- return false;
- }
- float MediaPresenter::getPreAmp() const
- {
- return this->m_audioEffect.preampValue;
- }
- bool MediaPresenter::setEqualizerGain(int band, float gain)
- {
- QVector<Equalizer> &values = this->m_audioEffect.equalizerValues;
- if (band >= 0 && band < values.count())
- {
- Equalizer &eq = values[band];
- eq.gain = gain;
- if (this->m_audioEffect.eqaulizer && this->m_state && this->m_state->audio.handle)
- {
- BASS_BFX_PEAKEQ eqValue;
- eqValue.fBandwidth = eq.octave;
- eqValue.fCenter = eq.center;
- eqValue.fGain = eq.gain;
- eqValue.lBand = band;
- eqValue.lChannel = BASS_BFX_CHANALL;
- if (BASS_FXSetParameters(this->m_audioEffect.eqaulizer, &eqValue) == TRUE)
- return true;
- }
- else
- {
- return true;
- }
- }
- return false;
- }
- float MediaPresenter::getEqualizerGain(int band) const
- {
- const QVector<Equalizer> &values = this->m_audioEffect.equalizerValues;
- if (band >= 0 && band < values.count())
- return values[band].gain;
- return 0.0f;
- }
- int MediaPresenter::getBandCount() const
- {
- return this->m_audioEffect.equalizerValues.count();
- }
- bool MediaPresenter::isEnableSearchSubtitle() const
- {
- return this->m_enableSearchSubtitle;
- }
- bool MediaPresenter::isEnableSearchLyrics() const
- {
- return this->m_enableSearchLyrics;
- }
- void MediaPresenter::enableSearchSubtitle(bool enable)
- {
- this->m_enableSearchSubtitle = enable;
- }
- void MediaPresenter::enableSearchLyrics(bool enable)
- {
- this->m_enableSearchLyrics = enable;
- }
- void MediaPresenter::enableAutoSaveSearchLyrics(bool enable)
- {
- this->m_autoSaveSearchLyrics = enable;
- }
- bool MediaPresenter::isAutoSaveSearchLyrics() const
- {
- return this->m_autoSaveSearchLyrics;
- }
- void MediaPresenter::showAlbumJacket(bool show)
- {
- this->m_showAlbumJacket = show;
- }
- bool MediaPresenter::isShowAlbumJacket() const
- {
- return this->m_showAlbumJacket;
- }
- void MediaPresenter::useFrameDrop(bool enable)
- {
- this->m_useFrameDrop = enable;
- }
- bool MediaPresenter::isUseFrameDrop() const
- {
- return this->m_useFrameDrop;
- }
- void MediaPresenter::useBufferingMode(bool enable)
- {
- this->m_useBufferingMode = enable;
- }
- bool MediaPresenter::isUseBufferingMode() const
- {
- return this->m_useBufferingMode;
- }
- void MediaPresenter::useGPUConvert(bool use)
- {
- bool prev = this->m_useGPUConvert;
- this->m_useGPUConvert = use;
- if (prev != use)
- {
- if (this->isEnabledVideo())
- this->recover(this->getMasterClock());
- }
- }
- bool MediaPresenter::isUseGPUConvert() const
- {
- return this->m_useGPUConvert;
- }
- void MediaPresenter::seek(double time, bool any)
- {
- QMutexLocker locker(&this->m_controlLocker);
- if (this->m_state)
- {
- double incr = time - this->getCurrentPosition();
- int flag = (this->m_seekKeyFrame && !any) ? 0 : AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY;
- this->seekStream(time, incr, flag);
- }
- }
- uint8_t MediaPresenter::getMaxVolume() const
- {
- return 255;
- }
- void MediaPresenter::mute(bool mute)
- {
- if (mute)
- this->volumeInternal(0);
- else
- this->volume(this->m_volume);
- this->m_isMute = mute;
- }
- void MediaPresenter::volumeInternal(uint8_t volume)
- {
- if (this->m_state && !this->m_spdif.isOpened())
- BASS_ChannelSetAttribute(this->m_state->audio.handle, BASS_ATTRIB_VOL, (float)volume / (float)this->getMaxVolume());
- }
- void MediaPresenter::volume(uint8_t volume)
- {
- if (volume > this->getMaxVolume())
- this->m_volume = this->getMaxVolume();
- else
- this->m_volume = volume;
- this->volumeInternal(this->m_volume);
- }
- uint8_t MediaPresenter::getVolume() const
- {
- return this->m_volume;
- }
- double MediaPresenter::getDuration() const
- {
- if (this->m_state)
- return this->m_playData.duration;
- else
- return 0.0;
- }
- double MediaPresenter::getCurrentPosition()
- {
- if (this->m_state)
- {
- double duration = this->getDuration();
- double clock;
- clock = this->getMasterClock() + this->m_state->seek.inc;
- if (clock > duration)
- return duration;
- else
- return clock;
- }
- else
- {
- return 0.0;
- }
- }
- bool MediaPresenter::hasDuration() const
- {
- return Utils::zeroDouble(this->getDuration()) > 0.0;
- }
- double MediaPresenter::getAspectRatio(bool widthPrio) const
- {
- MediaState *ms = this->m_state;
- double aspectRatio = 0.0;
- if (!ms)
- return 0.0;
- if (!ms->video.stream.stream)
- return 0.0;
- AVCodecContext *codec = ms->video.stream.ctx;
- if (!codec)
- return 0.0;
- if (codec->sample_aspect_ratio.num == 0)
- {
- aspectRatio = 0.0;
- }
- else
- {
- aspectRatio = av_q2d(codec->sample_aspect_ratio);
- if (widthPrio)
- aspectRatio *= (double)codec->height / (double)codec->width;
- else
- aspectRatio *= (double)codec->width / (double)codec->height;
- }
- if (aspectRatio <= 0.0)
- {
- if (widthPrio)
- aspectRatio = (double)codec->height / (double)codec->width;
- else
- aspectRatio = (double)codec->width / (double)codec->height;
- }
- return aspectRatio;
- }
- bool MediaPresenter::isEnabledVideo() const
- {
- if (this->m_state && this->m_state->video.stream.stream)
- return true;
- else
- return false;
- }
- bool MediaPresenter::isAudio() const
- {
- return this->m_playData.totalFrame <= 100 && this->m_isAudioExt;
- }
- bool MediaPresenter::isVideo() const
- {
- return this->isEnabledVideo() && !this->isAudio();
- }
- bool MediaPresenter::isTempoUsable() const
- {
- if (this->m_state)
- {
- if (this->getCurrentAudioStreamIndex() >= 0)
- return this->m_state->audio.tempo != 0;
- else
- return true;
- }
- return false;
- }
- float MediaPresenter::getTempo() const
- {
- float tempo = 0.0f;
- if (this->isTempoUsable())
- {
- if (this->getCurrentAudioStreamIndex() >= 0)
- BASS_ChannelGetAttribute(this->m_state->audio.tempo, BASS_ATTRIB_TEMPO, &tempo);
- else
- tempo = this->m_state->video.tempo;
- }
- return tempo;
- }
- void MediaPresenter::setTempo(float percent)
- {
- if (this->isTempoUsable())
- {
- if (this->getCurrentAudioStreamIndex() >= 0)
- BASS_ChannelSetAttribute(this->m_state->audio.tempo, BASS_ATTRIB_TEMPO, percent);
- else
- this->m_state->video.tempo = percent;
- }
- }
- VirtualFile& MediaPresenter::getVirtualFile()
- {
- return VIRTUAL_FILE;
- }
- DTVReader& MediaPresenter::getDTVReader()
- {
- return DTV_READER;
- }
- bool MediaPresenter::isRemoteFile() const
- {
- return this->m_isRemoteFile;
- }
- bool MediaPresenter::isRemoteProtocol() const
- {
- return this->m_isRemoteProtocol;
- }
- bool MediaPresenter::changeStream(int newIndex, int oldIndex, bool isAudio, int *lastStreamIndex, bool *quitFlag)
- {
- QMutexLocker locker(&this->m_controlLocker);
- bool success = false;
- if (this->m_state == nullptr)
- return false;
- double clock = this->getMasterClock();
- this->m_state->streamChangeStartTime = this->getAbsoluteClock();
- this->m_state->readThreadQuit = true;
- if (this->m_readThread.isRunning())
- this->m_readThread.wait();
- if (quitFlag)
- *quitFlag = true;
- this->closeStreamComponent(oldIndex, isAudio);
- if (this->openStreamComponent(newIndex, isAudio))
- {
- if (newIndex == this->getCurrentAudioStreamIndex())
- {
- if (this->m_spdif.isOpened())
- this->m_spdif.play();
- else
- BASS_ChannelPlay(this->m_state->audio.handle, true);
- }
- this->seekStream(clock, 0.0, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);
- if (lastStreamIndex)
- *lastStreamIndex = newIndex;
- success = true;
- }
- this->startReadThread();
- this->m_state->streamChangeDriftTime += this->getAbsoluteClock() - this->m_state->streamChangeStartTime;
- return success;
- }
- int MediaPresenter::getCurrentAudioStreamIndex() const
- {
- if (this->m_state)
- return this->m_state->audio.stream.index;
- else
- return -1;
- }
- void MediaPresenter::getAudioStreamInfo(QVector<AudioStreamInfo> *ret) const
- {
- *ret = this->m_audioStreamInfo;
- }
- bool MediaPresenter::resetAudioStream()
- {
- return this->changeAudioStream(this->getCurrentAudioStreamIndex());
- }
- bool MediaPresenter::changeAudioStream(int index)
- {
- return this->changeStream(index, this->getCurrentAudioStreamIndex(),
- this->isUseAudioPath(), &this->m_lastAudioStream, nullptr);
- }
- HSTREAM MediaPresenter::getAudioHandle() const
- {
- if (this->m_state)
- return this->m_state->audio.handle;
- return 0;
- }
- Deinterlacer& MediaPresenter::getDeinterlacer()
- {
- return this->m_deinterlacer;
- }
- void MediaPresenter::setDeinterlacerAlgorithm(AnyVODEnums::DeinterlaceAlgorithm algorithm)
- {
- this->m_deinterlacer.setAlgorithm(algorithm);
- if (this->m_state)
- {
- Video &video = this->m_state->video;
- this->m_deinterlacer.setCodec(video.stream.ctx, video.pixFormat, video.stream.stream->time_base);
- }
- }
- FilterGraph& MediaPresenter::getFilterGraph()
- {
- return this->m_filterGraph;
- }
- bool MediaPresenter::configFilterGraph()
- {
- if (this->m_state)
- {
- Video &video = this->m_state->video;
- return this->m_filterGraph.setCodec(video.stream.ctx, video.pixFormat, this->m_format, video.stream.stream->time_base);
- }
- return false;
- }
- int MediaPresenter::getOptionDescY() const
- {
- return this->m_optionDescY;
- }
- void MediaPresenter::setOptionDescY(int y)
- {
- this->m_optionDescY = y;
- }
- void MediaPresenter::setVerticalScreenOffset(int offset)
- {
- QMutexLocker locker(&this->m_cameraLock);
- this->m_screenOffset.setY(offset);
- }
- void MediaPresenter::setHorizontalScreenOffset(int offset)
- {
- QMutexLocker locker(&this->m_cameraLock);
- this->m_screenOffset.setX(offset);
- }
- void MediaPresenter::useDistortion(bool use)
- {
- this->m_useDistortion = use;
- }
- bool MediaPresenter::isUseDistortion() const
- {
- return this->m_useDistortion;
- }
- void MediaPresenter::setBarrelDistortionCoefficients(const QVector2D &coefficients)
- {
- this->m_barrelDistortionCoefficients = coefficients;
- }
- QVector2D MediaPresenter::getBarrelDistortionCoefficients() const
- {
- return this->m_barrelDistortionCoefficients;
- }
- void MediaPresenter::setPincushionDistortionCoefficients(const QVector2D &coefficients)
- {
- this->m_pincushionDistortionCoefficients = coefficients;
- }
- QVector2D MediaPresenter::getPincushionDistortionCoefficients() const
- {
- return this->m_pincushionDistortionCoefficients;
- }
- void MediaPresenter::setDistortionLensCenter(const QVector2D &lensCenter)
- {
- this->m_distortionLensCenter = lensCenter;
- }
- QVector2D MediaPresenter::getDistortionLensCenter() const
- {
- return this->m_distortionLensCenter;
- }
- QString MediaPresenter::getRealFilePath() const
- {
- return this->m_realFilePath;
- }
- AVPixelFormat MediaPresenter::getFormat() const
- {
- return this->m_format;
- }
- void MediaPresenter::setBluetoothHeadsetConnected(bool connected)
- {
- this->m_bluetoothHeadsetConnected = connected;
- }
- bool MediaPresenter::getBluetoothHeadsetConnected() const
- {
- return this->m_bluetoothHeadsetConnected;
- }
- void MediaPresenter::setBluetoothHeadsetSync(double sync)
- {
- this->m_bluetoothHeadsetSync = sync;
- }
- double MediaPresenter::getBluetoothHeadsetSync() const
- {
- return this->m_bluetoothHeadsetSync;
- }
- #ifdef Q_OS_IOS
- void MediaPresenter::setIOSNotifyCallback(IOSNOTIFYPROC *proc)
- {
- this->m_iosNotify = proc;
- }
- #endif
- void MediaPresenter::setUserAspectRatio(UserAspectRatio &ratio)
- {
- this->m_userRatio = ratio;
- this->computeFrameSize();
- }
- void MediaPresenter::getUserAspectRatio(UserAspectRatio *ret) const
- {
- *ret = this->m_userRatio;
- }
- void MediaPresenter::setMaxTextureSize(int size)
- {
- this->m_maxTextureSize = size;
- this->initFrameBufferObject(&this->m_anaglyphFrameBuffer, size, size);
- }
- int MediaPresenter::getMaxTextureSize() const
- {
- return this->m_maxTextureSize;
- }
- void MediaPresenter::useSubtitleCacheMode(bool use)
- {
- this->m_useSubtitleCacheMode = use;
- }
- bool MediaPresenter::isUseSubtitleCacheMode() const
- {
- return this->m_useSubtitleCacheMode;
- }
- void MediaPresenter::showOptionDesc(const QString &desc)
- {
- if (this->isRunning())
- {
- QMutexLocker locker(&this->m_optionDescMutex);
- this->m_optionDesc = desc;
- this->m_showOptionDesc = true;
- if (this->m_showAudioOptionDescCallback.callback && this->isAudio())
- this->m_showAudioOptionDescCallback.callback(this->m_showAudioOptionDescCallback.userData, desc, true);
- }
- else
- {
- if (this->m_nonePlayingDescCallback.callback)
- this->m_nonePlayingDescCallback.callback(this->m_nonePlayingDescCallback.userData, desc);
- }
- }
- void MediaPresenter::clearFonts()
- {
- this->m_font.clear();
- this->m_subtitleFont.clear();
- }
- void MediaPresenter::clearFrameBuffers()
- {
- this->destroyFrameBufferObject(&this->m_anaglyphFrameBuffer);
- this->destroyFrameBufferObject(&this->m_distortionFrameBuffer);
- this->destroyFrameBufferObject(&this->m_leftDistortionFrameBuffer);
- this->destroyFrameBufferObject(&this->m_rightDistortionFrameBuffer);
- }
- float MediaPresenter::getCPUUsage()
- {
- qint64 pid = QCoreApplication::applicationPid();
- float usage = 0.0f;
- uint64_t processKernelNow = 0;
- uint64_t processUserNow = 0;
- uint64_t systemKernelNow = 0;
- uint64_t systemUserNow = 0;
- uint64_t processKernelElapsed = 0;
- uint64_t processUserElapsed = 0;
- uint64_t systemKernelElapsed = 0;
- uint64_t systemUserElapsed = 0;
- uint64_t totalProcessElapsed = 0;
- uint64_t totalSystemElapsed = 0;
- #ifdef Q_OS_WIN
- ULARGE_INTEGER int64;
- FILETIME dummy;
- FILETIME processFileTimeKernelNow;
- FILETIME processFileTimeUserNow;
- FILETIME systemFileTimeKernelNow;
- FILETIME systemFileTimeUserNow;
- HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
- if (GetProcessTimes(pHandle, &dummy, &dummy, &processFileTimeKernelNow, &processFileTimeUserNow) &&
- GetSystemTimes(&dummy, &systemFileTimeKernelNow, &systemFileTimeUserNow))
- {
- int64.LowPart = processFileTimeKernelNow.dwLowDateTime;
- int64.HighPart = processFileTimeKernelNow.dwHighDateTime;
- processKernelNow = int64.QuadPart;
- int64.LowPart = processFileTimeUserNow.dwLowDateTime;
- int64.HighPart = processFileTimeUserNow.dwHighDateTime;
- processUserNow = int64.QuadPart;
- int64.LowPart = systemFileTimeKernelNow.dwLowDateTime;
- int64.HighPart = systemFileTimeKernelNow.dwHighDateTime;
- systemKernelNow = int64.QuadPart;
- int64.LowPart = systemFileTimeUserNow.dwLowDateTime;
- int64.HighPart = systemFileTimeUserNow.dwHighDateTime;
- systemUserNow = int64.QuadPart;
- }
- if (pHandle)
- CloseHandle(pHandle);
- #elif defined Q_OS_LINUX
- QFile processStat(QString("/proc/%1/stat").arg(pid));
- QFile systemStat("/proc/stat");
- if (!processStat.open(QIODevice::ReadOnly))
- return 0.0f;
- if (!systemStat.open(QIODevice::ReadOnly))
- return 0.0f;
- QTextStream data;
- QString line;
- int idum;
- QString sdum;
- data.setDevice(&processStat);
- …
Large files files are truncated, but you can click here to view the full file