blob: cf2056b8486457759644fdb01ecbb65152ad5c40 [file] [log] [blame]
vaibhav bhallaacdf9322015-02-23 11:57:38 +05301/*
2 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
Michael Bestas47636f62018-05-25 21:30:28 +03003 * Copyright (C) 2018 The LineageOS Project
vaibhav bhallaacdf9322015-02-23 11:57:38 +05304 *
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 Bestas47636f62018-05-25 21:30:28 +030030
vaibhav bhallaacdf9322015-02-23 11:57:38 +053031#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 Bestas1add9ac2018-03-25 22:56:44 +030041#define LOG_TAG "QCOM PowerHAL"
Ethan Chena42f4a82018-03-01 21:31:15 -080042#include <log/log.h>
vaibhav bhallaacdf9322015-02-23 11:57:38 +053043#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 bhalla98677f92015-03-25 22:20:28 +053052static void process_video_encode_hint(void *metadata)
53{
54 char governor[80];
55 struct video_encode_metadata_t video_encode_metadata;
vaibhav bhalla98677f92015-03-25 22:20:28 +053056
57 if (get_scaling_governor(governor, sizeof(governor)) == -1) {
58 ALOGE("Can't obtain scaling governor.");
Michael Bestas47636f62018-05-25 21:30:28 +030059 return;
60 }
vaibhav bhalla98677f92015-03-25 22:20:28 +053061
Michael Bestas47636f62018-05-25 21:30:28 +030062 if (!metadata) {
vaibhav bhalla98677f92015-03-25 22:20:28 +053063 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 Bestas47636f62018-05-25 21:30:28 +030071 if (parse_video_encode_metadata((char *)metadata,
72 &video_encode_metadata) == -1) {
73 ALOGE("Error occurred while parsing metadata.");
vaibhav bhalla98677f92015-03-25 22:20:28 +053074 return;
75 }
76
77 if (video_encode_metadata.state == 1) {
Ethan Chen4b4acdf2018-03-01 21:41:04 -080078 if (is_interactive_governor(governor)) {
Michael Bestas47636f62018-05-25 21:30:28 +030079 int resource_values[] = {
80 HS_FREQ_800, THREAD_MIGRATION_SYNC_OFF
81 };
vaibhav bhalla98677f92015-03-25 22:20:28 +053082 perform_hint_action(video_encode_metadata.hint_id,
Zhao Wei Liewd4fe61e2016-06-26 11:37:59 +080083 resource_values, ARRAY_SIZE(resource_values));
vaibhav bhalla98677f92015-03-25 22:20:28 +053084 }
85 } else if (video_encode_metadata.state == 0) {
Ethan Chen4b4acdf2018-03-01 21:41:04 -080086 if (is_interactive_governor(governor)) {
Michael Bestas47636f62018-05-25 21:30:28 +030087 undo_hint_action(video_encode_metadata.hint_id);
vaibhav bhalla98677f92015-03-25 22:20:28 +053088 }
89 }
90}
91
Rashed Abdel-Tawaba2a70712017-12-31 01:21:40 +020092int power_hint_override(power_hint_t hint, void *data)
vaibhav bhallaacdf9322015-02-23 11:57:38 +053093{
Michael Bestas47636f62018-05-25 21:30:28 +030094 switch (hint) {
vaibhav bhallaacdf9322015-02-23 11:57:38 +053095 case POWER_HINT_VIDEO_ENCODE:
Michael Bestas47636f62018-05-25 21:30:28 +030096 process_video_encode_hint(data);
97 return HINT_HANDLED;
vaibhav bhallaacdf9322015-02-23 11:57:38 +053098 default:
vaibhav bhallaacdf9322015-02-23 11:57:38 +053099 break;
vaibhav bhallaacdf9322015-02-23 11:57:38 +0530100 }
101 return HINT_NONE;
102}