Home | History | Annotate | Download | only in libmedia
      1 /*
      2 **
      3 ** Copyright 2009, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #define LOG_TAG "IAudioPolicyService"
     19 #include <utils/Log.h>
     20 
     21 #include <stdint.h>
     22 #include <sys/types.h>
     23 
     24 #include <binder/Parcel.h>
     25 
     26 #include <media/IAudioPolicyService.h>
     27 
     28 #include <system/audio.h>
     29 
     30 namespace android {
     31 
     32 enum {
     33     SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
     34     GET_DEVICE_CONNECTION_STATE,
     35     SET_PHONE_STATE,
     36     SET_RINGER_MODE,
     37     SET_FORCE_USE,
     38     GET_FORCE_USE,
     39     GET_OUTPUT,
     40     START_OUTPUT,
     41     STOP_OUTPUT,
     42     RELEASE_OUTPUT,
     43     GET_INPUT,
     44     START_INPUT,
     45     STOP_INPUT,
     46     RELEASE_INPUT,
     47     INIT_STREAM_VOLUME,
     48     SET_STREAM_VOLUME,
     49     GET_STREAM_VOLUME,
     50     GET_STRATEGY_FOR_STREAM,
     51     GET_OUTPUT_FOR_EFFECT,
     52     REGISTER_EFFECT,
     53     UNREGISTER_EFFECT,
     54     IS_STREAM_ACTIVE,
     55     GET_DEVICES_FOR_STREAM,
     56     QUERY_DEFAULT_PRE_PROCESSING,
     57     SET_EFFECT_ENABLED
     58 };
     59 
     60 class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
     61 {
     62 public:
     63     BpAudioPolicyService(const sp<IBinder>& impl)
     64         : BpInterface<IAudioPolicyService>(impl)
     65     {
     66     }
     67 
     68     virtual status_t setDeviceConnectionState(
     69                                     audio_devices_t device,
     70                                     audio_policy_dev_state_t state,
     71                                     const char *device_address)
     72     {
     73         Parcel data, reply;
     74         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
     75         data.writeInt32(static_cast <uint32_t>(device));
     76         data.writeInt32(static_cast <uint32_t>(state));
     77         data.writeCString(device_address);
     78         remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
     79         return static_cast <status_t> (reply.readInt32());
     80     }
     81 
     82     virtual audio_policy_dev_state_t getDeviceConnectionState(
     83                                     audio_devices_t device,
     84                                     const char *device_address)
     85     {
     86         Parcel data, reply;
     87         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
     88         data.writeInt32(static_cast <uint32_t>(device));
     89         data.writeCString(device_address);
     90         remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
     91         return static_cast <audio_policy_dev_state_t>(reply.readInt32());
     92     }
     93 
     94     virtual status_t setPhoneState(int state)
     95     {
     96         Parcel data, reply;
     97         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
     98         data.writeInt32(state);
     99         remote()->transact(SET_PHONE_STATE, data, &reply);
    100         return static_cast <status_t> (reply.readInt32());
    101     }
    102 
    103     virtual status_t setRingerMode(uint32_t mode, uint32_t mask)
    104     {
    105         Parcel data, reply;
    106         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    107         data.writeInt32(mode);
    108         data.writeInt32(mask);
    109         remote()->transact(SET_RINGER_MODE, data, &reply);
    110         return static_cast <status_t> (reply.readInt32());
    111     }
    112 
    113     virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
    114     {
    115         Parcel data, reply;
    116         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    117         data.writeInt32(static_cast <uint32_t>(usage));
    118         data.writeInt32(static_cast <uint32_t>(config));
    119         remote()->transact(SET_FORCE_USE, data, &reply);
    120         return static_cast <status_t> (reply.readInt32());
    121     }
    122 
    123     virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
    124     {
    125         Parcel data, reply;
    126         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    127         data.writeInt32(static_cast <uint32_t>(usage));
    128         remote()->transact(GET_FORCE_USE, data, &reply);
    129         return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
    130     }
    131 
    132     virtual audio_io_handle_t getOutput(
    133                                         audio_stream_type_t stream,
    134                                         uint32_t samplingRate,
    135                                         uint32_t format,
    136                                         uint32_t channels,
    137                                         audio_policy_output_flags_t flags)
    138     {
    139         Parcel data, reply;
    140         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    141         data.writeInt32(static_cast <uint32_t>(stream));
    142         data.writeInt32(samplingRate);
    143         data.writeInt32(static_cast <uint32_t>(format));
    144         data.writeInt32(channels);
    145         data.writeInt32(static_cast <uint32_t>(flags));
    146         remote()->transact(GET_OUTPUT, data, &reply);
    147         return static_cast <audio_io_handle_t> (reply.readInt32());
    148     }
    149 
    150     virtual status_t startOutput(audio_io_handle_t output,
    151                                  audio_stream_type_t stream,
    152                                  int session)
    153     {
    154         Parcel data, reply;
    155         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    156         data.writeInt32(output);
    157         data.writeInt32(stream);
    158         data.writeInt32(session);
    159         remote()->transact(START_OUTPUT, data, &reply);
    160         return static_cast <status_t> (reply.readInt32());
    161     }
    162 
    163     virtual status_t stopOutput(audio_io_handle_t output,
    164                                 audio_stream_type_t stream,
    165                                 int session)
    166     {
    167         Parcel data, reply;
    168         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    169         data.writeInt32(output);
    170         data.writeInt32(stream);
    171         data.writeInt32(session);
    172         remote()->transact(STOP_OUTPUT, data, &reply);
    173         return static_cast <status_t> (reply.readInt32());
    174     }
    175 
    176     virtual void releaseOutput(audio_io_handle_t output)
    177     {
    178         Parcel data, reply;
    179         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    180         data.writeInt32(output);
    181         remote()->transact(RELEASE_OUTPUT, data, &reply);
    182     }
    183 
    184     virtual audio_io_handle_t getInput(
    185                                     int inputSource,
    186                                     uint32_t samplingRate,
    187                                     uint32_t format,
    188                                     uint32_t channels,
    189                                     audio_in_acoustics_t acoustics,
    190                                     int audioSession)
    191     {
    192         Parcel data, reply;
    193         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    194         data.writeInt32(inputSource);
    195         data.writeInt32(samplingRate);
    196         data.writeInt32(static_cast <uint32_t>(format));
    197         data.writeInt32(channels);
    198         data.writeInt32(static_cast <uint32_t>(acoustics));
    199         data.writeInt32(audioSession);
    200         remote()->transact(GET_INPUT, data, &reply);
    201         return static_cast <audio_io_handle_t> (reply.readInt32());
    202     }
    203 
    204     virtual status_t startInput(audio_io_handle_t input)
    205     {
    206         Parcel data, reply;
    207         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    208         data.writeInt32(input);
    209         remote()->transact(START_INPUT, data, &reply);
    210         return static_cast <status_t> (reply.readInt32());
    211     }
    212 
    213     virtual status_t stopInput(audio_io_handle_t input)
    214     {
    215         Parcel data, reply;
    216         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    217         data.writeInt32(input);
    218         remote()->transact(STOP_INPUT, data, &reply);
    219         return static_cast <status_t> (reply.readInt32());
    220     }
    221 
    222     virtual void releaseInput(audio_io_handle_t input)
    223     {
    224         Parcel data, reply;
    225         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    226         data.writeInt32(input);
    227         remote()->transact(RELEASE_INPUT, data, &reply);
    228     }
    229 
    230     virtual status_t initStreamVolume(audio_stream_type_t stream,
    231                                     int indexMin,
    232                                     int indexMax)
    233     {
    234         Parcel data, reply;
    235         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    236         data.writeInt32(static_cast <uint32_t>(stream));
    237         data.writeInt32(indexMin);
    238         data.writeInt32(indexMax);
    239         remote()->transact(INIT_STREAM_VOLUME, data, &reply);
    240         return static_cast <status_t> (reply.readInt32());
    241     }
    242 
    243     virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, int index)
    244     {
    245         Parcel data, reply;
    246         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    247         data.writeInt32(static_cast <uint32_t>(stream));
    248         data.writeInt32(index);
    249         remote()->transact(SET_STREAM_VOLUME, data, &reply);
    250         return static_cast <status_t> (reply.readInt32());
    251     }
    252 
    253     virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, int *index)
    254     {
    255         Parcel data, reply;
    256         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    257         data.writeInt32(static_cast <uint32_t>(stream));
    258         remote()->transact(GET_STREAM_VOLUME, data, &reply);
    259         int lIndex = reply.readInt32();
    260         if (index) *index = lIndex;
    261         return static_cast <status_t> (reply.readInt32());
    262     }
    263 
    264     virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
    265     {
    266         Parcel data, reply;
    267         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    268         data.writeInt32(static_cast <uint32_t>(stream));
    269         remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
    270         return reply.readInt32();
    271     }
    272 
    273     virtual uint32_t getDevicesForStream(audio_stream_type_t stream)
    274     {
    275         Parcel data, reply;
    276         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    277         data.writeInt32(static_cast <uint32_t>(stream));
    278         remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
    279         return (uint32_t) reply.readInt32();
    280     }
    281 
    282     virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc)
    283     {
    284         Parcel data, reply;
    285         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    286         data.write(desc, sizeof(effect_descriptor_t));
    287         remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
    288         return static_cast <audio_io_handle_t> (reply.readInt32());
    289     }
    290 
    291     virtual status_t registerEffect(effect_descriptor_t *desc,
    292                                         audio_io_handle_t io,
    293                                         uint32_t strategy,
    294                                         int session,
    295                                         int id)
    296     {
    297         Parcel data, reply;
    298         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    299         data.write(desc, sizeof(effect_descriptor_t));
    300         data.writeInt32(io);
    301         data.writeInt32(strategy);
    302         data.writeInt32(session);
    303         data.writeInt32(id);
    304         remote()->transact(REGISTER_EFFECT, data, &reply);
    305         return static_cast <status_t> (reply.readInt32());
    306     }
    307 
    308     virtual status_t unregisterEffect(int id)
    309     {
    310         Parcel data, reply;
    311         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    312         data.writeInt32(id);
    313         remote()->transact(UNREGISTER_EFFECT, data, &reply);
    314         return static_cast <status_t> (reply.readInt32());
    315     }
    316 
    317     virtual status_t setEffectEnabled(int id, bool enabled)
    318     {
    319         Parcel data, reply;
    320         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    321         data.writeInt32(id);
    322         data.writeInt32(enabled);
    323         remote()->transact(SET_EFFECT_ENABLED, data, &reply);
    324         return static_cast <status_t> (reply.readInt32());
    325     }
    326 
    327     virtual bool isStreamActive(int stream, uint32_t inPastMs) const
    328     {
    329         Parcel data, reply;
    330         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    331         data.writeInt32(stream);
    332         data.writeInt32(inPastMs);
    333         remote()->transact(IS_STREAM_ACTIVE, data, &reply);
    334         return reply.readInt32();
    335     }
    336 
    337     virtual status_t queryDefaultPreProcessing(int audioSession,
    338                                                effect_descriptor_t *descriptors,
    339                                                uint32_t *count)
    340     {
    341         if (descriptors == NULL || count == NULL) {
    342             return BAD_VALUE;
    343         }
    344         Parcel data, reply;
    345         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    346         data.writeInt32(audioSession);
    347         data.writeInt32(*count);
    348         status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
    349         if (status != NO_ERROR) {
    350             return status;
    351         }
    352         status = static_cast <status_t> (reply.readInt32());
    353         uint32_t retCount = reply.readInt32();
    354         if (retCount != 0) {
    355             uint32_t numDesc = (retCount < *count) ? retCount : *count;
    356             reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
    357         }
    358         *count = retCount;
    359         return status;
    360     }
    361 };
    362 
    363 IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
    364 
    365 // ----------------------------------------------------------------------
    366 
    367 
    368 status_t BnAudioPolicyService::onTransact(
    369     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
    370 {
    371     switch(code) {
    372         case SET_DEVICE_CONNECTION_STATE: {
    373             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    374             audio_devices_t device =
    375                     static_cast <audio_devices_t>(data.readInt32());
    376             audio_policy_dev_state_t state =
    377                     static_cast <audio_policy_dev_state_t>(data.readInt32());
    378             const char *device_address = data.readCString();
    379             reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
    380                                                                               state,
    381                                                                               device_address)));
    382             return NO_ERROR;
    383         } break;
    384 
    385         case GET_DEVICE_CONNECTION_STATE: {
    386             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    387             audio_devices_t device =
    388                     static_cast<audio_devices_t> (data.readInt32());
    389             const char *device_address = data.readCString();
    390             reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
    391                                                                               device_address)));
    392             return NO_ERROR;
    393         } break;
    394 
    395         case SET_PHONE_STATE: {
    396             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    397             reply->writeInt32(static_cast <uint32_t>(setPhoneState(data.readInt32())));
    398             return NO_ERROR;
    399         } break;
    400 
    401         case SET_RINGER_MODE: {
    402             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    403             uint32_t mode = data.readInt32();
    404             uint32_t mask = data.readInt32();
    405             reply->writeInt32(static_cast <uint32_t>(setRingerMode(mode, mask)));
    406             return NO_ERROR;
    407         } break;
    408 
    409         case SET_FORCE_USE: {
    410             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    411             audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(data.readInt32());
    412             audio_policy_forced_cfg_t config =
    413                     static_cast <audio_policy_forced_cfg_t>(data.readInt32());
    414             reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
    415             return NO_ERROR;
    416         } break;
    417 
    418         case GET_FORCE_USE: {
    419             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    420             audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(data.readInt32());
    421             reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
    422             return NO_ERROR;
    423         } break;
    424 
    425         case GET_OUTPUT: {
    426             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    427             audio_stream_type_t stream =
    428                     static_cast <audio_stream_type_t>(data.readInt32());
    429             uint32_t samplingRate = data.readInt32();
    430             uint32_t format = data.readInt32();
    431             uint32_t channels = data.readInt32();
    432             audio_policy_output_flags_t flags =
    433                     static_cast <audio_policy_output_flags_t>(data.readInt32());
    434 
    435             audio_io_handle_t output = getOutput(stream,
    436                                                  samplingRate,
    437                                                  format,
    438                                                  channels,
    439                                                  flags);
    440             reply->writeInt32(static_cast <int>(output));
    441             return NO_ERROR;
    442         } break;
    443 
    444         case START_OUTPUT: {
    445             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    446             audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
    447             uint32_t stream = data.readInt32();
    448             int session = data.readInt32();
    449             reply->writeInt32(static_cast <uint32_t>(startOutput(output,
    450                                                                  (audio_stream_type_t)stream,
    451                                                                  session)));
    452             return NO_ERROR;
    453         } break;
    454 
    455         case STOP_OUTPUT: {
    456             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    457             audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
    458             uint32_t stream = data.readInt32();
    459             int session = data.readInt32();
    460             reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
    461                                                                 (audio_stream_type_t)stream,
    462                                                                 session)));
    463             return NO_ERROR;
    464         } break;
    465 
    466         case RELEASE_OUTPUT: {
    467             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    468             audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
    469             releaseOutput(output);
    470             return NO_ERROR;
    471         } break;
    472 
    473         case GET_INPUT: {
    474             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    475             int inputSource = data.readInt32();
    476             uint32_t samplingRate = data.readInt32();
    477             uint32_t format = data.readInt32();
    478             uint32_t channels = data.readInt32();
    479             audio_in_acoustics_t acoustics =
    480                     static_cast <audio_in_acoustics_t>(data.readInt32());
    481             int audioSession = data.readInt32();
    482             audio_io_handle_t input = getInput(inputSource,
    483                                                samplingRate,
    484                                                format,
    485                                                channels,
    486                                                acoustics,
    487                                                audioSession);
    488             reply->writeInt32(static_cast <int>(input));
    489             return NO_ERROR;
    490         } break;
    491 
    492         case START_INPUT: {
    493             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    494             audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
    495             reply->writeInt32(static_cast <uint32_t>(startInput(input)));
    496             return NO_ERROR;
    497         } break;
    498 
    499         case STOP_INPUT: {
    500             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    501             audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
    502             reply->writeInt32(static_cast <uint32_t>(stopInput(input)));
    503             return NO_ERROR;
    504         } break;
    505 
    506         case RELEASE_INPUT: {
    507             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    508             audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
    509             releaseInput(input);
    510             return NO_ERROR;
    511         } break;
    512 
    513         case INIT_STREAM_VOLUME: {
    514             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    515             audio_stream_type_t stream =
    516                     static_cast <audio_stream_type_t>(data.readInt32());
    517             int indexMin = data.readInt32();
    518             int indexMax = data.readInt32();
    519             reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
    520             return NO_ERROR;
    521         } break;
    522 
    523         case SET_STREAM_VOLUME: {
    524             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    525             audio_stream_type_t stream =
    526                     static_cast <audio_stream_type_t>(data.readInt32());
    527             int index = data.readInt32();
    528             reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream, index)));
    529             return NO_ERROR;
    530         } break;
    531 
    532         case GET_STREAM_VOLUME: {
    533             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    534             audio_stream_type_t stream =
    535                     static_cast <audio_stream_type_t>(data.readInt32());
    536             int index;
    537             status_t status = getStreamVolumeIndex(stream, &index);
    538             reply->writeInt32(index);
    539             reply->writeInt32(static_cast <uint32_t>(status));
    540             return NO_ERROR;
    541         } break;
    542 
    543         case GET_STRATEGY_FOR_STREAM: {
    544             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    545             audio_stream_type_t stream =
    546                     static_cast <audio_stream_type_t>(data.readInt32());
    547             reply->writeInt32(getStrategyForStream(stream));
    548             return NO_ERROR;
    549         } break;
    550 
    551         case GET_DEVICES_FOR_STREAM: {
    552             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    553             audio_stream_type_t stream =
    554                     static_cast <audio_stream_type_t>(data.readInt32());
    555             reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
    556             return NO_ERROR;
    557         } break;
    558 
    559         case GET_OUTPUT_FOR_EFFECT: {
    560             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    561             effect_descriptor_t desc;
    562             data.read(&desc, sizeof(effect_descriptor_t));
    563             audio_io_handle_t output = getOutputForEffect(&desc);
    564             reply->writeInt32(static_cast <int>(output));
    565             return NO_ERROR;
    566         } break;
    567 
    568         case REGISTER_EFFECT: {
    569             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    570             effect_descriptor_t desc;
    571             data.read(&desc, sizeof(effect_descriptor_t));
    572             audio_io_handle_t io = data.readInt32();
    573             uint32_t strategy = data.readInt32();
    574             int session = data.readInt32();
    575             int id = data.readInt32();
    576             reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
    577                                                                    io,
    578                                                                    strategy,
    579                                                                    session,
    580                                                                    id)));
    581             return NO_ERROR;
    582         } break;
    583 
    584         case UNREGISTER_EFFECT: {
    585             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    586             int id = data.readInt32();
    587             reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
    588             return NO_ERROR;
    589         } break;
    590 
    591         case SET_EFFECT_ENABLED: {
    592             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    593             int id = data.readInt32();
    594             bool enabled = static_cast <bool>(data.readInt32());
    595             reply->writeInt32(static_cast <int32_t>(setEffectEnabled(id, enabled)));
    596             return NO_ERROR;
    597         } break;
    598 
    599         case IS_STREAM_ACTIVE: {
    600             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    601             int stream = data.readInt32();
    602             uint32_t inPastMs = (uint32_t)data.readInt32();
    603             reply->writeInt32( isStreamActive(stream, inPastMs) );
    604             return NO_ERROR;
    605         } break;
    606 
    607         case QUERY_DEFAULT_PRE_PROCESSING: {
    608             CHECK_INTERFACE(IAudioPolicyService, data, reply);
    609             int audioSession = data.readInt32();
    610             uint32_t count = data.readInt32();
    611             uint32_t retCount = count;
    612             effect_descriptor_t *descriptors =
    613                     (effect_descriptor_t *)new char[count * sizeof(effect_descriptor_t)];
    614             status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
    615             reply->writeInt32(status);
    616             if (status != NO_ERROR && status != NO_MEMORY) {
    617                 retCount = 0;
    618             }
    619             reply->writeInt32(retCount);
    620             if (retCount) {
    621                 if (retCount < count) {
    622                     count = retCount;
    623                 }
    624                 reply->write(descriptors, sizeof(effect_descriptor_t) * count);
    625             }
    626             delete[] descriptors;
    627             return status;
    628         }
    629 
    630         default:
    631             return BBinder::onTransact(code, data, reply, flags);
    632     }
    633 }
    634 
    635 // ----------------------------------------------------------------------------
    636 
    637 }; // namespace android
    638