Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 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 | /** |
| 18 | * Native media transcoder library benchmark tests. |
| 19 | * |
| 20 | * How to run the benchmark: |
| 21 | * |
| 22 | * 1. Download the media assets from http://go/transcodingbenchmark and push the directory |
| 23 | * ("TranscodingBenchmark") to /data/local/tmp. |
| 24 | * |
| 25 | * 2. Compile the benchmark and sync to device: |
| 26 | * $ mm -j72 && adb sync |
| 27 | * |
| 28 | * 3. Run: |
| 29 | * $ adb shell /data/nativetest64/MediaTranscoderBenchmark/MediaTranscoderBenchmark |
| 30 | */ |
| 31 | |
| 32 | #include <benchmark/benchmark.h> |
Naveen Kumar Ponnusamy | 2d074ba | 2020-12-17 17:13:45 -0800 | [diff] [blame] | 33 | #include <binder/ProcessState.h> |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 34 | #include <fcntl.h> |
| 35 | #include <media/MediaTranscoder.h> |
Linus Nilsson | 4aef0de | 2021-01-29 17:58:55 -0800 | [diff] [blame^] | 36 | #include <media/NdkCommon.h> |
Linus Nilsson | 4735241 | 2020-12-16 12:21:26 -0800 | [diff] [blame] | 37 | |
Naveen Kumar Ponnusamy | 8b8e700 | 2020-12-02 12:01:32 +0530 | [diff] [blame] | 38 | #include <iostream> |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 39 | |
| 40 | using namespace android; |
| 41 | |
Naveen Kumar Ponnusamy | 8b8e700 | 2020-12-02 12:01:32 +0530 | [diff] [blame] | 42 | const std::string PARAM_VIDEO_FRAME_RATE = "VideoFrameRate"; |
| 43 | |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 44 | class TranscoderCallbacks : public MediaTranscoder::CallbackInterface { |
| 45 | public: |
| 46 | virtual void onFinished(const MediaTranscoder* transcoder __unused) override { |
| 47 | std::unique_lock<std::mutex> lock(mMutex); |
| 48 | mFinished = true; |
| 49 | mCondition.notify_all(); |
| 50 | } |
| 51 | |
| 52 | virtual void onError(const MediaTranscoder* transcoder __unused, |
| 53 | media_status_t error) override { |
| 54 | std::unique_lock<std::mutex> lock(mMutex); |
| 55 | mFinished = true; |
| 56 | mStatus = error; |
| 57 | mCondition.notify_all(); |
| 58 | } |
| 59 | |
| 60 | virtual void onProgressUpdate(const MediaTranscoder* transcoder __unused, |
| 61 | int32_t progress __unused) override {} |
| 62 | |
| 63 | virtual void onCodecResourceLost(const MediaTranscoder* transcoder __unused, |
Chong Zhang | e4e088f | 2020-10-21 19:10:42 -0700 | [diff] [blame] | 64 | const std::shared_ptr<ndk::ScopedAParcel>& pausedState |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 65 | __unused) override {} |
| 66 | |
| 67 | bool waitForTranscodingFinished() { |
| 68 | std::unique_lock<std::mutex> lock(mMutex); |
| 69 | while (!mFinished) { |
| 70 | if (mCondition.wait_for(lock, std::chrono::minutes(5)) == std::cv_status::timeout) { |
| 71 | return false; |
| 72 | } |
| 73 | } |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | media_status_t mStatus = AMEDIA_OK; |
| 78 | |
| 79 | private: |
| 80 | std::mutex mMutex; |
| 81 | std::condition_variable mCondition; |
| 82 | bool mFinished = false; |
| 83 | }; |
| 84 | |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 85 | static AMediaFormat* CreateDefaultVideoFormat() { |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 86 | // Default bitrate |
| 87 | static constexpr int32_t kVideoBitRate = 20 * 1000 * 1000; // 20Mbs |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 88 | |
| 89 | AMediaFormat* videoFormat = AMediaFormat_new(); |
| 90 | AMediaFormat_setInt32(videoFormat, AMEDIAFORMAT_KEY_BIT_RATE, kVideoBitRate); |
Linus Nilsson | 4aef0de | 2021-01-29 17:58:55 -0800 | [diff] [blame^] | 91 | AMediaFormat_setString(videoFormat, AMEDIAFORMAT_KEY_MIME, AMEDIA_MIMETYPE_VIDEO_AVC); |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 92 | return videoFormat; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Callback to configure tracks for transcoding. |
| 97 | * @param mime The source track mime type. |
| 98 | * @param dstFormat The destination format if the track should be transcoded or nullptr if the track |
| 99 | * should be passed through. |
| 100 | * @return True if the track should be included in the output file. |
| 101 | */ |
| 102 | using TrackSelectionCallback = std::function<bool(const char* mime, AMediaFormat** dstFormat)>; |
| 103 | |
| 104 | static void TranscodeMediaFile(benchmark::State& state, const std::string& srcFileName, |
| 105 | const std::string& dstFileName, |
| 106 | TrackSelectionCallback trackSelectionCallback) { |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 107 | // Write-only, create file if non-existent. |
| 108 | static constexpr int kDstOpenFlags = O_WRONLY | O_CREAT; |
| 109 | // User R+W permission. |
| 110 | static constexpr int kDstFileMode = S_IRUSR | S_IWUSR; |
| 111 | // Asset directory |
| 112 | static const std::string kAssetDirectory = "/data/local/tmp/TranscodingBenchmark/"; |
| 113 | |
| 114 | int srcFd = 0; |
| 115 | int dstFd = 0; |
| 116 | |
| 117 | std::string srcPath = kAssetDirectory + srcFileName; |
| 118 | std::string dstPath = kAssetDirectory + dstFileName; |
| 119 | |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 120 | media_status_t status = AMEDIA_OK; |
| 121 | |
| 122 | if ((srcFd = open(srcPath.c_str(), O_RDONLY)) < 0) { |
| 123 | state.SkipWithError("Unable to open source file"); |
| 124 | goto exit; |
| 125 | } |
| 126 | if ((dstFd = open(dstPath.c_str(), kDstOpenFlags, kDstFileMode)) < 0) { |
| 127 | state.SkipWithError("Unable to open destination file"); |
| 128 | goto exit; |
| 129 | } |
| 130 | |
| 131 | for (auto _ : state) { |
Naveen Kumar Ponnusamy | 78d362a | 2020-12-16 18:10:47 -0800 | [diff] [blame] | 132 | auto callbacks = std::make_shared<TranscoderCallbacks>(); |
Chong Zhang | bbb4eac | 2020-11-18 11:12:06 -0800 | [diff] [blame] | 133 | auto transcoder = MediaTranscoder::create(callbacks); |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 134 | |
| 135 | status = transcoder->configureSource(srcFd); |
| 136 | if (status != AMEDIA_OK) { |
| 137 | state.SkipWithError("Unable to configure transcoder source"); |
| 138 | goto exit; |
| 139 | } |
| 140 | |
| 141 | status = transcoder->configureDestination(dstFd); |
| 142 | if (status != AMEDIA_OK) { |
| 143 | state.SkipWithError("Unable to configure transcoder destination"); |
| 144 | goto exit; |
| 145 | } |
| 146 | |
| 147 | std::vector<std::shared_ptr<AMediaFormat>> trackFormats = transcoder->getTrackFormats(); |
| 148 | for (int i = 0; i < trackFormats.size(); ++i) { |
| 149 | AMediaFormat* srcFormat = trackFormats[i].get(); |
| 150 | AMediaFormat* dstFormat = nullptr; |
| 151 | |
| 152 | const char* mime = nullptr; |
| 153 | if (!AMediaFormat_getString(srcFormat, AMEDIAFORMAT_KEY_MIME, &mime)) { |
| 154 | state.SkipWithError("Source track format does not have MIME type"); |
| 155 | goto exit; |
| 156 | } |
| 157 | |
| 158 | if (strncmp(mime, "video/", 6) == 0) { |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 159 | int32_t frameCount; |
| 160 | if (AMediaFormat_getInt32(srcFormat, AMEDIAFORMAT_KEY_FRAME_COUNT, &frameCount)) { |
Naveen Kumar Ponnusamy | 0dbe871 | 2020-12-16 23:31:38 -0800 | [diff] [blame] | 161 | state.counters[PARAM_VIDEO_FRAME_RATE] = benchmark::Counter( |
| 162 | frameCount, benchmark::Counter::kIsIterationInvariantRate); |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 163 | } |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 166 | if (trackSelectionCallback(mime, &dstFormat)) { |
| 167 | status = transcoder->configureTrackFormat(i, dstFormat); |
| 168 | } |
| 169 | |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 170 | if (dstFormat != nullptr) { |
| 171 | AMediaFormat_delete(dstFormat); |
| 172 | } |
| 173 | if (status != AMEDIA_OK) { |
| 174 | state.SkipWithError("Unable to configure track"); |
| 175 | goto exit; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | status = transcoder->start(); |
| 180 | if (status != AMEDIA_OK) { |
| 181 | state.SkipWithError("Unable to start transcoder"); |
| 182 | goto exit; |
| 183 | } |
| 184 | |
| 185 | if (!callbacks->waitForTranscodingFinished()) { |
Linus Nilsson | b09aac2 | 2020-07-29 11:56:53 -0700 | [diff] [blame] | 186 | transcoder->cancel(); |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 187 | state.SkipWithError("Transcoder timed out"); |
| 188 | goto exit; |
| 189 | } |
| 190 | if (callbacks->mStatus != AMEDIA_OK) { |
| 191 | state.SkipWithError("Transcoder error when running"); |
| 192 | goto exit; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | exit: |
| 197 | if (srcFd > 0) close(srcFd); |
| 198 | if (dstFd > 0) close(dstFd); |
| 199 | } |
| 200 | |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 201 | /** |
| 202 | * Callback to edit track format for transcoding. |
| 203 | * @param dstFormat The default track format for the track type. |
| 204 | */ |
| 205 | using TrackFormatEditCallback = std::function<void(AMediaFormat* dstFormat)>; |
| 206 | |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 207 | static void TranscodeMediaFile(benchmark::State& state, const std::string& srcFileName, |
| 208 | const std::string& dstFileName, bool includeAudio, |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 209 | bool transcodeVideo, |
| 210 | const TrackFormatEditCallback& videoFormatEditor = nullptr) { |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 211 | TranscodeMediaFile(state, srcFileName, dstFileName, |
| 212 | [=](const char* mime, AMediaFormat** dstFormatOut) -> bool { |
| 213 | *dstFormatOut = nullptr; |
| 214 | if (strncmp(mime, "video/", 6) == 0 && transcodeVideo) { |
| 215 | *dstFormatOut = CreateDefaultVideoFormat(); |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 216 | if (videoFormatEditor != nullptr) { |
| 217 | videoFormatEditor(*dstFormatOut); |
| 218 | } |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 219 | } else if (strncmp(mime, "audio/", 6) == 0 && !includeAudio) { |
| 220 | return false; |
| 221 | } |
| 222 | return true; |
| 223 | }); |
| 224 | } |
| 225 | |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 226 | static void SetMaxOperatingRate(AMediaFormat* format) { |
Linus Nilsson | 4aef0de | 2021-01-29 17:58:55 -0800 | [diff] [blame^] | 227 | AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_OPERATING_RATE, INT32_MAX); |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 228 | AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_PRIORITY, 1); |
| 229 | } |
| 230 | |
| 231 | //-------------------------------- AVC to AVC Benchmarks ------------------------------------------- |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 232 | |
| 233 | static void BM_TranscodeAvc2AvcAudioVideo2AudioVideo(benchmark::State& state) { |
| 234 | TranscodeMediaFile(state, "video_1920x1080_3648frame_h264_22Mbps_30fps_aac.mp4", |
| 235 | "video_1920x1080_3648frame_h264_22Mbps_30fps_aac_transcoded_AV.mp4", |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 236 | true /* includeAudio */, true /* transcodeVideo */); |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 239 | static void BM_TranscodeAvc2AvcVideo2Video(benchmark::State& state) { |
| 240 | TranscodeMediaFile(state, "video_1920x1080_3648frame_h264_22Mbps_30fps.mp4", |
| 241 | "video_1920x1080_3648frame_h264_22Mbps_30fps_transcoded_V.mp4", |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 242 | false /* includeAudio */, true /* transcodeVideo */); |
| 243 | } |
| 244 | |
| 245 | static void BM_TranscodeAvc2AvcAV2AVMaxOperatingRate(benchmark::State& state) { |
| 246 | TranscodeMediaFile(state, "video_1920x1080_3648frame_h264_22Mbps_30fps_aac.mp4", |
| 247 | "video_1920x1080_3648frame_h264_22Mbps_30fps_aac_transcoded_AV.mp4", |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 248 | true /* includeAudio */, true /* transcodeVideo */, SetMaxOperatingRate); |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static void BM_TranscodeAvc2AvcV2VMaxOperatingRate(benchmark::State& state) { |
| 252 | TranscodeMediaFile(state, "video_1920x1080_3648frame_h264_22Mbps_30fps.mp4", |
| 253 | "video_1920x1080_3648frame_h264_22Mbps_30fps_transcoded_V.mp4", |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 254 | false /* includeAudio */, true /* transcodeVideo */, SetMaxOperatingRate); |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Linus Nilsson | a7aa2f6 | 2020-10-29 13:19:35 -0700 | [diff] [blame] | 257 | static void BM_TranscodeAvc2AvcAV2AV720P(benchmark::State& state) { |
| 258 | TranscodeMediaFile(state, "video_1280x720_3648frame_h264_16Mbps_30fps_aac.mp4", |
| 259 | "video_1280x720_3648frame_h264_16Mbps_30fps_aac_transcoded_AV.mp4", |
| 260 | true /* includeAudio */, true /* transcodeVideo */); |
| 261 | } |
| 262 | |
| 263 | static void BM_TranscodeAvc2AvcAV2AV720PMaxOperatingRate(benchmark::State& state) { |
| 264 | TranscodeMediaFile(state, "video_1280x720_3648frame_h264_16Mbps_30fps_aac.mp4", |
| 265 | "video_1280x720_3648frame_h264_16Mbps_30fps_aac_transcoded_AV.mp4", |
| 266 | true /* includeAudio */, true /* transcodeVideo */, SetMaxOperatingRate); |
| 267 | } |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 268 | //-------------------------------- HEVC to AVC Benchmarks ------------------------------------------ |
| 269 | |
| 270 | static void BM_TranscodeHevc2AvcAudioVideo2AudioVideo(benchmark::State& state) { |
| 271 | TranscodeMediaFile(state, "video_1920x1080_3863frame_hevc_4Mbps_30fps_aac.mp4", |
| 272 | "video_1920x1080_3863frame_hevc_4Mbps_30fps_aac_transcoded_AV.mp4", |
| 273 | true /* includeAudio */, true /* transcodeVideo */); |
| 274 | } |
| 275 | |
| 276 | static void BM_TranscodeHevc2AvcVideo2Video(benchmark::State& state) { |
| 277 | TranscodeMediaFile(state, "video_1920x1080_3863frame_hevc_4Mbps_30fps.mp4", |
| 278 | "video_1920x1080_3863frame_hevc_4Mbps_30fps_transcoded_V.mp4", |
| 279 | false /* includeAudio */, true /* transcodeVideo */); |
| 280 | } |
| 281 | |
| 282 | static void BM_TranscodeHevc2AvcAV2AVMaxOperatingRate(benchmark::State& state) { |
| 283 | TranscodeMediaFile(state, "video_1920x1080_3863frame_hevc_4Mbps_30fps_aac.mp4", |
| 284 | "video_1920x1080_3863frame_hevc_4Mbps_30fps_aac_transcoded_AV.mp4", |
| 285 | true /* includeAudio */, true /* transcodeVideo */, SetMaxOperatingRate); |
| 286 | } |
| 287 | |
| 288 | static void BM_TranscodeHevc2AvcV2VMaxOperatingRate(benchmark::State& state) { |
| 289 | TranscodeMediaFile(state, "video_1920x1080_3863frame_hevc_4Mbps_30fps.mp4", |
| 290 | "video_1920x1080_3863frame_hevc_4Mbps_30fps_transcoded_V.mp4", |
| 291 | false /* includeAudio */, true /* transcodeVideo */, SetMaxOperatingRate); |
| 292 | } |
| 293 | |
Linus Nilsson | a7aa2f6 | 2020-10-29 13:19:35 -0700 | [diff] [blame] | 294 | static void BM_TranscodeHevc2AvcAV2AV720P(benchmark::State& state) { |
| 295 | TranscodeMediaFile(state, "video_1280x720_3863frame_hevc_16Mbps_30fps_aac.mp4", |
| 296 | "video_1280x720_3863frame_hevc_16Mbps_30fps_aac_transcoded_AV.mp4", |
| 297 | true /* includeAudio */, true /* transcodeVideo */); |
| 298 | } |
| 299 | |
| 300 | static void BM_TranscodeHevc2AvcAV2AV720PMaxOperatingRate(benchmark::State& state) { |
| 301 | TranscodeMediaFile(state, "video_1280x720_3863frame_hevc_16Mbps_30fps_aac.mp4", |
| 302 | "video_1280x720_3863frame_hevc_16Mbps_30fps_aac_transcoded_AV.mp4", |
| 303 | true /* includeAudio */, true /* transcodeVideo */, SetMaxOperatingRate); |
| 304 | } |
| 305 | |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 306 | //-------------------------------- Passthrough Benchmarks ------------------------------------------ |
| 307 | |
Linus Nilsson | 6233fed | 2020-08-13 15:15:14 -0700 | [diff] [blame] | 308 | static void BM_TranscodeAudioVideoPassthrough(benchmark::State& state) { |
| 309 | TranscodeMediaFile(state, "video_1920x1080_3648frame_h264_22Mbps_30fps_aac.mp4", |
| 310 | "video_1920x1080_3648frame_h264_22Mbps_30fps_aac_passthrough_AV.mp4", |
| 311 | true /* includeAudio */, false /* transcodeVideo */); |
| 312 | } |
| 313 | static void BM_TranscodeVideoPassthrough(benchmark::State& state) { |
| 314 | TranscodeMediaFile(state, "video_1920x1080_3648frame_h264_22Mbps_30fps.mp4", |
| 315 | "video_1920x1080_3648frame_h264_22Mbps_30fps_passthrough_AV.mp4", |
| 316 | false /* includeAudio */, false /* transcodeVideo */); |
| 317 | } |
| 318 | |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 319 | //-------------------------------- Benchmark Registration ------------------------------------------ |
| 320 | |
| 321 | // Benchmark registration wrapper for transcoding. |
| 322 | #define TRANSCODER_BENCHMARK(func) \ |
| 323 | BENCHMARK(func)->UseRealTime()->MeasureProcessCPUTime()->Unit(benchmark::kMillisecond) |
| 324 | |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 325 | TRANSCODER_BENCHMARK(BM_TranscodeAvc2AvcAudioVideo2AudioVideo); |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 326 | TRANSCODER_BENCHMARK(BM_TranscodeAvc2AvcVideo2Video); |
Linus Nilsson | 16d772b | 2020-09-29 19:21:11 -0700 | [diff] [blame] | 327 | TRANSCODER_BENCHMARK(BM_TranscodeAvc2AvcAV2AVMaxOperatingRate); |
| 328 | TRANSCODER_BENCHMARK(BM_TranscodeAvc2AvcV2VMaxOperatingRate); |
Linus Nilsson | a7aa2f6 | 2020-10-29 13:19:35 -0700 | [diff] [blame] | 329 | TRANSCODER_BENCHMARK(BM_TranscodeAvc2AvcAV2AV720P); |
| 330 | TRANSCODER_BENCHMARK(BM_TranscodeAvc2AvcAV2AV720PMaxOperatingRate); |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 331 | |
| 332 | TRANSCODER_BENCHMARK(BM_TranscodeHevc2AvcAudioVideo2AudioVideo); |
| 333 | TRANSCODER_BENCHMARK(BM_TranscodeHevc2AvcVideo2Video); |
| 334 | TRANSCODER_BENCHMARK(BM_TranscodeHevc2AvcAV2AVMaxOperatingRate); |
| 335 | TRANSCODER_BENCHMARK(BM_TranscodeHevc2AvcV2VMaxOperatingRate); |
Linus Nilsson | a7aa2f6 | 2020-10-29 13:19:35 -0700 | [diff] [blame] | 336 | TRANSCODER_BENCHMARK(BM_TranscodeHevc2AvcAV2AV720P); |
| 337 | TRANSCODER_BENCHMARK(BM_TranscodeHevc2AvcAV2AV720PMaxOperatingRate); |
Linus Nilsson | 6bf4653 | 2020-10-07 11:58:02 -0700 | [diff] [blame] | 338 | |
Linus Nilsson | 6233fed | 2020-08-13 15:15:14 -0700 | [diff] [blame] | 339 | TRANSCODER_BENCHMARK(BM_TranscodeAudioVideoPassthrough); |
| 340 | TRANSCODER_BENCHMARK(BM_TranscodeVideoPassthrough); |
Linus Nilsson | 8f0b876 | 2020-07-23 17:12:45 -0700 | [diff] [blame] | 341 | |
Naveen Kumar Ponnusamy | 8b8e700 | 2020-12-02 12:01:32 +0530 | [diff] [blame] | 342 | class CustomCsvReporter : public benchmark::BenchmarkReporter { |
| 343 | public: |
| 344 | CustomCsvReporter() : mPrintedHeader(false) {} |
| 345 | virtual bool ReportContext(const Context& context); |
| 346 | virtual void ReportRuns(const std::vector<Run>& reports); |
| 347 | |
| 348 | private: |
| 349 | void PrintRunData(const Run& report); |
| 350 | |
| 351 | bool mPrintedHeader; |
| 352 | std::vector<std::string> mHeaders = {"name", "real_time", "cpu_time", PARAM_VIDEO_FRAME_RATE}; |
| 353 | }; |
| 354 | |
| 355 | bool CustomCsvReporter::ReportContext(const Context& context __unused) { |
| 356 | return true; |
| 357 | } |
| 358 | |
| 359 | void CustomCsvReporter::ReportRuns(const std::vector<Run>& reports) { |
| 360 | std::ostream& Out = GetOutputStream(); |
| 361 | |
| 362 | if (!mPrintedHeader) { |
| 363 | // print the header |
| 364 | for (auto header = mHeaders.begin(); header != mHeaders.end();) { |
| 365 | Out << *header++; |
| 366 | if (header != mHeaders.end()) Out << ","; |
| 367 | } |
| 368 | Out << "\n"; |
| 369 | mPrintedHeader = true; |
| 370 | } |
| 371 | |
| 372 | // print results for each run |
| 373 | for (const auto& run : reports) { |
| 374 | PrintRunData(run); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | void CustomCsvReporter::PrintRunData(const Run& run) { |
| 379 | if (run.error_occurred) { |
| 380 | return; |
| 381 | } |
| 382 | std::ostream& Out = GetOutputStream(); |
| 383 | Out << run.benchmark_name() << ","; |
| 384 | Out << run.GetAdjustedRealTime() << ","; |
| 385 | Out << run.GetAdjustedCPUTime() << ","; |
| 386 | auto frameRate = run.counters.find(PARAM_VIDEO_FRAME_RATE); |
| 387 | if (frameRate == run.counters.end()) { |
| 388 | Out << "NA" |
| 389 | << ","; |
| 390 | } else { |
| 391 | Out << frameRate->second << ","; |
| 392 | } |
| 393 | Out << '\n'; |
| 394 | } |
| 395 | |
| 396 | int main(int argc, char** argv) { |
Naveen Kumar Ponnusamy | 2d074ba | 2020-12-17 17:13:45 -0800 | [diff] [blame] | 397 | android::ProcessState::self()->startThreadPool(); |
Naveen Kumar Ponnusamy | 8b8e700 | 2020-12-02 12:01:32 +0530 | [diff] [blame] | 398 | std::unique_ptr<benchmark::BenchmarkReporter> fileReporter; |
| 399 | for (int i = 1; i < argc; ++i) { |
| 400 | if (std::string(argv[i]).find("--benchmark_out") != std::string::npos) { |
| 401 | fileReporter.reset(new CustomCsvReporter); |
| 402 | break; |
| 403 | } |
| 404 | } |
| 405 | ::benchmark::Initialize(&argc, argv); |
| 406 | if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; |
| 407 | ::benchmark::RunSpecifiedBenchmarks(nullptr, fileReporter.get()); |
| 408 | } |