⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsdlwidget.cpp

📁 强大的QT,GTK的学习Demo.包含DSP驱动以及所使用库文件资源。
💻 CPP
📖 第 1 页 / 共 5 页
字号:

    time = (QTime**)malloc(totalport * sizeof(QTime *));
    memset(time, 0x0, 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()));

        Qtloop[i] = new QTimer(this, temp);
        connect(Qtloop[i], SIGNAL(timeout()), SLOT(process_time_loop()));

        time[i] = new QTime();
        time[i]->start();
    }   /* 需要在板卡初始化化之后才调用的么? */
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
QSDLWidget::~QSDLWidget()
{
    OutputDebugString("Enter into delete QSDLWidget\n");

    int port;
    int totalport;

    totalport = GetTotalChannels();

    RecordAllSet(FALSE);
    RecordSubAllSet(FALSE);
    ImageStreamAllSet(0, 704, 576);

    if(DSCLASSDEMO(SelectPort)->net_flag)   /* 考虑到网传是统一设置的,所以可以只需考虑一个flag */
        NetTransferSet(FALSE);

    for(port = 0; port < totalport; port++)
    {
        dsdemoclass[port]->DestoryThread();
        pthread_join(DSCLASSDEMO(port)->hPreviewThread, NULL);
        OutputErrorString("*****************close port%d******************\n", port);   /* 借用一下OutputErrorString */
    }

    OutputErrorString("ending threads <<<<<<<<<<<<<<<<<<<<\n");

    MotionAllSet(FALSE);

    if(pm)
    {
        delete pm;
        pm = NULL;
    }

    for(port = 0; port < totalport; port++)
    {
        if(DSCLASSDEMO(port)->audio_flag)
            break;
    }

    if(port != totalport)
    {
        SetAudioPreview(DSCLASSDEMO(port)->ChannelHandle, 0);
        DSCLASSDEMO(port)->audio_flag = 0;
    }

    for(port = 0; port < totalport; port++)
    {
        ChannelClose(DSCLASSDEMO(port)->ChannelHandle);
        dsdemoclass[port]->end_record();
        dsdemoclass[port]->end_subrecord();
        dsdemoclass[port]->end_imagestream();
        delete dsdemoclass[port];
        delete time[port];
        delete timer[port];
        delete Qtloop[port];
    }

    if(dsdemoclass)
    {
        free(dsdemoclass);
        dsdemoclass = NULL;
    }

    if(checkpass)
    {
        free(checkpass);
        checkpass = NULL;
    }

    if(time)
    {
        free(time);
        time = NULL;
    }

    if(timer)
    {
        free(timer);
        timer = NULL;
    }

    if(Qtloop)
    {
        free(Qtloop);
        Qtloop = NULL;
    }

    OutputDebugString("Before DeInitDSPs\n");
    DeInitDSPs();

    SDL_Quit();
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
void QSDLWidget::process_time()
{
    int                 temp;
    int                 Nowport = 0;
    int                 timepassed;
    unsigned int        elapseTime;
    FRAMES_STATISTICS   frame_statistics, sub_frame_statistics;
    float               audioframerate, videoframerate;

    /*
     * int bitRate;
     */
    int                 totalFrame;
    int                 userCount;
    int                 LostFrame;

    for(temp = 0; temp < GetTotalChannels(); temp++)
    {
        QTimer*     Qtemp = (QTimer *) (this->sender());
        if(atoi(Qtemp->name()) == temp)
        {
            Nowport = temp;
            break;
        }
    }

    timepassed = time[Nowport]->elapsed();
    elapseTime = (unsigned int)timepassed + (unsigned int)(TIMEDAYS * (DSCLASSDEMO(Nowport)->countdays));

    /* 注意这里,QTime24小时,计数器会自动转换为0 */
    if(timepassed > TIMEDAYS)   /* 49天的问题 */
        DSCLASSDEMO(Nowport)->countdays++;

    GetFramesStatistics(DSCLASSDEMO(Nowport)->ChannelHandle, &frame_statistics);

#if 0
    SetupSubChannel(DSCLASSDEMO(Nowport)->ChannelHandle, 1);
    GetFramesStatistics(DSCLASSDEMO(Nowport)->ChannelHandle, &sub_frame_statistics);
    SetupSubChannel(DSCLASSDEMO(Nowport)->ChannelHandle, 0);
#endif
    audioframerate = ((float)frame_statistics.AudioFrames) / ((float)elapseTime / (float)1000);

    emit    audioChange(Nowport, audioframerate);

    videoframerate = ((float)frame_statistics.VideoFrames) / ((float)elapseTime / (float)1000);

    emit    videoChange(Nowport, videoframerate);

    totalFrame = frame_statistics.VideoFrames + frame_statistics.AudioFrames;

    emit    totalChange(Nowport, totalFrame);

    LostFrame = sub_frame_statistics.FramesLost;

    /*
     * bitRate= (int)(float(DSCLASSDEMO(SelectPort)->bit_rate_size)/((float)elapseTime/(float)8000));
     */
    emit    bitRateChange(Nowport, frame_statistics.CurBps);
    if(Nowport == 4)
    {
        OutputDebugString("frame_statistics: %d,%d,%d\n", frame_statistics.AudioFrames,
                          frame_statistics.VideoFrames, frame_statistics.CurBps);
    }

    userCount = MP4_ServerGetState();
    if(userCount <= 0)
        userCount = 0;

    emit    countChange(userCount);
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
void QSDLWidget::process_time_loop()
{
    int             totalport;
    char            savepath[10] = ".";
    struct statfs   bbuf;
    int             Nowport = 0;
    int             temp;
    int             ImageLength = 0;
    int             width;
    int             height;
    int             fps = 5;                        /* 在函数SetImageStream中用到 */

    totalport = GetTotalChannels();

    for(temp = 0; temp < totalport; temp++)
    {
        QTimer*     Qtemp = (QTimer *) (this->sender());
        if(atoi(Qtemp->name()) == temp)
        {
            Nowport = temp;
            break;
        }
    }

    for(temp = 0; temp < totalport; temp++)
    {
        if(DSCLASSDEMO(temp)->imagefile_flag)
        {
            width = DSCLASSDEMO(temp)->imagewidth;
            height = DSCLASSDEMO(temp)->imageheight;
            ImageLength += (fps * (width * height * 3 / 2) * TIMECONST) / (8 * 1024);
        }
    }

    if(statfs(savepath, &bbuf) < 0)
    {
        OutputErrorString("statsfs() faied, error: %d\n", errno);
    }
    else
    {
        if((int)(bbuf.f_bavail * (bbuf.f_bsize / 1024)) <= (int)
               ((TIMECONST * (totalport * FIXSIZE) + ImageLength) + LastSpace))
        /* If no enough space, reset count */
        {
            OutputDebugString("No enough space.avialable blocks = %ld\n", bbuf.f_bavail);
            if(!(DSCLASSDEMO(Nowport)->fullspace_flag))
            {
                emit    fullSpace();
                DSCLASSDEMO(Nowport)->Maxcount = DSCLASSDEMO(Nowport)->count;
                OutputDebugString("fullspace$$$$$ the max count of port %02d is %d\n", Nowport,
                                  DSCLASSDEMO(Nowport)->Maxcount);

                DSCLASSDEMO(Nowport)->count = -1;   /* 当硬盘第一次满的时候清除count值 */
                DSCLASSDEMO(Nowport)->fullspace_flag = 1;
            }
        }
    }

    if((DSCLASSDEMO(Nowport)->Maxcount == DSCLASSDEMO(Nowport)->count) &&
       (DSCLASSDEMO(Nowport)->fullspace_flag))
    {
        OutputDebugString("&&&&&&port %02d get the count %d\n", Nowport, DSCLASSDEMO(Nowport)->count);
        DSCLASSDEMO(Nowport)->count = -1;           /* 当count值达到最大值的时候, 清除count值 */
    }

#ifdef WRITE_FILE
    if(DSCLASSDEMO(Nowport)->record_flag || DSCLASSDEMO(Nowport)->cifqcif_flag ||
       DSCLASSDEMO(Nowport)->imagefile_flag)
        DSCLASSDEMO(Nowport)->count++;
    else
        return;

    if(DSCLASSDEMO(Nowport)->record_flag)
    {
        dsdemoclass[Nowport]->CreateFiles();
    }

    if(DSCLASSDEMO(Nowport)->cifqcif_flag)
    {
        dsdemoclass[Nowport]->CreateCifQcifFiles();
    }

    if(DSCLASSDEMO(Nowport)->imagefile_flag)
    {
        dsdemoclass[Nowport]->CreateImageStreamFiles();

        /*
         * After stop imagestream and then start imagestream right now, it will overwrite
         * the newest imagefile
         */
#if 0
        int width = DSCLASSDEMO(Nowport)->imagewidth;
        int height = DSCLASSDEMO(Nowport)->imageheight;
        (DSCLASSDEMO(Nowport)->imagefile_fd)->writeBlock((char*)(DSCLASSDEMO(Nowport)->imageBuf),
                                                         (width * height * 3) / 2);
#endif
    }
#endif
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
void QSDLWidget::OsdEnableSet(bool on)
{
    DSCLASSDEMO(SelectPort)->osd_flag = int(on);
    SetOsd(DSCLASSDEMO(SelectPort)->ChannelHandle, int(on));
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
void QSDLWidget::OsdEnableAllSet(bool on)
{
    int temp = SelectPort;
    int port;

    for(port = 0; port < GetTotalChannels(); port++)
    {
        if(on)
        {
            if(!(DSCLASSDEMO(port)->osd_flag))
            {
                SelectPort = port;
                OsdEnableSet(TRUE);
            }
        }
        else
        {
            if(DSCLASSDEMO(port)->osd_flag)
            {
                SelectPort = port;
                OsdEnableSet(FALSE);
            }
        }
    }

    SelectPort = temp;
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
void QSDLWidget::OsdTranslucentSet(bool on)
{
    dsdemoclass[SelectPort]->SetOsdTranslucent(short(on));
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
void QSDLWidget::OsdTranslucentAllSet(bool on)
{
    int temp = SelectPort;
    int port;

    for(port = 0; port < GetTotalChannels(); port++)
    {
        SelectPort = port;
        OsdTranslucentSet(on);
    }

    SelectPort = temp;
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
void QSDLWidget::OsdBrightnessSet(int number)
{
    dsdemoclass[SelectPort]->SetOsdBrightness(number);
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
void QSDLWidget::OsdBrightnessAllSet(int number)
{
    int temp = SelectPort;
    int port;

    for(port = 0; port < GetTotalChannels(); port++)
    {
        SelectPort = port;
        OsdBrightnessSet(number);
    }

    SelectPort = temp;
}

/*
 =======================================================================================================================
 *
 =======================================================================================================================
 */
void QSDLWidget::OsdPosXSet(int number)
{
    dsdemoclass[SelectPort]->SetOsdPosX(short(number));
}

/*
 =======================================================================================================================
 *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -