mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix hls media codec info bug, ignore nal_unit_type 7/8/9. 0.9.152
This commit is contained in:
parent
aefff75d08
commit
21a75924ad
2 changed files with 43 additions and 7 deletions
|
@ -1214,10 +1214,19 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
// for type1/5/6, insert aud packet.
|
||||||
static u_int8_t aud_nal[] = { 0x00, 0x00, 0x00, 0x01, 0x09, 0xf0 };
|
static u_int8_t aud_nal[] = { 0x00, 0x00, 0x00, 0x01, 0x09, 0xf0 };
|
||||||
vb->append(aud_nal, sizeof(aud_nal));
|
|
||||||
|
|
||||||
bool sps_pps_sent = false;
|
bool sps_pps_sent = false;
|
||||||
|
bool aud_sent = false;
|
||||||
|
/**
|
||||||
|
* a ts sample is format as:
|
||||||
|
* 00 00 00 01 // header
|
||||||
|
* xxxxxxx // data bytes
|
||||||
|
* 00 00 01 // continue header
|
||||||
|
* xxxxxxx // data bytes.
|
||||||
|
* so, for each sample, we append header in aud_nal, then appends the bytes in sample.
|
||||||
|
*/
|
||||||
for (int i = 0; i < sample->nb_buffers; i++) {
|
for (int i = 0; i < sample->nb_buffers; i++) {
|
||||||
SrsCodecBuffer* buf = &sample->buffers[i];
|
SrsCodecBuffer* buf = &sample->buffers[i];
|
||||||
int32_t size = buf->size;
|
int32_t size = buf->size;
|
||||||
|
@ -1228,12 +1237,20 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* step 1:
|
||||||
|
* first, before each "real" sample,
|
||||||
|
* we add some packets according to the nal_unit_type,
|
||||||
|
* for example, when got nal_unit_type=5, insert SPS/PPS before sample.
|
||||||
|
*/
|
||||||
|
|
||||||
// 5bits, 7.3.1 NAL unit syntax,
|
// 5bits, 7.3.1 NAL unit syntax,
|
||||||
// H.264-AVC-ISO_IEC_14496-10.pdf, page 44.
|
// H.264-AVC-ISO_IEC_14496-10.pdf, page 44.
|
||||||
u_int8_t nal_unit_type;
|
u_int8_t nal_unit_type;
|
||||||
nal_unit_type = *buf->bytes;
|
nal_unit_type = *buf->bytes;
|
||||||
nal_unit_type &= 0x1f;
|
nal_unit_type &= 0x1f;
|
||||||
|
|
||||||
|
// @see: ngx_rtmp_hls_video
|
||||||
// Table 7-1 – NAL unit type codes, page 61
|
// Table 7-1 – NAL unit type codes, page 61
|
||||||
// 1: Coded slice
|
// 1: Coded slice
|
||||||
if (nal_unit_type == 1) {
|
if (nal_unit_type == 1) {
|
||||||
|
@ -1245,27 +1262,43 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample)
|
||||||
//if (vf->key && !sps_pps_sent) {
|
//if (vf->key && !sps_pps_sent) {
|
||||||
sps_pps_sent = true;
|
sps_pps_sent = true;
|
||||||
|
|
||||||
// ngx_rtmp_hls_append_sps_pps
|
// @see: ngx_rtmp_hls_append_sps_pps
|
||||||
if (codec->sequenceParameterSetLength > 0) {
|
if (codec->sequenceParameterSetLength > 0) {
|
||||||
// AnnexB prefix
|
// AnnexB prefix, for sps always 4 bytes header
|
||||||
vb->append(aud_nal, 4);
|
vb->append(aud_nal, 4);
|
||||||
// sps
|
// sps
|
||||||
vb->append(codec->sequenceParameterSetNALUnit, codec->sequenceParameterSetLength);
|
vb->append(codec->sequenceParameterSetNALUnit, codec->sequenceParameterSetLength);
|
||||||
}
|
}
|
||||||
if (codec->pictureParameterSetLength > 0) {
|
if (codec->pictureParameterSetLength > 0) {
|
||||||
// AnnexB prefix
|
// AnnexB prefix, for pps always 4 bytes header
|
||||||
vb->append(aud_nal, 4);
|
vb->append(aud_nal, 4);
|
||||||
// pps
|
// pps
|
||||||
vb->append(codec->pictureParameterSetNALUnit, codec->pictureParameterSetLength);
|
vb->append(codec->pictureParameterSetNALUnit, codec->pictureParameterSetLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 6: Supplemental enhancement information (SEI) sei_rbsp( ), page 61
|
||||||
|
// @see: ngx_rtmp_hls_append_aud
|
||||||
|
if (nal_unit_type == 6 && !aud_sent) {
|
||||||
|
// for type 6, append a aud with type 9.
|
||||||
|
vb->append(aud_nal, sizeof(aud_nal));
|
||||||
|
}
|
||||||
|
// 7-9, ignore, @see: ngx_rtmp_hls_video
|
||||||
|
if (nal_unit_type >= 7 && nal_unit_type <= 9) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* step 2:
|
||||||
|
* output the "real" sample, in buf.
|
||||||
|
* when we output some special assist packets according to nal_unit_type
|
||||||
|
*/
|
||||||
|
|
||||||
// sample start prefix, '00 00 00 01' or '00 00 01'
|
// sample start prefix, '00 00 00 01' or '00 00 01'
|
||||||
u_int8_t* p = aud_nal + 1;
|
u_int8_t* p = aud_nal + 1;
|
||||||
u_int8_t* end = p + 3;
|
u_int8_t* end = p + 3;
|
||||||
|
|
||||||
// first AnnexB prefix is long (4 bytes)
|
// first AnnexB prefix is long (4 bytes)
|
||||||
if (i == 0) {
|
if (vb->size == 0) {
|
||||||
p = aud_nal;
|
p = aud_nal;
|
||||||
}
|
}
|
||||||
vb->append(p, end - p);
|
vb->append(p, end - p);
|
||||||
|
@ -1496,8 +1529,11 @@ void SrsHls::hls_mux()
|
||||||
{
|
{
|
||||||
// reportable
|
// reportable
|
||||||
if (pithy_print->can_print()) {
|
if (pithy_print->can_print()) {
|
||||||
|
// the run time is not equals to stream time,
|
||||||
|
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/81#issuecomment-48100994
|
||||||
|
// it's ok.
|
||||||
srs_trace("-> "SRS_LOG_ID_HLS
|
srs_trace("-> "SRS_LOG_ID_HLS
|
||||||
" time=%"PRId64", dts=%"PRId64"(%"PRId64"ms), sequence_no=%d",
|
" time=%"PRId64", stream dts=%"PRId64"(%"PRId64"ms), sequence_no=%d",
|
||||||
pithy_print->age(), stream_dts, stream_dts / 90, muxer->sequence_no());
|
pithy_print->age(), stream_dts, stream_dts / 90, muxer->sequence_no());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// current release version
|
// current release version
|
||||||
#define VERSION_MAJOR "0"
|
#define VERSION_MAJOR "0"
|
||||||
#define VERSION_MINOR "9"
|
#define VERSION_MINOR "9"
|
||||||
#define VERSION_REVISION "151"
|
#define VERSION_REVISION "152"
|
||||||
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
||||||
// server info.
|
// server info.
|
||||||
#define RTMP_SIG_SRS_KEY "SRS"
|
#define RTMP_SIG_SRS_KEY "SRS"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue