📄 dec.c
字号:
/* * dec.c * * ============================================================================ * Copyright (c) Texas Instruments Inc 2005 * * Use of this software is controlled by the terms and conditions found in the * license agreement under which this software has been supplied or provided. * ============================================================================ *//* Standard Linux headers */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <fcntl.h>#include <errno.h>/* Davinci EVM utility libraries */#include <msp430lib.h>#include <simplewidget.h>/* Application header file */#include "interface.h"/* The font size */#define PTSIZE 20/* The 0-7 transparency value to use for the OSD */#define OSD_TRANSPARENCY 0x66/* The demo diagrams to show on the video window */#define DEMO_DIAGRAM_NTSC "data/pics/decode_ntsc.uyvy"#define DEMO_DIAGRAM_PAL "data/pics/decode_pal.uyvy"#define NAV_BUTTON_X 290#define NAV_BUTTON_Y 310#define WRONG_BUTTON_X 325#define WRONG_BUTTON_Y 205/* The strings to draw on the screen */#define DEMONAMESTRING "Decode"#define H264CODECSTRING "H.264 BP Video"#define MPEG4CODECSTRING "MPEG4 Video"#define MPEG2CODECSTRING "MPEG2 Video"#define G711CODECSTRING "G.711 Speech"#define MPEG1L2CODECSTRING "MPEG1L2 Audio"#define AACCODECSTRING "AAC Audio"#define RESOLUTIONSTRING "D1 (720x480)"#define DISPLAYSTRING "NTSC display"#define AUDIOSAMFREQSTRING "44.1KHz samp rate"#define SPEECHSAMFREQSTRING "8KHz samp rate"/* Selector color */#define SELECTOR_R 0xff#define SELECTOR_G 0#define SELECTOR_B 0#define FILESELECTOR_X 35#define FILESELECTOR_Y YSCALE(20)#define FILESELECTOR_W 370#define FILESELECTOR_H YSCALE(180)enum InitLevels { CREATEDINTERFACE = 1, MSP430LIBINITIALIZED,};typedef struct Button { simplewidget_png *pressedImgPtr; simplewidget_png *origImgPtr; int x; int y;} Button; /* OSD widgets */static simplewidget_screen simpleScreen = NULL;static simplewidget_png infoImg = NULL;static simplewidget_png navImg = NULL;static simplewidget_png navLeftImg = NULL;static simplewidget_png navRightImg = NULL;static simplewidget_png navUpImg = NULL;static simplewidget_png navDownImg = NULL;static simplewidget_png ctrlImg = NULL;static simplewidget_png ctrlPlayImg = NULL;static simplewidget_png ctrlPauseImg = NULL;static simplewidget_png ctrlStopImg = NULL;static simplewidget_png ctrlRecImg = NULL;static simplewidget_png wrongImg = NULL;static simplewidget_png noWrongImg = NULL;static simplewidget_text demoNameText = NULL;static simplewidget_text h264VideoCodecText = NULL;static simplewidget_text mpeg4VideoCodecText = NULL;static simplewidget_text mpeg2VideoCodecText = NULL;static simplewidget_text aacAudioCodecText = NULL;static simplewidget_text mpeg1l2AudioCodecText = NULL;static simplewidget_text g711SpeechCodecText = NULL;static simplewidget_text resolutionText = NULL;static simplewidget_text displayText = NULL;static simplewidget_text speechSampleFreqText = NULL;static simplewidget_text audioSampleFreqText = NULL;static simplewidget_text *videoCodecTextPtr;static simplewidget_text *soundCodecTextPtr;static int osdTransparency = OSD_TRANSPARENCY;static int osdVisible = 1;enum Buttons { CTRLPLAY, CTRLPAUSE, CTRLSTOP, CTRLREC, NAVPLUS, NAVMINUS, NAVUP, NAVDOWN, WRONG};static Button buttons[9] = { { &ctrlPlayImg, &ctrlImg, CTRL_BUTTON_X, CTRL_BUTTON_Y }, { &ctrlPauseImg, &ctrlImg, CTRL_BUTTON_X, CTRL_BUTTON_Y }, { &ctrlStopImg, &ctrlImg, CTRL_BUTTON_X, CTRL_BUTTON_Y }, { &ctrlRecImg, &ctrlImg, CTRL_BUTTON_X, CTRL_BUTTON_Y }, { &navRightImg, &navImg, NAV_BUTTON_X, NAV_BUTTON_Y }, { &navLeftImg, &navImg, NAV_BUTTON_X, NAV_BUTTON_Y }, { &navUpImg, &navImg, NAV_BUTTON_X, NAV_BUTTON_Y }, { &navDownImg, &navImg, NAV_BUTTON_X, NAV_BUTTON_Y }, { &wrongImg, &noWrongImg, WRONG_BUTTON_X, WRONG_BUTTON_Y }};#define NUM_FILE_COMBOS 5#define MAX_FILENAME_LENGTH 40#define DAVINCIEFFECT_MPEG2_NTSC "data/videos/davincieffect_ntsc.m2v"#define DAVINCIEFFECT_MPEG2_PAL "data/videos/davincieffect_pal.m2v"#define DAVINCIEFFECT_H264_NTSC "data/videos/davincieffect_ntsc.264"#define DAVINCIEFFECT_H264_PAL "data/videos/davincieffect_pal.264"#define DAVINCIEFFECT_MPEG4_NTSC "data/videos/davincieffect_ntsc.mpeg4"#define DAVINCIEFFECT_MPEG4_PAL "data/videos/davincieffect_pal.mpeg4"#define USERMADE_MPEG4 "data/videos/demo.mpeg4"#define USERMADE_H264 "data/videos/demo.264"#define DAVINCIEFFECT_G711 "data/sounds/davincieffect.g711"#define DAVINCIEFFECT_AAC "data/sounds/davincieffect.aac"#define DAVINCIEFFECT_MPEG1L2 "data/sounds/davincieffect.mp2"#define USERMADE_MPEG4_G711 "data/sounds/demompeg4.g711"#define USERMADE_H264_G711 "data/sounds/demo264.g711"typedef struct FileCombo { char videoFile[MAX_FILENAME_LENGTH]; char soundFile[MAX_FILENAME_LENGTH];} FileCombo;FileCombo fileCombos[NUM_FILE_COMBOS];static int fileComboIdx = 0;static int videoAvail;static int soundAvail;/****************************************************************************** * drawSelection ******************************************************************************/static void drawSelection(void){ FileCombo *combo = &fileCombos[fileComboIdx]; struct stat st; size_t videoSize = 0; size_t soundSize = 0; char *extension; simplewidget_text fileInfoText; char fileInfo[1024]; char *fileName; if (stat(combo->videoFile, &st) == -1) { videoAvail = 0; } else { videoAvail = 1; videoSize = st.st_size / 1024; } if (stat(combo->soundFile, &st) == -1) { soundAvail = 0; } else { soundAvail = 1; soundSize = st.st_size / 1024; } /* Draw the red background for text */ if (simplewidget_screen_draw_rectangle(simpleScreen, FILESELECTOR_X, FILESELECTOR_Y, FILESELECTOR_W, FILESELECTOR_H, SELECTOR_R, SELECTOR_G, SELECTOR_B) == FAILURE) { ERR("Failed to draw rectangle\n"); return; } /* Remove the old entry for video codec */ if (simplewidget_screen_draw_rectangle(simpleScreen, COLUMN_3, YSCALE(55), 220, YSCALE(30), 0, 0, 0) == FAILURE) { ERR("Failed to draw rectangle\n"); return; } extension = rindex(combo->videoFile, '.'); if (extension == NULL) { // shouldn't happen ERR("Video file without extension (%s)\n", combo->videoFile); videoAvail = 0; } if (strcmp(extension, ".m2v") == 0) { videoCodecTextPtr = &mpeg2VideoCodecText; } else if (strcmp(extension, ".264") == 0) { videoCodecTextPtr = &h264VideoCodecText; } else if (strcmp(extension, ".mpeg4") == 0) { videoCodecTextPtr = &mpeg4VideoCodecText; } else { ERR("Unknown video file extension: %s\n", extension); return; } fileName = rindex(combo->videoFile, '/'); if (fileName == NULL) { fileName = combo->videoFile; } else { fileName++; // Skip the '/' } if (simplewidget_text_show(*videoCodecTextPtr, simpleScreen) == -1) { ERR("Failed to show video codec text\n"); return; } sprintf(fileInfo, "Video file: %s", fileName); if (simplewidget_text_create(COLUMN_1, ROW_1, 16, fileInfo, &fileInfoText) == -1) { ERR("Failed to create video file info text\n"); return; } if (simplewidget_text_show(fileInfoText, simpleScreen) == -1) { ERR("Failed to show video file info text\n"); return; } simplewidget_text_delete(fileInfoText); if (videoAvail) { sprintf(fileInfo, "Size: %d KB", videoSize); if (simplewidget_text_create(COLUMN_1, ROW_2, 16, fileInfo, &fileInfoText) == -1) { ERR("Failed to create video file info text\n"); return; } if (simplewidget_text_show(fileInfoText, simpleScreen) == -1) { ERR("Failed to show video file info text\n"); return; } simplewidget_text_delete(fileInfoText); } else { sprintf(fileInfo, "File not found!"); if (simplewidget_text_create(COLUMN_1, ROW_2, 16, fileInfo, &fileInfoText) == -1) { ERR("Failed to create video file info text\n"); return; } if (simplewidget_text_show(fileInfoText, simpleScreen) == -1) { ERR("Failed to show video file info text\n"); return; } simplewidget_text_delete(fileInfoText); } /* Remove the old entry for sound codec */ if (simplewidget_screen_draw_rectangle(simpleScreen, COLUMN_3, YSCALE(85), 220, YSCALE(30), 0, 0, 0) == FAILURE) { ERR("Failed to draw rectangle\n"); return; } extension = rindex(combo->soundFile, '.'); if (extension == NULL) { // shouldn't happen ERR("Sound file without extension (%s)\n", combo->soundFile); return; } if (strcmp(extension, ".g711") == 0) { soundCodecTextPtr = &g711SpeechCodecText; } else if (strcmp(extension, ".mp2") == 0) { soundCodecTextPtr = &mpeg1l2AudioCodecText; } else if (strcmp(extension, ".aac") == 0) { soundCodecTextPtr = &aacAudioCodecText; } else { ERR("Unknown sound file extension: %s\n", extension); return; } fileName = rindex(combo->soundFile, '/'); if (fileName == NULL) { fileName = combo->soundFile; } else { fileName++; // Skip the '/' } if (simplewidget_text_show(*soundCodecTextPtr, simpleScreen) == -1) { ERR("Failed to show sound codec text\n"); return; } sprintf(fileInfo, "Sound file: %s", fileName); if (simplewidget_text_create(COLUMN_1, ROW_4, 16, fileInfo, &fileInfoText) == -1) { ERR("Failed to create sound file info text\n"); return; } if (simplewidget_text_show(fileInfoText, simpleScreen) == -1) { ERR("Failed to show sound file info text\n"); return; } simplewidget_text_delete(fileInfoText); if (soundAvail) { fileName = rindex(combo->soundFile, '/'); sprintf(fileInfo, "Size: %d KB", soundSize); if (simplewidget_text_create(COLUMN_1, ROW_5, 16, fileInfo, &fileInfoText) == -1) { ERR("Failed to create sound file info text\n"); return; } if (simplewidget_text_show(fileInfoText, simpleScreen) == -1) { ERR("Failed to show sound file info text\n"); return; } simplewidget_text_delete(fileInfoText); } else { fileName = rindex(combo->soundFile, '/'); sprintf(fileInfo, "File not found!"); if (simplewidget_text_create(COLUMN_1, ROW_5, 16, fileInfo, &fileInfoText) == -1) { ERR("Failed to create sound file info text\n"); return; } if (simplewidget_text_show(fileInfoText, simpleScreen) == -1) { ERR("Failed to show sound file info text\n"); return; } simplewidget_text_delete(fileInfoText); }}/****************************************************************************** * uiPressButton ******************************************************************************/static int uiPressButton(enum Buttons btnIdx){ Button *btnPtr = &buttons[btnIdx]; if (simplewidget_png_show(*btnPtr->pressedImgPtr, simpleScreen, btnPtr->x, YSCALE(btnPtr->y)) == -1) { ERR("Failed to show pressed button png image\n"); return FAILURE; } usleep(500000); if (simplewidget_png_show(*btnPtr->origImgPtr, simpleScreen, btnPtr->x, YSCALE(btnPtr->y)) == -1) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -