• 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 
33 // Enumeration for the device connection results.
34 enum DeviceConnectionResult : int32_t {
35     DEVICE_CONNECTION_RESULT_SUCCESS = 0,              // Audio delivered
36     DEVICE_CONNECTION_RESULT_UNKNOWN = 1,              // Success is unknown.
37     DEVICE_CONNECTION_RESULT_JAVA_SERVICE_CANCEL = 2,  // Canceled in Java service
38     // Do not modify the constants above after R.  Adding new constants is fine.
39 };
40 
41 // Enumeration for all the string translations to integers (generally int32_t) unless noted.
42 enum AudioEnumCategory {
43     AAUDIO_DIRECTION,
44     AAUDIO_PERFORMANCE_MODE,
45     AAUDIO_SHARING_MODE,
46     CALLER_NAME,
47     CONTENT_TYPE,
48     ENCODING,
49     INPUT_DEVICE,  // int64_t
50     INPUT_FLAG,
51     OUTPUT_DEVICE, // int64_t
52     OUTPUT_FLAG,
53     SOURCE_TYPE,
54     STREAM_TYPE,
55     THREAD_TYPE,
56     TRACK_TRAITS,
57     USAGE,
58 };
59 
60 // Convert a string (or arbitrary S) from an AudioEnumCategory to a particular type.
61 // This is used to convert log std::strings back to the original type (int32_t or int64_t).
62 //
63 // For a string, generally there is a prefix "AUDIO_INPUT_FLAG" or some such that could
64 // actually indicate the category so the AudioEnumCategory could be superfluous, but
65 // we use it to find the proper default value in case of an unknown string.
66 //
67 // lookup<ENCODING, int32_t>("AUDIO_FORMAT_PCM_16_BIT") -> 1
68 //
69 template <AudioEnumCategory C, typename T, typename S>
70 T lookup(const S &str);
71 
72 // Helper: Allow using a const char * in lieu of std::string.
73 template <AudioEnumCategory C, typename T>
lookup(const char * str)74 T lookup(const char *str) {
75     return lookup<C, T, std::string>(str);
76 }
77 
78 bool isInputThreadType(const std::string &threadType);
79 
80 } // namespace android::mediametrics::types
81