Chia Sẽ Kinh Nghiệm Về IT



Tìm Kiếm Với Google
-


Gởi Ðề Tài Mới  Gửi trả lời
 
Công Cụ Xếp Bài
Tuổi 10-06-2014, 04:22 PM   #1
hoctinhoc
Guest
 
Trả Lời: n/a
Streaming video trên KIT Tiny6410
Streaming video trên KIT Tiny6410



1. Giới thiệu

Bài viết này minh họa kỹ thuật streaming video, viết chương trình streaming video server bằng Qt chạy trên KIT Linux FriendlyArm Tiny6410.

Xem thêm bài viết về kỹ thuật này Tìm hiểu kỹ thuật video streaming

Chương trình sử dụng thư viện live555 để streaming các file video có định dạng .mkv , .264, .webm, etc...
Về bản chất, thư viện live555 là một thư viện triển khai giao thức RTSP, RTP để thực hiện quá trình streaming video thỏa mãn điều kiện ràng buộc về mặt thời gian. Với thư viện này, người sử dụng hoàn toàn có thể thử nghiệm kỹ thuật streaming với các loại file video, audio khác nhau với các điều kiện môi trường mạng khác nhau.

2. Xây dựng chương trình

Thiết kế giao diện Qt cho ứng dụng streaming video server chạy trên KIT


Giao diện ứng dụng server có chức năng hiện các thông báo trạng thái của server.

Server có một luồng chính làm nhiệm vụ tạo rstp server (thư viện LIVE555) để phục vụ các yêu cầu từ các client gửi đến.

Chương trình gồm 2 lớp MainWindow và ThreadStream.
Lớp MainWindow : lớp này kế thừa QMainWindow và tạo giao diện cho chương trình streaming video. Mã nguồn của lớp MainWindow: gồm 2 file mainwindow.h và mainwindow.cpp
/* file mainwindow.h */
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_btStream_clicked();
void on_btCancel_clicked();
void notifyThreadStartedMessage();
void notifyThreadStopedMessage();
void notifyServerMessage(QString message);
private:
Ui::MainWindow *ui;
ThreadStream *streamVideoThread; //Khai báo luồng streaming video
};

/* file mainwindow.cpp */
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
streamVideoThread = new ThreadStream(this); connect(streamVideoThread,SIGNAL(started()),this,
SLOT(notifyThreadStartedMessage()));
connect(streamVideoThread,SIGNAL(terminated()),thi s,
SLOT(notifyThreadStopedMessage()));
connect(streamVideoThread,SIGNAL(notifyMessage(QSt ring)),this,
SLOT(notifyServerMessage(QString)));
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_btStream_clicked()
{
this->streamVideoThread->start(); //Goi run
}
void MainWindow::on_btCancel_clicked()
{
this->streamVideoThread->terminate();
}
void MainWindow::notifyThreadStartedMessage()
{
ui->txtMessage->setText(QString("Server is streaming..."));
}
void MainWindow::notifyThreadStopedMessage()
{
ui->txtMessage->setText(QString("Server is stopped."));
}

void MainWindow::notifyServerMessage(QString message)
{
ui->txtMessage->append(message);
}

Lớp ThreadStream: Lớp này kế thừa từ lớp QThread và thực hiện tạo luồng streaming video
/* file threadstream.h */
class ThreadStream : public QThread {
Q_OBJECT
public:
explicit ThreadStream(QObject *parent = 0);
virtual void run();
signals:
void notifyMessage(QString message);
};



/* file threadstream.cpp */
ThreadStream::ThreadStream(QObject *parent):QThread(parent)
{
}
void ThreadStream::run()
{
// Begin by setting up our usage environment:
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
UserAuthenticationDatabase* authDB = NULL;
#ifdef ACCESS_CONTROL
// To implement client access control to the RTSP server, do the following:
authDB = new UserAuthenticationDatabase;
authDB->addUserRecord("username1", "password1"); // replace these with real strings
// Repeat the above with each <username>, <password> that you wish to allow
// access to the server.
#endif
// Create the RTSP server. Try first with the default port number (554),
// and then with the alternative port number (8888):
RTSPServer* rtspServer;
portNumBits rtspServerPortNum = 554;
rtspServer = DynamicRTSPServer::createNew(*env, rtspServerPortNum, authDB);
if (rtspServer == NULL) {
rtspServerPortNum = 8888;
rtspServer = DynamicRTSPServer::createNew(*env, rtspServerPortNum, authDB);
}
if (rtspServer == NULL) {
QString msg = "Failed to create RTSP server";
emit notifyMessage(msg);
exit(1);
}
QString msge = "LIVE555 Media Server\n";
char* urlPrefix = rtspServer->rtspURLPrefix();
msge += "Play streams from this server using the URL\n\t"
+ QString(urlPrefix) + "<filename>\nwhere <filename> is a file present in the current directory.\n"
+ "Each file's type is inferred from its name suffix:\n"
+ "\t\".264\" => a H.264 Video Elementary Stream file\n"
+ "\t\".aac\" => an AAC Audio (ADTS format) file\n"
+ "\t\".ac3\" => an AC-3 Audio file\n"
+ "\t\".amr\" => an AMR Audio file\n"
+ "\t\".dv\" => a DV Video file\n"
+ "\t\".m4e\" => a MPEG-4 Video Elementary Stream file\n"
+ "\t\".mkv\" => a Matroska audio+video+(optional)subtitles file\n"
+ "\t\".mp3\" => a MPEG-1 or 2 Audio file\n"
+ "\t\".mpg\" => a MPEG-1 or 2 Program Stream (audio+video) file\n"
+ "\t\".ts\" => a MPEG Transport Stream file\n"
+ "\t\t(a \".tsx\" index file - if present - provides server 'trick play' support)\n"
+ "\t\".wav\" => a WAV Audio file\n"
+ "\t\".webm\" => a WebM audio(Vorbis)+video(VP8) file\n";
emit notifyMessage(msge);
env->taskScheduler().doEventLoop(); // does not return
}


3. Thử nghiệm trên KIT FriendlyArm Tiny6410


Nối KIT Tiny6410 với PC sử dụng mạng LAN (cấu hình cùng giải địa chỉ).

KIT Tiny6410 đóng vai trò RTSP server chạy ứng dụng streaming video server.

PC đóng vai trò RTSP client chạy 2 ứng dụng: một ứng dụng có sẵn VLC và một ứng dụng streaming client viết bằng C# (dùng thư viện VLC .NET)

Hình ảnh kết quả:



RTSP Server trên Tiny6410




RTSP Client trên PC (C# + VLC .NET)


Video minh họa

Qt streaming video server Tiny6410
  Trả lời ngay kèm theo trích dẫn này
Gửi trả lời


Công Cụ
Xếp Bài

Quyền Hạn Của Bạn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Hình Cảm xúc đang Mở
[IMG] đang Mở
Mã HTML đang Tắt




Bây giờ là 08:15 PM. Giờ GMT +7



Diễn đàn tin học QuantriNet
quantrinet.com | quantrimang.co.cc
Founded by Trương Văn Phương | Developed by QuantriNet's members.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.