Skip to content

Commit 87519aa

Browse files
committed
fix the avc codec bug, the ibmf format may like the annexb, we must guess only one time. 2.0.114
1 parent 66931a8 commit 87519aa

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

trunk/src/core/srs_core.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3131
// current release version
3232
#define VERSION_MAJOR 2
3333
#define VERSION_MINOR 0
34-
#define VERSION_REVISION 113
34+
#define VERSION_REVISION 114
3535

3636
// server info.
3737
#define RTMP_SIG_SRS_KEY "SRS"

trunk/src/kernel/srs_kernel_codec.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ SrsAvcAacCodec::SrsAvcAacCodec()
199199
pictureParameterSetLength = 0;
200200
pictureParameterSetNALUnit = NULL;
201201

202+
payload_format = SrsAvcPayloadFormatGuess;
202203
stream = new SrsStream();
203204
}
204205

@@ -469,20 +470,42 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample
469470
srs_error("avc decode failed, sequence header not found. ret=%d", ret);
470471
return ret;
471472
}
472-
473-
// One or more NALUs (Full frames are required)
474-
// try "AnnexB" from H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
475-
if ((ret = avc_demux_annexb_format(stream, sample)) != ERROR_SUCCESS) {
476-
// stop try when system error.
477-
if (ret != ERROR_HLS_AVC_TRY_OTHERS) {
478-
srs_error("avc demux for annexb failed. ret=%d", ret);
479-
return ret;
473+
474+
// guess for the first time.
475+
if (payload_format == SrsAvcPayloadFormatGuess) {
476+
// One or more NALUs (Full frames are required)
477+
// try "AnnexB" from H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
478+
if ((ret = avc_demux_annexb_format(stream, sample)) != ERROR_SUCCESS) {
479+
// stop try when system error.
480+
if (ret != ERROR_HLS_AVC_TRY_OTHERS) {
481+
srs_error("avc demux for annexb failed. ret=%d", ret);
482+
return ret;
483+
}
484+
485+
// try "ISO Base Media File Format" from H.264-AVC-ISO_IEC_14496-15.pdf, page 20
486+
if ((ret = avc_demux_ibmf_format(stream, sample)) != ERROR_SUCCESS) {
487+
return ret;
488+
} else {
489+
payload_format = SrsAvcPayloadFormatIbmf;
490+
srs_info("hls guess avc payload is ibmf format.");
491+
}
492+
} else {
493+
payload_format = SrsAvcPayloadFormatAnnexb;
494+
srs_info("hls guess avc payload is annexb format.");
480495
}
481-
496+
} else if (payload_format == SrsAvcPayloadFormatIbmf) {
482497
// try "ISO Base Media File Format" from H.264-AVC-ISO_IEC_14496-15.pdf, page 20
483498
if ((ret = avc_demux_ibmf_format(stream, sample)) != ERROR_SUCCESS) {
484499
return ret;
485500
}
501+
srs_info("hls decode avc payload in ibmf format.");
502+
} else {
503+
// One or more NALUs (Full frames are required)
504+
// try "AnnexB" from H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
505+
if ((ret = avc_demux_annexb_format(stream, sample)) != ERROR_SUCCESS) {
506+
return ret;
507+
}
508+
srs_info("hls decode avc payload in annexb format.");
486509
}
487510
} else {
488511
// ignored.

trunk/src/kernel/srs_kernel_codec.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,18 @@ class SrsCodecSample
358358
int add_sample_unit(char* bytes, int size);
359359
};
360360

361+
/**
362+
* the avc payload format, must be ibmf or annexb format.
363+
* we guess by annexb first, then ibmf for the first time,
364+
* and we always use the guessed format for the next time.
365+
*/
366+
enum SrsAvcPayloadFormat
367+
{
368+
SrsAvcPayloadFormatGuess = 0,
369+
SrsAvcPayloadFormatAnnexb,
370+
SrsAvcPayloadFormatIbmf,
371+
};
372+
361373
/**
362374
* the h264/avc and aac codec, for media stream.
363375
*
@@ -404,6 +416,9 @@ class SrsAvcAacCodec
404416
char* sequenceParameterSetNALUnit;
405417
u_int16_t pictureParameterSetLength;
406418
char* pictureParameterSetNALUnit;
419+
private:
420+
// the avc payload format.
421+
SrsAvcPayloadFormat payload_format;
407422
public:
408423
/**
409424
* audio specified

0 commit comments

Comments
 (0)