mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-30 06:59:22 +08:00
hls/mp4录像/mp4点播/ts解析/ps解析初步支持G711
This commit is contained in:
parent
eb67bc8348
commit
2e3cee09bb
@ -64,6 +64,19 @@ class G711FrameNoCacheAble : public FrameNoCacheAble {
|
|||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<G711FrameNoCacheAble> Ptr;
|
typedef std::shared_ptr<G711FrameNoCacheAble> Ptr;
|
||||||
|
|
||||||
|
//兼容通用接口
|
||||||
|
G711FrameNoCacheAble(char *ptr,uint32_t size,uint32_t dts, uint32_t pts = 0,int prefixeSize = 0){
|
||||||
|
_ptr = ptr;
|
||||||
|
_size = size;
|
||||||
|
_dts = dts;
|
||||||
|
_prefixSize = prefixeSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
//兼容通用接口
|
||||||
|
void setCodec(CodecId codecId){
|
||||||
|
_codecId = codecId;
|
||||||
|
}
|
||||||
|
|
||||||
G711FrameNoCacheAble(CodecId codecId, char *ptr,uint32_t size,uint32_t dts,int prefixeSize = 0){
|
G711FrameNoCacheAble(CodecId codecId, char *ptr,uint32_t size,uint32_t dts,int prefixeSize = 0){
|
||||||
_codecId = codecId;
|
_codecId = codecId;
|
||||||
_ptr = ptr;
|
_ptr = ptr;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "Extension/H265.h"
|
#include "Extension/H265.h"
|
||||||
#include "Extension/H264.h"
|
#include "Extension/H264.h"
|
||||||
#include "Extension/AAC.h"
|
#include "Extension/AAC.h"
|
||||||
|
#include "Extension/G711.h"
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
@ -120,6 +121,12 @@ void MP4Demuxer::onAudioTrack(uint32_t track_id, uint8_t object, int channel_cou
|
|||||||
_track_to_codec.emplace(track_id, audio);
|
_track_to_codec.emplace(track_id, audio);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MOV_OBJECT_G711a:
|
||||||
|
case MOV_OBJECT_G711u:{
|
||||||
|
auto audio = std::make_shared<G711Track>(object == MOV_OBJECT_G711a ? CodecG711A : CodecG711U, sample_rate, channel_count, bit_per_sample / channel_count );
|
||||||
|
_track_to_codec.emplace(track_id, audio);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
WarnL << "不支持该编码类型的MP4,已忽略:" << getObjectName(object);
|
WarnL << "不支持该编码类型的MP4,已忽略:" << getObjectName(object);
|
||||||
break;
|
break;
|
||||||
@ -223,8 +230,16 @@ Frame::Ptr MP4Demuxer::makeFrame(uint32_t track_id, const Buffer::Ptr &buf, int6
|
|||||||
}
|
}
|
||||||
return std::make_shared<FrameWrapper<H265FrameNoCacheAble> >(buf, pts, dts, 4);
|
return std::make_shared<FrameWrapper<H265FrameNoCacheAble> >(buf, pts, dts, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
case CodecAAC :
|
case CodecAAC :
|
||||||
return std::make_shared<FrameWrapper<AACFrameNoCacheAble> >(buf, pts, dts, 0);
|
return std::make_shared<FrameWrapper<AACFrameNoCacheAble> >(buf, pts, dts, 0);
|
||||||
|
|
||||||
|
case CodecG711A:
|
||||||
|
case CodecG711U: {
|
||||||
|
auto frame = std::make_shared<FrameWrapper<G711FrameNoCacheAble> >(buf, pts, dts, 0);
|
||||||
|
frame->setCodec(codec);
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -124,22 +124,47 @@ void MP4Muxer::inputFrame(const Frame::Ptr &frame) {
|
|||||||
|
|
||||||
void MP4Muxer::addTrack(const Track::Ptr &track) {
|
void MP4Muxer::addTrack(const Track::Ptr &track) {
|
||||||
switch (track->getCodecId()) {
|
switch (track->getCodecId()) {
|
||||||
|
case CodecG711A:
|
||||||
|
case CodecG711U: {
|
||||||
|
auto audio_track = dynamic_pointer_cast<G711Track>(track);
|
||||||
|
if (!audio_track) {
|
||||||
|
WarnL << "不是G711 Track";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!audio_track->ready()) {
|
||||||
|
WarnL << "G711 Track未就绪";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto track_id = mov_writer_add_audio(_mov_writter.get(),
|
||||||
|
track->getCodecId() == CodecG711A ? MOV_OBJECT_G711a : MOV_OBJECT_G711u,
|
||||||
|
audio_track->getAudioChannel(),
|
||||||
|
audio_track->getAudioSampleBit() * audio_track->getAudioChannel(),
|
||||||
|
audio_track->getAudioSampleRate(),
|
||||||
|
nullptr, 0);
|
||||||
|
if (track_id < 0) {
|
||||||
|
WarnL << "添加G711 Track失败:" << track_id;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_codec_to_trackid[track->getCodecId()].track_id = track_id;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case CodecAAC: {
|
case CodecAAC: {
|
||||||
auto aac_track = dynamic_pointer_cast<AACTrack>(track);
|
auto audio_track = dynamic_pointer_cast<AACTrack>(track);
|
||||||
if (!aac_track) {
|
if (!audio_track) {
|
||||||
WarnL << "不是AAC Track";
|
WarnL << "不是AAC Track";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!aac_track->ready()){
|
if(!audio_track->ready()){
|
||||||
WarnL << "AAC Track未就绪";
|
WarnL << "AAC Track未就绪";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto track_id = mov_writer_add_audio(_mov_writter.get(),
|
auto track_id = mov_writer_add_audio(_mov_writter.get(),
|
||||||
MOV_OBJECT_AAC,
|
MOV_OBJECT_AAC,
|
||||||
aac_track->getAudioChannel(),
|
audio_track->getAudioChannel(),
|
||||||
aac_track->getAudioSampleBit() * aac_track->getAudioChannel(),
|
audio_track->getAudioSampleBit() * audio_track->getAudioChannel(),
|
||||||
aac_track->getAudioSampleRate(),
|
audio_track->getAudioSampleRate(),
|
||||||
aac_track->getAacCfg().data(), 2);
|
audio_track->getAacCfg().data(), 2);
|
||||||
if(track_id < 0){
|
if(track_id < 0){
|
||||||
WarnL << "添加AAC Track失败:" << track_id;
|
WarnL << "添加AAC Track失败:" << track_id;
|
||||||
return;
|
return;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "Common/MediaSink.h"
|
#include "Common/MediaSink.h"
|
||||||
#include "Extension/AAC.h"
|
#include "Extension/AAC.h"
|
||||||
|
#include "Extension/G711.h"
|
||||||
#include "Extension/H264.h"
|
#include "Extension/H264.h"
|
||||||
#include "Extension/H265.h"
|
#include "Extension/H265.h"
|
||||||
#include "Common/Stamp.h"
|
#include "Common/Stamp.h"
|
||||||
|
@ -39,6 +39,14 @@ void TsMuxer::addTrack(const Track::Ptr &track) {
|
|||||||
_codec_to_trackid[track->getCodecId()].track_id = mpeg_ts_add_stream(_context, PSI_STREAM_AAC, nullptr, 0);
|
_codec_to_trackid[track->getCodecId()].track_id = mpeg_ts_add_stream(_context, PSI_STREAM_AAC, nullptr, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CodecG711A:
|
||||||
|
case CodecG711U: {
|
||||||
|
//todo 此处未区分G711a和G711u
|
||||||
|
_codec_to_trackid[track->getCodecId()].track_id = mpeg_ts_add_stream(_context, PSI_STREAM_AUDIO_G711, nullptr, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "Util/File.h"
|
#include "Util/File.h"
|
||||||
#include "Extension/H265.h"
|
#include "Extension/H265.h"
|
||||||
#include "Extension/AAC.h"
|
#include "Extension/AAC.h"
|
||||||
|
#include "Extension/G711.h"
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
@ -271,6 +272,27 @@ void RtpProcess::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t d
|
|||||||
_muxer->inputFrame(std::make_shared<AACFrameNoCacheAble>((char *) data, bytes, dts, 0, 7));
|
_muxer->inputFrame(std::make_shared<AACFrameNoCacheAble>((char *) data, bytes, dts, 0, 7));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case STREAM_AUDIO_G711: {
|
||||||
|
_dts = dts;
|
||||||
|
//todo 等待陈大佬更新ts/ps解析库,现在暂时固定为G711A
|
||||||
|
auto codec = CodecG711A;
|
||||||
|
if (!_codecid_audio) {
|
||||||
|
//获取到音频
|
||||||
|
_codecid_audio = codecid;
|
||||||
|
InfoL << "got audio track: G711";
|
||||||
|
//G711传统只支持 8000/1/16的规格,FFmpeg貌似做了扩展,但是这里不管它了
|
||||||
|
auto track = std::make_shared<G711Track>(codec, 8000, 1, 16);
|
||||||
|
_muxer->addTrack(track);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codecid != _codecid_audio) {
|
||||||
|
WarnL << "audio track change to G711 from codecid:" << getCodecName(_codecid_audio);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_muxer->inputFrame(std::make_shared<G711FrameNoCacheAble>(codec, (char *) data, bytes, dts));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if(codecid != 0){
|
if(codecid != 0){
|
||||||
WarnL << "unsupported codec type:" << getCodecName(codecid);
|
WarnL << "unsupported codec type:" << getCodecName(codecid);
|
||||||
|
Loading…
Reference in New Issue
Block a user