Skip to content

Commit

Permalink
H265: For #1747, Support HEVC/H.265 in SRT/RTMP/HLS.
Browse files Browse the repository at this point in the history
  • Loading branch information
runner365 authored and winlinvip committed Dec 4, 2021
1 parent 72ad526 commit 3ca1107
Show file tree
Hide file tree
Showing 14 changed files with 1,601 additions and 117 deletions.
6 changes: 6 additions & 0 deletions trunk/auto/auto_headers.sh
Expand Up @@ -80,6 +80,12 @@ else
srs_undefine_macro "SRS_FFMPEG_FIT" $SRS_AUTO_HEADERS_H
fi

if [ $SRS_H265 = YES ]; then
srs_define_macro "SRS_H265" $SRS_AUTO_HEADERS_H
else
srs_undefine_macro "SRS_H265" $SRS_AUTO_HEADERS_H
fi

if [ $SRS_SIMULATOR = YES ]; then
srs_define_macro "SRS_SIMULATOR" $SRS_AUTO_HEADERS_H
else
Expand Down
5 changes: 5 additions & 0 deletions trunk/auto/options.sh
Expand Up @@ -6,6 +6,7 @@ help=no
SRS_HDS=NO
SRS_SRT=NO
SRS_RTC=YES
SRS_H265=YES
SRS_GB28181=NO
SRS_ICONV=NO
SRS_CXX11=YES
Expand Down Expand Up @@ -129,6 +130,7 @@ Features:
--cxx11=on|off Whether enable the C++11. Default: $(value2switch $SRS_CXX11)
--cxx14=on|off Whether enable the C++14. Default: $(value2switch $SRS_CXX14)
--ffmpeg-fit=on|off Whether enable the FFmpeg fit(source code). Default: $(value2switch $SRS_FFMPEG_FIT)
--h265=on|off Whether build the H.265 support. Default: $(value2switch $SRS_H265)
--prefix=<path> The absolute installation path. Default: $SRS_PREFIX
--gcov=on|off Whether enable the GCOV compiler options. Default: $(value2switch $SRS_GCOV)
Expand Down Expand Up @@ -288,6 +290,8 @@ function parse_user_option() {
--simulator) SRS_SIMULATOR=$(switch2value $value) ;;
--ffmpeg-fit) SRS_FFMPEG_FIT=$(switch2value $value) ;;

--h265) if [[ $value == off ]]; then SRS_H265=NO; else SRS_H265=YES; fi ;;

--with-gb28181) SRS_GB28181=YES ;;
--without-gb28181) SRS_GB28181=NO ;;
--with-iconv) SRS_ICONV=YES ;;
Expand Down Expand Up @@ -525,6 +529,7 @@ function regenerate_options() {
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cherrypy=$(value2switch $SRS_CHERRYPY)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srt=$(value2switch $SRS_SRT)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --rtc=$(value2switch $SRS_RTC)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --h265=$(value2switch $SRS_H265)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --simulator=$(value2switch $SRS_SIMULATOR)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gb28181=$(value2switch $SRS_GB28181)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --iconv=$(value2switch $SRS_ICONV)"
Expand Down
3 changes: 3 additions & 0 deletions trunk/configure
Expand Up @@ -240,6 +240,9 @@ fi
if [[ $SRS_FFMPEG_FIT == YES ]]; then
ModuleLibIncs+=("${LibFfmpegRoot[*]}")
fi
if [[ $SRS_H265 == YES ]]; then
MODULE_FILES+=("srs_raw_hevc")
fi
PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . auto/modules.sh
PROTOCOL_OBJS="${MODULE_OBJS[@]}"
#
Expand Down
8 changes: 7 additions & 1 deletion trunk/src/app/srs_app_hls.cpp
Expand Up @@ -378,6 +378,8 @@ srs_error_t SrsHlsMuxer::segment_open()
std::string default_vcodec_str = _srs_config->get_hls_vcodec(req->vhost);
if (default_vcodec_str == "h264") {
default_vcodec = SrsVideoCodecIdAVC;
} else if (default_vcodec_str == "h265") {
default_vcodec = SrsVideoCodecIdHEVC;
} else if (default_vcodec_str == "vn") {
default_vcodec = SrsVideoCodecIdDisabled;
} else {
Expand Down Expand Up @@ -1319,7 +1321,11 @@ srs_error_t SrsHls::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* forma
}

srs_assert(format->vcodec);
if (format->vcodec->id != SrsVideoCodecIdAVC) {
bool ignore_frame = (format->vcodec->id != SrsVideoCodecIdAVC);
#ifdef SRS_H265
ignore_frame = ignore_frame && (format->vcodec->id != SrsVideoCodecIdHEVC);
#endif
if (ignore_frame) {
return err;
}

Expand Down
7 changes: 5 additions & 2 deletions trunk/src/app/srs_app_source.cpp
Expand Up @@ -614,8 +614,11 @@ srs_error_t SrsGopCache::cache(SrsSharedPtrMessage* shared_msg)

// got video, update the video count if acceptable
if (msg->is_video()) {
// drop video when not h.264
if (!SrsFlvVideo::h264(msg->payload, msg->size)) {
bool ignore_frame = !SrsFlvVideo::h264(msg->payload, msg->size);
#ifdef SRS_H265
ignore_frame = ignore_frame && !SrsFlvVideo::hevc(msg->payload, msg->size);
#endif
if (ignore_frame) {
return err;
}

Expand Down

0 comments on commit 3ca1107

Please sign in to comment.