Compare commits

..

3 Commits

Author SHA1 Message Date
xia-chu
aa56576b0e 修复默认音频参数相关bug
Some checks are pending
Android / build (push) Waiting to run
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Docker / build (push) Waiting to run
Linux / build (push) Waiting to run
macOS / build (push) Waiting to run
Windows / build (push) Waiting to run
2024-11-30 10:54:45 +08:00
xia-chu
d1f3961326 完善rtp服务器对各编码类型es流的支持 2024-11-30 08:50:07 +08:00
xia-chu
892108d6ba 新增若干音视频编码类型的默认实现
部分支持VP8/VP9/AV1/JPEG/MP3/H266/ADPCM/SVAC/G722/G723/G729
2024-11-30 08:23:10 +08:00
4 changed files with 76 additions and 74 deletions

View File

@ -38,7 +38,7 @@ CodecId getCodecU() {
} }
Track::Ptr getTrackByCodecId_l(CodecId codec, int sample_rate, int channels, int sample_bit) { Track::Ptr getTrackByCodecId_l(CodecId codec, int sample_rate, int channels, int sample_bit) {
return (sample_rate && channels && sample_bit) ? std::make_shared<G711Track>(codec, sample_rate, channels, sample_bit) : nullptr; return std::make_shared<G711Track>(codec, sample_rate, 1, 16);
} }
Track::Ptr getTrackByCodecIdA(int sample_rate, int channels, int sample_bit) { Track::Ptr getTrackByCodecIdA(int sample_rate, int channels, int sample_bit) {

View File

@ -65,7 +65,7 @@ public:
* [AUTO-TRANSLATED:397b982e] * [AUTO-TRANSLATED:397b982e]
*/ */
static Track::Ptr getTrackByCodecId(CodecId codecId, int sample_rate = 0, int channels = 0, int sample_bit = 0); static Track::Ptr getTrackByCodecId(CodecId codecId, int sample_rate = 0, int channels = 1, int sample_bit = 16);
// //////////////////////////////rtsp相关////////////////////////////////// [AUTO-TRANSLATED:884055ec] // //////////////////////////////rtsp相关////////////////////////////////// [AUTO-TRANSLATED:884055ec]
// //////////////////////////////rtsp相关////////////////////////////////// // //////////////////////////////rtsp相关//////////////////////////////////

View File

@ -83,79 +83,76 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
// Prevent too many pt types from causing memory overflow // Prevent too many pt types from causing memory overflow
WarnL << "Rtp payload type more than 2 types: " << _rtp_receiver.size(); WarnL << "Rtp payload type more than 2 types: " << _rtp_receiver.size();
} }
switch (pt) {
case Rtsp::PT_PCMA: do {
case Rtsp::PT_PCMU: { if (pt < 96) {
// CodecG711U or CodecG711A auto codec = RtpPayload::getCodecId(pt);
ref = std::make_shared<RtpReceiverImp>(8000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); if (codec != CodecInvalid && codec != CodecTS) {
auto track = Factory::getTrackByCodecId(pt == Rtsp::PT_PCMU ? CodecG711U : CodecG711A, 8000, 1, 16); auto sample_rate = RtpPayload::getClockRate(pt);
CHECK(track); auto channels = RtpPayload::getAudioChannel(pt);
track->setIndex(pt); ref = std::make_shared<RtpReceiverImp>(sample_rate, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
_interface->addTrack(track); auto track = Factory::getTrackByCodecId(codec, sample_rate, channels);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
break;
}
case Rtsp::PT_JPEG: {
// mjpeg
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
auto track = Factory::getTrackByCodecId(CodecJPEG);
CHECK(track);
track->setIndex(pt);
_interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
break;
}
default: {
if (pt == opus_pt) {
// opus负载 [AUTO-TRANSLATED:defa6a8d]
// opus payload
ref = std::make_shared<RtpReceiverImp>(48000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
auto track = Factory::getTrackByCodecId(CodecOpus);
CHECK(track); CHECK(track);
track->setIndex(pt); track->setIndex(pt);
_interface->addTrack(track); _interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId()); _rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
} else if (pt == h265_pt) { break;
// H265负载 [AUTO-TRANSLATED:61fbcf7f]
// H265 payload
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
auto track = Factory::getTrackByCodecId(CodecH265);
CHECK(track);
track->setIndex(pt);
_interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
} else if (pt == h264_pt) {
// H264负载 [AUTO-TRANSLATED:6f3fbb0d]
// H264 payload
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
auto track = Factory::getTrackByCodecId(CodecH264);
CHECK(track);
track->setIndex(pt);
_interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
} else {
if (pt != Rtsp::PT_MP2T && pt != ps_pt) {
WarnL << "Unknown rtp payload type(" << (int)pt << "), decode it as mpeg-ps or mpeg-ts";
}
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
// ts或ps负载 [AUTO-TRANSLATED:3ca31480]
// ts or ps payload
_rtp_decoder[pt] = std::make_shared<CommonRtpDecoder>(CodecInvalid, 32 * 1024);
// 设置dump目录 [AUTO-TRANSLATED:23c88ace]
// Set dump directory
GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir);
if (!dump_dir.empty()) {
auto save_path = File::absolutePath(_media_info.stream + ".mpeg", dump_dir);
_save_file_ps.reset(File::create_file(save_path.data(), "wb"), [](FILE *fp) {
if (fp) {
fclose(fp);
}
});
}
} }
}
if (pt == opus_pt) {
// opus负载 [AUTO-TRANSLATED:defa6a8d]
// opus payload
ref = std::make_shared<RtpReceiverImp>(48000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
auto track = Factory::getTrackByCodecId(CodecOpus);
CHECK(track);
track->setIndex(pt);
_interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
break; break;
} }
} if (pt == h265_pt) {
// H265负载 [AUTO-TRANSLATED:61fbcf7f]
// H265 payload
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
auto track = Factory::getTrackByCodecId(CodecH265);
CHECK(track);
track->setIndex(pt);
_interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
break;
}
if (pt == h264_pt) {
// H264负载 [AUTO-TRANSLATED:6f3fbb0d]
// H264 payload
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
auto track = Factory::getTrackByCodecId(CodecH264);
CHECK(track);
track->setIndex(pt);
_interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
break;
}
if (pt != Rtsp::PT_MP2T && pt != ps_pt) {
WarnL << "Unknown rtp payload type(" << (int)pt << "), decode it as mpeg-ps or mpeg-ts";
}
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
// ts或ps负载 [AUTO-TRANSLATED:3ca31480]
// ts or ps payload
_rtp_decoder[pt] = std::make_shared<CommonRtpDecoder>(CodecInvalid, 32 * 1024);
// 设置dump目录 [AUTO-TRANSLATED:23c88ace]
// Set dump directory
GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir);
if (!dump_dir.empty()) {
auto save_path = File::absolutePath(_media_info.stream + ".mpeg", dump_dir);
_save_file_ps.reset(File::create_file(save_path.data(), "wb"), [](FILE *fp) {
if (fp) {
fclose(fp);
}
});
}
} while (false);
// 设置frame回调 [AUTO-TRANSLATED:dec7590f] // 设置frame回调 [AUTO-TRANSLATED:dec7590f]
// Set frame callback // Set frame callback
_rtp_decoder[pt]->addDelegate([this, pt](const Frame::Ptr &frame) { _rtp_decoder[pt]->addDelegate([this, pt](const Frame::Ptr &frame) {
@ -169,11 +166,16 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
} }
void GB28181Process::onRtpDecode(const Frame::Ptr &frame) { void GB28181Process::onRtpDecode(const Frame::Ptr &frame) {
if (frame->getCodecId() != CodecInvalid) { switch (frame->getCodecId()) {
// 这里不是ps或ts [AUTO-TRANSLATED:6f79ac69] case CodecInvalid:
// This is not ps or ts case CodecTS:
_interface->inputFrame(frame); case CodecPS: break;
return;
default:
// 这里不是ps或ts [AUTO-TRANSLATED:6f79ac69]
// This is not ps or ts
_interface->inputFrame(frame);
return;
} }
// 这是TS或PS [AUTO-TRANSLATED:55782860] // 这是TS或PS [AUTO-TRANSLATED:55782860]

View File

@ -65,7 +65,7 @@ bool RtspMuxer::addTrack(const Track::Ptr &track) {
WarnL << "Already add a track kind of: " << track->getTrackTypeStr() << ", ignore track: " << track->getCodecName(); WarnL << "Already add a track kind of: " << track->getTrackTypeStr() << ", ignore track: " << track->getCodecName();
return false; return false;
} }
if (track->ready()) { if (!track->ready()) {
WarnL << track->getCodecName() << " unready!"; WarnL << track->getCodecName() << " unready!";
return false; return false;
} }