ZLMediaKit/src/Rtmp/RtmpCodec.h

66 lines
1.5 KiB
C++
Raw Permalink Normal View History

2018-10-25 10:00:17 +08:00
/*
2023-12-09 16:23:51 +08:00
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
2018-10-25 10:00:17 +08:00
*
2023-12-09 16:23:51 +08:00
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
2018-10-25 10:00:17 +08:00
*
2023-12-09 16:23:51 +08:00
* Use of this source code is governed by MIT-like license that can be found in the
2020-04-04 20:30:09 +08:00
* 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.
2018-10-25 10:00:17 +08:00
*/
2018-10-24 12:01:40 +08:00
#ifndef ZLMEDIAKIT_RTMPCODEC_H
#define ZLMEDIAKIT_RTMPCODEC_H
#include "Rtmp/Rtmp.h"
2018-10-30 14:59:42 +08:00
#include "Extension/Frame.h"
2018-10-24 12:01:40 +08:00
#include "Util/RingBuffer.h"
2018-10-24 17:17:55 +08:00
namespace mediakit{
2018-10-24 12:01:40 +08:00
class RtmpRing {
2018-10-24 12:01:40 +08:00
public:
using Ptr = std::shared_ptr<RtmpRing>;
using RingType = toolkit::RingBuffer<RtmpPacket::Ptr>;
2018-10-24 12:01:40 +08:00
virtual ~RtmpRing() = default;
2018-10-24 12:01:40 +08:00
/**
* rtmp环形缓存
*/
2023-12-09 16:23:51 +08:00
void setRtmpRing(const RingType::Ptr &ring) {
_ring = ring;
2019-12-26 09:43:44 +08:00
}
2018-10-24 12:01:40 +08:00
/**
* rtmp包
* @param rtmp rtmp包
*/
virtual void inputRtmp(const RtmpPacket::Ptr &rtmp) {
if (_ring) {
_ring->write(rtmp, rtmp->isVideoKeyFrame());
2018-10-26 22:07:01 +08:00
}
2018-10-24 12:01:40 +08:00
}
2020-08-30 10:48:34 +08:00
2018-10-24 12:01:40 +08:00
protected:
RingType::Ptr _ring;
2018-10-24 12:01:40 +08:00
};
2023-12-09 16:23:51 +08:00
class RtmpCodec : public RtmpRing, public FrameWriterInterface {
2018-10-24 12:01:40 +08:00
public:
2022-12-02 14:43:06 +08:00
using Ptr = std::shared_ptr<RtmpCodec>;
2023-12-09 16:23:51 +08:00
RtmpCodec(Track::Ptr track) { _track = std::move(track); }
virtual void makeConfigPacket() {}
bool inputFrame(const Frame::Ptr &frame) override { return _track->inputFrame(frame); }
const Track::Ptr &getTrack() const { return _track; }
private:
Track::Ptr _track;
2018-10-24 12:01:40 +08:00
};
2018-10-24 17:17:55 +08:00
}//namespace mediakit
2018-10-24 12:01:40 +08:00
#endif //ZLMEDIAKIT_RTMPCODEC_H