2017-10-09 22:11:01 +08:00
|
|
|
|
/*
|
2017-09-27 16:20:30 +08:00
|
|
|
|
* MIT License
|
2017-04-01 16:35:56 +08:00
|
|
|
|
*
|
2017-09-27 16:20:30 +08:00
|
|
|
|
* 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.
|
2017-04-01 16:35:56 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef DEVICE_DEVICE_H_
|
|
|
|
|
#define DEVICE_DEVICE_H_
|
2017-04-25 11:35:41 +08:00
|
|
|
|
|
|
|
|
|
#include <memory>
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include "Util/util.h"
|
2018-08-29 11:19:00 +08:00
|
|
|
|
#include "Player/Player.h"
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#include "RTP/RtpMakerAAC.h"
|
|
|
|
|
#include "RTP/RtpMakerH264.h"
|
|
|
|
|
#include "Rtsp/RtspToRtmpMediaSource.h"
|
2018-10-23 22:18:25 +08:00
|
|
|
|
#include "Rtsp/RtspSdp.h"
|
2018-03-02 15:00:04 +08:00
|
|
|
|
#include "Util/TimeTicker.h"
|
2017-04-25 11:35:41 +08:00
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace ZL::Rtsp;
|
|
|
|
|
using namespace ZL::Util;
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_FAAC
|
|
|
|
|
#include "Codec/AACEncoder.h"
|
|
|
|
|
using namespace ZL::Codec;
|
|
|
|
|
#endif //ENABLE_FAAC
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_X264
|
|
|
|
|
#include "Codec/H264Encoder.h"
|
|
|
|
|
using namespace ZL::Codec;
|
|
|
|
|
#endif //ENABLE_X264
|
|
|
|
|
|
2018-02-02 18:06:08 +08:00
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
namespace ZL {
|
|
|
|
|
namespace DEV {
|
|
|
|
|
|
|
|
|
|
class VideoInfo {
|
|
|
|
|
public:
|
|
|
|
|
int iWidth;
|
|
|
|
|
int iHeight;
|
|
|
|
|
float iFrameRate;
|
|
|
|
|
};
|
|
|
|
|
class AudioInfo {
|
|
|
|
|
public:
|
|
|
|
|
int iChannel;
|
|
|
|
|
int iSampleBit;
|
|
|
|
|
int iSampleRate;
|
2018-08-29 11:19:00 +08:00
|
|
|
|
int iProfile;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
2018-02-02 18:06:08 +08:00
|
|
|
|
class DevChannel : public RtspToRtmpMediaSource{
|
2017-04-01 16:35:56 +08:00
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<DevChannel> Ptr;
|
2018-02-07 11:16:43 +08:00
|
|
|
|
//fDuration<=0为直播,否则为点播
|
|
|
|
|
DevChannel(const char *strVhost,
|
|
|
|
|
const char *strApp,
|
|
|
|
|
const char *strId,
|
|
|
|
|
float fDuration = 0,
|
|
|
|
|
bool bEanbleHls = true,
|
|
|
|
|
bool bEnableMp4 = false);
|
2017-04-01 16:35:56 +08:00
|
|
|
|
virtual ~DevChannel();
|
|
|
|
|
|
|
|
|
|
void initVideo(const VideoInfo &info);
|
|
|
|
|
void initAudio(const AudioInfo &info);
|
|
|
|
|
|
2018-08-29 11:19:00 +08:00
|
|
|
|
void inputH264(const char *pcData, int iDataLen, uint32_t uiStamp);
|
|
|
|
|
void inputAAC(const char *pcDataWithAdts, int iDataLen, uint32_t uiStamp, bool withAdtsHeader = true);
|
|
|
|
|
void inputAAC(const char *pcDataWithoutAdts,int iDataLen, uint32_t uiStamp,const char *pcAdtsHeader);
|
2018-02-07 11:16:43 +08:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_X264
|
|
|
|
|
void inputYUV(char *apcYuv[3], int aiYuvLen[3], uint32_t uiStamp);
|
|
|
|
|
#endif //ENABLE_X264
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_FAAC
|
|
|
|
|
void inputPCM(char *pcData, int iDataLen, uint32_t uiStamp);
|
|
|
|
|
#endif //ENABLE_FAAC
|
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
private:
|
|
|
|
|
inline void makeSDP_264(unsigned char *pucData, int iDataLen);
|
2017-12-19 10:34:52 +08:00
|
|
|
|
inline void makeSDP_AAC(unsigned char *pucData);
|
2017-04-01 16:35:56 +08:00
|
|
|
|
inline void makeSDP(const string& strSdp);
|
|
|
|
|
#ifdef ENABLE_X264
|
2018-10-24 15:43:52 +08:00
|
|
|
|
std::shared_ptr<H264Encoder> _pH264Enc;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#endif //ENABLE_X264
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_FAAC
|
2018-10-24 15:43:52 +08:00
|
|
|
|
std::shared_ptr<AACEncoder> _pAacEnc;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#endif //ENABLE_FAAC
|
2018-10-24 15:43:52 +08:00
|
|
|
|
RtpMaker_AAC::Ptr _pRtpMaker_aac;
|
|
|
|
|
RtpMaker_H264::Ptr _pRtpMaker_h264;
|
|
|
|
|
bool _bSdp_gotH264 = false;
|
|
|
|
|
bool _bSdp_gotAAC = false;
|
|
|
|
|
|
|
|
|
|
unsigned char _aucSPS[256];
|
|
|
|
|
unsigned int _uiSPSLen = 0;
|
|
|
|
|
unsigned char _aucPPS[256];
|
|
|
|
|
unsigned int _uiPPSLen = 0;
|
|
|
|
|
std::shared_ptr<VideoInfo> _video;
|
|
|
|
|
std::shared_ptr<AudioInfo> _audio;
|
|
|
|
|
SmoothTicker _aTicker[2];
|
|
|
|
|
std::shared_ptr<AACFrame> _pAdtsHeader;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} /* namespace DEV */
|
|
|
|
|
} /* namespace ZL */
|
|
|
|
|
|
|
|
|
|
#endif /* DEVICE_DEVICE_H_ */
|