power: Clean up and fix video encode/decode hint handling

* Unify code style for non legacy SoCs

Change-Id: Ieb84e6d6c8d762614e21267e81e6057aa64b36dd
diff --git a/power-660.c b/power-660.c
index 00d50c5..23a91b6 100644
--- a/power-660.c
+++ b/power-660.c
@@ -53,8 +53,6 @@
 
 static int video_encode_hint_sent;
 
-static void process_video_encode_hint(void* metadata);
-
 /**
  * Returns true if the target is SDM630/SDM455.
  */
@@ -70,18 +68,87 @@
     return is_SDM630;
 }
 
-int power_hint_override(power_hint_t hint, void* data) {
-    switch (hint) {
-        case POWER_HINT_VSYNC:
-            break;
-        case POWER_HINT_VIDEO_ENCODE: {
-            process_video_encode_hint(data);
+static int process_video_encode_hint(void* metadata) {
+    char governor[80];
+    struct video_encode_metadata_t video_encode_metadata;
+
+    if (!metadata) return HINT_NONE;
+
+    if (get_scaling_governor(governor, sizeof(governor)) == -1) {
+        ALOGE("Can't obtain scaling governor.");
+        return HINT_NONE;
+    }
+
+    /* Initialize encode metadata struct fields */
+    memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
+    video_encode_metadata.state = -1;
+    video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
+
+    if (parse_video_encode_metadata((char*)metadata, &video_encode_metadata) == -1) {
+        ALOGE("Error occurred while parsing metadata.");
+        return HINT_NONE;
+    }
+
+    if (video_encode_metadata.state == 1) {
+        if (is_interactive_governor(governor)) {
+            if (is_target_SDM630()) {
+                /*
+                    1. CPUfreq params
+                        - hispeed freq for big - 1113Mhz
+                        - go hispeed load for big - 95
+                        - above_hispeed_delay for big - 40ms
+                        - target loads - 95
+                        - nr_run - 5
+                    2. BusDCVS V2 params
+                        - Sample_ms of 10ms
+                 */
+                int resource_values[] = {0x41414000, 0x459, 0x41410000, 0x5F, 0x41400000, 0x4,
+                                         0x41420000, 0x5F,  0x40C2C000, 0X5,  0x41820000, 0xA};
+                if (!video_encode_hint_sent) {
+                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
+                                        ARRAY_SIZE(resource_values));
+                    video_encode_hint_sent = 1;
+                    return HINT_HANDLED;
+                }
+            } else {
+                /*
+                    1. CPUfreq params
+                        - hispeed freq for little - 902Mhz
+                        - go hispeed load for little - 95
+                        - above_hispeed_delay for little - 40ms
+                    2. BusDCVS V2 params
+                        - Sample_ms of 10ms
+                 */
+                int resource_values[] = {0x41414100, 0x386, 0x41410100, 0x5F,
+                                         0x41400100, 0x4,   0x41820000, 0xA};
+                if (!video_encode_hint_sent) {
+                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
+                                        ARRAY_SIZE(resource_values));
+                    video_encode_hint_sent = 1;
+                    return HINT_HANDLED;
+                }
+            }
+        }
+    } else if (video_encode_metadata.state == 0) {
+        if (is_interactive_governor(governor)) {
+            undo_hint_action(video_encode_metadata.hint_id);
+            video_encode_hint_sent = 0;
             return HINT_HANDLED;
         }
+    }
+    return HINT_NONE;
+}
+
+int power_hint_override(power_hint_t hint, void* data) {
+    int ret_val = HINT_NONE;
+    switch (hint) {
+        case POWER_HINT_VIDEO_ENCODE:
+            ret_val = process_video_encode_hint(data);
+            break;
         default:
             break;
     }
-    return HINT_NONE;
+    return ret_val;
 }
 
 int set_interactive_override(int on) {
@@ -138,76 +205,3 @@
     }
     return HINT_HANDLED;
 }
-
-/* Video Encode Hint */
-static void process_video_encode_hint(void* metadata) {
-    char governor[80];
-    int resource_values[20];
-    int num_resources;
-    struct video_encode_metadata_t video_encode_metadata;
-
-    ALOGI("Got process_video_encode_hint");
-
-    if (get_scaling_governor(governor, sizeof(governor)) == -1) {
-        ALOGE("Can't obtain scaling governor.");
-        // return HINT_HANDLED;
-    }
-
-    /* Initialize encode metadata struct fields. */
-    memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
-    video_encode_metadata.state = -1;
-    video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
-
-    if (metadata) {
-        if (parse_video_encode_metadata((char*)metadata, &video_encode_metadata) == -1) {
-            ALOGE("Error occurred while parsing metadata.");
-            return;
-        }
-    } else {
-        return;
-    }
-
-    if (video_encode_metadata.state == 1) {
-        if (is_interactive_governor(governor)) {
-            /*
-                1. CPUfreq params
-                       - hispeed freq for big - 1113Mhz
-                       - go hispeed load for big - 95
-                       - above_hispeed_delay for big - 40ms
-                       - target loads - 95
-                       - nr_run - 5
-                2. BusDCVS V2 params
-                       - Sample_ms of 10ms
-           */
-            if (is_target_SDM630()) {
-                int res[] = {0x41414000, 0x459, 0x41410000, 0x5F, 0x41400000, 0x4,
-                             0x41420000, 0x5F,  0x40C2C000, 0X5,  0x41820000, 0xA};
-                memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
-                num_resources = ARRAY_SIZE(res);
-            }
-            /*
-                 1. CPUfreq params
-                        - hispeed freq for little - 902Mhz
-                        - go hispeed load for little - 95
-                        - above_hispeed_delay for little - 40ms
-                 2. BusDCVS V2 params
-                        - Sample_ms of 10ms
-            */
-            else {
-                int res[] = {0x41414100, 0x386, 0x41410100, 0x5F, 0x41400100, 0x4, 0x41820000, 0xA};
-                memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
-                num_resources = ARRAY_SIZE(res);
-            }
-            if (!video_encode_hint_sent) {
-                perform_hint_action(video_encode_metadata.hint_id, resource_values, num_resources);
-                video_encode_hint_sent = 1;
-            }
-        }
-    } else if (video_encode_metadata.state == 0) {
-        if (is_interactive_governor(governor)) {
-            undo_hint_action(video_encode_metadata.hint_id);
-            video_encode_hint_sent = 0;
-        }
-    }
-    return;
-}
diff --git a/power-845.c b/power-845.c
index ffe455d..ac6c4d7 100644
--- a/power-845.c
+++ b/power-845.c
@@ -151,7 +151,6 @@
 
     if (get_scaling_governor(governor, sizeof(governor)) == -1) {
         ALOGE("Can't obtain scaling governor.");
-
         return HINT_NONE;
     }
 
@@ -167,13 +166,11 @@
     if (video_encode_metadata.state == 1) {
         if (is_interactive_governor(governor)) {
             video_encode_handle = perf_hint_enable(VIDEO_ENCODE_HINT, 0);
-            ALOGI("Video encode hint start");
             return HINT_HANDLED;
         }
     } else if (video_encode_metadata.state == 0) {
         if (is_interactive_governor(governor)) {
             release_request(video_encode_handle);
-            ALOGI("Video Encode hint stop");
             return HINT_HANDLED;
         }
     }
diff --git a/power-8937.c b/power-8937.c
index 48defb8..4d1cbde 100644
--- a/power-8937.c
+++ b/power-8937.c
@@ -49,10 +49,7 @@
 #include "power-common.h"
 #include "utils.h"
 
-#define MIN_VAL(X, Y) ((X > Y) ? (Y) : (X))
-
 static int video_encode_hint_sent;
-static void process_video_encode_hint(void* metadata);
 
 /**
  * Returns true if the target is SDM439/SDM429.
@@ -69,18 +66,97 @@
     return is_SDM439;
 }
 
-int power_hint_override(power_hint_t hint, void* data) {
-    switch (hint) {
-        case POWER_HINT_VSYNC:
-            break;
-        case POWER_HINT_VIDEO_ENCODE: {
-            process_video_encode_hint(data);
+static int process_video_encode_hint(void* metadata) {
+    char governor[80];
+    struct video_encode_metadata_t video_encode_metadata;
+
+    if (!metadata) return HINT_NONE;
+
+    if (get_scaling_governor(governor, sizeof(governor)) == -1) {
+        ALOGE("Can't obtain scaling governor.");
+        return HINT_NONE;
+    }
+
+    /* Initialize encode metadata struct fields */
+    memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
+    video_encode_metadata.state = -1;
+    video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
+
+    if (parse_video_encode_metadata((char*)metadata, &video_encode_metadata) == -1) {
+        ALOGE("Error occurred while parsing metadata.");
+        return HINT_NONE;
+    }
+
+    if (video_encode_metadata.state == 1) {
+        if (is_schedutil_governor(governor)) {
+            if (is_target_SDM439()) {
+                /* sample_ms = 10mS
+                 * SLB for Core0 = -6
+                 * SLB for Core1 = -6
+                 * SLB for Core2 = -6
+                 * SLB for Core3 = -6
+                 * hispeed load = 95
+                 * hispeed freq = 998Mhz */
+                int resource_values[] = {
+                        0x41820000, 0xa,        0x40c68100, 0xfffffffa, 0x40c68110,
+                        0xfffffffa, 0x40c68120, 0xfffffffa, 0x40c68130, 0xfffffffa,
+                        0x41440100, 0x5f,       0x4143c100, 0x3e6,
+                };
+                if (!video_encode_hint_sent) {
+                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
+                                        ARRAY_SIZE(resource_values));
+                    video_encode_hint_sent = 1;
+                    return HINT_HANDLED;
+                }
+            } else {
+                /* sample_ms = 10mS */
+                int resource_values[] = {
+                        0x41820000,
+                        0xa,
+                };
+                if (!video_encode_hint_sent) {
+                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
+                                        ARRAY_SIZE(resource_values));
+                    video_encode_hint_sent = 1;
+                    return HINT_HANDLED;
+                }
+            }
+        } else if (is_interactive_governor(governor)) {
+            /* Sched_load and migration_notification disable
+             * timer rate - 40mS*/
+            int resource_values[] = {INT_OP_CLUSTER0_USE_SCHED_LOAD,      0x1,
+                                     INT_OP_CLUSTER1_USE_SCHED_LOAD,      0x1,
+                                     INT_OP_CLUSTER0_USE_MIGRATION_NOTIF, 0x1,
+                                     INT_OP_CLUSTER1_USE_MIGRATION_NOTIF, 0x1,
+                                     INT_OP_CLUSTER0_TIMER_RATE,          BIG_LITTLE_TR_MS_40,
+                                     INT_OP_CLUSTER1_TIMER_RATE,          BIG_LITTLE_TR_MS_40};
+            if (!video_encode_hint_sent) {
+                perform_hint_action(video_encode_metadata.hint_id, resource_values,
+                                    ARRAY_SIZE(resource_values));
+                video_encode_hint_sent = 1;
+                return HINT_HANDLED;
+            }
+        }
+    } else if (video_encode_metadata.state == 0) {
+        if (is_interactive_governor(governor) || is_schedutil_governor(governor)) {
+            undo_hint_action(video_encode_metadata.hint_id);
+            video_encode_hint_sent = 0;
             return HINT_HANDLED;
         }
+    }
+    return HINT_NONE;
+}
+
+int power_hint_override(power_hint_t hint, void* data) {
+    int ret_val = HINT_NONE;
+    switch (hint) {
+        case POWER_HINT_VIDEO_ENCODE:
+            ret_val = process_video_encode_hint(data);
+            break;
         default:
             break;
     }
-    return HINT_NONE;
+    return ret_val;
 }
 
 int set_interactive_override(int on) {
@@ -117,85 +193,3 @@
 
     return HINT_HANDLED;
 }
