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

11 12
#ifndef ZLMEDIAKIT_RTPSESSION_H
#define ZLMEDIAKIT_RTPSESSION_H
Gemfield committed
13

14
#if defined(ENABLE_RTPPROXY)
夏楚 committed
15

16
#include "Network/Session.h"
Gemfield committed
17 18 19 20
#include "RtpSplitter.h"
#include "RtpProcess.h"
#include "Util/TimeTicker.h"

21 22
namespace mediakit{

夏楚 committed
23
class RtpSession : public toolkit::Session, public RtpSplitter, public MediaSourceEvent {
Gemfield committed
24
public:
夏楚 committed
25
    static const std::string kStreamID;
26
    static const std::string kSSRC;
27
    static const std::string kOnlyAudio;
28

夏楚 committed
29
    RtpSession(const toolkit::Socket::Ptr &sock);
Gemfield committed
30
    ~RtpSession() override;
夏楚 committed
31 32
    void onRecv(const toolkit::Buffer::Ptr &) override;
    void onError(const toolkit::SockException &err) override;
Gemfield committed
33
    void onManager() override;
34
    void setParams(toolkit::mINI &ini);
夏楚 committed
35
    void attachServer(const toolkit::Server &server) override;
36

37 38
protected:
    // 通知其停止推流
39
    bool close(MediaSource &sender) override;
xiongziliang committed
40
    // 收到rtp回调
41
    void onRtpPacket(const char *data, size_t len) override;
42
    // RtpSplitter override
43 44
    const char *onSearchPacketTail(const char *data, size_t len) override;

Gemfield committed
45
private:
46
    bool _delay_close = false;
47
    bool _is_udp = false;
48 49
    bool _search_rtp = false;
    bool _search_rtp_finished = false;
50
    bool _only_audio = false;
51
    uint32_t _ssrc = 0;
夏楚 committed
52 53
    toolkit::Ticker _ticker;
    std::string _stream_id;
xiongziliang committed
54
    struct sockaddr_storage _addr;
xiongziliang committed
55
    RtpProcess::Ptr _process;
Gemfield committed
56 57
};

58 59 60
}//namespace mediakit
#endif//defined(ENABLE_RTPPROXY)
#endif //ZLMEDIAKIT_RTPSESSION_H