forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
126 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 1,9 @@ | ||
[submodule "contrib/libchardet"] | ||
path = contrib/libchardet | ||
url = https://github.com/wang-bin/libchardet.git | ||
[submodule "contrib/capi"] | ||
path = contrib/capi | ||
url = https://github.com/wang-bin/capi.git | ||
[submodule "tools/build_ffmpeg"] | ||
path = tools/build_ffmpeg | ||
url = https://github.com/wang-bin/build_ffmpeg.git | ||
[submodule "contrib/uchardet"] | ||
path = contrib/uchardet | ||
url = https://github.com/BYVoid/uchardet.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,25 @@ | ||
/****************************************************************************** | ||
QtAV: Media play library based on Qt and FFmpeg | ||
Copyright (C) 2015 Wang Bin <[email protected]> | ||
* This file is part of QtAV | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library 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 | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
******************************************************************************/ | ||
#include <uchardet.h> | ||
|
||
void test() { | ||
uchardet_new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,5 @@ | ||
include(../paths.pri) | ||
|
||
TARGET = uchardet_test | ||
SOURCES = main.cpp | ||
LIBS = -luchardet |
Submodule libchardet
deleted from
38c9fb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,53 @@ | ||
UCHARDET_SRC = $$PWD/uchardet/src | ||
INCLUDEPATH = $$UCHARDET_SRC | ||
HEADERS = \ | ||
$$UCHARDET_SRC/uchardet.h \ | ||
$$UCHARDET_SRC/nsMBCSGroupProber.h \ | ||
$$UCHARDET_SRC/nsGB2312Prober.h \ | ||
$$UCHARDET_SRC/nsUTF8Prober.h \ | ||
$$UCHARDET_SRC/nsBig5Prober.h \ | ||
$$UCHARDET_SRC/nsEUCTWProber.h \ | ||
$$UCHARDET_SRC/nsCharSetProber.h \ | ||
$$UCHARDET_SRC/nsSBCSGroupProber.h \ | ||
$$UCHARDET_SRC/nsCodingStateMachine.h \ | ||
$$UCHARDET_SRC/nsEUCKRProber.h \ | ||
$$UCHARDET_SRC/nsUniversalDetector.h \ | ||
$$UCHARDET_SRC/nsSJISProber.h \ | ||
$$UCHARDET_SRC/nsLatin1Prober.h \ | ||
$$UCHARDET_SRC/nsSBCharSetProber.h \ | ||
$$UCHARDET_SRC/nscore.h \ | ||
$$UCHARDET_SRC/CharDistribution.h \ | ||
$$UCHARDET_SRC/nsPkgInt.h \ | ||
$$UCHARDET_SRC/nsEscCharsetProber.h \ | ||
$$UCHARDET_SRC/nsHebrewProber.h \ | ||
$$UCHARDET_SRC/prmem.h \ | ||
$$UCHARDET_SRC/JpCntx.h \ | ||
$$UCHARDET_SRC/nsEUCJPProber.h | ||
|
||
SOURCES = \ | ||
$$UCHARDET_SRC/uchardet.cpp \ | ||
$$UCHARDET_SRC/nsEUCTWProber.cpp \ | ||
$$UCHARDET_SRC/LangCyrillicModel.cpp \ | ||
$$UCHARDET_SRC/nsSBCharSetProber.cpp \ | ||
$$UCHARDET_SRC/CharDistribution.cpp \ | ||
$$UCHARDET_SRC/nsLatin1Prober.cpp \ | ||
$$UCHARDET_SRC/nsEscSM.cpp \ | ||
$$UCHARDET_SRC/nsUTF8Prober.cpp \ | ||
$$UCHARDET_SRC/nsBig5Prober.cpp \ | ||
$$UCHARDET_SRC/LangBulgarianModel.cpp \ | ||
$$UCHARDET_SRC/nsGB2312Prober.cpp \ | ||
$$UCHARDET_SRC/nsCharSetProber.cpp \ | ||
$$UCHARDET_SRC/nsEscCharsetProber.cpp \ | ||
$$UCHARDET_SRC/nsEUCKRProber.cpp \ | ||
$$UCHARDET_SRC/nsEUCJPProber.cpp \ | ||
$$UCHARDET_SRC/nsSJISProber.cpp \ | ||
$$UCHARDET_SRC/nsMBCSSM.cpp \ | ||
$$UCHARDET_SRC/nsHebrewProber.cpp \ | ||
$$UCHARDET_SRC/nsUniversalDetector.cpp \ | ||
$$UCHARDET_SRC/nsSBCSGroupProber.cpp \ | ||
$$UCHARDET_SRC/nsMBCSGroupProber.cpp \ | ||
$$UCHARDET_SRC/LangThaiModel.cpp \ | ||
$$UCHARDET_SRC/LangHebrewModel.cpp \ | ||
$$UCHARDET_SRC/JpCntx.cpp \ | ||
$$UCHARDET_SRC/LangHungarianModel.cpp \ | ||
$$UCHARDET_SRC/LangGreekModel.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 1,6 @@ | ||
/****************************************************************************** | ||
QtAV: Media play library based on Qt and FFmpeg | ||
Copyright (C) 2014 Wang Bin <[email protected]> | ||
Copyright (C) 2014-2015 Wang Bin <[email protected]> | ||
* This file is part of QtAV | ||
|
@@ -18,130 18,51 @@ | |
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
******************************************************************************/ | ||
|
||
#include "CharsetDetector.h" | ||
#include "QtAV/QtAV_Global.h" | ||
#include <cassert> | ||
#include <QtCore/QLibrary> | ||
#include "utils/Logger.h" | ||
|
||
#if QTAV_HAVE(CHARDET) | ||
#include <chardet.h> | ||
class CharDet { | ||
public: | ||
bool isLoaded() { return true;} | ||
}; | ||
#ifdef LINK_UCHARDET | ||
#include <uchardet/uchardet.h> | ||
#define HAVE_UCHARDET | ||
#else | ||
//from https://github.com/cnangel/libchardet, chardet.h | ||
#define CHARDET_RESULT_OK 0 | ||
#define CHARDET_RESULT_NOMEMORY (-1) | ||
#define CHARDET_RESULT_INVALID_DETECTOR (-2) | ||
|
||
#define CHARDET_MAX_ENCODING_NAME 64 | ||
|
||
typedef void* chardet_t; | ||
|
||
class dll_helper { | ||
public: | ||
dll_helper(const QString& soname) { | ||
m_lib.setFileName(soname); | ||
if (m_lib.load()) | ||
qDebug("%s loaded", m_lib.fileName().toUtf8().constData()); | ||
else | ||
qDebug("can not load %s: %s", m_lib.fileName().toUtf8().constData(), m_lib.errorString().toUtf8().constData()); | ||
|
||
} | ||
virtual ~dll_helper() { m_lib.unload();} | ||
bool isLoaded() const { return m_lib.isLoaded(); } | ||
void* resolve(const char *symbol) { return (void*)m_lib.resolve(symbol);} | ||
private: | ||
QLibrary m_lib; | ||
}; | ||
|
||
class CharDet : public dll_helper { | ||
public: | ||
typedef int chardet_create_t(chardet_t* pdet); | ||
typedef void chardet_destroy_t(chardet_t det); | ||
typedef int chardet_handle_data_t(chardet_t det, const char* data, unsigned int len); | ||
typedef int chardet_data_end_t(chardet_t det); | ||
typedef int chardet_reset_t(chardet_t det); | ||
typedef int chardet_get_charset_t(chardet_t det, char* namebuf, unsigned int buflen); | ||
#ifdef BUILD_UCHARDET | ||
#include "uchardet.h" | ||
#define HAVE_UCHARDET | ||
#endif | ||
#endif //LINK_UCHARDET | ||
|
||
CharDet() : dll_helper("chardet") { | ||
fp_chardet_create = (chardet_create_t*)resolve("chardet_create"); | ||
fp_chardet_destroy = (chardet_destroy_t*)resolve("chardet_destroy"); | ||
fp_chardet_handle_data = (chardet_handle_data_t*)resolve("chardet_handle_data"); | ||
fp_chardet_data_end = (chardet_data_end_t*)resolve("chardet_data_end"); | ||
fp_chardet_reset = (chardet_reset_t*)resolve("chardet_reset"); | ||
fp_chardet_get_charset = (chardet_get_charset_t*)resolve("chardet_get_charset"); | ||
} | ||
int chardet_create(chardet_t* pdet) { | ||
assert(fp_chardet_create); | ||
return fp_chardet_create(pdet); | ||
} | ||
void chardet_destroy(chardet_t det) { | ||
assert(fp_chardet_destroy); | ||
fp_chardet_destroy(det); | ||
} | ||
int chardet_handle_data(chardet_t det, const char* data, unsigned int len) { | ||
assert(fp_chardet_handle_data); | ||
return fp_chardet_handle_data(det, data, len); | ||
} | ||
int chardet_data_end(chardet_t det) { | ||
assert(fp_chardet_data_end); | ||
return fp_chardet_data_end(det); | ||
} | ||
int chardet_reset(chardet_t det) { | ||
assert(fp_chardet_reset); | ||
return fp_chardet_reset(det); | ||
} | ||
int chardet_get_charset(chardet_t det, char* namebuf, unsigned int buflen) { | ||
assert(fp_chardet_get_charset); | ||
return fp_chardet_get_charset(det, namebuf, buflen); | ||
} | ||
private: | ||
chardet_create_t* fp_chardet_create; | ||
chardet_destroy_t* fp_chardet_destroy; | ||
chardet_handle_data_t* fp_chardet_handle_data; | ||
chardet_data_end_t* fp_chardet_data_end; | ||
chardet_reset_t* fp_chardet_reset; | ||
chardet_get_charset_t* fp_chardet_get_charset; | ||
}; | ||
#endif //QTAV_HAVE(CHARDET) | ||
class CharsetDetector::Private : public CharDet | ||
class CharsetDetector::Private | ||
{ | ||
public: | ||
Private() | ||
: CharDet() | ||
, m_det(NULL) | ||
: m_det(NULL) | ||
{ | ||
if (!isLoaded()) | ||
return; | ||
int ret = chardet_create(&m_det); | ||
if (ret != CHARDET_RESULT_OK) | ||
m_det = NULL; | ||
#ifdef HAVE_UCHARDET | ||
m_det = uchardet_new(); | ||
#endif | ||
} | ||
~Private() { | ||
if (!m_det) | ||
return; | ||
chardet_destroy(m_det); | ||
#ifdef HAVE_UCHARDET | ||
uchardet_delete(m_det); | ||
#endif | ||
m_det = NULL; | ||
} | ||
|
||
QByteArray detect(const QByteArray& data) { | ||
#ifdef HAVE_UCHARDET | ||
if (!m_det) | ||
return QByteArray(); | ||
int ret = chardet_handle_data(m_det, data.constData(), data.size()); | ||
if (ret != CHARDET_RESULT_OK) | ||
if (uchardet_handle_data(m_det, data.constData(), data.size()) != 0) | ||
return QByteArray(); | ||
chardet_data_end(m_det); | ||
QByteArray cs(256, ' '); | ||
chardet_get_charset(m_det, cs.data(), cs.size()); | ||
chardet_reset(m_det); | ||
uchardet_data_end(m_det); | ||
QByteArray cs(uchardet_get_charset(m_det)); | ||
uchardet_reset(m_det); | ||
return cs.trimmed(); | ||
#else | ||
return QByteArray(); | ||
#endif | ||
} | ||
|
||
chardet_t m_det; | ||
uchardet_t m_det; | ||
}; | ||
|
||
CharsetDetector::CharsetDetector() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 1,6 @@ | ||
/****************************************************************************** | ||
QtAV: Media play library based on Qt and FFmpeg | ||
Copyright (C) 2014 Wang Bin <[email protected]> | ||
Copyright (C) 2014-2015 Wang Bin <[email protected]> | ||
* This file is part of QtAV | ||
|
@@ -19,8 19,8 @@ | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
******************************************************************************/ | ||
|
||
#ifndef QTAV_CHARSETDETECTOR_H | ||
#define QTAV_CHARSETDETECTOR_H | ||
#ifndef QTAV_UCHARDET_H | ||
#define QTAV_UCHARDET_H | ||
|
||
#include <QtCore/QByteArray> | ||
|
||
|
@@ -41,4 41,4 @@ class CharsetDetector | |
Private *priv; | ||
}; | ||
|
||
#endif // QTAV_CHARSETDETECTOR_H | ||
#endif // QTAV_UCHARDET_H |