Device.h 3.73 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2
 * MIT License
xzl committed
3
 *
xiongziliang committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * 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.
xzl committed
25 26 27 28
 */

#ifndef DEVICE_DEVICE_H_
#define DEVICE_DEVICE_H_
xiongzilaing committed
29 30

#include <memory>
xzl committed
31 32 33
#include <string>
#include <functional>
#include "Util/util.h"
34
#include "Player/Player.h"
xzl committed
35 36 37
#include "RTP/RtpMakerAAC.h"
#include "RTP/RtpMakerH264.h"
#include "Rtsp/RtspToRtmpMediaSource.h"
38
#include "Rtsp/RtspEncoder.h"
xiongziliang committed
39
#include "Util/TimeTicker.h"
xiongzilaing committed
40

xzl committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54
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

55

xzl committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69
namespace ZL {
namespace DEV {

class VideoInfo {
public:
	int iWidth;
	int iHeight;
	float iFrameRate;
};
class AudioInfo {
public:
	int iChannel;
	int iSampleBit;
	int iSampleRate;
70
	int iProfile;
xzl committed
71 72
};

73
class DevChannel  : public RtspToRtmpMediaSource{
xzl committed
74 75
public:
	typedef std::shared_ptr<DevChannel> Ptr;
76 77 78 79 80 81 82
    //fDuration<=0为直播,否则为点播
	DevChannel(const char *strVhost,
               const char *strApp,
               const char *strId,
               float fDuration = 0,
               bool bEanbleHls = true,
               bool bEnableMp4 = false);
xzl committed
83 84 85 86 87
	virtual ~DevChannel();

	void initVideo(const VideoInfo &info);
	void initAudio(const AudioInfo &info);

88 89 90
	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);
91 92 93 94 95 96 97 98 99

#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

xzl committed
100 101
private:
	inline void makeSDP_264(unsigned char *pucData, int iDataLen);
102
	inline void makeSDP_AAC(unsigned char *pucData);
xzl committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
	inline void makeSDP(const string& strSdp);
#ifdef ENABLE_X264
	std::shared_ptr<H264Encoder> m_pH264Enc;
#endif //ENABLE_X264

#ifdef ENABLE_FAAC
	std::shared_ptr<AACEncoder> m_pAacEnc;
#endif //ENABLE_FAAC
	RtpMaker_AAC::Ptr m_pRtpMaker_aac;
	RtpMaker_H264::Ptr m_pRtpMaker_h264;
	bool m_bSdp_gotH264 = false;
	bool m_bSdp_gotAAC = false;

	unsigned char m_aucSPS[256];
	unsigned int m_uiSPSLen = 0;
	unsigned char m_aucPPS[256];
	unsigned int m_uiPPSLen = 0;
	std::shared_ptr<VideoInfo> m_video;
	std::shared_ptr<AudioInfo> m_audio;
xiongziliang committed
122
    SmoothTicker m_aTicker[2];
123
	std::shared_ptr<AACFrame> m_pAdtsHeader;
xzl committed
124 125 126 127 128 129 130
};


} /* namespace DEV */
} /* namespace ZL */

#endif /* DEVICE_DEVICE_H_ */