Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
* New: cache information in playback information
Browse files Browse the repository at this point in the history
  • Loading branch information
bylee20 committed Oct 21, 2013
1 parent 84d3e9f commit 4e86980
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/cmplayer/imports/CMPlayerSkin/PlayInfoView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,22 @@ Item {
styleColor: "black"
}
Text {
id: videoinfo
id: cacheinfo
anchors.top: resources.bottom
anchors.left: parent.left
width: contentWidth
height: contentHeight
font.pixelSize: wrapper.fontSize
font.family: wrapper.fontFamily
color: "yellow"
style: Text.Outline
styleColor: "black"
text: qsTr("Cache: %1").arg(engine.cache < 0 ? qsTr("Unavailable") : (engine.cache*100.0).toFixed(0) + "%");
}
Text {
id: videoinfo
anchors.top: cacheinfo.bottom
anchors.left: parent.left
anchors.topMargin: wrapper.fontSize
width: contentWidth
height: contentHeight
Expand Down
16 changes: 15 additions & 1 deletion src/cmplayer/playengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct PlayEngine::Data {
int volume = 100;
double amp = 1.0;
double speed = 1.0;
qreal cache = -1.0;
MPContext *mpctx = nullptr;
VideoOutput *video = nullptr;
GetMrlInt getStartTimeFunc, getCacheFunc;
Expand Down Expand Up @@ -285,6 +286,10 @@ PlayEngine::~PlayEngine() {
delete d;
}

qreal PlayEngine::cache() const {
return d->cache;
}

int PlayEngine::begin() const { return d->begin; }
int PlayEngine::end() const { return d->begin + d->duration; }

Expand Down Expand Up @@ -527,6 +532,10 @@ void PlayEngine::customEvent(QEvent *event) {
d->dvd = getData<DvdInfo>(event);
emit dvdInfoChanged();
break;
case UpdateCache:
d->cache = getData<int>(event)*1e-2;
emit cacheChanged();
break;
case UpdateTrack: {
auto streams = getData<std::array<StreamList, STREAM_TYPE_COUNT>>(event);
if (_CheckSwap(d->videoStreams, streams[STREAM_VIDEO]))
Expand All @@ -551,11 +560,13 @@ void PlayEngine::customEvent(QEvent *event) {
d->audioInfo.setAudio(this);
d->start = 0;
d->position = 0;
d->cache = -1;
emit tick(d->position);
emit seekableChanged(isSeekable());
emit started(d->playlist.loadedMrl());
emit mediaChanged();
emit audioChanged();
emit cacheChanged();
break;
case StateChange: {
const auto state = getData<PlayEngine::State>(event);
Expand Down Expand Up @@ -708,7 +719,7 @@ int PlayEngine::playAudioVideo(const Mrl &/*mrl*/, int &terminated, int &duratio
if (error != MPERROR_NONE)
return error;
DvdInfo dvd;
if (!strcmp(mpctx->stream->info->name, "dvd")) {
if (mpctx->stream && mpctx->stream->info && !strcmp(mpctx->stream->info->name, "dvd")) {
char buffer[256];
if (dvd_volume_id(mpctx->stream, buffer, sizeof(buffer)))
dvd.volume = QString::fromLocal8Bit(buffer);
Expand Down Expand Up @@ -750,6 +761,7 @@ int PlayEngine::playAudioVideo(const Mrl &/*mrl*/, int &terminated, int &duratio
postData(this, StreamOpen);
d->tellmp("vf set", d->vfs);
auto state = this->state(), newState = Loading;
int cache = -1;
while (!mpctx->stop_play) {
if (!duration)
checkTimeRange();
Expand All @@ -763,6 +775,8 @@ int PlayEngine::playAudioVideo(const Mrl &/*mrl*/, int &terminated, int &duratio
newState = Paused;
if (_Change(state, newState))
setState(state);
if (_Change(cache, mp_get_cache_percent(mpctx)))
postData(this, UpdateCache, cache);
}
terminated = time();
duration = this->duration();
Expand Down
3 changes: 3 additions & 0 deletions src/cmplayer/playengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PlayEngine : public QObject {
Q_PROPERTY(QString hardwareAccelerationText READ hwAccText NOTIFY hwAccChanged)
Q_PROPERTY(double relativePosition READ relativePosition NOTIFY relativePositionChanged)
Q_PROPERTY(QQuickItem *screen READ screen)
Q_PROPERTY(qreal cache READ cache NOTIFY cacheChanged)
public:
enum State {Stopped = 1, Playing = 2, Paused = 4, Finished = 8, Loading = 16, Error = 32, Running = Playing | Loading };
enum class HardwareAcceleration { Unavailable, Deactivated, Activated };
Expand Down Expand Up @@ -136,6 +137,7 @@ class PlayEngine : public QObject {
double relativePosition() const { return (double)(time()-begin())/duration(); }
Q_INVOKABLE double bps(double fps) const;
static void registerObjects();
qreal cache() const;
public slots:
void setVolume(int volume);
void setAmp(double amp);
Expand Down Expand Up @@ -179,6 +181,7 @@ public slots:
void runningChanged();
void relativePositionChanged();
void hwAccChanged();
void cacheChanged();
private:
int playImage(const Mrl &mrl, int &terminated, int &duration);
int playAudioVideo(const Mrl &mrl, int &terminated, int &duration);
Expand Down
2 changes: 1 addition & 1 deletion src/cmplayer/playengine_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void mp_msg_log_va2(struct mp_log *log, int lev, const char *format, va_list va)

enum EventType {
UserType = QEvent::User, TimeRangeChange, StreamOpen, UpdateTrack, StateChange, MrlStopped, MrlFinished, PlaylistFinished, MrlChanged, VideoFormatChanged, UpdateChapterList,
HwAccChanged, UpdateDVDInfo
HwAccChanged, UpdateDVDInfo, UpdateCache
};

enum MpCmd : int {
Expand Down

0 comments on commit 4e86980

Please sign in to comment.