1
0
Fork 0
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:
winlin 2015-01-22 17:40:06 +08:00
parent 0f59073400
commit 77d78eac5c
2 changed files with 64 additions and 5 deletions

View file

@ -34,18 +34,20 @@ using namespace std;
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_kernel_file.hpp>
#include <srs_kernel_avc.hpp>
SrsTsEncoder::SrsTsEncoder()
{
_fs = NULL;
tag_stream = new SrsStream();
codec = new SrsAvcAacCodec();
sample = new SrsCodecSample();
}
SrsTsEncoder::~SrsTsEncoder()
{
srs_freep(tag_stream);
srs_freep(codec);
srs_freep(sample);
}
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 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;
}
int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size)
{
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;
}