-
-/* Video Encode Hint */
-static void process_video_encode_hint(void* metadata) {
-    char governor[80] = {0};
-    int resource_values[20] = {0};
-    struct video_encode_metadata_t video_encode_metadata;
-
-    ALOGI("Got process_video_encode_hint");
-
-    if (get_scaling_governor(governor, sizeof(governor)) == -1) {
-        ALOGE("Can't obtain scaling governor.");
-        return;
-    }
-
-    /* Initialize encode metadata struct fields. */
-    memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
-    video_encode_metadata.state = -1;
-    video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
-
-    if (metadata) {
-        if (parse_video_encode_metadata((char*)metadata, &video_encode_metadata) == -1) {
-            ALOGE("Error occurred while parsing metadata.");
-            return;
-        }
-    } else {
-        return;
-    }
-
-    if (video_encode_metadata.state == 1) {
-        if (is_schedutil_governor(governor)) {
-            if (is_target_SDM439()) {
-                /* sample_ms = 10mS
-                 * SLB for Core0 = -6
-                 * SLB for Core1 = -6
-                 * SLB for Core2 = -6
-                 * SLB for Core3 = -6
-                 * hispeed load = 95
-                 * hispeed freq = 998Mhz */
-                int res[] = {
-                        0x41820000, 0xa,        0x40c68100, 0xfffffffa, 0x40c68110,
-                        0xfffffffa, 0x40c68120, 0xfffffffa, 0x40c68130, 0xfffffffa,
-                        0x41440100, 0x5f,       0x4143c100, 0x3e6,
-                };
-                memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
-                if (!video_encode_hint_sent) {
-                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
-                                        ARRAY_SIZE(res));
-                    video_encode_hint_sent = 1;
-                }
-            } else {
-                /* sample_ms = 10mS */
-                int res[] = {
-                        0x41820000,
-                        0xa,
-                };
-                memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
-                if (!video_encode_hint_sent) {
-                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
-                                        ARRAY_SIZE(res));
-                    video_encode_hint_sent = 1;
-                }
-            }
-        } else if (is_interactive_governor(governor)) {
-            /* Sched_load and migration_notif*/
-            int res[] = {INT_OP_CLUSTER0_USE_SCHED_LOAD,      0x1,
-                         INT_OP_CLUSTER1_USE_SCHED_LOAD,      0x1,
-                         INT_OP_CLUSTER0_USE_MIGRATION_NOTIF, 0x1,
-                         INT_OP_CLUSTER1_USE_MIGRATION_NOTIF, 0x1,
-                         INT_OP_CLUSTER0_TIMER_RATE,          BIG_LITTLE_TR_MS_40,
-                         INT_OP_CLUSTER1_TIMER_RATE,          BIG_LITTLE_TR_MS_40};
-            memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
-            perform_hint_action(video_encode_metadata.hint_id, resource_values, ARRAY_SIZE(res));
-            video_encode_hint_sent = 1;
-        }
-    } else if (video_encode_metadata.state == 0) {
-        if (is_interactive_governor(governor) || is_schedutil_governor(governor)) {
-            undo_hint_action(video_encode_metadata.hint_id);
-            video_encode_hint_sent = 0;
-        }
-    }
-    return;
-}
diff --git a/power-8953.c b/power-8953.c
index 9ed6dd0..7ed5b0b 100644
--- a/power-8953.c
+++ b/power-8953.c
@@ -49,12 +49,8 @@
 #include "power-common.h"
 #include "utils.h"
 
-#define MIN_VAL(X, Y) ((X > Y) ? (Y) : (X))
-
 static int video_encode_hint_sent;
 
-static void process_video_encode_hint(void* metadata);
-
 /**
  * Returns true if the target is SDM632.
  */
@@ -70,18 +66,94 @@
     return is_SDM632;
 }
 
