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 Sep 23, 2021
1 parent 054dccd commit a6dc187
Show file tree
Hide file tree
Showing 15 changed files with 1,602 additions and 118 deletions.
6 changes: 6 additions & 0 deletions trunk/auto/auto_headers.sh
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -128,6 +129,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 @@ -279,6 +281,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 @@ -499,6 +503,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,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 @@ -1308,7 +1310,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
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,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
Loading

0 comments on commit a6dc187

Please sign in to comment.