File: oss.c

package info (click to toggle)
alsaplayer 0.99.80-5.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,852 kB
  • sloc: ansic: 20,659; cpp: 10,547; sh: 10,213; makefile: 1,173; yacc: 289; sed: 16
file content (132 lines) | stat: -rw-r--r-- 2,870 bytes parent folder | download | duplicates (5)
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
/*  oss.c - Output driver for OSS/Lite and OSS/Linux
 *  Copyright (C) 1999-2002 Andy Lo A Foe <andy@alsaplayer.org>
 *
 *  This file is part of AlsaPlayer.
 *
 *  AlsaPlayer 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  AlsaPlayer 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, see <http://www.gnu.org/licenses/>.
 *
*/ 

#include "config.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/soundcard.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include "output_plugin.h"
#include "alsaplayer_error.h"

static int oss_fd;
static int oss_card;
static int oss_device;

static int oss_init(void)
{
	// Always return ok for now
	oss_fd = -1;
	oss_card = 0;
	oss_device = 0;
	return 1;
}

static int oss_open(const char *name)
{
	if (name[0] != '/') {
		name = "/dev/dsp";
		}
	if ((oss_fd = open(name,  O_WRONLY, 0)) == -1) {
		alsaplayer_error("error opening %s", name);
		return 0;
	}
	return 1;
}


static void oss_close(void)
{
	close(oss_fd);
	return;
}


static int oss_write(void *data, int count)
{
	write(oss_fd, data, count);
	return 1;
}


static int oss_set_buffer(int *fragment_size, int *fragment_count, int *channels)
{
	int val;
	int hops;
	int size;
	int count;
	
	size = *fragment_size;
	count = *fragment_count;
	
	for (hops=0; size >>=1; hops++);
	
	val = (count << 16) + hops;
	ioctl(oss_fd,SNDCTL_DSP_SETFRAGMENT,&val);
	val = AFMT_S16_NE;
	ioctl(oss_fd,SNDCTL_DSP_SETFMT,&val);
	val = *channels - 1;
	ioctl(oss_fd,SNDCTL_DSP_STEREO,&val);
	ioctl(oss_fd,SNDCTL_DSP_GETBLKSIZE,&val);
	return 1;
}


static unsigned int oss_set_sample_rate(unsigned int rate)
{
	if (ioctl(oss_fd,SNDCTL_DSP_SPEED,&rate) < 0) {
					alsaplayer_error("error setting sample_rate");
					return 0;
	}				
	return rate;
}


output_plugin oss_output;

#ifdef __cplusplus
extern "C" {
#endif

output_plugin *output_plugin_info(void)
{
	memset(&oss_output, 0, sizeof(output_plugin));
	oss_output.version = OUTPUT_PLUGIN_VERSION;
	oss_output.name = "OSS output v1.0";
	oss_output.author = "Andy Lo A Foe";
	oss_output.init = oss_init;
	oss_output.open = oss_open;
	oss_output.close = oss_close;
	oss_output.write = oss_write;
	oss_output.set_buffer = oss_set_buffer;
	oss_output.set_sample_rate = oss_set_sample_rate;
	return &oss_output;
}

#ifdef __cplusplus
}
#endif