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
|
|
|
|
*
|
2019-05-08 15:40:07 +08:00
|
|
|
|
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
|
|
|
|
* 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-03-02 15:00:04 +08:00
|
|
|
|
#include "Util/TimeTicker.h"
|
2018-10-26 16:09:48 +08:00
|
|
|
|
#include "Common/MultiMediaSourceMuxer.h"
|
2017-04-25 11:35:41 +08:00
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
using namespace std;
|
2018-10-24 17:17:55 +08:00
|
|
|
|
using namespace toolkit;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2018-10-26 16:09:48 +08:00
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#ifdef ENABLE_FAAC
|
|
|
|
|
#include "Codec/AACEncoder.h"
|
|
|
|
|
#endif //ENABLE_FAAC
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_X264
|
|
|
|
|
#include "Codec/H264Encoder.h"
|
|
|
|
|
#endif //ENABLE_X264
|
|
|
|
|
|
2018-02-02 18:06:08 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit {
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
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-10-29 11:48:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 该类已经废弃,保留只为兼容旧代码,请直接使用MultiMediaSourceMuxer类!
|
|
|
|
|
*/
|
|
|
|
|
class DevChannel : public MultiMediaSourceMuxer{
|
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为直播,否则为点播
|
2019-03-27 18:41:52 +08:00
|
|
|
|
DevChannel(const string &strVhost,
|
|
|
|
|
const string &strApp,
|
|
|
|
|
const string &strId,
|
2018-02-07 11:16:43 +08:00
|
|
|
|
float fDuration = 0,
|
|
|
|
|
bool bEanbleHls = true,
|
|
|
|
|
bool bEnableMp4 = false);
|
2018-10-29 11:48:24 +08:00
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
virtual ~DevChannel();
|
|
|
|
|
|
2018-10-29 11:48:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 初始化h264视频Track
|
|
|
|
|
* 相当于MultiMediaSourceMuxer::addTrack(H264Track::Ptr );
|
|
|
|
|
* @param info
|
|
|
|
|
*/
|
|
|
|
|
void initVideo(const VideoInfo &info);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化aac音频Track
|
|
|
|
|
* 相当于MultiMediaSourceMuxer::addTrack(AACTrack::Ptr );
|
|
|
|
|
* @param info
|
|
|
|
|
*/
|
2017-04-01 16:35:56 +08:00
|
|
|
|
void initAudio(const AudioInfo &info);
|
|
|
|
|
|
2018-10-29 11:48:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 输入264帧
|
|
|
|
|
* @param pcData 264单帧数据指针
|
|
|
|
|
* @param iDataLen 数据指针长度
|
2018-10-29 11:50:36 +08:00
|
|
|
|
* @param uiStamp 时间戳,单位毫秒;等于0时内部会自动生成时间戳
|
2018-10-29 11:48:24 +08:00
|
|
|
|
*/
|
2018-10-29 12:27:13 +08:00
|
|
|
|
void inputH264(const char *pcData, int iDataLen, uint32_t uiStamp);
|
2018-10-29 11:48:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入可能带adts头的aac帧
|
|
|
|
|
* @param pcDataWithAdts 可能带adts头的aac帧
|
|
|
|
|
* @param iDataLen 帧数据长度
|
2018-10-29 11:50:36 +08:00
|
|
|
|
* @param uiStamp 时间戳,单位毫秒,等于0时内部会自动生成时间戳
|
2018-10-29 11:48:24 +08:00
|
|
|
|
* @param withAdtsHeader 是否带adts头
|
|
|
|
|
*/
|
2018-08-29 11:19:00 +08:00
|
|
|
|
void inputAAC(const char *pcDataWithAdts, int iDataLen, uint32_t uiStamp, bool withAdtsHeader = true);
|
2018-10-29 11:48:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入不带adts头的aac帧
|
|
|
|
|
* @param pcDataWithoutAdts 不带adts头的aac帧
|
|
|
|
|
* @param iDataLen 帧数据长度
|
|
|
|
|
* @param uiStamp 时间戳,单位毫秒
|
|
|
|
|
* @param pcAdtsHeader adts头
|
|
|
|
|
*/
|
2018-08-29 11:19:00 +08:00
|
|
|
|
void inputAAC(const char *pcDataWithoutAdts,int iDataLen, uint32_t uiStamp,const char *pcAdtsHeader);
|
2018-02-07 11:16:43 +08:00
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_X264
|
2018-10-29 11:48:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 输入yuv420p视频帧,内部会完成编码并调用inputH264方法
|
|
|
|
|
* @param apcYuv
|
|
|
|
|
* @param aiYuvLen
|
|
|
|
|
* @param uiStamp
|
|
|
|
|
*/
|
|
|
|
|
void inputYUV(char *apcYuv[3], int aiYuvLen[3], uint32_t uiStamp);
|
2018-02-07 11:16:43 +08:00
|
|
|
|
#endif //ENABLE_X264
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_FAAC
|
2018-10-29 11:48:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入pcm数据,内部会完成编码并调用inputAAC方法
|
|
|
|
|
* @param pcData
|
|
|
|
|
* @param iDataLen
|
|
|
|
|
* @param uiStamp
|
|
|
|
|
*/
|
|
|
|
|
void inputPCM(char *pcData, int iDataLen, uint32_t uiStamp);
|
2018-02-07 11:16:43 +08:00
|
|
|
|
#endif //ENABLE_FAAC
|
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
private:
|
|
|
|
|
#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-29 11:48:24 +08:00
|
|
|
|
std::shared_ptr<VideoInfo> _video;
|
|
|
|
|
std::shared_ptr<AudioInfo> _audio;
|
|
|
|
|
|
2018-10-24 15:43:52 +08:00
|
|
|
|
SmoothTicker _aTicker[2];
|
2018-10-29 11:48:24 +08:00
|
|
|
|
uint8_t _adtsHeader[7];
|
2017-04-01 16:35:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
} /* namespace mediakit */
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
#endif /* DEVICE_DEVICE_H_ */
|