1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/omx/AudioOutput.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* 1.7 + * Copyright (c) 2014 The Linux Foundation. All rights reserved. 1.8 + * Copyright (C) 2008 The Android Open Source Project 1.9 + * 1.10 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.11 + * you may not use this file except in compliance with the License. 1.12 + * You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, software 1.17 + * distributed under the License is distributed on an "AS IS" BASIS, 1.18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.19 + * See the License for the specific language governing permissions and 1.20 + * limitations under the License. 1.21 + */ 1.22 + 1.23 +#ifndef AUDIOOUTPUT_H_ 1.24 +#define AUDIOOUTPUT_H_ 1.25 + 1.26 +#include <stagefright/foundation/ABase.h> 1.27 +#include <utils/Mutex.h> 1.28 +#include <AudioTrack.h> 1.29 + 1.30 +#include "AudioSink.h" 1.31 + 1.32 +#define LOG_TAG "AudioOffloadPlayer" 1.33 + 1.34 +namespace mozilla { 1.35 + 1.36 +/** 1.37 + * Stripped version of Android KK MediaPlayerService::AudioOutput class 1.38 + * Android MediaPlayer uses AudioOutput as a wrapper to handle 1.39 + * Android::AudioTrack 1.40 + * Similarly to ease handling offloaded tracks, part of AudioOutput is used here 1.41 + */ 1.42 +class AudioOutput : public AudioSink 1.43 +{ 1.44 + typedef android::Mutex Mutex; 1.45 + typedef android::String8 String8; 1.46 + typedef android::status_t status_t; 1.47 + typedef android::AudioTrack AudioTrack; 1.48 + 1.49 + class CallbackData; 1.50 + 1.51 +public: 1.52 + AudioOutput(int aSessionId, int aUid); 1.53 + virtual ~AudioOutput(); 1.54 + 1.55 + virtual ssize_t FrameSize() const; 1.56 + virtual status_t GetPosition(uint32_t* aPosition) const; 1.57 + virtual status_t SetVolume(float aVolume) const; 1.58 + virtual status_t SetParameters(const String8& aKeyValuePairs); 1.59 + 1.60 + // Creates an offloaded audio track with the given parameters 1.61 + // TODO: Try to recycle audio tracks instead of creating new audio tracks 1.62 + // every time 1.63 + virtual status_t Open(uint32_t aSampleRate, 1.64 + int aChannelCount, 1.65 + audio_channel_mask_t aChannelMask, 1.66 + audio_format_t aFormat, 1.67 + AudioCallback aCb, 1.68 + void* aCookie, 1.69 + audio_output_flags_t aFlags = AUDIO_OUTPUT_FLAG_NONE, 1.70 + const audio_offload_info_t* aOffloadInfo = nullptr); 1.71 + 1.72 + virtual status_t Start(); 1.73 + virtual void Stop(); 1.74 + virtual void Flush(); 1.75 + virtual void Pause(); 1.76 + virtual void Close(); 1.77 + 1.78 +private: 1.79 + static void CallbackWrapper(int aEvent, void* aMe, void* aInfo); 1.80 + 1.81 + android::sp<AudioTrack> mTrack; 1.82 + void* mCallbackCookie; 1.83 + AudioCallback mCallback; 1.84 + CallbackData* mCallbackData; 1.85 + 1.86 + // Uid of the current process, need to create audio track 1.87 + int mUid; 1.88 + 1.89 + // Session id given by Android::AudioSystem and used to create audio track 1.90 + int mSessionId; 1.91 + 1.92 + // CallbackData is what is passed to the AudioTrack as the "user" data. 1.93 + // We need to be able to target this to a different Output on the fly, 1.94 + // so we can't use the Output itself for this. 1.95 + class CallbackData 1.96 + { 1.97 + public: 1.98 + CallbackData(AudioOutput* aCookie) 1.99 + { 1.100 + mData = aCookie; 1.101 + } 1.102 + AudioOutput* GetOutput() { return mData;} 1.103 + void SetOutput(AudioOutput* aNewcookie) { mData = aNewcookie; } 1.104 + // Lock/Unlock are used by the callback before accessing the payload of 1.105 + // this object 1.106 + void Lock() { mLock.lock(); } 1.107 + void Unlock() { mLock.unlock(); } 1.108 + private: 1.109 + AudioOutput* mData; 1.110 + mutable Mutex mLock; 1.111 + DISALLOW_EVIL_CONSTRUCTORS(CallbackData); 1.112 + }; 1.113 +}; // AudioOutput 1.114 + 1.115 +} // namespace mozilla 1.116 + 1.117 +#endif /* AUDIOOUTPUT_H_ */