RtmpDemuxer.h 2.45 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 SRC_RTMP_RTMPDEMUXER_H_
#define SRC_RTMP_RTMPDEMUXER_H_
xzl committed
29

xiongzilaing committed
30 31
#include <functional>
#include <unordered_map>
32 33
#include "Rtmp/amf.h"
#include "Rtmp/Rtmp.h"
xzl committed
34
#include "Player/PlayerBase.h"
xiongziliang committed
35 36
#include "Util/TimeTicker.h"
#include "RtmpCodec.h"
xiongzilaing committed
37

xiongziliang committed
38
using namespace toolkit;
39

xiongziliang committed
40
namespace mediakit {
xzl committed
41

42
class RtmpDemuxer : public Demuxer{
xzl committed
43
public:
44
	typedef std::shared_ptr<RtmpDemuxer> Ptr;
45 46 47 48 49 50 51 52 53 54

	/**
	 * 等效于RtmpDemuxer(AMFValue(AMF_NULL))
	 */
	RtmpDemuxer(){}
	/**
	 * 构造rtmp解复用器
	 * @param val rtmp的metedata,可以传入null类型,
	 * 这样就会在inputRtmp时异步探测媒体编码格式
	 */
55
	RtmpDemuxer(const AMFValue &val);
56
	virtual ~RtmpDemuxer(){};
57

58 59 60 61 62 63 64 65
	/**
	 *
	 * 获取rtmp track 数
	 * @param metedata rtmp的metedata
	 * @return
	 */
	static int getTrackCount(const AMFValue &metedata);

xiongziliang committed
66 67 68 69 70
	/**
	 * 开始解复用
	 * @param pkt rtmp包
	 * @return true 代表是i帧
	 */
xiongziliang committed
71
	bool inputRtmp(const RtmpPacket::Ptr &pkt);
xiongziliang committed
72 73 74 75
private:
	void makeVideoTrack(const AMFValue &val);
	void makeAudioTrack(const AMFValue &val);
private:
76 77
	bool _tryedGetVideoTrack = false;
	bool _tryedGetAudioTrack = false;
xiongziliang committed
78 79
	RtmpCodec::Ptr _audioRtmpDecoder;
	RtmpCodec::Ptr _videoRtmpDecoder;
xzl committed
80 81
};

xiongziliang committed
82
} /* namespace mediakit */
xzl committed
83

xiongziliang committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
















100
#endif /* SRC_RTMP_RTMPDEMUXER_H_ */