Home | History | Annotate | Download | only in mediaanalytics
      1 /*
      2  * Copyright (C) 2017 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 
     18 #ifndef ANDROID_METRICSSUMMARIZER_H
     19 #define ANDROID_METRICSSUMMARIZER_H
     20 
     21 #include <utils/threads.h>
     22 #include <utils/Errors.h>
     23 #include <utils/KeyedVector.h>
     24 #include <utils/String8.h>
     25 #include <utils/List.h>
     26 
     27 #include <media/IMediaAnalyticsService.h>
     28 
     29 
     30 namespace android {
     31 
     32 class MetricsSummarizer
     33 {
     34 
     35  public:
     36 
     37     MetricsSummarizer(const char *key);
     38     virtual ~MetricsSummarizer();
     39 
     40     // show the key
     41     const char * getKey();
     42 
     43     // should the record be given to this summarizer
     44     bool isMine(MediaAnalyticsItem &item);
     45 
     46     // hand the record to this summarizer
     47     void handleRecord(MediaAnalyticsItem *item);
     48 
     49     virtual void mergeRecord(MediaAnalyticsItem &have, MediaAnalyticsItem &incoming);
     50 
     51     // dump the summarized records (for dumpsys)
     52     AString dumpSummary(int &slot);
     53     AString dumpSummary(int &slot, const char *only);
     54 
     55     void setIgnorables(const char **);
     56     const char **getIgnorables();
     57 
     58  protected:
     59 
     60     // various comparators
     61     // "do these records have same attributes and values in those attrs"
     62     bool sameAttributes(MediaAnalyticsItem *summ, MediaAnalyticsItem *single, const char **ignoreables);
     63 
     64     void minMaxVar64(MediaAnalyticsItem &summ, const char *key, int64_t value);
     65 
     66     static int PropSorter(const void *a, const void *b);
     67     void sortProps(MediaAnalyticsItem *item);
     68 
     69  private:
     70     const char *mKey;
     71     const char **mIgnorables;
     72     List<MediaAnalyticsItem *> *mSummaries;
     73 
     74 
     75 };
     76 
     77 // ----------------------------------------------------------------------------
     78 
     79 }; // namespace android
     80 
     81 #endif // ANDROID_METRICSSUMMARIZER_H
     82