Skip to content

Commit

Permalink
add hplayer.conf; retry when disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Dec 2, 2019
1 parent 28a887a commit baf292c
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 44 deletions.
30 changes: 24 additions & 6 deletions Makefile

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@
- 添加人脸检测与识别功能;
- 添加美颜功能;

## DEPENDENTS

git submodule update --init

## BUILD
## Submodule
```
git clone --recurse-submodules https://github.com/ithewei/hplayer.git
```
or
```
git clone https://github.com/ithewei/hplayer.git
git submodule update --init
```

## Mirror
```
https://gitee.com/ithewei/hplayer.git
```

## Build

see BUILD.md

Expand Down
9 changes: 9 additions & 0 deletions bin/msvc14_x86/hplayer.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# [root]

# logfile = hplayer.log
# loglevel = [VERBOSE,DEBUG,INFO,WARN,ERROR,FATAL,SILENT]
loglevel = INFO
log_remain_days = 3
log_filesize = 16M

# generated by app
Binary file modified bin/msvc14_x86/hplayer.exe
Binary file not shown.
4 changes: 3 additions & 1 deletion hplayer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ HEADERS += \
src/hw/base/hmutex.h \
src/hw/base/hthread.h \
src/hw/utils/singleton.h \
src/hw/utils/hframe.h \
src/hw/utils/hgl.h \
src/hw/utils/hframe.h \
src/hw/utils/iniparser.h \
SOURCES += \
src/hw/base/hversion.c \
Expand All @@ -60,6 +61,7 @@ SOURCES += \
src/hw/base/hlog.c \
src/hw/base/hstring.cpp \
src/hw/utils/hframe.cpp \
src/hw/utils/iniparser.cpp \
# qt
INCLUDEPATH += src/qt
Expand Down
4 changes: 3 additions & 1 deletion hplayer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<ClCompile Include="src\hw\base\herr.c" />
<ClCompile Include="src\video\hffplayer.cpp" />
<ClCompile Include="src\hw\utils\hframe.cpp" />
<ClCompile Include="src\hw\utils\iniparser.cpp" />
<ClCompile Include="src\hw\base\hlog.c" />
<ClCompile Include="src\hw\base\hstring.cpp" />
<ClCompile Include="src\ui\htable.cpp" />
Expand Down Expand Up @@ -171,6 +172,7 @@
<ClInclude Include="src\video\hffplayer.h" />
<ClInclude Include="src\hw\utils\hframe.h" />
<ClInclude Include="src\hw\utils\hgl.h" />
<ClInclude Include="src\hw\utils\iniparser.h" />
<ClInclude Include="src\hw\base\hgui.h" />
<ClInclude Include="src\hw\base\hlog.h" />
<ClInclude Include="src\video\hmedia.h" />
Expand Down Expand Up @@ -270,4 +272,4 @@
<Import Project="$(QtMsBuild)\qt.targets" />
</ImportGroup>
<ImportGroup Label="ExtensionTargets" />
</Project>
</Project>
37 changes: 37 additions & 0 deletions hplayer_resource.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <windows.h>

IDI_ICON1 ICON DISCARDABLE "G:\\Qt\\HPlayer\\favicon.ico"

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,0,0
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "\0"
VALUE "FileVersion", "0.0.0.0\0"
VALUE "LegalCopyright", "\0"
VALUE "OriginalFilename", "hplayer.exe\0"
VALUE "ProductName", "hplayer\0"
VALUE "ProductVersion", "0.0.0.0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END
/* End of Version info */

8 changes: 8 additions & 0 deletions src/confile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef HPLAYER_CONFILE_H_
#define HPLAYER_CONFILE_H_

#include "iniparser.h"

extern IniParser* g_confile;

#endif // HPLAYER_CONFILE_H_
2 changes: 1 addition & 1 deletion src/hw
Submodule hw updated from cf10de to 2c5b6e
75 changes: 72 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "mainwindow.h"
#include "qtstyles.h"
#include "appdef.h"
#include "confile.h"

IniParser* g_confile = NULL;

#define LOG_LEVEL 0

Expand Down Expand Up @@ -54,10 +57,73 @@ void qLogHandler(QtMsgType type, const QMessageLogContext & ctx, const QString &

int main(int argc, char *argv[]) {
qInstallMessageHandler(qLogHandler);
hlog_set_file(APP_NAME".log");
hlog_set_level(LOG_LEVEL_INFO);

hlogi("%s", get_compile_version());
g_confile = new IniParser;
g_confile->LoadFromFile(APP_NAME".conf");
// logfile
string str = g_confile->GetValue("logfile");
if (!str.empty()) {
hlog_set_file(str.c_str());
}
else {
hlog_set_file(APP_NAME".log");
}
// loglevel
const char* szLoglevel = g_confile->GetValue("loglevel").c_str();
int loglevel = LOG_LEVEL_DEBUG;
if (stricmp(szLoglevel, "VERBOSE") == 0) {
loglevel = LOG_LEVEL_VERBOSE;
} else if (stricmp(szLoglevel, "DEBUG") == 0) {
loglevel = LOG_LEVEL_DEBUG;
} else if (stricmp(szLoglevel, "INFO") == 0) {
loglevel = LOG_LEVEL_INFO;
} else if (stricmp(szLoglevel, "WARN") == 0) {
loglevel = LOG_LEVEL_WARN;
} else if (stricmp(szLoglevel, "ERROR") == 0) {
loglevel = LOG_LEVEL_ERROR;
} else if (stricmp(szLoglevel, "FATAL") == 0) {
loglevel = LOG_LEVEL_FATAL;
} else if (stricmp(szLoglevel, "SILENT") == 0) {
loglevel = LOG_LEVEL_SILENT;
} else {
loglevel = LOG_LEVEL_INFO;
}
hlog_set_level(loglevel);
// log_filesize
str = g_confile->GetValue("log_filesize");
if (!str.empty()) {
int num = atoi(str.c_str());
if (num > 0) {
// 16 16M 16MB
const char* p = str.c_str() + str.size() - 1;
char unit;
if (*p >= '0' && *p <= '9') unit = 'M';
else if (*p == 'B') unit = *(p-1);
else unit = *p;
unsigned long long filesize = num;
switch (unit) {
case 'K': filesize <<= 10; break;
case 'M': filesize <<= 20; break;
case 'G': filesize <<= 30; break;
default: filesize <<= 20; break;
}
hlog_set_max_filesize(filesize);
}
}
// log_remain_days
str = g_confile->GetValue("log_remain_days");
if (!str.empty()) {
hlog_set_remain_days(atoi(str.c_str()));
}
// log_fsync
str = g_confile->GetValue("log_fsync");
if (!str.empty()) {
logger_enable_fsync(hlog, getboolean(str.c_str()));
}
// first log here
hlogi("%s version: %s", argv[0], get_compile_version());
hlog_fsync();

qInfo("-------------------app start----------------------------------");
QApplication a(argc, argv);
a.setApplicationName(APP_NAME);
Expand All @@ -76,5 +142,8 @@ int main(int argc, char *argv[]) {

MainWindow::exitInstance();
qInfo("-------------------app end----------------------------------");

g_confile->Save();
SAFE_DELETE(g_confile);
return retcode;
}
7 changes: 7 additions & 0 deletions src/ui/HOpenMediaDlg.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "HOpenMediaDlg.h"
#include "hdevice.h"
#include "confile.h"

FileTab::FileTab(QWidget *parent) : QWidget(parent) {
QVBoxLayout* vbox = new QVBoxLayout;
Expand All @@ -9,6 +10,7 @@ FileTab::FileTab(QWidget *parent) : QWidget(parent) {

QHBoxLayout* hbox = new QHBoxLayout;
edit = new QLineEdit;
edit->setText(g_confile->GetValue("last_file_source").c_str());
hbox->addWidget(edit);
btnBrowse = new QPushButton("...");
connect(btnBrowse, &QPushButton::clicked, this, [=]() {
Expand All @@ -34,6 +36,7 @@ NetworkTab::NetworkTab(QWidget *parent) : QWidget(parent) {
vbox->addWidget(new QLabel(tr("URL:")));

edit = new QLineEdit;
edit->setText(g_confile->GetValue("last_network_source").c_str());

vbox->addWidget(edit);
vbox->addStretch();
Expand Down Expand Up @@ -99,6 +102,8 @@ void HOpenMediaDlg::accept() {
if (filetab) {
media.type = MEDIA_TYPE_FILE;
media.src = qPrintable(filetab->edit->text());
g_confile->SetValue("last_file_source", media.src);
g_confile->Save();
}
}
break;
Expand All @@ -108,6 +113,8 @@ void HOpenMediaDlg::accept() {
if (nettab) {
media.type = MEDIA_TYPE_NETWORK;
media.src = qPrintable(nettab->edit->text());
g_confile->SetValue("last_network_source", media.src);
g_confile->Save();
}
}
break;
Expand Down
45 changes: 43 additions & 2 deletions src/ui/HVideoWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
#include "HOpenMediaDlg.h"
#include "HVideoPlayerFactory.h"

#define DEFAULT_RETRY_INTERVAL 3000 // ms
#define DEFAULT_RETRY_MAXCNT 100

HVideoWidget::HVideoWidget(QWidget *parent) : QFrame(parent)
{
playerid = 0;
status = STOP;
pImpl_player = NULL;
// retry
retry_interval = DEFAULT_RETRY_INTERVAL;
max_retry_cnt = DEFAULT_RETRY_MAXCNT;
last_retry_time = 0;
retry_cnt = 0;

initUI();
initConnect();
Expand Down Expand Up @@ -155,7 +163,7 @@ void HVideoWidget::start() {
pImpl_player->resume();
}

timer->start(1000/pImpl_player->fps);
timer->start(1000 / pImpl_player->fps);
status = PLAY;

end:
Expand All @@ -174,6 +182,9 @@ void HVideoWidget::stop() {
videoWnd->update();
status = STOP;

last_retry_time = 0;
retry_cnt = 0;

updateUI();
}

Expand All @@ -198,8 +209,38 @@ void HVideoWidget::onTimerUpdate() {
videoWnd->update();
}
else {
if (pImpl_player->signal == SIGNAL_END_OF_FILE) {
if (pImpl_player->flags == EOF) {
stop();
return;
}
if (pImpl_player->error != 0) {
switch (media.type) {
case MEDIA_TYPE_NETWORK:
// retry
if (retry_cnt < max_retry_cnt) {
uint64_t cur_time = timestamp_ms();
if (cur_time - last_retry_time > retry_interval) {
++retry_cnt;
last_retry_time = cur_time;
pImpl_player->stop();
int ret = pImpl_player->start();
if (ret != 0) {
hlogw("retry cnt=%d media.src=%s failed!", retry_cnt, media.src.c_str());
}
else {
hlogi("retry cnt=%d media.src=%s succeed!", retry_cnt, media.src.c_str());
retry_cnt = 0;
}
}
}
else {
stop();
}
break;
default:
stop();
break;
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/ui/HVideoWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "HVideoToolbar.h"
#include "HVideoPlayer.h"

class HVideoWidget : public QFrame
class HVideoWidget : public QFrame
{
Q_OBJECT
public:
Expand Down Expand Up @@ -64,6 +64,11 @@ public slots:

HMedia media;
HVideoPlayer* pImpl_player;
// for retry when SIGNAL_END_OF_FILE
uint64_t retry_interval;
int max_retry_cnt;
uint64_t last_retry_time;
int retry_cnt;
};

#endif // H_VIDEO_WIDGET_H
8 changes: 4 additions & 4 deletions src/video/HVideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#define DEFAULT_FPS 25
#define DEFAULT_FRAME_CACHE 5

#define SIGNAL_END_OF_FILE 0x01

#define HARDWARE_DECODE 1
#define SOFTWARE_DECODE 2

Expand All @@ -37,7 +35,8 @@ class HVideoPlayer
decode_mode = DEFAULT_DECODE_MODE;
duration = 0;
start_time = 0;
signal = 0;
error = 0;
flags = 0;
}

virtual ~HVideoPlayer() {}
Expand Down Expand Up @@ -85,7 +84,8 @@ class HVideoPlayer
int decode_mode;
int64_t duration; // ms
int64_t start_time; // ms
int signal;
int error;
int flags;
protected:
HFrameBuf frame_buf;
};
Expand Down
Loading

0 comments on commit baf292c

Please sign in to comment.