-int power_hint_override(power_hint_t hint, void* data) {
-    switch (hint) {
-        case POWER_HINT_VSYNC:
-            break;
-        case POWER_HINT_VIDEO_ENCODE: {
-            process_video_encode_hint(data);
+static int process_video_encode_hint(void* metadata) {
+    char governor[80];
+    struct video_encode_metadata_t video_encode_metadata;
+
+    if (!metadata) return HINT_NONE;
+
+    if (get_scaling_governor(governor, sizeof(governor)) == -1) {
+        ALOGE("Can't obtain scaling governor.");
+        return HINT_NONE;
+    }
+
+    /* Initialize encode metadata struct fields */
+    memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
+    video_encode_metadata.state = -1;
+    video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
+
+    if (parse_video_encode_metadata((char*)metadata, &video_encode_metadata) == -1) {
+        ALOGE("Error occurred while parsing metadata.");
+        return HINT_NONE;
+    }
+
+    if (video_encode_metadata.state == 1) {
+        if (is_schedutil_governor(governor)) {
+            if (is_target_SDM632()) {
+                /* sample_ms = 10mS
+                 * SLB for Core0 = -6
+                 * SLB for Core1 = -6
+                 * SLB for Core2 = -6
+                 * SLB for Core3 = -6
+                 * hispeed load = 95
+                 * hispeed freq = 1036 */
+                int resource_values[] = {
+                        0x41820000, 0xa,        0x40c68100, 0xfffffffa, 0x40c68110,
+                        0xfffffffa, 0x40c68120, 0xfffffffa, 0x40c68130, 0xfffffffa,
+                        0x41440100, 0x5f,       0x4143c100, 0x40c,
+                };
+                if (!video_encode_hint_sent) {
+                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
+                                        ARRAY_SIZE(resource_values));
+                    video_encode_hint_sent = 1;
+                    return HINT_HANDLED;
+                }
+            } else {
+                /* sample_ms = 10mS */
+                int resource_values[] = {
+                        0x41820000,
+                        0xa,
+                };
+                if (!video_encode_hint_sent) {
+                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
+                                        ARRAY_SIZE(resource_values));
+                    video_encode_hint_sent = 1;
+                    return HINT_HANDLED;
+                }
+            }
+        } else if (is_interactive_governor(governor)) {
+            /* Sched_load and migration_notification disable
+             * timer rate - 40mS*/
+            int resource_values[] = {
+                    0x41430000, 0x1, 0x41434000, 0x1, 0x41424000, 0x28,
+            };
+            if (!video_encode_hint_sent) {
+                perform_hint_action(video_encode_metadata.hint_id, resource_values,
+                                    ARRAY_SIZE(resource_values));
+                video_encode_hint_sent = 1;
+                return HINT_HANDLED;
+            }
+        }
+    } else if (video_encode_metadata.state == 0) {
+        if (is_interactive_governor(governor) || is_schedutil_governor(governor)) {
+            undo_hint_action(video_encode_metadata.hint_id);
+            video_encode_hint_sent = 0;
             return HINT_HANDLED;
         }
+    }
+    return HINT_NONE;
+}
+
+int power_hint_override(power_hint_t hint, void* data) {
+    int ret_val = HINT_NONE;
+    switch (hint) {
+        case POWER_HINT_VIDEO_ENCODE:
+            ret_val = process_video_encode_hint(data);
+            break;
         default:
             break;
     }
-    return HINT_NONE;
+    return ret_val;
 }
 
 int set_interactive_override(int on) {
@@ -119,86 +191,3 @@
 
     return HINT_HANDLED;
 }
-
-/* Video Encode Hint */
-static void process_video_encode_hint(void* metadata) {
-    char governor[80] = {0};
-    int resource_values[20] = {0};
-    struct video_encode_metadata_t video_encode_metadata;
-
-    ALOGI("Got process_video_encode_hint");
-
-    if (get_scaling_governor(governor, sizeof(governor)) == -1) {
-        ALOGE("Can't obtain scaling governor.");
-        // return HINT_HANDLED;
-    }
-
-    /* Initialize encode metadata struct fields. */
-    memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
-    video_encode_metadata.state = -1;
-    video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
-
-    if (metadata) {
-        if (parse_video_encode_metadata((char*)metadata, &video_encode_metadata) == -1) {
-            ALOGE("Error occurred while parsing metadata.");
-            return;
-        }
-    } else {
-        return;
-    }
-
-    if (video_encode_metadata.state == 1) {
-        if (is_schedutil_governor(governor)) {
-            if (is_target_SDM632()) {
-                /* sample_ms = 10mS
-                 * SLB for Core0 = -6
-                 * SLB for Core1 = -6
-                 * SLB for Core2 = -6
-                 * SLB for Core3 = -6
-                 * hispeed load = 95
-                 * hispeed freq = 1036 */
-                int res[] = {
-                        0x41820000, 0xa,        0x40c68100, 0xfffffffa, 0x40c68110,
-                        0xfffffffa, 0x40c68120, 0xfffffffa, 0x40c68130, 0xfffffffa,
-                        0x41440100, 0x5f,       0x4143c100, 0x40c,
-                };
-                memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
-                if (!video_encode_hint_sent) {
-                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
-                                        ARRAY_SIZE(res));
-                    video_encode_hint_sent = 1;
-                }
-            } else {
-                /* sample_ms = 10mS */
-                int res[] = {
-                        0x41820000,
-                        0xa,
-                };
-                memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
-                if (!video_encode_hint_sent) {
-                    perform_hint_action(video_encode_metadata.hint_id, resource_values,
-                                        ARRAY_SIZE(res));
-                    video_encode_hint_sent = 1;
-                }
-            }
-        } else if (is_interactive_governor(governor)) {
-            /* Sched_load and migration_notification disable
-             * timer rate - 40mS*/
-            int res[] = {
-                    0x41430000, 0x1, 0x41434000, 0x1, 0x41424000, 0x28,
-            };
-            memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
-            if (!video_encode_hint_sent) {
-                perform_hint_action(video_encode_metadata.hint_id, resource_values,
-                                    ARRAY_SIZE(res));
-                video_encode_hint_sent = 1;
-            }
-        }
-    } else if (video_encode_metadata.state == 0) {
-        if (is_interactive_governor(governor) || is_schedutil_governor(governor)) {
-            undo_hint_action(video_encode_metadata.hint_id);
-            video_encode_hint_sent = 0;
-        }
-    }
-    return;
-}
diff --git a/power-8996.c b/power-8996.c
index b66e5c9..49f120f 100644
--- a/power-8996.c
+++ b/power-8996.c
@@ -47,13 +47,16 @@
 #include "power-common.h"
 #include "utils.h"
 
