You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
6.6 KiB

/*
* Copyright (C) 2016 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.
*/
#ifndef ANDROID_AUDIO_MMAP_STREAM_INTERFACE_H
#define ANDROID_AUDIO_MMAP_STREAM_INTERFACE_H
#include <system/audio.h>
aaudio: indicate client UID and PID to audio flinger Implement correct indication of client UID and PID to audio flinger for AAudio MMAP streams in both exclusive mode and shared mode. - Add start/stop client methods on MMAP streams used only when the MMAP stream is in AAudio service and carries a mix of shared streams. - Add "In Service'" indication from "client" side to AAudioServiceStreamMMAP so that the behavior can be adapted accordingly. - Modify logic on audio flinger side with regard to mmap tracks and audio HAL stream activity: - use same audio session for all clients on a same stream to match audio policy logic to share same direct output stream for clients on same session. This is also more consistent with current volume and effect handling as all MMAP clients sharing the same output stream have the same volume and use case. - start/stop the HAL when the stream is started/stopped with the initial client handle (returned when the stream is opened) but do not create a track. AAudioService implementation will always send an additional start command before first client starts and a stop command after last client stops, in both shared and exclusive mode. - start/stop a track only if the start/stop stream command is received with a handle different from the initial handle. - Allow more than one active client from the same UID on a MMAP input in audio policy. Bug: 62950008 Test: verify playback and capture in mmap mode Change-Id: I86151bbb637ff172d2fd5f813056eab13a7bcd3c
7 years ago
#include <media/AudioClient.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
namespace android {
class MmapStreamCallback;
class MmapStreamInterface : public virtual RefBase
{
public:
/**
* Values for direction argument passed to openMmapStream()
*/
typedef enum {
DIRECTION_OUTPUT = 0, /**< open a playback mmap stream */
DIRECTION_INPUT, /**< open a capture mmap stream */
} stream_direction_t;
/**
* Open a playback or capture stream in MMAP mode at the audio HAL.
*
* \note This method is implemented by AudioFlinger
*
* \param[in] direction open a playback or capture stream.
* \param[in] attr audio attributes defining the main use case for this stream
* \param[in,out] config audio parameters (sampling rate, format ...) for the stream.
* Requested parameters as input,
* Actual parameters as output
aaudio: indicate client UID and PID to audio flinger Implement correct indication of client UID and PID to audio flinger for AAudio MMAP streams in both exclusive mode and shared mode. - Add start/stop client methods on MMAP streams used only when the MMAP stream is in AAudio service and carries a mix of shared streams. - Add "In Service'" indication from "client" side to AAudioServiceStreamMMAP so that the behavior can be adapted accordingly. - Modify logic on audio flinger side with regard to mmap tracks and audio HAL stream activity: - use same audio session for all clients on a same stream to match audio policy logic to share same direct output stream for clients on same session. This is also more consistent with current volume and effect handling as all MMAP clients sharing the same output stream have the same volume and use case. - start/stop the HAL when the stream is started/stopped with the initial client handle (returned when the stream is opened) but do not create a track. AAudioService implementation will always send an additional start command before first client starts and a stop command after last client stops, in both shared and exclusive mode. - start/stop a track only if the start/stop stream command is received with a handle different from the initial handle. - Allow more than one active client from the same UID on a MMAP input in audio policy. Bug: 62950008 Test: verify playback and capture in mmap mode Change-Id: I86151bbb637ff172d2fd5f813056eab13a7bcd3c
7 years ago
* \param[in] client a AudioClient struct describing the first client using this stream.
* \param[in,out] deviceId audio device the stream should preferably be routed to/from
* Requested as input,
* Actual as output
* \param[in,out] sessionId audio sessionId for the stream
* Requested as input, may be AUDIO_SESSION_ALLOCATE
* Actual as output
* \param[in] callback the MmapStreamCallback interface used by AudioFlinger to notify
* condition changes affecting the stream operation
* \param[out] interface the MmapStreamInterface interface controlling the created stream
aaudio: indicate client UID and PID to audio flinger Implement correct indication of client UID and PID to audio flinger for AAudio MMAP streams in both exclusive mode and shared mode. - Add start/stop client methods on MMAP streams used only when the MMAP stream is in AAudio service and carries a mix of shared streams. - Add "In Service'" indication from "client" side to AAudioServiceStreamMMAP so that the behavior can be adapted accordingly. - Modify logic on audio flinger side with regard to mmap tracks and audio HAL stream activity: - use same audio session for all clients on a same stream to match audio policy logic to share same direct output stream for clients on same session. This is also more consistent with current volume and effect handling as all MMAP clients sharing the same output stream have the same volume and use case. - start/stop the HAL when the stream is started/stopped with the initial client handle (returned when the stream is opened) but do not create a track. AAudioService implementation will always send an additional start command before first client starts and a stop command after last client stops, in both shared and exclusive mode. - start/stop a track only if the start/stop stream command is received with a handle different from the initial handle. - Allow more than one active client from the same UID on a MMAP input in audio policy. Bug: 62950008 Test: verify playback and capture in mmap mode Change-Id: I86151bbb637ff172d2fd5f813056eab13a7bcd3c
7 years ago
* \param[out] same unique handle as the one used for the first client stream started.
* \return OK if the stream was successfully created.
* NO_INIT if AudioFlinger is not properly initialized
* BAD_VALUE if the stream cannot be opened because of invalid arguments
* INVALID_OPERATION if the stream cannot be opened because of platform limitations
*/
static status_t openMmapStream(stream_direction_t direction,
const audio_attributes_t *attr,
audio_config_base_t *config,
aaudio: indicate client UID and PID to audio flinger Implement correct indication of client UID and PID to audio flinger for AAudio MMAP streams in both exclusive mode and shared mode. - Add start/stop client methods on MMAP streams used only when the MMAP stream is in AAudio service and carries a mix of shared streams. - Add "In Service'" indication from "client" side to AAudioServiceStreamMMAP so that the behavior can be adapted accordingly. - Modify logic on audio flinger side with regard to mmap tracks and audio HAL stream activity: - use same audio session for all clients on a same stream to match audio policy logic to share same direct output stream for clients on same session. This is also more consistent with current volume and effect handling as all MMAP clients sharing the same output stream have the same volume and use case. - start/stop the HAL when the stream is started/stopped with the initial client handle (returned when the stream is opened) but do not create a track. AAudioService implementation will always send an additional start command before first client starts and a stop command after last client stops, in both shared and exclusive mode. - start/stop a track only if the start/stop stream command is received with a handle different from the initial handle. - Allow more than one active client from the same UID on a MMAP input in audio policy. Bug: 62950008 Test: verify playback and capture in mmap mode Change-Id: I86151bbb637ff172d2fd5f813056eab13a7bcd3c
7 years ago
const AudioClient& client,
audio_port_handle_t *deviceId,
audio_session_t *sessionId,
const sp<MmapStreamCallback>& callback,
aaudio: indicate client UID and PID to audio flinger Implement correct indication of client UID and PID to audio flinger for AAudio MMAP streams in both exclusive mode and shared mode. - Add start/stop client methods on MMAP streams used only when the MMAP stream is in AAudio service and carries a mix of shared streams. - Add "In Service'" indication from "client" side to AAudioServiceStreamMMAP so that the behavior can be adapted accordingly. - Modify logic on audio flinger side with regard to mmap tracks and audio HAL stream activity: - use same audio session for all clients on a same stream to match audio policy logic to share same direct output stream for clients on same session. This is also more consistent with current volume and effect handling as all MMAP clients sharing the same output stream have the same volume and use case. - start/stop the HAL when the stream is started/stopped with the initial client handle (returned when the stream is opened) but do not create a track. AAudioService implementation will always send an additional start command before first client starts and a stop command after last client stops, in both shared and exclusive mode. - start/stop a track only if the start/stop stream command is received with a handle different from the initial handle. - Allow more than one active client from the same UID on a MMAP input in audio policy. Bug: 62950008 Test: verify playback and capture in mmap mode Change-Id: I86151bbb637ff172d2fd5f813056eab13a7bcd3c
7 years ago
sp<MmapStreamInterface>& interface,
audio_port_handle_t *handle);
/**
* Retrieve information on the mmap buffer used for audio samples transfer.
* Must be called before any other method after opening the stream or entering standby.
*
* \param[in] min_size_frames minimum buffer size requested. The actual buffer
* size returned in struct audio_mmap_buffer_info can be larger.
* \param[out] info address at which the mmap buffer information should be returned.
*
* \return OK if the buffer was allocated.
* NO_INIT in case of initialization error
* BAD_VALUE if the requested buffer size is too large
* INVALID_OPERATION if called out of sequence (e.g. buffer already allocated)
*/
virtual status_t createMmapBuffer(int32_t minSizeFrames,
struct audio_mmap_buffer_info *info) = 0;
/**
* Read current read/write position in the mmap buffer with associated time stamp.
*
* \param[out] position address at which the mmap read/write position should be returned.
*
* \return OK if the position is successfully returned.
* NO_INIT in case of initialization error
* NOT_ENOUGH_DATA if the position cannot be retrieved
* INVALID_OPERATION if called before createMmapBuffer()
*/
virtual status_t getMmapPosition(struct audio_mmap_position *position) = 0;
/**
* Start a stream operating in mmap mode.
* createMmapBuffer() must be called before calling start()
*
aaudio: indicate client UID and PID to audio flinger Implement correct indication of client UID and PID to audio flinger for AAudio MMAP streams in both exclusive mode and shared mode. - Add start/stop client methods on MMAP streams used only when the MMAP stream is in AAudio service and carries a mix of shared streams. - Add "In Service'" indication from "client" side to AAudioServiceStreamMMAP so that the behavior can be adapted accordingly. - Modify logic on audio flinger side with regard to mmap tracks and audio HAL stream activity: - use same audio session for all clients on a same stream to match audio policy logic to share same direct output stream for clients on same session. This is also more consistent with current volume and effect handling as all MMAP clients sharing the same output stream have the same volume and use case. - start/stop the HAL when the stream is started/stopped with the initial client handle (returned when the stream is opened) but do not create a track. AAudioService implementation will always send an additional start command before first client starts and a stop command after last client stops, in both shared and exclusive mode. - start/stop a track only if the start/stop stream command is received with a handle different from the initial handle. - Allow more than one active client from the same UID on a MMAP input in audio policy. Bug: 62950008 Test: verify playback and capture in mmap mode Change-Id: I86151bbb637ff172d2fd5f813056eab13a7bcd3c
7 years ago
* \param[in] client a AudioClient struct describing the client starting on this stream.
* \param[in] attr audio attributes provided by the client.
* \param[out] handle unique handle for this instance. Used with stop().
* \return OK in case of success.
* NO_INIT in case of initialization error
* INVALID_OPERATION if called out of sequence
*/
virtual status_t start(const AudioClient& client,
const audio_attributes_t *attr,
audio_port_handle_t *handle) = 0;
/**
* Stop a stream operating in mmap mode.
* Must be called after start()
*
* \param[in] handle unique handle allocated by start().
* \return OK in case of success.
* NO_INIT in case of initialization error
* INVALID_OPERATION if called out of sequence
*/
virtual status_t stop(audio_port_handle_t handle) = 0;
/**
* Put a stream operating in mmap mode into standby.
* Must be called after createMmapBuffer(). Cannot be called if any client is active.
* It is recommended to place a mmap stream into standby as often as possible when no client is
* active to save power.
*
* \return OK in case of success.
* NO_INIT in case of initialization error
* INVALID_OPERATION if called out of sequence
*/
virtual status_t standby() = 0;
protected:
// Subclasses can not be constructed directly by clients.
MmapStreamInterface() {}
// The destructor automatically closes the stream.
virtual ~MmapStreamInterface() {}
};
} // namespace android
#endif // ANDROID_AUDIO_MMAP_STREAM_INTERFACE_H