Skip to content

Commit

Permalink
fix ts play
Browse files Browse the repository at this point in the history
known issue:
1 Invalid NAL unit 4, skipping.
2 cannot compatible with 264/hevc
  • Loading branch information
wnpllrzodiac committed Jan 23, 2018
1 parent 36fa248 commit 23f2160
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
5 changes: 4 additions & 1 deletion trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
if (default_vcodec_str == "h264") {
default_vcodec = SrsCodecVideoAVC;
srs_info("hls: use default h264 vcodec");
} else if (default_vcodec_str == "h265") {
default_vcodec = SrsCodecVideoHEVC;
srs_info("hls: use default h264 vcodec");
} else if (default_vcodec_str == "vn") {
default_vcodec = SrsCodecVideoDisabled;
srs_info("hls: use default vn vcodec for pure audio");
Expand Down Expand Up @@ -1395,7 +1398,7 @@ int SrsHls::on_video(SrsSharedPtrMessage* shared_video, bool is_sps_pps)
return ret;
}

if (codec->video_codec_id != SrsCodecVideoAVC) {
if (codec->video_codec_id != SrsCodecVideoAVC && codec->video_codec_id != SrsCodecVideoHEVC) {
return ret;
}

Expand Down
24 changes: 14 additions & 10 deletions trunk/src/kernel/srs_kernel_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ string srs_ts_stream2string(SrsTsStream stream)
case SrsTsStreamAudioAC3: return "AC3";
case SrsTsStreamAudioDTS: return "AudioDTS";
case SrsTsStreamVideoH264: return "H.264";
case SrsTsStreamVideoMpeg4: return "MP4";
case SrsTsStreamVideoHEVC: return "H.265";
case SrsTsStreamVideoMpeg4: return "MP4";
case SrsTsStreamAudioMpeg4: return "MP4A";
default: return "Other";
}
Expand Down Expand Up @@ -381,7 +382,7 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea
{
int ret = ERROR_SUCCESS;

if (vs != SrsTsStreamVideoH264 && as != SrsTsStreamAudioAAC && as != SrsTsStreamAudioMp3) {
if (vs != SrsTsStreamVideoH264 && vs != SrsTsStreamVideoHEVC && as != SrsTsStreamAudioAAC && as != SrsTsStreamAudioMp3) {
ret = ERROR_HLS_NO_STREAM;
srs_error("hls: no pmt pcr pid, vs=%d, as=%d. ret=%d", vs, as, ret);
return ret;
Expand Down Expand Up @@ -461,7 +462,7 @@ int SrsTsContext::encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t p
return ret;
}

if (sid != SrsTsStreamVideoH264 && sid != SrsTsStreamAudioMp3 && sid != SrsTsStreamAudioAAC) {
if (sid != SrsTsStreamVideoH264 && sid != SrsTsStreamVideoHEVC && sid != SrsTsStreamAudioMp3 && sid != SrsTsStreamAudioAAC) {
srs_info("ts: ignore the unknown stream, sid=%d", sid);
return ret;
}
Expand Down Expand Up @@ -802,7 +803,7 @@ SrsTsPacket* SrsTsPacket::create_pmt(SrsTsContext* context, int16_t pmt_number,
pmt->program_info_length = 0;

// must got one valid codec.
srs_assert(vs == SrsTsStreamVideoH264 || as == SrsTsStreamAudioAAC || as == SrsTsStreamAudioMp3);
srs_assert(vs == SrsTsStreamVideoH264 || vs == SrsTsStreamVideoHEVC || as == SrsTsStreamAudioAAC || as == SrsTsStreamAudioMp3);

// if mp3 or aac specified, use audio to carry pcr.
if (as == SrsTsStreamAudioAAC || as == SrsTsStreamAudioMp3) {
Expand All @@ -813,7 +814,7 @@ SrsTsPacket* SrsTsPacket::create_pmt(SrsTsContext* context, int16_t pmt_number,
}

// if h.264 specified, use video to carry pcr.
if (vs == SrsTsStreamVideoH264) {
if (vs == SrsTsStreamVideoH264 || vs == SrsTsStreamVideoHEVC) {
pmt->PCR_PID = vpid;
pmt->infos.push_back(new SrsTsPayloadPMTESInfo(vs, vpid));
}
Expand Down Expand Up @@ -2606,6 +2607,7 @@ int SrsTsPayloadPMT::psi_decode(SrsStream* stream)
switch (info->stream_type) {
case SrsTsStreamVideoH264:
case SrsTsStreamVideoMpeg4:
case SrsTsStreamVideoHEVC:
packet->context->set(info->elementary_PID, SrsTsPidApplyVideo, info->stream_type);
break;
case SrsTsStreamAudioAAC:
Expand Down Expand Up @@ -2692,6 +2694,7 @@ int SrsTsPayloadPMT::psi_encode(SrsStream* stream)
// update the apply pid table
switch (info->stream_type) {
case SrsTsStreamVideoH264:
case SrsTsStreamVideoHEVC:
case SrsTsStreamVideoMpeg4:
packet->context->set(info->elementary_PID, SrsTsPidApplyVideo, info->stream_type);
break;
Expand Down Expand Up @@ -3056,7 +3059,7 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample)
return ret;
}

if (codec->video_codec_id == 7)
if (codec->video_codec_id == SrsCodecVideoAVC)
{
// 5bits, 7.3.1 NAL unit syntax,
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 83.
Expand All @@ -3076,11 +3079,11 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample)
is_sps_pps_appended = true;
}
}
else if (codec->video_codec_id == 12)
else if (codec->video_codec_id == SrsCodecVideoHEVC)
{
// 5bits, 7.3.1 NAL unit syntax,
// H.264-AVC-ISO_IEC_14496-10-2012.pdf, page 83.
SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(sample_unit->bytes[0] & 0x7e);
SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)((sample_unit->bytes[0] & 0x7e) >> 1);

// Insert sps/pps before IDR when there is no sps/pps in samples.
// The sps/pps is parsed from sequence header(generally the first flv packet).
Expand Down Expand Up @@ -3211,14 +3214,15 @@ int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size)
srs_error("http: ts codec demux video failed. ret=%d", ret);
return ret;
}
SrsCodecVideo vcodec = (SrsCodecVideo)codec->video_codec_id;

// ignore info frame,
// @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909
if (sample->frame_type == SrsCodecVideoAVCFrameVideoInfoFrame) {
return ret;
}
if (codec->video_codec_id != SrsCodecVideoAVC) {

if (codec->video_codec_id != SrsCodecVideoAVC && codec->video_codec_id != SrsCodecVideoHEVC) {
return ret;
}

Expand Down

0 comments on commit 23f2160

Please sign in to comment.