|
@@ -196,7 +196,9 @@ int test2()
|
|
|
|
|
|
|
|
|
|
#include "modulecomm.h"
|
|
#include "modulecomm.h"
|
|
|
|
+#include "rtspclientup.h"
|
|
|
|
|
|
|
|
+rtspclientup * gup1 = NULL;
|
|
|
|
|
|
std::shared_ptr<char> gpstr_data;
|
|
std::shared_ptr<char> gpstr_data;
|
|
bool gbUpdate = false;
|
|
bool gbUpdate = false;
|
|
@@ -214,7 +216,14 @@ void Listenframe(const char * strdata,const unsigned int nSize,const unsigned in
|
|
gbUpdate = true;
|
|
gbUpdate = true;
|
|
gmutex.unlock();
|
|
gmutex.unlock();
|
|
// qDebug(" %02x %02x %02x %02x %02x %02x",strdata[0],strdata[1],strdata[2],strdata[3],strdata[4],strdata[5]);
|
|
// qDebug(" %02x %02x %02x %02x %02x %02x",strdata[0],strdata[1],strdata[2],strdata[3],strdata[4],strdata[5]);
|
|
-
|
|
|
|
|
|
+ iv::framedata xframe;
|
|
|
|
+ xframe.mframe_ptr = std::shared_ptr<char>(new char[nSize]);
|
|
|
|
+ mempcpy(xframe.mframe_ptr.get(),strdata,nSize);
|
|
|
|
+ xframe.mndatasize = nSize;
|
|
|
|
+ if(gup1 != NULL)
|
|
|
|
+ {
|
|
|
|
+ gup1->AddData(xframe);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -231,6 +240,7 @@ std::vector<iv::datapac> gvectorsend;
|
|
|
|
|
|
void threadrecv()
|
|
void threadrecv()
|
|
{
|
|
{
|
|
|
|
+// return;
|
|
static AVFormatContext *i_fmt_ctx;
|
|
static AVFormatContext *i_fmt_ctx;
|
|
static AVStream *i_video_stream;
|
|
static AVStream *i_video_stream;
|
|
|
|
|
|
@@ -245,11 +255,15 @@ void threadrecv()
|
|
/* should set to NULL so that avformat_open_input() allocate a new one */
|
|
/* should set to NULL so that avformat_open_input() allocate a new one */
|
|
i_fmt_ctx = NULL;
|
|
i_fmt_ctx = NULL;
|
|
//这是我用ONVIF协议得到的摄像头RTSP流媒体地址
|
|
//这是我用ONVIF协议得到的摄像头RTSP流媒体地址
|
|
- char rtspUrl[] = "rtsp://111.33.136.149:9554/mystream";
|
|
|
|
|
|
+ char rtspUrl[] = "rtsp://111.33.136.149:9554/testhello2";
|
|
|
|
|
|
|
|
|
|
|
|
+ AVDictionary *avdic=NULL;
|
|
|
|
+ char option_key[]="rtsp_transport";
|
|
|
|
+ char option_value[]="tcp";
|
|
|
|
+ av_dict_set(&avdic,option_key,option_value,0);
|
|
|
|
|
|
- if (avformat_open_input(&i_fmt_ctx, rtspUrl, NULL, NULL)!=0)
|
|
|
|
|
|
+ if (avformat_open_input(&i_fmt_ctx, rtspUrl, NULL, &avdic)!=0)
|
|
{
|
|
{
|
|
fprintf(stderr, " = could not open input file\n");
|
|
fprintf(stderr, " = could not open input file\n");
|
|
return ;
|
|
return ;
|
|
@@ -262,7 +276,7 @@ void threadrecv()
|
|
// av_dict_set(&opts, "muxdelay", "0.1", 0);
|
|
// av_dict_set(&opts, "muxdelay", "0.1", 0);
|
|
|
|
|
|
|
|
|
|
- if (avformat_find_stream_info(i_fmt_ctx, &opts)<0)
|
|
|
|
|
|
+ if (avformat_find_stream_info(i_fmt_ctx,NULL)<0)
|
|
{
|
|
{
|
|
fprintf(stderr, " = could not find stream info\n");
|
|
fprintf(stderr, " = could not find stream info\n");
|
|
return ;
|
|
return ;
|
|
@@ -284,6 +298,8 @@ void threadrecv()
|
|
if (av_read_frame(i_fmt_ctx, &i_pkt) <0 )
|
|
if (av_read_frame(i_fmt_ctx, &i_pkt) <0 )
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
int sizedata = i_pkt.size;
|
|
int sizedata = i_pkt.size;
|
|
int i;;
|
|
int i;;
|
|
gmutexlat.lock();
|
|
gmutexlat.lock();
|
|
@@ -297,16 +313,30 @@ void threadrecv()
|
|
}
|
|
}
|
|
gmutexlat.unlock();
|
|
gmutexlat.unlock();
|
|
std::cout<<" time: "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<" read packet size:"<<i_pkt.size<<std::endl;
|
|
std::cout<<" time: "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<" read packet size:"<<i_pkt.size<<std::endl;
|
|
|
|
+ av_packet_unref(&i_pkt);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+#include <QFile>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
int main(int argc, char *argv[])
|
|
{
|
|
{
|
|
QCoreApplication a(argc, argv);
|
|
QCoreApplication a(argc, argv);
|
|
|
|
|
|
|
|
+ av_register_all(); //初始化FFMPEG 调用了这个才能正常适用编码器和解码器
|
|
|
|
+
|
|
|
|
+ //Network
|
|
|
|
+ avformat_network_init();
|
|
|
|
+
|
|
|
|
+ rtspclientup * pup = new rtspclientup("rtsp://111.33.136.149:9554/test",1920,1080);
|
|
|
|
+ gup1 = pup;
|
|
void * pa = iv::modulecomm::RegisterRecv("h264front",Listenframe);
|
|
void * pa = iv::modulecomm::RegisterRecv("h264front",Listenframe);
|
|
|
|
+ return a.exec();
|
|
|
|
+
|
|
|
|
+
|
|
AVFormatContext *ifmt_ctx = NULL;
|
|
AVFormatContext *ifmt_ctx = NULL;
|
|
AVPacket pkt;
|
|
AVPacket pkt;
|
|
const char *in_filename, *out_filename;
|
|
const char *in_filename, *out_filename;
|
|
@@ -314,21 +344,20 @@ int main(int argc, char *argv[])
|
|
int ret;
|
|
int ret;
|
|
int frame_index = 0;
|
|
int frame_index = 0;
|
|
|
|
|
|
- in_filename = "/home/yuchuli/imx291.h264";
|
|
|
|
|
|
+ in_filename = "./imx291.h264";
|
|
|
|
|
|
out_filename = "rtsp://111.33.136.149:9554/testhello2";
|
|
out_filename = "rtsp://111.33.136.149:9554/testhello2";
|
|
//out_filename = "rtp://233.233.233.233:6666";
|
|
//out_filename = "rtp://233.233.233.233:6666";
|
|
//out_filename = "tcp://127.0.0.1:9000";
|
|
//out_filename = "tcp://127.0.0.1:9000";
|
|
//out_filename = "udp://127.0.0.1:9000";
|
|
//out_filename = "udp://127.0.0.1:9000";
|
|
|
|
|
|
- av_register_all(); //初始化FFMPEG 调用了这个才能正常适用编码器和解码器
|
|
|
|
|
|
|
|
- //Network
|
|
|
|
- avformat_network_init();
|
|
|
|
|
|
|
|
|
|
|
|
std::thread * precvthread = new std::thread(threadrecv);
|
|
std::thread * precvthread = new std::thread(threadrecv);
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
|
|
if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
|
|
printf("Could not open input file.");
|
|
printf("Could not open input file.");
|
|
return -1;
|
|
return -1;
|
|
@@ -341,14 +370,71 @@ int main(int argc, char *argv[])
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- ifmt_ctx->streams[0]->avg_frame_rate.num = 30;
|
|
|
|
- ifmt_ctx->streams[0]->codecpar->sample_aspect_ratio.num = 30;
|
|
|
|
- ifmt_ctx->streams[0]->time_base.den = 30;
|
|
|
|
|
|
+ ifmt_ctx->streams[0]->codecpar->width = 1920;
|
|
|
|
+ ifmt_ctx->streams[0]->codecpar->height = 1080;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ AVFormatContext * fmtctx = NULL;
|
|
|
|
+ int nrtn = avformat_alloc_output_context2(&fmtctx,NULL,"rtsp","rtsp://127.0.0.1:9554/test2.sdp");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ fmtctx->bit_rate = 2000000;
|
|
|
|
+ fmtctx->fps_probe_size = 30;
|
|
|
|
+
|
|
|
|
+ int err = 0;
|
|
|
|
+
|
|
|
|
+ AVStream *out_stream = avformat_new_stream(fmtctx, NULL);
|
|
|
|
+
|
|
|
|
+ QFile xFile;
|
|
|
|
+
|
|
|
|
+#ifdef SAVECODEPAR
|
|
|
|
+ xFile.setFileName("./codepar");
|
|
|
|
+ if(xFile.open(QIODevice::ReadWrite))
|
|
|
|
+ {
|
|
|
|
+ xFile.write((char*)ifmt_ctx->streams[0]->codecpar,sizeof(AVCodecParameters));
|
|
|
|
+ if(ifmt_ctx->streams[0]->codecpar->extradata_size>0)
|
|
|
|
+ {
|
|
|
|
+ xFile.write((char*)ifmt_ctx->streams[0]->codecpar->extradata,ifmt_ctx->streams[0]->codecpar->extradata_size);
|
|
|
|
+ }
|
|
|
|
+ xFile.close();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+ xFile.setFileName(":/codepar");
|
|
|
|
+ if(xFile.open(QIODevice::ReadOnly))
|
|
|
|
+ {
|
|
|
|
+ int n = sizeof(AVCodecParameters);
|
|
|
|
+ xFile.read((char *)out_stream->codecpar,sizeof(AVCodecParameters));
|
|
|
|
+ if(out_stream->codecpar->extradata_size>0)
|
|
|
|
+ {
|
|
|
|
+ out_stream->codecpar->extradata = new uint8_t[out_stream->codecpar->extradata_size];
|
|
|
|
+ xFile.read((char*)out_stream->codecpar->extradata,out_stream->codecpar->extradata_size);
|
|
|
|
+ }
|
|
|
|
+ xFile.close();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"can't get codepar from file."<<std::endl;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ out_stream->codecpar->bit_rate = 2000000;
|
|
|
|
+ out_stream->codecpar->width = 1280;
|
|
|
|
+ out_stream->codecpar->height = 720;
|
|
|
|
+
|
|
|
|
+// avcodec_parameters_copy(fmtctx->streams[0]->codecpar, ifmt_ctx->streams[0]->codecpar);
|
|
|
|
+
|
|
|
|
+// memcpy(fmtctx->streams[0]->codecpar, ifmt_ctx->streams[0]->codecpar,sizeof(AVCodecParameters));
|
|
|
|
|
|
- ifmt_ctx->bit_rate = 2000000;
|
|
|
|
if (NULL == pusher) {
|
|
if (NULL == pusher) {
|
|
pusher = new FfmpegOutputer();
|
|
pusher = new FfmpegOutputer();
|
|
- ret = pusher->OpenOutputStream(out_filename, ifmt_ctx);
|
|
|
|
|
|
+ // ret = pusher->OpenOutputStream(out_filename, ifmt_ctx);
|
|
|
|
+ ret = pusher->OpenOutputStream(out_filename, fmtctx);
|
|
if (ret != 0){
|
|
if (ret != 0){
|
|
return -3;
|
|
return -3;
|
|
}
|
|
}
|
|
@@ -358,7 +444,9 @@ int main(int argc, char *argv[])
|
|
av_dump_format(ifmt_ctx, 0, in_filename, 0);
|
|
av_dump_format(ifmt_ctx, 0, in_filename, 0);
|
|
|
|
|
|
int pos = 0;
|
|
int pos = 0;
|
|
- av_read_frame(ifmt_ctx, &pkt);
|
|
|
|
|
|
+// av_read_frame(ifmt_ctx, &pkt);
|
|
|
|
+
|
|
|
|
+ // pkt = av_packet_alloc();
|
|
while (true) {
|
|
while (true) {
|
|
|
|
|
|
if(gbUpdate == false)
|
|
if(gbUpdate == false)
|
|
@@ -377,6 +465,9 @@ int main(int argc, char *argv[])
|
|
// pkt.buf->data = pkt.data;
|
|
// pkt.buf->data = pkt.data;
|
|
memcpy(pkt.data, gpstr_data.get(),gndatasize);
|
|
memcpy(pkt.data, gpstr_data.get(),gndatasize);
|
|
pkt.size = gndatasize;
|
|
pkt.size = gndatasize;
|
|
|
|
+ pkt.stream_index = 0;
|
|
|
|
+ pkt.side_data = 0;
|
|
|
|
+ pkt.side_data_elems = 0;
|
|
// std::cout<<" size : "<<gndatasize<<std::endl;
|
|
// std::cout<<" size : "<<gndatasize<<std::endl;
|
|
// std::cout<<" buf size: "<<pkt.buf->size<<std::endl;
|
|
// std::cout<<" buf size: "<<pkt.buf->size<<std::endl;
|
|
// pkt.buf->size = gndatasize;
|
|
// pkt.buf->size = gndatasize;
|
|
@@ -400,11 +491,11 @@ int main(int argc, char *argv[])
|
|
std::cout<<" time: "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<" pos: "<<pkt.pos<<" size: "<<pkt.size<<" flats: "<<pkt.flags<< std::endl;
|
|
std::cout<<" time: "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<" pos: "<<pkt.pos<<" size: "<<pkt.size<<" flats: "<<pkt.flags<< std::endl;
|
|
// if (ret < 0) break;
|
|
// if (ret < 0) break;
|
|
|
|
|
|
- pkt.duration = 3;
|
|
|
|
|
|
+ pkt.duration = 3*1000;
|
|
|
|
|
|
// std::cout<<" pts: "<<pkt.pts<<" dts: "<<pkt.dts<<std::endl;
|
|
// std::cout<<" pts: "<<pkt.pts<<" dts: "<<pkt.dts<<std::endl;
|
|
if (pkt.pts == AV_NOPTS_VALUE) {
|
|
if (pkt.pts == AV_NOPTS_VALUE) {
|
|
- pkt.dts = pkt.pts = (1.0/30)*90*frame_index;
|
|
|
|
|
|
+ pkt.dts = pkt.pts = 1000* (1.0/30)*90*frame_index;
|
|
// pkt.dts = pkt.pts = frame_index * 1;
|
|
// pkt.dts = pkt.pts = frame_index * 1;
|
|
// frame_index++;
|
|
// frame_index++;
|
|
|
|
|
|
@@ -412,8 +503,9 @@ int main(int argc, char *argv[])
|
|
// std::cout<<" pts: "<<pkt.pts<<" dts: "<<pkt.dts<<std::endl;
|
|
// std::cout<<" pts: "<<pkt.pts<<" dts: "<<pkt.dts<<std::endl;
|
|
|
|
|
|
pusher->InputPacket(&pkt);
|
|
pusher->InputPacket(&pkt);
|
|
|
|
+ delete pkt.data;
|
|
av_packet_unref(&pkt);
|
|
av_packet_unref(&pkt);
|
|
-// delete pkt.data;
|
|
|
|
|
|
+
|
|
frame_index++;
|
|
frame_index++;
|
|
// av_usleep(40000);
|
|
// av_usleep(40000);
|
|
}
|
|
}
|