MmapStreamInterface.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ANDROID_AUDIO_MMAP_STREAM_INTERFACE_H
  17. #define ANDROID_AUDIO_MMAP_STREAM_INTERFACE_H
  18. #include <system/audio.h>
  19. #include <media/AudioClient.h>
  20. #include <utils/Errors.h>
  21. #include <utils/RefBase.h>
  22. namespace android {
  23. class MmapStreamCallback;
  24. class MmapStreamInterface : public virtual RefBase
  25. {
  26. public:
  27. /**
  28. * Values for direction argument passed to openMmapStream()
  29. */
  30. typedef enum {
  31. DIRECTION_OUTPUT = 0, /**< open a playback mmap stream */
  32. DIRECTION_INPUT, /**< open a capture mmap stream */
  33. } stream_direction_t;
  34. /**
  35. * Open a playback or capture stream in MMAP mode at the audio HAL.
  36. *
  37. * \note This method is implemented by AudioFlinger
  38. *
  39. * \param[in] direction open a playback or capture stream.
  40. * \param[in] attr audio attributes defining the main use case for this stream
  41. * \param[in,out] config audio parameters (sampling rate, format ...) for the stream.
  42. * Requested parameters as input,
  43. * Actual parameters as output
  44. * \param[in] client a AudioClient struct describing the first client using this stream.
  45. * \param[in,out] deviceId audio device the stream should preferably be routed to/from
  46. * Requested as input,
  47. * Actual as output
  48. * \param[in,out] sessionId audio sessionId for the stream
  49. * Requested as input, may be AUDIO_SESSION_ALLOCATE
  50. * Actual as output
  51. * \param[in] callback the MmapStreamCallback interface used by AudioFlinger to notify
  52. * condition changes affecting the stream operation
  53. * \param[out] interface the MmapStreamInterface interface controlling the created stream
  54. * \param[out] same unique handle as the one used for the first client stream started.
  55. * \return OK if the stream was successfully created.
  56. * NO_INIT if AudioFlinger is not properly initialized
  57. * BAD_VALUE if the stream cannot be opened because of invalid arguments
  58. * INVALID_OPERATION if the stream cannot be opened because of platform limitations
  59. */
  60. static status_t openMmapStream(stream_direction_t direction,
  61. const audio_attributes_t *attr,
  62. audio_config_base_t *config,
  63. const AudioClient& client,
  64. audio_port_handle_t *deviceId,
  65. audio_session_t *sessionId,
  66. const sp<MmapStreamCallback>& callback,
  67. sp<MmapStreamInterface>& interface,
  68. audio_port_handle_t *handle);
  69. /**
  70. * Retrieve information on the mmap buffer used for audio samples transfer.
  71. * Must be called before any other method after opening the stream or entering standby.
  72. *
  73. * \param[in] min_size_frames minimum buffer size requested. The actual buffer
  74. * size returned in struct audio_mmap_buffer_info can be larger.
  75. * \param[out] info address at which the mmap buffer information should be returned.
  76. *
  77. * \return OK if the buffer was allocated.
  78. * NO_INIT in case of initialization error
  79. * BAD_VALUE if the requested buffer size is too large
  80. * INVALID_OPERATION if called out of sequence (e.g. buffer already allocated)
  81. */
  82. virtual status_t createMmapBuffer(int32_t minSizeFrames,
  83. struct audio_mmap_buffer_info *info) = 0;
  84. /**
  85. * Read current read/write position in the mmap buffer with associated time stamp.
  86. *
  87. * \param[out] position address at which the mmap read/write position should be returned.
  88. *
  89. * \return OK if the position is successfully returned.
  90. * NO_INIT in case of initialization error
  91. * NOT_ENOUGH_DATA if the position cannot be retrieved
  92. * INVALID_OPERATION if called before createMmapBuffer()
  93. */
  94. virtual status_t getMmapPosition(struct audio_mmap_position *position) = 0;
  95. /**
  96. * Start a stream operating in mmap mode.
  97. * createMmapBuffer() must be called before calling start()
  98. *
  99. * \param[in] client a AudioClient struct describing the client starting on this stream.
  100. * \param[out] handle unique handle for this instance. Used with stop().
  101. * \return OK in case of success.
  102. * NO_INIT in case of initialization error
  103. * INVALID_OPERATION if called out of sequence
  104. */
  105. virtual status_t start(const AudioClient& client, audio_port_handle_t *handle) = 0;
  106. /**
  107. * Stop a stream operating in mmap mode.
  108. * Must be called after start()
  109. *
  110. * \param[in] handle unique handle allocated by start().
  111. * \return OK in case of success.
  112. * NO_INIT in case of initialization error
  113. * INVALID_OPERATION if called out of sequence
  114. */
  115. virtual status_t stop(audio_port_handle_t handle) = 0;
  116. /**
  117. * Put a stream operating in mmap mode into standby.
  118. * Must be called after createMmapBuffer(). Cannot be called if any client is active.
  119. * It is recommended to place a mmap stream into standby as often as possible when no client is
  120. * active to save power.
  121. *
  122. * \return OK in case of success.
  123. * NO_INIT in case of initialization error
  124. * INVALID_OPERATION if called out of sequence
  125. */
  126. virtual status_t standby() = 0;
  127. protected:
  128. // Subclasses can not be constructed directly by clients.
  129. MmapStreamInterface() {}
  130. // The destructor automatically closes the stream.
  131. virtual ~MmapStreamInterface() {}
  132. };
  133. } // namespace android
  134. #endif // ANDROID_AUDIO_MMAP_STREAM_INTERFACE_H