头文件:avi_t.h
#include "user.h"
#include "ui_user.h"
#include <QModelIndex>
#include <QHeaderView>
#include <QMessageBox>
User::User(QDialog *parent) :
QDialog(parent),
ui(new Ui::User)
{
ui->setupUi(this);
setWindowTitle("用户列表管理");
userinfo();
}
User::~User()
{
delete ui;
}
void User::userinfo()
{
model = new QSqlTableModel;
model->setTable("userinfo");
model->select();
ui->userTableView->setModel(model);
ui->userTableView->horizontalHeader()->setSortIndicatorShown(true);
connect(ui->userTableView->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(slotHeadViewClicked(int)));
}
void User::slotHeadViewClicked(int logicalIndex)
{
Qt::SortOrder order = ui->userTableView->horizontalHeader()->sortIndicatorOrder();
if(order == Qt::AscendingOrder)
{
model->setSort(logicalIndex, Qt::DescendingOrder);
}
else
{
model->setSort(logicalIndex, Qt::AscendingOrder);
}
model->select();
}
void User::on_delPushButton_clicked()
{
int curRow = ui->userTableView->currentIndex().row();
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->removeRow(curRow);
int ok = QMessageBox::warning(this, "确认删除", "你确定要删除当前记录?", QMessageBox::Yes, QMessageBox::No);
if(ok == QMessageBox::Yes)
{
model->submitAll();
}
else
{
model->revertAll();
}
model->setEditStrategy(QSqlTableModel::OnFieldChange);
}
void User::on_submitPushButton_clicked()
{
model->database().transaction(); //事物处理
if(model->submitAll())
{
model->database()mit();
}
else
{
model->database().rollback();
QMessageBox::warning(this, "data submit error", model->lastError().text());
}
}
头文件:myplayer.h
#ifndef MYPLAYER_H
#define MYPLAYER_H
#include <QDialog>
#include <Phonon>
namespace Ui {
class Myplayer;
}
class Myplayer : public QDialog
{
Q_OBJECT
public:
explicit Myplayer(QDialog *parent = 0);
~Myplayer();
QString filePath;
public slots:
void on_playToolButton_clicked();
private slots:
void on_stopToolButton_clicked();
void on_pauseToolButton_clicked();
private:
Ui::Myplayer *ui;
Phonon::MediaObject *mediaObject;
Phonon::VideoWidget *videoWidget;
};
#endif // MYPLAYER_H
头文件:savetoavi.h
#ifndef SAVETOAVI_H
#define SAVETOAVI_H
#include "avi_t.h"
/
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
class saveTOAVI
{
public:
saveTOAVI();
void getFileName1(char *name);
void getFileName2(char *name);
void getFileName3(char *name);
void getFileName4(char *name);
avi_t* AVI_o
pen_output_file(char * filename);
void AVI_set_video(avi_t *&AVI, long width, long height, double fps, char *compressor);
int AVI_close(avi_t *&AVI);
int avi_close_output_file(avi_t *&AVI);
int avi_add_chunk(avi_t *&AVI, char *tag, char *data, int length);
void long2str(unsigned char *dst, int n);
int avi_sampsize(avi_t *&AVI);
int AVI_write_frame(avi_t *&AVI, char *&data, long bytes);
int avi_write_data(avi_t *&AVI, char *&data, long length, int audio);
int avi_add_index_entry(avi_t *&AVI, char *tag, long flags, long pos, long len);
};
#endif // SAVETOAVI_H
头文件:spcaframe.h
struct frame_t{
char header[5];
int nbframe;
double seqtimes;
int deltatimes;
int w;
int h;
int size;
int format;
unsigned short bright;
unsigned short contrast;
unsigned short colors;
unsigned short exposure;
unsigned char wakeup;
int acknowledge;
} __attribute__ ((packed));
struct client_t{
char message[4];
unsigned char x;
unsigned char y;
unsigned char fps;
unsigned char updobright;
unsigned char updocontrast;
unsigned char updocolors;
unsigned char updoexposure;
unsigned char updosize;
unsigned char sleepon;
} __attribute__ ((packed));
头文件:user.h
#ifndef USER_H
#define USER_H
#include <QDialog>
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QSqlError>
#include <QTableView>
namespace Ui {
class User;
}
class User : public QDialog
{
Q_OBJECT
public:
explicit User(QDialog *parent = 0);
~User();
QSqlTableModel *model;
private:
Ui::User *ui;
void userinfo();
private slots:
void slotHeadViewClicked(int);
void on_delPushButton_clicked();
void on_submitPushButton_clicked();
};
#endif // USER_H
头文件:userinfo.h
#ifndef USER_H
#define USER_H
#include <QDialog>
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QSqlError>
#include <QTableView>
namespace Ui {
class User;
}
class User : public QDialog
{
Q_OBJECT
public:
explicit User(QDialog *parent = 0);
~User();
QSqlTableModel *model;
private:
Ui::User *ui;
void userinfo();
private slots:
void slotHeadViewClicked(int);
void on_delPushButton_clicked();
void on_submitPushButton_clicked();
};
#endif // USER_H
头文件:videopro.h
#ifndef VIDEOPRO_H
#define VIDEOPRO_H
#include "avi_t.h"
#include "savetoavi.h"
#include "spcaframe.h"
#include "user.h"
#include "userinfo.h"
#include "myplayer.h"
#include <QWidget>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QHostAddress>
#include <QTextCodec>
#include <QTcpSocket>
#include <QTime>
#include <QTimer>
#include <QFileInfo>
#include <QTcpSocket>
#include <QByteArray>
#include <QPixmap>
#include <QMouseEvent>
#include <QListWidgetItem>
namespace Ui {
class VideoPro;
}
cla
ss VideoPro : public QWidget
{
Q_OBJECT
public:
explicit VideoPro(QWidget *parent = 0);
~VideoPro();
signals:
void videoDoubleClickEvent(int);
private slots:
void slotVideo1Received();
void slotVideoConnect();
void slotVideo1Disconnect();
void slotVideo1Error(QAbstractSocket::SocketError);
void slotVideo2Received();
// void slotVideo2Connect();
void slotVideo2Disconnect();
void slotVideo2Error(QAbstractSocket::SocketError);
void slotVideo3Received();
// void slotVideo3Connect();
void slotVideo3Disconnect();
void slotVideo3Error(QAbstractSocket::SocketError);
void slotVideo4Received();
// void slotVideo4Connect();
void slotVideo4Disconnect();
void slotVideo4Error(QAbstractSocket::SocketError);
void slotVideoDoubleClickEvent(int);
void slotPlayer(QListWidgetItem*);
void on_loginPushButton_clicked();
void on_registPushButton_clicked();
void on_submitPushButton_clicked();
void on_CancelPushButton_clicked();
void on_startPushButton_clicked();
void on_filePushButton_clicked();
void on_pause1pushButton_clicked();
void on_pause2pushButton_clicked();
void on_pause3pushButton_clicked();
void on_pause4pushButton_clicked();
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::VideoPro *ui;
QHostAddress hostAddr;
QTcpSocket *clientSocket;
QTcpSocket *videoSocket1;
QTcpSocket *videoSocket2;
QTcpSocket *videoSocket3;
QTcpSocket *videoSocket4;
QString username;
QString loginPsw;
QTimer *timer1;
QTimer *timer2;
QTimer *timer3;
QTimer *timer4;
bool isGotFrameHead1;
bool isGotFrameHead2;
bool isGotFrameHead3;
bool isGotFrameHead4;
bool isOpen1;
bool isOpen2;
bool isOpen3;
bool isOpen4;
bool isBig;
bool v1;
bool v2;
bool v3;
bool v4;
int port;
struct frame_t *frame1;
struct frame_t *frame2;
struct frame_t *frame3;
struct frame_t *frame4;
struct client_t *message1;
struct client_t *message2;
struct client_t *message3;
struct client_t *message4;
saveTOAVI *video1;
saveTOAVI *video2;
saveTOAVI *video3;
saveTOAVI *video4;
avi_t *out_fd1;
avi_t *out_fd2;
avi_t *out_fd3;
avi_t *out_fd4;
QString videoName1;
QString videoName2;
QString videoName3;
QString videoName4;
QTime curTime;
int minute1;
int minute2;
int minute3;
int minute4;
User *user;
UserInfo *userInfo;
Myplayer *player;
enum SOCKET{SOCKET1, SOCKET2, SOCKET3, SOCKET4};
int init_message(struct client_t *&message, struct frame_t *&frame);
void openFile1();
void closeFile1();
void openFile2();
void closeFile2();
void openFile3();
void closeFile3();
void openFile4();
void closeFile4();
void ad
dAllFile(QString name);
protected:
void mouseDoubleClickEvent(QMouseEvent *e);
};
#endif // VIDEOPRO_H
源文件:main.cpp
#include <QtGui/QApplication>
#include "videopro.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1"); //mysql服务器所在的IP地址
db.setUserName("root"); //登录mysql服务器的用户名
db.setPassword("123456"); //MYSQL登录密码
db.setDatabaseName("videomonitor");
bool ok = db.open();
if(!ok)
{
QMessageBox::critical(0, "Database Open Error", db.lastError().text());
return false;
}
VideoPro w;
w.show();
();
}
源文件:myplayer.cpp
#include "myplayer.h"
#include "ui_myplayer.h"
#include <QFileDialog>
#include <QMessageBox>
Myplayer::Myplayer(QDialog *parent) :
QDialog(parent),
ui(new Ui::Myplayer)
{
ui->setupUi(this);
setWindowTitle("Mplayer播放器");
mediaObject = new Phonon::MediaObject(this);
videoWidget = new Phonon::VideoWidget(this);
videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioWidget);
Phonon::createPath(mediaObject, videoWidget);
ui->verticalLayout->insertWidget(0, videoWidget);
Phonon::SeekSlider *slider = new Phonon::SeekSlider(this);
slider->setMediaObject(mediaObject);
ui->verticalLayout->insertWidget(1, slider);
}
Myplayer::~Myplayer()
{
delete ui;
}
void Myplayer::on_playToolButton_clicked()
{
qDebug() << filePath;
if(mediaObject->state() == Phonon::PausedState)
{
mediaObject->play();
ui->playToolButton->setEnabled(false);
ui->pauseToolButton->setEnabled(true);
return;
}
mediaObject->setCurrentSource(Phonon::MediaSource(filePath));
mediaObject->play();
ui->playToolButton->setEnabled(false);
ui->pauseToolButton->setEnabled(true);
}
void Myplayer::on_stopToolButton_clicked()
{
if(mediaObject->state() == Phonon::PlayingState || mediaObject->state() == Phonon::PausedState)
{
mediaObject->stop();
}
ui->playToolButton->setEnabled(true);
}
void Myplayer::on_pauseToolButton_clicked()
{
if(mediaObject->state() == Phonon::PlayingState)
{
mediaObject->pause();
}
ui->playToolButton->setEnabled(true);
ui->pauseToolButton->setEnabled(false);
}
源文件:savetoavi.cpp
#include "savetoavi.h"
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#define MAXCOMP 4
#define PREC int
#define HEADERBYTES 2048
#define AVI_MAX_LEN 2000000000
#define AVI_MODE_WRITE 0
#define AVI_MODE_READ 1
#define AVIF_HASINDEX
0x00000010 /* Index at end of file */
#define AVIF_MUSTUSEINDEX 0x00000020
#define AVIF_ISINTERLEAVED 0x00000100
#define AVIF_TRUSTCKTYPE 0x00000800 /* Use CKType to find key frames */
#define AVIF_WASCAPTUREFILE 0x00010000
#define AVIF_COPYRIGHTED 0x00020000
#define OUT4CC(s) \
if(nhb<=HEADERBYTES-4) memcpy(AVI_header+nhb,s,4); nhb += 4
#define OUTLONG(n) \
if(nhb<=HEADERBYTES-4) long2str(AVI_header+nhb,n); nhb += 4
#define OUTSHRT(n) \
if(nhb<=HEADERBYTES-2) { \
AVI_header[nhb ] = (n )&0xff; \
AVI_header[nhb+1] = (n>>8)&0xff; \
} \
nhb += 2
#define PAD_EVEN(x) ( ((x)+1) & ~1 )
////////////////////////////////////////////////////////////////////////////////////////
saveTOAVI::saveTOAVI()
{
}
void saveTOAVI::getFileName1(char *name)
{
char temp[100];
char *myext = "avi";
int i = 1;
time_t curdate;
struct tm *tdate;
memset (temp, '\0', sizeof (temp));
time (&curdate);
tdate = localtime (&curdate);
snprintf (temp, 100, "/home/yzm/videomonitor/video1/%4d-%2d-%2d_%2d:%2d.%s",
tdate->tm_year + 1900, tdate->tm_mon + 1, tdate->tm_mday,
tdate->tm_hour, tdate->tm_min, myext);
while(access(temp, 0) == 0)
{
memset(temp, '\0', sizeof(temp));
snprintf (temp, 100, "/home/yzm/videomonitor/video1/%4d-%2d-%2d_%2d:%2d(%d).%s",
tdate->tm_year + 1900, tdate->tm_mon + 1, tdate->tm_mday,
tdate->tm_hour, tdate->tm_min, i, myext);
i++;
}
memcpy (name, temp, strlen (temp));
}
void saveTOAVI::getFileName2(char *name)
{
char temp[100];
char *myext = "avi";
int i = 1;
time_t curdate;
struct tm *tdate;
memset (temp, '\0', sizeof (temp));
time (&curdate);
getsavefilenametdate = localtime (&curdate);
snprintf (temp, 100, "/home/yzm/videomonitor/video2/%4d-%2d-%2d_%2d:%2d.%s",
tdate->tm_year + 1900, tdate->tm_mon + 1, tdate->tm_mday,
tdate->tm_hour, tdate->tm_min, myext);
while(access(temp, 0) == 0)
{
memset(temp, '\0', sizeof(temp));
snprintf (temp, 100, "/home/yzm/videomonitor/video2/%4d-%2d-%2d_%2d:%2d(%d).%s",
tdate->tm_year + 1900, tdate->tm_mon + 1, tdate->tm_mday,
tdate->tm_hour, tdate->tm_min, i, myext);
i++;
}
memcpy (name, temp, strlen (temp));
}
void saveTOAVI::getFileName3(char *name)
{
char temp[100];
char *myext = "avi";
int i = 1;
time_t curdate;
struct tm *tdate;
memset (temp, '\0', sizeof (temp));
time (&curdate);
tdate = localtime (&curdate);
snprintf (temp, 100, "/home/yzm/videomonitor/video3/%4d-%2d-%2d_%2d:%2d.%s",
tdate->tm_year + 1900, tdate->tm_mon + 1, tdate->tm_mday,
tdate->tm_hour, tdate->tm_min, myext);
while(access(temp, 0) == 0)
{
memset(temp, '\0', sizeof(te
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论