winlin

fix hls media codec info bug, ignore nal_unit_type 7/8/9. 0.9.152

@@ -1214,10 +1214,19 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) @@ -1214,10 +1214,19 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample)
1214 { 1214 {
1215 int ret = ERROR_SUCCESS; 1215 int ret = ERROR_SUCCESS;
1216 1216
  1217 + // for type1/5/6, insert aud packet.
1217 static u_int8_t aud_nal[] = { 0x00, 0x00, 0x00, 0x01, 0x09, 0xf0 }; 1218 static u_int8_t aud_nal[] = { 0x00, 0x00, 0x00, 0x01, 0x09, 0xf0 };
1218 - vb->append(aud_nal, sizeof(aud_nal));  
1219 1219
1220 bool sps_pps_sent = false; 1220 bool sps_pps_sent = false;
  1221 + bool aud_sent = false;
  1222 + /**
  1223 + * a ts sample is format as:
  1224 + * 00 00 00 01 // header
  1225 + * xxxxxxx // data bytes
  1226 + * 00 00 01 // continue header
  1227 + * xxxxxxx // data bytes.
  1228 + * so, for each sample, we append header in aud_nal, then appends the bytes in sample.
  1229 + */
1221 for (int i = 0; i < sample->nb_buffers; i++) { 1230 for (int i = 0; i < sample->nb_buffers; i++) {
1222 SrsCodecBuffer* buf = &sample->buffers[i]; 1231 SrsCodecBuffer* buf = &sample->buffers[i];
1223 int32_t size = buf->size; 1232 int32_t size = buf->size;
@@ -1228,12 +1237,20 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) @@ -1228,12 +1237,20 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample)
1228 return ret; 1237 return ret;
1229 } 1238 }
1230 1239
  1240 + /**
  1241 + * step 1:
  1242 + * first, before each "real" sample,
  1243 + * we add some packets according to the nal_unit_type,
  1244 + * for example, when got nal_unit_type=5, insert SPS/PPS before sample.
  1245 + */
  1246 +
1231 // 5bits, 7.3.1 NAL unit syntax, 1247 // 5bits, 7.3.1 NAL unit syntax,
1232 // H.264-AVC-ISO_IEC_14496-10.pdf, page 44. 1248 // H.264-AVC-ISO_IEC_14496-10.pdf, page 44.
1233 u_int8_t nal_unit_type; 1249 u_int8_t nal_unit_type;
1234 nal_unit_type = *buf->bytes; 1250 nal_unit_type = *buf->bytes;
1235 nal_unit_type &= 0x1f; 1251 nal_unit_type &= 0x1f;
1236 1252
  1253 + // @see: ngx_rtmp_hls_video
1237 // Table 7-1 – NAL unit type codes, page 61 1254 // Table 7-1 – NAL unit type codes, page 61
1238 // 1: Coded slice 1255 // 1: Coded slice
1239 if (nal_unit_type == 1) { 1256 if (nal_unit_type == 1) {
@@ -1245,27 +1262,43 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) @@ -1245,27 +1262,43 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample)
1245 //if (vf->key && !sps_pps_sent) { 1262 //if (vf->key && !sps_pps_sent) {
1246 sps_pps_sent = true; 1263 sps_pps_sent = true;
1247 1264
1248 - // ngx_rtmp_hls_append_sps_pps 1265 + // @see: ngx_rtmp_hls_append_sps_pps
1249 if (codec->sequenceParameterSetLength > 0) { 1266 if (codec->sequenceParameterSetLength > 0) {
1250 - // AnnexB prefix 1267 + // AnnexB prefix, for sps always 4 bytes header
1251 vb->append(aud_nal, 4); 1268 vb->append(aud_nal, 4);
1252 // sps 1269 // sps
1253 vb->append(codec->sequenceParameterSetNALUnit, codec->sequenceParameterSetLength); 1270 vb->append(codec->sequenceParameterSetNALUnit, codec->sequenceParameterSetLength);
1254 } 1271 }
1255 if (codec->pictureParameterSetLength > 0) { 1272 if (codec->pictureParameterSetLength > 0) {
1256 - // AnnexB prefix 1273 + // AnnexB prefix, for pps always 4 bytes header
1257 vb->append(aud_nal, 4); 1274 vb->append(aud_nal, 4);
1258 // pps 1275 // pps
1259 vb->append(codec->pictureParameterSetNALUnit, codec->pictureParameterSetLength); 1276 vb->append(codec->pictureParameterSetNALUnit, codec->pictureParameterSetLength);
1260 } 1277 }
1261 } 1278 }
  1279 + // 6: Supplemental enhancement information (SEI) sei_rbsp( ), page 61
  1280 + // @see: ngx_rtmp_hls_append_aud
  1281 + if (nal_unit_type == 6 && !aud_sent) {
  1282 + // for type 6, append a aud with type 9.
  1283 + vb->append(aud_nal, sizeof(aud_nal));
  1284 + }
  1285 + // 7-9, ignore, @see: ngx_rtmp_hls_video
  1286 + if (nal_unit_type >= 7 && nal_unit_type <= 9) {
  1287 + continue;
  1288 + }
  1289 +
  1290 + /**
  1291 + * step 2:
  1292 + * output the "real" sample, in buf.
  1293 + * when we output some special assist packets according to nal_unit_type
  1294 + */
1262 1295
1263 // sample start prefix, '00 00 00 01' or '00 00 01' 1296 // sample start prefix, '00 00 00 01' or '00 00 01'
1264 u_int8_t* p = aud_nal + 1; 1297 u_int8_t* p = aud_nal + 1;
1265 u_int8_t* end = p + 3; 1298 u_int8_t* end = p + 3;
1266 1299
1267 // first AnnexB prefix is long (4 bytes) 1300 // first AnnexB prefix is long (4 bytes)
1268 - if (i == 0) { 1301 + if (vb->size == 0) {
1269 p = aud_nal; 1302 p = aud_nal;
1270 } 1303 }
1271 vb->append(p, end - p); 1304 vb->append(p, end - p);
@@ -1496,8 +1529,11 @@ void SrsHls::hls_mux() @@ -1496,8 +1529,11 @@ void SrsHls::hls_mux()
1496 { 1529 {
1497 // reportable 1530 // reportable
1498 if (pithy_print->can_print()) { 1531 if (pithy_print->can_print()) {
  1532 + // the run time is not equals to stream time,
  1533 + // @see: https://github.com/winlinvip/simple-rtmp-server/issues/81#issuecomment-48100994
  1534 + // it's ok.
1499 srs_trace("-> "SRS_LOG_ID_HLS 1535 srs_trace("-> "SRS_LOG_ID_HLS
1500 - " time=%"PRId64", dts=%"PRId64"(%"PRId64"ms), sequence_no=%d", 1536 + " time=%"PRId64", stream dts=%"PRId64"(%"PRId64"ms), sequence_no=%d",
1501 pithy_print->age(), stream_dts, stream_dts / 90, muxer->sequence_no()); 1537 pithy_print->age(), stream_dts, stream_dts / 90, muxer->sequence_no());
1502 } 1538 }
1503 1539
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "151" 34 +#define VERSION_REVISION "152"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"