2018-10-25 10:00:17 +08:00
|
|
|
|
/*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* Use of this source code is governed by MIT-like license that can be found in the
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* 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.
|
2018-10-25 10:00:17 +08:00
|
|
|
|
*/
|
2018-10-24 09:23:57 +08:00
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_FACTORY_H
|
|
|
|
|
#define ZLMEDIAKIT_FACTORY_H
|
|
|
|
|
|
|
|
|
|
#include <string>
|
2018-10-25 10:00:17 +08:00
|
|
|
|
#include "Rtmp/amf.h"
|
2018-10-30 14:59:42 +08:00
|
|
|
|
#include "Extension/Track.h"
|
2023-12-09 16:23:51 +08:00
|
|
|
|
#include "Extension/Frame.h"
|
2019-06-28 17:30:13 +08:00
|
|
|
|
#include "Rtsp/RtpCodec.h"
|
|
|
|
|
#include "Rtmp/RtmpCodec.h"
|
2023-12-10 10:21:40 +08:00
|
|
|
|
#include "Util/onceToken.h"
|
2018-10-24 09:23:57 +08:00
|
|
|
|
|
2023-12-10 10:21:40 +08:00
|
|
|
|
#define REGISTER_STATIC_VAR_INNER(var_name, line) var_name##_##line##__
|
|
|
|
|
#define REGISTER_STATIC_VAR(var_name, line) REGISTER_STATIC_VAR_INNER(var_name, line)
|
|
|
|
|
|
|
|
|
|
#define REGISTER_CODEC(plugin) \
|
|
|
|
|
static toolkit::onceToken REGISTER_STATIC_VAR(s_token, __LINE__) ([]() { \
|
|
|
|
|
Factory::registerPlugin(plugin); \
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
namespace mediakit {
|
|
|
|
|
|
|
|
|
|
struct CodecPlugin {
|
|
|
|
|
CodecId (*getCodec)();
|
|
|
|
|
Track::Ptr (*getTrackByCodecId)(int sample_rate, int channels, int sample_bit);
|
|
|
|
|
Track::Ptr (*getTrackBySdp)(const SdpTrack::Ptr &track);
|
|
|
|
|
RtpCodec::Ptr (*getRtpEncoderByCodecId)(uint8_t pt);
|
|
|
|
|
RtpCodec::Ptr (*getRtpDecoderByCodecId)();
|
|
|
|
|
RtmpCodec::Ptr (*getRtmpEncoderByTrack)(const Track::Ptr &track);
|
|
|
|
|
RtmpCodec::Ptr (*getRtmpDecoderByTrack)(const Track::Ptr &track);
|
|
|
|
|
Frame::Ptr (*getFrameFromPtr)(const char *data, size_t bytes, uint64_t dts, uint64_t pts);
|
|
|
|
|
};
|
2018-10-24 09:23:57 +08:00
|
|
|
|
|
|
|
|
|
class Factory {
|
|
|
|
|
public:
|
2023-12-10 10:21:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* 注册插件,非线程安全的
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Register plugin, not thread-safe
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:43e22d01]
|
2023-12-10 10:21:40 +08:00
|
|
|
|
*/
|
|
|
|
|
static void registerPlugin(const CodecPlugin &plugin);
|
2023-07-22 17:31:39 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据codec_id 获取track
|
|
|
|
|
* @param codecId 编码id
|
|
|
|
|
* @param sample_rate 采样率,视频固定为90000
|
|
|
|
|
* @param channels 音频通道数
|
|
|
|
|
* @param sample_bit 音频采样位数
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Get track by codec_id
|
|
|
|
|
* @param codecId codec id
|
|
|
|
|
* @param sample_rate sample rate, video is fixed to 90000
|
|
|
|
|
* @param channels number of audio channels
|
|
|
|
|
* @param sample_bit audio sample bit
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:397b982e]
|
2023-07-22 17:31:39 +08:00
|
|
|
|
*/
|
|
|
|
|
static Track::Ptr getTrackByCodecId(CodecId codecId, int sample_rate = 0, int channels = 0, int sample_bit = 0);
|
|
|
|
|
|
2024-09-19 14:53:50 +08:00
|
|
|
|
// //////////////////////////////rtsp相关////////////////////////////////// [AUTO-TRANSLATED:884055ec]
|
|
|
|
|
// //////////////////////////////rtsp相关//////////////////////////////////
|
2018-10-25 09:15:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 根据sdp生成Track对象
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Generate Track object based on sdp
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:79a99990]
|
2018-10-25 09:15:46 +08:00
|
|
|
|
*/
|
2018-10-26 09:56:29 +08:00
|
|
|
|
static Track::Ptr getTrackBySdp(const SdpTrack::Ptr &track);
|
2018-10-24 09:23:57 +08:00
|
|
|
|
|
2022-07-07 16:48:35 +08:00
|
|
|
|
/**
|
|
|
|
|
* 根据c api 抽象的Track生成具体Track对象
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Generate specific Track object based on Track abstracted from c api
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:991e7721]
|
2022-07-07 16:48:35 +08:00
|
|
|
|
*/
|
|
|
|
|
static Track::Ptr getTrackByAbstractTrack(const Track::Ptr& track);
|
|
|
|
|
|
2022-08-05 17:36:51 +08:00
|
|
|
|
/**
|
|
|
|
|
* 根据codec id生成rtp编码器
|
|
|
|
|
* @param codec_id 编码id
|
|
|
|
|
* @param pt rtp payload type
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Generate rtp encoder based on codec id
|
|
|
|
|
* @param codec_id codec id
|
|
|
|
|
* @param pt rtp payload type
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:3895b39c]
|
2022-08-05 17:36:51 +08:00
|
|
|
|
*/
|
2023-12-09 16:23:51 +08:00
|
|
|
|
static RtpCodec::Ptr getRtpEncoderByCodecId(CodecId codec_id, uint8_t pt);
|
2022-08-05 17:36:51 +08:00
|
|
|
|
|
2018-10-24 09:23:57 +08:00
|
|
|
|
/**
|
2019-01-24 12:21:29 +08:00
|
|
|
|
* 根据Track生成Rtp解包器
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Generate Rtp unpacker based on Track
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:50dbf826]
|
2018-10-24 09:23:57 +08:00
|
|
|
|
*/
|
2023-12-10 10:21:40 +08:00
|
|
|
|
static RtpCodec::Ptr getRtpDecoderByCodecId(CodecId codec);
|
2018-10-24 22:03:17 +08:00
|
|
|
|
|
|
|
|
|
|
2024-09-19 14:53:50 +08:00
|
|
|
|
// //////////////////////////////rtmp相关////////////////////////////////// [AUTO-TRANSLATED:df02d6fb]
|
|
|
|
|
// //////////////////////////////rtmp相关//////////////////////////////////
|
2018-10-24 22:03:17 +08:00
|
|
|
|
|
2018-10-25 09:15:46 +08:00
|
|
|
|
/**
|
2020-04-17 17:47:10 +08:00
|
|
|
|
* 根据amf对象获取视频相应的Track
|
|
|
|
|
* @param amf rtmp metadata中的videocodecid的值
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Get the corresponding video Track based on the amf object
|
|
|
|
|
* @param amf the value of videocodecid in rtmp metadata
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:c0c632c1]
|
2018-10-25 09:15:46 +08:00
|
|
|
|
*/
|
2020-04-17 17:47:10 +08:00
|
|
|
|
static Track::Ptr getVideoTrackByAmf(const AMFValue &amf);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据amf对象获取音频相应的Track
|
|
|
|
|
* @param amf rtmp metadata中的audiocodecid的值
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Get the corresponding audio Track based on the amf object
|
|
|
|
|
* @param amf the value of audiocodecid in rtmp metadata
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:fc34f9e4]
|
2020-04-17 17:47:10 +08:00
|
|
|
|
*/
|
2020-04-18 22:13:11 +08:00
|
|
|
|
static Track::Ptr getAudioTrackByAmf(const AMFValue& amf, int sample_rate, int channels, int sample_bit);
|
2018-10-25 09:15:46 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* 根据Track获取Rtmp的编码器
|
2018-10-25 14:16:40 +08:00
|
|
|
|
* @param track 媒体描述对象
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Get the Rtmp encoder based on Track
|
|
|
|
|
* @param track media description object
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:81fc38af]
|
2018-10-25 09:15:46 +08:00
|
|
|
|
*/
|
2023-12-09 16:23:51 +08:00
|
|
|
|
static RtmpCodec::Ptr getRtmpEncoderByTrack(const Track::Ptr &track);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据Track获取Rtmp的解码器
|
|
|
|
|
* @param track 媒体描述对象
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Get the Rtmp decoder based on Track
|
|
|
|
|
* @param track media description object
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:0744b09e]
|
2023-12-09 16:23:51 +08:00
|
|
|
|
*/
|
|
|
|
|
static RtmpCodec::Ptr getRtmpDecoderByTrack(const Track::Ptr &track);
|
2018-10-25 14:49:47 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据codecId获取rtmp的codec描述
|
2024-09-19 14:53:50 +08:00
|
|
|
|
* Get the rtmp codec description based on codecId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* [AUTO-TRANSLATED:67c749b7]
|
2018-10-25 14:49:47 +08:00
|
|
|
|
*/
|
|
|
|
|
static AMFValue getAmfByCodecId(CodecId codecId);
|
2023-12-09 16:23:51 +08:00
|
|
|
|
|
|
|
|
|
static Frame::Ptr getFrameFromPtr(CodecId codec, const char *data, size_t size, uint64_t dts, uint64_t pts);
|
|
|
|
|
static Frame::Ptr getFrameFromBuffer(CodecId codec, toolkit::Buffer::Ptr data, uint64_t dts, uint64_t pts);
|
2018-10-24 09:23:57 +08:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
}//namespace mediakit
|
2018-10-24 09:23:57 +08:00
|
|
|
|
|
|
|
|
|
#endif //ZLMEDIAKIT_FACTORY_H
|