当前位置:网站首页>Player practice 20 unpacking thread
Player practice 20 unpacking thread
2022-06-12 14:10:00 【Sister Suo】

To open xvideothread( To initialize the playback control, its abstract class needs to be passed in ),xaudiothread,xedmux,
take testtread Class encapsulated into the unpacking thread
1.xdemuxthread.h
#pragma once
#include<qthread.h>
#include<mutex>
#include"ivideocall.h"
#include"xdemux.h"
#include"xaudiothread.h"
#include"xvideothread.h"
class xdemuxthread:public QThread
{
public:
virtual bool open(const char* url,ivideocall *call);
// Start all threads , Create an object and open
virtual void start();
xdemuxthread();
virtual ~xdemuxthread();
void run();
protected:
xdemux *demux=0;
xvideothread *vt=0;
xaudiothread *at=0;
std::mutex mux;
bool isexit = false;
};
#include "xdemuxthread.h"
#include<iostream>
using namespace std;
void xdemuxthread::run()
{
while (!isexit)
{
mux.lock();
if (!demux)
{
mux.unlock();// if demux If it is not opened, unlock it to let other threads in , wait for 5 Second hope demux Can open the , Then make the next judgment , Judge demux Whether to open
msleep(5);
continue;
}
AVPacket* pkt = demux->readfz();
if (!pkt)
{
// It's the end
mux.unlock();
msleep(5);
continue;
}
if (demux->isvideo(pkt))
{
if (vt)vt->push(pkt);
}
else
{
if (at)at->push(pkt);
}
mux.unlock();
}
}
xdemuxthread::xdemuxthread()
{
}
xdemuxthread::~xdemuxthread()
{
isexit = true;// The current thread is not stopped until the destructor is called
wait();
cout << " Unpack thread exit " << endl;
}
bool xdemuxthread::open(const char* url, ivideocall* call)
{
mux.lock();
if (!demux)demux = new xdemux();
if (!vt)vt = new xvideothread();
if (!at)at = new xaudiothread();
bool re=demux->Open(url);
if (!re)
{
cout << "demux->open(url) failed!";
return false;
}
re = vt->open(demux->CopyVPara(),call,demux->width,demux->height);
if (!re)
{
cout << "vt->open(url) failed!";
re = false;
}
re = at->open(demux->CopyAPara(), demux->sampletrate, demux->channels);
if (!re)
{
cout << "at->open(url) failed!";
re = false;
}
mux.unlock();
cout << "xdemuxopen open:(1 success 0 Failure )" << re << endl;
return true;
}
void xdemuxthread::start()
{
mux.lock();
QThread::start();// Start the current thread , Call the... Of the current class run()
if (at)at->start();
if (vt)vt->start();
mux.unlock();
}
1. stay open Open audio thread and video thread in
2. When the main function calls the... Of the decoding thread run Called when xdemuxthread::start(), Call the... Of the audio thread in this function run With video threads run
3. stay run By reading the package packet, Determine its type , If it's a video push Queue for video threads , If it is audio, then push Queue for audio thread
At this time main() The function is greatly simplified :
using namespace std;
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
Xplay2 w;
w.show();
xdemuxthread dt;
dt.open("E:\\ffmpeg\\test222.mp4",w.ui.openGLWidget);
dt.start();
return a.exec();
}
边栏推荐
- 如何使用android studio制作一个阿里云物联网APP
- Lua common built-in functions
- Shell notes
- Introduction to database system (Fifth Edition) notes Chapter 1 Introduction
- 什么是自动出价?它的优势是什么?
- 2000. reverse word prefix
- Briefly describe the difference between CGI and fastcgi
- SystemC:SC_ Thread and SC_ METHOD
- Conversion of player's actual 10 pixel format and size
- 公司运营中更注重转化的出价策略,如何实现? —Google sem
猜你喜欢

Lua callinfo structure, stkid structure resolution

Design of PLC intelligent slave station based on PROFIBUS DP protocol

程序分析与优化 - 6 循环优化

Implementation and debug of process hiding under x64

Dismantle and modify the advertising machine - Amateur decompression

动态搜索广告智能查找匹配关键字

How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem

Briefly describe the difference between CGI and fastcgi

Relevant knowledge points of cocoapods

初学者入门阿里云haas510开板式DTU(2.0版本)--510-AS
随机推荐
高考回憶錄
Is MySQL query limit 1000,10 as fast as limit 10? How to crack deep paging
Leetcode 2185. 统计包含给定前缀的字符串
[wustctf2020] selfie score query -1
Dismantle and modify the advertising machine - Amateur decompression
Why do Chinese programmers change jobs?
【mysql进阶】mysql索引数据结构的演变(四)
Socket model of punctual atom stm32f429 core board
Implementation of Ackermann function with simulated recursion
对于跨境电商,更侧重收入的出价策略 —Google SEM
SystemC time
SystemC uses SC_ report_ Handler processing log printing
【mysql进阶】索引分类及索引优化方案(五)
Wait function in SystemC
Running phase of SystemC
CSDN blog points rule
注重点击,追求更多用户进入网站,可以选择什么出价策略?
TestEngine with ID ‘junit-vintage‘ failed to discover tests
Fourteen week assignment
拆改广告机---业余解压