📄 qsdlwidget.cpp
字号:
#include <qdatetime.h>
#include <qtimer.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include "interfun.h"
#include "QSDLWidget.h"
/*
=======================================================================================================================
*
=======================================================================================================================
*/
QSDLWidget::QSDLWidget(QWidget* parent, const char* name) :
QWidget(parent, name, 0)
{
SelectPort = 0;
sameSetting = 0;
fullArea = 0;
RunStream = 0; /* 这个标志的作用是看是否有流媒体在运行 */
RunVideoOut = 0; /* 这个标志的作用是看是否有VideoOut在运行 */
playSoundPort = -1;
#ifdef RAWSTREAM
rawFile = new QFile("./displayimagefile.yuv");
rawFile->open(IO_ReadWrite | IO_Truncate);
imagebuf = (unsigned char*)malloc(704 * 576 * 3 / 2 * sizeof(unsigned char));
memset(imagebuf, 0x0, 704 * 576 * 3 / 2 * sizeof(unsigned char));
#endif
#ifdef CIRCLE
pthread_mutex_init(&mutex, NULL);
#endif
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void QSDLWidget::SetEnv()
{
int i, tempHandle;
int displayChannelCount;
int totalcard;
SDL_Surface* pOverlayScreen;
char SDL_windowhack[32];
QsStruct QsTemp;
QsTemp.qsclass = this;
QsTemp.pmf = &QSDLWidget::ReadDataCallBack;
#ifdef RAWSTREAM
QsTemp.ImageStreamCallbackpmf = &QSDLWidget::ImageStreamCallback;
#endif
SetsQstruct(&QsTemp);
sprintf(SDL_windowhack, "SDL_WINDOWID=%ld", winId());
OutputDebugString("%ld \n", winId());
putenv(SDL_windowhack);
putenv("SDL_VIDEO_YUV_HWACCEL=0");
OutputDebugString("Init the sdl...\n");
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
OutputErrorString("<sdk_error> init sdl failed!%s\n", SDL_GetError());
exit(0);
}
pOverlayScreen = SDL_SetVideoMode(WIN_W, WIN_H, 0, SDL_HWSURFACE); /* here it is freed by
* SDL_Quit();
* */
if(pOverlayScreen == NULL)
{
OutputErrorString("<sdk_error> create the sdl screen failed! for %s!\n", SDL_GetError());
SDL_Quit();
exit(0);
}
HW_InitDecDevice(&totalport);
totalcard = GetTotalDSPs();
OutputDebugString("total dsps = %d, total ports = %ld, Display Channel = %d\n", totalcard,
totalport, GetDisplayChannelCount());
mddemoclass = (Dsclass**)malloc(totalport * sizeof(Dsclass *));
memset(mddemoclass, 0x0, totalport * sizeof(Dsclass *));
for(i = 0; i < totalport; i++)
{
if(HW_ChannelOpen(i, &tempHandle) < 0)
{
OutputErrorString("<demo_info> Open the decode channle failed!\n");
HW_ReleaseDecDevice();
}
else
{
mddemoclass[i] = new Dsclass(i, tempHandle, pOverlayScreen);
mddemoclass[i]->SetdstRect(GetChanNum());
mddemoclass[i]->startDisplayThread();
}
}
displayChannelCount = GetDisplayChannelCount();
for(i = 0; i < displayChannelCount; i++)
SetDisplayStandard(i, StandardPAL);
#ifdef RAWSTREAM
RegisterDisplayVideoCaptureCallback((IMAGE_STREAM_CALLBACK) InterImageStream, NULL);
#endif
timer = (QTimer**)malloc(totalport * sizeof(QTimer *));
time = (QTime**)malloc(totalport * sizeof(QTime *));
for(i = 0; i < totalport; i++)
{
char temp[3];
sprintf(temp, "%2d", i);
temp[3] = '\0';
timer[i] = new QTimer(this, temp);
connect(timer[i], SIGNAL(timeout()), SLOT(process_time()));
time[i] = new QTime();
time[i]->start();
}
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void QSDLWidget::process_time()
{
int temp;
int Nowport = 0;
int timepassed;
int bitRate;
unsigned long framerate;
unsigned long totalDecFrame;
for(temp = 0; temp < totalport; temp++)
{
QTimer* Qtemp = (QTimer *) (this->sender());
if(atoi(Qtemp->name()) == temp)
{
Nowport = temp;
break;
}
}
timepassed = time[Nowport]->elapsed(); /* ms */
bitRate = (int)(((RetMDDEMO(Nowport)->datasum) * 8) / ((float)timepassed / 1000));
emit BitRateChange(Nowport, bitRate);
HW_GetCurrentFrameRate(RetMDDEMO(Nowport)->ChannelHandle, &framerate);
emit RateChange(Nowport, framerate);
HW_GetPlayedFrames(RetMDDEMO(Nowport)->ChannelHandle, &totalDecFrame);
emit FrameChange(Nowport, totalDecFrame);
if(mddemoclass[Nowport]->IsPlayOver() && (!bitRate && !framerate))
{
erase(RetMDDEMO(Nowport)->dstRect.x, RetMDDEMO(Nowport)->dstRect.y,
RetMDDEMO(Nowport)->dstRect.w, RetMDDEMO(Nowport)->dstRect.h);
timer[Nowport]->stop();
#ifdef CIRCLE
usleep(1000);
pthread_mutex_lock(&mutex);
SelectPort = Nowport;
FileOpen(FileName);
pthread_mutex_unlock(&mutex);
#endif
}
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
long int QSDLWidget::RetTotalPort()
{
return totalport;
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void QSDLWidget::SameSetting()
{
sameSetting = !sameSetting;
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void QSDLWidget::ImageStreamCallback(unsigned int displayNum, void* context)
{
#ifdef RAWSTREAM
if(displayNum == 1)
{
rawFile->writeBlock((char*)imagebuf, 704 * 576 * 3 / 2);
OutputDebugString("have write stream into it\n");
}
#endif
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void QSDLWidget::mousePressEvent(QMouseEvent* e)
{
int i;
if(fullArea)
return;
QPoint pnt = e->pos();
if(e->button() == Qt::LeftButton)
{
for(i = 0; i < totalport; i++)
{
if(PtInRect(RetMDDEMO(i)->dstRect, pnt.x(), pnt.y()))
{
SelectPort = i;
break;
}
}
if(i == totalport)
return;
emit portchanged(SelectPort);
emit playStatus(RetMDDEMO(SelectPort)->playType);
/* emit */
emit BitRateChange(SelectPort, 0);
emit RateChange(SelectPort, 0);
emit FrameChange(SelectPort, 0);
}
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
void QSDLWidget::mouseDoubleClickEvent(QMouseEvent* e)
{
int temp;
QPoint pnt = e->pos();
int chan = GetChanNum();
if(!fullArea)
{
int i;
for(i = 0; i < totalport; i++)
{
if(PtInRect(RetMDDEMO(i)->dstRect, pnt.x(), pnt.y()))
break;
}
if(i == totalport)
return;
}
if(e->button() == Qt::LeftButton)
{
if(RetMDDEMO(SelectPort)->bDisplayOpen)
{
if(!fullArea)
{
for(temp = 0; temp < totalport; temp++)
{
if(RetMDDEMO(temp)->bDisplayOpen && RetMDDEMO(temp)->playType)
mddemoclass[temp]->stopDisplay();
}
/*
* OutputErrorString("@@@@stop Display not or yes\n");
*/
(RetMDDEMO(SelectPort)->dstRect).x = 0;
(RetMDDEMO(SelectPort)->dstRect).y = 0;
(RetMDDEMO(SelectPort)->dstRect).w = WIN_W;
(RetMDDEMO(SelectPort)->dstRect).h = WIN_H;
/* 必须保证同步,即打开startDisplay的时候必须保证已经关闭了stopDisplay. */
mddemoclass[SelectPort]->startDisplay();
fullArea = 1;
}
else
{
mddemoclass[SelectPort]->stopDisplay();
mddemoclass[SelectPort]->SetdstRect(chan);
erase();
for(temp = 0; temp < totalport; temp++)
{
if(RetMDDEMO(temp)->playType && !(RetMDDEMO(temp)->bDisplayOpen))
{
mddemoclass[temp]->startDisplay();
}
}
fullArea = 0;
}
}
}
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
char* QSDLWidget::RetIP()
{
return RetMDDEMO(SelectPort)->serverip;
}
/*
=======================================================================================================================
*
=======================================================================================================================
*/
int QSDLWidget::RetChan()
{
return RetMDDEMO(SelectPort)->serverchan;
}
/*
=======================================================================================================================
*
=======================================================================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -