From 87519aaae835199e5adb60c0ae2c1cd24939448c Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 10 Feb 2015 22:37:29 +0800 Subject: [PATCH] fix the avc codec bug, the ibmf format may like the annexb, we must guess only one time. 2.0.114 --- trunk/src/core/srs_core.hpp | 2 +- trunk/src/kernel/srs_kernel_codec.cpp | 41 +++++++++++++++++++++------ trunk/src/kernel/srs_kernel_codec.hpp | 15 ++++++++++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 7ff4aa757b..c1f965ea72 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 113 +#define VERSION_REVISION 114 // 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 d347e7b916..abe078d0bc 100644 --- a/trunk/src/kernel/srs_kernel_codec.cpp +++ b/trunk/src/kernel/srs_kernel_codec.cpp @@ -199,6 +199,7 @@ SrsAvcAacCodec::SrsAvcAacCodec() pictureParameterSetLength = 0; pictureParameterSetNALUnit = NULL; + payload_format = SrsAvcPayloadFormatGuess; stream = new SrsStream(); } @@ -469,20 +470,42 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample srs_error("avc decode failed, sequence header not found. ret=%d", ret); return ret; } - - // One or more NALUs (Full frames are required) - // try "AnnexB" from H.264-AVC-ISO_IEC_14496-10.pdf, page 211. - if ((ret = avc_demux_annexb_format(stream, sample)) != ERROR_SUCCESS) { - // stop try when system error. - if (ret != ERROR_HLS_AVC_TRY_OTHERS) { - srs_error("avc demux for annexb failed. ret=%d", ret); - return ret; + + // guess for the first time. + if (payload_format == SrsAvcPayloadFormatGuess) { + // One or more NALUs (Full frames are required) + // try "AnnexB" from H.264-AVC-ISO_IEC_14496-10.pdf, page 211. + if ((ret = avc_demux_annexb_format(stream, sample)) != ERROR_SUCCESS) { + // stop try when system error. + if (ret != ERROR_HLS_AVC_TRY_OTHERS) { + srs_error("avc demux for annexb failed. ret=%d", ret); + return ret; + } + + // try "ISO Base Media File Format" from H.264-AVC-ISO_IEC_14496-15.pdf, page 20 + if ((ret = avc_demux_ibmf_format(stream, sample)) != ERROR_SUCCESS) { + return ret; + } else { + payload_format = SrsAvcPayloadFormatIbmf; + srs_info("hls guess avc payload is ibmf format."); + } + } else { + payload_format = SrsAvcPayloadFormatAnnexb; + srs_info("hls guess avc payload is annexb format."); } - + } else if (payload_format == SrsAvcPayloadFormatIbmf) { // try "ISO Base Media File Format" from H.264-AVC-ISO_IEC_14496-15.pdf, page 20 if ((ret = avc_demux_ibmf_format(stream, sample)) != ERROR_SUCCESS) { return ret; } + srs_info("hls decode avc payload in ibmf format."); + } else { + // One or more NALUs (Full frames are required) + // try "AnnexB" from H.264-AVC-ISO_IEC_14496-10.pdf, page 211. + if ((ret = avc_demux_annexb_format(stream, sample)) != ERROR_SUCCESS) { + return ret; + } + srs_info("hls decode avc payload in annexb format."); } } else { // ignored. diff --git a/trunk/src/kernel/srs_kernel_codec.hpp b/trunk/src/kernel/srs_kernel_codec.hpp index 8608260a79..00a8ed4e30 100644 --- a/trunk/src/kernel/srs_kernel_codec.hpp +++ b/trunk/src/kernel/srs_kernel_codec.hpp @@ -358,6 +358,18 @@ class SrsCodecSample int add_sample_unit(char* bytes, int size); }; +/** +* the avc payload format, must be ibmf or annexb format. +* we guess by annexb first, then ibmf for the first time, +* and we always use the guessed format for the next time. +*/ +enum SrsAvcPayloadFormat +{ + SrsAvcPayloadFormatGuess = 0, + SrsAvcPayloadFormatAnnexb, + SrsAvcPayloadFormatIbmf, +}; + /** * the h264/avc and aac codec, for media stream. * @@ -404,6 +416,9 @@ class SrsAvcAacCodec char* sequenceParameterSetNALUnit; u_int16_t pictureParameterSetLength; char* pictureParameterSetNALUnit; +private: + // the avc payload format. + SrsAvcPayloadFormat payload_format; public: /** * audio specified