int MediaBridgeSession::StartSendingAudio(char *sendAudioIp,int sendAudioPort,RTPMap& rtpMap) { Log("-StartSendingAudio [%s,%d]\n",sendAudioIp,sendAudioPort); //Si estabamos mandando tenemos que parar if (sendingAudio) //Y esperamos que salga StopSendingAudio(); //Si tenemos Audio if (sendAudioPort==0) return Error("No Audio port defined\n"); //Iniciamos las sesiones rtp de envio if(!rtpAudio.SetRemotePort(sendAudioIp,sendAudioPort)) return Error("Error abriendo puerto rtp\n"); //Set sending map rtpAudio.SetSendingRTPMap(rtpMap); //Set default codec rtpAudio.SetSendingCodec(rtpAudioCodec); //Estamos mandando sendingAudio=1; //Arrancamos los procesos createPriorityThread(&sendAudioThread,startSendingAudio,this,0); return sendingAudio; }
/*************************************** * StartReceiving * Abre los sockets y empieza la recetpcion ****************************************/ int AudioStream::StartReceiving(AudioCodec::RTPMap& rtpMap) { //If already receiving if (receivingAudio) //Stop it StopReceiving(); //Get local rtp port int recAudioPort = rtp.GetLocalPort(); //Set receving map rtp.SetReceivingAudioRTPMap(rtpMap); //We are reciving audio receivingAudio=1; //Create thread createPriorityThread(&recAudioThread,startReceivingAudio,this,1); //Log Log("<StartReceiving audio [%d]\n",recAudioPort); //Return receiving port return recAudioPort; }
int MP4Streamer::Seek(QWORD time) { Log(">MP4Streamer seek\n"); //Stop Playback Stop(); //Lock pthread_mutex_lock(&mutex); //Check we are opened if (!opened) { //Unlock pthread_mutex_unlock(&mutex); //Exit return Error("MP4Streamer not opened!\n"); } //We are playing playing = 1; //Seet seeked seeked = time; //Arrancamos los procesos createPriorityThread(&thread,play,this,0); //Unlock pthread_mutex_unlock(&mutex); Log("<MP4Streamer seeked [%lld,%lld]\n",time,seeked); return 1; }
int MP4Streamer::Play() { Log(">MP4Streamer Play\n"); //Stop just in case Stop(); //Lock pthread_mutex_lock(&mutex); //Check we are opened if (!opened) { //Unlock pthread_mutex_unlock(&mutex); //Exit return Error("MP4Streamer not opened!\n"); } //We are playing playing = 1; //From the begining seeked = 0; //Arrancamos los procesos createPriorityThread(&thread,play,this,0); //Unlock pthread_mutex_unlock(&mutex); Log("<MP4Streamer Play\n"); return playing; }
/*********************** * Init * Inicializa el mezclado de audio ************************/ int AudioMixer::Init() { // Estamos mzclando mixingAudio = true; //Y arrancamoe el thread createPriorityThread(&mixAudioThread,startMixingAudio,this,0); return 1; }
int RTMPConnection::Init(int fd) { Log("RTMP Connection init [%d]\n",fd); //Store socket socket = fd; //I am inited inited = 1; //Create thread createPriorityThread(&thread,run,this,0); Log("<RTMP Connection init\n"); return 1; }
int RTPMultiplexerSmoother::Start() { Log("-RTPMultiplexerSmoother start\n"); //Check if we are already inited if (inited) //End first Stop(); //We are inited inited = true; //Run createPriorityThread(&thread,run,this,1); return 1; }
/*************************************** * StartSending * Comienza a mandar a la ip y puertos especificados ***************************************/ int AudioEncoderWorker::StartEncoding() { Log(">Start encoding audio\n"); //Si estabamos mandando tenemos que parar if (encodingAudio) //paramos StopEncoding(); encodingAudio=1; //Start thread createPriorityThread(&encodingAudioThread,startEncoding,this,1); Log("<StartSending audio [%d]\n",encodingAudio); return 1; }
int VNCServer::Client::Connect(WebSocket *ws) { Debug(">VNCServer::Client::Connect [ws:%p,this:%p]\n",ws,this); //Store websocekt this->ws = ws; rfbProtocolVersionMsg pv; sprintf(pv,rfbProtocolVersionFormat,cl->screen->protocolMajorVersion,cl->screen->protocolMinorVersion); //Write protocol version if (rfbWriteExact(cl, pv, sz_rfbProtocolVersionMsg) < 0) { rfbLogPerror("rfbNewClient: write"); rfbCloseClient(cl); rfbClientConnectionGone(cl); return Error("-Could not write protocol version"); } //Enable extension for(rfbProtocolExtension* extension = rfbGetExtensionIterator(); extension; extension=extension->next) { void* data = NULL; /* if the extension does not have a newClient method, it wants * to be initialized later. */ if(extension->newClient && extension->newClient(cl, &data)) rfbEnableExtension(cl, extension, data); } rfbReleaseExtensionIterator(); cl->onHold = FALSE; //Start thread createPriorityThread(&thread,run,this,0); Debug("<VNCServer::Client::Connect [ws:%p,this:%p]\n",ws,this); //OK return 1; }
bool RTMPFLVStream::Play(std::wstring& url) { char filename[1024]; //If already playing if (fd!=-1) //Close it and start a new playback Close(); //get file name snprintf(filename,1024,"%ls",url.c_str()); //Open file fd = open(filename,O_RDONLY); //Check fd if (fd==-1) { //Send error comand SendCommand(L"onStatus", new RTMPNetStatusEvent(L"NetStream.Play.StreamNotFound",L"error",L"Stream not found")); //exit return Error("-Could not open file [%d,%s]\n",errno,filename); } //We are playing playing = true; //Send play comand SendCommand(L"onStatus", new RTMPNetStatusEvent(L"NetStream.Play.Reset",L"status",L"Playback reset") ); //Send play comand SendCommand(L"onStatus", new RTMPNetStatusEvent(L"NetStream.Play.Start",L"status",L"Playback started") ); //Start thread createPriorityThread(&thread,play,this,0); return true; }
/*************************************** * StartSending * Comienza a mandar a la ip y puertos especificados ***************************************/ int AudioStream::StartSending(char *sendAudioIp,int sendAudioPort,AudioCodec::RTPMap& rtpMap) { Log(">StartSending audio [%s,%d]\n",sendAudioIp,sendAudioPort); //Si estabamos mandando tenemos que parar if (sendingAudio) //paramos StopSending(); //Si tenemos audio if (sendAudioPort==0) //Error return Error("Audio port 0\n"); //Y la de audio if(!rtp.SetRemotePort(sendAudioIp,sendAudioPort)) //Error return Error("Error en el SetRemotePort\n"); //Set sending map rtp.SetSendingAudioRTPMap(rtpMap); //Set audio codec if(!rtp.SetSendingAudioCodec(audioCodec)) //Error return Error("%s audio codec not supported by peer\n",AudioCodec::GetNameFor(audioCodec)); //Arrancamos el thread de envio sendingAudio=1; //Start thread createPriorityThread(&sendAudioThread,startSendingAudio,this,1); Log("<StartSending audio [%d]\n",sendingAudio); return 1; }
int MediaBridgeSession::StartReceivingText(RTPMap& rtpMap) { //Si estabamos reciviendo tenemos que parar if (receivingText) StopReceivingText(); //Iniciamos las sesiones rtp de recepcion int recTextPort = rtpText.GetLocalPort(); //Estamos recibiendo receivingText = 1; //Set receving map rtpText.SetReceivingRTPMap(rtpMap); //Arrancamos los procesos createPriorityThread(&recTextThread,startReceivingText,this,0); //Logeamos Log("-StartReceivingText [%d]\n",recTextPort); return recTextPort; }
/*************************************** * StartReceiving * Abre los sockets y empieza la recetpcion ****************************************/ int VideoStream::StartReceiving(const RTPMap& rtpMap,const RTPMap& aptMap) { //Si estabamos reciviendo tenemos que parar if (receivingVideo) StopReceiving(); //Iniciamos las sesiones rtp de recepcion int recVideoPort= rtp.GetLocalPort(); //Set receving map rtp.SetReceivingRTPMap(rtpMap,aptMap); //Estamos recibiendo receivingVideo=1; //Arrancamos los procesos createPriorityThread(&recVideoThread,startReceivingVideo,this,0); //Logeamos Log("-StartReceiving Video [%d]\n",recVideoPort); return recVideoPort; }
int RTPEndpoint::StartReceiving() { //Check if inited if (!inited) //Exit return Error("Not initied"); //Check if (receiving) //Exit return Error("Alredy receiving"); //Inited receiving = true; //Create thread createPriorityThread(&thread,run,this,1); //Sedn on reset ResetStream(); //Return listening port return 1; }
/*************************************** * StartSending * Comienza a mandar a la ip y puertos especificados ***************************************/ int VideoStream::StartSending(char *sendVideoIp,int sendVideoPort,const RTPMap& rtpMap,const RTPMap& aptMap) { Log(">StartSendingVideo [%s,%d]\n",sendVideoIp,sendVideoPort); //Si estabamos mandando tenemos que parar if (sendingVideo) //Y esperamos que salga StopSending(); //Si tenemos video if (sendVideoPort==0) return Error("No video\n"); //Iniciamos las sesiones rtp de envio if(!rtp.SetRemotePort(sendVideoIp,sendVideoPort)) return Error("Error abriendo puerto rtp\n"); //Set sending map rtp.SetSendingRTPMap(rtpMap,aptMap); //Set video codec if(!rtp.SetSendingCodec(videoCodec)) //Error return Error("%s video codec not supported by peer\n",VideoCodec::GetNameFor(videoCodec)); //Estamos mandando sendingVideo=1; //Arrancamos los procesos createPriorityThread(&sendVideoThread,startSendingVideo,this,0); //LOgeamos Log("<StartSending video [%d]\n",sendingVideo); return 1; }
int FLVEncoder::StartEncoding() { Log(">Start encoding FLV [id:%d]\n",id); //Si estabamos mandando tenemos que parar if (encodingAudio || encodingVideo) //paramos StopEncoding(); //Set init time getUpdDifTime(&first); //Check if got old meta if (meta) //Delete delete(meta); //Create metadata object meta = new RTMPMetaData(0); //Set name meta->AddParam(new AMFString(L"@setDataFrame")); //Set name meta->AddParam(new AMFString(L"onMetaData")); //Create properties string AMFEcmaArray *prop = new AMFEcmaArray(); //Set audio properties switch(audioCodec) { case AudioCodec::SPEEX16: prop->AddProperty(L"audiocodecid" ,(float)RTMPAudioFrame::SPEEX ); //Number Audio codec ID used in the file (see E.4.2.1 for available SoundFormat values) prop->AddProperty(L"audiosamplerate" ,(float)16000.0 ); // Number Frequency at which the audio stream is replayed break; case AudioCodec::NELLY11: prop->AddProperty(L"audiocodecid" ,(float)RTMPAudioFrame::NELLY ); //Number Audio codec ID used in the file (see E.4.2.1 for available SoundFormat values) prop->AddProperty(L"audiosamplerate" ,(float)11025.0 ); // Number Frequency at which the audio stream is replayed break; case AudioCodec::NELLY8: prop->AddProperty(L"audiocodecid" ,(float)RTMPAudioFrame::NELLY8khz ); //Number Audio codec ID used in the file (see E.4.2.1 for available SoundFormat values) prop->AddProperty(L"audiosamplerate" ,(float)8000.0 ); // Number Frequency at which the audio stream is replayed break; } prop->AddProperty(L"stereo" ,new AMFBoolean(false) ); // Boolean Indicating stereo audio prop->AddProperty(L"audiodelay" ,0.0 ); // Number Delay introduced by the audio codec in seconds //Set video codecs if (videoCodec==VideoCodec::SORENSON) //Set number prop->AddProperty(L"videocodecid" ,(float)RTMPVideoFrame::FLV1 ); // Number Video codec ID used in the file (see E.4.3.1 for available CodecID values) else if (videoCodec==VideoCodec::H264) //AVC prop->AddProperty(L"videocodecid" ,new AMFString(L"avc1") ); // Number Video codec ID used in the file (see E.4.3.1 for available CodecID values) prop->AddProperty(L"framerate" ,(float)fps ); // Number Number of frames per second prop->AddProperty(L"height" ,(float)height ); // Number Height of the video in pixels prop->AddProperty(L"videodatarate" ,(float)bitrate ); // Number Video bit rate in kilobits per second prop->AddProperty(L"width" ,(float)width ); // Number Width of the video in pixels prop->AddProperty(L"canSeekToEnd" ,new AMFBoolean(false) ); // Boolean Indicating the last video frame is a key frame //Add param meta->AddParam(prop); //Send metadata SendMetaData(meta); //If got audio if (audioInput) { //We are enconding encodingAudio = 1; //Start thread createPriorityThread(&encodingAudioThread,startEncodingAudio,this,1); } //If got video if (videoInput) { //We are enconding encodingVideo = 1; //Start thread createPriorityThread(&encodingVideoThread,startEncodingVideo,this,1); } Log("<Stop encoding FLV [%d]\n",encodingAudio); return 1; }