source: roaraudio/roard/codecfilter_cmd.c @ 5439:7950543cabbc

Last change on this file since 5439:7950543cabbc was 5381:430b1d26e12d, checked in by phi, 12 years ago

updated copyright years

File size: 2.9 KB
Line 
1//codecfilter_cmd.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28#if defined(ROAR_HAVE_UNIX) && defined(ROAR_HAVE_BSDSOCKETS) && defined(ROAR_HAVE_IO_POSIX)
29#define _CAN_OPERATE
30#endif
31
32#if !defined(ROAR_WITHOUT_CF_CMD) && defined(_CAN_OPERATE)
33
34#define CMDMAXLEN 1024
35
36int cf_cmd_open(CODECFILTER_USERDATA_T * inst, int codec,
37                                             struct roar_stream_server * info,
38                                             struct roar_codecfilter   * filter) {
39 int socks[2];
40 int execed = -1;
41 char cmd[CMDMAXLEN+1] = {0};
42 char * tmp = NULL;
43 char   tb[CMDMAXLEN+1];
44 char * o = filter->options;
45 int i;
46
47 if ( !o )
48  return -1;
49
50 for (i = 0; i < CMDMAXLEN && *o != 0; i++, o++) {
51  if ( *o == '%' ) {
52//   printf("ol: *o='%c' (escape)\n", *o);
53   tmp = NULL;
54
55   o++;
56   if ( *o == 0 ) {
57    break;
58   } else if ( *o == 'R' ) {
59    tmp = tb;
60    snprintf(tb, CMDMAXLEN, "%i", g_sa->rate);
61   } else if ( *o == 'B' ) {
62    tmp = tb;
63    snprintf(tb, CMDMAXLEN, "%i", g_sa->bits);
64   } else if ( *o == 'C' ) {
65    tmp = tb;
66    snprintf(tb, CMDMAXLEN, "%i", g_sa->channels);
67   }
68
69//   printf("*o='%c', tmp=%p\n", *o, tmp);
70
71   if ( tmp ) {
72    for (; i < CMDMAXLEN && *tmp != 0; i++, tmp++)
73     cmd[i] = *tmp;
74    i--;
75   }
76  } else {
77//   printf("ol: *o='%c' (copy to cmd[i=%i])\n", *o, i);
78   cmd[i] = *o;
79  }
80 }
81
82 cmd[i+1] = 0;
83
84 //printf("cmd='%s'\n", cmd);
85
86 if ( socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == -1 ) {
87  return -1;
88 }
89
90 if ( lib_run_bg(cmd, ROAR_STREAM(info)->fh, socks[1], ROAR_STDERR, socks, 2) == -1 )
91  return -1;
92
93 if ( info->client != -1 ) {
94  execed = g_clients[info->client]->execed;
95
96  if ( execed != -1 ) {
97   if ( g_streams[execed] == info ) {
98    g_clients[info->client]->fh = socks[0];
99   } else {
100    close(ROAR_STREAM(info)->fh);
101   }
102  } else {
103   close(ROAR_STREAM(info)->fh);
104  }
105 } else {
106  close(ROAR_STREAM(info)->fh);
107 }
108
109 ROAR_STREAM(info)->fh = socks[0];
110 ROAR_STREAM(info)->info.codec = ROAR_CODEC_DEFAULT;
111 close(socks[1]);
112
113 info->codecfilter = -1;
114
115 return 0;
116}
117
118#endif
119
120//ll
Note: See TracBrowser for help on using the repository browser.