1 /* 2 * Copyright 2023 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 MMC_METRICS_MMC_RTT_LOGGER_H_ 18 #define MMC_METRICS_MMC_RTT_LOGGER_H_ 19 20 #include <cstdint> 21 #include <string> 22 23 namespace mmc { 24 25 // MmcRttLogger computes and uploads below rtt stats: 26 // Maximum rtt, mean rtt, num requests, codec type. 27 class MmcRttLogger { 28 public: 29 explicit MmcRttLogger(int codec_type); 30 ~MmcRttLogger(); 31 32 // MmcRttLogger is neither copyable nor movable. 33 MmcRttLogger(const MmcRttLogger&) = delete; 34 MmcRttLogger& operator=(const MmcRttLogger&) = delete; 35 36 // Records elapsed_time (in microseconds). 37 // Elapsed time should be positive, otherwise it won't be recorded. 38 void RecordRtt(int64_t elapsed_time); 39 40 // Computes transcode rtt statics, uploads record via bluetooth metrics api, 41 // and clears the record. Empty record will be ignored. 42 void UploadTranscodeRttStatics(); 43 44 private: 45 int codec_type_; 46 int64_t num_requests_; 47 double rtt_sum_; // for computing mean rtt 48 int64_t maximum_rtt_; 49 }; 50 51 } // namespace mmc 52 53 #endif // MMC_METRICS_MMC_RTT_LOGGER_H_ 54