Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2014 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 #ifndef AUDIO_POLICY_HELPER_H_
     17 #define AUDIO_POLICY_HELPER_H_
     18 
     19 #include <system/audio.h>
     20 
     21 static audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
     22 {
     23     // flags to stream type mapping
     24     if ((attr->flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) == AUDIO_FLAG_AUDIBILITY_ENFORCED) {
     25         return AUDIO_STREAM_ENFORCED_AUDIBLE;
     26     }
     27     if ((attr->flags & AUDIO_FLAG_SCO) == AUDIO_FLAG_SCO) {
     28         return AUDIO_STREAM_BLUETOOTH_SCO;
     29     }
     30 
     31     // usage to stream type mapping
     32     switch (attr->usage) {
     33     case AUDIO_USAGE_MEDIA:
     34     case AUDIO_USAGE_GAME:
     35     case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY:
     36     case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
     37         return AUDIO_STREAM_MUSIC;
     38     case AUDIO_USAGE_ASSISTANCE_SONIFICATION:
     39         return AUDIO_STREAM_SYSTEM;
     40     case AUDIO_USAGE_VOICE_COMMUNICATION:
     41         return AUDIO_STREAM_VOICE_CALL;
     42 
     43     case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING:
     44         return AUDIO_STREAM_DTMF;
     45 
     46     case AUDIO_USAGE_ALARM:
     47         return AUDIO_STREAM_ALARM;
     48     case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE:
     49         return AUDIO_STREAM_RING;
     50 
     51     case AUDIO_USAGE_NOTIFICATION:
     52     case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST:
     53     case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT:
     54     case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED:
     55     case AUDIO_USAGE_NOTIFICATION_EVENT:
     56         return AUDIO_STREAM_NOTIFICATION;
     57 
     58     case AUDIO_USAGE_UNKNOWN:
     59     default:
     60         return AUDIO_STREAM_MUSIC;
     61     }
     62 }
     63 
     64 static void stream_type_to_audio_attributes(audio_stream_type_t streamType,
     65                                      audio_attributes_t *attr) {
     66     memset(attr, 0, sizeof(audio_attributes_t));
     67 
     68     switch (streamType) {
     69     case AUDIO_STREAM_DEFAULT:
     70     case AUDIO_STREAM_MUSIC:
     71         attr->content_type = AUDIO_CONTENT_TYPE_MUSIC;
     72         attr->usage = AUDIO_USAGE_MEDIA;
     73         break;
     74     case AUDIO_STREAM_VOICE_CALL:
     75         attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
     76         attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION;
     77         break;
     78     case AUDIO_STREAM_ENFORCED_AUDIBLE:
     79         attr->flags  |= AUDIO_FLAG_AUDIBILITY_ENFORCED;
     80         // intended fall through, attributes in common with STREAM_SYSTEM
     81     case AUDIO_STREAM_SYSTEM:
     82         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
     83         attr->usage = AUDIO_USAGE_ASSISTANCE_SONIFICATION;
     84         break;
     85     case AUDIO_STREAM_RING:
     86         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
     87         attr->usage = AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE;
     88         break;
     89     case AUDIO_STREAM_ALARM:
     90         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
     91         attr->usage = AUDIO_USAGE_ALARM;
     92         break;
     93     case AUDIO_STREAM_NOTIFICATION:
     94         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
     95         attr->usage = AUDIO_USAGE_NOTIFICATION;
     96         break;
     97     case AUDIO_STREAM_BLUETOOTH_SCO:
     98         attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
     99         attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION;
    100         attr->flags |= AUDIO_FLAG_SCO;
    101         break;
    102     case AUDIO_STREAM_DTMF:
    103         attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
    104         attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING;
    105         break;
    106     case AUDIO_STREAM_TTS:
    107         attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
    108         attr->usage = AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY;
    109         break;
    110     default:
    111         ALOGE("invalid stream type %d when converting to attributes", streamType);
    112     }
    113 }
    114 
    115 #endif //AUDIO_POLICY_HELPER_H_
    116