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.

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

mercurial