summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/media/AudioSystem.h39
-rw-r--r--include/media/AudioTrack.h15
-rw-r--r--include/media/IAudioFlinger.h13
-rw-r--r--include/media/IAudioFlingerClient.h2
-rw-r--r--include/media/IMediaRecorder.h1
-rw-r--r--include/media/PVMediaRecorder.h1
-rw-r--r--include/media/mediarecorder.h1
-rw-r--r--media/libmedia/AudioRecord.cpp18
-rw-r--r--media/libmedia/AudioSystem.cpp103
-rw-r--r--media/libmedia/AudioTrack.cpp15
-rw-r--r--media/libmedia/IAudioFlinger.cpp47
-rw-r--r--media/libmedia/IAudioFlingerClient.cpp12
-rw-r--r--media/libmedia/IMediaRecorder.cpp29
-rw-r--r--media/libmedia/JetPlayer.cpp2
-rw-r--r--media/libmedia/ToneGenerator.cpp8
-rw-r--r--media/libmedia/mediaplayer.cpp2
-rw-r--r--media/libmedia/mediarecorder.cpp32
-rw-r--r--media/libmediaplayerservice/MediaPlayerService.cpp10
-rw-r--r--media/libmediaplayerservice/MediaRecorderClient.cpp11
-rw-r--r--media/libmediaplayerservice/MediaRecorderClient.h1
-rw-r--r--media/libmediaplayerservice/MidiFile.cpp2
-rw-r--r--media/libmediaplayerservice/VorbisPlayer.cpp2
22 files changed, 242 insertions, 124 deletions
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 6bd54ba..7437f65 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -29,8 +29,27 @@ class AudioSystem
{
public:
+ enum stream_type {
+ DEFAULT =-1,
+ VOICE_CALL = 0,
+ SYSTEM = 1,
+ RING = 2,
+ MUSIC = 3,
+ ALARM = 4,
+ NOTIFICATION = 5,
+ BLUETOOTH_SCO = 6,
+ NUM_STREAM_TYPES
+ };
+
+ enum audio_output_type {
+ AUDIO_OUTPUT_DEFAULT =-1,
+ AUDIO_OUTPUT_HARDWARE = 0,
+ AUDIO_OUTPUT_A2DP = 1,
+ NUM_AUDIO_OUTPUT_TYPES
+ };
+
enum audio_format {
- DEFAULT = 0,
+ FORMAT_DEFAULT = 0,
PCM_16_BIT,
PCM_8_BIT,
INVALID_FORMAT
@@ -96,9 +115,11 @@ public:
static float linearToLog(int volume);
static int logToLinear(float volume);
- static status_t getOutputSamplingRate(int* samplingRate);
- static status_t getOutputFrameCount(int* frameCount);
- static status_t getOutputLatency(uint32_t* latency);
+ static status_t getOutputSamplingRate(int* samplingRate, int stream = DEFAULT);
+ static status_t getOutputFrameCount(int* frameCount, int stream = DEFAULT);
+ static status_t getOutputLatency(uint32_t* latency, int stream = DEFAULT);
+
+ static bool routedToA2dpOutput(int streamType);
static status_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount,
size_t* buffSize);
@@ -117,9 +138,10 @@ private:
virtual void binderDied(const wp<IBinder>& who);
// IAudioFlingerClient
- virtual void audioOutputChanged(uint32_t frameCount, uint32_t samplingRate, uint32_t latency);
+ virtual void a2dpEnabledChanged(bool enabled);
};
+ static int getOutput(int streamType);
static sp<AudioFlingerClient> gAudioFlingerClient;
@@ -128,9 +150,10 @@ private:
static Mutex gLock;
static sp<IAudioFlinger> gAudioFlinger;
static audio_error_callback gAudioErrorCallback;
- static int gOutSamplingRate;
- static int gOutFrameCount;
- static uint32_t gOutLatency;
+ static int gOutSamplingRate[NUM_AUDIO_OUTPUT_TYPES];
+ static int gOutFrameCount[NUM_AUDIO_OUTPUT_TYPES];
+ static uint32_t gOutLatency[NUM_AUDIO_OUTPUT_TYPES];
+ static bool gA2dpEnabled;
static size_t gInBuffSize;
// previous parameters for recording buffer size queries
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 5b2bab9..659f5f8 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -42,19 +42,6 @@ class audio_track_cblk_t;
class AudioTrack
{
public:
-
- enum stream_type {
- DEFAULT =-1,
- VOICE_CALL = 0,
- SYSTEM = 1,
- RING = 2,
- MUSIC = 3,
- ALARM = 4,
- NOTIFICATION = 5,
- BLUETOOTH_SCO = 6,
- NUM_STREAM_TYPES
- };
-
enum channel_index {
MONO = 0,
LEFT = 0,
@@ -128,7 +115,7 @@ public:
* Parameters:
*
* streamType: Select the type of audio stream this track is attached to
- * (e.g. AudioTrack::MUSIC).
+ * (e.g. AudioSystem::MUSIC).
* sampleRate: Track sampling rate in Hz.
* format: PCM sample format (e.g AudioSystem::PCM_16_BIT for signed
* 16 bits per sample).
diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h
index df601d7..6f13fe0 100644
--- a/include/media/IAudioFlinger.h
+++ b/include/media/IAudioFlinger.h
@@ -65,11 +65,11 @@ public:
/* query the audio hardware state. This state never changes,
* and therefore can be cached.
*/
- virtual uint32_t sampleRate() const = 0;
- virtual int channelCount() const = 0;
- virtual int format() const = 0;
- virtual size_t frameCount() const = 0;
- virtual uint32_t latency() const = 0;
+ virtual uint32_t sampleRate(int output) const = 0;
+ virtual int channelCount(int output) const = 0;
+ virtual int format(int output) const = 0;
+ virtual size_t frameCount(int output) const = 0;
+ virtual uint32_t latency(int output) const = 0;
/* set/get the audio hardware state. This will probably be used by
* the preference panel, mostly.
@@ -117,6 +117,9 @@ public:
// force AudioFlinger thread out of standby
virtual void wakeUp() = 0;
+
+ // is A2DP output enabled
+ virtual bool isA2dpEnabled() const = 0;
};
diff --git a/include/media/IAudioFlingerClient.h b/include/media/IAudioFlingerClient.h
index 10c3e0f..c3deb0b 100644
--- a/include/media/IAudioFlingerClient.h
+++ b/include/media/IAudioFlingerClient.h
@@ -32,7 +32,7 @@ public:
DECLARE_META_INTERFACE(AudioFlingerClient);
// Notifies a change of audio output from/to hardware to/from A2DP.
- virtual void audioOutputChanged(uint32_t frameCount, uint32_t samplingRate, uint32_t latency) = 0;
+ virtual void a2dpEnabledChanged(bool enabled) = 0;
};
diff --git a/include/media/IMediaRecorder.h b/include/media/IMediaRecorder.h
index 49e45d1..0dff84e 100644
--- a/include/media/IMediaRecorder.h
+++ b/include/media/IMediaRecorder.h
@@ -38,6 +38,7 @@ public:
virtual status_t setVideoEncoder(int ve) = 0;
virtual status_t setAudioEncoder(int ae) = 0;
virtual status_t setOutputFile(const char* path) = 0;
+ virtual status_t setOutputFile(int fd, int64_t offset, int64_t length) = 0;
virtual status_t setVideoSize(int width, int height) = 0;
virtual status_t setVideoFrameRate(int frames_per_second) = 0;
virtual status_t prepare() = 0;
diff --git a/include/media/PVMediaRecorder.h b/include/media/PVMediaRecorder.h
index 5fee0d6..f795d04 100644
--- a/include/media/PVMediaRecorder.h
+++ b/include/media/PVMediaRecorder.h
@@ -43,6 +43,7 @@ public:
status_t setCamera(const sp<ICamera>& camera);
status_t setPreviewSurface(const sp<ISurface>& surface);
status_t setOutputFile(const char *path);
+ status_t setOutputFile(int fd, int64_t offset, int64_t length);
status_t prepare();
status_t start();
status_t stop();
diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h
index a901d32..436e8f1 100644
--- a/include/media/mediarecorder.h
+++ b/include/media/mediarecorder.h
@@ -102,6 +102,7 @@ public:
status_t setVideoEncoder(int ve);
status_t setAudioEncoder(int ae);
status_t setOutputFile(const char* path);
+ status_t setOutputFile(int fd, int64_t offset, int64_t length);
status_t setVideoSize(int width, int height);
status_t setVideoFrameRate(int frames_per_second);
status_t prepare();
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index a987b92..3d39181 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -128,22 +128,8 @@ status_t AudioRecord::set(
return BAD_VALUE;
}
- size_t inputBuffSizeInBytes = -1;
- if (AudioSystem::getInputBufferSize(sampleRate, format, channelCount, &inputBuffSizeInBytes)
- != NO_ERROR) {
- LOGE("AudioSystem could not query the input buffer size.");
- return NO_INIT;
- }
- if (inputBuffSizeInBytes == 0) {
- LOGE("Recording parameters are not supported: sampleRate %d, channelCount %d, format %d",
- sampleRate, channelCount, format);
- return BAD_VALUE;
- }
- int frameSizeInBytes = channelCount * (format == AudioSystem::PCM_16_BIT ? 2 : 1);
-
- // We use 2* size of input buffer for ping pong use of record buffer.
- int minFrameCount = 2 * inputBuffSizeInBytes / frameSizeInBytes;
- LOGV("AudioRecord::set() minFrameCount = %d", minFrameCount);
+ // TODO: Get input frame count from hardware.
+ int minFrameCount = 1024*2;
if (frameCount == 0) {
frameCount = minFrameCount;
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index cf91105..63dfc3b 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -20,7 +20,6 @@
#include <utils/Log.h>
#include <utils/IServiceManager.h>
#include <media/AudioSystem.h>
-#include <media/AudioTrack.h>
#include <math.h>
namespace android {
@@ -31,9 +30,10 @@ sp<IAudioFlinger> AudioSystem::gAudioFlinger;
sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient;
audio_error_callback AudioSystem::gAudioErrorCallback = NULL;
// Cached values
-int AudioSystem::gOutSamplingRate = 0;
-int AudioSystem::gOutFrameCount = 0;
-uint32_t AudioSystem::gOutLatency = 0;
+int AudioSystem::gOutSamplingRate[NUM_AUDIO_OUTPUT_TYPES];
+int AudioSystem::gOutFrameCount[NUM_AUDIO_OUTPUT_TYPES];
+uint32_t AudioSystem::gOutLatency[NUM_AUDIO_OUTPUT_TYPES];
+bool AudioSystem::gA2dpEnabled;
// Cached values for recording queries
uint32_t AudioSystem::gPrevInSamplingRate = 16000;
int AudioSystem::gPrevInFormat = AudioSystem::PCM_16_BIT;
@@ -66,9 +66,12 @@ const sp<IAudioFlinger>& AudioSystem::get_audio_flinger()
gAudioFlinger = interface_cast<IAudioFlinger>(binder);
gAudioFlinger->registerClient(gAudioFlingerClient);
// Cache frequently accessed parameters
- gOutFrameCount = (int)gAudioFlinger->frameCount();
- gOutSamplingRate = (int)gAudioFlinger->sampleRate();
- gOutLatency = gAudioFlinger->latency();
+ for (int output = 0; output < NUM_AUDIO_OUTPUT_TYPES; output++) {
+ gOutFrameCount[output] = (int)gAudioFlinger->frameCount(output);
+ gOutSamplingRate[output] = (int)gAudioFlinger->sampleRate(output);
+ gOutLatency[output] = gAudioFlinger->latency(output);
+ }
+ gA2dpEnabled = gAudioFlinger->isA2dpEnabled();
}
LOGE_IF(gAudioFlinger==0, "no AudioFlinger!?");
return gAudioFlinger;
@@ -147,7 +150,7 @@ status_t AudioSystem::getMasterMute(bool* mute)
status_t AudioSystem::setStreamVolume(int stream, float value)
{
- if (uint32_t(stream) >= AudioTrack::NUM_STREAM_TYPES) return BAD_VALUE;
+ if (uint32_t(stream) >= NUM_STREAM_TYPES) return BAD_VALUE;
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
if (af == 0) return PERMISSION_DENIED;
af->setStreamVolume(stream, value);
@@ -156,7 +159,7 @@ status_t AudioSystem::setStreamVolume(int stream, float value)
status_t AudioSystem::setStreamMute(int stream, bool mute)
{
- if (uint32_t(stream) >= AudioTrack::NUM_STREAM_TYPES) return BAD_VALUE;
+ if (uint32_t(stream) >= NUM_STREAM_TYPES) return BAD_VALUE;
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
if (af == 0) return PERMISSION_DENIED;
af->setStreamMute(stream, mute);
@@ -165,7 +168,7 @@ status_t AudioSystem::setStreamMute(int stream, bool mute)
status_t AudioSystem::getStreamVolume(int stream, float* volume)
{
- if (uint32_t(stream) >= AudioTrack::NUM_STREAM_TYPES) return BAD_VALUE;
+ if (uint32_t(stream) >= NUM_STREAM_TYPES) return BAD_VALUE;
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
if (af == 0) return PERMISSION_DENIED;
*volume = af->streamVolume(stream);
@@ -174,7 +177,7 @@ status_t AudioSystem::getStreamVolume(int stream, float* volume)
status_t AudioSystem::getStreamMute(int stream, bool* mute)
{
- if (uint32_t(stream) >= AudioTrack::NUM_STREAM_TYPES) return BAD_VALUE;
+ if (uint32_t(stream) >= NUM_STREAM_TYPES) return BAD_VALUE;
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
if (af == 0) return PERMISSION_DENIED;
*mute = af->streamMute(stream);
@@ -252,37 +255,48 @@ int AudioSystem::logToLinear(float volume)
return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
}
-status_t AudioSystem::getOutputSamplingRate(int* samplingRate)
+status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType)
{
- if (gOutSamplingRate == 0) {
+ int output = getOutput(streamType);
+
+ if (gOutSamplingRate[output] == 0) {
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
if (af == 0) return PERMISSION_DENIED;
// gOutSamplingRate is updated by get_audio_flinger()
}
- *samplingRate = gOutSamplingRate;
+ LOGV("getOutputSamplingRate() streamType %d, output %d, sampling rate %d", streamType, output, gOutSamplingRate[output]);
+ *samplingRate = gOutSamplingRate[output];
return NO_ERROR;
}
-status_t AudioSystem::getOutputFrameCount(int* frameCount)
+status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType)
{
- if (gOutFrameCount == 0) {
+ int output = getOutput(streamType);
+
+ if (gOutFrameCount[output] == 0) {
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
if (af == 0) return PERMISSION_DENIED;
// gOutFrameCount is updated by get_audio_flinger()
}
- *frameCount = gOutFrameCount;
+ LOGV("getOutputFrameCount() streamType %d, output %d, frame count %d", streamType, output, gOutFrameCount[output]);
+
+ *frameCount = gOutFrameCount[output];
return NO_ERROR;
}
-status_t AudioSystem::getOutputLatency(uint32_t* latency)
+status_t AudioSystem::getOutputLatency(uint32_t* latency, int streamType)
{
- if (gOutLatency == 0) {
+ int output = getOutput(streamType);
+
+ if (gOutLatency[output] == 0) {
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
if (af == 0) return PERMISSION_DENIED;
// gOutLatency is updated by get_audio_flinger()
- }
- *latency = gOutLatency;
+ }
+ LOGV("getOutputLatency() streamType %d, output %d, latency %d", streamType, output, gOutLatency[output]);
+
+ *latency = gOutLatency[output];
return NO_ERROR;
}
@@ -315,24 +329,23 @@ status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, int format, int ch
void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who) {
Mutex::Autolock _l(AudioSystem::gLock);
AudioSystem::gAudioFlinger.clear();
- AudioSystem::gOutSamplingRate = 0;
- AudioSystem::gOutFrameCount = 0;
- AudioSystem::gOutLatency = 0;
+
+ for (int output = 0; output < NUM_AUDIO_OUTPUT_TYPES; output++) {
+ gOutFrameCount[output] = 0;
+ gOutSamplingRate[output] = 0;
+ gOutLatency[output] = 0;
+ }
AudioSystem::gInBuffSize = 0;
-
+
if (gAudioErrorCallback) {
gAudioErrorCallback(DEAD_OBJECT);
}
LOGW("AudioFlinger server died!");
}
-void AudioSystem::AudioFlingerClient::audioOutputChanged(uint32_t frameCount, uint32_t samplingRate, uint32_t latency) {
-
- AudioSystem::gOutFrameCount = frameCount;
- AudioSystem::gOutSamplingRate = samplingRate;
- AudioSystem::gOutLatency = latency;
-
- LOGV("AudioFlinger output changed!");
+void AudioSystem::AudioFlingerClient::a2dpEnabledChanged(bool enabled) {
+ gA2dpEnabled = enabled;
+ LOGV("AudioFlinger A2DP enabled status changed! %d", enabled);
}
void AudioSystem::setErrorCallback(audio_error_callback cb) {
@@ -340,5 +353,31 @@ void AudioSystem::setErrorCallback(audio_error_callback cb) {
gAudioErrorCallback = cb;
}
+int AudioSystem::getOutput(int streamType)
+{
+ if (streamType == DEFAULT) {
+ streamType = MUSIC;
+ }
+ if (gA2dpEnabled && routedToA2dpOutput(streamType)) {
+ return AUDIO_OUTPUT_A2DP;
+ } else {
+ return AUDIO_OUTPUT_HARDWARE;
+ }
+}
+
+bool AudioSystem::routedToA2dpOutput(int streamType) {
+ switch(streamType) {
+ case MUSIC:
+ case VOICE_CALL:
+ case BLUETOOTH_SCO:
+ case SYSTEM:
+ return true;
+ default:
+ return false;
+ }
+}
+
+
+
}; // namespace android
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 63b2012..1ffad46 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -128,22 +128,21 @@ status_t AudioTrack::set(
return NO_INIT;
}
int afSampleRate;
- if (AudioSystem::getOutputSamplingRate(&afSampleRate) != NO_ERROR) {
+ if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
return NO_INIT;
}
int afFrameCount;
- if (AudioSystem::getOutputFrameCount(&afFrameCount) != NO_ERROR) {
+ if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != NO_ERROR) {
return NO_INIT;
}
uint32_t afLatency;
- if (AudioSystem::getOutputLatency(&afLatency) != NO_ERROR) {
+ if (AudioSystem::getOutputLatency(&afLatency, streamType) != NO_ERROR) {
return NO_INIT;
}
-
// handle default values first.
- if (streamType == DEFAULT) {
- streamType = MUSIC;
+ if (streamType == AudioSystem::DEFAULT) {
+ streamType = AudioSystem::MUSIC;
}
if (sampleRate == 0) {
sampleRate = afSampleRate;
@@ -260,7 +259,7 @@ status_t AudioTrack::set(
mMarkerPosition = 0;
mNewPosition = 0;
mUpdatePeriod = 0;
-
+
return NO_ERROR;
}
@@ -434,7 +433,7 @@ void AudioTrack::setSampleRate(int rate)
{
int afSamplingRate;
- if (AudioSystem::getOutputSamplingRate(&afSamplingRate) != NO_ERROR) {
+ if (AudioSystem::getOutputSamplingRate(&afSamplingRate, mStreamType) != NO_ERROR) {
return;
}
// Resampler implementation limits input sampling rate to 2 x output sampling rate.
diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cpp
index 4215820..5cbb25c 100644
--- a/media/libmedia/IAudioFlinger.cpp
+++ b/media/libmedia/IAudioFlinger.cpp
@@ -53,7 +53,8 @@ enum {
SET_PARAMETER,
REGISTER_CLIENT,
GET_INPUTBUFFERSIZE,
- WAKE_UP
+ WAKE_UP,
+ IS_A2DP_ENABLED
};
class BpAudioFlinger : public BpInterface<IAudioFlinger>
@@ -123,42 +124,47 @@ public:
return interface_cast<IAudioRecord>(reply.readStrongBinder());
}
- virtual uint32_t sampleRate() const
+ virtual uint32_t sampleRate(int output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
+ data.writeInt32(output);
remote()->transact(SAMPLE_RATE, data, &reply);
return reply.readInt32();
}
- virtual int channelCount() const
+ virtual int channelCount(int output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
+ data.writeInt32(output);
remote()->transact(CHANNEL_COUNT, data, &reply);
return reply.readInt32();
}
- virtual int format() const
+ virtual int format(int output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
+ data.writeInt32(output);
remote()->transact(FORMAT, data, &reply);
return reply.readInt32();
}
- virtual size_t frameCount() const
+ virtual size_t frameCount(int output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
+ data.writeInt32(output);
remote()->transact(FRAME_COUNT, data, &reply);
return reply.readInt32();
}
- virtual uint32_t latency() const
+ virtual uint32_t latency(int output) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
+ data.writeInt32(output);
remote()->transact(LATENCY, data, &reply);
return reply.readInt32();
}
@@ -333,6 +339,14 @@ public:
remote()->transact(WAKE_UP, data, &reply);
return;
}
+
+ virtual bool isA2dpEnabled() const
+ {
+ Parcel data, reply;
+ data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
+ remote()->transact(IS_A2DP_ENABLED, data, &reply);
+ return (bool)reply.readInt32();
+ }
};
IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
@@ -385,27 +399,32 @@ status_t BnAudioFlinger::onTransact(
} break;
case SAMPLE_RATE: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
- reply->writeInt32( sampleRate() );
+ int output = data.readInt32();
+ reply->writeInt32( sampleRate(output) );
return NO_ERROR;
} break;
case CHANNEL_COUNT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
- reply->writeInt32( channelCount() );
+ int output = data.readInt32();
+ reply->writeInt32( channelCount(output) );
return NO_ERROR;
} break;
case FORMAT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
- reply->writeInt32( format() );
+ int output = data.readInt32();
+ reply->writeInt32( format(output) );
return NO_ERROR;
} break;
case FRAME_COUNT: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
- reply->writeInt32( frameCount() );
+ int output = data.readInt32();
+ reply->writeInt32( frameCount(output) );
return NO_ERROR;
} break;
case LATENCY: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
- reply->writeInt32( latency() );
+ int output = data.readInt32();
+ reply->writeInt32( latency(output) );
return NO_ERROR;
} break;
case SET_MASTER_VOLUME: {
@@ -519,7 +538,11 @@ status_t BnAudioFlinger::onTransact(
wakeUp();
return NO_ERROR;
} break;
-
+ case IS_A2DP_ENABLED: {
+ CHECK_INTERFACE(IAudioFlinger, data, reply);
+ reply->writeInt32( (int)isA2dpEnabled() );
+ return NO_ERROR;
+ } break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/media/libmedia/IAudioFlingerClient.cpp b/media/libmedia/IAudioFlingerClient.cpp
index d956266..5feb11f 100644
--- a/media/libmedia/IAudioFlingerClient.cpp
+++ b/media/libmedia/IAudioFlingerClient.cpp
@@ -38,13 +38,11 @@ public:
{
}
- void audioOutputChanged(uint32_t frameCount, uint32_t samplingRate, uint32_t latency)
+ void a2dpEnabledChanged(bool enabled)
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlingerClient::getInterfaceDescriptor());
- data.writeInt32(frameCount);
- data.writeInt32(samplingRate);
- data.writeInt32(latency);
+ data.writeInt32((int)enabled);
remote()->transact(AUDIO_OUTPUT_CHANGED, data, &reply);
}
};
@@ -65,10 +63,8 @@ status_t BnAudioFlingerClient::onTransact(
switch(code) {
case AUDIO_OUTPUT_CHANGED: {
CHECK_INTERFACE(IAudioFlingerClient, data, reply);
- uint32_t frameCount = data.readInt32();
- uint32_t samplingRate = data.readInt32();
- uint32_t latency = data.readInt32();
- audioOutputChanged(frameCount, samplingRate, latency);
+ bool enabled = (bool)data.readInt32();
+ a2dpEnabledChanged(enabled);
return NO_ERROR;
} break;
default:
diff --git a/media/libmedia/IMediaRecorder.cpp b/media/libmedia/IMediaRecorder.cpp
index 1f6d599..507d03e 100644
--- a/media/libmedia/IMediaRecorder.cpp
+++ b/media/libmedia/IMediaRecorder.cpp
@@ -39,7 +39,8 @@ enum {
SET_OUTPUT_FORMAT,
SET_VIDEO_ENCODER,
SET_AUDIO_ENCODER,
- SET_OUTPUT_FILE,
+ SET_OUTPUT_FILE_PATH,
+ SET_OUTPUT_FILE_FD,
SET_VIDEO_SIZE,
SET_VIDEO_FRAMERATE,
SET_PREVIEW_SURFACE,
@@ -139,7 +140,18 @@ public:
Parcel data, reply;
data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
data.writeCString(path);
- remote()->transact(SET_OUTPUT_FILE, data, &reply);
+ remote()->transact(SET_OUTPUT_FILE_PATH, data, &reply);
+ return reply.readInt32();
+ }
+
+ status_t setOutputFile(int fd, int64_t offset, int64_t length) {
+ LOGV("setOutputFile(%d, %lld, %lld)", fd, offset, length);
+ Parcel data, reply;
+ data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
+ data.writeFileDescriptor(fd);
+ data.writeInt64(offset);
+ data.writeInt64(length);
+ remote()->transact(SET_OUTPUT_FILE_FD, data, &reply);
return reply.readInt32();
}
@@ -330,13 +342,22 @@ status_t BnMediaRecorder::onTransact(
return NO_ERROR;
} break;
- case SET_OUTPUT_FILE: {
- LOGV("SET_OUTPUT_FILE");
+ case SET_OUTPUT_FILE_PATH: {
+ LOGV("SET_OUTPUT_FILE_PATH");
CHECK_INTERFACE(IMediaRecorder, data, reply);
const char* path = data.readCString();
reply->writeInt32(setOutputFile(path));
return NO_ERROR;
} break;
+ case SET_OUTPUT_FILE_FD: {
+ LOGV("SET_OUTPUT_FILE_FD");
+ CHECK_INTERFACE(IMediaRecorder, data, reply);
+ int fd = dup(data.readFileDescriptor());
+ int64_t offset = data.readInt64();
+ int64_t length = data.readInt64();
+ reply->writeInt32(setOutputFile(fd, offset, length));
+ return NO_ERROR;
+ } break;
case SET_VIDEO_SIZE: {
LOGV("SET_VIDEO_SIZE");
CHECK_INTERFACE(IMediaRecorder, data, reply);
diff --git a/media/libmedia/JetPlayer.cpp b/media/libmedia/JetPlayer.cpp
index ead24d4..9bd75c2 100644
--- a/media/libmedia/JetPlayer.cpp
+++ b/media/libmedia/JetPlayer.cpp
@@ -96,7 +96,7 @@ int JetPlayer::init()
// create the output AudioTrack
mAudioTrack = new AudioTrack();
- mAudioTrack->set(AudioTrack::MUSIC, //TODO parametrize this
+ mAudioTrack->set(AudioSystem::MUSIC, //TODO parametrize this
pLibConfig->sampleRate,
1, // format = PCM 16bits per sample,
pLibConfig->numChannels,
diff --git a/media/libmedia/ToneGenerator.cpp b/media/libmedia/ToneGenerator.cpp
index fa36460..7fafc56 100644
--- a/media/libmedia/ToneGenerator.cpp
+++ b/media/libmedia/ToneGenerator.cpp
@@ -93,7 +93,7 @@ ToneGenerator::ToneGenerator(int streamType, float volume) {
mState = TONE_IDLE;
- if (AudioSystem::getOutputSamplingRate(&mSamplingRate) != NO_ERROR) {
+ if (AudioSystem::getOutputSamplingRate(&mSamplingRate, streamType) != NO_ERROR) {
LOGE("Unable to marshal AudioFlinger");
return;
}
@@ -182,7 +182,7 @@ bool ToneGenerator::startTone(int toneType) {
mLock.lock();
if (mState == TONE_STARTING) {
if (mWaitCbkCond.waitRelative(mLock, seconds(1)) != NO_ERROR) {
- LOGE("--- timed out");
+ LOGE("--- Immediate start timed out");
mState = TONE_IDLE;
}
}
@@ -200,7 +200,7 @@ bool ToneGenerator::startTone(int toneType) {
}
LOGV("cond received");
} else {
- LOGE("--- timed out");
+ LOGE("--- Delayed start timed out");
mState = TONE_IDLE;
}
}
@@ -235,7 +235,7 @@ void ToneGenerator::stopTone() {
if (lStatus == NO_ERROR) {
LOGV("track stop complete, time %d", (unsigned int)(systemTime()/1000000));
} else {
- LOGE("--- timed out");
+ LOGE("--- Stop timed out");
mState = TONE_IDLE;
mpAudioTrack->stop();
}
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index 31ff507..bd8579c 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -82,7 +82,7 @@ MediaPlayer::MediaPlayer()
mListener = NULL;
mCookie = NULL;
mDuration = -1;
- mStreamType = AudioTrack::MUSIC;
+ mStreamType = AudioSystem::MUSIC;
mCurrentPosition = -1;
mSeekPosition = -1;
mCurrentState = MEDIA_PLAYER_IDLE;
diff --git a/media/libmedia/mediarecorder.cpp b/media/libmedia/mediarecorder.cpp
index 6ee4c0d..4ab26ac 100644
--- a/media/libmedia/mediarecorder.cpp
+++ b/media/libmedia/mediarecorder.cpp
@@ -248,7 +248,33 @@ status_t MediaRecorder::setOutputFile(const char* path)
status_t ret = mMediaRecorder->setOutputFile(path);
if (OK != ret) {
- LOGV("setAudioEncoder failed: %d", ret);
+ LOGV("setOutputFile failed: %d", ret);
+ mCurrentState = MEDIA_RECORDER_ERROR;
+ return UNKNOWN_ERROR;
+ }
+ mIsOutputFileSet = true;
+ return ret;
+}
+
+status_t MediaRecorder::setOutputFile(int fd, int64_t offset, int64_t length)
+{
+ LOGV("setOutputFile(%d, %lld, %lld)", fd, offset, length);
+ if(mMediaRecorder == NULL) {
+ LOGE("media recorder is not initialized yet");
+ return INVALID_OPERATION;
+ }
+ if (mIsOutputFileSet) {
+ LOGE("output file has already been set");
+ return INVALID_OPERATION;
+ }
+ if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
+ LOGE("setOutputFile called in an invalid state(%d)", mCurrentState);
+ return INVALID_OPERATION;
+ }
+
+ status_t ret = mMediaRecorder->setOutputFile(fd, offset, length);
+ if (OK != ret) {
+ LOGV("setOutputFile failed: %d", ret);
mCurrentState = MEDIA_RECORDER_ERROR;
return UNKNOWN_ERROR;
}
@@ -306,7 +332,7 @@ status_t MediaRecorder::prepare()
return INVALID_OPERATION;
}
if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
- LOGE("setVideoFrameRate called in an invalid state: %d", mCurrentState);
+ LOGE("prepare called in an invalid state: %d", mCurrentState);
return INVALID_OPERATION;
}
@@ -328,7 +354,7 @@ status_t MediaRecorder::getMaxAmplitude(int* max)
return INVALID_OPERATION;
}
if (mCurrentState & MEDIA_RECORDER_ERROR) {
- LOGE("setVideoFrameRate called in an invalid state: %d", mCurrentState);
+ LOGE("getMaxAmplitude called in an invalid state: %d", mCurrentState);
return INVALID_OPERATION;
}
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 9e366e2..97e3536 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -818,7 +818,7 @@ Exit:
MediaPlayerService::AudioOutput::AudioOutput()
{
mTrack = 0;
- mStreamType = AudioTrack::MUSIC;
+ mStreamType = AudioSystem::MUSIC;
mLeftVolume = 1.0;
mRightVolume = 1.0;
mLatency = 0;
@@ -900,15 +900,15 @@ status_t MediaPlayerService::AudioOutput::open(uint32_t sampleRate, int channelC
int afFrameCount;
int frameCount;
- if (AudioSystem::getOutputFrameCount(&afFrameCount) != NO_ERROR) {
+ if (AudioSystem::getOutputFrameCount(&afFrameCount, mStreamType) != NO_ERROR) {
return NO_INIT;
}
- if (AudioSystem::getOutputSamplingRate(&afSampleRate) != NO_ERROR) {
+ if (AudioSystem::getOutputSamplingRate(&afSampleRate, mStreamType) != NO_ERROR) {
return NO_INIT;
}
- frameCount = (sampleRate*afFrameCount)/afSampleRate;
- AudioTrack *t = new AudioTrack(mStreamType, sampleRate, format, channelCount, frameCount*bufferCount);
+ frameCount = (sampleRate*afFrameCount*bufferCount)/afSampleRate;
+ AudioTrack *t = new AudioTrack(mStreamType, sampleRate, format, channelCount, frameCount);
if ((t == 0) || (t->initCheck() != NO_ERROR)) {
LOGE("Unable to create audio track");
delete t;
diff --git a/media/libmediaplayerservice/MediaRecorderClient.cpp b/media/libmediaplayerservice/MediaRecorderClient.cpp
index f326a0e..e8ba17f 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.cpp
+++ b/media/libmediaplayerservice/MediaRecorderClient.cpp
@@ -121,6 +121,17 @@ status_t MediaRecorderClient::setOutputFile(const char* path)
return mRecorder->setOutputFile(path);
}
+status_t MediaRecorderClient::setOutputFile(int fd, int64_t offset, int64_t length)
+{
+ LOGV("setOutputFile(%d, %lld, %lld)", fd, offset, length);
+ Mutex::Autolock lock(mLock);
+ if (mRecorder == NULL) {
+ LOGE("recorder is not initialized");
+ return NO_INIT;
+ }
+ return mRecorder->setOutputFile(fd, offset, length);
+}
+
status_t MediaRecorderClient::setVideoSize(int width, int height)
{
LOGV("setVideoSize(%dx%d)", width, height);
diff --git a/media/libmediaplayerservice/MediaRecorderClient.h b/media/libmediaplayerservice/MediaRecorderClient.h
index 3158017..2b80c10 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.h
+++ b/media/libmediaplayerservice/MediaRecorderClient.h
@@ -36,6 +36,7 @@ public:
virtual status_t setVideoEncoder(int ve);
virtual status_t setAudioEncoder(int ae);
virtual status_t setOutputFile(const char* path);
+ virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
virtual status_t setVideoSize(int width, int height);
virtual status_t setVideoFrameRate(int frames_per_second);
virtual status_t prepare();
diff --git a/media/libmediaplayerservice/MidiFile.cpp b/media/libmediaplayerservice/MidiFile.cpp
index 7ce2fab..d03caa5 100644
--- a/media/libmediaplayerservice/MidiFile.cpp
+++ b/media/libmediaplayerservice/MidiFile.cpp
@@ -58,7 +58,7 @@ static const S_EAS_LIB_CONFIG* pLibConfig = NULL;
MidiFile::MidiFile() :
mEasData(NULL), mEasHandle(NULL), mAudioBuffer(NULL),
mPlayTime(-1), mDuration(-1), mState(EAS_STATE_ERROR),
- mStreamType(AudioTrack::MUSIC), mLoop(false), mExit(false),
+ mStreamType(AudioSystem::MUSIC), mLoop(false), mExit(false),
mPaused(false), mRender(false), mTid(-1)
{
LOGV("constructor");
diff --git a/media/libmediaplayerservice/VorbisPlayer.cpp b/media/libmediaplayerservice/VorbisPlayer.cpp
index 009d628..0ad335f 100644
--- a/media/libmediaplayerservice/VorbisPlayer.cpp
+++ b/media/libmediaplayerservice/VorbisPlayer.cpp
@@ -55,7 +55,7 @@ static status_t STATE_OPEN = 2;
VorbisPlayer::VorbisPlayer() :
mAudioBuffer(NULL), mPlayTime(-1), mDuration(-1), mState(STATE_ERROR),
- mStreamType(AudioTrack::MUSIC), mLoop(false), mAndroidLoop(false),
+ mStreamType(AudioSystem::MUSIC), mLoop(false), mAndroidLoop(false),
mExit(false), mPaused(false), mRender(false), mRenderTid(-1)
{
LOGV("constructor\n");