/*********************************************************************************************************** **函数:Rtp_Lock **功能: **输入参数: **返回值: ***********************************************************************************************************/ static int RtpSetup( uint16_t portbase) { int status; RTPUDPv4TransmissionParams transparams; RTPSessionParams sessparams; sessparams.SetOwnTimestampUnit(1.0/90000.0); sessparams.SetMaximumPacketSize(1200); transparams.SetPortbase(portbase); sess.SetDefaultPayloadType(PLOAD_TYPE); sess.SetDefaultMark(false); sess.SetDefaultTimestampIncrement(DefaultTimestampIncrement); status = sess.Create(sessparams,&transparams); checkerror(status); return status; }
int main(int argc, char ** argv) { uint16_t portbase,destport; uint32_t destip; std:string ipstr; //get the destiny ip from the std input stream // NALU_t *n; printf("Please Enter:./test framenum(500)\n"); if(argc!=2) { printf("Please Enter:./test framenum\n"); exit(EXIT_FAILURE); } //dev_name=argv[1]; frame_num=atoi(argv[1]); //convert a string to an integer if(!frame_num) { printf("frame_num should be over 0 frame\n"); exit(EXIT_FAILURE); } // @0506 here ,there is no need to test YUYV | YUV420 | tmpH264 , for Module Test //openFiles(); //***************************************************************************** //****************** the capturing process *****************start********* printf("capture video begin\n"); open_device(); init_device(); start_capturing(); //fp = fopen(filename, "wa+"); //yuv422 // *********** //alloc_image(); // *********** // *********** //open_x264file("test420.yuv"); init_encoder(); init_picture(yuv_size_2); // *********** portbase = 33334; destport = 9000; //ipstr = "222.197.174.76"; ipstr = "202.115.11.128"; destip = inet_addr(ipstr.c_str()); //destip = ntohl(destip); ///************** very important ************** destip = htonl(destip); //********************** get the rtp parameter from std input stream ****above *** // @2 Setting basic parameter ---------------------------------- RTPUDPv4TransmissionParams transparams; transparams.SetPortbase(portbase); RTPSessionParams sessparams; sessparams.SetOwnTimestampUnit(1.0/90000.0); status=sess.Create(sessparams,&transparams); checkerror(status); RTPIPv4Address addr(destip,destport); status = sess.AddDestination(addr); checkerror(status); sess.SetDefaultPayloadType(96); sess.SetDefaultMark(false); sess.SetDefaultTimestampIncrement(90000.0/10.0); // frame rate control 10 / 25 RTPTime delay(0.040);//RTPTime delay(0.040) //RTPTime::Wait(delay); RTPTime starttime=RTPTime::CurrentTime(); // // @3.0 Preparation for sending NALU package---------------------------------------------------- // char sendbuf[1500]; // char *nalu_payload; // int size=0; // unsigned int timestamp_increase=0,ts_current=0; // OpenBitstreamFile("test.h264"); // n=AllocNALU(8000000);// alloc memory for the <struct NALU> n->maxSize = 8_000_000 = 8 MB // int start=false; // //**************************************************************** //****************** the capturing process ********************end ****** //****************** x264 encode ******************************* start *** // open_yuvfile(filename); // alloc_image(); // swscale_start(); // ****** yuv422 -> I420 ******* // swscale_close(); // open_x264file(dst_filename); // init_encoder(); // init_picture(yuv_size); // encode_frame(); // **** encode x264 format *** // close_encoder(); //****************** x264 encode ******************************* end *** //----------------------------------------------------------- //@1223--01 struct timeval tpstart,tpend; float timeuse; gettimeofday(&tpstart,NULL); ///------ implement capture the pictures next line ----------------------------- tmpFP264 = fopen("softEncodeH264.h264","wb"); mainloop(frame_num); // **** capture frame ***** fclose(tmpFP264); ///----------------------------------------------------------------------------- gettimeofday(&tpend,NULL); timeuse=1000000 * (tpend.tv_sec-tpstart.tv_sec) + tpend.tv_usec - tpstart.tv_usec; timeuse/=1000000; printf("timeuse total Used Time( Second ):%f\n",timeuse); //@1223--02 //----------------------------------------------------------- stop_capturing(); uninit_device(); close_device(); close_encoder(); return 0; }
int main(int argc, char ** argv) { uint16_t portbase,destport; uint32_t destip; std:string ipstr; //get the destiny ip from the std input stream // NALU_t *n; printf("Please Enter:./test framenum(500)\n"); if(argc!=2) { printf("Please Enter:./test framenum\n"); exit(EXIT_FAILURE); } //dev_name=argv[1]; frame_num=atoi(argv[1]); //convert a string to an integer if(!frame_num) { printf("frame_num should be over 0 frame\n"); exit(EXIT_FAILURE); } // @0506 here ,there is no need to test YUYV | YUV420 | tmpH264 , for Module Test //openFiles(); //***************************************************************************** //****************** the capturing process *****************start********* printf("capture video begin\n"); open_device(); init_device(); start_capturing(); //fp = fopen(filename, "wa+"); //yuv422 // *********** //alloc_image(); // *********** // *********** //open_x264file("test420.yuv"); init_encoder(); init_picture(yuv_size_2); // *********** portbase = 33334; destport = 9000; //ipstr = "222.197.174.76"; // @ 1204 change the ip to the LAN IP //ipstr = "202.115.11.128"; ipstr = "192.168.5.155"; destip = inet_addr(ipstr.c_str()); //destip = ntohl(destip); ///************** very important ************** destip = htonl(destip); //********************** get the rtp parameter from std input stream ****above *** // @2 Setting basic parameter ---------------------------------- RTPUDPv4TransmissionParams transparams; transparams.SetPortbase(portbase); RTPSessionParams sessparams; sessparams.SetOwnTimestampUnit(1.0/90000.0); status=sess.Create(sessparams,&transparams); checkerror(status); RTPIPv4Address addr(destip,destport); status = sess.AddDestination(addr); checkerror(status); sess.SetDefaultPayloadType(96); sess.SetDefaultMark(false); sess.SetDefaultTimestampIncrement(90000.0/10.0); // frame rate control 10 / 25 RTPTime delay(0.040);//RTPTime delay(0.040) //RTPTime::Wait(delay); RTPTime starttime=RTPTime::CurrentTime(); // // @3.0 Preparation for sending NALU package---------------------------------------------------- // char sendbuf[1500]; // char *nalu_payload; // int size=0; // unsigned int timestamp_increase=0,ts_current=0; // OpenBitstreamFile("test.h264"); // n=AllocNALU(8000000);// alloc memory for the <struct NALU> n->maxSize = 8_000_000 = 8 MB // int start=false; // //**************************************************************** mainloop(frame_num); // **** capture frame ***** // fclose(fp); stop_capturing(); uninit_device(); close_device(); close_encoder(); printf("capture video is over\n"); //****************** the capturing process ********************end ****** //****************** x264 encode ******************************* start *** // open_yuvfile(filename); // alloc_image(); // swscale_start(); // ****** yuv422 -> I420 ******* // swscale_close(); // open_x264file(dst_filename); // init_encoder(); // init_picture(yuv_size); // encode_frame(); // **** encode x264 format *** // close_encoder(); //****************** x264 encode ******************************* end *** /////--------------------------------------------------------------------------------------------------- printf("encode x264 video is over\n"); printf("Wait to jrtpsend....\n"); //****************** RTP send *********************** start ********** // @1 Getting basic parameter ------------------------------- // std::cout<<"Enter local portbase:"<<std::endl; // std::cin>>portbase; // std::cout<<std::endl; // std::cout << "Enter the destination IP address" << std::endl; // std::cin >> ipstr; // destip = inet_addr(ipstr.c_str()); // if (destip == INADDR_NONE) // { // std::cerr << "Bad IP address specified" << std::endl; // return -1; // } // destip = ntohl(destip); // std::cout << "Enter the destination port" << std::endl; // std::cin >> destport; // portbase = 33333; // destport = 55555; // ipstr = "222.197.174.76"; // destip = inet_addr(ipstr.c_str()); // //********************** get the rtp parameter from std input stream ****above *** // // @2 Setting basic parameter ---------------------------------- // RTPUDPv4TransmissionParams transparams; // transparams.SetPortbase(portbase); // RTPSessionParams sessparams; // sessparams.SetOwnTimestampUnit(1.0/90000.0); // status=sess.Create(sessparams,&transparams); // checkerror(status); // RTPIPv4Address addr(destip,destport); // status = sess.AddDestination(addr); // checkerror(status); // sess.SetDefaultPayloadType(96); // sess.SetDefaultMark(false); // sess.SetDefaultTimestampIncrement(90000.0/10.0); // RTPTime delay(0.030);//RTPTime delay(0.040) // //RTPTime::Wait(delay); // RTPTime starttime=RTPTime::CurrentTime(); // // @3.0 Preparation for sending NALU package---------------------------------------------------- // char sendbuf[1500]; // char *nalu_payload; // int size=0; // unsigned int timestamp_increase=0,ts_current=0; // OpenBitstreamFile("test.h264"); // n=AllocNALU(8000000);// alloc memory for the <struct NALU> n->maxSize = 8_000_000 = 8 MB // int start=false; // NALU packages sending loop ----------------------------------- // while(!feof(bits)) // { // size=GetAnnexbNALU(n); // having original souce for this function // if(size<4) // { // printf("get nalu error!\n"); // continue; // } // printf("size:%d\n",size); // dump(n); // if(!start) // { // if(n->nal_unit_type==1||n->nal_unit_type==5||n->nal_unit_type==6||n->nal_unit_type==7) // { // printf("begin\n"); // start=true; // } // } // if(n->len <= MAX_RTP_PKT_LENGTH) // { // nalu_hdr=(NALU_HEADER *)&sendbuf[0]; // nalu_hdr->F=n->forbidden_bit; // nalu_hdr->NRI=n->nal_reference_idc>>5; // nalu_hdr->TYPE=n->nal_unit_type; // nalu_payload=&sendbuf[1]; // memcpy(nalu_payload,n->buf+1,n->len-1); // ts_current=ts_current+timestamp_increase; // if(n->nal_unit_type==1||n->nal_unit_type==5) // { // status=sess.SendPacket((void *)sendbuf,n->len,96,true,3600); // } // else // { // status=sess.SendPacket((void *)sendbuf,n->len,96,true,0); // continue; // } // checkerror(status); // } // else if(n->len > MAX_RTP_PKT_LENGTH) // { // int k=0,l=0; // k=n->len/MAX_RTP_PKT_LENGTH; // l=n->len%MAX_RTP_PKT_LENGTH; // int t=0; // while(t<=k) // { // if(!t)//first pkt package // { // memset(sendbuf,0,1500); // fu_ind=(FU_INDICATOR *)&sendbuf[0]; // fu_ind->F=n->forbidden_bit; // fu_ind->NRI=n->nal_reference_idc>>5; // fu_ind->TYPE=28;//FU-A // fu_hdr=(FU_HEADER *)&sendbuf[1]; // fu_hdr->E=0; // fu_hdr->R=0; // fu_hdr->S=1; // fu_hdr->TYPE=n->nal_unit_type; // nalu_payload=&sendbuf[2]; // memcpy(nalu_payload,n->buf+1,MAX_RTP_PKT_LENGTH); // status=sess.SendPacket((void *)sendbuf,MAX_RTP_PKT_LENGTH+2,96,false,0); // checkerror(status); // t++; // } // else if(t==k)//last package // { // memset(sendbuf,0,1500); // fu_ind=(FU_INDICATOR *)&sendbuf[0]; // fu_ind->F=n->forbidden_bit; // fu_ind->NRI=n->nal_reference_idc>>5; // fu_ind->TYPE=28;//FU-A // fu_hdr=(FU_HEADER *)&sendbuf[1]; // fu_hdr->R=0; // fu_hdr->S=0; // fu_hdr->E=1; // fu_hdr->TYPE=n->nal_unit_type; // nalu_payload=&sendbuf[2]; // memcpy(nalu_payload,n->buf+t*MAX_RTP_PKT_LENGTH+1,l-1); // status=sess.SendPacket((void *)sendbuf,l+1,96,true,3600); // checkerror(status); // t++; // } // else if( (t<k) && (t!=0) ) //packageS between the first and the last // { // memset(sendbuf,0,1500); // fu_ind=(FU_INDICATOR *)&sendbuf[0]; // fu_ind->F=n->forbidden_bit; // fu_ind->NRI=n->nal_reference_idc>>5; // fu_ind->TYPE=28;//FU-A // fu_hdr=(FU_HEADER *)&sendbuf[1]; // fu_hdr->R=0; // fu_hdr->S=0; // fu_hdr->E=0;//E=1 // fu_hdr->TYPE=n->nal_unit_type; // nalu_payload=&sendbuf[2]; // memcpy(nalu_payload,n->buf+t*MAX_RTP_PKT_LENGTH+1,MAX_RTP_PKT_LENGTH); // status=sess.SendPacket((void *)sendbuf,MAX_RTP_PKT_LENGTH+2,96,false,0); // checkerror(status); // t++; // } // } // } // RTPTime::Wait(delay);//Wait(delay); // RTPTime time=RTPTime::CurrentTime(); // time-=starttime; // if(time>RTPTime(60.0))break; // } // // @4 Finish sending NALU package // printf("Mission over\n"); // delay=RTPTime(10.0); // sess.BYEDestroy(delay,"Time's up",9); return 0; }
int main(int argc, char** argv) { #if 0 CRTPSender sender; string destip_str = "127.0.0.1"; uint32_t dest_ip = inet_addr(destip_str.c_str()); SetRTPParams(sender,dest_ip,DEST_PORT,BASE_PORT); sender.SetParamsForSendingH264(); #else RTPSession session; RTPSessionParams sessionparams; sessionparams.SetOwnTimestampUnit(1.0/90000.0); RTPUDPv4TransmissionParams transparams; transparams.SetPortbase(8000); int status = session.Create(sessionparams,&transparams); if (status < 0) { std::cerr << RTPGetErrorString(status) << std::endl; exit(-1); } uint8_t localip[]={127,0,0,1}; RTPIPv4Address addr(localip,9000); status = session.AddDestination(addr); if (status < 0) { std::cerr << RTPGetErrorString(status) << std::endl; exit(-1); } session.SetDefaultPayloadType(96); session.SetDefaultMark(false); session.SetDefaultTimestampIncrement(90000.0 /25.0); RTPTime delay(0.040); RTPTime starttime = RTPTime::CurrentTime(); #endif NALU_HEADER *nalu_hdr; FU_INDICATOR *fu_ind; FU_HEADER *fu_hdr; char sendbuf[1500]; char* nalu_payload; unsigned int timestamp_increse=0,ts_current=0; #define ddd OpenBitstreamFile("raw.264");//打开264文件,并将文件指针赋给bits,在此修改文件名实现打开别的264文件。 NALU_t *n; n = AllocNALU(8000000);//为结构体nalu_t及其成员buf分配空间。返回值为指向nalu_t存储空间的指针 bool start=false; while(!feof(bits)) { int size=GetAnnexbNALU(n);//每执行一次,文件的指针指向本次找到的NALU的末尾,下一个位置即为下个NALU的起始码0x000001 if(size<4) { printf("get nul error!\n"); continue; } dump(n);//输出NALU长度和TYPE if(!start) { if(n->nal_unit_type==5||n->nal_unit_type==6|| n->nal_unit_type==7||n->nal_unit_type==7) { printf("begin\n"); start=true; } } //将编码数据写入文件t //fwrite(pNals[i].p_payload, 1, pNals[i].i_payload, pFile); //发送编码文件 #if 1 // 当一个NALU小于MAX_RTP_PKT_LENGTH字节的时候,采用一个单RTP包发送 if(n->len<=MAX_RTP_PKT_LENGTH) { //printf("ddd0\n"); //session.SetDefaultMark(false); //设置NALU HEADER,并将这个HEADER填入sendbuf[12] nalu_hdr =(NALU_HEADER*)&sendbuf[0]; //将sendbuf[12]的地址赋给nalu_hdr,之后对nalu_hdr的写入就将写入sendbuf中; nalu_hdr->F=n->forbidden_bit; nalu_hdr->NRI=n->nal_reference_idc>>5;//有效数据在n->nal_reference_idc的第6,7位,需要右移5位才能将其值赋给nalu_hdr->NRI。 nalu_hdr->TYPE=n->nal_unit_type; nalu_payload=&sendbuf[1];//同理将sendbuf[13]赋给nalu_payload memcpy(nalu_payload,n->buf+1,n->len-1);//去掉nalu头的nalu剩余内容写入sendbuf[13]开始的字符串。 ts_current=ts_current+timestamp_increse; //status = session.SendPacket((void *)sendbuf,n->len); if(n->nal_unit_type==1 || n->nal_unit_type==5) { status = session.SendPacket((void *)sendbuf,n->len,96,true,3600); } else { status = session.SendPacket((void *)sendbuf,n->len,96,true,0);\ //如果是6,7类型的包,不应该延时;之前有停顿,原因这在这 continue; } //发送RTP格式数据包并指定负载类型为96 if (status < 0) { std::cerr << RTPGetErrorString(status) << std::endl; exit(-1); } } else if(n->len>MAX_RTP_PKT_LENGTH)