RtspPlayerImp.h 2.26 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 13 14
 */

#ifndef SRC_RTP_RTPPARSERTESTER_H_
#define SRC_RTP_RTPPARSERTESTER_H_

#include <memory>
xiongzilaing committed
15 16 17
#include <algorithm>
#include <functional>
#include "RtspPlayer.h"
18 19
#include "RtspDemuxer.h"
#include "RtspMediaSource.h"
xzl committed
20

xiongziliang committed
21
namespace mediakit {
22

23
class RtspPlayerImp : public PlayerImp<RtspPlayer, PlayerBase> ,private TrackListener {
xzl committed
24
public:
25 26
    using Ptr = std::shared_ptr<RtspPlayerImp>;
    using Super = PlayerImp<RtspPlayer, PlayerBase>;
xiongziliang committed
27

夏楚 committed
28
    RtspPlayerImp(const toolkit::EventPoller::Ptr &poller) : Super(poller) {}
29 30

    ~RtspPlayerImp() override {
xia-chu committed
31
        DebugL;
xiongziliang committed
32 33 34 35
    }

    float getProgress() const override {
        if (getDuration() > 0) {
36
            return getProgressMilliSecond() / (getDuration() * 1000);
xzl committed
37
        }
xiongziliang committed
38
        return PlayerBase::getProgress();
xiongziliang committed
39 40
    }

41 42 43 44 45
    uint32_t getProgressPos() const override {
        if (getDuration() > 0) {
            return getProgressMilliSecond();
        }
        return PlayerBase::getProgressPos();
ziyue committed
46
    }
47

ziyue committed
48 49 50
    void seekTo(float fProgress) override {
        fProgress = MAX(float(0), MIN(fProgress, float(1.0)));
        seekToMilliSecond((uint32_t) (fProgress * getDuration() * 1000));
51 52 53
    }

    void seekTo(uint32_t seekPos) override {
54
        uint32_t pos = MAX(float(0), MIN(seekPos, getDuration())) * 1000;
55
        seekToMilliSecond(pos);
xiongziliang committed
56 57
    }

mtdxc committed
58
    float getDuration() const override;
59

mtdxc committed
60
    std::vector<Track::Ptr> getTracks(bool ready = true) const override;
61

xzl committed
62
private:
63
    //派生类回调函数
mtdxc committed
64
    bool onCheckSDP(const std::string &sdp) override;
xiongziliang committed
65

mtdxc committed
66
    void onRecvRTP(RtpPacket::Ptr rtp, const SdpTrack::Ptr &track) override;
xiongziliang committed
67

mtdxc committed
68
    void onPlayResult(const toolkit::SockException &ex) override;
xiongziliang committed
69

70 71
    bool addTrack(const Track::Ptr &track) override { return true; }

mtdxc committed
72
    void addTrackCompleted() override;
73

xiongziliang committed
74
private:
75 76
    RtspDemuxer::Ptr _demuxer;
    RtspMediaSource::Ptr _rtsp_media_src;
xzl committed
77 78
};

xiongziliang committed
79
} /* namespace mediakit */
xzl committed
80 81

#endif /* SRC_RTP_RTPPARSERTESTER_H_ */