1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
// ------------------------------------------------------------------------
// ecicpp_helper.cpp: Helper routines for C++ ECI programming.
// Copyright (C) 2002-2007 Kai Vehmanen
//
// 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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// ------------------------------------------------------------------------
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <kvu_dbc.h>
#include <kvu_utils.h>
#include <eca-control-interface.h>
#include "ecicpp_helpers.h"
/**
* Definitions and options
*/
using std::cerr;
using std::cout;
using std::endl;
using std::string;
/**
* Function declarations
*/
static void escape(string& str, string& x, string& rep)
{
for (size_t i = 0; (i = str.find(x, i)) != string::npos; i += rep.length())
str.replace(i, x.length(), rep);
}
int ecicpp_add_file_input(ECA_CONTROL_INTERFACE* eci, string& filename, string* format)
{
string space(" ");
string space_e("\\ ");
string comma(",");
string comma_e("\\\\,");
escape(filename, space, space_e);
escape(filename, comma, comma_e);
return ecicpp_add_input(eci, filename, format);
}
int ecicpp_add_input(ECA_CONTROL_INTERFACE* eci, const string& input, string* format)
{
eci->command("ai-add " + input);
bool error = eci->error();
eci->command("ai-list");
if (error == true || eci->last_string_list().size() != 1) {
cerr << eci->last_error() << endl;
cerr << "---\nError while processing input " << input << ". Exiting...\n";
return -1;
}
/* we must connect to get correct input format */
eci->command("ao-add null");
eci->command("cs-connect");
eci->command("ai-iselect 1");
eci->command("ai-get-format");
*format = eci->last_string();
/* disconnect and remove the null output */
eci->command("cs-disconnect");
eci->command("ao-iselect 1");
eci->command("ao-remove");
return 0;
}
int ecicpp_add_output(ECA_CONTROL_INTERFACE* eci, const string& output, const string& format)
{
eci->command("cs-set-audio-format " + format);
eci->command("ao-add " + output);
bool error = eci->error();
eci->command("ao-list");
if (error == true || eci->last_string_list().size() != 1) {
cerr << eci->last_error() << endl;
cerr << "---\nError while processing output " << output << ". Exiting...\n";
return -1;
}
return 0;
}
int ecicpp_connect_chainsetup(ECA_CONTROL_INTERFACE* eci, const string& csname)
{
eci->command("cs-connect");
bool error = eci->error();
string errorstr = eci->last_error();
eci->command("cs-connected");
if (error == true || eci->last_string() != csname) {
cerr << endl << errorstr << endl;
cerr << "---\nUnable to start processing. Exiting...\n";
return -1;
}
return 0;
}
int ecicpp_format_channels(const string& format)
{
std::vector<std::string> tokens = kvu_string_to_vector(format, ',');
DBC_CHECK(tokens.size() >= 3);
return atoi(tokens[1].c_str());
}
|