mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-29 22:55:52 +08:00
sync from master
This commit is contained in:
commit
3adbad5fc4
6
AUTHORS
6
AUTHORS
@ -44,7 +44,6 @@ Xinghua Zhao <(holychaossword@hotmail.com>
|
|||||||
[Dw9](https://github.com/Dw9)
|
[Dw9](https://github.com/Dw9)
|
||||||
明月惊鹊 <mingyuejingque@gmail.com>
|
明月惊鹊 <mingyuejingque@gmail.com>
|
||||||
cgm <2958580318@qq.com>
|
cgm <2958580318@qq.com>
|
||||||
hejilin <1724010622@qq.com>
|
|
||||||
alexliyu7352 <liyu7352@gmail.com>
|
alexliyu7352 <liyu7352@gmail.com>
|
||||||
cgm <2958580318@qq.com>
|
cgm <2958580318@qq.com>
|
||||||
[haorui wang](https://github.com/HaoruiWang)
|
[haorui wang](https://github.com/HaoruiWang)
|
||||||
@ -104,3 +103,8 @@ WuPeng <wp@zafu.edu.cn>
|
|||||||
[sandro-qiang](https://github.com/sandro-qiang)
|
[sandro-qiang](https://github.com/sandro-qiang)
|
||||||
[Paul Philippov](https://github.com/themactep)
|
[Paul Philippov](https://github.com/themactep)
|
||||||
[张传峰](https://github.com/zhang-chuanfeng)
|
[张传峰](https://github.com/zhang-chuanfeng)
|
||||||
|
[lidaofu-hub](https://github.com/lidaofu-hub)
|
||||||
|
[huangcaichun](https://github.com/huangcaichun)
|
||||||
|
[jamesZHANG500](https://github.com/jamesZHANG500)
|
||||||
|
[weidelong](https://github.com/wdl1697454803)
|
||||||
|
[小强先生](https://github.com/linshangqiang)
|
@ -57,7 +57,8 @@ option(ENABLE_SCTP "Enable SCTP" ON)
|
|||||||
option(ENABLE_WEBRTC "Enable WebRTC" ON)
|
option(ENABLE_WEBRTC "Enable WebRTC" ON)
|
||||||
option(ENABLE_X264 "Enable x264" OFF)
|
option(ENABLE_X264 "Enable x264" OFF)
|
||||||
option(ENABLE_WEPOLL "Enable wepoll" ON)
|
option(ENABLE_WEPOLL "Enable wepoll" ON)
|
||||||
option(DISABLE_REPORT "Disable report to report.zlmediakit.com" off)
|
option(ENABLE_VIDEOSTACK "Enable video stack" OFF)
|
||||||
|
option(DISABLE_REPORT "Disable report to report.zlmediakit.com" OFF)
|
||||||
option(USE_SOLUTION_FOLDERS "Enable solution dir supported" ON)
|
option(USE_SOLUTION_FOLDERS "Enable solution dir supported" ON)
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# 设置socket默认缓冲区大小为256k.如果设置为0则不设置socket的默认缓冲区大小,使用系统内核默认值(设置为0仅对linux有效)
|
# 设置socket默认缓冲区大小为256k.如果设置为0则不设置socket的默认缓冲区大小,使用系统内核默认值(设置为0仅对linux有效)
|
||||||
@ -141,8 +142,8 @@ if(GIT_FOUND)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
configure_file(
|
configure_file(
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/version.h.ini
|
${CMAKE_CURRENT_SOURCE_DIR}/ZLMVersion.h.ini
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/version.h
|
${CMAKE_CURRENT_BINARY_DIR}/ZLMVersion.h
|
||||||
@ONLY)
|
@ONLY)
|
||||||
|
|
||||||
message(STATUS "Git version is ${BRANCH_NAME} ${COMMIT_HASH}/${COMMIT_TIME} ${BUILD_TIME}")
|
message(STATUS "Git version is ${BRANCH_NAME} ${COMMIT_HASH}/${COMMIT_TIME} ${BUILD_TIME}")
|
||||||
@ -191,7 +192,7 @@ if(UNIX)
|
|||||||
set(COMPILE_OPTIONS_DEFAULT
|
set(COMPILE_OPTIONS_DEFAULT
|
||||||
"-fPIC"
|
"-fPIC"
|
||||||
"-Wall;-Wextra"
|
"-Wall;-Wextra"
|
||||||
"-Wno-unused-function;-Wno-unused-parameter;-Wno-unused-variable"
|
"-Wno-unused-function;-Wno-unused-parameter;-Wno-unused-variable;-Wno-deprecated-declarations"
|
||||||
"-Wno-error=extra;-Wno-error=missing-field-initializers;-Wno-error=type-limits")
|
"-Wno-error=extra;-Wno-error=missing-field-initializers;-Wno-error=type-limits")
|
||||||
|
|
||||||
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
||||||
@ -535,6 +536,6 @@ file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/default.pem" DESTINATION ${EXECUTABLE_OUT
|
|||||||
|
|
||||||
# 拷贝VideoStack 无视频流时默认填充的背景图片
|
# 拷贝VideoStack 无视频流时默认填充的背景图片
|
||||||
# Copy the default background image used by VideoStack when there is no video stream
|
# Copy the default background image used by VideoStack when there is no video stream
|
||||||
if (ENABLE_FFMPEG AND ENABLE_X264)
|
if (ENABLE_VIDEOSTACK AND ENABLE_FFMPEG AND ENABLE_X264)
|
||||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/conf/novideo.yuv" DESTINATION ${EXECUTABLE_OUTPUT_PATH})
|
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/conf/novideo.yuv" DESTINATION ${EXECUTABLE_OUTPUT_PATH})
|
||||||
endif ()
|
endif ()
|
@ -358,6 +358,11 @@ bash build_docker_images.sh
|
|||||||
[sandro-qiang](https://github.com/sandro-qiang)
|
[sandro-qiang](https://github.com/sandro-qiang)
|
||||||
[Paul Philippov](https://github.com/themactep)
|
[Paul Philippov](https://github.com/themactep)
|
||||||
[张传峰](https://github.com/zhang-chuanfeng)
|
[张传峰](https://github.com/zhang-chuanfeng)
|
||||||
|
[lidaofu-hub](https://github.com/lidaofu-hub)
|
||||||
|
[huangcaichun](https://github.com/huangcaichun)
|
||||||
|
[jamesZHANG500](https://github.com/jamesZHANG500)
|
||||||
|
[weidelong](https://github.com/wdl1697454803)
|
||||||
|
[小强先生](https://github.com/linshangqiang)
|
||||||
|
|
||||||
同时感谢JetBrains对开源项目的支持,本项目使用CLion开发与调试:
|
同时感谢JetBrains对开源项目的支持,本项目使用CLion开发与调试:
|
||||||
|
|
||||||
|
@ -516,6 +516,11 @@ Thanks to all those who have supported this project in various ways, including b
|
|||||||
[sandro-qiang](https://github.com/sandro-qiang)
|
[sandro-qiang](https://github.com/sandro-qiang)
|
||||||
[Paul Philippov](https://github.com/themactep)
|
[Paul Philippov](https://github.com/themactep)
|
||||||
[张传峰](https://github.com/zhang-chuanfeng)
|
[张传峰](https://github.com/zhang-chuanfeng)
|
||||||
|
[lidaofu-hub](https://github.com/lidaofu-hub)
|
||||||
|
[huangcaichun](https://github.com/huangcaichun)
|
||||||
|
[jamesZHANG500](https://github.com/jamesZHANG500)
|
||||||
|
[weidelong](https://github.com/wdl1697454803)
|
||||||
|
[小强先生](https://github.com/linshangqiang)
|
||||||
|
|
||||||
Also thank to JetBrains for their support for open source project, we developed and debugged zlmediakit with CLion:
|
Also thank to JetBrains for their support for open source project, we developed and debugged zlmediakit with CLion:
|
||||||
|
|
||||||
|
@ -24,6 +24,10 @@
|
|||||||
# define API_CALL
|
# define API_CALL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#define _strdup strdup
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(_MSC_VER)
|
#if defined(_WIN32) && defined(_MSC_VER)
|
||||||
# if !defined(GENERATE_EXPORT)
|
# if !defined(GENERATE_EXPORT)
|
||||||
# if defined(MediaKitApi_EXPORTS)
|
# if defined(MediaKitApi_EXPORTS)
|
||||||
|
@ -103,6 +103,16 @@ API_EXPORT int API_CALL mk_media_source_get_track_count(const mk_media_source ct
|
|||||||
API_EXPORT mk_track API_CALL mk_media_source_get_track(const mk_media_source ctx, int index);
|
API_EXPORT mk_track API_CALL mk_media_source_get_track(const mk_media_source ctx, int index);
|
||||||
// MediaSource::broadcastMessage
|
// MediaSource::broadcastMessage
|
||||||
API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx, const char *msg, size_t len);
|
API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx, const char *msg, size_t len);
|
||||||
|
// MediaSource::getOriginUrl()
|
||||||
|
API_EXPORT const char* API_CALL mk_media_source_get_origin_url(const mk_media_source ctx);
|
||||||
|
// MediaSource::getOriginType()
|
||||||
|
API_EXPORT int API_CALL mk_media_source_get_origin_type(const mk_media_source ctx);
|
||||||
|
// MediaSource::getCreateStamp()
|
||||||
|
API_EXPORT uint64_t API_CALL mk_media_source_get_create_stamp(const mk_media_source ctx);
|
||||||
|
// MediaSource::isRecording() 0:hls,1:MP4
|
||||||
|
API_EXPORT int API_CALL mk_media_source_is_recording(const mk_media_source ctx, int type);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 直播源在ZLMediaKit中被称作为MediaSource,
|
* 直播源在ZLMediaKit中被称作为MediaSource,
|
||||||
@ -142,7 +152,7 @@ API_EXPORT void API_CALL mk_media_source_find(const char *schema,
|
|||||||
void *user_data,
|
void *user_data,
|
||||||
on_mk_media_source_find_cb cb);
|
on_mk_media_source_find_cb cb);
|
||||||
|
|
||||||
API_EXPORT const mk_media_source API_CALL mk_media_source_find2(const char *schema,
|
API_EXPORT mk_media_source API_CALL mk_media_source_find2(const char *schema,
|
||||||
const char *vhost,
|
const char *vhost,
|
||||||
const char *app,
|
const char *app,
|
||||||
const char *stream,
|
const char *stream,
|
||||||
|
@ -304,10 +304,10 @@ API_EXPORT void API_CALL mk_webrtc_get_answer_sdp2(void *user_data, on_user_data
|
|||||||
std::string offer_str = offer;
|
std::string offer_str = offer;
|
||||||
std::shared_ptr<void> ptr(user_data, user_data_free ? user_data_free : [](void *) {});
|
std::shared_ptr<void> ptr(user_data, user_data_free ? user_data_free : [](void *) {});
|
||||||
auto args = std::make_shared<WebRtcArgsUrl>(url);
|
auto args = std::make_shared<WebRtcArgsUrl>(url);
|
||||||
WebRtcPluginManager::Instance().getAnswerSdp(*session, type, *args,
|
WebRtcPluginManager::Instance().negotiateSdp(*session, type, *args, [offer_str, session, ptr, cb](const WebRtcInterface &exchanger) mutable {
|
||||||
[offer_str, session, ptr, cb](const WebRtcInterface &exchanger) mutable {
|
auto &handler = const_cast<WebRtcInterface &>(exchanger);
|
||||||
try {
|
try {
|
||||||
auto sdp_answer = exchangeSdp(exchanger, offer_str);
|
auto sdp_answer = handler.getAnswerSdp(offer_str);
|
||||||
cb(ptr.get(), sdp_answer.data(), nullptr);
|
cb(ptr.get(), sdp_answer.data(), nullptr);
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
cb(ptr.get(), nullptr, ex.what());
|
cb(ptr.get(), nullptr, ex.what());
|
||||||
|
@ -14,7 +14,10 @@
|
|||||||
#include "Http/HttpSession.h"
|
#include "Http/HttpSession.h"
|
||||||
#include "Rtsp/RtspSession.h"
|
#include "Rtsp/RtspSession.h"
|
||||||
#include "Record/MP4Recorder.h"
|
#include "Record/MP4Recorder.h"
|
||||||
|
|
||||||
|
#ifdef ENABLE_WEBRTC
|
||||||
#include "webrtc/WebRtcTransport.h"
|
#include "webrtc/WebRtcTransport.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
@ -168,7 +171,7 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
|
|||||||
sender.getMediaTuple().stream.c_str(), ssrc.c_str(), ex.getErrCode(), ex.what());
|
sender.getMediaTuple().stream.c_str(), ssrc.c_str(), ex.getErrCode(), ex.what());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
#ifdef ENABLE_WEBRTC
|
||||||
NoticeCenter::Instance().addListener(&s_tag, Broadcast::kBroadcastRtcSctpConnecting,[](BroadcastRtcSctpConnectArgs){
|
NoticeCenter::Instance().addListener(&s_tag, Broadcast::kBroadcastRtcSctpConnecting,[](BroadcastRtcSctpConnectArgs){
|
||||||
if (s_events.on_mk_rtc_sctp_connecting) {
|
if (s_events.on_mk_rtc_sctp_connecting) {
|
||||||
s_events.on_mk_rtc_sctp_connecting((mk_rtc_transport)&sender);
|
s_events.on_mk_rtc_sctp_connecting((mk_rtc_transport)&sender);
|
||||||
@ -204,6 +207,7 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
|
|||||||
s_events.on_mk_rtc_sctp_received((mk_rtc_transport)&sender, streamId, ppid, msg, len);
|
s_events.on_mk_rtc_sctp_received((mk_rtc_transport)&sender, streamId, ppid, msg, len);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
#include "Http/HttpClient.h"
|
#include "Http/HttpClient.h"
|
||||||
#include "Rtsp/RtspSession.h"
|
#include "Rtsp/RtspSession.h"
|
||||||
|
|
||||||
|
#ifdef ENABLE_WEBRTC
|
||||||
#include "webrtc/WebRtcTransport.h"
|
#include "webrtc/WebRtcTransport.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
@ -127,7 +130,7 @@ API_EXPORT const char* API_CALL mk_parser_get_content(const mk_parser ctx, size_
|
|||||||
API_EXPORT const char* API_CALL mk_media_info_get_params(const mk_media_info ctx){
|
API_EXPORT const char* API_CALL mk_media_info_get_params(const mk_media_info ctx){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MediaInfo *info = (MediaInfo *)ctx;
|
MediaInfo *info = (MediaInfo *)ctx;
|
||||||
return info->param_strs.c_str();
|
return info->params.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT const char* API_CALL mk_media_info_get_schema(const mk_media_info ctx){
|
API_EXPORT const char* API_CALL mk_media_info_get_schema(const mk_media_info ctx){
|
||||||
@ -225,6 +228,30 @@ API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx,
|
|||||||
return src->broadcastMessage(any);
|
return src->broadcastMessage(any);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
API_EXPORT const char* API_CALL mk_media_source_get_origin_url(const mk_media_source ctx) {
|
||||||
|
assert(ctx);
|
||||||
|
MediaSource *src = (MediaSource *)ctx;
|
||||||
|
return _strdup(src->getOriginUrl().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
API_EXPORT int API_CALL mk_media_source_get_origin_type(const mk_media_source ctx) {
|
||||||
|
assert(ctx);
|
||||||
|
MediaSource *src = (MediaSource *)ctx;
|
||||||
|
return static_cast<int>(src->getOriginType());
|
||||||
|
}
|
||||||
|
|
||||||
|
API_EXPORT uint64_t API_CALL mk_media_source_get_create_stamp(const mk_media_source ctx) {
|
||||||
|
assert(ctx);
|
||||||
|
MediaSource *src = (MediaSource *)ctx;
|
||||||
|
return src->getCreateStamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
API_EXPORT int API_CALL mk_media_source_is_recording(const mk_media_source ctx,int type) {
|
||||||
|
assert(ctx);
|
||||||
|
MediaSource *src = (MediaSource *)ctx;
|
||||||
|
return src->isRecording((Recorder::type)type);
|
||||||
|
}
|
||||||
|
|
||||||
API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){
|
API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
MediaSource *src = (MediaSource *)ctx;
|
MediaSource *src = (MediaSource *)ctx;
|
||||||
@ -275,7 +302,7 @@ API_EXPORT void API_CALL mk_media_source_find(const char *schema,
|
|||||||
cb(user_data, (mk_media_source)src.get());
|
cb(user_data, (mk_media_source)src.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
API_EXPORT const mk_media_source API_CALL mk_media_source_find2(const char *schema,
|
API_EXPORT mk_media_source API_CALL mk_media_source_find2(const char *schema,
|
||||||
const char *vhost,
|
const char *vhost,
|
||||||
const char *app,
|
const char *app,
|
||||||
const char *stream,
|
const char *stream,
|
||||||
|
@ -21,10 +21,6 @@ using namespace std;
|
|||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#define _strdup strdup
|
|
||||||
#endif
|
|
||||||
|
|
||||||
API_EXPORT void API_CALL mk_free(void *ptr) {
|
API_EXPORT void API_CALL mk_free(void *ptr) {
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
152
api/tests/h264_pusher.c
Normal file
152
api/tests/h264_pusher.c
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by MIT-like license that can be found in the
|
||||||
|
* LICENSE file in the root of the source tree. All contributing project authors
|
||||||
|
* may be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "windows.h"
|
||||||
|
#else
|
||||||
|
#include "unistd.h"
|
||||||
|
#endif
|
||||||
|
#include "mk_mediakit.h"
|
||||||
|
|
||||||
|
static int exit_flag = 0;
|
||||||
|
static void s_on_exit(int sig) {
|
||||||
|
exit_flag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_h264_frame(void *user_data, mk_h264_splitter splitter, const char *data, int size) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
Sleep(40);
|
||||||
|
#else
|
||||||
|
usleep(40 * 1000);
|
||||||
|
#endif
|
||||||
|
static int dts = 0;
|
||||||
|
mk_frame frame = mk_frame_create(MKCodecH264, dts, dts, data, size, NULL, NULL);
|
||||||
|
dts += 40;
|
||||||
|
mk_media_input_frame((mk_media)user_data, frame);
|
||||||
|
mk_frame_unref(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
mk_pusher pusher;
|
||||||
|
char *url;
|
||||||
|
} Context;
|
||||||
|
|
||||||
|
void release_context(void *user_data) {
|
||||||
|
Context *ptr = (Context *)user_data;
|
||||||
|
if (ptr->pusher) {
|
||||||
|
mk_pusher_release(ptr->pusher);
|
||||||
|
}
|
||||||
|
free(ptr->url);
|
||||||
|
free(ptr);
|
||||||
|
log_info("停止推流");
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_push_result(void *user_data, int err_code, const char *err_msg) {
|
||||||
|
Context *ptr = (Context *)user_data;
|
||||||
|
if (err_code == 0) {
|
||||||
|
log_info("推流成功: %s", ptr->url);
|
||||||
|
} else {
|
||||||
|
log_warn("推流%s失败: %d(%s)", ptr->url, err_code, err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_push_shutdown(void *user_data, int err_code, const char *err_msg) {
|
||||||
|
Context *ptr = (Context *)user_data;
|
||||||
|
log_warn("推流%s中断: %d(%s)", ptr->url, err_code, err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void API_CALL on_regist(void *user_data, mk_media_source sender, int regist) {
|
||||||
|
Context *ptr = (Context *)user_data;
|
||||||
|
const char *schema = mk_media_source_get_schema(sender);
|
||||||
|
if (strstr(ptr->url, schema) != ptr->url) {
|
||||||
|
// 协议匹配失败
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!regist) {
|
||||||
|
// 注销
|
||||||
|
if (ptr->pusher) {
|
||||||
|
mk_pusher_release(ptr->pusher);
|
||||||
|
ptr->pusher = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 注册
|
||||||
|
if (!ptr->pusher) {
|
||||||
|
ptr->pusher = mk_pusher_create_src(sender);
|
||||||
|
mk_pusher_set_on_result2(ptr->pusher, on_push_result, ptr, NULL);
|
||||||
|
mk_pusher_set_on_shutdown2(ptr->pusher, on_push_shutdown, ptr, NULL);
|
||||||
|
// 开始推流
|
||||||
|
mk_pusher_publish(ptr->pusher, ptr->url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
if (argc < 3) {
|
||||||
|
log_error("Usage: /path/to/h264/file rtsp_or_rtmp_url");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
mk_config config = { .ini = NULL,
|
||||||
|
.ini_is_path = 1,
|
||||||
|
.log_level = 0,
|
||||||
|
.log_mask = LOG_CONSOLE,
|
||||||
|
.log_file_path = NULL,
|
||||||
|
.log_file_days = 0,
|
||||||
|
.ssl = NULL,
|
||||||
|
.ssl_is_path = 1,
|
||||||
|
.ssl_pwd = NULL,
|
||||||
|
.thread_num = 0 };
|
||||||
|
mk_env_init(&config);
|
||||||
|
|
||||||
|
FILE *fp = fopen(argv[1], "rb");
|
||||||
|
if (!fp) {
|
||||||
|
log_error("打开文件失败!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mk_media media = mk_media_create("__defaultVhost__", "live", "test", 0, 0, 0);
|
||||||
|
// h264的codec
|
||||||
|
codec_args v_args = { 0 };
|
||||||
|
mk_track v_track = mk_track_create(MKCodecH264, &v_args);
|
||||||
|
mk_media_init_track(media, v_track);
|
||||||
|
mk_media_init_complete(media);
|
||||||
|
mk_track_unref(v_track);
|
||||||
|
|
||||||
|
Context *ctx = (Context *)malloc(sizeof(Context));
|
||||||
|
memset(ctx, 0, sizeof(Context));
|
||||||
|
ctx->url = strdup(argv[2]);
|
||||||
|
|
||||||
|
mk_media_set_on_regist2(media, on_regist, ctx, release_context);
|
||||||
|
|
||||||
|
// 创建h264分帧器
|
||||||
|
mk_h264_splitter splitter = mk_h264_splitter_create(on_h264_frame, media, 0);
|
||||||
|
signal(SIGINT, s_on_exit); // 设置退出信号
|
||||||
|
signal(SIGTERM, s_on_exit); // 设置退出信号
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
while (!exit_flag) {
|
||||||
|
int size = fread(buf, 1, sizeof(buf) - 1, fp);
|
||||||
|
if (size > 0) {
|
||||||
|
mk_h264_splitter_input_data(splitter, buf, size);
|
||||||
|
} else {
|
||||||
|
// 文件读完了,重新开始
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log_info("文件读取完毕");
|
||||||
|
mk_h264_splitter_release(splitter);
|
||||||
|
mk_media_release(media);
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
@ -357,7 +357,7 @@ tcpPort = 8000
|
|||||||
rembBitRate=0
|
rembBitRate=0
|
||||||
#rtc支持的音频codec类型,在前面的优先级更高
|
#rtc支持的音频codec类型,在前面的优先级更高
|
||||||
#以下范例为所有支持的音频codec
|
#以下范例为所有支持的音频codec
|
||||||
preferredCodecA=PCMU,PCMA,opus,mpeg4-generic
|
preferredCodecA=PCMA,PCMU,opus,mpeg4-generic
|
||||||
#rtc支持的视频codec类型,在前面的优先级更高
|
#rtc支持的视频codec类型,在前面的优先级更高
|
||||||
#以下范例为所有支持的视频codec
|
#以下范例为所有支持的视频codec
|
||||||
preferredCodecV=H264,H265,AV1,VP9,VP8
|
preferredCodecV=H264,H265,AV1,VP9,VP8
|
||||||
|
@ -17,7 +17,7 @@ using namespace toolkit;
|
|||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
void AACRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt) {
|
void AACRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt) {
|
||||||
CHECK(pkt->size() > 2);
|
CHECK_RET(pkt->size() > 2);
|
||||||
if (pkt->isConfigFrame()) {
|
if (pkt->isConfigFrame()) {
|
||||||
getTrack()->setExtraData((uint8_t *)pkt->data() + 2, pkt->size() - 2);
|
getTrack()->setExtraData((uint8_t *)pkt->data() + 2, pkt->size() - 2);
|
||||||
return;
|
return;
|
||||||
|
@ -14,14 +14,6 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
#define CHECK_RET(...) \
|
|
||||||
try { \
|
|
||||||
CHECK(__VA_ARGS__); \
|
|
||||||
} catch (AssertFailedException & ex) { \
|
|
||||||
WarnL << ex.what(); \
|
|
||||||
return; \
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
void H264RtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt) {
|
void H264RtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt) {
|
||||||
|
@ -18,14 +18,6 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
#define CHECK_RET(...) \
|
|
||||||
try { \
|
|
||||||
CHECK(__VA_ARGS__); \
|
|
||||||
} catch (AssertFailedException & ex) { \
|
|
||||||
WarnL << ex.what(); \
|
|
||||||
return; \
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
void H265RtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt) {
|
void H265RtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#if defined(ENABLE_X264) && defined(ENABLE_FFMPEG)
|
#if defined(ENABLE_VIDEOSTACK) && defined(ENABLE_X264) && defined(ENABLE_FFMPEG)
|
||||||
#include "VideoStack.h"
|
#include "VideoStack.h"
|
||||||
#include "Codec/Transcode.h"
|
#include "Codec/Transcode.h"
|
||||||
#include "Common/Device.h"
|
#include "Common/Device.h"
|
||||||
@ -62,7 +62,8 @@ void Channel::addParam(const std::weak_ptr<Param>& p)
|
|||||||
void Channel::onFrame(const mediakit::FFmpegFrame::Ptr& frame)
|
void Channel::onFrame(const mediakit::FFmpegFrame::Ptr& frame)
|
||||||
{
|
{
|
||||||
std::weak_ptr<Channel> weakSelf = shared_from_this();
|
std::weak_ptr<Channel> weakSelf = shared_from_this();
|
||||||
// toolkit::WorkThreadPool::Instance().getFirstPoller()->async([weakSelf, frame]() {
|
_poller = _poller ? _poller : toolkit::WorkThreadPool::Instance().getPoller();
|
||||||
|
_poller->async([weakSelf, frame]() {
|
||||||
auto self = weakSelf.lock();
|
auto self = weakSelf.lock();
|
||||||
if (!self) {
|
if (!self) {
|
||||||
return;
|
return;
|
||||||
@ -70,7 +71,7 @@ void Channel::onFrame(const mediakit::FFmpegFrame::Ptr& frame)
|
|||||||
self->_tmp = self->_sws->inputFrame(frame);
|
self->_tmp = self->_sws->inputFrame(frame);
|
||||||
|
|
||||||
self->forEachParam([self](const Param::Ptr& p) { self->fillBuffer(p); });
|
self->forEachParam([self](const Param::Ptr& p) { self->fillBuffer(p); });
|
||||||
// });
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::forEachParam(const std::function<void(const Param::Ptr&)>& func)
|
void Channel::forEachParam(const std::function<void(const Param::Ptr&)>& func)
|
||||||
@ -180,7 +181,7 @@ void StackPlayer::play()
|
|||||||
self->onFrame(frame);
|
self->onFrame(frame);
|
||||||
});
|
});
|
||||||
|
|
||||||
videoTrack->addDelegate((std::function<bool(const mediakit::Frame::Ptr&)>)[decoder](const mediakit::Frame::Ptr& frame) {
|
videoTrack->addDelegate([decoder](const mediakit::Frame::Ptr& frame) {
|
||||||
return decoder->inputFrame(frame, false, true);
|
return decoder->inputFrame(frame, false, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -440,6 +441,7 @@ int VideoStackManager::stopVideoStack(const std::string& id)
|
|||||||
auto it = _stackMap.find(id);
|
auto it = _stackMap.find(id);
|
||||||
if (it != _stackMap.end()) {
|
if (it != _stackMap.end()) {
|
||||||
_stackMap.erase(it);
|
_stackMap.erase(it);
|
||||||
|
InfoL << "VideoStack stop: " << id;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@ -467,8 +469,8 @@ Params VideoStackManager::parseParams(const Json::Value& json,
|
|||||||
float gaph = json["gaph"].asFloat(); //水平间距
|
float gaph = json["gaph"].asFloat(); //水平间距
|
||||||
|
|
||||||
//单个间距
|
//单个间距
|
||||||
int gaphPix = static_cast<int>(std::round(width * gaph));
|
int gaphPix = static_cast<int>(round(width * gaph));
|
||||||
int gapvPix = static_cast<int>(std::round(height * gapv));
|
int gapvPix = static_cast<int>(round(height * gapv));
|
||||||
|
|
||||||
// 根据间距计算格子宽高
|
// 根据间距计算格子宽高
|
||||||
int gridWidth = cols > 1 ? (width - gaphPix * (cols - 1)) / cols : width;
|
int gridWidth = cols > 1 ? (width - gaphPix * (cols - 1)) / cols : width;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#if defined(ENABLE_X264) && defined(ENABLE_FFMPEG)
|
#if defined(ENABLE_VIDEOSTACK) && defined(ENABLE_X264) && defined(ENABLE_FFMPEG)
|
||||||
#include "Codec/Transcode.h"
|
#include "Codec/Transcode.h"
|
||||||
#include "Common/Device.h"
|
#include "Common/Device.h"
|
||||||
#include "Player/MediaPlayer.h"
|
#include "Player/MediaPlayer.h"
|
||||||
@ -80,6 +80,7 @@ class Channel : public std::enable_shared_from_this<Channel> {
|
|||||||
std::vector<std::weak_ptr<Param>> _params;
|
std::vector<std::weak_ptr<Param>> _params;
|
||||||
|
|
||||||
mediakit::FFmpegSws::Ptr _sws;
|
mediakit::FFmpegSws::Ptr _sws;
|
||||||
|
toolkit::EventPoller::Ptr _poller;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StackPlayer : public std::enable_shared_from_this<StackPlayer> {
|
class StackPlayer : public std::enable_shared_from_this<StackPlayer> {
|
||||||
|
@ -59,10 +59,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_VERSION)
|
#if defined(ENABLE_VERSION)
|
||||||
#include "version.h"
|
#include "ZLMVersion.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_X264) && defined (ENABLE_FFMPEG)
|
#if defined(ENABLE_VIDEOSTACK) && defined(ENABLE_X264) && defined (ENABLE_FFMPEG)
|
||||||
#include "VideoStack.h"
|
#include "VideoStack.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ static HttpApi toApi(const function<void(API_ARGS_MAP_ASYNC)> &cb) {
|
|||||||
|
|
||||||
//参数解析成map
|
//参数解析成map
|
||||||
auto args = getAllArgs(parser);
|
auto args = getAllArgs(parser);
|
||||||
cb(sender, headerOut, HttpAllArgs<decltype(args)>(parser, args), val, invoker);
|
cb(sender, headerOut, ArgsMap(parser, args), val, invoker);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ static HttpApi toApi(const function<void(API_ARGS_JSON_ASYNC)> &cb) {
|
|||||||
Json::Reader reader;
|
Json::Reader reader;
|
||||||
reader.parse(parser.content(), args);
|
reader.parse(parser.content(), args);
|
||||||
|
|
||||||
cb(sender, headerOut, HttpAllArgs<decltype(args)>(parser, args), val, invoker);
|
cb(sender, headerOut, ArgsJson(parser, args), val, invoker);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ static HttpApi toApi(const function<void(API_ARGS_STRING_ASYNC)> &cb) {
|
|||||||
Json::Value val;
|
Json::Value val;
|
||||||
val["code"] = API::Success;
|
val["code"] = API::Success;
|
||||||
|
|
||||||
cb(sender, headerOut, HttpAllArgs<string>(parser, (string &)parser.content()), val, invoker);
|
cb(sender, headerOut, ArgsString(parser, (string &)parser.content()), val, invoker);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,6 +389,7 @@ void dumpMediaTuple(const MediaTuple &tuple, Json::Value& item) {
|
|||||||
item[VHOST_KEY] = tuple.vhost;
|
item[VHOST_KEY] = tuple.vhost;
|
||||||
item["app"] = tuple.app;
|
item["app"] = tuple.app;
|
||||||
item["stream"] = tuple.stream;
|
item["stream"] = tuple.stream;
|
||||||
|
item["params"] = tuple.params;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value makeMediaSourceJson(MediaSource &media){
|
Value makeMediaSourceJson(MediaSource &media){
|
||||||
@ -584,8 +585,10 @@ void addStreamProxy(const string &vhost, const string &app, const string &stream
|
|||||||
//添加拉流代理
|
//添加拉流代理
|
||||||
auto player = s_player_proxy.make(key, vhost, app, stream, option, retry_count);
|
auto player = s_player_proxy.make(key, vhost, app, stream, option, retry_count);
|
||||||
|
|
||||||
// 先透传参数
|
// 先透传拷贝参数
|
||||||
player->mINI::operator=(args);
|
for (auto &pr : args) {
|
||||||
|
(*player)[pr.first] = pr.second;
|
||||||
|
}
|
||||||
|
|
||||||
//指定RTP over TCP(播放rtsp时有效)
|
//指定RTP over TCP(播放rtsp时有效)
|
||||||
(*player)[Client::kRtpType] = rtp_type;
|
(*player)[Client::kRtpType] = rtp_type;
|
||||||
@ -660,13 +663,6 @@ void addStreamPusherProxy(const string &schema,
|
|||||||
pusher->publish(url);
|
pusher->publish(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
static void getArgsValue(const HttpAllArgs<ApiArgsType> &allArgs, const string &key, Type &value) {
|
|
||||||
auto val = allArgs[key];
|
|
||||||
if (!val.empty()) {
|
|
||||||
value = (Type)val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安装api接口
|
* 安装api接口
|
||||||
@ -733,7 +729,7 @@ void installWebApi() {
|
|||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
auto &ini = mINI::Instance();
|
auto &ini = mINI::Instance();
|
||||||
int changed = API::Success;
|
int changed = API::Success;
|
||||||
for (auto &pr : allArgs.getArgs()) {
|
for (auto &pr : allArgs.args) {
|
||||||
if (ini.find(pr.first) == ini.end()) {
|
if (ini.find(pr.first) == ini.end()) {
|
||||||
#if 1
|
#if 1
|
||||||
//没有这个key
|
//没有这个key
|
||||||
@ -1091,7 +1087,7 @@ void installWebApi() {
|
|||||||
CHECK_ARGS("vhost","app","stream","url");
|
CHECK_ARGS("vhost","app","stream","url");
|
||||||
|
|
||||||
mINI args;
|
mINI args;
|
||||||
for (auto &pr : allArgs.getArgs()) {
|
for (auto &pr : allArgs.args) {
|
||||||
args.emplace(pr.first, pr.second);
|
args.emplace(pr.first, pr.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1188,7 +1184,7 @@ void installWebApi() {
|
|||||||
//测试url http://127.0.0.1/index/api/downloadBin
|
//测试url http://127.0.0.1/index/api/downloadBin
|
||||||
api_regist("/index/api/downloadBin",[](API_ARGS_MAP_ASYNC){
|
api_regist("/index/api/downloadBin",[](API_ARGS_MAP_ASYNC){
|
||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
invoker.responseFile(allArgs.getParser().getHeader(),StrCaseMap(),exePath());
|
invoker.responseFile(allArgs.parser.getHeader(), StrCaseMap(), exePath());
|
||||||
});
|
});
|
||||||
|
|
||||||
#if defined(ENABLE_RTPPROXY)
|
#if defined(ENABLE_RTPPROXY)
|
||||||
@ -1319,7 +1315,7 @@ void installWebApi() {
|
|||||||
if (!src) {
|
if (!src) {
|
||||||
throw ApiRetException("can not find the source stream", API::NotFound);
|
throw ApiRetException("can not find the source stream", API::NotFound);
|
||||||
}
|
}
|
||||||
auto type = allArgs["type"].as<int>();
|
auto type = allArgs["type"].empty() ? (int)MediaSourceEvent::SendRtpArgs::kRtpPS : allArgs["type"].as<int>();
|
||||||
if (!allArgs["use_ps"].empty()) {
|
if (!allArgs["use_ps"].empty()) {
|
||||||
// 兼容之前的use_ps参数
|
// 兼容之前的use_ps参数
|
||||||
type = allArgs["use_ps"].as<int>();
|
type = allArgs["use_ps"].as<int>();
|
||||||
@ -1359,7 +1355,7 @@ void installWebApi() {
|
|||||||
if (!src) {
|
if (!src) {
|
||||||
throw ApiRetException("can not find the source stream", API::NotFound);
|
throw ApiRetException("can not find the source stream", API::NotFound);
|
||||||
}
|
}
|
||||||
auto type = allArgs["type"].as<int>();
|
auto type = allArgs["type"].empty() ? (int)MediaSourceEvent::SendRtpArgs::kRtpPS : allArgs["type"].as<int>();
|
||||||
if (!allArgs["use_ps"].empty()) {
|
if (!allArgs["use_ps"].empty()) {
|
||||||
// 兼容之前的use_ps参数
|
// 兼容之前的use_ps参数
|
||||||
type = allArgs["use_ps"].as<int>();
|
type = allArgs["use_ps"].as<int>();
|
||||||
@ -1568,7 +1564,7 @@ void installWebApi() {
|
|||||||
api_regist("/index/api/deleteRecordDirectory", [](API_ARGS_MAP) {
|
api_regist("/index/api/deleteRecordDirectory", [](API_ARGS_MAP) {
|
||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
CHECK_ARGS("vhost", "app", "stream", "period");
|
CHECK_ARGS("vhost", "app", "stream", "period");
|
||||||
auto tuple = MediaTuple{allArgs["vhost"], allArgs["app"], allArgs["stream"]};
|
auto tuple = MediaTuple{allArgs["vhost"], allArgs["app"], allArgs["stream"], ""};
|
||||||
auto record_path = Recorder::getRecordPath(Recorder::type_mp4, tuple, allArgs["customized_path"]);
|
auto record_path = Recorder::getRecordPath(Recorder::type_mp4, tuple, allArgs["customized_path"]);
|
||||||
auto period = allArgs["period"];
|
auto period = allArgs["period"];
|
||||||
record_path = record_path + period + "/";
|
record_path = record_path + period + "/";
|
||||||
@ -1607,7 +1603,7 @@ void installWebApi() {
|
|||||||
api_regist("/index/api/getMP4RecordFile", [](API_ARGS_MAP){
|
api_regist("/index/api/getMP4RecordFile", [](API_ARGS_MAP){
|
||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
CHECK_ARGS("vhost", "app", "stream");
|
CHECK_ARGS("vhost", "app", "stream");
|
||||||
auto tuple = MediaTuple{allArgs["vhost"], allArgs["app"], allArgs["stream"]};
|
auto tuple = MediaTuple{allArgs["vhost"], allArgs["app"], allArgs["stream"], ""};
|
||||||
auto record_path = Recorder::getRecordPath(Recorder::type_mp4, tuple, allArgs["customized_path"]);
|
auto record_path = Recorder::getRecordPath(Recorder::type_mp4, tuple, allArgs["customized_path"]);
|
||||||
auto period = allArgs["period"];
|
auto period = allArgs["period"];
|
||||||
|
|
||||||
@ -1695,7 +1691,7 @@ void installWebApi() {
|
|||||||
|
|
||||||
//截图存在,且未过期,那么返回之
|
//截图存在,且未过期,那么返回之
|
||||||
res_old_snap = true;
|
res_old_snap = true;
|
||||||
responseSnap(path, allArgs.getParser().getHeader(), invoker);
|
responseSnap(path, allArgs.parser.getHeader(), invoker);
|
||||||
//中断遍历
|
//中断遍历
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@ -1726,7 +1722,7 @@ void installWebApi() {
|
|||||||
File::delete_file(new_snap);
|
File::delete_file(new_snap);
|
||||||
rename(new_snap_tmp.data(), new_snap.data());
|
rename(new_snap_tmp.data(), new_snap.data());
|
||||||
}
|
}
|
||||||
responseSnap(new_snap, allArgs.getParser().getHeader(), invoker, err_msg);
|
responseSnap(new_snap, allArgs.parser.getHeader(), invoker, err_msg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1741,7 +1737,7 @@ void installWebApi() {
|
|||||||
#ifdef ENABLE_WEBRTC
|
#ifdef ENABLE_WEBRTC
|
||||||
class WebRtcArgsImp : public WebRtcArgs {
|
class WebRtcArgsImp : public WebRtcArgs {
|
||||||
public:
|
public:
|
||||||
WebRtcArgsImp(const HttpAllArgs<string> &args, std::string session_id)
|
WebRtcArgsImp(const ArgsString &args, std::string session_id)
|
||||||
: _args(args)
|
: _args(args)
|
||||||
, _session_id(std::move(session_id)) {}
|
, _session_id(std::move(session_id)) {}
|
||||||
~WebRtcArgsImp() override = default;
|
~WebRtcArgsImp() override = default;
|
||||||
@ -1759,40 +1755,26 @@ void installWebApi() {
|
|||||||
CHECK_ARGS("app", "stream");
|
CHECK_ARGS("app", "stream");
|
||||||
|
|
||||||
return StrPrinter << "rtc://" << _args["Host"] << "/" << _args["app"] << "/"
|
return StrPrinter << "rtc://" << _args["Host"] << "/" << _args["app"] << "/"
|
||||||
<< _args["stream"] << "?" << _args.getParser().params() + "&session=" + _session_id;
|
<< _args["stream"] << "?" << _args.parser.params() + "&session=" + _session_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HttpAllArgs<string> _args;
|
ArgsString _args;
|
||||||
std::string _session_id;
|
std::string _session_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
api_regist("/index/api/webrtc",[](API_ARGS_STRING_ASYNC){
|
api_regist("/index/api/webrtc",[](API_ARGS_STRING_ASYNC){
|
||||||
CHECK_ARGS("type");
|
CHECK_ARGS("type");
|
||||||
auto type = allArgs["type"];
|
auto type = allArgs["type"];
|
||||||
auto offer = allArgs.getArgs();
|
auto offer = allArgs.args;
|
||||||
CHECK(!offer.empty(), "http body(webrtc offer sdp) is empty");
|
CHECK(!offer.empty(), "http body(webrtc offer sdp) is empty");
|
||||||
std::string host = allArgs.getParser()["Host"];
|
|
||||||
std::string localIp = host.substr(0, host.find(':'));
|
|
||||||
|
|
||||||
auto isVaildIP = [](std::string ip)-> bool {
|
|
||||||
int a,b,c,d;
|
|
||||||
return sscanf(ip.c_str(),"%d.%d.%d.%d", &a, &b, &c, &d) == 4;
|
|
||||||
};
|
|
||||||
if (!isVaildIP(localIp) || localIp=="127.0.0.1") {
|
|
||||||
localIp = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
auto &session = static_cast<Session&>(sender);
|
||||||
auto args = std::make_shared<WebRtcArgsImp>(allArgs, sender.getIdentifier());
|
auto args = std::make_shared<WebRtcArgsImp>(allArgs, sender.getIdentifier());
|
||||||
WebRtcPluginManager::Instance().getAnswerSdp(static_cast<Session&>(sender), type, *args, [invoker, val, offer, headerOut, localIp](const WebRtcInterface &exchanger) mutable {
|
WebRtcPluginManager::Instance().negotiateSdp(session, type, *args, [invoker, val, offer, headerOut](const WebRtcInterface &exchanger) mutable {
|
||||||
//设置返回类型
|
auto &handler = const_cast<WebRtcInterface &>(exchanger);
|
||||||
headerOut["Content-Type"] = HttpFileManager::getContentType(".json");
|
|
||||||
//设置跨域
|
|
||||||
headerOut["Access-Control-Allow-Origin"] = "*";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLocalIp(exchanger,localIp);
|
val["sdp"] = handler.getAnswerSdp(offer);
|
||||||
val["sdp"] = exchangeSdp(exchanger, offer);
|
|
||||||
val["id"] = exchanger.getIdentifier();
|
val["id"] = exchanger.getIdentifier();
|
||||||
val["type"] = "answer";
|
val["type"] = "answer";
|
||||||
invoker(200, headerOut, val.toStyledString());
|
invoker(200, headerOut, val.toStyledString());
|
||||||
@ -1806,21 +1788,19 @@ void installWebApi() {
|
|||||||
|
|
||||||
static constexpr char delete_webrtc_url [] = "/index/api/delete_webrtc";
|
static constexpr char delete_webrtc_url [] = "/index/api/delete_webrtc";
|
||||||
static auto whip_whep_func = [](const char *type, API_ARGS_STRING_ASYNC) {
|
static auto whip_whep_func = [](const char *type, API_ARGS_STRING_ASYNC) {
|
||||||
auto offer = allArgs.getArgs();
|
auto offer = allArgs.args;
|
||||||
CHECK(!offer.empty(), "http body(webrtc offer sdp) is empty");
|
CHECK(!offer.empty(), "http body(webrtc offer sdp) is empty");
|
||||||
|
|
||||||
auto &session = static_cast<Session&>(sender);
|
auto &session = static_cast<Session&>(sender);
|
||||||
auto location = std::string("http") + (session.overSsl() ? "s" : "") + "://" + allArgs["host"] + delete_webrtc_url;
|
auto location = std::string(session.overSsl() ? "https://" : "http://") + allArgs["host"] + delete_webrtc_url;
|
||||||
auto args = std::make_shared<WebRtcArgsImp>(allArgs, sender.getIdentifier());
|
auto args = std::make_shared<WebRtcArgsImp>(allArgs, sender.getIdentifier());
|
||||||
WebRtcPluginManager::Instance().getAnswerSdp(session, type, *args,
|
WebRtcPluginManager::Instance().negotiateSdp(session, type, *args, [invoker, offer, headerOut, location](const WebRtcInterface &exchanger) mutable {
|
||||||
[invoker, offer, headerOut, location](const WebRtcInterface &exchanger) mutable {
|
auto &handler = const_cast<WebRtcInterface &>(exchanger);
|
||||||
// 设置跨域
|
|
||||||
headerOut["Access-Control-Allow-Origin"] = "*";
|
|
||||||
try {
|
try {
|
||||||
// 设置返回类型
|
// 设置返回类型
|
||||||
headerOut["Content-Type"] = "application/sdp";
|
headerOut["Content-Type"] = "application/sdp";
|
||||||
headerOut["Location"] = location + "?id=" + exchanger.getIdentifier() + "&token=" + exchanger.deleteRandStr();
|
headerOut["Location"] = location + "?id=" + exchanger.getIdentifier() + "&token=" + exchanger.deleteRandStr();
|
||||||
invoker(201, headerOut, exchangeSdp(exchanger, offer));
|
invoker(201, headerOut, handler.getAnswerSdp(offer));
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
headerOut["Content-Type"] = "text/plain";
|
headerOut["Content-Type"] = "text/plain";
|
||||||
invoker(406, headerOut, ex.what());
|
invoker(406, headerOut, ex.what());
|
||||||
@ -1833,7 +1813,7 @@ void installWebApi() {
|
|||||||
|
|
||||||
api_regist(delete_webrtc_url, [](API_ARGS_MAP_ASYNC) {
|
api_regist(delete_webrtc_url, [](API_ARGS_MAP_ASYNC) {
|
||||||
CHECK_ARGS("id", "token");
|
CHECK_ARGS("id", "token");
|
||||||
CHECK(allArgs.getParser().method() == "DELETE", "http method is not DELETE: " + allArgs.getParser().method());
|
CHECK(allArgs.parser.method() == "DELETE", "http method is not DELETE: " + allArgs.parser.method());
|
||||||
auto obj = WebRtcTransportManager::Instance().getItem(allArgs["id"]);
|
auto obj = WebRtcTransportManager::Instance().getItem(allArgs["id"]);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
invoker(404, headerOut, "id not found");
|
invoker(404, headerOut, "id not found");
|
||||||
@ -1919,44 +1899,39 @@ void installWebApi() {
|
|||||||
if (!save_name.empty()) {
|
if (!save_name.empty()) {
|
||||||
res_header.emplace("Content-Disposition", "attachment;filename=\"" + save_name + "\"");
|
res_header.emplace("Content-Disposition", "attachment;filename=\"" + save_name + "\"");
|
||||||
}
|
}
|
||||||
invoker.responseFile(allArgs.getParser().getHeader(), res_header, allArgs["file_path"]);
|
invoker.responseFile(allArgs.parser.getHeader(), res_header, allArgs["file_path"]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool flag = NOTICE_EMIT(BroadcastHttpAccessArgs, Broadcast::kBroadcastHttpAccess, allArgs.getParser(), file_path, false, file_invoker, sender);
|
bool flag = NOTICE_EMIT(BroadcastHttpAccessArgs, Broadcast::kBroadcastHttpAccess, allArgs.parser, file_path, false, file_invoker, sender);
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
// 文件下载鉴权事件无人监听,不允许下载
|
// 文件下载鉴权事件无人监听,不允许下载
|
||||||
invoker(401, StrCaseMap {}, "None http access event listener");
|
invoker(401, StrCaseMap {}, "None http access event listener");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
#if defined(ENABLE_X264) && defined(ENABLE_FFMPEG)
|
#if defined(ENABLE_VIDEOSTACK) && defined(ENABLE_X264) && defined(ENABLE_FFMPEG)
|
||||||
VideoStackManager::Instance().loadBgImg("novideo.yuv");
|
VideoStackManager::Instance().loadBgImg("novideo.yuv");
|
||||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastStreamNoneReader, [](BroadcastStreamNoneReaderArgs) {
|
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastStreamNoneReader, [](BroadcastStreamNoneReaderArgs) {
|
||||||
auto id = sender.getMediaTuple().stream;
|
auto id = sender.getMediaTuple().stream;
|
||||||
VideoStackManager::Instance().stopVideoStack(id);
|
VideoStackManager::Instance().stopVideoStack(id);
|
||||||
InfoL << "VideoStack: " << id <<" stop";
|
|
||||||
});
|
});
|
||||||
|
|
||||||
api_regist("/index/api/stack/start", [](API_ARGS_JSON_ASYNC) {
|
api_regist("/index/api/stack/start", [](API_ARGS_JSON_ASYNC) {
|
||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
auto ret = VideoStackManager::Instance().startVideoStack(allArgs.getArgs());
|
auto ret = VideoStackManager::Instance().startVideoStack(allArgs.args);
|
||||||
if (!ret) {
|
val["code"] = ret;
|
||||||
invoker(200, headerOut, "success");
|
val["msg"] = ret ? "failed" : "success";
|
||||||
} else {
|
invoker(200, headerOut, val.toStyledString());
|
||||||
invoker(200, headerOut, "failed");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
api_regist("/index/api/stack/stop", [](API_ARGS_MAP_ASYNC) {
|
api_regist("/index/api/stack/stop", [](API_ARGS_MAP_ASYNC) {
|
||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
CHECK_ARGS("id");
|
CHECK_ARGS("id");
|
||||||
auto ret = VideoStackManager::Instance().stopVideoStack(allArgs["id"]);
|
auto ret = VideoStackManager::Instance().stopVideoStack(allArgs["id"]);
|
||||||
if (!ret) {
|
val["code"] = ret;
|
||||||
invoker(200, headerOut, "success");
|
val["msg"] = ret ? "failed" : "success";
|
||||||
} else {
|
invoker(200, headerOut, val.toStyledString());
|
||||||
invoker(200, headerOut, "failed");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -115,72 +115,41 @@ std::string getValue(const mediakit::Parser &parser, Args &args, const First &fi
|
|||||||
|
|
||||||
template<typename Args>
|
template<typename Args>
|
||||||
class HttpAllArgs {
|
class HttpAllArgs {
|
||||||
|
mediakit::Parser* _parser = nullptr;
|
||||||
|
Args* _args = nullptr;
|
||||||
public:
|
public:
|
||||||
HttpAllArgs(const mediakit::Parser &parser, Args &args) {
|
const mediakit::Parser& parser;
|
||||||
_get_args = [&args]() {
|
Args& args;
|
||||||
return (void *) &args;
|
|
||||||
};
|
|
||||||
_get_parser = [&parser]() -> const mediakit::Parser & {
|
|
||||||
return parser;
|
|
||||||
};
|
|
||||||
_get_value = [](HttpAllArgs &that, const std::string &key) {
|
|
||||||
return getValue(that.getParser(), that.getArgs(), key);
|
|
||||||
};
|
|
||||||
_clone = [&](HttpAllArgs &that) {
|
|
||||||
that._get_args = [args]() {
|
|
||||||
return (void *) &args;
|
|
||||||
};
|
|
||||||
that._get_parser = [parser]() -> const mediakit::Parser & {
|
|
||||||
return parser;
|
|
||||||
};
|
|
||||||
that._get_value = [](HttpAllArgs &that, const std::string &key) {
|
|
||||||
return getValue(that.getParser(), that.getArgs(), key);
|
|
||||||
};
|
|
||||||
that._cache_able = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpAllArgs(const HttpAllArgs &that) {
|
HttpAllArgs(const mediakit::Parser &p, Args &a): parser(p), args(a) {}
|
||||||
if (that._cache_able) {
|
|
||||||
_get_args = that._get_args;
|
HttpAllArgs(const HttpAllArgs &that): _parser(new mediakit::Parser(that.parser)),
|
||||||
_get_parser = that._get_parser;
|
_args(new Args(that.args)),
|
||||||
_get_value = that._get_value;
|
parser(*_parser), args(*_args) {}
|
||||||
_cache_able = true;
|
~HttpAllArgs() {
|
||||||
} else {
|
if (_parser) {
|
||||||
that._clone(*this);
|
delete _parser;
|
||||||
|
}
|
||||||
|
if (_args) {
|
||||||
|
delete _args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key>
|
template<typename Key>
|
||||||
toolkit::variant operator[](const Key &key) const {
|
toolkit::variant operator[](const Key &key) const {
|
||||||
return (toolkit::variant)_get_value(*(HttpAllArgs*)this, key);
|
return (toolkit::variant)getValue(parser, args, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const mediakit::Parser &getParser() const {
|
|
||||||
return _get_parser();
|
|
||||||
}
|
|
||||||
|
|
||||||
Args &getArgs() {
|
|
||||||
return *((Args *) _get_args());
|
|
||||||
}
|
|
||||||
|
|
||||||
const Args &getArgs() const {
|
|
||||||
return *((Args *) _get_args());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool _cache_able = false;
|
|
||||||
std::function<void *() > _get_args;
|
|
||||||
std::function<const mediakit::Parser &() > _get_parser;
|
|
||||||
std::function<std::string(HttpAllArgs &that, const std::string &key)> _get_value;
|
|
||||||
std::function<void(HttpAllArgs &that) > _clone;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define API_ARGS_MAP toolkit::SockInfo &sender, mediakit::HttpSession::KeyValue &headerOut, const HttpAllArgs<ApiArgsType> &allArgs, Json::Value &val
|
using ArgsMap = HttpAllArgs<ApiArgsType>;
|
||||||
|
using ArgsJson = HttpAllArgs<Json::Value>;
|
||||||
|
using ArgsString = HttpAllArgs<std::string>;
|
||||||
|
|
||||||
|
#define API_ARGS_MAP toolkit::SockInfo &sender, mediakit::HttpSession::KeyValue &headerOut, const ArgsMap &allArgs, Json::Value &val
|
||||||
#define API_ARGS_MAP_ASYNC API_ARGS_MAP, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
#define API_ARGS_MAP_ASYNC API_ARGS_MAP, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
||||||
#define API_ARGS_JSON toolkit::SockInfo &sender, mediakit::HttpSession::KeyValue &headerOut, const HttpAllArgs<Json::Value> &allArgs, Json::Value &val
|
#define API_ARGS_JSON toolkit::SockInfo &sender, mediakit::HttpSession::KeyValue &headerOut, const ArgsJson &allArgs, Json::Value &val
|
||||||
#define API_ARGS_JSON_ASYNC API_ARGS_JSON, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
#define API_ARGS_JSON_ASYNC API_ARGS_JSON, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
||||||
#define API_ARGS_STRING toolkit::SockInfo &sender, mediakit::HttpSession::KeyValue &headerOut, const HttpAllArgs<std::string> &allArgs, Json::Value &val
|
#define API_ARGS_STRING toolkit::SockInfo &sender, mediakit::HttpSession::KeyValue &headerOut, const ArgsString &allArgs, Json::Value &val
|
||||||
#define API_ARGS_STRING_ASYNC API_ARGS_STRING, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
#define API_ARGS_STRING_ASYNC API_ARGS_STRING, const mediakit::HttpSession::HttpResponseInvoker &invoker
|
||||||
#define API_ARGS_VALUE sender, headerOut, allArgs, val
|
#define API_ARGS_VALUE sender, headerOut, allArgs, val
|
||||||
|
|
||||||
@ -234,8 +203,6 @@ void unInstallWebApi();
|
|||||||
|
|
||||||
#if defined(ENABLE_RTPPROXY)
|
#if defined(ENABLE_RTPPROXY)
|
||||||
uint16_t openRtpServer(uint16_t local_port, const std::string &stream_id, int tcp_mode, const std::string &local_ip, bool re_use_port, uint32_t ssrc, int only_track, bool multiplex=false);
|
uint16_t openRtpServer(uint16_t local_port, const std::string &stream_id, int tcp_mode, const std::string &local_ip, bool re_use_port, uint32_t ssrc, int only_track, bool multiplex=false);
|
||||||
void connectRtpServer(const std::string &stream_id, const std::string &dst_url, uint16_t dst_port, const std::function<void(const toolkit::SockException &ex)> &cb);
|
|
||||||
bool closeRtpServer(const std::string &stream_id);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Json::Value makeMediaSourceJson(mediakit::MediaSource &media);
|
Json::Value makeMediaSourceJson(mediakit::MediaSource &media);
|
||||||
|
@ -225,7 +225,7 @@ static ArgsType make_json(const MediaInfo &args) {
|
|||||||
ArgsType body;
|
ArgsType body;
|
||||||
body["schema"] = args.schema;
|
body["schema"] = args.schema;
|
||||||
dumpMediaTuple(args, body);
|
dumpMediaTuple(args, body);
|
||||||
body["params"] = args.param_strs;
|
body["params"] = args.params;
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ static string getPullUrl(const string &origin_fmt, const MediaInfo &info) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
// 告知源站这是来自边沿站的拉流请求,如果未找到流请立即返回拉流失败
|
// 告知源站这是来自边沿站的拉流请求,如果未找到流请立即返回拉流失败
|
||||||
return string(url) + '?' + kEdgeServerParam + '&' + VHOST_KEY + '=' + info.vhost + '&' + info.param_strs;
|
return string(url) + '?' + kEdgeServerParam + '&' + VHOST_KEY + '=' + info.vhost + '&' + info.params;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pullStreamFromOrigin(const vector<string> &urls, size_t index, size_t failed_cnt, const MediaInfo &args, const function<void()> &closePlayer) {
|
static void pullStreamFromOrigin(const vector<string> &urls, size_t index, size_t failed_cnt, const MediaInfo &args, const function<void()> &closePlayer) {
|
||||||
@ -498,7 +498,7 @@ void installWebHook() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start_with(args.param_strs, kEdgeServerParam)) {
|
if (start_with(args.params, kEdgeServerParam)) {
|
||||||
// 源站收到来自边沿站的溯源请求,流不存在时立即返回拉流失败
|
// 源站收到来自边沿站的溯源请求,流不存在时立即返回拉流失败
|
||||||
closePlayer();
|
closePlayer();
|
||||||
return;
|
return;
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_VERSION)
|
#if defined(ENABLE_VERSION)
|
||||||
#include "version.h"
|
#include "ZLMVersion.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
@ -258,6 +258,15 @@ int start_main(int argc,char *argv[]) {
|
|||||||
//加载配置文件,如果配置文件不存在就创建一个
|
//加载配置文件,如果配置文件不存在就创建一个
|
||||||
loadIniConfig(g_ini_file.data());
|
loadIniConfig(g_ini_file.data());
|
||||||
|
|
||||||
|
auto &secret = mINI::Instance()[API::kSecret];
|
||||||
|
if (secret == "035c73f7-bb6b-4889-a715-d9eb2d1925cc" || secret.empty()) {
|
||||||
|
// 使用默认secret被禁止启动
|
||||||
|
secret = makeRandStr(32, true);
|
||||||
|
mINI::Instance().dumpFile(g_ini_file);
|
||||||
|
WarnL << "The " << API::kSecret << " is invalid, modified it to: " << secret
|
||||||
|
<< ", saved config file: " << g_ini_file;
|
||||||
|
}
|
||||||
|
|
||||||
if (!File::is_dir(ssl_file)) {
|
if (!File::is_dir(ssl_file)) {
|
||||||
// 不是文件夹,加载证书,证书包含公钥和私钥
|
// 不是文件夹,加载证书,证书包含公钥和私钥
|
||||||
SSL_Initor::Instance().loadCertificate(ssl_file.data());
|
SSL_Initor::Instance().loadCertificate(ssl_file.data());
|
||||||
@ -352,14 +361,6 @@ int start_main(int argc,char *argv[]) {
|
|||||||
InfoL << "已启动http hook 接口";
|
InfoL << "已启动http hook 接口";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto &secret = mINI::Instance()[API::kSecret];
|
|
||||||
if (secret == "035c73f7-bb6b-4889-a715-d9eb2d1925cc" || secret.empty()) {
|
|
||||||
// 使用默认secret被禁止启动
|
|
||||||
secret = makeRandStr(32, true);
|
|
||||||
mINI::Instance().dumpFile(g_ini_file);
|
|
||||||
WarnL << "The " << API::kSecret << " is invalid, modified it to: " << secret
|
|
||||||
<< ", saved config file: " << g_ini_file;
|
|
||||||
}
|
|
||||||
//rtsp服务器,端口默认554
|
//rtsp服务器,端口默认554
|
||||||
if (rtspPort) { rtspSrv->start<RtspSession>(rtspPort); }
|
if (rtspPort) { rtspSrv->start<RtspSession>(rtspPort); }
|
||||||
//rtsps服务器,端口默认322
|
//rtsps服务器,端口默认322
|
||||||
|
@ -113,7 +113,7 @@ ProtocolOption::ProtocolOption() {
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct MediaSourceNull : public MediaSource {
|
struct MediaSourceNull : public MediaSource {
|
||||||
MediaSourceNull() : MediaSource("schema", MediaTuple{"vhost", "app", "stream"}) {};
|
MediaSourceNull() : MediaSource("schema", MediaTuple{"vhost", "app", "stream", ""}) {};
|
||||||
int readerCount() override { return 0; }
|
int readerCount() override { return 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -583,7 +583,7 @@ void MediaInfo::parse(const std::string &url_in){
|
|||||||
auto url = url_in;
|
auto url = url_in;
|
||||||
auto pos = url.find("?");
|
auto pos = url.find("?");
|
||||||
if (pos != string::npos) {
|
if (pos != string::npos) {
|
||||||
param_strs = url.substr(pos + 1);
|
params = url.substr(pos + 1);
|
||||||
url.erase(pos);
|
url.erase(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -616,9 +616,10 @@ void MediaInfo::parse(const std::string &url_in){
|
|||||||
stream = stream_id;
|
stream = stream_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto params = Parser::parseArgs(param_strs);
|
auto kv = Parser::parseArgs(params);
|
||||||
if (params.find(VHOST_KEY) != params.end()) {
|
auto it = kv.find(VHOST_KEY);
|
||||||
vhost = params[VHOST_KEY];
|
if (it != kv.end()) {
|
||||||
|
vhost = it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
|
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
|
||||||
|
@ -136,6 +136,15 @@ private:
|
|||||||
toolkit::Timer::Ptr _async_close_timer;
|
toolkit::Timer::Ptr _async_close_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <typename MAP, typename KEY, typename TYPE>
|
||||||
|
static void getArgsValue(const MAP &allArgs, const KEY &key, TYPE &value) {
|
||||||
|
auto val = ((MAP &)allArgs)[key];
|
||||||
|
if (!val.empty()) {
|
||||||
|
value = (TYPE)val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ProtocolOption {
|
class ProtocolOption {
|
||||||
public:
|
public:
|
||||||
ProtocolOption();
|
ProtocolOption();
|
||||||
@ -243,15 +252,6 @@ public:
|
|||||||
GET_OPT_VALUE(stream_replace);
|
GET_OPT_VALUE(stream_replace);
|
||||||
GET_OPT_VALUE(max_track);
|
GET_OPT_VALUE(max_track);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
template <typename MAP, typename KEY, typename TYPE>
|
|
||||||
static void getArgsValue(const MAP &allArgs, const KEY &key, TYPE &value) {
|
|
||||||
auto val = ((MAP &)allArgs)[key];
|
|
||||||
if (!val.empty()) {
|
|
||||||
value = (TYPE)val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//该对象用于拦截感兴趣的MediaSourceEvent事件
|
//该对象用于拦截感兴趣的MediaSourceEvent事件
|
||||||
@ -299,7 +299,6 @@ public:
|
|||||||
std::string full_url;
|
std::string full_url;
|
||||||
std::string schema;
|
std::string schema;
|
||||||
std::string host;
|
std::string host;
|
||||||
std::string param_strs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool equalMediaTuple(const MediaTuple& a, const MediaTuple& b);
|
bool equalMediaTuple(const MediaTuple& a, const MediaTuple& b);
|
||||||
|
@ -294,8 +294,8 @@ void RtspUrl::setup(bool is_ssl, const string &url, const string &user, const st
|
|||||||
splitUrl(ip, ip, port);
|
splitUrl(ip, ip, port);
|
||||||
|
|
||||||
_url = std::move(url);
|
_url = std::move(url);
|
||||||
_user = strCoding::UrlDecode(std::move(user));
|
_user = strCoding::UrlDecodeUserOrPass(user);
|
||||||
_passwd = strCoding::UrlDecode(std::move(passwd));
|
_passwd = strCoding::UrlDecodeUserOrPass(passwd);
|
||||||
_host = std::move(ip);
|
_host = std::move(ip);
|
||||||
_port = port;
|
_port = port;
|
||||||
_is_ssl = is_ssl;
|
_is_ssl = is_ssl;
|
||||||
|
@ -30,7 +30,7 @@ struct StrCaseCompare {
|
|||||||
|
|
||||||
class StrCaseMap : public std::multimap<std::string, std::string, StrCaseCompare> {
|
class StrCaseMap : public std::multimap<std::string, std::string, StrCaseCompare> {
|
||||||
public:
|
public:
|
||||||
using Super = multimap<std::string, std::string, StrCaseCompare>;
|
using Super = std::multimap<std::string, std::string, StrCaseCompare>;
|
||||||
|
|
||||||
std::string &operator[](const std::string &k) {
|
std::string &operator[](const std::string &k) {
|
||||||
auto it = find(k);
|
auto it = find(k);
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
#if defined(ENABLE_VERSION)
|
#if defined(ENABLE_VERSION)
|
||||||
#include "version.h"
|
#include "ZLMVersion.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -36,6 +36,16 @@
|
|||||||
#define CHECK(exp, ...) ::mediakit::Assert_ThrowCpp(!(exp), #exp, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
|
#define CHECK(exp, ...) ::mediakit::Assert_ThrowCpp(!(exp), #exp, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
|
||||||
#endif // CHECK
|
#endif // CHECK
|
||||||
|
|
||||||
|
#ifndef CHECK_RET
|
||||||
|
#define CHECK_RET(...) \
|
||||||
|
try { \
|
||||||
|
CHECK(__VA_ARGS__); \
|
||||||
|
} catch (AssertFailedException & ex) { \
|
||||||
|
WarnL << ex.what(); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#endif // MAX
|
#endif // MAX
|
||||||
|
@ -52,25 +52,7 @@ char HexStrToBin(const char *str) {
|
|||||||
}
|
}
|
||||||
return (high << 4) | low;
|
return (high << 4) | low;
|
||||||
}
|
}
|
||||||
|
static string UrlEncodeCommon(const string &str,const char* dont_escape){
|
||||||
string strCoding::UrlEncode(const string &str) {
|
|
||||||
string out;
|
|
||||||
size_t len = str.size();
|
|
||||||
for (size_t i = 0; i < len; ++i) {
|
|
||||||
char ch = str[i];
|
|
||||||
if (isalnum((uint8_t) ch)) {
|
|
||||||
out.push_back(ch);
|
|
||||||
} else {
|
|
||||||
char buf[4];
|
|
||||||
sprintf(buf, "%%%X%X", (uint8_t) ch >> 4, (uint8_t) ch & 0x0F);
|
|
||||||
out.append(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
string strCoding::UrlEncodePath(const string &str) {
|
|
||||||
const char *dont_escape = "!#&'*+:=?@/._-$,;~()";
|
|
||||||
string out;
|
string out;
|
||||||
size_t len = str.size();
|
size_t len = str.size();
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
@ -85,52 +67,7 @@ string strCoding::UrlEncodePath(const string &str) {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
static string UrlDecodeCommon(const string &str,const char* dont_unescape){
|
||||||
string strCoding::UrlEncodeComponent(const string &str) {
|
|
||||||
const char *dont_escape = "!'()*-._~";
|
|
||||||
string out;
|
|
||||||
size_t len = str.size();
|
|
||||||
for (size_t i = 0; i < len; ++i) {
|
|
||||||
char ch = str[i];
|
|
||||||
if (isalnum((uint8_t) ch) || strchr(dont_escape, (uint8_t) ch) != NULL) {
|
|
||||||
out.push_back(ch);
|
|
||||||
} else {
|
|
||||||
char buf[4];
|
|
||||||
snprintf(buf, 4, "%%%X%X", (uint8_t) ch >> 4, (uint8_t) ch & 0x0F);
|
|
||||||
out.append(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
string strCoding::UrlDecode(const string &str) {
|
|
||||||
string output;
|
|
||||||
size_t i = 0, len = str.length();
|
|
||||||
while (i < len) {
|
|
||||||
if (str[i] == '%') {
|
|
||||||
if (i + 3 > len) {
|
|
||||||
// %后面必须还有两个字节才会反转义
|
|
||||||
output.append(str, i, len - i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
char ch = HexStrToBin(&(str[i + 1]));
|
|
||||||
if (ch == -1) {
|
|
||||||
// %后面两个字节不是16进制字符串,转义失败;直接拼接3个原始字符
|
|
||||||
output.append(str, i, 3);
|
|
||||||
} else {
|
|
||||||
output += ch;
|
|
||||||
}
|
|
||||||
i += 3;
|
|
||||||
} else {
|
|
||||||
output += str[i];
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
string strCoding::UrlDecodePath(const string &str) {
|
|
||||||
const char *dont_unescape = "#$&+,/:;=?@";
|
|
||||||
string output;
|
string output;
|
||||||
size_t i = 0, len = str.length();
|
size_t i = 0, len = str.length();
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
@ -156,6 +93,36 @@ string strCoding::UrlDecodePath(const string &str) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string strCoding::UrlEncodePath(const string &str) {
|
||||||
|
const char *dont_escape = "!#&'*+:=?@/._-$,;~()";
|
||||||
|
return UrlEncodeCommon(str,dont_escape);
|
||||||
|
}
|
||||||
|
|
||||||
|
string strCoding::UrlEncodeComponent(const string &str) {
|
||||||
|
const char *dont_escape = "!'()*-._~";
|
||||||
|
return UrlEncodeCommon(str,dont_escape);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string strCoding::UrlEncodeUserOrPass(const std::string &str) {
|
||||||
|
// from rfc https://datatracker.ietf.org/doc/html/rfc3986
|
||||||
|
// §2.3 Unreserved characters (mark)
|
||||||
|
//'-', '_', '.', '~'
|
||||||
|
// §2.2 Reserved characters (reserved)
|
||||||
|
// '$', '&', '+', ',', '/', ':', ';', '=', '?', '@',
|
||||||
|
// §3.2.1
|
||||||
|
// The RFC allows ';', ':', '&', '=', '+', '$', and ',' in
|
||||||
|
// userinfo, so we must escape only '@', '/', and '?'.
|
||||||
|
// The parsing of userinfo treats ':' as special so we must escape
|
||||||
|
// that too.
|
||||||
|
const char *dont_escape = "$&+,;=-._~";
|
||||||
|
return UrlEncodeCommon(str,dont_escape);
|
||||||
|
}
|
||||||
|
|
||||||
|
string strCoding::UrlDecodePath(const string &str) {
|
||||||
|
const char *dont_unescape = "#$&+,/:;=?@";
|
||||||
|
return UrlDecodeCommon(str,dont_unescape);
|
||||||
|
}
|
||||||
|
|
||||||
std::string strCoding::UrlDecodeComponent(const std::string &str) {
|
std::string strCoding::UrlDecodeComponent(const std::string &str) {
|
||||||
string output;
|
string output;
|
||||||
size_t i = 0, len = str.length();
|
size_t i = 0, len = str.length();
|
||||||
@ -185,27 +152,11 @@ std::string strCoding::UrlDecodeComponent(const std::string &str) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
#include "Util/onceToken.h"
|
|
||||||
static toolkit::onceToken token([]() {
|
|
||||||
auto str0 = strCoding::UrlDecode(
|
|
||||||
"rtsp%3A%2F%2Fadmin%3AJm13317934%25jm%40111.47.84.69%3A554%2FStreaming%2FChannels%2F101%3Ftransportmode%3Dunicast%26amp%3Bprofile%3DProfile_1");
|
|
||||||
auto str1 = strCoding::UrlDecode("%j1"); // 测试%后面两个字节不是16进制字符串
|
|
||||||
auto str2 = strCoding::UrlDecode("%a"); // 测试%后面字节数不够
|
|
||||||
auto str3 = strCoding::UrlDecode("%"); // 测试只有%
|
|
||||||
auto str4 = strCoding::UrlDecode("%%%"); // 测试多个%
|
|
||||||
auto str5 = strCoding::UrlDecode("%%%%40"); // 测试多个非法%后恢复正常解析
|
|
||||||
auto str6 = strCoding::UrlDecode("Jm13317934%jm"); // 测试多个非法%后恢复正常解析
|
|
||||||
cout << str0 << endl;
|
|
||||||
cout << str1 << endl;
|
|
||||||
cout << str2 << endl;
|
|
||||||
cout << str3 << endl;
|
|
||||||
cout << str4 << endl;
|
|
||||||
cout << str5 << endl;
|
|
||||||
cout << str6 << endl;
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
std::string strCoding::UrlDecodeUserOrPass(const std::string &str) {
|
||||||
|
const char *dont_unescape = "";
|
||||||
|
return UrlDecodeCommon(str,dont_unescape);
|
||||||
|
}
|
||||||
///////////////////////////////windows专用///////////////////////////////////
|
///////////////////////////////windows专用///////////////////////////////////
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
void UnicodeToGB2312(char* pOut, wchar_t uData)
|
void UnicodeToGB2312(char* pOut, wchar_t uData)
|
||||||
|
@ -18,12 +18,12 @@ namespace mediakit {
|
|||||||
|
|
||||||
class strCoding {
|
class strCoding {
|
||||||
public:
|
public:
|
||||||
[[deprecated]] static std::string UrlEncode(const std::string &str); //url utf8编码, deprecated
|
|
||||||
static std::string UrlEncodePath(const std::string &str); //url路径 utf8编码
|
static std::string UrlEncodePath(const std::string &str); //url路径 utf8编码
|
||||||
static std::string UrlEncodeComponent(const std::string &str); // url参数 utf8编码
|
static std::string UrlEncodeComponent(const std::string &str); // url参数 utf8编码
|
||||||
[[deprecated]] static std::string UrlDecode(const std::string &str); //url utf8解码, deprecated
|
|
||||||
static std::string UrlDecodePath(const std::string &str); //url路径 utf8解码
|
static std::string UrlDecodePath(const std::string &str); //url路径 utf8解码
|
||||||
static std::string UrlDecodeComponent(const std::string &str); // url参数 utf8解码
|
static std::string UrlDecodeComponent(const std::string &str); // url参数 utf8解码
|
||||||
|
static std::string UrlEncodeUserOrPass(const std::string &str); // url中用户名与密码编码
|
||||||
|
static std::string UrlDecodeUserOrPass(const std::string &str); // url中用户名与密码解码
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static std::string UTF8ToGB2312(const std::string &str);//utf_8转为gb2312
|
static std::string UTF8ToGB2312(const std::string &str);//utf_8转为gb2312
|
||||||
static std::string GB2312ToUTF8(const std::string &str); //gb2312 转utf_8
|
static std::string GB2312ToUTF8(const std::string &str); //gb2312 转utf_8
|
||||||
|
@ -65,18 +65,18 @@ void HttpRequestSplitter::input(const char *data,size_t len) {
|
|||||||
_content_len = onRecvHeader(header_ptr, header_size);
|
_content_len = onRecvHeader(header_ptr, header_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_remain_data_size <= 0){
|
|
||||||
//没有剩余数据,清空缓存
|
|
||||||
_remain_data.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 恢复末尾字节
|
* 恢复末尾字节
|
||||||
* 移动到这来,目的是防止HttpRequestSplitter::reset()导致内存失效
|
* 移动到这来,目的是防止HttpRequestSplitter::reset()导致内存失效
|
||||||
*/
|
*/
|
||||||
tail_ref = tail_tmp;
|
tail_ref = tail_tmp;
|
||||||
|
|
||||||
|
if(_remain_data_size <= 0){
|
||||||
|
//没有剩余数据,清空缓存
|
||||||
|
_remain_data.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(_content_len == 0){
|
if(_content_len == 0){
|
||||||
//尚未找到http头,缓存定位到剩余数据部分
|
//尚未找到http头,缓存定位到剩余数据部分
|
||||||
_remain_data.assign(ptr,_remain_data_size);
|
_remain_data.assign(ptr,_remain_data_size);
|
||||||
|
@ -683,18 +683,6 @@ void HttpSession::sendResponse(int code,
|
|||||||
AsyncSender::onSocketFlushed(data);
|
AsyncSender::onSocketFlushed(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
string HttpSession::urlDecode(const string &str) {
|
|
||||||
auto ret = strCoding::UrlDecode(str);
|
|
||||||
#ifdef _WIN32
|
|
||||||
GET_CONFIG(string, charSet, Http::kCharSet);
|
|
||||||
bool isGb2312 = !strcasecmp(charSet.data(), "gb2312");
|
|
||||||
if (isGb2312) {
|
|
||||||
ret = strCoding::UTF8ToGB2312(ret);
|
|
||||||
}
|
|
||||||
#endif // _WIN32
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
string HttpSession::urlDecodePath(const string &str) {
|
string HttpSession::urlDecodePath(const string &str) {
|
||||||
auto ret = strCoding::UrlDecodePath(str);
|
auto ret = strCoding::UrlDecodePath(str);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -44,7 +44,6 @@ public:
|
|||||||
void onRecv(const toolkit::Buffer::Ptr &) override;
|
void onRecv(const toolkit::Buffer::Ptr &) override;
|
||||||
void onError(const toolkit::SockException &err) override;
|
void onError(const toolkit::SockException &err) override;
|
||||||
void onManager() override;
|
void onManager() override;
|
||||||
[[deprecated]] static std::string urlDecode(const std::string &str);
|
|
||||||
static std::string urlDecodePath(const std::string &str);
|
static std::string urlDecodePath(const std::string &str);
|
||||||
static std::string urlDecodeComponent(const std::string &str);
|
static std::string urlDecodeComponent(const std::string &str);
|
||||||
void setTimeoutSec(size_t second);
|
void setTimeoutSec(size_t second);
|
||||||
|
@ -195,10 +195,8 @@ std::shared_ptr<FILE> HlsMakerImp::makeFile(const string &file, bool setbuf) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HlsMakerImp::setMediaSource(const string &vhost, const string &app, const string &stream_id) {
|
void HlsMakerImp::setMediaSource(const MediaTuple& tuple) {
|
||||||
_info.app = app;
|
static_cast<MediaTuple &>(_info) = tuple;
|
||||||
_info.stream = stream_id;
|
|
||||||
_info.vhost = vhost;
|
|
||||||
_media_src = std::make_shared<HlsMediaSource>(isFmp4() ? HLS_FMP4_SCHEMA : HLS_SCHEMA, _info);
|
_media_src = std::make_shared<HlsMediaSource>(isFmp4() ? HLS_FMP4_SCHEMA : HLS_SCHEMA, _info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,11 +27,8 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置媒体信息
|
* 设置媒体信息
|
||||||
* @param vhost 虚拟主机
|
|
||||||
* @param app 应用名
|
|
||||||
* @param stream_id 流id
|
|
||||||
*/
|
*/
|
||||||
void setMediaSource(const std::string &vhost, const std::string &app, const std::string &stream_id);
|
void setMediaSource(const MediaTuple& tuple);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取MediaSource
|
* 获取MediaSource
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setMediaSource(const MediaTuple& tuple) {
|
void setMediaSource(const MediaTuple& tuple) {
|
||||||
_hls->setMediaSource(tuple.vhost, tuple.app, tuple.stream);
|
_hls->setMediaSource(tuple);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setListener(const std::weak_ptr<MediaSourceEvent> &listener) {
|
void setListener(const std::weak_ptr<MediaSourceEvent> &listener) {
|
||||||
|
@ -38,7 +38,7 @@ MP4Reader::MP4Reader(const std::string &vhost, const std::string &app, const std
|
|||||||
|
|
||||||
void MP4Reader::setup(const std::string &vhost, const std::string &app, const std::string &stream_id, const std::string &file_path, const ProtocolOption &option, toolkit::EventPoller::Ptr poller) {
|
void MP4Reader::setup(const std::string &vhost, const std::string &app, const std::string &stream_id, const std::string &file_path, const ProtocolOption &option, toolkit::EventPoller::Ptr poller) {
|
||||||
//读写文件建议放在后台线程
|
//读写文件建议放在后台线程
|
||||||
auto tuple = MediaTuple{vhost, app, stream_id};
|
auto tuple = MediaTuple{vhost, app, stream_id, ""};
|
||||||
_poller = poller ? std::move(poller) : WorkThreadPool::Instance().getPoller();
|
_poller = poller ? std::move(poller) : WorkThreadPool::Instance().getPoller();
|
||||||
_file_path = file_path;
|
_file_path = file_path;
|
||||||
if (_file_path.empty()) {
|
if (_file_path.empty()) {
|
||||||
|
@ -22,12 +22,10 @@ using namespace toolkit;
|
|||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
MP4Recorder::MP4Recorder(const string &path, const string &vhost, const string &app, const string &stream_id, size_t max_second) {
|
MP4Recorder::MP4Recorder(const MediaTuple &tuple, const string &path, size_t max_second) {
|
||||||
_folder_path = path;
|
_folder_path = path;
|
||||||
/////record 业务逻辑//////
|
/////record 业务逻辑//////
|
||||||
_info.app = app;
|
static_cast<MediaTuple &>(_info) = tuple;
|
||||||
_info.stream = stream_id;
|
|
||||||
_info.vhost = vhost;
|
|
||||||
_info.folder = path;
|
_info.folder = path;
|
||||||
GET_CONFIG(uint32_t, s_max_second, Protocol::kMP4MaxSecond);
|
GET_CONFIG(uint32_t, s_max_second, Protocol::kMP4MaxSecond);
|
||||||
_max_second = max_second ? max_second : s_max_second;
|
_max_second = max_second ? max_second : s_max_second;
|
||||||
@ -120,7 +118,7 @@ bool MP4Recorder::inputFrame(const Frame::Ptr &frame) {
|
|||||||
//b帧情况下dts时间戳可能回退
|
//b帧情况下dts时间戳可能回退
|
||||||
_last_dts = MAX(frame->dts(), _last_dts);
|
_last_dts = MAX(frame->dts(), _last_dts);
|
||||||
}
|
}
|
||||||
auto duration = 5; // 默认至少一帧5ms
|
auto duration = 5u; // 默认至少一帧5ms
|
||||||
if (frame->dts() > 0 && frame->dts() > _last_dts) {
|
if (frame->dts() > 0 && frame->dts() > _last_dts) {
|
||||||
duration = MAX(duration, frame->dts() - _last_dts);
|
duration = MAX(duration, frame->dts() - _last_dts);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ class MP4Recorder final : public MediaSinkInterface {
|
|||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<MP4Recorder>;
|
using Ptr = std::shared_ptr<MP4Recorder>;
|
||||||
|
|
||||||
MP4Recorder(const std::string &path, const std::string &vhost, const std::string &app, const std::string &stream_id, size_t max_second);
|
MP4Recorder(const MediaTuple &tuple, const std::string &path, size_t max_second);
|
||||||
~MP4Recorder() override;
|
~MP4Recorder() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,8 +68,7 @@ string Recorder::getRecordPath(Recorder::type type, const MediaTuple& tuple, con
|
|||||||
}
|
}
|
||||||
return File::absolutePath(m3u8FilePath, hlsPath);
|
return File::absolutePath(m3u8FilePath, hlsPath);
|
||||||
}
|
}
|
||||||
default:
|
default: return "";
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,13 +84,12 @@ std::shared_ptr<MediaSinkInterface> Recorder::createRecorder(type type, const Me
|
|||||||
#else
|
#else
|
||||||
throw std::invalid_argument("hls相关功能未打开,请开启ENABLE_HLS宏后编译再测试");
|
throw std::invalid_argument("hls相关功能未打开,请开启ENABLE_HLS宏后编译再测试");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case Recorder::type_mp4: {
|
case Recorder::type_mp4: {
|
||||||
#if defined(ENABLE_MP4)
|
#if defined(ENABLE_MP4)
|
||||||
auto path = Recorder::getRecordPath(type, tuple, option.mp4_save_path);
|
auto path = Recorder::getRecordPath(type, tuple, option.mp4_save_path);
|
||||||
return std::make_shared<MP4Recorder>(path, tuple.vhost, tuple.app, tuple.stream, option.mp4_max_second);
|
return std::make_shared<MP4Recorder>(tuple, path, option.mp4_max_second);
|
||||||
#else
|
#else
|
||||||
throw std::invalid_argument("mp4相关功能未打开,请开启ENABLE_MP4宏后编译再测试");
|
throw std::invalid_argument("mp4相关功能未打开,请开启ENABLE_MP4宏后编译再测试");
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,6 +22,7 @@ struct MediaTuple {
|
|||||||
std::string vhost;
|
std::string vhost;
|
||||||
std::string app;
|
std::string app;
|
||||||
std::string stream;
|
std::string stream;
|
||||||
|
std::string params;
|
||||||
std::string shortUrl() const {
|
std::string shortUrl() const {
|
||||||
return vhost + '/' + app + '/' + stream;
|
return vhost + '/' + app + '/' + stream;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,13 @@ public:
|
|||||||
getRtmpRing()->setDelegate(_media_src);
|
getRtmpRing()->setDelegate(_media_src);
|
||||||
}
|
}
|
||||||
|
|
||||||
~RtmpMediaSourceMuxer() override { RtmpMuxer::flush(); }
|
~RtmpMediaSourceMuxer() override {
|
||||||
|
try {
|
||||||
|
RtmpMuxer::flush();
|
||||||
|
} catch (std::exception &ex) {
|
||||||
|
WarnL << ex.what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setListener(const std::weak_ptr<MediaSourceEvent> &listener){
|
void setListener(const std::weak_ptr<MediaSourceEvent> &listener){
|
||||||
setDelegate(listener);
|
setDelegate(listener);
|
||||||
|
@ -165,14 +165,7 @@ void RtmpProtocol::sendResponse(int type, const string &str) {
|
|||||||
|
|
||||||
void RtmpProtocol::sendInvoke(const string &cmd, const AMFValue &val) {
|
void RtmpProtocol::sendInvoke(const string &cmd, const AMFValue &val) {
|
||||||
AMFEncoder enc;
|
AMFEncoder enc;
|
||||||
if (val.type() == AMFType::AMF_OBJECT || val.type() == AMFType::AMF_NULL)
|
|
||||||
{
|
|
||||||
enc << cmd << ++_send_req_id << val;
|
enc << cmd << ++_send_req_id << val;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
enc << cmd << ++_send_req_id << AMFValue() << val;
|
|
||||||
}
|
|
||||||
sendRequest(MSG_CMD, enc.data());
|
sendRequest(MSG_CMD, enc.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,6 +625,7 @@ const char* RtmpProtocol::handle_rtmp(const char *data, size_t len) {
|
|||||||
case 4:
|
case 4:
|
||||||
chunk_data.ts_field = load_be24(header->time_stamp);
|
chunk_data.ts_field = load_be24(header->time_stamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto time_stamp = chunk_data.ts_field;
|
auto time_stamp = chunk_data.ts_field;
|
||||||
if (chunk_data.ts_field == 0xFFFFFF) {
|
if (chunk_data.ts_field == 0xFFFFFF) {
|
||||||
if (len < header_len + offset + 4) {
|
if (len < header_len + offset + 4) {
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#ifndef SRC_RTMP_RTMPPROTOCOL_H_
|
#ifndef SRC_RTMP_RTMPPROTOCOL_H_
|
||||||
#define SRC_RTMP_RTMPPROTOCOL_H_
|
#define SRC_RTMP_RTMPPROTOCOL_H_
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -163,18 +163,6 @@ void RtmpPusher::send_connect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RtmpPusher::send_createStream() {
|
void RtmpPusher::send_createStream() {
|
||||||
// Workaround : 兼容较旧的 FMS3.0
|
|
||||||
{
|
|
||||||
{
|
|
||||||
AMFValue obj(_stream_id);
|
|
||||||
sendInvoke("releaseStream", obj);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
AMFValue obj(_stream_id);
|
|
||||||
sendInvoke("FCPublish", obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
AMFValue obj(AMF_NULL);
|
AMFValue obj(AMF_NULL);
|
||||||
sendInvoke("createStream", obj);
|
sendInvoke("createStream", obj);
|
||||||
addOnResultCB([this](AMFDecoder &dec) {
|
addOnResultCB([this](AMFDecoder &dec) {
|
||||||
@ -185,8 +173,6 @@ void RtmpPusher::send_createStream() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#define RTMP_STREAM_LIVE "live"
|
#define RTMP_STREAM_LIVE "live"
|
||||||
void RtmpPusher::send_publish() {
|
void RtmpPusher::send_publish() {
|
||||||
AMFEncoder enc;
|
AMFEncoder enc;
|
||||||
|
@ -63,8 +63,8 @@ void SrtTransportImp::onHandShakeFinished(std::string &streamid, struct sockaddr
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto params = Parser::parseArgs(_media_info.param_strs);
|
auto kv = Parser::parseArgs(_media_info.params);
|
||||||
if (params["m"] == "publish") {
|
if (kv["m"] == "publish") {
|
||||||
_is_pusher = true;
|
_is_pusher = true;
|
||||||
_decoder = DecoderImp::createDecoder(DecoderImp::decoder_ts, this);
|
_decoder = DecoderImp::createDecoder(DecoderImp::decoder_ts, this);
|
||||||
emitOnPublish();
|
emitOnPublish();
|
||||||
@ -98,10 +98,10 @@ bool SrtTransportImp::parseStreamid(std::string &streamid) {
|
|||||||
app = tmps[0];
|
app = tmps[0];
|
||||||
stream_name = tmps[1];
|
stream_name = tmps[1];
|
||||||
} else {
|
} else {
|
||||||
if (_media_info.param_strs.empty()) {
|
if (_media_info.params.empty()) {
|
||||||
_media_info.param_strs = it.first + "=" + it.second;
|
_media_info.params = it.first + "=" + it.second;
|
||||||
} else {
|
} else {
|
||||||
_media_info.param_strs += "&" + it.first + "=" + it.second;
|
_media_info.params += "&" + it.first + "=" + it.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ bool SrtTransportImp::parseStreamid(std::string &streamid) {
|
|||||||
_media_info.app = app;
|
_media_info.app = app;
|
||||||
_media_info.stream = stream_name;
|
_media_info.stream = stream_name;
|
||||||
|
|
||||||
TraceL << " mediainfo=" << _media_info.shortUrl() << " params=" << _media_info.param_strs;
|
TraceL << " mediainfo=" << _media_info.shortUrl() << " params=" << _media_info.params;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ using namespace mediakit;
|
|||||||
class FlvSplitterImp : public FlvSplitter {
|
class FlvSplitterImp : public FlvSplitter {
|
||||||
public:
|
public:
|
||||||
FlvSplitterImp() {
|
FlvSplitterImp() {
|
||||||
_src = std::make_shared<RtmpMediaSourceImp>(MediaTuple{DEFAULT_VHOST, "live", "test"});
|
_src = std::make_shared<RtmpMediaSourceImp>(MediaTuple{DEFAULT_VHOST, "live", "test", ""});
|
||||||
}
|
}
|
||||||
~FlvSplitterImp() override = default;
|
~FlvSplitterImp() override = default;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ void initEventListener() {
|
|||||||
static onceToken s_token([]() {
|
static onceToken s_token([]() {
|
||||||
//监听kBroadcastOnGetRtspRealm事件决定rtsp链接是否需要鉴权(传统的rtsp鉴权方案)才能访问
|
//监听kBroadcastOnGetRtspRealm事件决定rtsp链接是否需要鉴权(传统的rtsp鉴权方案)才能访问
|
||||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastOnGetRtspRealm, [](BroadcastOnGetRtspRealmArgs) {
|
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastOnGetRtspRealm, [](BroadcastOnGetRtspRealmArgs) {
|
||||||
DebugL << "RTSP是否需要鉴权事件:" << args.getUrl() << " " << args.param_strs;
|
DebugL << "RTSP是否需要鉴权事件:" << args.getUrl() << " " << args.params;
|
||||||
if (string("1") == args.stream) {
|
if (string("1") == args.stream) {
|
||||||
// live/1需要认证
|
// live/1需要认证
|
||||||
//该流需要认证,并且设置realm
|
//该流需要认证,并且设置realm
|
||||||
@ -104,7 +104,7 @@ void initEventListener() {
|
|||||||
|
|
||||||
//监听kBroadcastOnRtspAuth事件返回正确的rtsp鉴权用户密码
|
//监听kBroadcastOnRtspAuth事件返回正确的rtsp鉴权用户密码
|
||||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastOnRtspAuth, [](BroadcastOnRtspAuthArgs) {
|
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastOnRtspAuth, [](BroadcastOnRtspAuthArgs) {
|
||||||
DebugL << "RTSP播放鉴权:" << args.getUrl() << " " << args.param_strs;
|
DebugL << "RTSP播放鉴权:" << args.getUrl() << " " << args.params;
|
||||||
DebugL << "RTSP用户:" << user_name << (must_no_encrypt ? " Base64" : " MD5") << " 方式登录";
|
DebugL << "RTSP用户:" << user_name << (must_no_encrypt ? " Base64" : " MD5") << " 方式登录";
|
||||||
string user = user_name;
|
string user = user_name;
|
||||||
//假设我们异步读取数据库
|
//假设我们异步读取数据库
|
||||||
@ -134,14 +134,14 @@ void initEventListener() {
|
|||||||
|
|
||||||
//监听rtsp/rtmp推流事件,返回结果告知是否有推流权限
|
//监听rtsp/rtmp推流事件,返回结果告知是否有推流权限
|
||||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastMediaPublish, [](BroadcastMediaPublishArgs) {
|
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastMediaPublish, [](BroadcastMediaPublishArgs) {
|
||||||
DebugL << "推流鉴权:" << args.getUrl() << " " << args.param_strs;
|
DebugL << "推流鉴权:" << args.getUrl() << " " << args.params;
|
||||||
invoker("", ProtocolOption());//鉴权成功
|
invoker("", ProtocolOption());//鉴权成功
|
||||||
//invoker("this is auth failed message");//鉴权失败
|
//invoker("this is auth failed message");//鉴权失败
|
||||||
});
|
});
|
||||||
|
|
||||||
//监听rtsp/rtsps/rtmp/http-flv播放事件,返回结果告知是否有播放权限(rtsp通过kBroadcastOnRtspAuth或此事件都可以实现鉴权)
|
//监听rtsp/rtsps/rtmp/http-flv播放事件,返回结果告知是否有播放权限(rtsp通过kBroadcastOnRtspAuth或此事件都可以实现鉴权)
|
||||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastMediaPlayed, [](BroadcastMediaPlayedArgs) {
|
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastMediaPlayed, [](BroadcastMediaPlayedArgs) {
|
||||||
DebugL << "播放鉴权:" << args.getUrl() << " " << args.param_strs;
|
DebugL << "播放鉴权:" << args.getUrl() << " " << args.params;
|
||||||
invoker("");//鉴权成功
|
invoker("");//鉴权成功
|
||||||
//invoker("this is auth failed message");//鉴权失败
|
//invoker("this is auth failed message");//鉴权失败
|
||||||
});
|
});
|
||||||
@ -183,13 +183,13 @@ void initEventListener() {
|
|||||||
* 你可以在这个事件触发时再去拉流,这样就可以实现按需拉流
|
* 你可以在这个事件触发时再去拉流,这样就可以实现按需拉流
|
||||||
* 拉流成功后,ZLMediaKit会把其立即转发给播放器(最大等待时间约为5秒,如果5秒都未拉流成功,播放器会播放失败)
|
* 拉流成功后,ZLMediaKit会把其立即转发给播放器(最大等待时间约为5秒,如果5秒都未拉流成功,播放器会播放失败)
|
||||||
*/
|
*/
|
||||||
DebugL << "未找到流事件:" << args.getUrl() << " " << args.param_strs;
|
DebugL << "未找到流事件:" << args.getUrl() << " " << args.params;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//监听播放或推流结束时消耗流量事件
|
//监听播放或推流结束时消耗流量事件
|
||||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastFlowReport, [](BroadcastFlowReportArgs) {
|
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastFlowReport, [](BroadcastFlowReportArgs) {
|
||||||
DebugL << "播放器(推流器)断开连接事件:" << args.getUrl() << " " << args.param_strs << "\r\n使用流量:" << totalBytes << " bytes,连接时长:" << totalDuration << "秒";
|
DebugL << "播放器(推流器)断开连接事件:" << args.getUrl() << " " << args.params << "\r\n使用流量:" << totalBytes << " bytes,连接时长:" << totalDuration << "秒";
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,10 +23,10 @@ namespace Rtc {
|
|||||||
const string kPreferredCodecA = RTC_FIELD "preferredCodecA";
|
const string kPreferredCodecA = RTC_FIELD "preferredCodecA";
|
||||||
const string kPreferredCodecV = RTC_FIELD "preferredCodecV";
|
const string kPreferredCodecV = RTC_FIELD "preferredCodecV";
|
||||||
static onceToken token([]() {
|
static onceToken token([]() {
|
||||||
mINI::Instance()[kPreferredCodecA] = "PCMU,PCMA,opus,mpeg4-generic";
|
mINI::Instance()[kPreferredCodecA] = "PCMA,PCMU,opus,mpeg4-generic";
|
||||||
mINI::Instance()[kPreferredCodecV] = "H264,H265,AV1,VP9,VP8";
|
mINI::Instance()[kPreferredCodecV] = "H264,H265,AV1,VP9,VP8";
|
||||||
});
|
});
|
||||||
}
|
} // namespace Rtc
|
||||||
|
|
||||||
using onCreateSdpItem = function<SdpItem::Ptr(const string &key, const string &value)>;
|
using onCreateSdpItem = function<SdpItem::Ptr(const string &key, const string &value)>;
|
||||||
static map<string, onCreateSdpItem, StrCaseCompare> sdpItemCreator;
|
static map<string, onCreateSdpItem, StrCaseCompare> sdpItemCreator;
|
||||||
@ -73,9 +73,7 @@ public:
|
|||||||
|
|
||||||
class DirectionInterfaceImp : public SdpItem, public DirectionInterface {
|
class DirectionInterfaceImp : public SdpItem, public DirectionInterface {
|
||||||
public:
|
public:
|
||||||
DirectionInterfaceImp(RtpDirection direct){
|
DirectionInterfaceImp(RtpDirection direct) { direction = direct; }
|
||||||
direction = direct;
|
|
||||||
}
|
|
||||||
const char *getKey() const override { return getRtpDirectionString(getDirection()); }
|
const char *getKey() const override { return getRtpDirectionString(getDirection()); }
|
||||||
RtpDirection getDirection() const override { return direction; }
|
RtpDirection getDirection() const override { return direction; }
|
||||||
|
|
||||||
@ -717,8 +715,7 @@ void SdpAttrCandidate::parse(const string &str) {
|
|||||||
|
|
||||||
string SdpAttrCandidate::toString() const {
|
string SdpAttrCandidate::toString() const {
|
||||||
if (value.empty()) {
|
if (value.empty()) {
|
||||||
value = foundation + " " + to_string(component) + " " + transport + " " + to_string(priority) +
|
value = foundation + " " + to_string(component) + " " + transport + " " + to_string(priority) + " " + address + " " + to_string(port) + " typ " + type;
|
||||||
" " + address + " " + to_string(port) + " typ " + type;
|
|
||||||
for (auto &pr : arr) {
|
for (auto &pr : arr) {
|
||||||
value += ' ';
|
value += ' ';
|
||||||
value += pr.first;
|
value += pr.first;
|
||||||
@ -952,8 +949,7 @@ void RtcSession::loadFrom(const string &str) {
|
|||||||
if (fmtp_it != fmtp_map.end()) {
|
if (fmtp_it != fmtp_map.end()) {
|
||||||
plan.fmtp = fmtp_it->second.fmtp;
|
plan.fmtp = fmtp_it->second.fmtp;
|
||||||
}
|
}
|
||||||
for (auto rtpfb_it = rtcpfb_map.find(pt);
|
for (auto rtpfb_it = rtcpfb_map.find(pt); rtpfb_it != rtcpfb_map.end() && rtpfb_it->second.pt == pt; ++rtpfb_it) {
|
||||||
rtpfb_it != rtcpfb_map.end() && rtpfb_it->second.pt == pt; ++rtpfb_it) {
|
|
||||||
plan.rtcp_fb.emplace(rtpfb_it->second.rtcp_type);
|
plan.rtcp_fb.emplace(rtpfb_it->second.rtcp_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -986,8 +982,7 @@ void RtcSdpBase::toRtsp() {
|
|||||||
case 'a': {
|
case 'a': {
|
||||||
auto attr = dynamic_pointer_cast<SdpAttr>(*it);
|
auto attr = dynamic_pointer_cast<SdpAttr>(*it);
|
||||||
CHECK(attr);
|
CHECK(attr);
|
||||||
if (!strcasecmp(attr->detail->getKey(), "rtpmap")
|
if (!strcasecmp(attr->detail->getKey(), "rtpmap") || !strcasecmp(attr->detail->getKey(), "fmtp")) {
|
||||||
|| !strcasecmp(attr->detail->getKey(), "fmtp")) {
|
|
||||||
++it;
|
++it;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1221,9 +1216,9 @@ RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(ice_lite)
|
if (ice_lite) {
|
||||||
sdp.addAttr(std::make_shared<SdpCommon>("ice-lite"));
|
sdp.addAttr(std::make_shared<SdpCommon>("ice-lite"));
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1427,16 +1422,14 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
|
|||||||
preferred_codec = s_preferred_codec;
|
preferred_codec = s_preferred_codec;
|
||||||
|
|
||||||
rtcp_fb = { SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb };
|
rtcp_fb = { SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb };
|
||||||
extmap = {
|
extmap = { { RtpExtType::ssrc_audio_level, RtpDirection::sendrecv },
|
||||||
{RtpExtType::ssrc_audio_level, RtpDirection::sendrecv},
|
|
||||||
{ RtpExtType::csrc_audio_level, RtpDirection::sendrecv },
|
{ RtpExtType::csrc_audio_level, RtpDirection::sendrecv },
|
||||||
{ RtpExtType::abs_send_time, RtpDirection::sendrecv },
|
{ RtpExtType::abs_send_time, RtpDirection::sendrecv },
|
||||||
{ RtpExtType::transport_cc, RtpDirection::sendrecv },
|
{ RtpExtType::transport_cc, RtpDirection::sendrecv },
|
||||||
// rtx重传rtp时,忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时,如果存在sdes_mid的ext,将导致无法播放
|
// rtx重传rtp时,忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时,如果存在sdes_mid的ext,将导致无法播放
|
||||||
//{RtpExtType::sdes_mid,RtpDirection::sendrecv},
|
//{RtpExtType::sdes_mid,RtpDirection::sendrecv},
|
||||||
{ RtpExtType::sdes_rtp_stream_id, RtpDirection::sendrecv },
|
{ RtpExtType::sdes_rtp_stream_id, RtpDirection::sendrecv },
|
||||||
{RtpExtType::sdes_repaired_rtp_stream_id, RtpDirection::sendrecv}
|
{ RtpExtType::sdes_repaired_rtp_stream_id, RtpDirection::sendrecv } };
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TrackVideo: {
|
case TrackVideo: {
|
||||||
@ -1446,8 +1439,7 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
|
|||||||
preferred_codec = s_preferred_codec;
|
preferred_codec = s_preferred_codec;
|
||||||
|
|
||||||
rtcp_fb = { SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb, "nack", "ccm fir", "nack pli" };
|
rtcp_fb = { SdpConst::kTWCCRtcpFb, SdpConst::kRembRtcpFb, "nack", "ccm fir", "nack pli" };
|
||||||
extmap = {
|
extmap = { { RtpExtType::abs_send_time, RtpDirection::sendrecv },
|
||||||
{RtpExtType::abs_send_time, RtpDirection::sendrecv},
|
|
||||||
{ RtpExtType::transport_cc, RtpDirection::sendrecv },
|
{ RtpExtType::transport_cc, RtpDirection::sendrecv },
|
||||||
// rtx重传rtp时,忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时,如果存在sdes_mid的ext,将导致无法播放
|
// rtx重传rtp时,忽略sdes_mid类型的rtp ext,实测发现Firefox在接收rtx时,如果存在sdes_mid的ext,将导致无法播放
|
||||||
//{RtpExtType::sdes_mid,RtpDirection::sendrecv},
|
//{RtpExtType::sdes_mid,RtpDirection::sendrecv},
|
||||||
@ -1460,8 +1452,7 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
|
|||||||
// 手机端推webrtc 会带有旋转角度,rtc协议能正常播放 其他协议拉流画面旋转
|
// 手机端推webrtc 会带有旋转角度,rtc协议能正常播放 其他协议拉流画面旋转
|
||||||
//{RtpExtType::video_orientation, RtpDirection::sendrecv},
|
//{RtpExtType::video_orientation, RtpDirection::sendrecv},
|
||||||
{ RtpExtType::toffset, RtpDirection::sendrecv },
|
{ RtpExtType::toffset, RtpDirection::sendrecv },
|
||||||
{RtpExtType::framemarking, RtpDirection::sendrecv}
|
{ RtpExtType::framemarking, RtpDirection::sendrecv } };
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TrackApplication: {
|
case TrackApplication: {
|
||||||
@ -1471,8 +1462,7 @@ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtcConfigure::setDefaultSetting(string ice_ufrag, string ice_pwd, RtpDirection direction,
|
void RtcConfigure::setDefaultSetting(string ice_ufrag, string ice_pwd, RtpDirection direction, const SdpAttrFingerprint &fingerprint) {
|
||||||
const SdpAttrFingerprint &fingerprint) {
|
|
||||||
video.setDefaultSetting(TrackVideo);
|
video.setDefaultSetting(TrackVideo);
|
||||||
audio.setDefaultSetting(TrackAudio);
|
audio.setDefaultSetting(TrackAudio);
|
||||||
application.setDefaultSetting(TrackApplication);
|
application.setDefaultSetting(TrackApplication);
|
||||||
@ -1683,8 +1673,7 @@ RETRY:
|
|||||||
answer_media.role = mathDtlsRole(offer_media.role);
|
answer_media.role = mathDtlsRole(offer_media.role);
|
||||||
|
|
||||||
// 如果codec匹配失败,那么禁用该track
|
// 如果codec匹配失败,那么禁用该track
|
||||||
answer_media.direction = check_codec ? matchDirection(offer_media.direction, configure.direction)
|
answer_media.direction = check_codec ? matchDirection(offer_media.direction, configure.direction) : RtpDirection::inactive;
|
||||||
: RtpDirection::inactive;
|
|
||||||
if (answer_media.direction == RtpDirection::invalid) {
|
if (answer_media.direction == RtpDirection::invalid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
35
webrtc/Sdp.h
35
webrtc/Sdp.h
@ -77,11 +77,7 @@ enum class DtlsRole {
|
|||||||
actpass,
|
actpass,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SdpType {
|
enum class SdpType { invalid = -1, offer, answer };
|
||||||
invalid = -1,
|
|
||||||
offer,
|
|
||||||
answer
|
|
||||||
};
|
|
||||||
|
|
||||||
DtlsRole getDtlsRole(const std::string &str);
|
DtlsRole getDtlsRole(const std::string &str);
|
||||||
const char *getDtlsRoleString(DtlsRole role);
|
const char *getDtlsRoleString(DtlsRole role);
|
||||||
@ -92,17 +88,11 @@ class SdpItem {
|
|||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<SdpItem>;
|
using Ptr = std::shared_ptr<SdpItem>;
|
||||||
virtual ~SdpItem() = default;
|
virtual ~SdpItem() = default;
|
||||||
virtual void parse(const std::string &str) {
|
virtual void parse(const std::string &str) { value = str; }
|
||||||
value = str;
|
virtual std::string toString() const { return value; }
|
||||||
}
|
|
||||||
virtual std::string toString() const {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
virtual const char *getKey() const = 0;
|
virtual const char *getKey() const = 0;
|
||||||
|
|
||||||
void reset() {
|
void reset() { value.clear(); }
|
||||||
value.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mutable std::string value;
|
mutable std::string value;
|
||||||
@ -259,9 +249,7 @@ public:
|
|||||||
void parse(const std::string &str) override;
|
void parse(const std::string &str) override;
|
||||||
std::string toString() const override;
|
std::string toString() const override;
|
||||||
const char *getKey() const override { return "msid-semantic"; }
|
const char *getKey() const override { return "msid-semantic"; }
|
||||||
bool empty() const {
|
bool empty() const { return msid.empty(); }
|
||||||
return msid.empty();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SdpAttrRtcp : public SdpItem {
|
class SdpAttrRtcp : public SdpItem {
|
||||||
@ -271,12 +259,11 @@ public:
|
|||||||
std::string nettype { "IN" };
|
std::string nettype { "IN" };
|
||||||
std::string addrtype { "IP4" };
|
std::string addrtype { "IP4" };
|
||||||
std::string address { "0.0.0.0" };
|
std::string address { "0.0.0.0" };
|
||||||
void parse(const std::string &str) override;;
|
void parse(const std::string &str) override;
|
||||||
|
;
|
||||||
std::string toString() const override;
|
std::string toString() const override;
|
||||||
const char *getKey() const override { return "rtcp"; }
|
const char *getKey() const override { return "rtcp"; }
|
||||||
bool empty() const {
|
bool empty() const { return address.empty() || !port; }
|
||||||
return address.empty() || !port;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SdpAttrIceUfrag : public SdpItem {
|
class SdpAttrIceUfrag : public SdpItem {
|
||||||
@ -364,9 +351,9 @@ public:
|
|||||||
// a=rtcp-fb:98 nack pli
|
// a=rtcp-fb:98 nack pli
|
||||||
// a=rtcp-fb:120 nack 支持 nack 重传,nack (Negative-Acknowledgment) 。
|
// a=rtcp-fb:120 nack 支持 nack 重传,nack (Negative-Acknowledgment) 。
|
||||||
// a=rtcp-fb:120 nack pli 支持 nack 关键帧重传,PLI (Picture Loss Indication) 。
|
// a=rtcp-fb:120 nack pli 支持 nack 关键帧重传,PLI (Picture Loss Indication) 。
|
||||||
//a=rtcp-fb:120 ccm fir 支持编码层关键帧请求,CCM (Codec Control Message),FIR (Full Intra Request ),通常与 nack pli 有同样的效果,但是 nack pli 是用于重传时的关键帧请求。
|
// a=rtcp-fb:120 ccm fir 支持编码层关键帧请求,CCM (Codec Control Message),FIR (Full Intra Request ),通常与 nack pli 有同样的效果,但是 nack pli
|
||||||
//a=rtcp-fb:120 goog-remb 支持 REMB (Receiver Estimated Maximum Bitrate) 。
|
// 是用于重传时的关键帧请求。 a=rtcp-fb:120 goog-remb 支持 REMB (Receiver Estimated Maximum Bitrate) 。 a=rtcp-fb:120 transport-cc 支持 TCC (Transport
|
||||||
//a=rtcp-fb:120 transport-cc 支持 TCC (Transport Congest Control) 。
|
// Congest Control) 。
|
||||||
uint8_t pt;
|
uint8_t pt;
|
||||||
std::string rtcp_type;
|
std::string rtcp_type;
|
||||||
void parse(const std::string &str) override;
|
void parse(const std::string &str) override;
|
||||||
|
@ -45,7 +45,7 @@ void WebRtcEchoTest::onCheckSdp(SdpType type, RtcSession &sdp) {
|
|||||||
for (auto &m : sdp.media) {
|
for (auto &m : sdp.media) {
|
||||||
for (auto &ssrc : m.rtp_rtx_ssrc) {
|
for (auto &ssrc : m.rtp_rtx_ssrc) {
|
||||||
if (!ssrc.msid.empty()) {
|
if (!ssrc.msid.empty()) {
|
||||||
ssrc.msid = "zlmediakit msid";
|
ssrc.msid = "zlmediakit-mslabel zlmediakit-label-" + m.mid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ protected:
|
|||||||
void onRtp(const char *buf, size_t len, uint64_t stamp_ms) override;
|
void onRtp(const char *buf, size_t len, uint64_t stamp_ms) override;
|
||||||
void onRtcp(const char *buf, size_t len) override;
|
void onRtcp(const char *buf, size_t len) override;
|
||||||
|
|
||||||
void onRecvRtp(MediaTrack &track, const std::string &rid, RtpPacket::Ptr rtp) override {};
|
|
||||||
void onBeforeEncryptRtp(const char *buf, int &len, void *ctx) override {};
|
void onBeforeEncryptRtp(const char *buf, int &len, void *ctx) override {};
|
||||||
void onBeforeEncryptRtcp(const char *buf, int &len, void *ctx) override {};
|
void onBeforeEncryptRtcp(const char *buf, int &len, void *ctx) override {};
|
||||||
|
|
||||||
|
@ -17,9 +17,8 @@ namespace mediakit {
|
|||||||
|
|
||||||
WebRtcPlayer::Ptr WebRtcPlayer::create(const EventPoller::Ptr &poller,
|
WebRtcPlayer::Ptr WebRtcPlayer::create(const EventPoller::Ptr &poller,
|
||||||
const RtspMediaSource::Ptr &src,
|
const RtspMediaSource::Ptr &src,
|
||||||
const MediaInfo &info,
|
const MediaInfo &info) {
|
||||||
bool preferred_tcp) {
|
WebRtcPlayer::Ptr ret(new WebRtcPlayer(poller, src, info), [](WebRtcPlayer *ptr) {
|
||||||
WebRtcPlayer::Ptr ret(new WebRtcPlayer(poller, src, info, preferred_tcp), [](WebRtcPlayer *ptr) {
|
|
||||||
ptr->onDestory();
|
ptr->onDestory();
|
||||||
delete ptr;
|
delete ptr;
|
||||||
});
|
});
|
||||||
@ -29,8 +28,7 @@ WebRtcPlayer::Ptr WebRtcPlayer::create(const EventPoller::Ptr &poller,
|
|||||||
|
|
||||||
WebRtcPlayer::WebRtcPlayer(const EventPoller::Ptr &poller,
|
WebRtcPlayer::WebRtcPlayer(const EventPoller::Ptr &poller,
|
||||||
const RtspMediaSource::Ptr &src,
|
const RtspMediaSource::Ptr &src,
|
||||||
const MediaInfo &info,
|
const MediaInfo &info) : WebRtcTransportImp(poller) {
|
||||||
bool preferred_tcp) : WebRtcTransportImp(poller,preferred_tcp) {
|
|
||||||
_media_info = info;
|
_media_info = info;
|
||||||
_play_src = src;
|
_play_src = src;
|
||||||
CHECK(src);
|
CHECK(src);
|
||||||
|
@ -19,7 +19,7 @@ namespace mediakit {
|
|||||||
class WebRtcPlayer : public WebRtcTransportImp {
|
class WebRtcPlayer : public WebRtcTransportImp {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<WebRtcPlayer>;
|
using Ptr = std::shared_ptr<WebRtcPlayer>;
|
||||||
static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info, bool preferred_tcp = false);
|
static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info);
|
||||||
MediaInfo getMediaInfo() { return _media_info; }
|
MediaInfo getMediaInfo() { return _media_info; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -27,10 +27,9 @@ protected:
|
|||||||
void onStartWebRTC() override;
|
void onStartWebRTC() override;
|
||||||
void onDestory() override;
|
void onDestory() override;
|
||||||
void onRtcConfigure(RtcConfigure &configure) const override;
|
void onRtcConfigure(RtcConfigure &configure) const override;
|
||||||
void onRecvRtp(MediaTrack &track, const std::string &rid, RtpPacket::Ptr rtp) override {};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebRtcPlayer(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info, bool preferred_tcp);
|
WebRtcPlayer(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//媒体相关元数据
|
//媒体相关元数据
|
||||||
|
@ -20,9 +20,8 @@ WebRtcPusher::Ptr WebRtcPusher::create(const EventPoller::Ptr &poller,
|
|||||||
const RtspMediaSource::Ptr &src,
|
const RtspMediaSource::Ptr &src,
|
||||||
const std::shared_ptr<void> &ownership,
|
const std::shared_ptr<void> &ownership,
|
||||||
const MediaInfo &info,
|
const MediaInfo &info,
|
||||||
const ProtocolOption &option,
|
const ProtocolOption &option) {
|
||||||
bool preferred_tcp) {
|
WebRtcPusher::Ptr ret(new WebRtcPusher(poller, src, ownership, info, option), [](WebRtcPusher *ptr) {
|
||||||
WebRtcPusher::Ptr ret(new WebRtcPusher(poller, src, ownership, info, option,preferred_tcp), [](WebRtcPusher *ptr) {
|
|
||||||
ptr->onDestory();
|
ptr->onDestory();
|
||||||
delete ptr;
|
delete ptr;
|
||||||
});
|
});
|
||||||
@ -34,8 +33,7 @@ WebRtcPusher::WebRtcPusher(const EventPoller::Ptr &poller,
|
|||||||
const RtspMediaSource::Ptr &src,
|
const RtspMediaSource::Ptr &src,
|
||||||
const std::shared_ptr<void> &ownership,
|
const std::shared_ptr<void> &ownership,
|
||||||
const MediaInfo &info,
|
const MediaInfo &info,
|
||||||
const ProtocolOption &option,
|
const ProtocolOption &option) : WebRtcTransportImp(poller) {
|
||||||
bool preferred_tcp) : WebRtcTransportImp(poller,preferred_tcp) {
|
|
||||||
_media_info = info;
|
_media_info = info;
|
||||||
_push_src = src;
|
_push_src = src;
|
||||||
_push_src_ownership = ownership;
|
_push_src_ownership = ownership;
|
||||||
|
@ -20,8 +20,7 @@ class WebRtcPusher : public WebRtcTransportImp, public MediaSourceEvent {
|
|||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<WebRtcPusher>;
|
using Ptr = std::shared_ptr<WebRtcPusher>;
|
||||||
static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src,
|
static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src,
|
||||||
const std::shared_ptr<void> &ownership, const MediaInfo &info, const ProtocolOption &option, bool preferred_tcp = false);
|
const std::shared_ptr<void> &ownership, const MediaInfo &info, const ProtocolOption &option);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///////WebRtcTransportImp override///////
|
///////WebRtcTransportImp override///////
|
||||||
@ -53,7 +52,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
WebRtcPusher(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src,
|
WebRtcPusher(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src,
|
||||||
const std::shared_ptr<void> &ownership, const MediaInfo &info, const ProtocolOption &option, bool preferred_tcp);
|
const std::shared_ptr<void> &ownership, const MediaInfo &info, const ProtocolOption &option);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _simulcast = false;
|
bool _simulcast = false;
|
||||||
|
@ -378,6 +378,12 @@ void WebRtcTransport::setRemoteDtlsFingerprint(const RtcSession &remote) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcTransport::onRtcConfigure(RtcConfigure &configure) const {
|
void WebRtcTransport::onRtcConfigure(RtcConfigure &configure) const {
|
||||||
|
SdpAttrFingerprint fingerprint;
|
||||||
|
fingerprint.algorithm = _offer_sdp->media[0].fingerprint.algorithm;
|
||||||
|
fingerprint.hash = getFingerprint(fingerprint.algorithm, _dtls_transport);
|
||||||
|
configure.setDefaultSetting(
|
||||||
|
_ice_server->GetUsernameFragment(), _ice_server->GetPassword(), RtpDirection::sendrecv, fingerprint);
|
||||||
|
|
||||||
// 开启remb后关闭twcc,因为开启twcc后remb无效
|
// 开启remb后关闭twcc,因为开启twcc后remb无效
|
||||||
GET_CONFIG(size_t, remb_bit_rate, Rtc::kRembBitRate);
|
GET_CONFIG(size_t, remb_bit_rate, Rtc::kRembBitRate);
|
||||||
configure.enableTWCC(!remb_bit_rate);
|
configure.enableTWCC(!remb_bit_rate);
|
||||||
@ -407,12 +413,7 @@ std::string WebRtcTransport::getAnswerSdp(const string &offer) {
|
|||||||
setRemoteDtlsFingerprint(*_offer_sdp);
|
setRemoteDtlsFingerprint(*_offer_sdp);
|
||||||
|
|
||||||
//// sdp 配置 ////
|
//// sdp 配置 ////
|
||||||
SdpAttrFingerprint fingerprint;
|
|
||||||
fingerprint.algorithm = _offer_sdp->media[0].fingerprint.algorithm;
|
|
||||||
fingerprint.hash = getFingerprint(fingerprint.algorithm, _dtls_transport);
|
|
||||||
RtcConfigure configure;
|
RtcConfigure configure;
|
||||||
configure.setDefaultSetting(
|
|
||||||
_ice_server->GetUsernameFragment(), _ice_server->GetPassword(), RtpDirection::sendrecv, fingerprint);
|
|
||||||
onRtcConfigure(configure);
|
onRtcConfigure(configure);
|
||||||
|
|
||||||
//// 生成answer sdp ////
|
//// 生成answer sdp ////
|
||||||
@ -431,10 +432,6 @@ static bool isDtls(char *buf) {
|
|||||||
return ((*buf > 19) && (*buf < 64));
|
return ((*buf > 19) && (*buf < 64));
|
||||||
}
|
}
|
||||||
|
|
||||||
static string getPeerAddress(RTC::TransportTuple *tuple) {
|
|
||||||
return tuple->get_peer_ip();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tuple) {
|
void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tuple) {
|
||||||
if (RTC::StunPacket::IsStun((const uint8_t *)buf, len)) {
|
if (RTC::StunPacket::IsStun((const uint8_t *)buf, len)) {
|
||||||
std::unique_ptr<RTC::StunPacket> packet(RTC::StunPacket::Parse((const uint8_t *)buf, len));
|
std::unique_ptr<RTC::StunPacket> packet(RTC::StunPacket::Parse((const uint8_t *)buf, len));
|
||||||
@ -451,7 +448,7 @@ void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tup
|
|||||||
}
|
}
|
||||||
if (isRtp(buf, len)) {
|
if (isRtp(buf, len)) {
|
||||||
if (!_srtp_session_recv) {
|
if (!_srtp_session_recv) {
|
||||||
WarnL << "received rtp packet when dtls not completed from:" << getPeerAddress(tuple);
|
WarnL << "received rtp packet when dtls not completed from:" << tuple->get_peer_ip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_srtp_session_recv->DecryptSrtp((uint8_t *)buf, &len)) {
|
if (_srtp_session_recv->DecryptSrtp((uint8_t *)buf, &len)) {
|
||||||
@ -461,7 +458,7 @@ void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tup
|
|||||||
}
|
}
|
||||||
if (isRtcp(buf, len)) {
|
if (isRtcp(buf, len)) {
|
||||||
if (!_srtp_session_recv) {
|
if (!_srtp_session_recv) {
|
||||||
WarnL << "received rtcp packet when dtls not completed from:" << getPeerAddress(tuple);
|
WarnL << "received rtcp packet when dtls not completed from:" << tuple->get_peer_ip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_srtp_session_recv->DecryptSrtcp((uint8_t *)buf, &len)) {
|
if (_srtp_session_recv->DecryptSrtcp((uint8_t *)buf, &len)) {
|
||||||
@ -533,8 +530,7 @@ void WebRtcTransportImp::OnDtlsTransportApplicationDataReceived(const RTC::DtlsT
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller,bool preferred_tcp)
|
WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) : WebRtcTransport(poller) {
|
||||||
: WebRtcTransport(poller), _preferred_tcp(preferred_tcp) {
|
|
||||||
InfoL << getIdentifier();
|
InfoL << getIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -674,7 +670,7 @@ void WebRtcTransportImp::onCheckAnswer(RtcSession &sdp) {
|
|||||||
});
|
});
|
||||||
for (auto &m : sdp.media) {
|
for (auto &m : sdp.media) {
|
||||||
m.addr.reset();
|
m.addr.reset();
|
||||||
m.addr.address = extern_ips.empty() ? _localIp.empty() ? SockUtil::get_local_ip() : _localIp : extern_ips[0];
|
m.addr.address = extern_ips.empty() ? _local_ip.empty() ? SockUtil::get_local_ip() : _local_ip : extern_ips[0];
|
||||||
m.rtcp_addr.reset();
|
m.rtcp_addr.reset();
|
||||||
m.rtcp_addr.address = m.addr.address;
|
m.rtcp_addr.address = m.addr.address;
|
||||||
|
|
||||||
@ -769,7 +765,7 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
|
|||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
if (extern_ips.empty()) {
|
if (extern_ips.empty()) {
|
||||||
std::string local_ip = _localIp.empty() ? SockUtil::get_local_ip() : _localIp;
|
std::string local_ip = _local_ip.empty() ? SockUtil::get_local_ip() : _local_ip;
|
||||||
if (local_udp_port) { configure.addCandidate(*makeIceCandidate(local_ip, local_udp_port, 120, "udp")); }
|
if (local_udp_port) { configure.addCandidate(*makeIceCandidate(local_ip, local_udp_port, 120, "udp")); }
|
||||||
if (local_tcp_port) { configure.addCandidate(*makeIceCandidate(local_ip, local_tcp_port, _preferred_tcp ? 125 : 115, "tcp")); }
|
if (local_tcp_port) { configure.addCandidate(*makeIceCandidate(local_ip, local_tcp_port, _preferred_tcp ? 125 : 115, "tcp")); }
|
||||||
} else {
|
} else {
|
||||||
@ -783,12 +779,16 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcTransportImp::setIceCandidate(vector<SdpAttrCandidate> cands) {
|
void WebRtcTransportImp::setPreferredTcp(bool flag) {
|
||||||
_cands = std::move(cands);
|
_preferred_tcp = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcTransportImp::setLocalIp(const std::string &localIp) {
|
void WebRtcTransportImp::setLocalIp(std::string local_ip) {
|
||||||
_localIp = localIp;
|
_local_ip = std::move(local_ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebRtcTransportImp::setIceCandidate(vector<SdpAttrCandidate> cands) {
|
||||||
|
_cands = std::move(cands);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
||||||
@ -1278,21 +1278,14 @@ void WebRtcPluginManager::registerPlugin(const string &type, Plugin cb) {
|
|||||||
_map_creator[type] = std::move(cb);
|
_map_creator[type] = std::move(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string exchangeSdp(const WebRtcInterface &exchanger, const std::string& offer) {
|
|
||||||
return const_cast<WebRtcInterface &>(exchanger).getAnswerSdp(offer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLocalIp(const WebRtcInterface& exchanger, const std::string& localIp) {
|
|
||||||
return const_cast<WebRtcInterface &>(exchanger).setLocalIp(localIp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebRtcPluginManager::setListener(Listener cb) {
|
void WebRtcPluginManager::setListener(Listener cb) {
|
||||||
lock_guard<mutex> lck(_mtx_creator);
|
lock_guard<mutex> lck(_mtx_creator);
|
||||||
_listener = std::move(cb);
|
_listener = std::move(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcPluginManager::getAnswerSdp(Session &sender, const string &type, const WebRtcArgs &args, const onCreateRtc &cb_in) {
|
void WebRtcPluginManager::negotiateSdp(Session &sender, const string &type, const WebRtcArgs &args, const onCreateWebRtc &cb_in) {
|
||||||
onCreateRtc cb;
|
onCreateWebRtc cb;
|
||||||
lock_guard<mutex> lck(_mtx_creator);
|
lock_guard<mutex> lck(_mtx_creator);
|
||||||
if (_listener) {
|
if (_listener) {
|
||||||
auto listener = _listener;
|
auto listener = _listener;
|
||||||
@ -1308,21 +1301,19 @@ void WebRtcPluginManager::getAnswerSdp(Session &sender, const string &type, cons
|
|||||||
|
|
||||||
auto it = _map_creator.find(type);
|
auto it = _map_creator.find(type);
|
||||||
if (it == _map_creator.end()) {
|
if (it == _map_creator.end()) {
|
||||||
cb(WebRtcException(SockException(Err_other, "the type can not supported")));
|
cb_in(WebRtcException(SockException(Err_other, "the type can not supported")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
it->second(sender, args, cb);
|
it->second(sender, args, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void echo_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
void echo_plugin(Session &sender, const WebRtcArgs &args, const onCreateWebRtc &cb) {
|
||||||
cb(*WebRtcEchoTest::create(EventPollerPool::Instance().getPoller()));
|
cb(*WebRtcEchoTest::create(EventPollerPool::Instance().getPoller()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
void push_plugin(Session &sender, const WebRtcArgs &args, const onCreateWebRtc &cb) {
|
||||||
MediaInfo info(args["url"]);
|
MediaInfo info(args["url"]);
|
||||||
bool preferred_tcp = args["preferred_tcp"];
|
Broadcast::PublishAuthInvoker invoker = [cb, info](const string &err, const ProtocolOption &option) mutable {
|
||||||
|
|
||||||
Broadcast::PublishAuthInvoker invoker = [cb, info, preferred_tcp](const string &err, const ProtocolOption &option) mutable {
|
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
cb(WebRtcException(SockException(Err_other, err)));
|
cb(WebRtcException(SockException(Err_other, err)));
|
||||||
return;
|
return;
|
||||||
@ -1361,7 +1352,7 @@ void push_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
|
|||||||
push_src_ownership = push_src->getOwnership();
|
push_src_ownership = push_src->getOwnership();
|
||||||
push_src->setProtocolOption(option);
|
push_src->setProtocolOption(option);
|
||||||
}
|
}
|
||||||
auto rtc = WebRtcPusher::create(EventPollerPool::Instance().getPoller(), push_src, push_src_ownership, info, option, preferred_tcp);
|
auto rtc = WebRtcPusher::create(EventPollerPool::Instance().getPoller(), push_src, push_src_ownership, info, option);
|
||||||
push_src->setListener(rtc);
|
push_src->setListener(rtc);
|
||||||
cb(*rtc);
|
cb(*rtc);
|
||||||
};
|
};
|
||||||
@ -1374,12 +1365,10 @@ void push_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
void play_plugin(Session &sender, const WebRtcArgs &args, const onCreateWebRtc &cb) {
|
||||||
MediaInfo info(args["url"]);
|
MediaInfo info(args["url"]);
|
||||||
bool preferred_tcp = args["preferred_tcp"];
|
|
||||||
|
|
||||||
auto session_ptr = static_pointer_cast<Session>(sender.shared_from_this());
|
auto session_ptr = static_pointer_cast<Session>(sender.shared_from_this());
|
||||||
Broadcast::AuthInvoker invoker = [cb, info, session_ptr, preferred_tcp](const string &err) mutable {
|
Broadcast::AuthInvoker invoker = [cb, info, session_ptr](const string &err) mutable {
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
cb(WebRtcException(SockException(Err_other, err)));
|
cb(WebRtcException(SockException(Err_other, err)));
|
||||||
return;
|
return;
|
||||||
@ -1395,7 +1384,7 @@ void play_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
|
|||||||
}
|
}
|
||||||
// 还原成rtc,目的是为了hook时识别哪种播放协议
|
// 还原成rtc,目的是为了hook时识别哪种播放协议
|
||||||
info.schema = "rtc";
|
info.schema = "rtc";
|
||||||
auto rtc = WebRtcPlayer::create(EventPollerPool::Instance().getPoller(), src, info, preferred_tcp);
|
auto rtc = WebRtcPlayer::create(EventPollerPool::Instance().getPoller(), src, info);
|
||||||
cb(*rtc);
|
cb(*rtc);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -1408,14 +1397,35 @@ void play_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_webrtc_cands(const WebRtcArgs &args, const WebRtcInterface &rtc) {
|
static void setWebRtcArgs(const WebRtcArgs &args, WebRtcInterface &rtc) {
|
||||||
|
{
|
||||||
|
static auto is_vaild_ip = [](const std::string &ip) -> bool {
|
||||||
|
int a, b, c, d;
|
||||||
|
return sscanf(ip.c_str(), "%d.%d.%d.%d", &a, &b, &c, &d) == 4;
|
||||||
|
};
|
||||||
|
std::string host = args["Host"];
|
||||||
|
if (!host.empty()) {
|
||||||
|
auto local_ip = host.substr(0, host.find(':'));
|
||||||
|
if (!is_vaild_ip(local_ip) || local_ip == "127.0.0.1") {
|
||||||
|
local_ip = "";
|
||||||
|
}
|
||||||
|
rtc.setLocalIp(std::move(local_ip));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool preferred_tcp = args["preferred_tcp"];
|
||||||
|
{
|
||||||
|
rtc.setPreferredTcp(preferred_tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
vector<SdpAttrCandidate> cands;
|
vector<SdpAttrCandidate> cands;
|
||||||
{
|
{
|
||||||
auto cand_str = trim(args["cand_udp"]);
|
auto cand_str = trim(args["cand_udp"]);
|
||||||
auto ip_port = toolkit::split(cand_str, ":");
|
auto ip_port = toolkit::split(cand_str, ":");
|
||||||
if (ip_port.size() == 2) {
|
if (ip_port.size() == 2) {
|
||||||
// udp优先
|
// udp优先
|
||||||
auto ice_cand = makeIceCandidate(ip_port[0], atoi(ip_port[1].data()), 120, "udp");
|
auto ice_cand = makeIceCandidate(ip_port[0], atoi(ip_port[1].data()), preferred_tcp ? 100 : 120, "udp");
|
||||||
cands.emplace_back(std::move(*ice_cand));
|
cands.emplace_back(std::move(*ice_cand));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1424,23 +1434,26 @@ static void set_webrtc_cands(const WebRtcArgs &args, const WebRtcInterface &rtc)
|
|||||||
auto ip_port = toolkit::split(cand_str, ":");
|
auto ip_port = toolkit::split(cand_str, ":");
|
||||||
if (ip_port.size() == 2) {
|
if (ip_port.size() == 2) {
|
||||||
// tcp模式
|
// tcp模式
|
||||||
auto ice_cand = makeIceCandidate(ip_port[0], atoi(ip_port[1].data()), 100, "tcp");
|
auto ice_cand = makeIceCandidate(ip_port[0], atoi(ip_port[1].data()), preferred_tcp ? 120 : 100, "tcp");
|
||||||
cands.emplace_back(std::move(*ice_cand));
|
cands.emplace_back(std::move(*ice_cand));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cands.empty()) {
|
if (!cands.empty()) {
|
||||||
// udp优先
|
// udp优先
|
||||||
const_cast<WebRtcInterface &>(rtc).setIceCandidate(std::move(cands));
|
rtc.setIceCandidate(std::move(cands));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static onceToken s_rtc_auto_register([]() {
|
static onceToken s_rtc_auto_register([]() {
|
||||||
|
#if !defined (NDEBUG)
|
||||||
|
// debug模式才开启echo插件
|
||||||
WebRtcPluginManager::Instance().registerPlugin("echo", echo_plugin);
|
WebRtcPluginManager::Instance().registerPlugin("echo", echo_plugin);
|
||||||
|
#endif
|
||||||
WebRtcPluginManager::Instance().registerPlugin("push", push_plugin);
|
WebRtcPluginManager::Instance().registerPlugin("push", push_plugin);
|
||||||
WebRtcPluginManager::Instance().registerPlugin("play", play_plugin);
|
WebRtcPluginManager::Instance().registerPlugin("play", play_plugin);
|
||||||
|
|
||||||
WebRtcPluginManager::Instance().setListener([](Session &sender, const std::string &type, const WebRtcArgs &args, const WebRtcInterface &rtc) {
|
WebRtcPluginManager::Instance().setListener([](Session &sender, const std::string &type, const WebRtcArgs &args, const WebRtcInterface &rtc) {
|
||||||
set_webrtc_cands(args, rtc);
|
setWebRtcArgs(args, const_cast<WebRtcInterface&>(rtc));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -42,13 +42,10 @@ public:
|
|||||||
virtual const std::string& getIdentifier() const = 0;
|
virtual const std::string& getIdentifier() const = 0;
|
||||||
virtual const std::string& deleteRandStr() const { static std::string s_null; return s_null; }
|
virtual const std::string& deleteRandStr() const { static std::string s_null; return s_null; }
|
||||||
virtual void setIceCandidate(std::vector<SdpAttrCandidate> cands) {}
|
virtual void setIceCandidate(std::vector<SdpAttrCandidate> cands) {}
|
||||||
virtual void setLocalIp(const std::string &localIp) {}
|
virtual void setLocalIp(std::string localIp) {}
|
||||||
|
virtual void setPreferredTcp(bool flag) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string exchangeSdp(const WebRtcInterface &exchanger, const std::string& offer);
|
|
||||||
|
|
||||||
void setLocalIp(const WebRtcInterface &exchanger, const std::string &localIp);
|
|
||||||
|
|
||||||
class WebRtcException : public WebRtcInterface {
|
class WebRtcException : public WebRtcInterface {
|
||||||
public:
|
public:
|
||||||
WebRtcException(const SockException &ex) : _ex(ex) {};
|
WebRtcException(const SockException &ex) : _ex(ex) {};
|
||||||
@ -88,7 +85,7 @@ public:
|
|||||||
* @param offer offer sdp
|
* @param offer offer sdp
|
||||||
* @return answer sdp
|
* @return answer sdp
|
||||||
*/
|
*/
|
||||||
std::string getAnswerSdp(const std::string &offer) override;
|
std::string getAnswerSdp(const std::string &offer) override final;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取对象唯一id
|
* 获取对象唯一id
|
||||||
@ -252,14 +249,16 @@ public:
|
|||||||
void onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool rtx = false);
|
void onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool rtx = false);
|
||||||
|
|
||||||
void createRtpChannel(const std::string &rid, uint32_t ssrc, MediaTrack &track);
|
void createRtpChannel(const std::string &rid, uint32_t ssrc, MediaTrack &track);
|
||||||
void setIceCandidate(std::vector<SdpAttrCandidate> cands) override;
|
|
||||||
void removeTuple(RTC::TransportTuple* tuple);
|
void removeTuple(RTC::TransportTuple* tuple);
|
||||||
void safeShutdown(const SockException &ex);
|
void safeShutdown(const SockException &ex);
|
||||||
|
|
||||||
void setLocalIp(const std::string &localIp) override;
|
void setPreferredTcp(bool flag) override;
|
||||||
|
void setLocalIp(std::string local_ip) override;
|
||||||
|
void setIceCandidate(std::vector<SdpAttrCandidate> cands) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnIceServerSelectedTuple(const RTC::IceServer *iceServer, RTC::TransportTuple *tuple) override;
|
void OnIceServerSelectedTuple(const RTC::IceServer *iceServer, RTC::TransportTuple *tuple) override;
|
||||||
WebRtcTransportImp(const EventPoller::Ptr &poller,bool preferred_tcp = false);
|
WebRtcTransportImp(const EventPoller::Ptr &poller);
|
||||||
void OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) override;
|
void OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) override;
|
||||||
void onStartWebRTC() override;
|
void onStartWebRTC() override;
|
||||||
void onSendSockData(Buffer::Ptr buf, bool flush = true, RTC::TransportTuple *tuple = nullptr) override;
|
void onSendSockData(Buffer::Ptr buf, bool flush = true, RTC::TransportTuple *tuple = nullptr) override;
|
||||||
@ -273,7 +272,7 @@ protected:
|
|||||||
void onCreate() override;
|
void onCreate() override;
|
||||||
void onDestory() override;
|
void onDestory() override;
|
||||||
void onShutdown(const SockException &ex) override;
|
void onShutdown(const SockException &ex) override;
|
||||||
virtual void onRecvRtp(MediaTrack &track, const std::string &rid, RtpPacket::Ptr rtp) = 0;
|
virtual void onRecvRtp(MediaTrack &track, const std::string &rid, RtpPacket::Ptr rtp) {}
|
||||||
void updateTicker();
|
void updateTicker();
|
||||||
float getLossRate(TrackType type);
|
float getLossRate(TrackType type);
|
||||||
void onRtcpBye() override;
|
void onRtcpBye() override;
|
||||||
@ -289,7 +288,7 @@ private:
|
|||||||
void onCheckAnswer(RtcSession &sdp);
|
void onCheckAnswer(RtcSession &sdp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _preferred_tcp;
|
bool _preferred_tcp = false;
|
||||||
uint16_t _rtx_seq[2] = {0, 0};
|
uint16_t _rtx_seq[2] = {0, 0};
|
||||||
//用掉的总流量
|
//用掉的总流量
|
||||||
uint64_t _bytes_usage = 0;
|
uint64_t _bytes_usage = 0;
|
||||||
@ -310,8 +309,8 @@ private:
|
|||||||
//根据接收rtp的pt获取相关信息
|
//根据接收rtp的pt获取相关信息
|
||||||
std::unordered_map<uint8_t/*pt*/, std::unique_ptr<WrappedMediaTrack>> _pt_to_track;
|
std::unordered_map<uint8_t/*pt*/, std::unique_ptr<WrappedMediaTrack>> _pt_to_track;
|
||||||
std::vector<SdpAttrCandidate> _cands;
|
std::vector<SdpAttrCandidate> _cands;
|
||||||
//源访问的hostip
|
//http访问时的host ip
|
||||||
std::string _localIp;
|
std::string _local_ip;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WebRtcTransportManager {
|
class WebRtcTransportManager {
|
||||||
@ -333,21 +332,20 @@ private:
|
|||||||
class WebRtcArgs : public std::enable_shared_from_this<WebRtcArgs> {
|
class WebRtcArgs : public std::enable_shared_from_this<WebRtcArgs> {
|
||||||
public:
|
public:
|
||||||
virtual ~WebRtcArgs() = default;
|
virtual ~WebRtcArgs() = default;
|
||||||
|
|
||||||
virtual variant operator[](const std::string &key) const = 0;
|
virtual variant operator[](const std::string &key) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using onCreateWebRtc = std::function<void(const WebRtcInterface &rtc)>;
|
||||||
class WebRtcPluginManager {
|
class WebRtcPluginManager {
|
||||||
public:
|
public:
|
||||||
using onCreateRtc = std::function<void(const WebRtcInterface &rtc)>;
|
using Plugin = std::function<void(Session &sender, const WebRtcArgs &args, const onCreateWebRtc &cb)>;
|
||||||
using Plugin = std::function<void(Session &sender, const WebRtcArgs &args, const onCreateRtc &cb)>;
|
|
||||||
using Listener = std::function<void(Session &sender, const std::string &type, const WebRtcArgs &args, const WebRtcInterface &rtc)>;
|
using Listener = std::function<void(Session &sender, const std::string &type, const WebRtcArgs &args, const WebRtcInterface &rtc)>;
|
||||||
|
|
||||||
static WebRtcPluginManager &Instance();
|
static WebRtcPluginManager &Instance();
|
||||||
|
|
||||||
void registerPlugin(const std::string &type, Plugin cb);
|
void registerPlugin(const std::string &type, Plugin cb);
|
||||||
void getAnswerSdp(Session &sender, const std::string &type, const WebRtcArgs &args, const onCreateRtc &cb);
|
|
||||||
void setListener(Listener cb);
|
void setListener(Listener cb);
|
||||||
|
void negotiateSdp(Session &sender, const std::string &type, const WebRtcArgs &args, const onCreateWebRtc &cb);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebRtcPluginManager() = default;
|
WebRtcPluginManager() = default;
|
||||||
|
Loading…
Reference in New Issue
Block a user