From b54f9b0f94b28c37ca0be6d58cc86fd303b80795 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 20 Jul 2015 09:31:46 +0800 Subject: [PATCH] refine the hls, ignore packet when no sequence header. 2.0.179 --- README.md | 1 + trunk/src/core/srs_core.hpp | 2 +- trunk/src/kernel/srs_kernel_codec.cpp | 40 ++++++++++++++++----------- trunk/src/kernel/srs_kernel_codec.hpp | 4 +++ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 094532eca..5c17108ad 100755 --- a/README.md +++ b/README.md @@ -344,6 +344,7 @@ Remark: ### SRS 2.0 history +* v2.0, 2015-07-20, refine the hls, ignore packet when no sequence header. 2.0.179 * v2.0, 2015-07-16, for [#441](https://github.com/simple-rtmp-server/srs/issues/441) use 30s timeout for first msg. 2.0.178 * v2.0, 2015-07-14, refine hls disable the time jitter, support not mix monotonically increase. 2.0.177 * v2.0, 2015-07-01, fix [#433](https://github.com/simple-rtmp-server/srs/issues/433) fix the sps parse bug. 2.0.176 diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index bafab467e..f00cfb63b 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 178 +#define VERSION_REVISION 179 // server info. #define RTMP_SIG_SRS_KEY "SRS" diff --git a/trunk/src/kernel/srs_kernel_codec.cpp b/trunk/src/kernel/srs_kernel_codec.cpp index a1ebf4a13..a0d0843f5 100644 --- a/trunk/src/kernel/srs_kernel_codec.cpp +++ b/trunk/src/kernel/srs_kernel_codec.cpp @@ -423,6 +423,16 @@ SrsAvcAacCodec::~SrsAvcAacCodec() srs_freep(pictureParameterSetNALUnit); } +bool SrsAvcAacCodec::is_avc_codec_ok() +{ + return avc_extra_size > 0 && avc_extra_data; +} + +bool SrsAvcAacCodec::is_aac_codec_ok() +{ + return aac_extra_size > 0 && aac_extra_data; +} + int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample) { int ret = ERROR_SUCCESS; @@ -441,7 +451,7 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample // audio decode if (!stream->require(1)) { ret = ERROR_HLS_DECODE_ERROR; - srs_error("audio codec decode sound_format failed. ret=%d", ret); + srs_error("aac decode sound_format failed. ret=%d", ret); return ret; } @@ -468,13 +478,13 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample // only support aac if (audio_codec_id != SrsCodecAudioAAC) { ret = ERROR_HLS_DECODE_ERROR; - srs_error("audio codec only support mp3/aac codec. actual=%d, ret=%d", audio_codec_id, ret); + srs_error("aac only support mp3/aac codec. actual=%d, ret=%d", audio_codec_id, ret); return ret; } if (!stream->require(1)) { ret = ERROR_HLS_DECODE_ERROR; - srs_error("audio codec decode aac_packet_type failed. ret=%d", ret); + srs_error("aac decode aac_packet_type failed. ret=%d", ret); return ret; } @@ -497,16 +507,15 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample } } else if (aac_packet_type == SrsCodecAudioTypeRawData) { // ensure the sequence header demuxed - if (aac_extra_size <= 0 || !aac_extra_data) { - ret = ERROR_HLS_DECODE_ERROR; - srs_error("audio codec decode aac failed, sequence header not found. ret=%d", ret); + if (!is_aac_codec_ok()) { + srs_warn("aac ignore type=%d for no sequence header. ret=%d", aac_packet_type, ret); return ret; } // Raw AAC frame data in UI8 [] // 6.3 Raw Data, aac-iso-13818-7.pdf, page 28 if ((ret = sample->add_sample_unit(stream->data() + stream->pos(), stream->size() - stream->pos())) != ERROR_SUCCESS) { - srs_error("audio codec add sample failed. ret=%d", ret); + srs_error("aac add sample failed. ret=%d", ret); return ret; } } else { @@ -536,7 +545,7 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample }; } - srs_info("audio decoded, type=%d, codec=%d, asize=%d, rate=%d, format=%d, size=%d", + srs_info("aac decoded, type=%d, codec=%d, asize=%d, rate=%d, format=%d, size=%d", sound_type, audio_codec_id, sound_size, sound_rate, sound_format, size); return ret; @@ -636,7 +645,7 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample // video decode if (!stream->require(1)) { ret = ERROR_HLS_DECODE_ERROR; - srs_error("video codec decode frame_type failed. ret=%d", ret); + srs_error("avc decode frame_type failed. ret=%d", ret); return ret; } @@ -650,21 +659,21 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample // ignore info frame without error, // @see https://github.com/simple-rtmp-server/srs/issues/288#issuecomment-69863909 if (sample->frame_type == SrsCodecVideoAVCFrameVideoInfoFrame) { - srs_warn("video codec igone the info frame, ret=%d", ret); + srs_warn("avc igone the info frame, ret=%d", ret); return ret; } // only support h.264/avc if (codec_id != SrsCodecVideoAVC) { ret = ERROR_HLS_DECODE_ERROR; - srs_error("video codec only support video h.264/avc codec. actual=%d, ret=%d", codec_id, ret); + srs_error("avc only support video h.264/avc codec. actual=%d, ret=%d", codec_id, ret); return ret; } video_codec_id = codec_id; if (!stream->require(4)) { ret = ERROR_HLS_DECODE_ERROR; - srs_error("video codec decode avc_packet_type failed. ret=%d", ret); + srs_error("avc decode avc_packet_type failed. ret=%d", ret); return ret; } int8_t avc_packet_type = stream->read_1bytes(); @@ -680,9 +689,8 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample } } else if (avc_packet_type == SrsCodecVideoAVCTypeNALU){ // ensure the sequence header demuxed - if (avc_extra_size <= 0 || !avc_extra_data) { - ret = ERROR_HLS_DECODE_ERROR; - srs_error("avc decode failed, sequence header not found. ret=%d", ret); + if (!is_avc_codec_ok()) { + srs_warn("avc ignore type=%d for no sequence header. ret=%d", avc_packet_type, ret); return ret; } @@ -738,7 +746,7 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample // ignored. } - srs_info("video decoded, type=%d, codec=%d, avc=%d, cts=%d, size=%d", + srs_info("avc decoded, type=%d, codec=%d, avc=%d, cts=%d, size=%d", frame_type, video_codec_id, avc_packet_type, composition_time, size); return ret; diff --git a/trunk/src/kernel/srs_kernel_codec.hpp b/trunk/src/kernel/srs_kernel_codec.hpp index 238feac76..204673882 100644 --- a/trunk/src/kernel/srs_kernel_codec.hpp +++ b/trunk/src/kernel/srs_kernel_codec.hpp @@ -608,6 +608,10 @@ public: public: SrsAvcAacCodec(); virtual ~SrsAvcAacCodec(); +public: + // whether avc or aac codec sequence header or extra data is decoded ok. + virtual bool is_avc_codec_ok(); + virtual bool is_aac_codec_ok(); // the following function used for hls to build the sample and codec. public: /**