Device.h 4.39 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2
 * MIT License
xzl committed
3
 *
xiongziliang committed
4
 * Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
xiongziliang committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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"
xiongziliang committed
34
#include "Util/TimeTicker.h"
35
#include "Common/MultiMediaSourceMuxer.h"
xiongzilaing committed
36

xzl committed
37
using namespace std;
xiongziliang committed
38
using namespace toolkit;
xzl committed
39

40

xzl committed
41 42 43 44 45 46 47 48
#ifdef ENABLE_FAAC
#include "Codec/AACEncoder.h"
#endif //ENABLE_FAAC

#ifdef ENABLE_X264
#include "Codec/H264Encoder.h"
#endif //ENABLE_X264

49

xiongziliang committed
50
namespace mediakit {
xzl committed
51 52 53 54 55 56 57 58 59 60 61 62

class VideoInfo {
public:
	int iWidth;
	int iHeight;
	float iFrameRate;
};
class AudioInfo {
public:
	int iChannel;
	int iSampleBit;
	int iSampleRate;
63
	int iProfile;
xzl committed
64 65
};

66 67 68 69
/**
 * 该类已经废弃,保留只为兼容旧代码,请直接使用MultiMediaSourceMuxer类!
 */
class DevChannel  : public MultiMediaSourceMuxer{
xzl committed
70 71
public:
	typedef std::shared_ptr<DevChannel> Ptr;
72
    //fDuration<=0为直播,否则为点播
xiongziliang committed
73 74 75
    DevChannel(const string &strVhost,
               const string &strApp,
               const string &strId,
76 77 78
               float fDuration = 0,
               bool bEanbleHls = true,
               bool bEnableMp4 = false);
79

xzl committed
80 81
	virtual ~DevChannel();

82 83 84 85 86 87 88 89 90 91 92 93
	/**
	 * 初始化h264视频Track
	 * 相当于MultiMediaSourceMuxer::addTrack(H264Track::Ptr );
	 * @param info
	 */
    void initVideo(const VideoInfo &info);

    /**
     * 初始化aac音频Track
     * 相当于MultiMediaSourceMuxer::addTrack(AACTrack::Ptr );
     * @param info
     */
xzl committed
94 95
	void initAudio(const AudioInfo &info);

96 97 98 99
	/**
	 * 输入264帧
	 * @param pcData 264单帧数据指针
	 * @param iDataLen 数据指针长度
xiongziliang committed
100
	 * @param uiStamp 时间戳,单位毫秒;等于0时内部会自动生成时间戳
101
	 */
102
	void inputH264(const char *pcData, int iDataLen, uint32_t uiStamp);
103 104 105 106 107

	/**
	 * 输入可能带adts头的aac帧
	 * @param pcDataWithAdts 可能带adts头的aac帧
	 * @param iDataLen 帧数据长度
xiongziliang committed
108
	 * @param uiStamp 时间戳,单位毫秒,等于0时内部会自动生成时间戳
109 110
	 * @param withAdtsHeader 是否带adts头
	 */
111
	void inputAAC(const char *pcDataWithAdts, int iDataLen, uint32_t uiStamp, bool withAdtsHeader = true);
112 113 114 115 116 117 118 119

	/**
	 * 输入不带adts头的aac帧
	 * @param pcDataWithoutAdts 不带adts头的aac帧
	 * @param iDataLen 帧数据长度
	 * @param uiStamp 时间戳,单位毫秒
	 * @param pcAdtsHeader adts头
	 */
120
	void inputAAC(const char *pcDataWithoutAdts,int iDataLen, uint32_t uiStamp,const char *pcAdtsHeader);
121 122

#ifdef ENABLE_X264
123 124 125 126 127 128 129
	/**
	 * 输入yuv420p视频帧,内部会完成编码并调用inputH264方法
	 * @param apcYuv
	 * @param aiYuvLen
	 * @param uiStamp
	 */
    void inputYUV(char *apcYuv[3], int aiYuvLen[3], uint32_t uiStamp);
130 131 132
#endif //ENABLE_X264

#ifdef ENABLE_FAAC
133 134 135 136 137 138 139 140

    /**
     * 输入pcm数据,内部会完成编码并调用inputAAC方法
     * @param pcData
     * @param iDataLen
     * @param uiStamp
     */
    void inputPCM(char *pcData, int iDataLen, uint32_t uiStamp);
141 142
#endif //ENABLE_FAAC

xzl committed
143 144
private:
#ifdef ENABLE_X264
145
	std::shared_ptr<H264Encoder> _pH264Enc;
xzl committed
146 147 148
#endif //ENABLE_X264

#ifdef ENABLE_FAAC
149
	std::shared_ptr<AACEncoder> _pAacEnc;
xzl committed
150
#endif //ENABLE_FAAC
151 152 153
    std::shared_ptr<VideoInfo> _video;
    std::shared_ptr<AudioInfo> _audio;

154
    SmoothTicker _aTicker[2];
155
    uint8_t _adtsHeader[7];
xzl committed
156 157
};

xiongziliang committed
158
} /* namespace mediakit */
xzl committed
159 160

#endif /* DEVICE_DEVICE_H_ */