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