+static int video_encode_hint_sent;
+
 static int process_video_encode_hint(void* metadata) {
     char governor[80];
     struct video_encode_metadata_t video_encode_metadata;
 
+    if (!metadata) return HINT_NONE;
+
     if (get_scaling_governor(governor, sizeof(governor)) == -1) {
         ALOGE("Can't obtain scaling governor.");
-
         return HINT_NONE;
     }
 
@@ -62,12 +65,8 @@
     video_encode_metadata.state = -1;
     video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
 
-    if (metadata) {
-        if (parse_video_encode_metadata((char*)metadata, &video_encode_metadata) == -1) {
-            ALOGE("Error occurred while parsing metadata.");
-            return HINT_NONE;
-        }
-    } else {
+    if (parse_video_encode_metadata((char*)metadata, &video_encode_metadata) == -1) {
+        ALOGE("Error occurred while parsing metadata.");
         return HINT_NONE;
     }
 
@@ -94,17 +93,17 @@
                                      0x41420000, 0x5A,  0x41400100, 0x4,  0x41410100, 0x5F,
                                      0x41414100, 0x22C, 0x41420100, 0x5A, 0x41810000, 0x9C4,
                                      0x41814000, 0x32,  0x4180C000, 0x0,  0x41820000, 0xA};
-
-            perform_hint_action(video_encode_metadata.hint_id, resource_values,
-                                ARRAY_SIZE(resource_values));
-            ALOGI("Video Encode hint start");
-            return HINT_HANDLED;
+            if (!video_encode_hint_sent) {
+                perform_hint_action(video_encode_metadata.hint_id, resource_values,
+                                    ARRAY_SIZE(resource_values));
+                video_encode_hint_sent = 1;
+                return HINT_HANDLED;
+            }
         }
     } else if (video_encode_metadata.state == 0) {
         if (is_interactive_governor(governor)) {
             undo_hint_action(video_encode_metadata.hint_id);
-
-            ALOGI("Video Encode hint stop");
+            video_encode_hint_sent = 0;
             return HINT_HANDLED;
         }
     }
diff --git a/power-8998.c b/power-8998.c
index b8154e3..39b7059 100644
--- a/power-8998.c
+++ b/power-8998.c
@@ -150,7 +150,6 @@
 
     if (get_scaling_governor(governor, sizeof(governor)) == -1) {
         ALOGE("Can't obtain scaling governor.");
-
         return HINT_NONE;
     }
 
@@ -171,7 +170,6 @@
     } else if (video_encode_metadata.state == 0) {
         if (is_interactive_governor(governor)) {
             release_request(video_encode_handle);
-            ALOGI("Video Encode hint stop");
             return HINT_HANDLED;
         }
     }