2001-04-16 11:27:16 +08:00
|
|
|
/* fhandler_dev_dsp: code to emulate OSS sound model /dev/dsp
|
2001-06-26 22:47:48 +08:00
|
|
|
|
2003-01-15 18:21:23 +08:00
|
|
|
Copyright 2001, 2002, 2003 Red Hat, Inc
|
2001-06-26 22:47:48 +08:00
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
Written by Andy Younger (andy@snoogie.demon.co.uk)
|
2001-06-26 22:47:48 +08:00
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
This file is part of Cygwin.
|
2001-06-26 22:47:48 +08:00
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <sys/soundcard.h>
|
|
|
|
#include <mmsystem.h>
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "cygerrno.h"
|
|
|
|
#include "security.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "path.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "fhandler.h"
|
2001-04-16 11:27:16 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Simple encapsulation of the win32 audio device.
|
2001-05-21 01:31:06 +08:00
|
|
|
//
|
|
|
|
static void CALLBACK wave_callback (HWAVE hWave, UINT msg, DWORD instance,
|
|
|
|
DWORD param1, DWORD param2);
|
2001-04-16 11:27:16 +08:00
|
|
|
class Audio
|
|
|
|
{
|
|
|
|
public:
|
2001-05-24 13:20:17 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAX_BLOCKS = 12,
|
|
|
|
BLOCK_SIZE = 16384,
|
|
|
|
TOT_BLOCK_SIZE = BLOCK_SIZE + sizeof (WAVEHDR)
|
|
|
|
};
|
2001-04-16 11:27:16 +08:00
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
Audio ();
|
|
|
|
~Audio ();
|
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
bool open (int rate, int bits, int channels, bool bCallback = false);
|
|
|
|
void close ();
|
|
|
|
int getvolume ();
|
|
|
|
void setvolume (int newVolume);
|
|
|
|
bool write (const void *pSampleData, int nBytes);
|
|
|
|
int blocks ();
|
|
|
|
void callback_sampledone (void *pData);
|
2001-05-21 01:31:06 +08:00
|
|
|
void setformat (int format) {formattype_ = format;}
|
2001-04-16 11:27:16 +08:00
|
|
|
int numbytesoutput ();
|
2001-05-21 01:31:06 +08:00
|
|
|
|
2001-05-24 13:20:17 +08:00
|
|
|
void *operator new (size_t, void *p) {return p;}
|
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
private:
|
|
|
|
char *initialisebuffer ();
|
|
|
|
void waitforcallback ();
|
|
|
|
bool flush ();
|
2001-05-21 01:31:06 +08:00
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
HWAVEOUT dev_;
|
|
|
|
volatile int nBlocksInQue_;
|
|
|
|
int nBytesWritten_;
|
|
|
|
char *buffer_;
|
|
|
|
int bufferIndex_;
|
|
|
|
CRITICAL_SECTION lock_;
|
|
|
|
char *freeblocks_[MAX_BLOCKS];
|
2001-04-25 15:26:54 +08:00
|
|
|
int formattype_;
|
2001-04-16 11:27:16 +08:00
|
|
|
|
2001-05-24 13:20:17 +08:00
|
|
|
char bigwavebuffer_[MAX_BLOCKS * TOT_BLOCK_SIZE];
|
2001-04-16 11:27:16 +08:00
|
|
|
};
|
|
|
|
|
2001-05-24 13:20:17 +08:00
|
|
|
static char audio_buf[sizeof (class Audio)];
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
Audio::Audio ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
InitializeCriticalSection (&lock_);
|
2001-05-24 13:20:17 +08:00
|
|
|
memset (bigwavebuffer_, 0, sizeof (bigwavebuffer_));
|
2001-04-16 11:27:16 +08:00
|
|
|
for (int i = 0; i < MAX_BLOCKS; i++)
|
2001-05-24 13:20:17 +08:00
|
|
|
freeblocks_[i] = &bigwavebuffer_[i * TOT_BLOCK_SIZE];
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
Audio::~Audio ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
if (dev_)
|
2001-05-21 01:31:06 +08:00
|
|
|
close ();
|
|
|
|
DeleteCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
bool
|
2002-02-20 06:06:50 +08:00
|
|
|
Audio::open (int rate, int bits, int channels, bool bCallback)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
WAVEFORMATEX format;
|
2001-05-21 01:31:06 +08:00
|
|
|
int nDevices = waveOutGetNumDevs ();
|
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
nBytesWritten_ = 0L;
|
|
|
|
bufferIndex_ = 0;
|
|
|
|
buffer_ = 0L;
|
2002-09-30 12:35:18 +08:00
|
|
|
debug_printf ("number devices %d", nDevices);
|
2001-04-16 11:27:16 +08:00
|
|
|
if (nDevices <= 0)
|
|
|
|
return false;
|
2001-05-21 01:31:06 +08:00
|
|
|
|
|
|
|
debug_printf ("trying to map device freq %d, bits %d, "
|
2002-09-30 12:35:18 +08:00
|
|
|
"channels %d, callback %d", rate, bits, channels,
|
2001-05-21 01:31:06 +08:00
|
|
|
bCallback);
|
2001-04-16 11:27:16 +08:00
|
|
|
|
|
|
|
int bytesperSample = bits / 8;
|
2001-05-21 01:31:06 +08:00
|
|
|
|
|
|
|
memset (&format, 0, sizeof (format));
|
2001-04-16 11:27:16 +08:00
|
|
|
format.wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
format.wBitsPerSample = bits;
|
|
|
|
format.nChannels = channels;
|
|
|
|
format.nSamplesPerSec = rate;
|
2001-05-21 01:31:06 +08:00
|
|
|
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nChannels *
|
|
|
|
bytesperSample;
|
|
|
|
format.nBlockAlign = format.nChannels * bytesperSample;
|
2001-04-16 11:27:16 +08:00
|
|
|
|
|
|
|
nBlocksInQue_ = 0;
|
2001-05-21 01:31:06 +08:00
|
|
|
HRESULT res = waveOutOpen (&dev_, WAVE_MAPPER, &format, (DWORD) wave_callback,
|
|
|
|
(DWORD) this, bCallback ? CALLBACK_FUNCTION : 0);
|
2001-04-16 11:27:16 +08:00
|
|
|
if (res == S_OK)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
debug_printf ("Sucessfully opened!");
|
2001-04-16 11:27:16 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
debug_printf ("failed to open");
|
2001-04-16 11:27:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
void
|
|
|
|
Audio::close ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
if (dev_)
|
2001-05-21 01:31:06 +08:00
|
|
|
{
|
|
|
|
flush (); // force out last block whatever size..
|
|
|
|
|
|
|
|
while (blocks ()) // block till finished..
|
|
|
|
waitforcallback ();
|
|
|
|
|
|
|
|
waveOutReset (dev_);
|
|
|
|
waveOutClose (dev_);
|
2001-04-16 11:27:16 +08:00
|
|
|
dev_ = 0L;
|
|
|
|
}
|
|
|
|
nBytesWritten_ = 0L;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-05-21 01:31:06 +08:00
|
|
|
Audio::numbytesoutput ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
return nBytesWritten_;
|
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
int
|
|
|
|
Audio::getvolume ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
DWORD volume;
|
2001-05-21 01:31:06 +08:00
|
|
|
|
|
|
|
waveOutGetVolume (dev_, &volume);
|
|
|
|
return ((volume >> 16) + (volume & 0xffff)) >> 1;
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
void
|
|
|
|
Audio::setvolume (int newVolume)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
waveOutSetVolume (dev_, (newVolume << 16) | newVolume);
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2001-05-21 01:31:06 +08:00
|
|
|
Audio::initialisebuffer ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
EnterCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
WAVEHDR *pHeader = 0L;
|
|
|
|
for (int i = 0; i < MAX_BLOCKS; i++)
|
|
|
|
{
|
|
|
|
char *pData = freeblocks_[i];
|
|
|
|
if (pData)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
pHeader = (WAVEHDR *) pData;
|
2001-04-16 11:27:16 +08:00
|
|
|
if (pHeader->dwFlags & WHDR_DONE)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
waveOutUnprepareHeader (dev_, pHeader, sizeof (WAVEHDR));
|
|
|
|
}
|
2001-04-16 11:27:16 +08:00
|
|
|
freeblocks_[i] = 0L;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-05-21 01:31:06 +08:00
|
|
|
LeaveCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
|
|
|
|
if (pHeader)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
memset (pHeader, 0, sizeof (WAVEHDR));
|
2001-04-16 11:27:16 +08:00
|
|
|
pHeader->dwBufferLength = BLOCK_SIZE;
|
2001-05-21 01:31:06 +08:00
|
|
|
pHeader->lpData = (LPSTR) (&pHeader[1]);
|
|
|
|
return (char *) pHeader->lpData;
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
bool
|
|
|
|
Audio::write (const void *pSampleData, int nBytes)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
// split up big blocks into smaller BLOCK_SIZE chunks
|
|
|
|
while (nBytes > BLOCK_SIZE)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
write (pSampleData, BLOCK_SIZE);
|
2001-04-16 11:27:16 +08:00
|
|
|
nBytes -= BLOCK_SIZE;
|
2001-05-21 01:31:06 +08:00
|
|
|
pSampleData = (void *) ((char *) pSampleData + BLOCK_SIZE);
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Block till next sound is flushed
|
2001-05-21 01:31:06 +08:00
|
|
|
if (blocks () == MAX_BLOCKS)
|
|
|
|
waitforcallback ();
|
2001-04-16 11:27:16 +08:00
|
|
|
|
|
|
|
// Allocate new wave buffer if necessary
|
|
|
|
if (buffer_ == 0L)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
buffer_ = initialisebuffer ();
|
2001-04-16 11:27:16 +08:00
|
|
|
if (buffer_ == 0L)
|
|
|
|
return false;
|
|
|
|
}
|
2001-05-21 01:31:06 +08:00
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
|
|
|
|
// Handle gathering blocks into larger buffer
|
|
|
|
int sizeleft = BLOCK_SIZE - bufferIndex_;
|
|
|
|
if (nBytes < sizeleft)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
memcpy (&buffer_[bufferIndex_], pSampleData, nBytes);
|
2001-04-16 11:27:16 +08:00
|
|
|
bufferIndex_ += nBytes;
|
|
|
|
nBytesWritten_ += nBytes;
|
|
|
|
return true;
|
|
|
|
}
|
2001-05-21 01:31:06 +08:00
|
|
|
|
|
|
|
// flushing when we reach our limit of BLOCK_SIZE
|
|
|
|
memcpy (&buffer_[bufferIndex_], pSampleData, sizeleft);
|
2001-04-16 11:27:16 +08:00
|
|
|
bufferIndex_ += sizeleft;
|
2001-05-21 01:31:06 +08:00
|
|
|
nBytesWritten_ += sizeleft;
|
|
|
|
flush ();
|
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
// change pointer to rest of sample, and size accordingly
|
2001-05-21 01:31:06 +08:00
|
|
|
pSampleData = (void *) ((char *) pSampleData + sizeleft);
|
|
|
|
nBytes -= sizeleft;
|
2001-04-16 11:27:16 +08:00
|
|
|
|
|
|
|
// if we still have some sample left over write it out
|
|
|
|
if (nBytes)
|
2001-05-21 01:31:06 +08:00
|
|
|
return write (pSampleData, nBytes);
|
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return number of blocks back.
|
2001-05-21 01:31:06 +08:00
|
|
|
int
|
|
|
|
Audio::blocks ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
EnterCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
int ret = nBlocksInQue_;
|
2001-05-21 01:31:06 +08:00
|
|
|
LeaveCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
// This is called on an interupt so use locking.. Note nBlocksInQue_ is
|
2001-04-16 11:27:16 +08:00
|
|
|
// modified by it so we should wrap all references to it in locks.
|
2001-05-21 01:31:06 +08:00
|
|
|
void
|
|
|
|
Audio::callback_sampledone (void *pData)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
EnterCriticalSection (&lock_);
|
|
|
|
|
|
|
|
nBlocksInQue_--;
|
2001-04-16 11:27:16 +08:00
|
|
|
for (int i = 0; i < MAX_BLOCKS; i++)
|
|
|
|
if (!freeblocks_[i])
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
freeblocks_[i] = (char *) pData;
|
2001-04-16 11:27:16 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-05-21 01:31:06 +08:00
|
|
|
|
|
|
|
LeaveCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-05-21 01:31:06 +08:00
|
|
|
Audio::waitforcallback ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
int n = blocks ();
|
2001-04-16 11:27:16 +08:00
|
|
|
if (!n)
|
2001-05-21 01:31:06 +08:00
|
|
|
return;
|
2001-04-16 11:27:16 +08:00
|
|
|
do
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
Sleep (250);
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
2001-05-21 01:31:06 +08:00
|
|
|
while (n == blocks ());
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2001-05-21 01:31:06 +08:00
|
|
|
Audio::flush ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
if (!buffer_)
|
2001-05-21 01:31:06 +08:00
|
|
|
return false;
|
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
// Send internal buffer out to the soundcard
|
2001-05-21 01:31:06 +08:00
|
|
|
WAVEHDR *pHeader = ((WAVEHDR *) buffer_) - 1;
|
2001-04-16 11:27:16 +08:00
|
|
|
pHeader->dwBufferLength = bufferIndex_;
|
2001-04-25 15:26:54 +08:00
|
|
|
|
|
|
|
// Quick bit of sample buffer conversion
|
|
|
|
if (formattype_ == AFMT_S8)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
unsigned char *p = ((unsigned char *) buffer_);
|
2001-04-25 15:26:54 +08:00
|
|
|
for (int i = 0; i < bufferIndex_; i++)
|
2001-05-21 01:31:06 +08:00
|
|
|
{
|
2001-04-25 15:26:54 +08:00
|
|
|
p[i] -= 0x7f;
|
2001-05-21 01:31:06 +08:00
|
|
|
}
|
2001-04-25 15:26:54 +08:00
|
|
|
}
|
2001-05-21 01:31:06 +08:00
|
|
|
|
|
|
|
if (waveOutPrepareHeader (dev_, pHeader, sizeof (WAVEHDR)) == S_OK &&
|
|
|
|
waveOutWrite (dev_, pHeader, sizeof (WAVEHDR)) == S_OK)
|
|
|
|
{
|
|
|
|
EnterCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
nBlocksInQue_++;
|
2001-05-21 01:31:06 +08:00
|
|
|
LeaveCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
bufferIndex_ = 0;
|
|
|
|
buffer_ = 0L;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
EnterCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
for (int i = 0; i < MAX_BLOCKS; i++)
|
|
|
|
if (!freeblocks_[i])
|
2001-05-21 01:31:06 +08:00
|
|
|
{
|
|
|
|
freeblocks_[i] = (char *) pHeader;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection (&lock_);
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Call back routine
|
2001-05-21 01:31:06 +08:00
|
|
|
static void CALLBACK
|
|
|
|
wave_callback (HWAVE hWave, UINT msg, DWORD instance, DWORD param1,
|
|
|
|
DWORD param2)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
if (msg == WOM_DONE)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
Audio *ptr = (Audio *) instance;
|
|
|
|
ptr->callback_sampledone ((void *) param1);
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
}
|
2001-05-21 01:31:06 +08:00
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// /dev/dsp handler
|
2001-05-21 01:31:06 +08:00
|
|
|
static Audio *s_audio; // static instance of the Audio handler
|
2001-04-16 11:27:16 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// wav file detection..
|
|
|
|
#pragma pack(1)
|
|
|
|
struct wavchunk
|
2001-05-21 01:31:06 +08:00
|
|
|
{
|
2001-04-16 11:27:16 +08:00
|
|
|
char id[4];
|
|
|
|
unsigned int len;
|
|
|
|
};
|
|
|
|
struct wavformat
|
|
|
|
{
|
|
|
|
unsigned short wFormatTag;
|
|
|
|
unsigned short wChannels;
|
|
|
|
unsigned int dwSamplesPerSec;
|
|
|
|
unsigned int dwAvgBytesPerSec;
|
|
|
|
unsigned short wBlockAlign;
|
|
|
|
unsigned short wBitsPerSample;
|
|
|
|
};
|
|
|
|
#pragma pack()
|
|
|
|
|
|
|
|
bool
|
2001-05-21 01:31:06 +08:00
|
|
|
fhandler_dev_dsp::setupwav (const char *pData, int nBytes)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
const char *end = pData + nBytes;
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
if (!(pData[0] == 'R' && pData[1] == 'I' &&
|
2001-04-16 11:27:16 +08:00
|
|
|
pData[2] == 'F' && pData[3] == 'F'))
|
|
|
|
return false;
|
2001-05-21 01:31:06 +08:00
|
|
|
if (!(pData[8] == 'W' && pData[9] == 'A' &&
|
|
|
|
pData[10] == 'V' && pData[11] == 'E'))
|
2001-04-16 11:27:16 +08:00
|
|
|
return false;
|
2001-05-21 01:31:06 +08:00
|
|
|
|
|
|
|
len = *(int *) &pData[4];
|
2001-04-16 11:27:16 +08:00
|
|
|
pData += 12;
|
|
|
|
while (len && pData < end)
|
2001-05-21 01:31:06 +08:00
|
|
|
{
|
|
|
|
wavchunk * pChunk = (wavchunk *) pData;
|
|
|
|
int blklen = pChunk-> len;
|
|
|
|
if (pChunk->id[0] == 'f' && pChunk->id[1] == 'm' &&
|
2001-04-16 11:27:16 +08:00
|
|
|
pChunk->id[2] == 't' && pChunk->id[3] == ' ')
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
wavformat *format = (wavformat *) (pChunk + 1);
|
|
|
|
if ((char *) (format + 1) > end)
|
2001-04-16 11:27:16 +08:00
|
|
|
return false;
|
2001-05-21 01:31:06 +08:00
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
// Open up audio device with correct frequency for wav file
|
2001-05-21 01:31:06 +08:00
|
|
|
//
|
2001-04-16 11:27:16 +08:00
|
|
|
// FIXME: should through away all the header & not output
|
|
|
|
// it to the soundcard.
|
2001-05-21 01:31:06 +08:00
|
|
|
s_audio->close ();
|
|
|
|
if (s_audio->open (format->dwSamplesPerSec, format->wBitsPerSample,
|
|
|
|
format->wChannels) == false)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
s_audio->open (audiofreq_, audiobits_, audiochannels_);
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
audiofreq_ = format->dwSamplesPerSec;
|
|
|
|
audiobits_ = format->wBitsPerSample;
|
|
|
|
audiochannels_ = format->wChannels;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
pData += blklen + sizeof (wavchunk);
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
2001-10-14 01:23:35 +08:00
|
|
|
fhandler_dev_dsp::fhandler_dev_dsp ():
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_base ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
fhandler_dev_dsp::~fhandler_dev_dsp ()
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_dev_dsp::open (int flags, mode_t mode)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
// currently we only support writing
|
|
|
|
if ((flags & (O_WRONLY | O_RDONLY | O_RDWR)) != O_WRONLY)
|
2002-06-04 19:18:46 +08:00
|
|
|
{
|
|
|
|
set_errno (EACCES);
|
|
|
|
return 0;
|
|
|
|
}
|
2001-05-21 01:31:06 +08:00
|
|
|
|
2002-07-03 11:20:50 +08:00
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
2001-05-21 01:31:06 +08:00
|
|
|
|
|
|
|
if (!s_audio)
|
2001-05-24 13:20:17 +08:00
|
|
|
s_audio = new (audio_buf) Audio;
|
2001-04-16 11:27:16 +08:00
|
|
|
|
|
|
|
// Work out initial sample format & frequency
|
|
|
|
// dev/dsp defaults
|
2001-10-04 10:34:20 +08:00
|
|
|
audioformat_ = AFMT_S8;
|
|
|
|
audiofreq_ = 8000;
|
|
|
|
audiobits_ = 8;
|
|
|
|
audiochannels_ = 1;
|
2001-04-16 11:27:16 +08:00
|
|
|
|
2002-06-05 09:42:28 +08:00
|
|
|
int res;
|
2001-05-21 01:31:06 +08:00
|
|
|
if (!s_audio->open (audiofreq_, audiobits_, audiochannels_))
|
2002-06-05 09:42:28 +08:00
|
|
|
res = 0;
|
2001-04-24 10:07:58 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
set_open_status ();
|
2002-06-05 09:42:28 +08:00
|
|
|
res = 1;
|
2001-04-24 10:07:58 +08:00
|
|
|
}
|
2002-06-05 09:42:28 +08:00
|
|
|
|
|
|
|
debug_printf ("returns %d", res);
|
|
|
|
return res;
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_dsp::write (const void *ptr, size_t len)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
if (s_audio->numbytesoutput () == 0)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
// check for wave file & setup frequencys properly if possible.
|
2001-05-21 01:31:06 +08:00
|
|
|
setupwav ((const char *) ptr, len);
|
|
|
|
|
2001-04-16 11:27:16 +08:00
|
|
|
// Open audio device properly with callbacks.
|
2001-05-21 01:31:06 +08:00
|
|
|
s_audio->close ();
|
|
|
|
if (!s_audio->open (audiofreq_, audiobits_, audiochannels_, true))
|
|
|
|
return 0;
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
2001-05-21 01:31:06 +08:00
|
|
|
|
|
|
|
s_audio->write (ptr, len);
|
2001-04-16 11:27:16 +08:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2002-12-14 12:01:32 +08:00
|
|
|
void __stdcall
|
|
|
|
fhandler_dev_dsp::read (void *ptr, size_t& len)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2002-12-14 12:01:32 +08:00
|
|
|
return;
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t
|
|
|
|
fhandler_dev_dsp::lseek (_off64_t offset, int whence)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_dsp::close (void)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
s_audio->close ();
|
2001-04-16 11:27:16 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_dev_dsp::dup (fhandler_base * child)
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
fhandler_dev_dsp *fhc = (fhandler_dev_dsp *) child;
|
2001-04-16 11:27:16 +08:00
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
fhc->set_flags (get_flags ());
|
2001-04-16 11:27:16 +08:00
|
|
|
fhc->audiochannels_ = audiochannels_;
|
|
|
|
fhc->audiobits_ = audiobits_;
|
|
|
|
fhc->audiofreq_ = audiofreq_;
|
|
|
|
fhc->audioformat_ = audioformat_;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
int
|
|
|
|
fhandler_dev_dsp::ioctl (unsigned int cmd, void *ptr)
|
2001-04-16 11:27:16 +08:00
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
int *intptr = (int *) ptr;
|
2001-04-16 11:27:16 +08:00
|
|
|
switch (cmd)
|
|
|
|
{
|
2002-09-30 12:35:18 +08:00
|
|
|
#define CASE(a) case a : debug_printf("/dev/dsp: ioctl %s", #a);
|
2001-04-16 11:27:16 +08:00
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
CASE (SNDCTL_DSP_RESET)
|
|
|
|
audioformat_ = AFMT_S8;
|
|
|
|
audiofreq_ = 8000;
|
|
|
|
audiobits_ = 8;
|
|
|
|
audiochannels_ = 1;
|
2001-06-29 10:20:01 +08:00
|
|
|
return 0;
|
2001-04-16 11:27:16 +08:00
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
CASE (SNDCTL_DSP_GETBLKSIZE)
|
|
|
|
*intptr = Audio::BLOCK_SIZE;
|
2001-11-05 14:09:15 +08:00
|
|
|
return 0;
|
2001-04-16 11:27:16 +08:00
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
CASE (SNDCTL_DSP_SETFMT)
|
|
|
|
{
|
|
|
|
int nBits = 0;
|
|
|
|
if (*intptr == AFMT_S16_LE)
|
|
|
|
nBits = 16;
|
|
|
|
else if (*intptr == AFMT_U8)
|
|
|
|
nBits = 8;
|
|
|
|
else if (*intptr == AFMT_S8)
|
|
|
|
nBits = 8;
|
|
|
|
if (nBits)
|
|
|
|
{
|
|
|
|
s_audio->setformat (*intptr);
|
|
|
|
s_audio->close ();
|
|
|
|
if (s_audio->open (audiofreq_, nBits, audiochannels_) == true)
|
|
|
|
{
|
|
|
|
audiobits_ = nBits;
|
2001-06-29 10:20:01 +08:00
|
|
|
return 0;
|
2001-05-21 01:31:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_audio->open (audiofreq_, audiobits_, audiochannels_);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
CASE (SNDCTL_DSP_SPEED)
|
|
|
|
s_audio->close ();
|
|
|
|
if (s_audio->open (*intptr, audiobits_, audiochannels_) == true)
|
|
|
|
{
|
|
|
|
audiofreq_ = *intptr;
|
2001-06-29 10:20:01 +08:00
|
|
|
return 0;
|
2001-05-21 01:31:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_audio->open (audiofreq_, audiobits_, audiochannels_);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
CASE (SNDCTL_DSP_STEREO)
|
|
|
|
{
|
|
|
|
int nChannels = *intptr + 1;
|
|
|
|
|
|
|
|
s_audio->close ();
|
|
|
|
if (s_audio->open (audiofreq_, audiobits_, nChannels) == true)
|
|
|
|
{
|
|
|
|
audiochannels_ = nChannels;
|
2001-06-29 10:20:01 +08:00
|
|
|
return 0;
|
2001-05-21 01:31:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_audio->open (audiofreq_, audiobits_, audiochannels_);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
CASE (SNDCTL_DSP_GETOSPACE)
|
|
|
|
{
|
|
|
|
audio_buf_info *p = (audio_buf_info *) ptr;
|
|
|
|
|
|
|
|
int nBlocks = s_audio->blocks ();
|
|
|
|
int leftblocks = ((Audio::MAX_BLOCKS - nBlocks) - 1);
|
|
|
|
if (leftblocks < 0)
|
|
|
|
leftblocks = 0;
|
|
|
|
if (leftblocks > 1)
|
|
|
|
leftblocks = 1;
|
|
|
|
int left = leftblocks * Audio::BLOCK_SIZE;
|
|
|
|
|
|
|
|
p->fragments = leftblocks;
|
|
|
|
p->fragstotal = Audio::MAX_BLOCKS;
|
|
|
|
p->fragsize = Audio::BLOCK_SIZE;
|
|
|
|
p->bytes = left;
|
|
|
|
|
|
|
|
debug_printf ("ptr %p nblocks %d leftblocks %d left bytes %d ",
|
|
|
|
ptr, nBlocks, leftblocks, left);
|
|
|
|
|
2001-06-29 10:20:01 +08:00
|
|
|
return 0;
|
2001-05-21 01:31:06 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
CASE (SNDCTL_DSP_SETFRAGMENT)
|
|
|
|
{
|
|
|
|
// Fake!! esound & mikmod require this on non PowerPC platforms.
|
|
|
|
//
|
2001-06-29 10:20:01 +08:00
|
|
|
return 0;
|
2001-05-21 01:31:06 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-01-14 10:08:35 +08:00
|
|
|
CASE (SNDCTL_DSP_GETFMTS)
|
|
|
|
{
|
|
|
|
*intptr = AFMT_S16_LE | AFMT_U8 | AFMT_S8; // more?
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-05-21 01:31:06 +08:00
|
|
|
default:
|
2002-09-30 12:35:18 +08:00
|
|
|
debug_printf ("/dev/dsp: ioctl not handled yet! FIXME:");
|
2001-05-21 01:31:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
#undef CASE
|
2001-04-16 11:27:16 +08:00
|
|
|
};
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_dev_dsp::dump ()
|
|
|
|
{
|
2001-05-21 01:31:06 +08:00
|
|
|
paranoid_printf ("here, fhandler_dev_dsp");
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
2001-05-24 13:20:17 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_dev_dsp::fixup_after_exec (HANDLE)
|
|
|
|
{
|
|
|
|
/* FIXME: Is there a better way to do this? */
|
|
|
|
s_audio = new (audio_buf) Audio;
|
|
|
|
}
|