1 /* 2 * Copyright (C) 2022 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 MEDIA_LIBAUDIOUSECASEVALIDATION_INCLUDE_MEDIA_USECASEVALIDATOR_H_ 17 #define MEDIA_LIBAUDIOUSECASEVALIDATION_INCLUDE_MEDIA_USECASEVALIDATOR_H_ 18 19 #pragma once 20 21 #include <error/Result.h> 22 #include <system/audio.h> 23 #include <android/content/AttributionSourceState.h> 24 25 #include <limits> 26 #include <memory> 27 28 namespace android { 29 namespace media { 30 31 /** 32 * Main entry-point for this library. 33 */ 34 class UsecaseValidator { 35 public: 36 virtual ~UsecaseValidator() = default; 37 38 /** 39 * A callback called by the module when the audio attributes for 40 * an active portId changes. 41 */ 42 class AttributesChangedCallback { 43 public: 44 virtual ~AttributesChangedCallback() = default; 45 virtual void onAttributesChanged(audio_port_handle_t portId, 46 const audio_attributes_t& attributes) = 0; 47 }; 48 49 /** 50 * Register a new mixer/stream. 51 * Called when the stream is opened at the HAL and communicates 52 * immutable stream attributes like flags, sampling rate, format. 53 */ 54 virtual status_t registerStream(audio_io_handle_t streamId, 55 const audio_config_base_t& audioConfig, 56 const audio_output_flags_t outputFlags) = 0; 57 58 /** 59 * Unregister a stream/mixer. 60 * Called when the stream is closed. 61 */ 62 virtual status_t unregisterStream(audio_io_handle_t streamId) = 0; 63 64 /** 65 * Indicates that some playback activity started on the stream. 66 * Called each time an audio track starts or resumes. 67 */ 68 virtual error::Result<audio_attributes_t> startClient(audio_io_handle_t streamId, 69 audio_port_handle_t portId, 70 const content::AttributionSourceState& attributionSource, 71 const audio_attributes_t& attributes, 72 const AttributesChangedCallback *callback) = 0; 73 74 /** 75 * Indicates that some playback activity stopped on the stream. 76 * Called each time an audio track stops or pauses. 77 */ 78 virtual status_t stopClient(audio_io_handle_t streamId, audio_port_handle_t portId) = 0; 79 80 /** 81 * Called to verify and update audio attributes for a track that is connected 82 * to the specified stream. 83 */ 84 virtual error::Result<audio_attributes_t> verifyAudioAttributes(audio_io_handle_t streamId, 85 const content::AttributionSourceState& attributionSource, 86 const audio_attributes_t& attributes) = 0; 87 }; 88 89 /** 90 * Creates an instance featuring a default implementation of the UsecaseValidator interface. 91 */ 92 std::unique_ptr<UsecaseValidator> createUsecaseValidator(); 93 94 } // namespace media 95 } // namespace android 96 97 #endif // MEDIA_LIBAUDIOUSECASEVALIDATION_INCLUDE_MEDIA_USECASEVALIDATOR_H_ 98