RtmpDemuxer.h 1.65 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
xiongziliang committed
3
 *
4
 * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
xiongziliang committed
5
 *
xiongziliang committed
6 7 8
 * 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.
xzl committed
9 10
 */

11 12
#ifndef SRC_RTMP_RTMPDEMUXER_H_
#define SRC_RTMP_RTMPDEMUXER_H_
xzl committed
13

xiongzilaing committed
14 15
#include <functional>
#include <unordered_map>
16 17
#include "Rtmp/amf.h"
#include "Rtmp/Rtmp.h"
xzl committed
18
#include "Player/PlayerBase.h"
xiongziliang committed
19 20
#include "Util/TimeTicker.h"
#include "RtmpCodec.h"
xiongzilaing committed
21

xiongziliang committed
22
using namespace toolkit;
23

xiongziliang committed
24
namespace mediakit {
xzl committed
25

26
class RtmpDemuxer : public Demuxer {
xzl committed
27
public:
28
    using Ptr = std::shared_ptr<RtmpDemuxer>;
29

30
    RtmpDemuxer() = default;
xiongziliang committed
31
    ~RtmpDemuxer() override = default;
32

33 34
    static size_t trackCount(const AMFValue &metadata);

35
    bool loadMetaData(const AMFValue &metadata);
36

37 38 39 40
    /**
     * 开始解复用
     * @param pkt rtmp包
     */
41
    void inputRtmp(const RtmpPacket::Ptr &pkt);
xiongziliang committed
42

43 44 45 46 47 48
    /**
     * 获取节目总时长
     * @return 节目总时长,单位秒
     */
    float getDuration() const;

xiongziliang committed
49
private:
xiongziliang committed
50 51
    void makeVideoTrack(const AMFValue &val, int bit_rate);
    void makeAudioTrack(const AMFValue &val, int sample_rate, int channels, int sample_bit, int bit_rate);
xiongziliang committed
52

xiongziliang committed
53
private:
xiongziliang committed
54 55
    bool _try_get_video_track = false;
    bool _try_get_audio_track = false;
56 57 58
    float _duration = 0;
    AudioTrack::Ptr _audio_track;
    VideoTrack::Ptr _video_track;
xiongziliang committed
59 60
    RtmpCodec::Ptr _audio_rtmp_decoder;
    RtmpCodec::Ptr _video_rtmp_decoder;
xzl committed
61 62
};

xiongziliang committed
63
} /* namespace mediakit */
xzl committed
64

65
#endif /* SRC_RTMP_RTMPDEMUXER_H_ */