* Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
150 lines
4.3 KiB
C++
150 lines
4.3 KiB
C++
/*
|
||
MediaAccessMock - a test (stub) target object for testing the factories
|
||
|
||
Copyright (C)
|
||
2008, Hermann Vosseler <Ichthyostega@web.de>
|
||
|
||
**Lumiera** 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 2 of the License, or (at your
|
||
option) any later version. See the file COPYING for further details.
|
||
|
||
* *****************************************************************/
|
||
|
||
|
||
/** @file media-access-mock.cpp
|
||
** Mock implementation of the Interface normally used to query media file
|
||
** information from the data backend. The Mock implementation instead holds
|
||
** a map of fixed response which will be delivered when querying some magic
|
||
** filenames.
|
||
** @todo this facility was occasionally used until 2011, yet never really completed
|
||
**
|
||
** @see mediaaccessmocktest.cpp validating the Mock
|
||
** @see MediaAccessFactory the real thing
|
||
**
|
||
*/
|
||
|
||
|
||
#include "vault/media-access-mock.hpp"
|
||
#include "steam/mobject/session/testclip.hpp"
|
||
|
||
#include "lib/util.hpp"
|
||
#include "lib/depend.hpp"
|
||
#include "lib/time/mutation.hpp"
|
||
#include "lib/symbol.hpp"
|
||
|
||
#include <vector>
|
||
#include <map>
|
||
|
||
using lumiera::error::Invalid;
|
||
using lib::time::Mutation;
|
||
using lib::time::Duration;
|
||
using lib::Literal;
|
||
using util::isnil;
|
||
using std::string;
|
||
using std::vector;
|
||
using std::map;
|
||
|
||
|
||
namespace vault {
|
||
namespace test {
|
||
|
||
typedef MediaAccessFacade::ChanHandle ChanHandle;
|
||
|
||
|
||
namespace { // implementation details
|
||
|
||
struct Response
|
||
{
|
||
MediaDesc globalDesc;
|
||
vector<ChanDesc> channels;
|
||
|
||
Response&
|
||
globalLength (Duration length)
|
||
{
|
||
globalDesc.length.accept (Mutation::changeDuration(length));
|
||
return *this;
|
||
}
|
||
|
||
Response&
|
||
channel (Literal name, Literal id)
|
||
{
|
||
channels.push_back (ChanDesc (name, id, genH()));
|
||
return *this;
|
||
}
|
||
|
||
private:
|
||
static int _i_;
|
||
|
||
ChanHandle
|
||
genH()
|
||
{
|
||
return reinterpret_cast<ChanHandle> (++_i_);
|
||
}
|
||
};
|
||
int Response::_i_(0);
|
||
const ChanDesc NULLResponse;
|
||
using steam::mobject::session::test::LENGTH_TestClip;
|
||
|
||
|
||
struct TestCases : map<string,Response>
|
||
{
|
||
TestCases ()
|
||
{
|
||
// ----------------------------------------------------------------------TESTCASES
|
||
(*this)["test-1"].globalLength(LENGTH_TestClip).channel("video","ID");
|
||
|
||
(*this)["test-2"].globalLength(LENGTH_TestClip).channel("video","H264")
|
||
.channel("audio-L","PCM")
|
||
.channel("audio-R","PCM");
|
||
(*this)["test-3"].globalLength(LENGTH_TestClip).channel("audio","PCM");
|
||
(*this)["test-4"].globalLength(LENGTH_TestClip).channel("audio-W","PCM")
|
||
.channel("audio-X","PCM")
|
||
.channel("audio-Y","PCM")
|
||
.channel("audio-Z","PCM");
|
||
// ----------------------------------------------------------------------TESTCASES
|
||
}
|
||
|
||
bool
|
||
known (string key)
|
||
{
|
||
const_iterator i = find (key);
|
||
return (i != end());
|
||
}
|
||
};
|
||
|
||
// instantiate TestCasses table
|
||
lib::Depend<TestCases> testCases;
|
||
|
||
} // (end) implementation namespace
|
||
|
||
|
||
|
||
MediaDesc&
|
||
MediaAccessMock::queryFile (string const& name) const
|
||
{
|
||
if (isnil (name))
|
||
throw Invalid ("empty filename passed to MediaAccessFacade.");
|
||
|
||
if (!testCases().known(name))
|
||
throw Invalid ("unable to use media file \""+name+"\"."
|
||
"Hint: you're using a test-mock file access, "
|
||
"which responds only to some magical names.");
|
||
|
||
return testCases()[name].globalDesc;
|
||
}
|
||
|
||
|
||
ChanDesc
|
||
MediaAccessMock::queryChannel (MediaDesc& h, uint chanNo) const
|
||
{
|
||
Response const& res (*reinterpret_cast<Response*> (&h));
|
||
|
||
if (res.channels.size() <= chanNo)
|
||
return NULLResponse;
|
||
else
|
||
return res.channels[chanNo];
|
||
}
|
||
|
||
|
||
}} // namespace vault::test
|