• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 #pragma once
18 
19 #include <string>
20 #include <unordered_map>
21 
22 namespace android::mediametrics::types {
23 
24 // Helper methods that map mediametrics logged strings to integer codes.
25 // In R we do not use the integer codes, but rather we can use these maps
26 // to validate correct strings.
27 const std::unordered_map<std::string, int32_t>& getAudioCallerNameMap();
28 const std::unordered_map<std::string, int64_t>& getAudioDeviceInMap();
29 const std::unordered_map<std::string, int64_t>& getAudioDeviceOutMap();
30 const std::unordered_map<std::string, int32_t>& getAudioThreadTypeMap();
31 const std::unordered_map<std::string, int32_t>& getAudioTrackTraitsMap();
32 const std::unordered_map<std::string, int32_t>& getHeadTrackingModeMap();
33 const std::unordered_map<std::string, int32_t>& getSpatializerLevelMap();
34 const std::unordered_map<std::string, int32_t>& getSpatializerModeMap();
35 
36 std::vector<int32_t> vectorFromMap(
37         const std::string &str, const std::unordered_map<std::string, int32_t>& map);
38 
39 std::vector<int64_t> channelMaskVectorFromString(const std::string &s);
40 
41 // Enumeration for the device connection results.
42 enum DeviceConnectionResult : int32_t {
43     DEVICE_CONNECTION_RESULT_SUCCESS = 0,              // Audio delivered
44     DEVICE_CONNECTION_RESULT_UNKNOWN = 1,              // Success is unknown.
45     DEVICE_CONNECTION_RESULT_JAVA_SERVICE_CANCEL = 2,  // Canceled in Java service
46     // Do not modify the constants above after R.  Adding new constants is fine.
47 };
48 
49 // Enumeration for all the string translations to integers (generally int32_t) unless noted.
50 // This is used to index the template method below:
51 // template <AudioEnumCategory C, typename T, typename S>  T lookup(const S &str);
52 //
53 // Okay to keep AudioEnumCategory alphabetical and add new translations in the middle.
54 enum AudioEnumCategory {
55     AAUDIO_DIRECTION,
56     AAUDIO_PERFORMANCE_MODE,
57     AAUDIO_SHARING_MODE,
58     AUDIO_DEVICE_INFO_TYPE,
59     CALLER_NAME,
60     CONTENT_TYPE,
61     ENCODING,
62     HEAD_TRACKING_MODE,
63     INPUT_DEVICE,  // int64_t
64     INPUT_FLAG,
65     OUTPUT_DEVICE, // int64_t
66     OUTPUT_FLAG,
67     SOURCE_TYPE,
68     SPATIALIZER_LEVEL,
69     SPATIALIZER_MODE,
70     STATUS,
71     STREAM_TYPE,
72     THREAD_TYPE,
73     TRACK_TRAITS,
74     USAGE,
75 };
76 
77 // Convert a string (or arbitrary S) from an AudioEnumCategory to a particular type.
78 // This is used to convert log std::strings back to the original type (int32_t or int64_t).
79 //
80 // For a string, generally there is a prefix "AUDIO_INPUT_FLAG" or some such that could
81 // actually indicate the category so the AudioEnumCategory could be superfluous, but
82 // we use it to find the proper default value in case of an unknown string.
83 //
84 // lookup<ENCODING, int32_t>("AUDIO_FORMAT_PCM_16_BIT") -> 1
85 //
86 template <AudioEnumCategory C, typename T, typename S>
87 T lookup(const S &str);
88 
89 // Helper: Allow using a const char * in lieu of std::string.
90 template <AudioEnumCategory C, typename T>
lookup(const char * str)91 T lookup(const char *str) {
92     return lookup<C, T, std::string>(str);
93 }
94 
95 bool isInputThreadType(const std::string &threadType);
96 
97 } // namespace android::mediametrics::types
98