The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
| 17 | #ifndef ANDROID_IAUDIOTRACK_H |
| 18 | #define ANDROID_IAUDIOTRACK_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/RefBase.h> |
| 24 | #include <utils/Errors.h> |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 25 | #include <binder/IInterface.h> |
| 26 | #include <binder/IMemory.h> |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 27 | #include <utils/LinearTransform.h> |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 28 | #include <utils/String8.h> |
Glenn Kasten | 53cec22 | 2013-08-29 09:01:02 -0700 | [diff] [blame] | 29 | #include <media/AudioTimestamp.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | // ---------------------------------------------------------------------------- |
| 34 | |
| 35 | class IAudioTrack : public IInterface |
| 36 | { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 37 | public: |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | DECLARE_META_INTERFACE(AudioTrack); |
| 39 | |
Glenn Kasten | 1099586 | 2012-01-03 14:50:23 -0800 | [diff] [blame] | 40 | /* Get this track's control block */ |
| 41 | virtual sp<IMemory> getCblk() const = 0; |
| 42 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | /* After it's created the track is not active. Call start() to |
Glenn Kasten | 3acbd05 | 2012-02-28 10:39:56 -0800 | [diff] [blame] | 44 | * make it active. |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | */ |
Glenn Kasten | 3acbd05 | 2012-02-28 10:39:56 -0800 | [diff] [blame] | 46 | virtual status_t start() = 0; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
| 48 | /* Stop a track. If set, the callback will cease being called and |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 49 | * obtainBuffer will return an error. Buffers that are already released |
Glenn Kasten | 99e53b8 | 2012-01-19 08:59:58 -0800 | [diff] [blame] | 50 | * will continue to be processed, unless/until flush() is called. |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | */ |
| 52 | virtual void stop() = 0; |
| 53 | |
Glenn Kasten | 99e53b8 | 2012-01-19 08:59:58 -0800 | [diff] [blame] | 54 | /* Flush a stopped or paused track. All pending/released buffers are discarded. |
| 55 | * This function has no effect if the track is not stopped or paused. |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | */ |
| 57 | virtual void flush() = 0; |
| 58 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | /* Pause a track. If set, the callback will cease being called and |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 60 | * obtainBuffer will return an error. Buffers that are already released |
Glenn Kasten | 99e53b8 | 2012-01-19 08:59:58 -0800 | [diff] [blame] | 61 | * will continue to be processed, unless/until flush() is called. |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | */ |
| 63 | virtual void pause() = 0; |
| 64 | |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 65 | /* Attach track auxiliary output to specified effect. Use effectId = 0 |
| 66 | * to detach track from effect. |
| 67 | */ |
| 68 | virtual status_t attachAuxEffect(int effectId) = 0; |
| 69 | |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 70 | |
| 71 | /* Allocate a shared memory buffer suitable for holding timed audio |
| 72 | samples */ |
| 73 | virtual status_t allocateTimedBuffer(size_t size, |
| 74 | sp<IMemory>* buffer) = 0; |
| 75 | |
| 76 | /* Queue a buffer obtained via allocateTimedBuffer for playback at the given |
| 77 | timestamp */ |
| 78 | virtual status_t queueTimedBuffer(const sp<IMemory>& buffer, |
| 79 | int64_t pts) = 0; |
| 80 | |
| 81 | /* Define the linear transform that will be applied to the timestamps |
| 82 | given to queueTimedBuffer (which are expressed in media time). |
| 83 | Target specifies whether this transform converts media time to local time |
| 84 | or Tungsten time. The values for target are defined in AudioTrack.h */ |
| 85 | virtual status_t setMediaTimeTransform(const LinearTransform& xform, |
| 86 | int target) = 0; |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 87 | |
| 88 | /* Send parameters to the audio hardware */ |
| 89 | virtual status_t setParameters(const String8& keyValuePairs) = 0; |
Glenn Kasten | 53cec22 | 2013-08-29 09:01:02 -0700 | [diff] [blame] | 90 | |
Glenn Kasten | 200092b | 2014-08-15 15:13:30 -0700 | [diff] [blame^] | 91 | /* Return NO_ERROR if timestamp is valid. timestamp is undefined otherwise. */ |
Glenn Kasten | 53cec22 | 2013-08-29 09:01:02 -0700 | [diff] [blame] | 92 | virtual status_t getTimestamp(AudioTimestamp& timestamp) = 0; |
Eric Laurent | 59fe010 | 2013-09-27 18:48:26 -0700 | [diff] [blame] | 93 | |
| 94 | /* Signal the playback thread for a change in control block */ |
| 95 | virtual void signal() = 0; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | // ---------------------------------------------------------------------------- |
| 99 | |
| 100 | class BnAudioTrack : public BnInterface<IAudioTrack> |
| 101 | { |
| 102 | public: |
| 103 | virtual status_t onTransact( uint32_t code, |
| 104 | const Parcel& data, |
| 105 | Parcel* reply, |
| 106 | uint32_t flags = 0); |
| 107 | }; |
| 108 | |
| 109 | // ---------------------------------------------------------------------------- |
| 110 | |
| 111 | }; // namespace android |
| 112 | |
| 113 | #endif // ANDROID_IAUDIOTRACK_H |