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
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
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>
|
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
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit {
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2020-11-21 22:39:32 +08:00
|
|
|
|
class H264Encoder;
|
|
|
|
|
class AACEncoder;
|
|
|
|
|
|
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;
|
2022-05-25 15:11:26 +08:00
|
|
|
|
int iBitRate = 2 * 1024 * 1024;
|
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;
|
2020-05-18 15:31:49 +08:00
|
|
|
|
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:
|
2022-03-12 13:19:21 +08:00
|
|
|
|
using Ptr = std::shared_ptr<DevChannel>;
|
2018-10-29 11:48:24 +08:00
|
|
|
|
|
2022-03-12 13:19:21 +08:00
|
|
|
|
//fDuration<=0为直播,否则为点播
|
2023-05-25 16:23:24 +08:00
|
|
|
|
DevChannel(const MediaTuple& tuple, float duration = 0, const ProtocolOption &option = ProtocolOption())
|
|
|
|
|
: MultiMediaSourceMuxer(tuple, duration, option) {}
|
2022-03-12 13:19:21 +08:00
|
|
|
|
~DevChannel() override = default;
|
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
|
|
|
|
*/
|
2021-09-27 14:34:26 +08:00
|
|
|
|
bool initVideo(const VideoInfo &info);
|
2018-10-29 11:48:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
*/
|
2021-09-27 14:34:26 +08:00
|
|
|
|
bool initAudio(const AudioInfo &info);
|
2020-03-20 11:51:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入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 播放时间戳,单位毫秒;等于0时内部会赋值为dts
|
|
|
|
|
*/
|
2022-08-08 17:13:39 +08:00
|
|
|
|
bool inputH264(const char *data, int len, uint64_t dts, uint64_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 播放时间戳,单位毫秒;等于0时内部会赋值为dts
|
|
|
|
|
*/
|
2022-08-08 17:13:39 +08:00
|
|
|
|
bool inputH265(const char *data, int len, uint64_t dts, uint64_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
|
|
|
|
*/
|
2022-08-08 17:13:39 +08:00
|
|
|
|
bool inputAAC(const char *data_without_adts, int len, uint64_t dts, const char *adts_header);
|
2018-02-07 11:16:43 +08:00
|
|
|
|
|
2020-04-08 15:42:52 +08:00
|
|
|
|
/**
|
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-04-08 15:42:52 +08:00
|
|
|
|
*/
|
2022-08-08 17:13:39 +08:00
|
|
|
|
bool inputAudio(const char *data, int len, uint64_t dts);
|
2020-04-18 23:56:27 +08:00
|
|
|
|
|
2020-03-20 11:51:24 +08:00
|
|
|
|
/**
|
|
|
|
|
* 输入yuv420p视频帧,内部会完成编码并调用inputH264方法
|
2022-05-25 15:11:26 +08:00
|
|
|
|
* @param yuv yuv420p数据指针
|
|
|
|
|
* @param linesize yuv420p数据linesize
|
|
|
|
|
* @param cts 采集时间戳,单位毫秒
|
2020-03-20 11:51:24 +08:00
|
|
|
|
*/
|
2022-08-08 17:13:39 +08:00
|
|
|
|
bool inputYUV(char *yuv[3], int linesize[3], uint64_t cts);
|
2018-10-29 11:48:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输入pcm数据,内部会完成编码并调用inputAAC方法
|
2022-05-25 15:11:26 +08:00
|
|
|
|
* @param data pcm数据指针,int16整形
|
|
|
|
|
* @param len pcm数据长度
|
|
|
|
|
* @param cts 采集时间戳,单位毫秒
|
2018-10-29 11:48:24 +08:00
|
|
|
|
*/
|
2022-08-08 17:13:39 +08:00
|
|
|
|
bool inputPCM(char *data, int len, uint64_t cts);
|
2018-02-07 11:16:43 +08:00
|
|
|
|
|
2023-03-11 11:02:20 +08:00
|
|
|
|
//// 重载基类方法,确保线程安全 ////
|
|
|
|
|
bool inputFrame(const Frame::Ptr &frame) override;
|
|
|
|
|
bool addTrack(const Track::Ptr & track) override;
|
|
|
|
|
void addTrackCompleted() override;
|
|
|
|
|
|
2020-09-27 11:32:49 +08:00
|
|
|
|
private:
|
|
|
|
|
MediaOriginType getOriginType(MediaSource &sender) const override;
|
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
private:
|
2020-03-20 11:51:24 +08:00
|
|
|
|
std::shared_ptr<H264Encoder> _pH264Enc;
|
|
|
|
|
std::shared_ptr<AACEncoder> _pAacEnc;
|
2018-10-29 11:48:24 +08:00
|
|
|
|
std::shared_ptr<VideoInfo> _video;
|
|
|
|
|
std::shared_ptr<AudioInfo> _audio;
|
2022-02-02 20:34:50 +08:00
|
|
|
|
toolkit::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_ */
|