第二篇在这里 第二篇 rtsp rtp gb28181转html5播放
udpserver假定服务端有一个端口接收rtp over udp,接收到数据以后转成html5能展示的,这种效果有作用否?
我们知道ffmpeg是可以直接发送rtp流的,gb28181 也是可以发送rtp流的,那么我们制作一个简洁的服务器,在udp端口接收到以后转成tcp,让后在网页上展示。
ffmpeg发送命令ffmpeg \ffmpeg -re -i video.mp4 -an -c:v copy -f rtp -sdp_file video.sdp “rtp://192.168.1.109:5004” 使用ffmpeg来发送文件,去除音频,当然也可以接收自己写的程序发送rtp,下面,我们使用asio来制作一个异步的服务器,来接收udp流。
code#pragma once
#include
#include
#include
#include
#include
#include
#include "c_rtp.h"
using boost::asio::ip::udp;
using namespace boost;
#include "c_hub.h"
#include "c_rtp.h"
#define DEFINE_EC \
boost::system::error_code ec;
class c_flvserver;
class c_udpserver:public std::enable_shared_from_this
{
//asio::strand v_strand;
asio::io_context &v_context;
asio::ip::udp::socket v_socket;
c_flvserver *v_flvserver = NULL;
unordered_map v_ctxs;
//s_rtp_h264_context v_rtp;
s_rtp_h264_context * getctx(uint32_t ssrc)
{
auto it = v_ctxs.find(ssrc);
if (it != v_ctxs.end())
return it->second;
else
{
s_rtp_h264_context *sc = new s_rtp_h264_context();
v_ctxs[ssrc] = sc;
return sc;
}
}
void data_call(s_rtp_h264_context *ctx);
s_flvhub * func_context(uint32_t ssrc);
int live_rtp_unpack_h264(s_rtp_h264_context *ctx, uint8_t *data, int inlen);
//int live_rtp_unpack_h265(s_rtp_h264_context *ctx, uint8_t *data, int inlen);
//int live_rtp_unpack_aac(s_rtp_h264_context *ctx, uint8_t *data, int inlen);
//int live_rtp_unpack_opus(s_rtp_h264_context *ctx, uint8_t *data, int inlen);
//int live_rtp_unpack(s_rtp_h264_context *ctx, uint8_t *data, int inlen);
public:
c_udpserver(asio::io_context& io_context, short port, c_flvserver *flvserver):
//v_strand(io_context.get_executor()),
v_context(io_context), v_flvserver(flvserver),
v_socket(v_context)
//v_socket(v_context, udp::endpoint(udp::v4(), port))
{
//boost::asio::ip::udp::endpoint ep(boost::asio::ip::address::from_string("192.168.1.206"),port);
udp::endpoint ep(udp::v4(), port);
v_socket.open(ep.protocol());
v_socket.set_option(boost::asio::ip::udp::socket::reuse_address(true));
boost::asio::socket_base::receive_buffer_size recv_option(1*1024*1024);
v_socket.set_option(recv_option);
v_socket.bind(ep);
}
~c_udpserver()
{
//v_context_maps.clear();
}
//to flv server
void do_receive();
#ifdef _WEBRTC_
void do_receive_webrtc()
{
//std::cout v_buffer + ctx->v_len, buffer + jump, len);
ctx->v_len += len;
}
else//分片丢失,RTP丢包
{
ctx->reset();
//ctx->v_current_FU = 0;
return -1;
}
}
else if (!(header & 0x80) && (header & 0x40)) {
/* Last part of fragmented packet (E bit set) */
if (ctx->v_current_FU) {
ctx->v_current_FU = 0;
memcpy(ctx->v_buffer + ctx->v_len, buffer + jump, len);
ctx->v_len += len;
//data_call(ctx);
//ctx->reset();
//return 0;
//printf("end of m:%d", m);
//cout
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?