📄 video.c
字号:
/* * * Copyright (c) 2001-2007 Sigma Designs, Inc. * All Rights Reserved. Proprietary and Confidential. * *//** @file video.c @brief functions to set up the emhwlib audio passthrough (no external chip interaction) @author Christian Wolff Sean.Sekwon.Choi*/// to enable or disable the debug messages of this source file, put 1 or 0 below#if 1#define LOCALDBG ENABLE#else#define LOCALDBG DISABLE#endif#include "common.h"#include "video.h"#include "../../dcc/include/dcc_macros.h"struct cap_video_instance { // Access struct RUA *pRUA; struct DCC *pDCC; struct rmcapture_options *cap_opt; // State RMuint32 STCTimerNumber; struct cap_video_config Setup; struct DCCVideoSource *pVideoSource; struct DCCSTCSource *pStcSource; RMuint32 ScalerModuleID; struct EMhwlibActiveFormatDescription afd;};// STC open and start (local function)static RMstatus cap_video_init_start_STC( struct cap_video_instance *pVideo){ RMstatus err; RMDBGLOG((FUNCNAME, "%s\n",__func__)); if (! pVideo->pStcSource) { struct DCCStcProfile stc_profile; // open first stc module stc_profile.STCID = pVideo->STCTimerNumber; stc_profile.master = Master_STC; stc_profile.stc_timer_id = 3 * pVideo->STCTimerNumber; stc_profile.stc_time_resolution = 90000; stc_profile.video_timer_id = 3 * pVideo->STCTimerNumber + 1; stc_profile.video_time_resolution = 90000; stc_profile.video_offset = 0; stc_profile.audio_timer_id = 3 * pVideo->STCTimerNumber + 2; stc_profile.audio_time_resolution = 90000; stc_profile.audio_offset = 0; err = DCCSTCOpen(pVideo->pDCC, &stc_profile, &(pVideo->pStcSource)); if (RMFAILED(err)) { RMDBGLOG((ENABLE, "Cannot open stc module: %s\n", RMstatusToString(err))); return RM_ERROR; } } DCCSTCSetTime(pVideo->pStcSource, 0, 90000); DCCSTCPlay(pVideo->pStcSource); return RM_OK;}// STC stop (local function)static RMstatus cap_video_stop_STC( struct cap_video_instance *pVideo){ RMstatus err = RM_OK; if (pVideo->pStcSource) { err = DCCSTCStop(pVideo->pStcSource); err = DCCSTCClose(pVideo->pStcSource); pVideo->pStcSource = NULL; } return err;}/* create the video instance */RMstatus cap_video_open( struct RUA *pRUA, struct DCC *pDCC, struct rmcapture_options *cap_opt, struct cap_video_instance **ppVideo){ RMstatus err = RM_OK; struct cap_video_instance *pVideo; RMDBGLOG((FUNCNAME, "%s\n",__func__)); // Sanity checks if (ppVideo == NULL) return RM_FATALINVALIDPOINTER; *ppVideo = NULL; if (pRUA == NULL) return RM_FATALINVALIDPOINTER; if (pDCC == NULL) return RM_FATALINVALIDPOINTER; if (cap_opt == NULL) return RM_FATALINVALIDPOINTER; // Allocate and clear local instance pVideo = (struct cap_video_instance *)RMMalloc(sizeof(struct cap_video_instance)); if (pVideo == NULL) { RMDBGLOG((ENABLE, "FATAL! Not enough memory for struct cap_video_instance!\n")); return RM_FATALOUTOFMEMORY; } RMMemset(pVideo, 0, sizeof(struct cap_video_instance)); *ppVideo = pVideo; // Set default and non-zero startup values pVideo->pRUA = pRUA; pVideo->pDCC = pDCC; pVideo->cap_opt = cap_opt; pVideo->STCTimerNumber = cap_opt->STCTimerNumber; pVideo->Setup.TVStandard = cap_opt->TVStandard; pVideo->Setup.InputColorSpace = cap_opt->InputColorSpace; pVideo->Setup.SurfaceColorSpace = cap_opt->SurfaceColorSpace; pVideo->Setup.SamplingMode = cap_opt-> SamplingMode; pVideo->Setup.ColorMode = cap_opt->ColorMode; pVideo->Setup.InputColorFormat = cap_opt->InputColorFormat; pVideo->Setup.PictureAspectRatio.X = cap_opt->PictureAspectRatio.X; pVideo->Setup.PictureAspectRatio.Y = cap_opt->PictureAspectRatio.Y; pVideo->Setup.InputModuleID = cap_opt->InputModuleID; pVideo->Setup.DigitalTimingSignal = cap_opt->DigitalTimingSignal; pVideo->Setup.UseVideoValid = cap_opt->UseVideoValid; pVideo->Setup.bussize = cap_opt->bussize; pVideo->Setup.override.ColorFormat = cap_opt->override.ColorFormat; pVideo->Setup.zoom_x = ZOOM_0; pVideo->Setup.zoom_y = ZOOM_0; pVideo->Setup.zoom_w = ZOOM_1; pVideo->Setup.zoom_h = ZOOM_1; pVideo->Setup.zoomstep = 1; pVideo->Setup.overscan_crop_amount = 5; // 5% (2.5% on each edge) err = cap_video_init_start_STC(pVideo); return err;}/* destroy the video instance, close open chips */RMstatus cap_video_close( struct cap_video_instance *pVideo){ RMstatus err = RM_OK; RMDBGLOG((FUNCNAME, "%s\n",__func__)); // Sanity checks if (pVideo == NULL) return RM_OK; // already closed // Free all available ressources //if (pVideo->disp_opt != NULL) { // err = cap_video_stop_passthrough(pVideo); //} else { err = cap_video_stop_capture(pVideo); //} err = cap_video_stop_STC(pVideo); RMFree(pVideo); return err;}RMstatus cap_video_get_config(struct cap_video_instance *pVideo, struct cap_video_config *pSetup){ RMDBGLOG((FUNCNAME, "%s\n",__func__)); // Sanity checks if (pVideo == NULL) return RM_FATALINVALIDPOINTER; if (pSetup == NULL) return RM_FATALINVALIDPOINTER; *pSetup = pVideo->Setup; // copy return RM_OK;}/* provide setup info to the video capture */RMstatus cap_video_set_config( struct cap_video_instance *pVideo, struct cap_video_config *pSetup) // necessary info for the video capture{ RMDBGLOG((FUNCNAME, "%s\n",__func__)); // Sanity checks if (pVideo == NULL) return RM_FATALINVALIDPOINTER; if (pSetup == NULL) return RM_FATALINVALIDPOINTER; pVideo->Setup = *pSetup; // copy return RM_OK;}/* helper function to reduce an aspect ratio */void cap_video_reduce_aspect_ratio( RMuint32 *X, RMuint32 *Y, RMuint32 boundary){ RMuint32 num, den, mod, max; if (*X && *Y) { num = *X; den = *Y; while ((mod = num % den) > 0) { num = den; den = mod; } (*X) /= den; (*Y) /= den; if (boundary) { max = RMmax(*X, *Y); if (max > boundary) { den = (max + boundary - 1) / boundary; *X /= den; *Y /= den; } } }}/* helper function, returns frame size and interlaced status */RMstatus cap_video_get_frame_size( struct cap_video_instance *pVideo, enum EMhwlibTVStandard standard, RMuint32 *x_size, RMuint32 *y_size, RMbool *interlaced){ RMstatus err; struct EMhwlibTVFormatDigital format; RMDBGLOG((FUNCNAME, "%s\n",__func__)); // Sanity checks if (pVideo == NULL) return RM_FATALINVALIDPOINTER; err = RUAExchangeProperty(pVideo->pRUA, DisplayBlock, RMDisplayBlockPropertyID_TVFormatDigital, &standard, sizeof(standard), &format, sizeof(format)); if (RMSUCCEEDED(err)) { if (interlaced) *interlaced = format.TopFieldHeight ? TRUE : FALSE; if (x_size) *x_size = format.ActiveWidth; if (y_size) { *y_size = format.ActiveHeight; if (format.TopFieldHeight) *y_size += format.ActiveHeight - format.YOffsetBottom + format.YOffsetTop; } } return err;}/* helper function, returns the inherent aspect ratio of a video mode */RMstatus cap_video_get_aspect_ratio_from_video_mode( enum EMhwlibTVStandard TVStandard, struct EMhwlibTVFormatDigital *pTVFormat, RMbool wide, // ambiguous modes (SDTV,EDTV): FALSE=4:3, TRUE=16:9 anamorphic RMuint32 *asp_x, RMuint32 *asp_y){ RMDBGLOG((FUNCNAME, "%s\n",__func__)); if ((asp_x == NULL) || (asp_y == NULL)) return RM_FATALINVALIDPOINTER; // determine aspect ratio from video mode switch (TVStandard) { case EMhwlibTVStandard_Custom: if (pTVFormat) { *asp_x = pTVFormat->ActiveWidth; *asp_y = pTVFormat->ActiveHeight; cap_video_reduce_aspect_ratio(asp_x, asp_y, 0); } else { *asp_x = 4; *asp_y = 3; } break; case EMhwlibTVStandard_HDMI_720p59: case EMhwlibTVStandard_HDMI_720p60: case EMhwlibTVStandard_HDMI_1080i59: case EMhwlibTVStandard_HDMI_1080i60: case EMhwlibTVStandard_HDMI_1080p59: case EMhwlibTVStandard_HDMI_1080p60: case EMhwlibTVStandard_HDMI_720p50: case EMhwlibTVStandard_HDMI_1080i50: case EMhwlibTVStandard_HDMI_1080p50: case EMhwlibTVStandard_HDMI_1080p23: case EMhwlibTVStandard_HDMI_1080p24: case EMhwlibTVStandard_HDMI_1080p25: case EMhwlibTVStandard_HDMI_1080p29: case EMhwlibTVStandard_HDMI_1080p30: case EMhwlibTVStandard_HDMI_1080i50_1250: case EMhwlibTVStandard_HDMI_1080i100: case EMhwlibTVStandard_HDMI_720p100: case EMhwlibTVStandard_HDMI_1080i119: case EMhwlibTVStandard_HDMI_1080i120: case EMhwlibTVStandard_HDMI_720p119: case EMhwlibTVStandard_HDMI_720p120: case EMhwlibTVStandard_1080p60: case EMhwlibTVStandard_1080p59: case EMhwlibTVStandard_1080p50: case EMhwlibTVStandard_1080i60: case EMhwlibTVStandard_1080i59: case EMhwlibTVStandard_1080i50: case EMhwlibTVStandard_1080i48: case EMhwlibTVStandard_1080i47: case EMhwlibTVStandard_1080p30:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -