Skip to content

Instantly share code, notes, and snippets.

@allquixotic
Last active December 4, 2016 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allquixotic/7dc2f3e5f8ccb0fb19686c409cb6a365 to your computer and use it in GitHub Desktop.
Save allquixotic/7dc2f3e5f8ccb0fb19686c409cb6a365 to your computer and use it in GitHub Desktop.
quick QtAV test that fails
  • http://www.qtav.org -- download version 1.11.x (minor version doesn't matter)
  • Get Qt Open Source 5.6.x (minor version doesn't matter) and make sure the compiler matches the QtAV binaries if you use Windows
  • Find sdk_deploy.bat or sdk_deploy.sh in the QtAV binaries and run it after having installed Qt; this will put the QtAV binaries in the right place
  • You might still have to copy libavcodec, libavformat, libswscale, libswresample, libavutil, etc. from the QtAV binaries to the Qt libs directory where the other DLLs / .sos are
  • Run qmake or use Qt Creator GUI to run qmake and build
  • run test.exe

Result that I get is the test fails on the QVERIFY2 within test_convert.cpp saying the buffer is empty. I expect it to have data in it.

#include "convert.h"
using namespace QtAV;
#define QQ qDebug() << i++;
convert::convert(QObject *parent) : QObject(parent)
{
}
//Assume `QIODevice` contains Signed 16-bit LE PCM samples at 48 kHz
QByteArray convert::convertRawToFlac(QIODevice *data, qint32 channels)
{
QByteArray retval;
QBuffer retbuf(&retval, this);
AVTranscoder avt(this);
AVPlayer player;
QVariantHash muxopt, avfopt, encopt;
AudioEncoder *enc;
AudioFormat enc_avformat, dec_avformat;
int i = 1;
avt.setAsync(false);
QQ
if(!data->isOpen())
{
data->open(QIODevice::ReadOnly);
}
QQ
retbuf.open(QIODevice::WriteOnly);
QQ
encopt["compression_level"] = 12;
QQ
dec_avformat.setSampleFormat(AudioFormat::SampleFormat::SampleFormat_Signed16);
dec_avformat.setChannels(channels);
dec_avformat.setSampleRate(48000);
QQ
enc_avformat.setChannels(1);
enc_avformat.setSampleRate(16000);
enc_avformat.setSampleFormat(AudioFormat::SampleFormat::SampleFormat_Signed16);
QQ
player.setIODevice(data);
player.audio()->setBackends(QStringList() << QString::fromLatin1("null"));
player.audio()->setAudioFormat(dec_avformat);
player.setAsyncLoad(false);
QQ
avt.createAudioEncoder();
enc = avt.audioEncoder();
qDebug() << "is enc NULL?" << (enc == NULL);
QQ
enc->setAudioFormat(enc_avformat);
QQ
enc->setCodecName(QString("flac"));
QQ
enc->setOptions(encopt);
QQ
avt.setMediaSource(&player);
QQ
avt.setOutputMedia(&retbuf);
qDebug() << "Is the avt running?" << (avt.isRunning()) << i++;
avt.start();
qDebug() << "Is the avt running?" << (avt.isRunning()) << i++;
qDebug() << "Is the player playing?" << (player.isPlaying()) << i++;
player.play();
qDebug() << "Is the player playing?" << (player.isPlaying()) << i++;
qDebug() << "Is the avt running?" << (avt.isRunning()) << i++;
retbuf.close();
QQ
return retval;
}
#ifndef CONVERT_H
#define CONVERT_H
#include <QtCore>
#include <QtAV>
#include <QtAV/AVTranscoder.h>
class convert : public QObject
{
Q_OBJECT
public:
explicit convert(QObject *parent = 0);
QByteArray convertRawToFlac(QIODevice *data, qint32 channels);
};
#endif // CONVERT_H
QT += testlib av
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
# Input
SOURCES += test_convert.cpp \
convert.cpp
HEADERS += \
../convert.h \
test_convert.h \
test_convert.h
#include <test_convert.h>
#include <iostream>
void TestConvert::testConvertMono()
{
testConvertGeneric(false);
}
void TestConvert::testConvertStereo()
{
testConvertGeneric(true);
}
void TestConvert::testConvertGeneric(bool stereo)
{
AVPlayer player(this);
QString som = (stereo ? "stereo" : "mono");
QString ext = ".raw";
QString filename = "bensound-littleidea-48k-s16le-" + som + ext;
QFile sourcedata(filename, this);
convert conv(this);
QBuffer playbuf(this);
qDebug() << "*=@*=@*=@*=@Before conv.convertRawToFlac() with filename=" << filename.toStdString();
QByteArray playdata = conv.convertRawToFlac(&sourcedata, (stereo ? 2 : 1));
qDebug() << "*=@*=@*=@*=@After conv.convertRawToFlac() with stereo=" << stereo;
QVERIFY2(playdata.length() > 0, "Returned FLAC buffer size was zero!"); //Always fails here.
playbuf.setData(playdata);
player.setIODevice(&playbuf);
qDebug() << "*=@*=@*=@*=@Before player.play()";
player.play();
qDebug() << "*=@*=@*=@*=@Got to end of testConvertGeneric with stereo=" << stereo;
}
QTEST_MAIN(TestConvert)
#ifndef TEST_CONVERT_H
#define TEST_CONVERT_H
#include <QtTest>
#include <QtAV>
#include <convert.h>
using namespace QtAV;
class TestConvert : public QObject
{
Q_OBJECT
private slots:
void testConvertMono();
void testConvertStereo();
private:
void testConvertGeneric(bool stereo);
};
#endif // TEST_CONVERT_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment