📄 librmmonitoring.c
字号:
/* * * Copyright (c) Sigma Designs, Inc. 2005. All rights reserved. * *//** * @file librmmonitoring.c * @brief Library of functions for monitoring EM86xx decoders. * * @author Sylvain Garrigues */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#define ALLOW_OS_CODE 1#include "rmrtk/include/rmrtk.h"#include "../include/librmmonitoring.h"#define WAIT_TIMEOUT_US 1000000#define FONT_FILE "Vera.ttf"#define FONT_FG_COLOR 0xff99ff99#define FONT_SCALE 14 #define MAX_LINES 32 /* maximum number of lines to display */#define BUFFER_SIZE 512 /* maximum number of bytes to read per /proc entries */#define STC_FILENAME "/proc/driver/em8xxx/0/monitoring/STC/STC0"#define VD_FILENAME "/proc/driver/em8xxx/0/monitoring/video/video_decoder0"#define AD_FILENAME "/proc/driver/em8xxx/0/monitoring/audio/audio_decoder0"#if (EM86XX_MODE == EM86XX_MODEID_STANDALONE)#define DMA0_FILENAME "/proc/driver/llad/pools/pool0"#define DMA1_FILENAME "/proc/driver/llad/pools/pool1"#else#define DMA0_FILENAME "/proc/driver/mum/0/DMA/pool0"#define DMA1_FILENAME "/proc/driver/mum/0/DMA/pool1"#endif#define GRAPH_SIDE_MARGIN 50#define GRAPH_BOTTOM_MARGIN 40#define GRAPH_COLORS_MAX 6static void draw_string(RMascii *, const RMuint32, const RMuint32, RMint32 *);static struct DCC *pDCC;static struct RUA *pRUA;static struct DCCVideoSource *pOSDSource;static RMTrtk rtk;static int fvideo_decoder, faudio_decoder, fstc, fdmapool0, fdmapool1;static RtkRect outputRect[MAX_LINES]; /* rectangles in which strings are written */static RMuint32 graph_osd_width;static RMuint32 graph_osd_height;static RMuint32 graph_current_column;static RMuint32 graph_color_index;static RMuint32 graph_color_table[GRAPH_COLORS_MAX] = {0xffff0000, 0xff0000ff, 0xffffff00, 0xffff00ff, 0xff00ff00, 0xff00ffff};static void graph_init(RMuint32 width, RMuint32 height){ RtkProp prop; RtkRect rect; /* Remember the OSD width and height */ graph_osd_width = width; graph_osd_height = height; /* The current column starts at the left margin */ graph_current_column = GRAPH_SIDE_MARGIN; /* Set the color property to the foreground color */ prop.scale = 1; prop.fgColor = FONT_FG_COLOR; prop.bgColor = FONT_FG_COLOR; prop.lineWidth = 0; prop.lineColor = FONT_FG_COLOR; /* Draw the top and bottom boundaries of the graph */ rect.width = graph_osd_width - (2 * GRAPH_SIDE_MARGIN); rect.height = 1; rect.x = GRAPH_SIDE_MARGIN; rect.y = graph_osd_height - GRAPH_BOTTOM_MARGIN; RMFRTKDrawRect(rtk, &rect, &prop); rect.y = graph_osd_height - GRAPH_BOTTOM_MARGIN - 100; RMFRTKDrawRect(rtk, &rect, &prop);}static void graph_erase_current_column(){ RtkProp prop; RtkRect rect; RtkPoint point; /* Set the color property to clear */ prop.scale = 1; prop.fgColor = 0xff000000; prop.bgColor = 0xff000000; prop.lineWidth = 0; prop.lineColor = 0xff000000; /* Erase the current column */ rect.width = 1; rect.height = 101; rect.x = graph_current_column; rect.y = graph_osd_height - GRAPH_BOTTOM_MARGIN - 100; RMFRTKDrawRect(rtk, &rect, &prop); /* Redraw the top and bottom pixels of the boundaries of the graph */ point.x = graph_current_column; point.y = graph_osd_height - GRAPH_BOTTOM_MARGIN; RMFRTKSetPixel(rtk, &point, FONT_FG_COLOR); point.y = graph_osd_height - GRAPH_BOTTOM_MARGIN - 100; RMFRTKSetPixel(rtk, &point, FONT_FG_COLOR); /* Reset the graph color table index */ graph_color_index = 0;}static void graph_advance_current_column(){ RtkProp prop; RtkRect rect; /* Advance the current column, wrapping if necessary */ graph_current_column++; if (graph_current_column + GRAPH_SIDE_MARGIN > graph_osd_width) graph_current_column = GRAPH_SIDE_MARGIN; /* Set the color property to the foreground color */ prop.scale = 1; prop.fgColor = FONT_FG_COLOR; prop.bgColor = FONT_FG_COLOR; prop.lineWidth = 0; prop.lineColor = FONT_FG_COLOR; /* Draw short vertical stubs at the top and bottom boundaries of the graph */ /* to mark the location of the current column */ rect.width = 1; rect.height = 10; rect.x = graph_current_column; rect.y = graph_osd_height - GRAPH_BOTTOM_MARGIN - 100; RMFRTKDrawRect(rtk, &rect, &prop); rect.y = graph_osd_height - GRAPH_BOTTOM_MARGIN - 9; RMFRTKDrawRect(rtk, &rect, &prop);}void update_monitoring(){ const char delimiters[] = "\n"; RMascii buffer[BUFFER_SIZE]; RMascii *running, *token; RMint32 line_number = 0; RMuint32 current_y = 40; RtkProp prop = {0, 0xff000000}; int times = 0; putchar('.'); fflush(stdout); /* Erase the current column on the graph */ graph_erase_current_column(); /* Read STC information from /proc entry. */ lseek(fstc, 0, SEEK_SET); memset(buffer, '\0', BUFFER_SIZE); read(fstc, buffer, BUFFER_SIZE - 1); running = buffer; token = strsep(&running, delimiters); while (running != NULL) { RMFRTKDrawRect(rtk, &outputRect[line_number], &prop); draw_string(token, 50, current_y, &line_number); current_y += FONT_SCALE; token = strsep(&running, delimiters); } current_y += FONT_SCALE; /* skip a line */ /* Read video decoder information from /proc entry. */ lseek(fvideo_decoder, 0, SEEK_SET); memset(buffer, '\0', BUFFER_SIZE); read(fvideo_decoder, buffer, BUFFER_SIZE - 1); running = buffer; token = strsep(&running, delimiters); while (running != NULL) { RMFRTKDrawRect(rtk, &outputRect[line_number], &prop); draw_string(token, 50, current_y, &line_number); current_y += FONT_SCALE; token = strsep(&running, delimiters); } current_y += FONT_SCALE; /* skip a line */ /* Read audio decoder information from /proc entry. */ lseek(faudio_decoder, 0, SEEK_SET); memset(buffer, '\0', BUFFER_SIZE); read(faudio_decoder, buffer, BUFFER_SIZE - 1); running = buffer; token = strsep(&running, delimiters); while (running != NULL) { RMFRTKDrawRect(rtk, &outputRect[line_number], &prop); draw_string(token, 50, current_y, &line_number); current_y += FONT_SCALE; token = strsep(&running, delimiters); } current_y += FONT_SCALE; /* Read DMA pool 0 decoder information from /proc entry. */ lseek(fdmapool0, 0, SEEK_SET); memset(buffer, '\0', BUFFER_SIZE); read(fdmapool0, buffer, BUFFER_SIZE - 1); running = buffer; token = strsep(&running, delimiters); while (running != NULL) { times++; RMFRTKDrawRect(rtk, &outputRect[line_number], &prop); draw_string(token, 50, current_y, &line_number); current_y += FONT_SCALE; token = strsep(&running, delimiters); } if (times == 1) { RMFRTKDrawRect(rtk, &outputRect[line_number++], &prop); RMFRTKDrawRect(rtk, &outputRect[line_number++], &prop); } times = 0; current_y += FONT_SCALE; /* Read DMA pool 1 decoder information from /proc entry. */ lseek(fdmapool1, 0, SEEK_SET); memset(buffer, '\0', BUFFER_SIZE); read(fdmapool1, buffer, BUFFER_SIZE - 1); running = buffer; token = strsep(&running, delimiters); while (running != NULL) { times++; RMFRTKDrawRect(rtk, &outputRect[line_number], &prop); draw_string(token, 50, current_y, &line_number); current_y += FONT_SCALE; token = strsep(&running, delimiters); } if (times == 1) { RMFRTKDrawRect(rtk, &outputRect[line_number++], &prop); RMFRTKDrawRect(rtk, &outputRect[line_number++], &prop); } times = 0; current_y += FONT_SCALE; /* Advance to the next column in the graph */ graph_advance_current_column();}static void draw_string(RMascii *text, const RMuint32 x, const RMuint32 y, RMint32 *line_number){ RtkPoint position; RtkProp prop; RMascii *ch; position.x = x; position.y = y; prop.scale = FONT_SCALE; prop.fgColor = FONT_FG_COLOR; prop.bgColor = 0x00000000; /* Search for a '%' within the string */ if ((ch = strchr(text, '%')) != NULL) { /* Check if the previous character is a number */ ch--; if ((ch >= text) && (*ch >= '0') && (*ch <= '9')) { RtkPoint pixel; RMuint32 percentage = *ch - '0'; /* Assemble the percentage from characters within the string */ ch--; if ((ch >= text) && (*ch >= '0') && (*ch <= '9')) { percentage += ((*ch - '0') * 10); ch--; if ((ch >= text) && (*ch == '1'))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -