content/media/omx/AudioOutput.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /*
michael@0 4 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
michael@0 5 * Copyright (C) 2008 The Android Open Source Project
michael@0 6 *
michael@0 7 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 8 * you may not use this file except in compliance with the License.
michael@0 9 * You may obtain a copy of the License at
michael@0 10 *
michael@0 11 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 12 *
michael@0 13 * Unless required by applicable law or agreed to in writing, software
michael@0 14 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 16 * See the License for the specific language governing permissions and
michael@0 17 * limitations under the License.
michael@0 18 */
michael@0 19
michael@0 20 #ifndef AUDIOOUTPUT_H_
michael@0 21 #define AUDIOOUTPUT_H_
michael@0 22
michael@0 23 #include <stagefright/foundation/ABase.h>
michael@0 24 #include <utils/Mutex.h>
michael@0 25 #include <AudioTrack.h>
michael@0 26
michael@0 27 #include "AudioSink.h"
michael@0 28
michael@0 29 #define LOG_TAG "AudioOffloadPlayer"
michael@0 30
michael@0 31 namespace mozilla {
michael@0 32
michael@0 33 /**
michael@0 34 * Stripped version of Android KK MediaPlayerService::AudioOutput class
michael@0 35 * Android MediaPlayer uses AudioOutput as a wrapper to handle
michael@0 36 * Android::AudioTrack
michael@0 37 * Similarly to ease handling offloaded tracks, part of AudioOutput is used here
michael@0 38 */
michael@0 39 class AudioOutput : public AudioSink
michael@0 40 {
michael@0 41 typedef android::Mutex Mutex;
michael@0 42 typedef android::String8 String8;
michael@0 43 typedef android::status_t status_t;
michael@0 44 typedef android::AudioTrack AudioTrack;
michael@0 45
michael@0 46 class CallbackData;
michael@0 47
michael@0 48 public:
michael@0 49 AudioOutput(int aSessionId, int aUid);
michael@0 50 virtual ~AudioOutput();
michael@0 51
michael@0 52 virtual ssize_t FrameSize() const;
michael@0 53 virtual status_t GetPosition(uint32_t* aPosition) const;
michael@0 54 virtual status_t SetVolume(float aVolume) const;
michael@0 55 virtual status_t SetParameters(const String8& aKeyValuePairs);
michael@0 56
michael@0 57 // Creates an offloaded audio track with the given parameters
michael@0 58 // TODO: Try to recycle audio tracks instead of creating new audio tracks
michael@0 59 // every time
michael@0 60 virtual status_t Open(uint32_t aSampleRate,
michael@0 61 int aChannelCount,
michael@0 62 audio_channel_mask_t aChannelMask,
michael@0 63 audio_format_t aFormat,
michael@0 64 AudioCallback aCb,
michael@0 65 void* aCookie,
michael@0 66 audio_output_flags_t aFlags = AUDIO_OUTPUT_FLAG_NONE,
michael@0 67 const audio_offload_info_t* aOffloadInfo = nullptr);
michael@0 68
michael@0 69 virtual status_t Start();
michael@0 70 virtual void Stop();
michael@0 71 virtual void Flush();
michael@0 72 virtual void Pause();
michael@0 73 virtual void Close();
michael@0 74
michael@0 75 private:
michael@0 76 static void CallbackWrapper(int aEvent, void* aMe, void* aInfo);
michael@0 77
michael@0 78 android::sp<AudioTrack> mTrack;
michael@0 79 void* mCallbackCookie;
michael@0 80 AudioCallback mCallback;
michael@0 81 CallbackData* mCallbackData;
michael@0 82
michael@0 83 // Uid of the current process, need to create audio track
michael@0 84 int mUid;
michael@0 85
michael@0 86 // Session id given by Android::AudioSystem and used to create audio track
michael@0 87 int mSessionId;
michael@0 88
michael@0 89 // CallbackData is what is passed to the AudioTrack as the "user" data.
michael@0 90 // We need to be able to target this to a different Output on the fly,
michael@0 91 // so we can't use the Output itself for this.
michael@0 92 class CallbackData
michael@0 93 {
michael@0 94 public:
michael@0 95 CallbackData(AudioOutput* aCookie)
michael@0 96 {
michael@0 97 mData = aCookie;
michael@0 98 }
michael@0 99 AudioOutput* GetOutput() { return mData;}
michael@0 100 void SetOutput(AudioOutput* aNewcookie) { mData = aNewcookie; }
michael@0 101 // Lock/Unlock are used by the callback before accessing the payload of
michael@0 102 // this object
michael@0 103 void Lock() { mLock.lock(); }
michael@0 104 void Unlock() { mLock.unlock(); }
michael@0 105 private:
michael@0 106 AudioOutput* mData;
michael@0 107 mutable Mutex mLock;
michael@0 108 DISALLOW_EVIL_CONSTRUCTORS(CallbackData);
michael@0 109 };
michael@0 110 }; // AudioOutput
michael@0 111
michael@0 112 } // namespace mozilla
michael@0 113
michael@0 114 #endif /* AUDIOOUTPUT_H_ */

mercurial