Files
BPI-CM9-Linux/aml-comp/vendor/amlogic/aml_subtitleserver/libsubtitle/utils/SubtitleLog.h
T
2026-08-24 10:03:24 +08:00

142 lines
4.8 KiB
C

/*
* Copyright (C) 2014-2025 Amlogic, Inc. All rights reserved.
*
* All information contained herein is Amlogic confidential.
*
* This software is provided to you pursuant to Software License Agreement
* (SLA) with Amlogic Inc ("Amlogic"). This software may be used
* only in accordance with the terms of this agreement.
*
* Redistribution and use in source and binary forms, with or without
* modification is strictly prohibited without prior written permission from
* Amlogic.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <cutils/properties.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utils/Log.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __ANDROID__
#define DUMP_DATA_DIRECTORY "/data/subtitleDump"
#define DUMP_DATA_FILE_PATH "/data/subtitleDump/cur_sub.dump"
#define DEV_SUBTITLE_DEBUG_LEVEL "vendor.subtitle.debug.level"
#else
#define DUMP_DATA_DIRECTORY "/tmp/subtitleDump"
#define DUMP_DATA_FILE_PATH "/tmp/subtitleDump/cur_sub.dump"
#define DEV_SUBTITLE_DEBUG_LEVEL "/tmp/subtitle_debug_level"
#endif
typedef enum {
SUB_LOG_SILENT = -1,
SUB_LOG_FATAL = 0,
SUB_LOG_ERROR = 1,
SUB_LOG_WARNING = 2,
SUB_LOG_INFO = 3,
SUB_LOG_DEBUG = 4,
SUB_LOG_DUMP = 5,
} SubtitleLogLevel;
extern SubtitleLogLevel gSubtitleLogLevel;
__attribute__((unused)) static inline SubtitleLogLevel* getLogLevel() {
return &gSubtitleLogLevel;
}
__attribute__((unused)) static inline void updateSubtitleLogLevel() {
// The size of the value must be 92 as the information in
// prebuilts/vndk/v33/x86/include/system/core/libcutils/include_outside_system/cutils/properties.h
char value[92] = {0};
SubtitleLogLevel* logLevel = getLogLevel();
#ifdef __ANDROID__
if (property_get(DEV_SUBTITLE_DEBUG_LEVEL, value, "3")) {
int level = atoi(value);
if (level >= SUB_LOG_SILENT && level <= SUB_LOG_DUMP) {
*logLevel = (SubtitleLogLevel)level;
} else {
*logLevel = SUB_LOG_INFO;
}
}
#else
FILE* file = fopen(DEV_SUBTITLE_DEBUG_LEVEL, "r");
if (file && fgets(value, sizeof(value), file)) {
fclose(file);
int level = atoi(value);
if (level >= SUB_LOG_SILENT && level <= SUB_LOG_DUMP) {
*logLevel = (SubtitleLogLevel)level;
} else {
*logLevel = SUB_LOG_INFO;
}
} else if (file) {
fclose(file);
}
#endif
}
__attribute__((unused)) static inline bool isSubtitleDumpAvailable() {
return *getLogLevel() == SUB_LOG_DUMP;
}
#ifndef MUTE_SUBTITLE_LOG
#define SUBTITLE_LOGF(fmt, ...) \
do { \
if (*getLogLevel() >= SUB_LOG_FATAL) \
ALOGE("%s: " fmt, __func__, ##__VA_ARGS__); \
abort(); \
} while (0)
#define SUBTITLE_LOGE(fmt, ...) \
do { \
if (*getLogLevel() >= SUB_LOG_ERROR) ALOGE("%s: " fmt, __func__, ##__VA_ARGS__); \
} while (0)
#define SUBTITLE_LOGW(fmt, ...) \
do { \
if (*getLogLevel() >= SUB_LOG_WARNING) ALOGW("%s: " fmt, __func__, ##__VA_ARGS__); \
} while (0)
#define SUBTITLE_LOGI(fmt, ...) \
do { \
if (*getLogLevel() >= SUB_LOG_INFO) ALOGI("%s: " fmt, __func__, ##__VA_ARGS__); \
} while (0)
#define SUBTITLE_LOGD(fmt, ...) \
do { \
if (*getLogLevel() >= SUB_LOG_DEBUG) ALOGD("%s: " fmt, __func__, ##__VA_ARGS__); \
} while (0)
#define SUBTITLE_LOGV(fmt, ...) \
do { \
if (*getLogLevel() >= SUB_LOG_DUMP) ALOGD("%s: " fmt, __func__, ##__VA_ARGS__); \
} while (0)
#else
#define SUBTITLE_LOGF(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
#define SUBTITLE_LOGE(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
#define SUBTITLE_LOGW(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
#define SUBTITLE_LOGI(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
#define SUBTITLE_LOGD(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
#define SUBTITLE_LOGV(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
#endif
#define SUBTITLE_LOGI_FUNC_IN() SUBTITLE_LOGI("ENTER")
#define SUBTITLE_LOGI_FUNC_OUT() SUBTITLE_LOGI("DONE")
#ifdef __cplusplus
}
#endif