mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #293, add http ts stream framework.
This commit is contained in:
parent
0f59073400
commit
77d78eac5c
2 changed files with 64 additions and 5 deletions
|
@ -34,18 +34,20 @@ using namespace std;
|
||||||
|
|
||||||
#include <srs_kernel_log.hpp>
|
#include <srs_kernel_log.hpp>
|
||||||
#include <srs_kernel_error.hpp>
|
#include <srs_kernel_error.hpp>
|
||||||
#include <srs_kernel_stream.hpp>
|
|
||||||
#include <srs_kernel_file.hpp>
|
#include <srs_kernel_file.hpp>
|
||||||
|
#include <srs_kernel_avc.hpp>
|
||||||
|
|
||||||
SrsTsEncoder::SrsTsEncoder()
|
SrsTsEncoder::SrsTsEncoder()
|
||||||
{
|
{
|
||||||
_fs = NULL;
|
_fs = NULL;
|
||||||
tag_stream = new SrsStream();
|
codec = new SrsAvcAacCodec();
|
||||||
|
sample = new SrsCodecSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsTsEncoder::~SrsTsEncoder()
|
SrsTsEncoder::~SrsTsEncoder()
|
||||||
{
|
{
|
||||||
srs_freep(tag_stream);
|
srs_freep(codec);
|
||||||
|
srs_freep(sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsTsEncoder::initialize(SrsFileWriter* fs)
|
int SrsTsEncoder::initialize(SrsFileWriter* fs)
|
||||||
|
@ -68,12 +70,67 @@ int SrsTsEncoder::initialize(SrsFileWriter* fs)
|
||||||
int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size)
|
int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
sample->clear();
|
||||||
|
if ((ret = codec->audio_aac_demux(data, size, sample)) != ERROR_SUCCESS) {
|
||||||
|
srs_error("http: ts codec demux audio failed. ret=%d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codec->audio_codec_id != SrsCodecAudioAAC) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore sequence header
|
||||||
|
if (sample->aac_packet_type == SrsCodecAudioTypeSequenceHeader) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the dts calc from rtmp/flv header.
|
||||||
|
// @remark for http ts stream, the timestamp is always monotonically increase,
|
||||||
|
// for the packet is filtered by consumer.
|
||||||
|
int64_t dts = timestamp * 90;
|
||||||
|
|
||||||
|
/*if ((ret = hls_cache->write_audio(codec, muxer, dts, sample)) != ERROR_SUCCESS) {
|
||||||
|
srs_error("http: ts cache write audio failed. ret=%d", ret);
|
||||||
|
return ret;
|
||||||
|
}*/
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size)
|
int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
sample->clear();
|
||||||
|
if ((ret = codec->video_avc_demux(data, size, sample)) != ERROR_SUCCESS) {
|
||||||
|
srs_error("http: ts codec demux video failed. ret=%d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore info frame,
|
||||||
|
// @see https://github.com/winlinvip/simple-rtmp-server/issues/288#issuecomment-69863909
|
||||||
|
if (sample->frame_type == SrsCodecVideoAVCFrameVideoInfoFrame) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codec->video_codec_id != SrsCodecVideoAVC) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore sequence header
|
||||||
|
if (sample->frame_type == SrsCodecVideoAVCFrameKeyFrame
|
||||||
|
&& sample->avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t dts = timestamp * 90;
|
||||||
|
/*if ((ret = hls_cache->write_video(codec, muxer, dts, sample)) != ERROR_SUCCESS) {
|
||||||
|
srs_error("http: ts cache write video failed. ret=%d", ret);
|
||||||
|
return ret;
|
||||||
|
}*/
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class SrsStream;
|
|
||||||
class SrsFileWriter;
|
class SrsFileWriter;
|
||||||
class SrsFileReader;
|
class SrsFileReader;
|
||||||
|
class SrsAvcAacCodec;
|
||||||
|
class SrsCodecSample;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* encode data to ts file.
|
* encode data to ts file.
|
||||||
|
@ -43,7 +44,8 @@ class SrsTsEncoder
|
||||||
private:
|
private:
|
||||||
SrsFileWriter* _fs;
|
SrsFileWriter* _fs;
|
||||||
private:
|
private:
|
||||||
SrsStream* tag_stream;
|
SrsAvcAacCodec* codec;
|
||||||
|
SrsCodecSample* sample;
|
||||||
public:
|
public:
|
||||||
SrsTsEncoder();
|
SrsTsEncoder();
|
||||||
virtual ~SrsTsEncoder();
|
virtual ~SrsTsEncoder();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue