blob: f4afd4508c270b6a91d76a2e1eb9a689e5a7c481 [file] [log] [blame]
Jean-Michel Trividf813a32014-07-20 17:58:33 -07001/*
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
21audio_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#endif //AUDIO_POLICY_HELPER_H_