ZLMediaKit/src/Extension/Track.h

200 lines
4.4 KiB
C++
Raw Normal View History

2018-10-30 14:59:42 +08:00
/*
2020-04-04 20:30:09 +08:00
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
2018-10-30 14:59:42 +08:00
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
2020-04-04 20:30:09 +08:00
* 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.
2018-10-30 14:59:42 +08:00
*/
#ifndef ZLMEDIAKIT_TRACK_H
#define ZLMEDIAKIT_TRACK_H
#include <memory>
#include <string>
#include "Frame.h"
#include "Util/RingBuffer.h"
#include "Rtsp/Rtsp.h"
using namespace toolkit;
namespace mediakit{
/**
*
*/
2019-12-25 20:07:42 +08:00
class Track : public FrameDispatcher , public CodecInfo{
2018-10-30 14:59:42 +08:00
public:
typedef std::shared_ptr<Track> Ptr;
Track(){}
virtual ~Track(){}
/**
* sps pps等信息
* @return
*/
virtual bool ready() = 0;
/**
*
*
*
* @return
*/
virtual Track::Ptr clone() = 0;
2019-06-28 16:12:39 +08:00
/**
* sdp
* @return sdp对象
*/
virtual Sdp::Ptr getSdp() = 0;
2018-10-30 14:59:42 +08:00
/**
*
*
* @param that
*/
Track(const Track &that){}
};
/**
* Track类fps信息
*/
class VideoTrack : public Track {
public:
typedef std::shared_ptr<VideoTrack> Ptr;
/**
*
* @return
*/
virtual int getVideoHeight() const {return 0;};
2018-10-30 14:59:42 +08:00
/**
*
* @return
*/
virtual int getVideoWidth() const {return 0;};
2018-10-30 14:59:42 +08:00
/**
* fps
* @return
*/
virtual float getVideoFps() const {return 0;};
2018-10-30 14:59:42 +08:00
};
/**
* Track派生类
*/
class AudioTrack : public Track {
public:
typedef std::shared_ptr<AudioTrack> Ptr;
/**
*
* @return
*/
virtual int getAudioSampleRate() const {return 0;};
2018-10-30 14:59:42 +08:00
/**
* 168
* @return
*/
virtual int getAudioSampleBit() const {return 0;};
2018-10-30 14:59:42 +08:00
/**
*
* @return
*/
virtual int getAudioChannel() const {return 0;};
2018-10-30 14:59:42 +08:00
};
2020-05-11 22:33:10 +08:00
class AudioTrackImp : public AudioTrack{
public:
typedef std::shared_ptr<AudioTrackImp> Ptr;
/**
*
* @param codecId
* @param sample_rate (HZ)
* @param channels
* @param sample_bit 16
*/
AudioTrackImp(CodecId codecId,int sample_rate, int channels, int sample_bit){
_codecid = codecId;
_sample_rate = sample_rate;
_channels = channels;
_sample_bit = sample_bit;
}
/**
*
*/
CodecId getCodecId() const override{
return _codecid;
}
/**
*
*/
bool ready() override {
return true;
}
/**
*
*/
int getAudioSampleRate() const override{
return _sample_rate;
}
/**
* 168
*/
int getAudioSampleBit() const override{
return _sample_bit;
}
/**
*
*/
int getAudioChannel() const override{
return _channels;
}
private:
CodecId _codecid;
int _sample_rate;
int _channels;
int _sample_bit;
};
2018-10-30 14:59:42 +08:00
2019-12-03 12:32:57 +08:00
class TrackSource{
public:
TrackSource(){}
virtual ~TrackSource(){}
/**
2020-03-20 11:51:24 +08:00
* Track
* @param trackReady Track
*/
2019-12-03 16:10:02 +08:00
virtual vector<Track::Ptr> getTracks(bool trackReady = true) const = 0;
2019-12-03 12:32:57 +08:00
/**
* Track
* @param type track类型
* @param trackReady Track
*/
Track::Ptr getTrack(TrackType type , bool trackReady = true) const {
auto tracks = getTracks(trackReady);
for(auto &track : tracks){
if(track->getTrackType() == type){
return track;
}
}
return nullptr;
}
};
2018-10-30 14:59:42 +08:00
}//namespace mediakit
2020-05-11 22:33:10 +08:00
#endif //ZLMEDIAKIT_TRACK_H