📄 win.cpp
字号:
#include "win.h"QLabel* PixmapLabel1;QPainter *paint;QImage img;unsigned char * ppm = new unsigned char [10000];//unsigned char *rgb;// --------------------------------RTP--------------------------// RTPSession sess;int localport;int status;QString str; int init_rtp(){ localport = atoi("5000"); RTPUDPv4TransmissionParams transparams; RTPSessionParams sessparams; // IMPORTANT: The local timestamp unit MUST be set, otherwise // RTCP Sender Report info will be calculated wrong // In this case, we'll be just use 8000 samples per second. sessparams.SetOwnTimestampUnit(1.0/10.0); transparams.SetPortbase(localport); status = sess.Create(sessparams,&transparams); checkerror(status); printf("session open\n");}void checkerror(int rtperr){ if (rtperr < 0) { std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl; exit(-1); }}void* receiver(void *data){ char done = 0; unsigned long timestamp1; unsigned char * RawData; //char temp[10000]; int length, i, index, sumlen; printf("allocation is over\n"); index=0;sumlen=0; memset(ppm, 0, 10000); do { sess.BeginDataAccess(); //status = sess.PollData(); if (sess.GotoFirstSourceWithData()) { do { RTPPacket* packet; printf("get source\n"); while ((packet = sess.GetNextPacket()) != NULL) { //printf("get packet\n"); timestamp1 = packet->GetTimestamp(); length=packet->GetPayloadLength(); RawData=packet->GetPayloadData(); printf("size of data is %d\n", length); //memcpy(temp, RawData, length); //receive too many packets without an end, clear if(sumlen>=10000) { printf("buffer is over\n"); index=0; sumlen=0; memset(ppm, 0, 10000); } if(length!=4) { //printf("timestamp: %ld length=%d data:%s\n",timestamp1,length,&temp); printf("receiver data, index=%d, sumlen=%d\n", index, sumlen); memcpy(ppm+1000*index, RawData, length); index++; sumlen+=length; /* if(index==2) { FILE *pFile; pFile=fopen("win.jpg", "wb"); if(pFile==NULL) { //'{' is made by me. fprintf(stderr, "open frame file error\n"); return NULL; } fwrite(RawData, 1, length, pFile); fclose(pFile); exit(0); }*/ //img.loadFromData(RawData, length, 0); //paint->drawImage(0, 0, img); } if(length==4) { //printf(" timestamp: %ld length=%d end_flag data:%s\n",timestamp1,length,&temp); printf("receiver end, index=%d, sumlen=%d\n", index, sumlen); str = (const char *)RawData; str.truncate(4); qWarning(str); printf("%d = %d\n", str.toInt(), sumlen); if(str.toInt()==sumlen) { img.loadFromData(ppm, sumlen, 0); paint->drawImage(0, 0, img); } index=0; sumlen=0; memset(ppm, 0, 10000); //done = 1; //printf("change done\n"); //break; } delete packet; } } while (sess.GotoNextSourceWithData()); } sess.EndDataAccess(); //RTPTime::Wait(RTPTime(1,0)); usleep(1000); } while(!done); //sess.BYEDestroy(RTPTime(10,0),0,0); //delete(ppm); return 0;}//------------------------RTP--------------------------------///* * Constructs a Form1 as a child of 'parent', with the * name 'name' and widget flags set to 'f'. * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ){ if ( !name ) setName( "Form1" ); PixmapLabel1 = new QLabel( this, "PixmapLabel1" ); PixmapLabel1->setGeometry( QRect( 120, 60, 320, 240 ) ); PushButton1 = new QPushButton( this, "PushButton1" ); PushButton1->setGeometry( QRect( 240, 350, 101, 31 ) ); QFont PushButton1_font( PushButton1->font() ); PushButton1_font.setFamily( "unifont" ); PushButton1_font.setPointSize( 16 ); PushButton1->setFont( PushButton1_font ); PushButton1->setText( QString::fromUtf8("开始") ); paint = new QPainter(PixmapLabel1); //languageChange(); resize( QSize(640, 480).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); // signals and slots connections connect( PushButton1, SIGNAL( clicked() ), this, SLOT( pix_chg() ) ); init_rtp(); printf("inited\n");}/* * Destroys the object and frees any allocated resources */Form1::~Form1(){ // no need to delete child widgets, Qt does it all for us}/* * Sets the strings of the subwidgets using the current * language. */void Form1::pix_chg(){ pthread_t th_a; int ret; printf("thread start\n"); ret = pthread_create(&th_a,NULL,receiver,NULL); printf("thread created\n"); if( ret ) { perror("create pthread:"); exit(1); } //pthread_join(th_a,NULL);}void Form1::pix_show(){ QPixmap img("voice.png"); PixmapLabel1->setPixmap(img); usleep(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -