blob: 04f6a20959d61ebc59e41b3af311ec06fea8c60f [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
Eric Laurente83b55d2014-11-14 10:06:21 -080021static audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
Jean-Michel Trividf813a32014-07-20 17:58:33 -070022{
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:
Jean-Michel Trividf813a32014-07-20 17:58:33 -070035 case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
Jean-Michel Trivi36867762016-12-29 12:03:28 -080036 case AUDIO_USAGE_ASSISTANT:
Jean-Michel Trividf813a32014-07-20 17:58:33 -070037 return AUDIO_STREAM_MUSIC;
Jean-Michel Trivi36867762016-12-29 12:03:28 -080038 case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY:
39 return AUDIO_STREAM_ACCESSIBILITY;
Jean-Michel Trividf813a32014-07-20 17:58:33 -070040 case AUDIO_USAGE_ASSISTANCE_SONIFICATION:
41 return AUDIO_STREAM_SYSTEM;
42 case AUDIO_USAGE_VOICE_COMMUNICATION:
43 return AUDIO_STREAM_VOICE_CALL;
44
45 case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING:
46 return AUDIO_STREAM_DTMF;
47
48 case AUDIO_USAGE_ALARM:
49 return AUDIO_STREAM_ALARM;
50 case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE:
51 return AUDIO_STREAM_RING;
52
53 case AUDIO_USAGE_NOTIFICATION:
54 case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST:
55 case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT:
56 case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED:
57 case AUDIO_USAGE_NOTIFICATION_EVENT:
58 return AUDIO_STREAM_NOTIFICATION;
59
60 case AUDIO_USAGE_UNKNOWN:
61 default:
62 return AUDIO_STREAM_MUSIC;
63 }
64}
65
Eric Laurente83b55d2014-11-14 10:06:21 -080066static void stream_type_to_audio_attributes(audio_stream_type_t streamType,
67 audio_attributes_t *attr) {
Eric Laurent275e8e92014-11-30 15:14:47 -080068 memset(attr, 0, sizeof(audio_attributes_t));
Eric Laurente83b55d2014-11-14 10:06:21 -080069
70 switch (streamType) {
71 case AUDIO_STREAM_DEFAULT:
72 case AUDIO_STREAM_MUSIC:
73 attr->content_type = AUDIO_CONTENT_TYPE_MUSIC;
74 attr->usage = AUDIO_USAGE_MEDIA;
75 break;
76 case AUDIO_STREAM_VOICE_CALL:
77 attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
78 attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION;
79 break;
80 case AUDIO_STREAM_ENFORCED_AUDIBLE:
81 attr->flags |= AUDIO_FLAG_AUDIBILITY_ENFORCED;
82 // intended fall through, attributes in common with STREAM_SYSTEM
83 case AUDIO_STREAM_SYSTEM:
84 attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
85 attr->usage = AUDIO_USAGE_ASSISTANCE_SONIFICATION;
86 break;
87 case AUDIO_STREAM_RING:
88 attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
89 attr->usage = AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE;
90 break;
91 case AUDIO_STREAM_ALARM:
92 attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
93 attr->usage = AUDIO_USAGE_ALARM;
94 break;
95 case AUDIO_STREAM_NOTIFICATION:
96 attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
97 attr->usage = AUDIO_USAGE_NOTIFICATION;
98 break;
99 case AUDIO_STREAM_BLUETOOTH_SCO:
100 attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
101 attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION;
102 attr->flags |= AUDIO_FLAG_SCO;
103 break;
104 case AUDIO_STREAM_DTMF:
105 attr->content_type = AUDIO_CONTENT_TYPE_SONIFICATION;
106 attr->usage = AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING;
107 break;
108 case AUDIO_STREAM_TTS:
109 attr->content_type = AUDIO_CONTENT_TYPE_SPEECH;
110 attr->usage = AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY;
111 break;
112 default:
113 ALOGE("invalid stream type %d when converting to attributes", streamType);
114 }
115}
116
Jean-Michel Trividf813a32014-07-20 17:58:33 -0700117#endif //AUDIO_POLICY_HELPER_H_