File: DBAudio_IPC.c

package info (click to toggle)
dbmix 0.9.8-6.3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 2,896 kB
  • sloc: ansic: 12,309; sh: 11,418; makefile: 153
file content (192 lines) | stat: -rw-r--r-- 4,709 bytes parent folder | download | duplicates (6)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*

  Author:  Bob Dean
  Copyright (c) 1999, 2000


   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public Licensse 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.

 */

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <limits.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <sys/shm.h>
#include <glib.h>
#include <math.h>

#include <dbsoundcard.h>
#include <dbchannel.h>
#include <dbdebug.h>
#include <dbaudiolib.h>
#include <sys/ipc.h>
#include <sys/msg.h>
	
#include "prototypes.h"
	
	/* variables to access DBMix channels shared memory */
	extern  int shmid, sysshmid;
	extern dbfsd_data * sysdata;
	/* static local_channel * cue_channels; */
	extern local_channel * ch;
	
	extern int debug_level; /* declared in debug module */
	
	
	int DBAudio_Set_Message_Handler(void(*message_handler)(dbfsd_msg msg),
									int msg_flags)
	{
		if (ch == NULL)  {errno = ERROR_NOT_INITIALIZED; return FAILURE;}
		
		ch->message_handler = message_handler;
		ch->msg_flags = msg_flags;
		
		/* do not allow pause messages to be requested if the device
           does not support pausing */

		return SUCCESS;
	}


	/*
	  handles message sent to DBAudioLib by outside sources.
	*/

	int DBAudio_Handle_Message_Queue()
	{
		dbfsd_msg msg;

		if (ch == NULL)  
		{
			errno = ERROR_NOT_INITIALIZED; 
			return FAILURE;
		}

		if (ch->msg_q_id == -1) 
		{
			return SUCCESS;
		}

		while (msgrcv(ch->msg_q_id, &msg,sizeof(dbfsd_msg) - sizeof(long int),0,IPC_NOWAIT) != -1)
		{
			/* if the client has asked for this message, send it */
			if (ch->msg_flags & msg.msg_type)
			{
				if (ch->message_handler != NULL)
				{
					Debug("dbaudiolib: passing message %d to client",msg.msg_type);
					(ch->message_handler)((dbfsd_msg)msg);
				}
			}
			else
			{
				/* hanle message internally */
				switch (msg.msg_type)
				{	
					case DBMSG_NONE:
						break;
					case DBMSG_MUTE:
						Debug("dbaudiolib: got MUTE message.");
						ch->mute = 1;
						break;
					case DBMSG_UNMUTE:				
						Debug("dbaudiolib: got UNMUTE message.");
						ch->mute = 0;
						break;
					case DBMSG_PAUSE:
						Debug("dbaudiolib: got PAUSE message. waiting for unpause...");
						if (!(PAUSE_ENABLED)) break;

						DBAudio_Pause(TRUE);
						break;
					case DBMSG_UNPAUSE:
						Debug("dbaudiolib: got UNPAUSE message.");
						if (!(PAUSE_ENABLED)) break;

						DBAudio_Pause(FALSE);
						break;
					case DBMSG_PLAY:
						Debug("dbaudiolib: got PLAY message.");
						break;
					case DBMSG_STOP:
						Debug("dbaudiolib: got STOP message.");
						break;
					case DBMSG_EJECT:
						Debug("dbaudiolib: got EJECT message.");
						break;
					case DBMSG_REWIND:
						Debug("dbaudiolib: got REWIND message.");
						break;
					case DBMSG_FFORWARD:
						Debug("dbaudiolib: got FFORWARD message.");
						break;
					case DBMSG_NEXT:
						Debug("dbaudiolib: got NEXT message.");
						break;
					case DBMSG_PREV:
						Debug("dbaudiolib: got PREV message.");
						break;
					case DBMSG_SAMPLERSIZE:
						Debug("dbaudiolib: got SAMPLERSIZE message.");
						break;
					case DBMSG_SAMPLERSAVE:
						Debug("dbaudiolib: got SAVE message.");
						DBAudio_Sampler_Save(sysdata->filename);
						break;
					case DBMSG_SAMPLERLOAD:
						Debug("dbaudiolib: got LOAD message.");
						DBAudio_Sampler_Load(sysdata->filename);
						break;
					case DBMSG_SAMPLERREC:
						Debug("dbaudiolib: got REC message.");
						DBAudio_Sampler_Record();
						break;
					case DBMSG_SAMPLERSTOP:
						Debug("dbaudiolib: got STOP message.");
						DBAudio_Sampler_Stop();
						break;
					case DBMSG_SAMPLERLOOP:
						Debug("dbaudiolib: got LOOP message.");
						DBAudio_Sampler_Loop();
						break;
					case DBMSG_SAMPLERONCE:
						Debug("dbaudiolib: got ONCE message.");
						DBAudio_Sampler_Single();
						break;
					default:
						Error("DBAudioLib: Handle_Message_Queue: unknown message type: %l\n",msg.msg_type);
						break;
				}
			}
		}

		return SUCCESS;
	}


#ifdef __cplusplus
}
#endif