source: roaraudio/roard/codecfilter_cmd.c @ 3358:7f9d211148e0

Last change on this file since 3358:7f9d211148e0 was 1479:71d2bfe4ebe0, checked in by phi, 15 years ago

only build cf if we have ROAR_HAVE_UNIX, ROAR_HAVE_BSDSOCKETS and ROAR_HAVE_IO_POSIX

File size: 2.8 KB
Line 
1//codecfilter_cmd.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27#if defined(ROAR_HAVE_UNIX) && defined(ROAR_HAVE_BSDSOCKETS) && defined(ROAR_HAVE_IO_POSIX)
28#define _CAN_OPERATE
29#endif
30
31#if !defined(ROAR_WITHOUT_CF_CMD) && defined(_CAN_OPERATE)
32
33#define CMDMAXLEN 1024
34
35int cf_cmd_open(CODECFILTER_USERDATA_T * inst, int codec,
36                                             struct roar_stream_server * info,
37                                             struct roar_codecfilter   * filter) {
38 int socks[2];
39 int execed = -1;
40 char cmd[CMDMAXLEN+1] = {0};
41 char * tmp = NULL;
42 char   tb[CMDMAXLEN+1];
43 char * o = filter->options;
44 int i;
45
46 if ( !o )
47  return -1;
48
49 for (i = 0; i < CMDMAXLEN && *o != 0; i++, o++) {
50  if ( *o == '%' ) {
51//   printf("ol: *o='%c' (escape)\n", *o);
52   tmp = NULL;
53
54   o++;
55   if ( *o == 0 ) {
56    break;
57   } else if ( *o == 'R' ) {
58    tmp = tb;
59    snprintf(tb, CMDMAXLEN, "%i", g_sa->rate);
60   } else if ( *o == 'B' ) {
61    tmp = tb;
62    snprintf(tb, CMDMAXLEN, "%i", g_sa->bits);
63   } else if ( *o == 'C' ) {
64    tmp = tb;
65    snprintf(tb, CMDMAXLEN, "%i", g_sa->channels);
66   }
67
68//   printf("*o='%c', tmp=%p\n", *o, tmp);
69
70   if ( tmp ) {
71    for (; i < CMDMAXLEN && *tmp != 0; i++, tmp++)
72     cmd[i] = *tmp;
73    i--;
74   }
75  } else {
76//   printf("ol: *o='%c' (copy to cmd[i=%i])\n", *o, i);
77   cmd[i] = *o;
78  }
79 }
80
81 cmd[i+1] = 0;
82
83 //printf("cmd='%s'\n", cmd);
84
85 if ( socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == -1 ) {
86  return -1;
87 }
88
89 if ( lib_run_bg(cmd, ROAR_STREAM(info)->fh, socks[1], ROAR_STDERR, socks, 2) == -1 )
90  return -1;
91
92 if ( info->client != -1 ) {
93  execed = g_clients[info->client]->execed;
94
95  if ( execed != -1 ) {
96   if ( g_streams[execed] == info ) {
97    g_clients[info->client]->fh = socks[0];
98   } else {
99    close(ROAR_STREAM(info)->fh);
100   }
101  } else {
102   close(ROAR_STREAM(info)->fh);
103  }
104 } else {
105  close(ROAR_STREAM(info)->fh);
106 }
107
108 ROAR_STREAM(info)->fh = socks[0];
109 ROAR_STREAM(info)->info.codec = ROAR_CODEC_DEFAULT;
110 close(socks[1]);
111
112 info->codecfilter = -1;
113
114 return 0;
115}
116
117#endif
118
119//ll
Note: See TracBrowser for help on using the repository browser.