Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2017 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_PLAYER_BASE_H__
     18 #define __ANDROID_PLAYER_BASE_H__
     19 
     20 #include <audiomanager/AudioManager.h>
     21 #include <audiomanager/IAudioManager.h>
     22 
     23 #include "android/media/BnPlayer.h"
     24 
     25 namespace android {
     26 
     27 class PlayerBase : public ::android::media::BnPlayer
     28 {
     29 public:
     30     explicit PlayerBase();
     31     virtual ~PlayerBase() override;
     32 
     33     virtual void destroy() = 0;
     34 
     35     //IPlayer implementation
     36     virtual binder::Status start() override;
     37     virtual binder::Status pause() override;
     38     virtual binder::Status stop() override;
     39     virtual binder::Status setVolume(float vol) override;
     40     virtual binder::Status setPan(float pan) override;
     41     virtual binder::Status setStartDelayMs(int32_t delayMs) override;
     42     virtual binder::Status applyVolumeShaper(
     43             const media::VolumeShaper::Configuration& configuration,
     44             const media::VolumeShaper::Operation& operation) override;
     45 
     46             status_t startWithStatus();
     47             status_t pauseWithStatus();
     48             status_t stopWithStatus();
     49 
     50             //FIXME temporary method while some player state is outside of this class
     51             void reportEvent(player_state_t event);
     52 
     53 protected:
     54 
     55             void init(player_type_t playerType, audio_usage_t usage);
     56             void baseDestroy();
     57 
     58     //IPlayer methods handlers for derived classes
     59     virtual status_t playerStart()  { return NO_ERROR; }
     60     virtual status_t playerPause()  { return NO_ERROR; }
     61     virtual status_t playerStop()  { return NO_ERROR; }
     62     virtual status_t playerSetVolume()  { return NO_ERROR; }
     63 
     64     // mutex for IPlayer volume and pan, and player-specific volume
     65     Mutex mSettingsLock;
     66 
     67     // volume multipliers coming from the IPlayer volume and pan controls
     68     float mPanMultiplierL, mPanMultiplierR;
     69     float mVolumeMultiplierL, mVolumeMultiplierR;
     70 
     71 private:
     72             // report events to AudioService
     73             void servicePlayerEvent(player_state_t event);
     74             void serviceReleasePlayer();
     75 
     76     // native interface to AudioService
     77     android::sp<android::IAudioManager> mAudioManager;
     78 
     79     // player interface ID, uniquely identifies the player in the system
     80     audio_unique_id_t mPIId;
     81 
     82     // Mutex for state reporting
     83     Mutex mPlayerStateLock;
     84     player_state_t mLastReportedEvent;
     85 };
     86 
     87 } // namespace android
     88 
     89 #endif /* __ANDROID_PLAYER_BASE_H__ */
     90