ZLMediaKit/src/RtspMuxer/AACRtpCodec.h

102 lines
3.1 KiB
C
Raw Normal View History

2018-10-25 10:00:17 +08:00
/*
* MIT License
*
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
2018-10-18 23:48:00 +08:00
#ifndef ZLMEDIAKIT_AACRTPCODEC_H
#define ZLMEDIAKIT_AACRTPCODEC_H
#include "RtpCodec.h"
2018-10-30 14:59:42 +08:00
#include "Extension/AAC.h"
2018-10-24 17:17:55 +08:00
namespace mediakit{
2018-10-21 22:24:24 +08:00
/**
* aac rtp转adts类
*/
2018-10-24 12:01:40 +08:00
class AACRtpDecoder : public RtpCodec , public ResourcePoolHelper<AACFrame> {
2018-10-18 23:48:00 +08:00
public:
2018-10-23 18:39:17 +08:00
typedef std::shared_ptr<AACRtpDecoder> Ptr;
2019-01-24 12:21:29 +08:00
AACRtpDecoder(const Track::Ptr &track);
2018-10-21 21:45:44 +08:00
~AACRtpDecoder() {}
2018-10-21 22:24:24 +08:00
/**
* rtp并解码
* @param rtp rtp数据包
* @param key_pos false,
*/
2018-10-23 18:39:17 +08:00
bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = false) override;
2018-10-23 11:09:21 +08:00
TrackType getTrackType() const override{
return TrackAudio;
}
CodecId getCodecId() const override{
return CodecAAC;
}
2019-01-24 12:21:29 +08:00
protected:
AACRtpDecoder();
2018-10-18 23:48:00 +08:00
private:
2018-10-24 14:21:59 +08:00
void onGetAAC(const AACFrame::Ptr &frame);
2018-10-23 11:09:21 +08:00
AACFrame::Ptr obtainFrame();
2018-10-18 23:48:00 +08:00
private:
2018-10-24 15:43:52 +08:00
AACFrame::Ptr _adts;
2019-01-24 12:21:29 +08:00
string _aac_cfg;
2018-10-18 23:48:00 +08:00
};
2018-10-21 22:24:24 +08:00
/**
* aac adts转rtp类
*/
2018-10-23 11:38:56 +08:00
class AACRtpEncoder : public AACRtpDecoder , public RtpInfo {
2018-10-21 21:45:44 +08:00
public:
2018-10-23 18:39:17 +08:00
typedef std::shared_ptr<AACRtpEncoder> Ptr;
2018-10-21 22:24:24 +08:00
/**
* @param ui32Ssrc ssrc
* @param ui32MtuSize mtu
* @param ui32SampleRate
* @param ui8PlayloadType pt类型
* @param ui8Interleaved rtsp interleaved
*/
2018-10-21 21:45:44 +08:00
AACRtpEncoder(uint32_t ui32Ssrc,
uint32_t ui32MtuSize,
uint32_t ui32SampleRate,
uint8_t ui8PlayloadType = 97,
uint8_t ui8Interleaved = TrackAudio * 2);
~AACRtpEncoder() {}
2018-10-21 22:24:24 +08:00
/**
* aac dats头
* @param frame dats头的aac数据
*/
2018-10-23 21:41:45 +08:00
void inputFrame(const Frame::Ptr &frame) override;
2018-10-21 21:45:44 +08:00
private:
void makeAACRtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
private:
2018-10-24 15:43:52 +08:00
unsigned char _aucSectionBuf[1600];
2018-10-21 21:45:44 +08:00
};
2018-10-24 17:17:55 +08:00
}//namespace mediakit
2018-10-21 21:21:14 +08:00
2018-10-18 23:48:00 +08:00
#endif //ZLMEDIAKIT_AACRTPCODEC_H