michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* michael@0: * Copyright (c) 2014 The Linux Foundation. All rights reserved. michael@0: * Copyright (C) 2007 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef AUDIO_SINK_H_ michael@0: #define AUDIO_SINK_H_ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #define DEFAULT_AUDIOSINK_BUFFERCOUNT 4 michael@0: #define DEFAULT_AUDIOSINK_BUFFERSIZE 1200 michael@0: #define DEFAULT_AUDIOSINK_SAMPLERATE 44100 michael@0: michael@0: // when the channel mask isn't known, use the channel count to derive a mask in michael@0: // AudioSink::open() michael@0: #define CHANNEL_MASK_USE_CHANNEL_ORDER 0 michael@0: michael@0: namespace mozilla { michael@0: michael@0: /** michael@0: * AudioSink: abstraction layer for audio output michael@0: * Stripped version of Android KK MediaPlayerBase::AudioSink class michael@0: */ michael@0: michael@0: class AudioSink : public android::RefBase michael@0: { michael@0: typedef android::String8 String8; michael@0: typedef android::status_t status_t; michael@0: michael@0: public: michael@0: enum cb_event_t { michael@0: CB_EVENT_FILL_BUFFER, // Request to write more data to buffer. michael@0: CB_EVENT_STREAM_END, // Sent after all the buffers queued in AF and HW michael@0: // are played back (after stop is called) michael@0: CB_EVENT_TEAR_DOWN // The AudioTrack was invalidated due to usecase michael@0: // change. Need to re-evaluate offloading options michael@0: }; michael@0: michael@0: // Callback returns the number of bytes actually written to the buffer. michael@0: typedef size_t (*AudioCallback)(AudioSink* aAudioSink, michael@0: void* aBuffer, michael@0: size_t aSize, michael@0: void* aCookie, michael@0: cb_event_t aEvent); michael@0: virtual ~AudioSink() {} michael@0: virtual ssize_t FrameSize() const = 0; michael@0: virtual status_t GetPosition(uint32_t* aPosition) const = 0; michael@0: virtual status_t SetVolume(float aVolume) const = 0; michael@0: virtual status_t SetParameters(const String8& aKeyValuePairs) michael@0: { michael@0: return android::NO_ERROR; michael@0: } michael@0: michael@0: virtual status_t Open(uint32_t aSampleRate, michael@0: int aChannelCount, michael@0: audio_channel_mask_t aChannelMask, michael@0: audio_format_t aFormat=AUDIO_FORMAT_PCM_16_BIT, michael@0: AudioCallback aCb = nullptr, michael@0: void* aCookie = nullptr, michael@0: audio_output_flags_t aFlags = AUDIO_OUTPUT_FLAG_NONE, michael@0: const audio_offload_info_t* aOffloadInfo = nullptr) = 0; michael@0: michael@0: virtual status_t Start() = 0; michael@0: virtual void Stop() = 0; michael@0: virtual void Flush() = 0; michael@0: virtual void Pause() = 0; michael@0: virtual void Close() = 0; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // AUDIO_SINK_H_