mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
parent
2e1a45895a
commit
c4988e7cfc
@ -187,7 +187,6 @@ API_EXPORT int API_CALL mk_media_init_video(mk_media ctx, int codec_id, int widt
|
|||||||
info.iWidth = width;
|
info.iWidth = width;
|
||||||
info.iHeight = height;
|
info.iHeight = height;
|
||||||
info.iBitRate = bit_rate;
|
info.iBitRate = bit_rate;
|
||||||
(*obj)->getChannel()->initVideo(info);
|
|
||||||
return (*obj)->getChannel()->initVideo(info);
|
return (*obj)->getChannel()->initVideo(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,12 +10,13 @@
|
|||||||
|
|
||||||
#include "mk_track.h"
|
#include "mk_track.h"
|
||||||
#include "Extension/Track.h"
|
#include "Extension/Track.h"
|
||||||
|
#include "Extension/Factory.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
class VideoTrackForC : public VideoTrack {
|
class VideoTrackForC : public VideoTrack, public std::enable_shared_from_this<VideoTrackForC> {
|
||||||
public:
|
public:
|
||||||
VideoTrackForC(int codec_id, codec_args *args) {
|
VideoTrackForC(int codec_id, codec_args *args) {
|
||||||
_codec_id = (CodecId) codec_id;
|
_codec_id = (CodecId) codec_id;
|
||||||
@ -49,7 +50,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Track::Ptr clone() override {
|
Track::Ptr clone() override {
|
||||||
return std::make_shared<std::remove_reference<decltype(*this)>::type>(*this);
|
auto track_in = std::shared_ptr<Track>(shared_from_this());
|
||||||
|
return Factory::getTrackByAbstractTrack(track_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sdp::Ptr getSdp() override {
|
Sdp::Ptr getSdp() override {
|
||||||
@ -61,7 +63,7 @@ private:
|
|||||||
codec_args _args;
|
codec_args _args;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AudioTrackForC : public AudioTrackImp {
|
class AudioTrackForC : public AudioTrackImp, public std::enable_shared_from_this<AudioTrackForC> {
|
||||||
public:
|
public:
|
||||||
~AudioTrackForC() override = default;
|
~AudioTrackForC() override = default;
|
||||||
|
|
||||||
@ -69,7 +71,8 @@ public:
|
|||||||
AudioTrackImp((CodecId) codec_id, args->audio.sample_rate, args->audio.channels, 16) {}
|
AudioTrackImp((CodecId) codec_id, args->audio.sample_rate, args->audio.channels, 16) {}
|
||||||
|
|
||||||
Track::Ptr clone() override {
|
Track::Ptr clone() override {
|
||||||
return std::make_shared<std::remove_reference<decltype(*this)>::type>(*this);
|
auto track_in = std::shared_ptr<Track>(shared_from_this());
|
||||||
|
return Factory::getTrackByAbstractTrack(track_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sdp::Ptr getSdp() override {
|
Sdp::Ptr getSdp() override {
|
||||||
|
@ -64,8 +64,12 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
mk_media media = mk_media_create("__defaultVhost__", "live", "test", 0, 0, 0);
|
mk_media media = mk_media_create("__defaultVhost__", "live", "test", 0, 0, 0);
|
||||||
//h264的codec
|
//h264的codec
|
||||||
mk_media_init_video(media, 0, 0, 0, 0, 2 * 104 * 1024);
|
//mk_media_init_video(media, 0, 0, 0, 0, 2 * 104 * 1024);
|
||||||
|
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_media_init_complete(media);
|
||||||
|
mk_track_unref(v_track);
|
||||||
|
|
||||||
//创建h264分帧器
|
//创建h264分帧器
|
||||||
mk_h264_splitter splitter = mk_h264_splitter_create(on_h264_frame, media);
|
mk_h264_splitter splitter = mk_h264_splitter_create(on_h264_frame, media);
|
||||||
|
@ -95,6 +95,32 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Track::Ptr Factory::getTrackByAbstractTrack(const Track::Ptr& track) {
|
||||||
|
auto codec = track->getCodecId();
|
||||||
|
switch (codec) {
|
||||||
|
case CodecG711A:
|
||||||
|
case CodecG711U: {
|
||||||
|
auto audio_track = dynamic_pointer_cast<AudioTrackImp>(track);
|
||||||
|
return std::make_shared<G711Track>(codec, audio_track->getAudioSampleRate(), audio_track->getAudioChannel(), 16);
|
||||||
|
}
|
||||||
|
case CodecL16: {
|
||||||
|
auto audio_track = dynamic_pointer_cast<AudioTrackImp>(track);
|
||||||
|
return std::make_shared<L16Track>(audio_track->getAudioSampleRate(), audio_track->getAudioChannel());
|
||||||
|
}
|
||||||
|
case CodecAAC : return std::make_shared<AACTrack>();
|
||||||
|
case CodecOpus : return std::make_shared<OpusTrack>();
|
||||||
|
case CodecH265 : return std::make_shared<H265Track>();
|
||||||
|
case CodecH264 : return std::make_shared<H264Track>();
|
||||||
|
|
||||||
|
default: {
|
||||||
|
//其他codec不支持
|
||||||
|
WarnL << "暂不支持该该编码类型创建Track:" << track->getCodecName();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RtpCodec::Ptr Factory::getRtpEncoderBySdp(const Sdp::Ptr &sdp) {
|
RtpCodec::Ptr Factory::getRtpEncoderBySdp(const Sdp::Ptr &sdp) {
|
||||||
GET_CONFIG(uint32_t,audio_mtu,Rtp::kAudioMtuSize);
|
GET_CONFIG(uint32_t,audio_mtu,Rtp::kAudioMtuSize);
|
||||||
GET_CONFIG(uint32_t,video_mtu,Rtp::kVideoMtuSize);
|
GET_CONFIG(uint32_t,video_mtu,Rtp::kVideoMtuSize);
|
||||||
|
@ -27,6 +27,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
static Track::Ptr getTrackBySdp(const SdpTrack::Ptr &track);
|
static Track::Ptr getTrackBySdp(const SdpTrack::Ptr &track);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据c api 抽象的Track生成具体Track对象
|
||||||
|
*/
|
||||||
|
static Track::Ptr getTrackByAbstractTrack(const Track::Ptr& track);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据sdp生成rtp编码器
|
* 根据sdp生成rtp编码器
|
||||||
* @param sdp sdp对象
|
* @param sdp sdp对象
|
||||||
|
Loading…
Reference in New Issue
Block a user