|
|
@ -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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|