2009-03-04 03:31:44 +00:00
|
|
|
/* //device/servers/AudioFlinger/AudioHardwareStub.cpp
|
|
|
|
**
|
|
|
|
** Copyright 2007, The Android Open Source Project
|
|
|
|
**
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
**
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
**
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <utils/String8.h>
|
|
|
|
|
|
|
|
#include "AudioHardwareStub.h"
|
2009-05-19 21:38:46 +00:00
|
|
|
#include <media/AudioRecord.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
AudioHardwareStub::AudioHardwareStub() : mMicMute(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioHardwareStub::~AudioHardwareStub()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t AudioHardwareStub::initCheck()
|
|
|
|
{
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioStreamOut* AudioHardwareStub::openOutputStream(
|
2009-07-17 19:17:14 +00:00
|
|
|
uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
AudioStreamOutStub* out = new AudioStreamOutStub();
|
2009-07-17 19:17:14 +00:00
|
|
|
status_t lStatus = out->set(format, channels, sampleRate);
|
2009-03-04 03:31:44 +00:00
|
|
|
if (status) {
|
|
|
|
*status = lStatus;
|
|
|
|
}
|
|
|
|
if (lStatus == NO_ERROR)
|
|
|
|
return out;
|
|
|
|
delete out;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
void AudioHardwareStub::closeOutputStream(AudioStreamOut* out)
|
|
|
|
{
|
|
|
|
delete out;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
AudioStreamIn* AudioHardwareStub::openInputStream(
|
2009-07-17 19:17:14 +00:00
|
|
|
uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate,
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t *status, AudioSystem::audio_in_acoustics acoustics)
|
|
|
|
{
|
2009-05-19 21:38:46 +00:00
|
|
|
// check for valid input source
|
2009-07-17 19:17:14 +00:00
|
|
|
if (!AudioSystem::isInputDevice((AudioSystem::audio_devices)devices)) {
|
2009-05-19 21:38:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
AudioStreamInStub* in = new AudioStreamInStub();
|
2009-07-17 19:17:14 +00:00
|
|
|
status_t lStatus = in->set(format, channels, sampleRate, acoustics);
|
2009-03-04 03:31:44 +00:00
|
|
|
if (status) {
|
|
|
|
*status = lStatus;
|
|
|
|
}
|
|
|
|
if (lStatus == NO_ERROR)
|
|
|
|
return in;
|
|
|
|
delete in;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
void AudioHardwareStub::closeInputStream(AudioStreamIn* in)
|
|
|
|
{
|
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t AudioHardwareStub::setVoiceVolume(float volume)
|
|
|
|
{
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t AudioHardwareStub::setMasterVolume(float volume)
|
|
|
|
{
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t AudioHardwareStub::dumpInternals(int fd, const Vector<String16>& args)
|
|
|
|
{
|
|
|
|
const size_t SIZE = 256;
|
|
|
|
char buffer[SIZE];
|
|
|
|
String8 result;
|
|
|
|
result.append("AudioHardwareStub::dumpInternals\n");
|
|
|
|
snprintf(buffer, SIZE, "\tmMicMute: %s\n", mMicMute? "true": "false");
|
|
|
|
result.append(buffer);
|
|
|
|
::write(fd, result.string(), result.size());
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t AudioHardwareStub::dump(int fd, const Vector<String16>& args)
|
|
|
|
{
|
|
|
|
dumpInternals(fd, args);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
status_t AudioStreamOutStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2009-07-17 19:17:14 +00:00
|
|
|
if (pFormat) *pFormat = format();
|
|
|
|
if (pChannels) *pChannels = channels();
|
|
|
|
if (pRate) *pRate = sampleRate();
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
return NO_ERROR;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t AudioStreamOutStub::write(const void* buffer, size_t bytes)
|
|
|
|
{
|
|
|
|
// fake timing for audio output
|
2009-07-17 19:17:14 +00:00
|
|
|
usleep(bytes * 1000000 / sizeof(int16_t) / AudioSystem::popCount(channels()) / sampleRate());
|
2009-03-04 03:31:44 +00:00
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t AudioStreamOutStub::standby()
|
|
|
|
{
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t AudioStreamOutStub::dump(int fd, const Vector<String16>& args)
|
|
|
|
{
|
|
|
|
const size_t SIZE = 256;
|
|
|
|
char buffer[SIZE];
|
|
|
|
String8 result;
|
|
|
|
snprintf(buffer, SIZE, "AudioStreamOutStub::dump\n");
|
|
|
|
snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate());
|
|
|
|
snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize());
|
2009-07-17 19:17:14 +00:00
|
|
|
snprintf(buffer, SIZE, "\tchannels: %d\n", channels());
|
2009-03-04 03:31:44 +00:00
|
|
|
snprintf(buffer, SIZE, "\tformat: %d\n", format());
|
|
|
|
result.append(buffer);
|
|
|
|
::write(fd, result.string(), result.size());
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
status_t AudioStreamInStub::set(int *pFormat, uint32_t *pChannels, uint32_t *pRate,
|
2009-03-04 03:31:44 +00:00
|
|
|
AudioSystem::audio_in_acoustics acoustics)
|
|
|
|
{
|
2009-07-17 19:17:14 +00:00
|
|
|
return NO_ERROR;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t AudioStreamInStub::read(void* buffer, ssize_t bytes)
|
|
|
|
{
|
|
|
|
// fake timing for audio input
|
2009-07-17 19:17:14 +00:00
|
|
|
usleep(bytes * 1000000 / sizeof(int16_t) / AudioSystem::popCount(channels()) / sampleRate());
|
2009-03-04 03:31:44 +00:00
|
|
|
memset(buffer, 0, bytes);
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t AudioStreamInStub::dump(int fd, const Vector<String16>& args)
|
|
|
|
{
|
|
|
|
const size_t SIZE = 256;
|
|
|
|
char buffer[SIZE];
|
|
|
|
String8 result;
|
|
|
|
snprintf(buffer, SIZE, "AudioStreamInStub::dump\n");
|
|
|
|
result.append(buffer);
|
|
|
|
snprintf(buffer, SIZE, "\tsample rate: %d\n", sampleRate());
|
|
|
|
result.append(buffer);
|
|
|
|
snprintf(buffer, SIZE, "\tbuffer size: %d\n", bufferSize());
|
|
|
|
result.append(buffer);
|
2009-07-17 19:17:14 +00:00
|
|
|
snprintf(buffer, SIZE, "\tchannels: %d\n", channels());
|
2009-03-04 03:31:44 +00:00
|
|
|
result.append(buffer);
|
|
|
|
snprintf(buffer, SIZE, "\tformat: %d\n", format());
|
|
|
|
result.append(buffer);
|
|
|
|
::write(fd, result.string(), result.size());
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|