vaibhav bhalla | acdf932 | 2015-02-23 11:57:38 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 3 | * Copyright (C) 2018 The LineageOS Project |
vaibhav bhalla | acdf932 | 2015-02-23 11:57:38 +0530 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * * Neither the name of The Linux Foundation nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived |
| 16 | * from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 25 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 27 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 28 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 30 | |
vaibhav bhalla | acdf932 | 2015-02-23 11:57:38 +0530 | [diff] [blame] | 31 | #define LOG_NIDEBUG 0 |
| 32 | |
| 33 | #include <errno.h> |
| 34 | #include <string.h> |
| 35 | #include <sys/types.h> |
| 36 | #include <sys/stat.h> |
| 37 | #include <fcntl.h> |
| 38 | #include <dlfcn.h> |
| 39 | #include <stdlib.h> |
| 40 | |
Michael Bestas | 1add9ac | 2018-03-25 22:56:44 +0300 | [diff] [blame] | 41 | #define LOG_TAG "QCOM PowerHAL" |
Ethan Chen | a42f4a8 | 2018-03-01 21:31:15 -0800 | [diff] [blame] | 42 | #include <log/log.h> |
vaibhav bhalla | acdf932 | 2015-02-23 11:57:38 +0530 | [diff] [blame] | 43 | #include <hardware/hardware.h> |
| 44 | #include <hardware/power.h> |
| 45 | |
| 46 | #include "utils.h" |
| 47 | #include "metadata-defs.h" |
| 48 | #include "hint-data.h" |
| 49 | #include "performance.h" |
| 50 | #include "power-common.h" |
| 51 | |
vaibhav bhalla | 98677f9 | 2015-03-25 22:20:28 +0530 | [diff] [blame] | 52 | static void process_video_encode_hint(void *metadata) |
| 53 | { |
| 54 | char governor[80]; |
| 55 | struct video_encode_metadata_t video_encode_metadata; |
vaibhav bhalla | 98677f9 | 2015-03-25 22:20:28 +0530 | [diff] [blame] | 56 | |
| 57 | if (get_scaling_governor(governor, sizeof(governor)) == -1) { |
| 58 | ALOGE("Can't obtain scaling governor."); |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 59 | return; |
| 60 | } |
vaibhav bhalla | 98677f9 | 2015-03-25 22:20:28 +0530 | [diff] [blame] | 61 | |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 62 | if (!metadata) { |
vaibhav bhalla | 98677f9 | 2015-03-25 22:20:28 +0530 | [diff] [blame] | 63 | return; |
| 64 | } |
| 65 | |
| 66 | /* Initialize encode metadata struct fields. */ |
| 67 | memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t)); |
| 68 | video_encode_metadata.state = -1; |
| 69 | video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID; |
| 70 | |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 71 | if (parse_video_encode_metadata((char *)metadata, |
| 72 | &video_encode_metadata) == -1) { |
| 73 | ALOGE("Error occurred while parsing metadata."); |
vaibhav bhalla | 98677f9 | 2015-03-25 22:20:28 +0530 | [diff] [blame] | 74 | return; |
| 75 | } |
| 76 | |
| 77 | if (video_encode_metadata.state == 1) { |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 78 | if (is_interactive_governor(governor)) { |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 79 | int resource_values[] = { |
| 80 | HS_FREQ_800, THREAD_MIGRATION_SYNC_OFF |
| 81 | }; |
vaibhav bhalla | 98677f9 | 2015-03-25 22:20:28 +0530 | [diff] [blame] | 82 | perform_hint_action(video_encode_metadata.hint_id, |
Zhao Wei Liew | d4fe61e | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 83 | resource_values, ARRAY_SIZE(resource_values)); |
vaibhav bhalla | 98677f9 | 2015-03-25 22:20:28 +0530 | [diff] [blame] | 84 | } |
| 85 | } else if (video_encode_metadata.state == 0) { |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 86 | if (is_interactive_governor(governor)) { |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 87 | undo_hint_action(video_encode_metadata.hint_id); |
vaibhav bhalla | 98677f9 | 2015-03-25 22:20:28 +0530 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
Rashed Abdel-Tawab | a2a7071 | 2017-12-31 01:21:40 +0200 | [diff] [blame] | 92 | int power_hint_override(power_hint_t hint, void *data) |
vaibhav bhalla | acdf932 | 2015-02-23 11:57:38 +0530 | [diff] [blame] | 93 | { |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 94 | switch (hint) { |
vaibhav bhalla | acdf932 | 2015-02-23 11:57:38 +0530 | [diff] [blame] | 95 | case POWER_HINT_VIDEO_ENCODE: |
Michael Bestas | 47636f6 | 2018-05-25 21:30:28 +0300 | [diff] [blame] | 96 | process_video_encode_hint(data); |
| 97 | return HINT_HANDLED; |
vaibhav bhalla | acdf932 | 2015-02-23 11:57:38 +0530 | [diff] [blame] | 98 | default: |
vaibhav bhalla | acdf932 | 2015-02-23 11:57:38 +0530 | [diff] [blame] | 99 | break; |
vaibhav bhalla | acdf932 | 2015-02-23 11:57:38 +0530 | [diff] [blame] | 100 | } |
| 101 | return HINT_NONE; |
| 102 | } |