void disableVideoOutput(bool disable) { int arg=disable?1:0; int fd; printf("[controld] videoOutput %s\n", disable?"off":"on"); if((fd = open(SAA7126_DEVICE,O_RDWR|O_NONBLOCK)) < 0) { perror("[controld] SAA DEVICE: "); return; } if ( (ioctl(fd,SAAIOSPOWERSAVE,&arg) < 0)) { perror("[controld] IOCTL: "); close(fd); return; } close(fd); /* arg=disable?0:0xf; if((fd = open("/dev/dbox/fp0",O_RDWR|O_NONBLOCK)) < 0) { perror("[controld] FP DEVICE: "); return; } if ( (ioctl(fd,FP_IOCTL_LCD_DIMM,&arg) < 0)) { perror("[controld] IOCTL: "); close(fd); return; } close(fd); */ if(!disable) { zapit.startPlayBack(); setvideooutput(settings.videooutput, false); setVideoFormat(settings.videoformat, false); } else { setvideooutput(0, false); setVideoFormat(-1, false); zapit.stopPlayBack(); } }
void VideoShader::update(VideoMaterial *material) { if (!material->bind()) return; const VideoFormat fmt(material->currentFormat()); //format is out of date because we may use the same shader for different formats setVideoFormat(fmt); // uniforms begin program()->bind(); //glUseProgram(id). for glUniform // all texture ids should be binded when renderering even for packed plane! const int nb_planes = fmt.planeCount(); //number of texture id for (int i = 0; i < nb_planes; ++i) { // use glUniform1i to swap planes. swap uv: i => (3-i)%3 // TODO: in shader, use uniform sample2D u_Texture[], and use glUniform1iv(u_Texture, 3, {...}) program()->setUniformValue(textureLocation(i), (GLint)i); } if (nb_planes < textureLocationCount()) { for (int i = nb_planes; i < textureLocationCount(); ++i) { program()->setUniformValue(textureLocation(i), (GLint)(nb_planes - 1)); } } //qDebug() << "color mat " << material->colorMatrix(); program()->setUniformValue(colorMatrixLocation(), material->colorMatrix()); program()->setUniformValue(bppLocation(), (GLfloat)material->bpp()); //program()->setUniformValue(matrixLocation(), material->matrix()); //what about sgnode? state.combindMatrix()? // uniform end. attribute begins }
status_t FFMPEGSoftCodec::setVideoFormat( const sp<MetaData> &meta, const char* mime, sp<IOMX> OMXhandle, IOMX::node_id nodeID, bool isEncoder, OMX_VIDEO_CODINGTYPE *compressionFormat) { sp<AMessage> msg = new AMessage(); msg->clear(); convertMetaDataToMessage(meta, &msg); return setVideoFormat(msg, mime, OMXhandle, nodeID, isEncoder, compressionFormat); }
FreenectDevice(freenect_context *_ctx, int _index) : m_video_resolution(FREENECT_RESOLUTION_MEDIUM), m_depth_resolution(FREENECT_RESOLUTION_MEDIUM) { if(freenect_open_device(_ctx, &m_dev, _index) < 0) throw std::runtime_error("Cannot open Kinect"); freenect_set_user(m_dev, this); setVideoFormat(FREENECT_VIDEO_RGB, FREENECT_RESOLUTION_MEDIUM); setDepthFormat(FREENECT_DEPTH_11BIT, FREENECT_RESOLUTION_MEDIUM); freenect_set_depth_callback(m_dev, freenect_depth_callback); freenect_set_video_callback(m_dev, freenect_video_callback); }
void CControldAspectRatioNotifier::aspectRatioChanged( int newAspectRatio ) { //printf("[controld] CControldAspectRatioNotifier::aspectRatioChanged( %d ) \n", newAspectRatio); aspectRatio= newAspectRatio; if ( settings.videoformat == 0 ) { switch (newAspectRatio) { case 2 : // 4:3 setVideoFormat( 2, false ); break; case 3 : // 16:9 case 4 : // 2,21:1 setVideoFormat( 1, false ); break; default: printf("[controld] Unknown aspectRatio: %d", newAspectRatio); } } }
int main(int argc, char **argv) { int listenfd, connfd; printf("Controld $Id: controld.cpp,v 1.76.2.1 2002/10/24 20:34:32 thegoodguy Exp $\n\n"); switch (fork()) { case -1: perror("[controld] fork"); return -1; case 0: break; default: return 0; } if (setsid() == -1) { perror("[controld] setsid"); return -1; } eventServer = new CEventServer; struct sockaddr_un servaddr; int clilen; memset(&servaddr, 0, sizeof(struct sockaddr_un)); servaddr.sun_family = AF_UNIX; strcpy(servaddr.sun_path, CONTROLD_UDS_NAME); clilen = sizeof(servaddr.sun_family) + strlen(servaddr.sun_path); unlink(CONTROLD_UDS_NAME); //network-setup if ((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { perror("socket"); } if ( bind(listenfd, (struct sockaddr*) &servaddr, clilen) <0 ) { perror("[controld] bind failed...\n"); exit(-1); } if (listen(listenfd, 5) !=0) { perror("[controld] listen failed...\n"); exit( -1 ); } //busyBox signal(SIGHUP,sig_catch); signal(SIGINT,sig_catch); signal(SIGQUIT,sig_catch); signal(SIGTERM,sig_catch); /* load configuration */ config = new CConfigFile(','); if (!config->loadConfig(CONF_FILE)) { /* set defaults if no configuration file exists */ printf("[controld] %s not found\n", CONF_FILE); } settings.volume = config->getInt32("volume", 100); settings.volume_avs = config->getInt32("volume_avs", 100); settings.mute = config->getBool("mute", false); settings.mute_avs = config->getBool("mute_avs", false); settings.videooutput = config->getInt32("videooutput", 1); // fblk1 - rgb settings.videoformat = config->getInt32("videoformat", 2); // fnc2 - 4:3 setBoxType(); // dummy set - liest den aktuellen Wert aus! watchDog = new CEventWatchDog(); aspectRatioNotifier = new CControldAspectRatioNotifier(); watchDog->registerNotifier(WDE_VIDEOMODE, aspectRatioNotifier); //init audioControl::setVolume(map_volume(settings.volume_avs, true)); zapit.setVolume(map_volume(settings.volume, false), map_volume(settings.volume, false)); lcdd.setVolume(settings.volume_avs); // we could also display settings.volume at startup audioControl::setMute(settings.mute_avs); zapit.muteAudio(settings.mute); lcdd.setMute(settings.mute || settings.mute_avs); setvideooutput(settings.videooutput); setVideoFormat(settings.videoformat, false); try { struct CControld::Header rmessage; while(true) { connfd = accept(listenfd, (struct sockaddr*) &servaddr, (socklen_t*) &clilen); memset(&rmessage, 0, sizeof(rmessage)); read(connfd,&rmessage,sizeof(rmessage)); parse_command(connfd, &rmessage); close(connfd); } } catch (std::exception& e) { printf("[controld] caught std-exception in main-thread %s!\n", e.what()); } catch (...) { printf("[controld] caught exception in main-thread!\n"); } }
void parse_command(int connfd, CControld::Header * rmessage) { if(rmessage->version != CControld::ACTVERSION) { perror("[controld] wrong version\n"); return; } switch (rmessage->cmd) { case CControld::CMD_SHUTDOWN: shutdownBox(); break; case CControld::CMD_SAVECONFIG: saveSettings(); break; case CControld::CMD_SETVOLUME: case CControld::CMD_SETVOLUME_AVS: CControld::commandVolume msg_commandVolume; read(connfd, &msg_commandVolume, sizeof(msg_commandVolume)); if (rmessage->cmd == CControld::CMD_SETVOLUME) { settings.volume = msg_commandVolume.volume; config->setInt32("volume", settings.volume); zapit.setVolume(map_volume(msg_commandVolume.volume, false), map_volume(msg_commandVolume.volume, false)); } else { settings.volume_avs = msg_commandVolume.volume; config->setInt32("volume_avs", settings.volume_avs); audioControl::setVolume(map_volume(msg_commandVolume.volume, true)); } lcdd.setVolume(msg_commandVolume.volume); eventServer->sendEvent(CControldClient::EVT_VOLUMECHANGED, CEventServer::INITID_CONTROLD, &msg_commandVolume.volume, sizeof(msg_commandVolume.volume)); break; case CControld::CMD_MUTE: settings.mute = true; config->setBool("mute", settings.mute); zapit.muteAudio(true); lcdd.setMute(true); eventServer->sendEvent(CControldClient::EVT_MUTECHANGED, CEventServer::INITID_CONTROLD, &settings.mute, sizeof(settings.mute)); break; case CControld::CMD_MUTE_AVS: settings.mute_avs = true; config->setBool("mute_avs", settings.mute_avs); audioControl::setMute(true); lcdd.setMute(true); eventServer->sendEvent(CControldClient::EVT_MUTECHANGED, CEventServer::INITID_CONTROLD, &settings.mute_avs, sizeof(settings.mute_avs)); break; case CControld::CMD_UNMUTE: settings.mute = false; config->setBool("mute", settings.mute); zapit.muteAudio(false); lcdd.setMute(settings.mute_avs); eventServer->sendEvent(CControldClient::EVT_MUTECHANGED, CEventServer::INITID_CONTROLD, &settings.mute_avs, sizeof(settings.mute_avs)); break; case CControld::CMD_UNMUTE_AVS: settings.mute_avs = false; config->setBool("mute_avs", settings.mute_avs); audioControl::setMute(false); lcdd.setMute(settings.mute); eventServer->sendEvent(CControldClient::EVT_MUTECHANGED, CEventServer::INITID_CONTROLD, &settings.mute, sizeof(settings.mute)); break; case CControld::CMD_SETANALOGMODE: CControld::commandAnalogMode msgmd; read(connfd, &msgmd, sizeof(msgmd)); zapit.setAudioMode(msgmd.mode); break; case CControld::CMD_SETVIDEOFORMAT: //printf("[controld] set videoformat\n"); CControld::commandVideoFormat msg2; read(connfd, &msg2, sizeof(msg2)); setVideoFormat(msg2.format); break; case CControld::CMD_SETVIDEOOUTPUT: //printf("[controld] set videooutput\n"); CControld::commandVideoOutput msg3; read(connfd, &msg3, sizeof(msg3)); setvideooutput(msg3.output); break; case CControld::CMD_SETBOXTYPE: //printf("[controld] set boxtype\n"); //-------------------dummy!!!!!!!!!! CControld::commandBoxType msg4; read(connfd, &msg4, sizeof(msg4)); setBoxType(); break; case CControld::CMD_SETSCARTMODE: //printf("[controld] set scartmode\n"); CControld::commandScartMode msg5; read(connfd, &msg5, sizeof(msg5)); setScartMode(msg5.mode); break; case CControld::CMD_SETVIDEOPOWERDOWN: //printf("[controld] set scartmode\n"); CControld::commandVideoPowerSave msg10; read(connfd, &msg10, sizeof(msg10)); disableVideoOutput(msg10.powerdown); break; case CControld::CMD_GETVOLUME: case CControld::CMD_GETVOLUME_AVS: CControld::responseVolume msg_responseVolume; msg_responseVolume.volume = (rmessage->cmd == CControld::CMD_GETVOLUME) ? settings.volume : settings.volume_avs; write(connfd, &msg_responseVolume, sizeof(msg_responseVolume)); break; case CControld::CMD_GETMUTESTATUS: case CControld::CMD_GETMUTESTATUS_AVS: CControld::responseMute msg_responseMute; msg_responseMute.mute = (rmessage->cmd == CControld::CMD_GETMUTESTATUS) ? settings.mute : settings.mute_avs; write(connfd, &msg_responseMute, sizeof(msg_responseMute)); break; case CControld::CMD_GETVIDEOFORMAT: //printf("[controld] get videoformat (fnc)\n"); CControld::responseVideoFormat msg8; msg8.format = settings.videoformat; write(connfd,&msg8,sizeof(msg8)); break; case CControld::CMD_GETASPECTRATIO: //printf("[controld] get videoformat (fnc)\n"); CControld::responseAspectRatio msga; msga.aspectRatio = aspectRatio; write(connfd,&msga,sizeof(msga)); break; case CControld::CMD_GETVIDEOOUTPUT: //printf("[controld] get videooutput (fblk)\n"); CControld::responseVideoOutput msg9; msg9.output = settings.videooutput; write(connfd,&msg9,sizeof(msg9)); break; case CControld::CMD_GETBOXTYPE: //printf("[controld] get boxtype\n"); CControld::responseBoxType msg0; msg0.boxtype = settings.boxtype; write(connfd,&msg0,sizeof(msg0)); break; case CControld::CMD_REGISTEREVENT: eventServer->registerEvent(connfd); break; case CControld::CMD_UNREGISTEREVENT: eventServer->unRegisterEvent(connfd); break; default: printf("[controld] unknown command\n"); } }
bool VC2Decoder::parseSeqHeader(char *_idata) { #define EXPECT_VAL(N) { uint32_t d = read_uint(idata, bits);\ if (d != (N)) {\ writelog(LOG_WARN, "%s:%d: Expected %d, got %d when parsing sequence header\n", __FILE__, __LINE__, (N), d); \ }\ } uint8_t *idata = (uint8_t *)_idata; if ((!mSeqHeaderEncoded) || mSeqHeaderEncodedLength == 0 || (memcmp(mSeqHeaderEncoded, idata, mSeqHeaderEncodedLength) != 0)) { writelog(LOG_INFO, "Processing Sequence Header"); int bits = 7; EXPECT_VAL(2); EXPECT_VAL(0); EXPECT_VAL(3); int level = read_uint(idata, bits); if (level != 3 && level != 6) { writelog(LOG_WARN, "%s:%d: Expected 3 or 6, got %d when reading level\n", __FILE__, __LINE__, level); } VC2DecoderParamsInternal params; params = mParams; params.video_format.base_video_format = read_uint(idata, bits); params.video_format.custom_dimensions_flag = read_bool(idata, bits); if (params.video_format.custom_dimensions_flag) { params.video_format.frame_width = read_uint(idata, bits); params.video_format.frame_height = read_uint(idata, bits); } params.video_format.custom_color_diff_format_flag = read_bool(idata, bits); if (params.video_format.custom_color_diff_format_flag) { params.video_format.color_diff_format_index = read_uint(idata, bits); } params.video_format.custom_scan_format_flag = read_bool(idata, bits); if (params.video_format.custom_scan_format_flag) { params.video_format.source_sampling = read_uint(idata, bits); } params.video_format.custom_frame_rate_flag = read_bool(idata, bits); if (params.video_format.custom_frame_rate_flag) { params.video_format.frame_rate_index = read_uint(idata, bits); if (params.video_format.frame_rate_index == 0) { params.video_format.frame_rate_numer = read_uint(idata, bits); params.video_format.frame_rate_denom = read_uint(idata, bits); } } params.video_format.custom_pixel_aspect_ratio_flag = read_bool(idata, bits); if (params.video_format.custom_pixel_aspect_ratio_flag) { params.video_format.pixel_aspect_ratio_index = read_uint(idata, bits); if (params.video_format.pixel_aspect_ratio_index == 0) { params.video_format.pixel_aspect_ratio_numer = read_uint(idata, bits); params.video_format.pixel_aspect_ratio_denom = read_uint(idata, bits); } } params.video_format.custom_clean_area_flag = read_bool(idata, bits); if (params.video_format.custom_clean_area_flag) { params.video_format.clean_width = read_uint(idata, bits); params.video_format.clean_height = read_uint(idata, bits); params.video_format.left_offset = read_uint(idata, bits); params.video_format.top_offset = read_uint(idata, bits); } params.video_format.custom_signal_range_flag = read_bool(idata, bits); if (params.video_format.custom_signal_range_flag) { params.video_format.signal_range_index = read_uint(idata, bits); if (params.video_format.signal_range_index == 0) { params.video_format.luma_offset = read_uint(idata, bits); params.video_format.luma_excursion = read_uint(idata, bits); params.video_format.color_diff_offset = read_uint(idata, bits); params.video_format.color_diff_excursion = read_uint(idata, bits); } } params.video_format.custom_color_spec_flag = read_bool(idata, bits); if (params.video_format.custom_color_spec_flag) { params.video_format.color_spec_index = read_uint(idata, bits); if (params.video_format.color_spec_index == 0) { params.video_format.custom_color_primaries_flag = read_bool(idata, bits); if (params.video_format.custom_color_primaries_flag) { params.video_format.color_primaries_index = read_uint(idata, bits); } params.video_format.custom_color_matrix_flag = read_bool(idata, bits); if (params.video_format.custom_color_matrix_flag) { params.video_format.color_matrix_index = read_uint(idata, bits); } params.video_format.custom_transfer_function_flag = read_bool(idata, bits); if (params.video_format.custom_transfer_function_flag) { params.video_format.transfer_function_index = read_uint(idata, bits); } } } uint32_t picture_coding_mode = read_uint(idata, bits); mInterlaced = (picture_coding_mode != 0); mParams = params; mConfigured = false; setVideoFormat(mParams); byte_align(idata, bits); if (mSeqHeaderEncoded) delete[] mSeqHeaderEncoded; mSeqHeaderEncodedLength = idata - (uint8_t *)_idata; mSeqHeaderEncoded = new uint8_t[mSeqHeaderEncodedLength]; memcpy(mSeqHeaderEncoded, _idata, mSeqHeaderEncodedLength); mSequenceInfo.video_format = params.video_format; mSequenceInfo.picture_coding_mode = picture_coding_mode; mSequenceInfo.sequence_headers_seen++; return true; } return false; }
void VideoDevice::configure(const Misc::ConfigurationFileSection& cfg) { /* Check which components of the video format are stored in the configuration file section: */ unsigned int frameSize[2]={0,0}; bool haveFrameSize=false; if(cfg.hasTag("./width")&&cfg.hasTag("./height")) { /* Read the requested frame size as width and height: */ frameSize[0]=cfg.retrieveValue<unsigned int>("./width"); frameSize[1]=cfg.retrieveValue<unsigned int>("./height"); haveFrameSize=true; } if(cfg.hasTag("./frameSize")) { /* Read the requested frame size as a two-element array: */ Misc::CFixedArrayValueCoder<unsigned int,2> valueCoder(frameSize); cfg.retrieveValueWC<unsigned int*>("./frameSize",valueCoder); haveFrameSize=true; } double frameRate=0.0; bool haveFrameRate=false; if(cfg.hasTag("./frameRate")) { /* Read the requested frame rate as a double: */ frameRate=cfg.retrieveValue<double>("./frameRate"); haveFrameRate=true; } unsigned int pixelFormat=0; bool havePixelFormat=false; if(cfg.hasTag("./pixelFormat")) { /* Read a pixel format as a FourCC code: */ std::string fourCC=cfg.retrieveValue<std::string>("./pixelFormat"); if(fourCC.size()!=4) Misc::throwStdErr("Video::VideoDevice::configure: Invalid pixel format code \"%s\"",fourCC.c_str()); /* Convert the FourCC code to a pixel format: */ VideoDataFormat temp; temp.setPixelFormat(fourCC.c_str()); pixelFormat=temp.pixelFormat; havePixelFormat=true; } if(cfg.hasTag("./pixelFormatHex")) { /* Read a pixel format as a hexadecimal number: */ std::string hex=cfg.retrieveString("./pixelFormatHex"); if(hex.size()!=8) Misc::throwStdErr("Video::VideoDevice::configure: Invalid hexadecimal pixel format code \"%s\"",hex.c_str()); for(int i=0;i<8;++i) { if(hex[i]>='0'&&hex[i]<='9') pixelFormat=(pixelFormat<<4)|(hex[i]-'0'); else if(hex[i]>='A'&&hex[i]<='F') pixelFormat=(pixelFormat<<4)|(hex[i]-'A'+10); else if(hex[i]>='a'&&hex[i]<='f') pixelFormat=(pixelFormat<<4)|(hex[i]-'a'+10); else Misc::throwStdErr("Video::VideoDevice::configure: Invalid hexadecimal pixel format code \"%s\"",hex.c_str()); } havePixelFormat=true; } /* Get the list of the device's supported video formats: */ std::vector<VideoDataFormat> deviceFormats=getVideoFormatList(); /* Find the best-matching video format among the device's advertised formats: */ std::vector<VideoDataFormat>::iterator bestFormat=deviceFormats.end(); double bestMatch=0.0; for(std::vector<VideoDataFormat>::iterator dfIt=deviceFormats.begin();dfIt!=deviceFormats.end();++dfIt) { double match=1.0; if(haveFrameSize) for(int i=0;i<2;++i) match*=dfIt->size[i]>=frameSize[i]?double(frameSize[i])/double(dfIt->size[i]):double(dfIt->size[i])/double(frameSize[i]); if(haveFrameRate) { double dfRate=double(dfIt->frameIntervalDenominator)/double(dfIt->frameIntervalCounter); match*=dfRate>=frameRate?frameRate/dfRate:dfRate/frameRate; } if(havePixelFormat&&dfIt->pixelFormat!=pixelFormat) match*=0.75; if(bestMatch<match) { bestFormat=dfIt; bestMatch=match; } } if(bestFormat==deviceFormats.end()) // Can only happen if there are no device formats throw std::runtime_error("Video::VideoDevice::configure: No matching video formats found"); /* Set the selected video format: */ setVideoFormat(*bestFormat); }
void VideoDevice::configure(const Misc::ConfigurationFileSection& cfg) { /* Get the device's current video format to use as default: */ VideoDataFormat currentFormat=getVideoFormat(); /* Get the list of the device's supported video formats: */ std::vector<VideoDataFormat> deviceFormats=getVideoFormatList(); /* Read the requested frame size: */ currentFormat.size[0]=cfg.retrieveValue<unsigned int>("./width",currentFormat.size[0]); currentFormat.size[1]=cfg.retrieveValue<unsigned int>("./height",currentFormat.size[1]); /* Find the best-matching frame size among the supported video formats: */ std::vector<VideoDataFormat>::iterator bestSizeMatch=deviceFormats.end(); double bestSizeMatchRatio=1.0e10; for(std::vector<VideoDataFormat>::iterator dfIt=deviceFormats.begin();dfIt!=deviceFormats.end();++dfIt) { /* Calculate the format's size mismatch: */ double sizeMatchRatio=0.0; for(int i=0;i<2;++i) { if(dfIt->size[i]<currentFormat.size[i]) sizeMatchRatio+=double(currentFormat.size[i])/double(dfIt->size[i]); else sizeMatchRatio+=double(dfIt->size[i])/double(currentFormat.size[i]); } if(bestSizeMatchRatio>sizeMatchRatio) { bestSizeMatch=dfIt; bestSizeMatchRatio=sizeMatchRatio; } } currentFormat.size[0]=bestSizeMatch->size[0]; currentFormat.size[1]=bestSizeMatch->size[1]; /* Read the requested frame rate: */ double frameRate=cfg.retrieveValue<double>("./frameRate",double(currentFormat.frameIntervalDenominator)/double(currentFormat.frameIntervalCounter)); /* Find the best-matching frame rate among the supporting video formats: */ std::vector<VideoDataFormat>::iterator bestRateMatch=deviceFormats.end(); double bestRateMatchRatio=1.0e10; for(std::vector<VideoDataFormat>::iterator dfIt=deviceFormats.begin();dfIt!=deviceFormats.end();++dfIt) if(dfIt->size[0]==currentFormat.size[0]&&dfIt->size[1]==currentFormat.size[1]) { /* Calculate the format's frame rate mismatch: */ double rate=double(dfIt->frameIntervalDenominator)/double(dfIt->frameIntervalCounter); double rateMatchRatio; if(rate<frameRate) rateMatchRatio=frameRate/rate; else rateMatchRatio=rate/frameRate; if(bestRateMatchRatio>rateMatchRatio) { bestRateMatch=dfIt; bestRateMatchRatio=rateMatchRatio; } } currentFormat.pixelFormat=bestRateMatch->pixelFormat; currentFormat.frameIntervalCounter=bestRateMatch->frameIntervalCounter; currentFormat.frameIntervalDenominator=bestRateMatch->frameIntervalDenominator; /* Set the selected video format: */ setVideoFormat(currentFormat); }