RtpProcess.h 2.84 KB
Newer Older
Gemfield committed
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * MIT License
 *
 * Copyright (c) 2019 Gemfield <gemfield@civilnet.cn>
 *
 * 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.
 */
Gemfield committed
26

27 28 29 30
#ifndef ZLMEDIAKIT_RTPPROCESS_H
#define ZLMEDIAKIT_RTPPROCESS_H

#if defined(ENABLE_RTPPROXY)
Gemfield committed
31 32 33 34 35

#include "Rtsp/RtpReceiver.h"
#include "RtpDecoder.h"
#include "PSDecoder.h"
#include "Common/Device.h"
36
#include "Common/Stamp.h"
Gemfield committed
37 38
using namespace mediakit;

39 40
namespace mediakit{

Gemfield committed
41
string printSSRC(uint32_t ui32Ssrc);
42
class FrameMerger;
Gemfield committed
43 44 45 46 47
class RtpProcess : public RtpReceiver , public RtpDecoder , public PSDecoder {
public:
    typedef std::shared_ptr<RtpProcess> Ptr;
    RtpProcess(uint32_t ssrc);
    ~RtpProcess();
48
    bool inputRtp(const char *data,int data_len, const struct sockaddr *addr , uint32_t *dts_out = nullptr);
Gemfield committed
49 50 51 52 53 54 55 56 57 58 59 60
    bool alive();
    string get_peer_ip();
    uint16_t get_peer_port();
protected:
    void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index) override ;
    void onRtpDecode(const void *packet, int bytes, uint32_t timestamp, int flags) override;
    void onPSDecode(int stream,
                    int codecid,
                    int flags,
                    int64_t pts,
                    int64_t dts,
                    const void *data,
61
                    int bytes) override ;
Gemfield committed
62 63 64 65 66 67 68 69 70 71 72
private:
    std::shared_ptr<FILE> _save_file_rtp;
    std::shared_ptr<FILE> _save_file_ps;
    std::shared_ptr<FILE> _save_file_video;
    uint32_t _ssrc;
    SdpTrack::Ptr _track;
    struct sockaddr *_addr = nullptr;
    uint16_t _sequence = 0;
    int _codecid_video = 0;
    int _codecid_audio = 0;
    MultiMediaSourceMuxer::Ptr _muxer;
73
    std::shared_ptr<FrameMerger> _merger;
Gemfield committed
74
    Ticker _last_rtp_time;
75
    map<int,Stamp> _stamps;
76
    uint32_t _dts = 0;
Gemfield committed
77 78
};

79 80 81
}//namespace mediakit
#endif//defined(ENABLE_RTPPROXY)
#endif //ZLMEDIAKIT_RTPPROCESS_H