no message

master
zcy 2023-11-30 00:22:43 +08:00
parent 02696e243c
commit cf02c1cb4b
11 changed files with 99 additions and 36 deletions

View File

@ -41,7 +41,7 @@ int main(int argc, char *argv[])
MainWindow main; MainWindow main;
main.setWindowTitle("직첵竟꿎桿묏야"); main.setWindowTitle("직첵竟꿎桿묏야");
main.setFixedSize(1920,1080); main.setFixedSize(1280,769);
main.show(); main.show();
return app.exec(); return app.exec();
} }

View File

@ -97,13 +97,14 @@ void MainWindow::on_pushButton_2_clicked()
GUIDToAvFormat(mCamera->MediaType())); GUIDToAvFormat(mCamera->MediaType()));
} }
mCamera->SetObserver(mVideoCoder); mCamera->SetObserver(mVideoCoder);
if(mPusher == nullptr)
mPusher = new H264RtmpPuser();
// todo 根据返回结果判断是否推流 // todo 根据返回结果判断是否推流
qDebug()<<"连接RTMP服务器"<<ui->lineEdit->text(); qDebug()<<"连接RTMP服务器"<<ui->lineEdit->text();
if (!mPusher->IfConnect()) { if (!mPusher->IfConnect()) {
const char* address = ui->lineEdit->text().toLocal8Bit().data(); const char* address = ui->lineEdit->text().toLocal8Bit().data();
qDebug()<<address; qDebug()<<address;
if (0 == mPusher->RTMP264_Connect("rtmp://127.0.0.1:1939/live/1")) { if (0 == mPusher->RTMP264_Connect("rtmp://hyrtc.net:2530/live/123")) {
ToastWidget::showTip("已经连接上RTMP服务器",this->parentWidget()); ToastWidget::showTip("已经连接上RTMP服务器",this->parentWidget());
mVideoCoder->SetOberver(mPusher); mVideoCoder->SetOberver(mPusher);
mPusher->StartPush(); mPusher->StartPush();

View File

@ -1,7 +1,7 @@
#ifndef __CAPTUREAUDIO_H__ #ifndef __CAPTUREAUDIO_H__
#define __CAPTUREAUDIO_H__ #define __CAPTUREAUDIO_H__
#include "stdint.h" #include "stdint.h"
#include "../third/portaudio/portaudio.h" #include "../third/portaudio/include/portaudio.h"
#include <vector> #include <vector>
#include <string> #include <string>
//Windows //Windows

View File

@ -208,6 +208,8 @@ int H264RtmpPuser::sortAndSendNal(uint8_t * data, int len)
uint8_t * nalhead = nullptr; uint8_t * nalhead = nullptr;
uint8_t * naltail = nullptr; uint8_t * naltail = nullptr;
uint32_t size = 0; uint32_t size = 0;
static uint32_t time = 0;
if(0 == mStartTime){ if(0 == mStartTime){
mStartTime = RTMP_GetTime(); mStartTime = RTMP_GetTime();
} }
@ -221,11 +223,12 @@ int H264RtmpPuser::sortAndSendNal(uint8_t * data, int len)
&& ((data[i + 2] == 0x00) && (data[i + 3] == 0x01) || (data[i + 2] == 0x01))) { && ((data[i + 2] == 0x00) && (data[i + 3] == 0x01) || (data[i + 2] == 0x01))) {
if ((nalhead == nullptr) && (i == 0) ) { if ((nalhead == nullptr) && (i == 0) ) {
if ((data[i + 3] == 0x01) && (data[i + 4] == 0x41)) { //p ÖĄÖą˝Óˇ˘ if ((data[i + 3] == 0x01) && (data[i + 4] == 0x41)) { //p ÖĄÖą˝Óˇ˘
time += 100;
nalhead = data; nalhead = data;
naltail = data + (len); naltail = data + (len);
size = naltail - nalhead; size = naltail - nalhead;
this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); this->SendH264Packet(nalhead, size, 0, time - mStartTime);
return 0; return 0;
} }
//sps ÖĄ˝řĐĐ˝â°ü //sps ÖĄ˝řĐĐ˝â°ü
@ -241,21 +244,22 @@ int H264RtmpPuser::sortAndSendNal(uint8_t * data, int len)
else { else {
// i frame // i frame
if ((data[i + 2] == 0x01) && (data[i + 3] == 0x65)) { if ((data[i + 2] == 0x01) && (data[i + 3] == 0x65)) {
time += 100;
naltail = data + i; naltail = data + i;
size = naltail - nalhead; size = naltail - nalhead;
this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); this->SendH264Packet(nalhead, size, 0, time - mStartTime);
nalhead = data + i; nalhead = data + i;
naltail = data + (len); naltail = data + (len);
size = naltail - nalhead; size = naltail - nalhead;
this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); this->SendH264Packet(nalhead, size, 0, time - mStartTime);
return 0; return 0;
} }
//pps //pps
if ((data[i + 3] == 0x01) && (data[i + 4] == 0x68)) { // sps or pps or sei if ((data[i + 3] == 0x01) && (data[i + 4] == 0x68)) { // sps or pps or sei
naltail = data + i; naltail = data + i;
size = naltail - nalhead; size = naltail - nalhead;
this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); this->SendH264Packet(nalhead, size, 0, time - mStartTime);
nalhead = data + i; nalhead = data + i;
i += 3; i += 3;
}//sps }//sps
@ -267,7 +271,7 @@ int H264RtmpPuser::sortAndSendNal(uint8_t * data, int len)
if ((data[i + 3] == 0x01) && (data[i + 4] == 0x06)) { // sps or pps or sei if ((data[i + 3] == 0x01) && (data[i + 4] == 0x06)) { // sps or pps or sei
naltail = data + i; naltail = data + i;
size = naltail - nalhead; size = naltail - nalhead;
this->SendH264Packet(nalhead, size, 0, RTMP_GetTime() - mStartTime); this->SendH264Packet(nalhead, size, 0, time - mStartTime);
nalhead = data + i; nalhead = data + i;
i += 3; i += 3;
} }

View File

@ -74,8 +74,8 @@ VideoCoder::VideoCoder(int width, int height, AVPixelFormat formt):
printf("Could not allocate video frame\n"); printf("Could not allocate video frame\n");
} }
mFrame->format = mCodecCtx->pix_fmt; mFrame->format = mCodecCtx->pix_fmt;
mFrame->width = mCodecCtx->width/2; mFrame->width = mCodecCtx->width;
mFrame->height = mCodecCtx->height/2; mFrame->height = mCodecCtx->height;
mFrame->pts = 0; mFrame->pts = 0;
int ret = av_image_alloc(mFrame->data, mFrame->linesize, mCodecCtx->width, mCodecCtx->height, int ret = av_image_alloc(mFrame->data, mFrame->linesize, mCodecCtx->width, mCodecCtx->height,
mCodecCtx->pix_fmt, 8); mCodecCtx->pix_fmt, 8);
@ -125,14 +125,17 @@ void VideoCoder::Encode(uint8_t * src, int size, enum AVPixelFormat format) {
mFrame->pts++; mFrame->pts++;
int got_picture = 0; int got_picture = 0;
//Encode //Encode
avcodec_encode_video2(mCodecCtx, &mAVPack, mFrame, &got_picture); ret = avcodec_encode_video2(mCodecCtx, &mAVPack, mFrame, &got_picture);
if (got_picture > 0) { if (got_picture > 0) {
fwrite(mAVPack.data, 1, mAVPack.size, p);
fflush(p);
if(nullptr != this->mObserver) if(nullptr != this->mObserver)
this->mObserver->OnGetCodeFrame(mAVPack.data, mAVPack.size); this->mObserver->OnGetCodeFrame(mAVPack.data, mAVPack.size);
} }
//Debuger::Debug(L"Succeed to encode frame: %5d\tsize:%5d\n", 1, mAVPack.size); Debuger::Debug(L"Succeed to encode frame: %5d\tsize:%5d\n", 1, mAVPack.size);
fwrite(mAVPack.data, 1, mAVPack.size, p);
fflush(p);
// 刷新coder防止包挤压 // 刷新coder防止包挤压
av_packet_unref(&mAVPack); av_packet_unref(&mAVPack);
av_freep(&pFrame[0]); av_freep(&pFrame[0]);
@ -252,7 +255,7 @@ int VideoCoder::forceYUV420P(uint8_t * src, int size,
memcpy(src_data[0], src, mWidth*mHeight * 3); //Packed memcpy(src_data[0], src, mWidth*mHeight * 3); //Packed
break; break;
} }
case AV_PIX_FMT_RGB32: { case AV_PIX_FMT_BGRA: {
memcpy(src_data[0], src, mWidth*mHeight *4); //Packed memcpy(src_data[0], src, mWidth*mHeight *4); //Packed
break; break;
} }
@ -273,7 +276,6 @@ int VideoCoder::forceYUV420P(uint8_t * src, int size,
*len = mDestWidth*mDestHeight + mDestWidth*mDestHeight / 2; *len = mDestWidth*mDestHeight + mDestWidth*mDestHeight / 2;
// source此时就不需要了但是dst要在外面free // source此时就不需要了但是dst要在外面free
av_freep(&src_data[0]); av_freep(&src_data[0]);
av_freep(&dst_data[0]);
sws_freeContext(img_convert_ctx); sws_freeContext(img_convert_ctx);
return 0; return 0;

View File

@ -2,7 +2,7 @@
#define AUDIOCAPTUREFF_H #define AUDIOCAPTUREFF_H
#include "stdint.h" #include "stdint.h"
#include "../third/portaudio/portaudio.h" #include "../third/portaudio/include/portaudio.h"
#include <vector> #include <vector>
#include <string> #include <string>
//Windows //Windows

View File

@ -9,7 +9,7 @@
3. opengl用于本地摄像头的渲染。 3. opengl用于本地摄像头的渲染。
4. directshow的相关接口用于获取本地的摄像头数据。 4. directshow的相关接口用于获取本地的摄像头数据。
5. 界面风格基于!qssWrpter库 https://gitee.com/290198252/qsswraper 5. 界面风格基于!qssWrpter库 https://gitee.com/290198252/qsswraper
6. librtmp需要openssl 1.10 以下版本 6. librtmp需要openssl 1.10以下版本
### 界面: ### 界面:
@ -20,3 +20,5 @@
#### 发行版 #### 发行版
- win32 - win32

View File

@ -20,5 +20,8 @@ AVPixelFormat GUIDToAvFormat(GUID mediatype){
if(IsEqualIID(MEDIASUBTYPE_RGB32,mediatype)){ if(IsEqualIID(MEDIASUBTYPE_RGB32,mediatype)){
return AV_PIX_FMT_BGRA; return AV_PIX_FMT_BGRA;
} }
if(IsEqualIID(MEDIASUBTYPE_ARGB32,mediatype)){
return AV_PIX_FMT_BGRA;
}
return AV_PIX_FMT_NONE; return AV_PIX_FMT_NONE;
} }

