diff --git a/trunk/src/kernel/srs_kernel_ts.cpp b/trunk/src/kernel/srs_kernel_ts.cpp index a653335943..97802f87be 100644 --- a/trunk/src/kernel/srs_kernel_ts.cpp +++ b/trunk/src/kernel/srs_kernel_ts.cpp @@ -34,18 +34,20 @@ using namespace std; #include #include -#include #include +#include 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; } diff --git a/trunk/src/kernel/srs_kernel_ts.hpp b/trunk/src/kernel/srs_kernel_ts.hpp index 8e71312bc0..dbd7ee1c4b 100644 --- a/trunk/src/kernel/srs_kernel_ts.hpp +++ b/trunk/src/kernel/srs_kernel_ts.hpp @@ -31,9 +31,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -class SrsStream; class SrsFileWriter; class SrsFileReader; +class SrsAvcAacCodec; +class SrsCodecSample; /** * encode data to ts file. @@ -43,7 +44,8 @@ class SrsTsEncoder private: SrsFileWriter* _fs; private: - SrsStream* tag_stream; + SrsAvcAacCodec* codec; + SrsCodecSample* sample; public: SrsTsEncoder(); virtual ~SrsTsEncoder();