Commit a97b9d9b authored by Tristan Matthews's avatar Tristan Matthews

* #6094, #6075: added API to query installed/supported codecs, with tests

parent 8d09feca
......@@ -3,7 +3,8 @@ SUBDIRS=test
noinst_PROGRAMS = ffmpeg2rtp ffmpeg2shm
noinst_LTLIBRARIES = libvideo_endpoint.la
libvideo_endpoint_la_SOURCES = video_endpoint.cpp video_endpoint.h
libvideo_endpoint_la_SOURCES = video_endpoint.cpp video_endpoint.h \
libav_utils.cpp libav_utils.h
libvideo_endpoint_la_LIBADD = @LIBAVFORMAT_LIBS@
AM_CXXFLAGS=@LIBAVCODEC_CFLAGS@ @LIBAVFORMAT_CFLAGS@ @LIBAVDEVICE_CFLAGS@ @LIBSWSCALE_CFLAGS@
......
/*
* Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include "libav_utils.h"
#include <list>
#include <algorithm>
#include <string>
#include <iostream>
extern "C" {
#define __STDC_CONSTANT_MACROS
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
namespace libav_utils {
bool isSupportedCodec(const char *name)
{
static std::list<std::string> SUPPORTED_CODECS;
if (SUPPORTED_CODECS.empty())
{
SUPPORTED_CODECS.push_back("mpeg4");
SUPPORTED_CODECS.push_back("h263p");
SUPPORTED_CODECS.push_back("libx264");
SUPPORTED_CODECS.push_back("libtheora");
SUPPORTED_CODECS.push_back("libvpx");
}
return std::find(SUPPORTED_CODECS.begin(), SUPPORTED_CODECS.end(), name) !=
SUPPORTED_CODECS.end();
}
std::list<std::string> installedCodecs()
{
// FIXME: not thread safe
static bool registered = false;
if (not registered)
{
av_register_all();
registered = true;
}
std::list<std::string> codecs;
AVCodec *p = NULL, *p2;
const char *last_name = "000";
while (true)
{
p2 = NULL;
while ((p = av_codec_next(p)))
{
if((p2 == NULL or strcmp(p->name, p2->name) < 0) and
strcmp(p->name, last_name) > 0)
{
p2 = p;
}
}
if (p2 == NULL)
break;
last_name = p2->name;
switch(p2->type)
{
case AVMEDIA_TYPE_VIDEO:
if (isSupportedCodec(p2->name))
codecs.push_back(p2->name);
break;
default:
break;
}
}
return codecs;
}
} // end namespace libav_utils
/*
* Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef __LIBAV_UTILS_H__
#define __LIBAV_UTILS_H__
#include <list>
#include <string>
namespace libav_utils {
/**
* Returns the list of codecs installed at runtime and that we support
*/
std::list<std::string> installedCodecs();
/**
* Returns true if a given codec is supported, that is to say it's use
* has been anticipated and it has been tested.
*/
bool isSupportedCodec(const char *codec);
}
#endif // __LIBAV_UTILS_H__
check_PROGRAMS=test_list_codecs
TESTS=test_video_endpoint
check_PROGRAMS=test_video_endpoint
test_list_codecs_SOURCES=test_video_endpoint.cpp
test_list_codecs_LDADD=$(top_builddir)/libs/video/libvideo_endpoint.la \
$(CPPUNIT_LIBS)
test_list_codecs_CXXFLAGS=-I./ -I../
test_video_endpoint_SOURCES=test_video_endpoint.cpp
test_video_endpoint_LDADD=$(top_builddir)/libs/video/libvideo_endpoint.la
test_video_endpoint_CXXFLAGS=-I./ -I../
......@@ -30,11 +30,27 @@
#include "test_video_endpoint.h"
#include <cstdlib>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/ui/text/TextTestRunner.h>
#include <iostream>
#include <cassert>
#include "video_endpoint.h"
#include "libav_utils.h"
void VideoEndpointTest::testListCodecs()
void VideoEndpointTest::testIsSupportedCodec()
{
/* This would list codecs */
assert(libav_utils::isSupportedCodec("mpeg4"));
assert(not libav_utils::isSupportedCodec("mp3"));
assert(not libav_utils::isSupportedCodec("xan_wc4"));
assert(not libav_utils::isSupportedCodec("schroedinger"));
}
void VideoEndpointTest::testListInstalledCodecs()
{
/* This would list codecs */
libav_utils::installedCodecs();
}
void VideoEndpointTest::testCodecMap()
{
/* This would list codecs */
typedef std::map<int, std::string> MapType;
......@@ -44,35 +60,14 @@ void VideoEndpointTest::testListCodecs()
if (iter->second == "MP4V-ES")
count++;
CPPUNIT_ASSERT(count == 1);
assert(count == 1);
}
int main (int argc, char* argv[])
{
printf ("\nSFLphone Video Test Suite, by Savoir-Faire Linux 2011\n\n");
// Default test suite : all tests
std::string testSuiteName = "All Tests";
// Get the top level suite from the registry
printf ("\n\n=== Test Suite: %s ===\n\n", testSuiteName.c_str());
CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry(testSuiteName).makeTest();
if (suite->getChildTestCount() == 0) {
exit (EXIT_FAILURE);
}
// Adds the test to the list of test to run
CppUnit::TextTestRunner runner;
runner.addTest (suite);
// Change the default outputter to a compiler error format outputter
runner.setOutputter (new CppUnit::CompilerOutputter(&runner.result(), std::cerr));
// Run the tests.
bool wasSucessful = runner.run();
// Return error code 1 if the one of test failed.
return wasSucessful ? 0 : 1;
VideoEndpointTest test;
test.testListInstalledCodecs();
test.testCodecMap();
test.testIsSupportedCodec();
return 0;
}
......@@ -31,25 +31,11 @@
#ifndef _VIDEO_ENDPOINT_TEST_
#define _VIDEO_ENDPOINT_TEST_
// Cppunit import
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestCase.h>
#include <cppunit/TestSuite.h>
#include <cassert>
class VideoEndpointTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( VideoEndpointTest );
CPPUNIT_TEST( testListCodecs );
CPPUNIT_TEST_SUITE_END();
class VideoEndpointTest {
public:
void testListCodecs();
void testListInstalledCodecs();
void testCodecMap();
void testIsSupportedCodec();
};
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(VideoEndpointTest, "VideoEndpointTest");
CPPUNIT_TEST_SUITE_REGISTRATION( VideoEndpointTest );
#endif // _VIDEO_ENDPOINT_TEST_
......@@ -29,6 +29,7 @@
*/
#include "video_endpoint.h"
#include "libav_utils.h"
#include <iostream>
#include <sstream>
#include <map>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment