Skip to content

Commit

Permalink
fix the avc codec bug, the ibmf format may like the annexb, we must g…
Browse files Browse the repository at this point in the history
…uess only one time. 2.0.114
  • Loading branch information
winlinvip committed Feb 10, 2015
1 parent 66931a8 commit 87519aa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
41 changes: 32 additions & 9 deletions trunk/src/kernel/srs_kernel_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ SrsAvcAacCodec::SrsAvcAacCodec()
pictureParameterSetLength = 0;
pictureParameterSetNALUnit = NULL;

payload_format = SrsAvcPayloadFormatGuess;
stream = new SrsStream();
}

Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions trunk/src/kernel/srs_kernel_codec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 87519aa

Please sign in to comment.