blob: 29fb241c83dde4f91194de6ee9b09f5bede84073 [file] [log] [blame]
Ray Essick20147322018-11-17 09:08:39 -08001/*
2 * Copyright (C) 2018 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#ifndef ANDROID_MEDIA_MEDIAMETRICS_H
18#define ANDROID_MEDIA_MEDIAMETRICS_H
19
20//
21// define a C interface to the media metrics functionality
22//
23// All functions that return a char * or const char * also give responsibility
24// for that string to the caller. The caller is responsible for calling free()
25// on that pointer when done using the value.
26
27__BEGIN_DECLS
28
29// internally re-cast to the behind-the-scenes C++ class instance
30typedef int64_t mediametrics_handle_t;
31typedef const char *mediametricskey_t;
32typedef const char *attr_t;
33
34mediametrics_handle_t mediametrics_create(mediametricskey_t key);
35void mediametrics_delete(mediametrics_handle_t handle);
36
37mediametricskey_t mediametrics_getKey(mediametrics_handle_t handle);
38
39
40// set
41void mediametrics_setInt32(mediametrics_handle_t handle, attr_t attr,
42 int32_t value);
43void mediametrics_setInt64(mediametrics_handle_t handle, attr_t attr,
44 int64_t value);
45void mediametrics_setDouble(mediametrics_handle_t handle, attr_t attr,
46 double value);
47void mediametrics_setRate(mediametrics_handle_t handle, attr_t attr,
48 int64_t count, int64_t duration);
49void mediametrics_setCString(mediametrics_handle_t handle, attr_t attr,
50 const char * value);
51
52// fused get/add/set; if attr wasn't there, it's a simple set.
53// these do not provide atomicity or mutual exclusion, only simpler code sequences.
54void mediametrics_addInt32(mediametrics_handle_t handle, attr_t attr,
55 int32_t value);
56void mediametrics_addInt64(mediametrics_handle_t handle, attr_t attr,
57 int64_t value);
58void mediametrics_addDouble(mediametrics_handle_t handle, attr_t attr,
59 double value);
60void mediametrics_addRate(mediametrics_handle_t handle, attr_t attr,
61 int64_t count, int64_t duration);
62
63// find & extract values
64// return indicates whether attr exists (and thus whether value filled in)
65// NULL parameter value suppresses storage of value.
66bool mediametrics_getInt32(mediametrics_handle_t handle, attr_t attr,
67 int32_t * value);
68bool mediametrics_getInt64(mediametrics_handle_t handle, attr_t attr,
69 int64_t * value);
70bool mediametrics_getDouble(mediametrics_handle_t handle, attr_t attr,
71 double *value);
72bool mediametrics_getRate(mediametrics_handle_t handle, attr_t attr,
73 int64_t * count, int64_t * duration, double *rate);
74bool mediametrics_getCString(mediametrics_handle_t handle, attr_t attr,
75 char **value);
76// to release strings returned via getCString()
77void mediametrics_freeCString(char *value);
78
79// # of attributes set within this record.
80int32_t mediametrics_count(mediametrics_handle_t handle);
81
Ray Essickbf536ac2019-08-26 11:04:28 -070082mediametrics_handle_t mediametrics_dup(mediametrics_handle_t handle);
Ray Essick20147322018-11-17 09:08:39 -080083bool mediametrics_selfRecord(mediametrics_handle_t handle);
84
85const char *mediametrics_readable(mediametrics_handle_t handle);
86void mediametrics_setUid(mediametrics_handle_t handle, uid_t uid);
87bool mediametrics_isEnabled();
88
Ray Essickba8c4842019-01-18 11:35:33 -080089// serialized copy of the attributes/values, mostly for upstream getMetrics() calls
90// caller owns the buffer allocated as part of this call.
91bool mediametrics_getAttributes(mediametrics_handle_t handle, char **buffer, size_t *length);
Ray Essick20147322018-11-17 09:08:39 -080092
93__END_DECLS
94
95#endif