ZLMediaKit/src/Common/Device.h

148 lines
3.9 KiB
C++
Raw Normal View History

2017-10-09 22:11:01 +08:00
/*
2020-04-04 20:30:09 +08:00
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
2017-09-27 16:20:30 +08:00
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
2020-04-04 20:30:09 +08:00
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
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-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
#ifdef ENABLE_FAAC
#include "Codec/AACEncoder.h"
#endif //ENABLE_FAAC
#ifdef ENABLE_X264
#include "Codec/H264Encoder.h"
#endif //ENABLE_X264
2018-10-24 17:17:55 +08:00
namespace mediakit {
2017-04-01 16:35:56 +08:00
class VideoInfo {
public:
2020-04-18 18:46:20 +08:00
CodecId codecId = CodecH264;
2020-03-20 11:51:24 +08:00
int iWidth;
int iHeight;
float iFrameRate;
2017-04-01 16:35:56 +08:00
};
2020-04-18 23:56:27 +08:00
2017-04-01 16:35:56 +08:00
class AudioInfo {
public:
2020-04-18 18:46:20 +08:00
CodecId codecId = CodecAAC;
int iChannel;
int iSampleBit;
int iSampleRate;
2017-04-01 16:35:56 +08:00
};
2018-10-29 11:48:24 +08:00
/**
2020-04-18 23:56:27 +08:00
* MultiMediaSourceMuxer类的包装便使
2018-10-29 11:48:24 +08:00
*/
class DevChannel : public MultiMediaSourceMuxer{
2017-04-01 16:35:56 +08:00
public:
2020-03-20 11:51:24 +08:00
typedef std::shared_ptr<DevChannel> Ptr;
//fDuration<=0为直播否则为点播
2020-09-20 09:26:00 +08:00
DevChannel(const string &vhost, const string &app, const string &stream_id,
float duration = 0, bool enable_hls = true, bool enable_mp4 = false);
2018-10-29 11:48:24 +08:00
2020-08-01 10:22:12 +08:00
~DevChannel() override ;
2017-04-01 16:35:56 +08:00
2020-03-20 11:51:24 +08:00
/**
2020-04-18 23:56:27 +08:00
* Track
* MultiMediaSourceMuxer::addTrack(VideoTrack::Ptr );
2020-04-18 18:46:20 +08:00
* @param info
2020-03-20 11:51:24 +08:00
*/
2018-10-29 11:48:24 +08:00
void initVideo(const VideoInfo &info);
/**
2020-04-18 23:56:27 +08:00
* Track
* MultiMediaSourceMuxer::addTrack(AudioTrack::Ptr );
2020-04-18 18:46:20 +08:00
* @param info
2018-10-29 11:48:24 +08:00
*/
2020-03-20 11:51:24 +08:00
void initAudio(const AudioInfo &info);
/**
* 264
2020-04-18 23:56:27 +08:00
* @param data 264
* @param len
2020-03-20 11:51:24 +08:00
* @param dts 0
* @param pts 0dts
*/
2020-04-18 23:56:27 +08:00
void inputH264(const char *data, int len, uint32_t dts, uint32_t pts = 0);
2020-03-20 11:51:24 +08:00
/**
* 265
2020-04-18 23:56:27 +08:00
* @param data 265
* @param len
2020-03-20 11:51:24 +08:00
* @param dts 0
* @param pts 0dts
*/
2020-04-18 23:56:27 +08:00
void inputH265(const char *data, int len, uint32_t dts, uint32_t pts = 0);
2020-03-20 11:51:24 +08:00
/**
2020-04-18 23:56:27 +08:00
* aac帧
* @param data_without_adts adts头的aac帧
* @param len
* @param dts
* @param adts_header adts头
2020-03-20 11:51:24 +08:00
*/
2020-04-18 23:56:27 +08:00
void inputAAC(const char *data_without_adts, int len, uint32_t dts, const char *adts_header);
/**
2020-08-01 10:22:12 +08:00
* OPUS/G711音频帧
2020-04-18 23:56:27 +08:00
* @param data
* @param len
* @param dts
*/
2020-08-01 10:22:12 +08:00
void inputAudio(const char *data, int len, uint32_t dts);
2020-04-18 23:56:27 +08:00
#ifdef ENABLE_X264
2020-03-20 11:51:24 +08:00
/**
* yuv420p视频帧inputH264方法
* @param apcYuv
* @param aiYuvLen
* @param uiStamp
*/
2018-10-29 11:48:24 +08:00
void inputYUV(char *apcYuv[3], int aiYuvLen[3], uint32_t uiStamp);
#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);
#endif //ENABLE_FAAC
2017-04-01 16:35:56 +08:00
private:
2020-04-18 23:56:27 +08:00
2017-04-01 16:35:56 +08:00
#ifdef ENABLE_X264
2020-03-20 11:51:24 +08:00
std::shared_ptr<H264Encoder> _pH264Enc;
2017-04-01 16:35:56 +08:00
#endif //ENABLE_X264
#ifdef ENABLE_FAAC
2020-03-20 11:51:24 +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];
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_ */