提交代码。
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
#include "RtspServer.h"
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <mk_common.h>
|
||||
@ -12,21 +14,23 @@ lowLatency=1
|
||||
)";
|
||||
class RtspServerPrivate {
|
||||
public:
|
||||
RtspServerPrivate(boost::asio::io_context &ioContext) : strand{ioContext.get_executor()} {
|
||||
}
|
||||
boost::asio::strand<boost::asio::io_context::executor_type> strand;
|
||||
mk_media media;
|
||||
mk_h264_splitter splitter;
|
||||
};
|
||||
|
||||
static void on_h264_frame(void *user_data, mk_h264_splitter splitter, const char *data, int size) {
|
||||
using namespace std::chrono;
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(40ms);
|
||||
static int dts = 0;
|
||||
mk_frame frame = mk_frame_create(MKCodecH264, dts, dts, data, size, NULL, NULL);
|
||||
dts += 40;
|
||||
int pts = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
|
||||
mk_frame frame = mk_frame_create(MKCodecH264, pts, pts, data, size, NULL, NULL);
|
||||
mk_media_input_frame((mk_media)user_data, frame);
|
||||
mk_frame_unref(frame);
|
||||
}
|
||||
|
||||
RtspServer::RtspServer() : m_d(new RtspServerPrivate()) {
|
||||
RtspServer::RtspServer(boost::asio::io_context &ioContext) : m_d(new RtspServerPrivate(ioContext)) {
|
||||
mk_config config;
|
||||
std::memset(&config, 0, sizeof(mk_config));
|
||||
config.ini = iniConfig;
|
||||
@ -58,5 +62,7 @@ RtspServer::~RtspServer() {
|
||||
}
|
||||
|
||||
void RtspServer::push(const uint8_t *data, uint32_t size) {
|
||||
mk_h264_splitter_input_data(m_d->splitter, reinterpret_cast<const char *>(data), size);
|
||||
boost::asio::post(m_d->strand, [this, frame = std::vector<uint8_t>(data, data + size)]() {
|
||||
mk_h264_splitter_input_data(m_d->splitter, reinterpret_cast<const char *>(frame.data()), frame.size());
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user