30
utils/utils.h Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include <windows.h>
#include <string>
#include <vector>
#include <functional>
#include <dshow.h>
#include <windows.h>
#include "qedit.h"
#include <mutex>
#include <vector>
#include "guiddef.h"
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libswscale/swscale.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
}
using namespace std;
wstring char2wchar(const char* cchar);
AVPixelFormat GUIDToAvFormat(GUID mediatype);

View File

@ -11,8 +11,8 @@ QT += multimedia
TARGET = yuvgl TARGET = yuvgl
INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib "C:/Program Files/OpenSSL-Win64/include" \ INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib \
$$PWD//third//ffmpeg//include media/
include(G:\\project\\c++qt\\qsswraper\\qsswraper.pri) include(G:\\project\\c++qt\\qsswraper\\qsswraper.pri)
@ -49,7 +49,6 @@ SOURCES += \
media/audiocaptureff.cpp \ media/audiocaptureff.cpp \
media/screen_capture.cpp \ media/screen_capture.cpp \
media/sps_decode.cpp \ media/sps_decode.cpp \
utils/Base64.cpp \
utils/Debuger.cpp \ utils/Debuger.cpp \
utils/utils.cpp utils/utils.cpp
HEADERS += \ HEADERS += \
@ -57,7 +56,8 @@ HEADERS += \
librtmp/strncasecmp.h \ librtmp/strncasecmp.h \
mainwindow.h \ mainwindow.h \
cplaywidget.h \ cplaywidget.h \
media/screen_capture.h media/screen_capture.h \
utils/utils.h
FORMS += \ FORMS += \
@ -65,9 +65,6 @@ FORMS += \
mainwindow.ui mainwindow.ui
INCLUDEPATH += media/ \
C:\\Program Files\\OpenSSL-Win64\\include
contains(DEFINES, __MINGW32__){ contains(DEFINES, __MINGW32__){
message("mingw") message("mingw")
INCLUDEPATH += media/ inc/ INCLUDEPATH += media/ inc/
@ -79,6 +76,7 @@ contains(DEFINES, __MINGW32__){
} else { } else {
message("64-bit") message("64-bit")
} }
}else{ }else{
message("msvc") message("msvc")
@ -88,7 +86,7 @@ contains(DEFINES, __MINGW32__){
contains(QT_ARCH, i386) { contains(QT_ARCH, i386) {
INCLUDEPATH += inc $$PWD/third/msvc32/fdk-aac/include \ INCLUDEPATH += inc $$PWD/third/fdk-aac/include \
$$PWD/third/msvc32/libx264/include \ $$PWD/third/msvc32/libx264/include \
$$PWD/third/msvc32/ffmpeg/include \ $$PWD/third/msvc32/ffmpeg/include \
$$PWD/third/msvc32/openssl/include $$PWD/third/msvc32/openssl/include
@ -101,12 +99,32 @@ contains(DEFINES, __MINGW32__){
LIBS += libavfilter.a libavdevice.a libavcodec.a libpostproc.a \ LIBS += libavfilter.a libavdevice.a libavcodec.a libpostproc.a \
libavformat.a libavutil.a \ libavformat.a libavutil.a \
libswresample.a libswscale.a fdk-aac.lib ws2_32.lib libeay32.lib ssleay32.lib \ libswresample.a libswscale.a fdk-aac.lib ws2_32.lib libeay32.lib ssleay32.lib \
shell32.lib gdi32.lib crypt32.lib User32.lib GDI32.lib Advapi32.lib zlibstaticd.lib Secur32.lib \ shell32.lib gdi32.lib crypt32.lib User32.lib GDI32.lib Advapi32.lib Secur32.lib \
Bcrypt.lib Kernel32.lib portaudio_x86.lib ole32.lib oleaut32.lib strmiids.lib libx264.lib d3d9.lib Bcrypt.lib Kernel32.lib portaudio_x86.lib ole32.lib oleaut32.lib strmiids.lib libx264.lib d3d9.lib
} }
else{ else{
message("64-bit") message("64-bit")
INCLUDEPATH += inc $$PWD/third/fdk-aac/include \
$$PWD/third/ffmpeg/include \
$$PWD/third/openssl_1_0_2/include \
$$PWD/third/libx264/include \
include
LIBS += -L$$PWD/third/openssl_1_0_2/lib
LIBS += -L$$PWD/third/ffmpeg/lib
LIBS += -L$$PWD/third/fdk-aac/lib
LIBS += -L$$PWD/third/portaudio/lib
LIBS += -L$$PWD/third/libx264/lib/x64
LIBS += avfilter.lib avdevice.lib libavcodec.dll.a postproc.lib \
libavformat.dll.a libavutil.dll.a \
libswresample.dll.a libswscale.dll.a fdk-aac.lib ws2_32.lib libeay32.lib ssleay32.lib \
shell32.lib gdi32.lib crypt32.lib User32.lib GDI32.lib Advapi32.lib Secur32.lib \
Bcrypt.lib Kernel32.lib portaudio_x64.lib ole32.lib oleaut32.lib strmiids.lib libx264.lib d3d9.lib
QMAKE_CXXFLAGS_RELEASE += -Zi QMAKE_CXXFLAGS_RELEASE += -Zi
QMAKE_LFLAGS_RELEASE += /DEBUG /OPT:REF QMAKE_LFLAGS_RELEASE += /DEBUG /OPT:REF

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 11.0.3, 2023-11-13T01:02:28. --> <!-- Written by QtCreator 11.0.3, 2023-11-29T00:51:06. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -82,6 +82,9 @@
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/> <valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value> <value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="CppEditor.QuickFix">
<value type="bool" key="UseGlobalSettings">true</value>
</valuemap>
</valuemap> </valuemap>
</data> </data>
<data> <data>
@ -238,12 +241,12 @@
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value> <value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">yuvgl2</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:G:/project/multimedia/client/rtmp_demo/yuvgl/yuvgl.pro</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/project/rtmp/yuvgl.pro</value> <value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">G:/project/multimedia/client/rtmp_demo/yuvgl/yuvgl.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">D:/project/rtmp/yuvgl.pro</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value> <value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">G:/project/multimedia/client/rtmp_demo/build-yuvgl-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug</value>
</valuemap> </valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value> <value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap> </valuemap>