Skip to content

Commit

Permalink
static lib: register io&subtitle. fix vc link error
Browse files Browse the repository at this point in the history
some components symbols in QtAV are not used by other files, for example
the AudioDecoderFFmpeg before 54a7f2c. Their code can be removed by
linker (-dead_strip for ios) then the component can not be registered.
If we use the RegisterXXX_Man symbol in another unit that is stripped,
then that component will be linked to exe and registered (when the base
class is used! for example, subtile is not registered for a minimal
player, why?). But what about
the static construct var?
  • Loading branch information
wang-bin committed Oct 23, 2015
1 parent c25e452 commit efff8be
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/AudioResampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
namespace QtAV {
FACTORY_DEFINE(AudioResampler)

extern void RegisterAudioResamplerFF_Man();
extern void RegisterAudioResamplerLibav_Man();
extern bool RegisterAudioResamplerFF_Man();
extern bool RegisterAudioResamplerLibav_Man();
void AudioResampler::registerAll()
{
static bool done = false;
Expand Down
1 change: 1 addition & 0 deletions src/QtAV/MediaIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Q_AV_EXPORT MediaIO : public QObject
void* avioContext(); //const?
void release(); //TODO: how to remove it?
public:
static void registerAll();
template<class C> static bool Register(MediaIOId id, const char* name) { return Register(id, create<C>, name);}
static MediaIO* create(MediaIOId id);
static MediaIO* create(const char* name);
Expand Down
2 changes: 1 addition & 1 deletion src/QtAV/Subtitle.h
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
Expand Down
2 changes: 1 addition & 1 deletion src/QtAV/private/MediaIO_p.h
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
Expand Down
3 changes: 2 additions & 1 deletion src/QtAV/private/SubtitleProcessor.h
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
Expand Down Expand Up @@ -83,6 +83,7 @@ class Q_AV_PRIVATE_EXPORT SubtitleProcessor
virtual void setFontsDir(const QString& dir) {Q_UNUSED(dir);}
virtual void setFontFileForced(bool force) {Q_UNUSED(force);}
public:
static void registerAll();
template<class C> static bool Register(SubtitleProcessorId id, const char* name) { return Register(id, create<C>, name);}
static SubtitleProcessor* create(SubtitleProcessorId id);
static SubtitleProcessor* create(const char* name = "FFmpeg");
Expand Down
12 changes: 12 additions & 0 deletions src/io/MediaIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ namespace QtAV {

FACTORY_DEFINE(MediaIO)

extern bool RegisterMediaIOQIODevice_Man();
extern bool RegisterMediaIOQFile_Man();
void MediaIO::registerAll()
{
static bool done = false;
if (done)
return;
done = true;
RegisterMediaIOQIODevice_Man();
RegisterMediaIOQFile_Man();
}

QStringList MediaIO::builtInNames()
{
static QStringList names;
Expand Down
1 change: 1 addition & 0 deletions src/libQtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ config_libass {
LIBS += -lass #-lfribidi -lfontconfig -lxml2 -lfreetype -lharfbuzz -lz
DEFINES += CAPI_LINK_ASS
}
DEFINES *= QTAV_HAVE_LIBASS=1
HEADERS *= subtitle/ass_api.h
SOURCES *= subtitle/ass_api.cpp
SOURCES *= subtitle/SubtitleProcessorLibASS.cpp
Expand Down
18 changes: 17 additions & 1 deletion src/subtitle/SubtitleProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,26 @@ namespace QtAV {

FACTORY_DEFINE(SubtitleProcessor)

// can not declare in class member
extern bool RegisterSubtitleProcessorFFmpeg_Man();
extern bool RegisterSubtitleProcessorLibASS_Man();
void SubtitleProcessor::registerAll()
{
static bool done = false;
if (done)
return;
done = true;
RegisterSubtitleProcessorFFmpeg_Man();
#if QTAV_HAVE(LIBASS)
RegisterSubtitleProcessorLibASS_Man();
#endif
}

SubtitleProcessor::SubtitleProcessor()
: m_width(0)
, m_height(0)
{}
{
}

bool SubtitleProcessor::process(const QString &path)
{
Expand Down
7 changes: 4 additions & 3 deletions src/subtitle/SubtitleProcessorLibASS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,14 @@ void SubtitleProcessorLibASS::updateFontCache()

// TODO: let user choose default font or FC
/*
* appdir/fonts has fonts
* appdir/fonts has fonts: set as fontsdir
* - has default.ttf: use default.ttf and disable FC.
* - no default.ttf: appdir/fonts as FC fonts dir
* appFontsDir (appdir/fonts has no fonts)
* - no fonts:
* - has qrc:/fonts/default.ttf: disable FC, save to appFontsDir and use the font
* - has fonts:
* - has default.ttf and size>0: disable FC, save to appFontsDir and use the font
* - has fonts: set as fontsdir
* - has default.ttf and size>0: disable FC, save to appFontsDir, use the font
* - no default.ttf: appFontsDir as FC fonts dir
* fontsDir if it has font files (appFontsDir has no fonts and qrc has no default.ttf): as FC fonts dir
* Skip setting fonts dir
Expand Down Expand Up @@ -683,6 +683,7 @@ void SubtitleProcessorLibASS::renderASS32(QImage *image, ASS_Image *img, int dst
ARGB32_SET(c, r, g, b, k);
#endif //USE_QRGBA
} else {
// c=k*dc/255=k*dc/256 * (1-1/256), -1<err(c) = k*dc/256^2<1, -1 is bad!
#if USE_QRGBA
// no need to &0xff because always be 0~255
dst[x] += qRgba2(k*(r-qRed(dst[x]))/255, k*(g-qGreen(dst[x]))/255, k*(b-qBlue(dst[x]))/255, k*(a-A)/255);
Expand Down

0 comments on commit efff8be

Please sign in to comment.