Skip to content

Commit

Permalink
added support for avdevice by forcing input format
Browse files Browse the repository at this point in the history
  • Loading branch information
sherpya committed Oct 13, 2014
1 parent 9fa43d5 commit d59c1c1
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 3 deletions.
3 changes: 2 additions & 1 deletion QtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 33,8 @@ OTHER_FILES = \
EssentialDepends = avutil avcodec avformat swscale
OptionalDepends = \
swresample \
avresample
avresample \
avdevice
# QtOpenGL module. In Qt5 we can disable it and still have opengl support
!no-gl:!no-widgets: OptionalDepends *= gl
!no-avfilter: OptionalDepends *= avfilter
Expand Down
12 changes: 12 additions & 0 deletions config.tests/avdevice/avdevice.pro
Original file line number Diff line number Diff line change
@@ -0,0 1,12 @@
CONFIG -= qt
CONFIG = console
DEFINES = __STDC_CONSTANT_MACROS
*msvc* {
#link FFmpeg and portaudio which are built by gcc need /SAFESEH:NO
QMAKE_LFLAGS = /SAFESEH:NO
INCLUDEPATH = ../../src/compat/msvc
}
SOURCES = main.cpp

LIBS = -lavdevice
include(../paths.pri)
26 changes: 26 additions & 0 deletions config.tests/avdevice/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 1,26 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013 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 <libavdevice/avdevice.h>

int main()
{
return 0;
}
3 changes: 3 additions & 0 deletions src/AVCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 43,9 @@ void ffmpeg_version_print()
#if QTAV_HAVE(AVFILTER)
{ "avfilter", LIBAVFILTER_VERSION_INT, avfilter_version() },
#endif //QTAV_HAVE(AVFILTER)
#if QTAV_HAVE(AVDEVICE)
{ "avdevice", LIBAVDEVICE_VERSION_INT, avdevice_version() },
#endif //QTAV_HAVE(AVDEVICE)
{ 0, 0, 0}
};
for (int i = 0; components[i].lib != 0; i) {
Expand Down
22 changes: 20 additions & 2 deletions src/AVDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 154,7 @@ AVDemuxer::AVDemuxer(const QString& fileName, QObject *parent)
, v_codec_context(0)
, s_codec_contex(0)
, _file_name(fileName)
, _iformat(0)
, m_pQAVIO(0)
, mSeekUnit(SeekByTime)
, mSeekTarget(SeekTarget_AccurateFrame)
Expand All @@ -164,6 165,9 @@ AVDemuxer::AVDemuxer(const QString& fileName, QObject *parent)
AVInitializer() {
qDebug("av_register_all, avcodec_register_all, avformat_network_init");
avcodec_register_all();
#if QTAV_HAVE(AVDEVICE)
avdevice_register_all();
#endif
av_register_all();
avformat_network_init();
}
Expand Down Expand Up @@ -451,6 455,20 @@ bool AVDemuxer::loadFile(const QString &fileName)
_file_name.insert(3, 'h');
else if (_file_name.startsWith("file://"))
_file_name.remove("file://");
#if QTAV_HAVE(AVDEVICE)
else if (_file_name.startsWith("avdevice:"))
{
// avdevice:video4linux2:file_name
QStringList parts = _file_name.split(":");
if (parts.count() != 3)
{
qDebug("invalid avdevice specification");
return false;
}
_iformat = av_find_input_format(parts[1].toUtf8().constData());
_file_name = parts[2];
}
#endif
if (m_pQAVIO)
m_pQAVIO->setDevice(0);
return load();
Expand Down Expand Up @@ -491,13 509,13 @@ bool AVDemuxer::load()

qDebug("avformat_open_input: format_context:'%p'...",format_context);
mpInterrup->begin(InterruptHandler::Open);
ret = avformat_open_input(&format_context, "iodevice", NULL, mOptions.isEmpty() ? NULL : &mpDict);
ret = avformat_open_input(&format_context, "iodevice", _iformat, mOptions.isEmpty() ? NULL : &mpDict);
mpInterrup->end();
qDebug("avformat_open_input: (with io device) ret:%d", ret);
} else {
qDebug("avformat_open_input: format_context:'%p', url:'%s'...",format_context, qPrintable(_file_name));
mpInterrup->begin(InterruptHandler::Open);
ret = avformat_open_input(&format_context, _file_name.toUtf8().constData(), NULL, mOptions.isEmpty() ? NULL : &mpDict);
ret = avformat_open_input(&format_context, _file_name.toUtf8().constData(), _iformat, mOptions.isEmpty() ? NULL : &mpDict);
mpInterrup->end();
qDebug("avformat_open_input: url:'%s' ret:%d",qPrintable(_file_name), ret);
}
Expand Down
2 changes: 2 additions & 0 deletions src/QtAV/AVDemuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 37,7 @@ typedef QTime QElapsedTimer;
#endif

struct AVFormatContext;
struct AVInputFormat;
struct AVCodecContext;
struct AVCodec;
struct AVFrame;
Expand Down Expand Up @@ -224,6 225,7 @@ class Q_AV_EXPORT AVDemuxer : public QObject //QIODevice?
AVCodecContext *a_codec_context, *v_codec_context, *s_codec_contex;
//copy the info, not parse the file when constructed, then need member vars
QString _file_name;
AVInputFormat *_iformat;
QAVIOContext* m_pQAVIO;
QMutex mutex; //for seek and readFrame
QElapsedTimer seek_timer;
Expand Down
4 changes: 4 additions & 0 deletions src/QtAV/private/AVCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 71,10 @@ extern "C"
#endif
#endif //QTAV_HAVE(AVFILTER)

#if QTAV_HAVE(AVDEVICE)
#include <libavdevice/avdevice.h>
#endif

#ifdef __cplusplus
}
#endif /*__cplusplus*/
Expand Down
3 changes: 3 additions & 0 deletions src/QtAV_Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 118,9 @@ QString aboutFFmpeg_HTML()
#if QTAV_HAVE(AVRESAMPLE)
{ FF_COMPONENT(avresample, AVRESAMPLE) },
#endif //QTAV_HAVE(AVRESAMPLE)
#if QTAV_HAVE(AVDEVICE)
{ FF_COMPONENT(avdevice, AVDEVICE) },
#endif //QTAV_HAVE(AVDEVICE)
#undef FF_COMPONENT
{ 0, 0, 0, 0, 0 }
};
Expand Down
4 changes: 4 additions & 0 deletions src/libQtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 105,10 @@ config_avresample {
SOURCES = AudioResamplerLibav.cpp
LIBS = -lavresample
}
config_avdevice {
DEFINES = QTAV_HAVE_AVDEVICE=1
LIBS = -lavdevice
}
config_ipp {
DEFINES = QTAV_HAVE_IPP=1
ICCROOT = $$(IPPROOT)/../compiler
Expand Down

0 comments on commit d59c1c1

Please sign in to comment.