<html dir="ltr"><head></head><body style="text-align:left; direction:ltr;"><div>On Fri, 2018-12-07 at 10:01 +0100, Thomas Guillem wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre><br></pre><pre>On Fri, Dec 7, 2018, at 05:43, Shaleen Jain wrote:</pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>---</pre><pre> modules/stream_out/Makefile.am | 2 +</pre><pre> modules/stream_out/chromecast/cast.cpp | 242 ++-----------------------</pre><pre> modules/stream_out/renderer_common.cpp | 213 ++++++++++++++++++++++</pre><pre> modules/stream_out/renderer_common.hpp | 109 +++++++++++</pre><pre> 4 files changed, 335 insertions(+), 231 deletions(-)</pre><pre> create mode 100644 modules/stream_out/renderer_common.cpp</pre><pre> create mode 100644 modules/stream_out/renderer_common.hpp</pre><pre><br></pre><pre>diff --git a/modules/stream_out/Makefile.am b/modules/stream_out/</pre><pre>Makefile.am</pre><pre>index 6bfc38fff2..dfb262c467 100644</pre><pre>--- a/modules/stream_out/Makefile.am</pre><pre>+++ b/modules/stream_out/Makefile.am</pre><pre>@@ -107,6 +107,8 @@ libdemux_chromecast_plugin_la_CPPFLAGS = $</pre><pre>(AM_CPPFLAGS) -Istream_out/chromecast</pre><pre> </pre><pre> libstream_out_chromecast_plugin_la_SOURCES = stream_out/chromecast/</pre><pre>cast.cpp stream_out/chromecast/chromecast.h \</pre><pre> stream_out/chromecast/</pre><pre>cast_channel.proto \</pre><pre>+ stream_out/</pre><pre>renderer_common.hpp \</pre><pre>+ stream_out/</pre><pre>renderer_common.cpp \</pre><pre> stream_out/chromecast/</pre><pre>chromecast_common.h stream_out/chromecast/chromecast_ctrl.cpp \</pre><pre> misc/webservices/json.h </pre><pre>misc/webservices/json.c stream_out/chromecast/</pre><pre>chromecast_communication.cpp</pre><pre> nodist_libstream_out_chromecast_plugin_la_SOURCES = stream_out/</pre><pre>chromecast/cast_channel.pb.cc</pre><pre>diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/</pre><pre>stream_out/chromecast/cast.cpp</pre><pre>index 7026eb1a95..b442fc1e1e 100644</pre><pre>--- a/modules/stream_out/chromecast/cast.cpp</pre><pre>+++ b/modules/stream_out/chromecast/cast.cpp</pre><pre>@@ -30,6 +30,7 @@</pre><pre> # include "config.h"</pre><pre> #endif</pre><pre> </pre><pre>+#include "../renderer_common.hpp"</pre><pre> #include "chromecast.h"</pre><pre> #include <vlc_dialog.h></pre><pre> </pre><pre>@@ -157,8 +158,6 @@ struct sout_stream_sys_t</pre><pre> unsigned int spu_streams_count;</pre><pre> </pre><pre> private:</pre><pre>- std::string GetVencOption( sout_stream_t *, vlc_fourcc_t *,</pre><pre>- const video_format_t *, int );</pre><pre> std::string GetAcodecOption( sout_stream_t *, vlc_fourcc_t *, const </pre><pre>audio_format_t *, int );</pre><pre> std::string GetVcodecOption( sout_stream_t *, vlc_fourcc_t *, const </pre><pre>video_format_t *, int );</pre><pre> bool UpdateOutput( sout_stream_t * );</pre><pre>@@ -199,39 +198,6 @@ static const char *const ppsz_sout_options[] = {</pre><pre> #define HTTP_PORT_TEXT N_("HTTP port")</pre><pre> #define HTTP_PORT_LONGTEXT N_("This sets the HTTP port of the local </pre><pre>server " \</pre><pre> "used to stream the media to the </pre><pre>Chromecast.")</pre><pre>-#define PERF_TEXT N_( "Performance warning" )</pre><pre>-#define PERF_LONGTEXT N_( "Display a performance warning when </pre><pre>transcoding" )</pre><pre>-#define AUDIO_PASSTHROUGH_TEXT N_( "Enable Audio passthrough" )</pre><pre>-#define AUDIO_PASSTHROUGH_LONGTEXT N_( "Disable if your receiver does </pre><pre>not support Dolby®." )</pre><pre>-</pre><pre>-enum {</pre><pre>- CONVERSION_QUALITY_HIGH = 0,</pre><pre>- CONVERSION_QUALITY_MEDIUM = 1,</pre><pre>- CONVERSION_QUALITY_LOW = 2,</pre><pre>- CONVERSION_QUALITY_LOWCPU = 3,</pre><pre>-};</pre><pre>-</pre><pre>-#if defined (__ANDROID__) || defined (__arm__) || (defined </pre><pre>(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)</pre><pre>-# define CONVERSION_QUALITY_DEFAULT CONVERSION_QUALITY_LOW</pre><pre>-#else</pre><pre>-# define CONVERSION_QUALITY_DEFAULT CONVERSION_QUALITY_MEDIUM</pre><pre>-#endif</pre><pre>-</pre><pre>-static const int conversion_quality_list[] = {</pre><pre>- CONVERSION_QUALITY_HIGH,</pre><pre>- CONVERSION_QUALITY_MEDIUM,</pre><pre>- CONVERSION_QUALITY_LOW,</pre><pre>- CONVERSION_QUALITY_LOWCPU,</pre><pre>-};</pre><pre>-static const char *const conversion_quality_list_text[] = {</pre><pre>- N_( "High (high quality and high bandwidth)" ),</pre><pre>- N_( "Medium (medium quality and medium bandwidth)" ),</pre><pre>- N_( "Low (low quality and low bandwidth)" ),</pre><pre>- N_( "Low CPU (low quality but high bandwidth)" ),</pre><pre>-};</pre><pre>-</pre><pre>-#define CONVERSION_QUALITY_TEXT N_( "Conversion quality" )</pre><pre>-#define CONVERSION_QUALITY_LONGTEXT N_( "Change this option to increase </pre><pre>conversion speed or quality." )</pre><pre> </pre><pre> #define IP_ADDR_TEXT N_("IP Address")</pre><pre> #define IP_ADDR_LONGTEXT N_("IP Address of the Chromecast.")</pre><pre>@@ -263,12 +229,7 @@ vlc_module_begin ()</pre><pre> add_integer(SOUT_CFG_PREFIX "http-port", HTTP_PORT, HTTP_PORT_TEXT, </pre><pre>HTTP_PORT_LONGTEXT, false)</pre><pre> add_obsolete_string(SOUT_CFG_PREFIX "mux")</pre><pre> add_obsolete_string(SOUT_CFG_PREFIX "mime")</pre><pre>- add_integer(SOUT_CFG_PREFIX "show-perf-warning", 1, PERF_TEXT, </pre><pre>PERF_LONGTEXT, true )</pre><pre>- change_private()</pre><pre>- add_bool(SOUT_CFG_PREFIX "audio-passthrough", false, </pre><pre>AUDIO_PASSTHROUGH_TEXT, AUDIO_PASSTHROUGH_LONGTEXT, false )</pre><pre>- add_integer(SOUT_CFG_PREFIX "conversion-quality", </pre><pre>CONVERSION_QUALITY_DEFAULT,</pre><pre>- CONVERSION_QUALITY_TEXT, CONVERSION_QUALITY_LONGTEXT, </pre><pre>false );</pre><pre>- change_integer_list(conversion_quality_list, </pre><pre>conversion_quality_list_text)</pre><pre>+ add_renderer_opts(SOUT_CFG_PREFIX)</pre><pre> </pre><pre> add_submodule()</pre><pre> /* sout proxy that start the cc input when all streams are loaded */</pre><pre>@@ -927,198 +888,16 @@ bool sout_stream_sys_t::transcodingCanFallback() const</pre><pre> return transcoding_state != (TRANSCODING_VIDEO|TRANSCODING_AUDIO);</pre><pre> }</pre><pre> </pre><pre>-static std::string GetVencVPXOption( sout_stream_t * /* p_stream */,</pre><pre>- const video_format_t * /* p_vid </pre><pre>*/,</pre><pre>- int /* i_quality */ )</pre><pre>-{</pre><pre>- return "venc=vpx{quality-mode=1}";</pre><pre>-}</pre><pre>-</pre><pre>-static std::string GetVencQSVH264Option( sout_stream_t * /* p_stream </pre><pre>*/,</pre><pre>- const video_format_t * /* </pre><pre>p_vid */,</pre><pre>- int i_quality )</pre><pre>-{</pre><pre>- std::stringstream ssout;</pre><pre>- static const char video_target_usage_quality[] = "quality";</pre><pre>- static const char video_target_usage_balanced[] = "balanced";</pre><pre>- static const char video_target_usage_speed[] = "speed";</pre><pre>- static const char video_bitrate_high[] = "vb=8000000";</pre><pre>- static const char video_bitrate_low[] = "vb=3000000";</pre><pre>- const char *psz_video_target_usage;</pre><pre>- const char *psz_video_bitrate;</pre><pre>-</pre><pre>- switch ( i_quality )</pre><pre>- {</pre><pre>- case CONVERSION_QUALITY_HIGH:</pre><pre>- psz_video_target_usage = video_target_usage_quality;</pre><pre>- psz_video_bitrate = video_bitrate_high;</pre><pre>- break;</pre><pre>- case CONVERSION_QUALITY_MEDIUM:</pre><pre>- psz_video_target_usage = video_target_usage_balanced;</pre><pre>- psz_video_bitrate = video_bitrate_high;</pre><pre>- break;</pre><pre>- case CONVERSION_QUALITY_LOW:</pre><pre>- psz_video_target_usage = video_target_usage_balanced;</pre><pre>- psz_video_bitrate = video_bitrate_low;</pre><pre>- break;</pre><pre>- default:</pre><pre>- case CONVERSION_QUALITY_LOWCPU:</pre><pre>- psz_video_target_usage = video_target_usage_speed;</pre><pre>- psz_video_bitrate = video_bitrate_low;</pre><pre>- break;</pre><pre>- }</pre><pre>-</pre><pre>- ssout << "venc=qsv{target-usage=" << psz_video_target_usage <<</pre><pre>- "}," << psz_video_bitrate;</pre><pre>- return ssout.str();</pre><pre>-}</pre><pre>-</pre><pre>-static std::string GetVencX264Option( sout_stream_t * /* p_stream */,</pre><pre>- const video_format_t *p_vid,</pre><pre>- int i_quality )</pre><pre>-{</pre><pre>- std::stringstream ssout;</pre><pre>- static const char video_x264_preset_veryfast[] = "veryfast";</pre><pre>- static const char video_x264_preset_ultrafast[] = "ultrafast";</pre><pre>- const char *psz_video_x264_preset;</pre><pre>- unsigned i_video_x264_crf_hd, i_video_x264_crf_720p;</pre><pre>-</pre><pre>- switch ( i_quality )</pre><pre>- {</pre><pre>- case CONVERSION_QUALITY_HIGH:</pre><pre>- i_video_x264_crf_hd = i_video_x264_crf_720p = 21;</pre><pre>- psz_video_x264_preset = video_x264_preset_veryfast;</pre><pre>- break;</pre><pre>- case CONVERSION_QUALITY_MEDIUM:</pre><pre>- i_video_x264_crf_hd = 23;</pre><pre>- i_video_x264_crf_720p = 21;</pre><pre>- psz_video_x264_preset = video_x264_preset_veryfast;</pre><pre>- break;</pre><pre>- case CONVERSION_QUALITY_LOW:</pre><pre>- i_video_x264_crf_hd = i_video_x264_crf_720p = 23;</pre><pre>- psz_video_x264_preset = video_x264_preset_veryfast;</pre><pre>- break;</pre><pre>- default:</pre><pre>- case CONVERSION_QUALITY_LOWCPU:</pre><pre>- i_video_x264_crf_hd = i_video_x264_crf_720p = 23;</pre><pre>- psz_video_x264_preset = video_x264_preset_ultrafast;</pre><pre>- break;</pre><pre>- }</pre><pre>-</pre><pre>- const bool b_hdres = p_vid->i_height == 0 || p_vid->i_height >= </pre><pre>800;</pre><pre>- unsigned i_video_x264_crf = b_hdres ? i_video_x264_crf_hd : </pre><pre>i_video_x264_crf_720p;</pre><pre>-</pre><pre>- ssout << "venc=x264{preset=" << psz_video_x264_preset</pre><pre>- << ",crf=" << i_video_x264_crf << "}";</pre><pre>- return ssout.str();</pre><pre>-}</pre><pre>-</pre><pre>-#ifdef __APPLE__</pre><pre>-static std::string GetVencAvcodecVTOption( sout_stream_t * /* p_stream </pre><pre>*/,</pre><pre>- const video_format_t * </pre><pre>p_vid,</pre><pre>- int i_quality )</pre><pre>-{</pre><pre>- std::stringstream ssout;</pre><pre>- ssout << </pre><pre>"venc=avcodec{codec=h264_videotoolbox,options{realtime=1}}";</pre><pre>- switch( i_quality )</pre><pre>- {</pre><pre>- /* Here, performances issues won't come from videotoolbox but </pre><pre>from</pre><pre>- * some old chromecast devices */</pre><pre>-</pre><pre>- case CONVERSION_QUALITY_HIGH:</pre><pre>- break;</pre><pre>- case CONVERSION_QUALITY_MEDIUM:</pre><pre>- ssout << ",vb=8000000";</pre><pre>- break;</pre><pre>- case CONVERSION_QUALITY_LOW:</pre><pre>- case CONVERSION_QUALITY_LOWCPU:</pre><pre>- ssout << ",vb=3000000";</pre><pre>- break;</pre><pre>- }</pre><pre>-</pre><pre>- return ssout.str();</pre><pre>-}</pre><pre>-#endif</pre><pre>-</pre><pre>-static struct</pre><pre>-{</pre><pre>- vlc_fourcc_t fcc;</pre><pre>- std::string (*get_opt)( sout_stream_t *, const video_format_t *, </pre><pre>int);</pre><pre>-} venc_opt_list[] = {</pre><pre>+venc_options venc_opt_list[] = {</pre><pre> #ifdef __APPLE__</pre><pre>- { .fcc = VLC_CODEC_H264, .get_opt = GetVencAvcodecVTOption },</pre><pre>+ { .fcc = VLC_CODEC_H264, .get_opt = </pre><pre>vlc_sout_renderer_GetVencAvcodecVTOption },</pre><pre> #endif</pre><pre>- { .fcc = VLC_CODEC_H264, .get_opt = GetVencQSVH264Option },</pre><pre>- { .fcc = VLC_CODEC_H264, .get_opt = GetVencX264Option },</pre><pre>- { .fcc = VLC_CODEC_VP8, .get_opt = GetVencVPXOption },</pre><pre>+ { .fcc = VLC_CODEC_H264, .get_opt = </pre><pre>vlc_sout_renderer_GetVencQSVH264Option },</pre><pre>+ { .fcc = VLC_CODEC_H264, .get_opt = </pre><pre>vlc_sout_renderer_GetVencX264Option },</pre><pre>+ { .fcc = VLC_CODEC_VP8, .get_opt = </pre><pre>vlc_sout_renderer_GetVencVPXOption },</pre><pre> { .fcc = VLC_CODEC_H264, .get_opt = NULL },</pre><pre> };</pre><pre> </pre></blockquote><pre><br></pre><pre>I see a lot of duplicate code between cast.cpp GetVcodecOption() and dlna.cpp GetVcodecOption()</pre><pre><br></pre><pre>This list should be internal to renderer_common.cpp</pre><pre>Renderer modules shouldn't handle what H264 encoder module need to be used. This should be done by your renderer_common.cpp helper.</pre><pre><br></pre><pre>The only thing that will change between renderer modules are the codecs. The way to encode for a particular codec should be hidden then."</pre><pre><br></pre></blockquote><pre><br></pre><pre>The problem with this is that chromecast doesn't provide a codec to use upfront.</pre><pre>It wait's on GetVencOption() to try every encoder before returning the codec to use.</pre><pre><br></pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>You should also factorize the maxwidth/with/fps code.</pre><pre><br></pre><pre><br></pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>-std::string</pre><pre>-sout_stream_sys_t::GetVencOption( sout_stream_t *p_stream, vlc_fourcc_t </pre><pre>*p_codec_video,</pre><pre>- const video_format_t *p_vid, int </pre><pre>i_quality )</pre><pre>-{</pre><pre>- for( size_t i = (venc_opt_idx == -1 ? 0 : venc_opt_idx);</pre><pre>- i < ARRAY_SIZE(venc_opt_list); ++i )</pre><pre>- {</pre><pre>- std::stringstream ssout, ssvenc;</pre><pre>- char fourcc[5];</pre><pre>- ssvenc << "vcodec=";</pre><pre>- vlc_fourcc_to_char( venc_opt_list[i].fcc, fourcc );</pre><pre>- fourcc[4] = '\0';</pre><pre>- ssvenc << fourcc << ',';</pre><pre>-</pre><pre>- if( venc_opt_list[i].get_opt != NULL )</pre><pre>- ssvenc << venc_opt_list[i].get_opt( p_stream, p_vid, </pre><pre>i_quality ) << ',';</pre><pre>-</pre><pre>- if( venc_opt_list[i].get_opt == NULL</pre><pre>- || ( venc_opt_idx != -1 && (unsigned) venc_opt_idx == i) )</pre><pre>- {</pre><pre>- venc_opt_idx = i;</pre><pre>- *p_codec_video = venc_opt_list[i].fcc;</pre><pre>- return ssvenc.str();</pre><pre>- }</pre><pre>-</pre><pre>- /* Test if a module can encode with the specified options / </pre><pre>fmt_video. */</pre><pre>- ssout << "transcode{" << ssvenc.str() << "}:dummy";</pre><pre>-</pre><pre>- sout_stream_t *p_sout_test =</pre><pre>- sout_StreamChainNew( p_stream->p_sout, ssout.str().c_str(), </pre><pre>NULL, NULL );</pre><pre>-</pre><pre>- if( p_sout_test != NULL )</pre><pre>- {</pre><pre>- p_sout_test->obj.flags |= OBJECT_FLAGS_QUIET|</pre><pre>OBJECT_FLAGS_NOINTERACT;</pre><pre>-</pre><pre>- es_format_t fmt;</pre><pre>- es_format_InitFromVideo( &fmt, p_vid );</pre><pre>- fmt.i_codec = fmt.video.i_chroma = VLC_CODEC_I420;</pre><pre>-</pre><pre>- /* Test the maximum size/fps we will encode */</pre><pre>- fmt.video.i_visible_width = fmt.video.i_width = 1920;</pre><pre>- fmt.video.i_visible_height = fmt.video.i_height = 1080;</pre><pre>- fmt.video.i_frame_rate = 30;</pre><pre>- fmt.video.i_frame_rate_base = 1;</pre><pre>-</pre><pre>- void *id = sout_StreamIdAdd( p_sout_test, &fmt );</pre><pre>-</pre><pre>- es_format_Clean( &fmt );</pre><pre>- const bool success = id != NULL;</pre><pre>-</pre><pre>- if( id )</pre><pre>- sout_StreamIdDel( p_sout_test, id );</pre><pre>- sout_StreamChainDelete( p_sout_test, NULL );</pre><pre>-</pre><pre>- if( success )</pre><pre>- {</pre><pre>- venc_opt_idx = i;</pre><pre>- *p_codec_video = venc_opt_list[i].fcc;</pre><pre>- return ssvenc.str();</pre><pre>- }</pre><pre>- }</pre><pre>- }</pre><pre>- vlc_assert_unreachable();</pre><pre>-}</pre><pre>-</pre><pre> std::string</pre><pre> sout_stream_sys_t::GetVcodecOption( sout_stream_t *p_stream, </pre><pre>vlc_fourcc_t *p_codec_video,</pre><pre> const video_format_t *p_vid, int </pre><pre>i_quality )</pre><pre>@@ -1127,7 +906,8 @@ sout_stream_sys_t::GetVcodecOption( sout_stream_t </pre><pre>*p_stream, vlc_fourcc_t *p_cod</pre><pre> static const char video_maxres_hd[] = </pre><pre>"maxwidth=1920,maxheight=1080";</pre><pre> static const char video_maxres_720p[] = </pre><pre>"maxwidth=1280,maxheight=720";</pre><pre> </pre><pre>- ssout << GetVencOption( p_stream, p_codec_video, p_vid, </pre><pre>i_quality );</pre><pre>+ ssout << vlc_sout_renderer_GetVencOption( p_stream, venc_opt_idx, </pre><pre>venc_opt_list,</pre><pre>+ ARRAY_SIZE(venc_opt_list), p_codec_video, p_vid, </pre><pre>i_quality );</pre><pre> </pre><pre> switch ( i_quality )</pre><pre> {</pre><pre>@@ -1291,7 +1071,7 @@ bool </pre><pre>sout_stream_sys_t::UpdateOutput( sout_stream_t *p_stream )</pre><pre> if ( !canRemux )</pre><pre> {</pre><pre> if ( !perf_warning_shown && i_codec_video == 0 && </pre><pre>p_original_video</pre><pre>- && var_InheritInteger( p_stream, SOUT_CFG_PREFIX "show-perf-</pre><pre>warning" ) )</pre><pre>+ && var_InheritInteger( p_stream, RENDERER_CFG_PREFIX "show-</pre><pre>perf-warning" ) )</pre><pre> {</pre><pre> int res = vlc_dialog_wait_question( p_stream,</pre><pre> VLC_DIALOG_QUESTION_WARNING,</pre><pre>@@ -1304,7 +1084,7 @@ bool </pre><pre>sout_stream_sys_t::UpdateOutput( sout_stream_t *p_stream )</pre><pre> return false;</pre><pre> perf_warning_shown = true;</pre><pre> if ( res == 2 )</pre><pre>- config_PutInt(SOUT_CFG_PREFIX "show-perf-warning", 0 );</pre><pre>+ config_PutInt(RENDERER_CFG_PREFIX "show-perf-warning", </pre><pre>0 );</pre><pre> }</pre><pre> </pre><pre> const int i_quality = var_InheritInteger( p_stream, </pre><pre>SOUT_CFG_PREFIX "conversion-quality" );</pre><pre>diff --git a/modules/stream_out/renderer_common.cpp b/modules/</pre><pre>stream_out/renderer_common.cpp</pre><pre>new file mode 100644</pre><pre>index 0000000000..6571685a22</pre><pre>--- /dev/null</pre><pre>+++ b/modules/stream_out/renderer_common.cpp</pre><pre>@@ -0,0 +1,213 @@</pre><pre>+/</pre><pre>*****************************************************************************</pre><pre>+ * renderer_common.cpp : renderer helper functions</pre><pre>+ </pre><pre>*****************************************************************************</pre><pre>+ * Copyright © 2014-2018 VideoLAN</pre><pre>+ *</pre><pre>+ * Authors: Adrien Maglo <</pre><a href="mailto:magsoft@videolan.org"><pre>magsoft@videolan.org</pre></a><pre>></pre><pre>+ * Jean-Baptiste Kempf <</pre><a href="mailto:jb@videolan.org"><pre>jb@videolan.org</pre></a><pre>></pre><pre>+ * Steve Lhomme <</pre><a href="mailto:robux4@videolabs.io"><pre>robux4@videolabs.io</pre></a><pre>></pre><pre>+ * Shaleen Jain <</pre><a href="mailto:shaleen@jain.sh"><pre>shaleen@jain.sh</pre></a><pre>></pre><pre>+ *</pre><pre>+ * This program is free software; you can redistribute it and/or modify </pre><pre>it</pre><pre>+ * under the terms of the GNU Lesser General Public License as </pre><pre>published by</pre><pre>+ * the Free Software Foundation; either version 2.1 of the License, or</pre><pre>+ * (at your option) any later version.</pre><pre>+ *</pre><pre>+ * This program is distributed in the hope that it will be useful,</pre><pre>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</pre><pre>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</pre><pre>+ * GNU Lesser General Public License for more details.</pre><pre>+ *</pre><pre>+ * You should have received a copy of the GNU Lesser General Public </pre><pre>License</pre><pre>+ * along with this program; if not, write to the Free Software </pre><pre>Foundation,</pre><pre>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.</pre><pre>+ </pre><pre>*****************************************************************************/</pre><pre>+</pre><pre>+#ifdef HAVE_CONFIG_H</pre><pre>+# include "config.h"</pre><pre>+#endif</pre><pre>+</pre><pre>+#include <assert.h></pre><pre>+#include <sstream></pre><pre>+</pre><pre>+#include "renderer_common.hpp"</pre><pre>+</pre><pre>+std::string</pre><pre>+vlc_sout_renderer_GetVencOption( sout_stream_t *p_stream, int </pre><pre>venc_opt_idx,</pre><pre>+ venc_options venc_opt_list[], size_t opt_list_length,</pre><pre>+ vlc_fourcc_t *p_codec_video, const video_format_t *p_vid,</pre><pre>+ int i_quality )</pre><pre>+{</pre><pre>+ for( size_t i = (venc_opt_idx == -1 ? 0 : venc_opt_idx);</pre><pre>+ i < opt_list_length; ++i )</pre><pre>+ {</pre><pre>+ std::stringstream ssout, ssvenc;</pre><pre>+ char fourcc[5];</pre><pre>+ ssvenc << "vcodec=";</pre><pre>+ vlc_fourcc_to_char( venc_opt_list[i].fcc, fourcc );</pre><pre>+ fourcc[4] = '\0';</pre><pre>+ ssvenc << fourcc << ',';</pre><pre>+</pre><pre>+ if( venc_opt_list[i].get_opt != NULL )</pre><pre>+ ssvenc << venc_opt_list[i].get_opt( p_stream, p_vid, </pre><pre>i_quality ) << ',';</pre><pre>+</pre><pre>+ if( venc_opt_list[i].get_opt == NULL</pre><pre>+ || ( venc_opt_idx != -1 && (unsigned) venc_opt_idx == i) )</pre><pre>+ {</pre><pre>+ venc_opt_idx = i;</pre><pre>+ *p_codec_video = venc_opt_list[i].fcc;</pre><pre>+ return ssvenc.str();</pre><pre>+ }</pre><pre>+</pre><pre>+ /* Test if a module can encode with the specified options / </pre><pre>fmt_video. */</pre><pre>+ ssout << "transcode{" << ssvenc.str() << "}:dummy";</pre><pre>+</pre><pre>+ sout_stream_t *p_sout_test =</pre><pre>+ sout_StreamChainNew( p_stream->p_sout, ssout.str().c_str(), </pre><pre>NULL, NULL );</pre><pre>+</pre><pre>+ if( p_sout_test != NULL )</pre><pre>+ {</pre><pre>+ p_sout_test->obj.flags |= OBJECT_FLAGS_QUIET|</pre><pre>OBJECT_FLAGS_NOINTERACT;</pre><pre>+</pre><pre>+ es_format_t fmt;</pre><pre>+ es_format_InitFromVideo( &fmt, p_vid );</pre><pre>+ fmt.i_codec = fmt.video.i_chroma = VLC_CODEC_I420;</pre><pre>+</pre><pre>+ /* Test the maximum size/fps we will encode */</pre><pre>+ fmt.video.i_visible_width = fmt.video.i_width = 1920;</pre><pre>+ fmt.video.i_visible_height = fmt.video.i_height = 1080;</pre><pre>+ fmt.video.i_frame_rate = 30;</pre><pre>+ fmt.video.i_frame_rate_base = 1;</pre><pre>+</pre><pre>+ void *id = sout_StreamIdAdd( p_sout_test, &fmt );</pre><pre>+</pre><pre>+ es_format_Clean( &fmt );</pre><pre>+ const bool success = id != NULL;</pre><pre>+</pre><pre>+ if( id )</pre><pre>+ sout_StreamIdDel( p_sout_test, id );</pre><pre>+ sout_StreamChainDelete( p_sout_test, NULL );</pre><pre>+</pre><pre>+ if( success )</pre><pre>+ {</pre><pre>+ venc_opt_idx = i;</pre><pre>+ *p_codec_video = venc_opt_list[i].fcc;</pre><pre>+ return ssvenc.str();</pre><pre>+ }</pre><pre>+ }</pre><pre>+ }</pre><pre>+ vlc_assert_unreachable();</pre><pre>+}</pre><pre>+</pre><pre>+std::string vlc_sout_renderer_GetVencVPXOption( sout_stream_t * /* </pre><pre>p_stream */,</pre><pre>+ const video_format_t * /* p_vid </pre><pre>*/,</pre><pre>+ int /* i_quality */ )</pre><pre>+{</pre><pre>+ return "venc=vpx{quality-mode=1}";</pre><pre>+}</pre><pre>+</pre><pre>+std::string vlc_sout_renderer_GetVencQSVH264Option( sout_stream_t * /* </pre><pre>p_stream */,</pre><pre>+ const video_format_t * /* </pre><pre>p_vid */,</pre><pre>+ int i_quality )</pre><pre>+{</pre><pre>+ std::stringstream ssout;</pre><pre>+ static const char video_target_usage_quality[] = "quality";</pre><pre>+ static const char video_target_usage_balanced[] = "balanced";</pre><pre>+ static const char video_target_usage_speed[] = "speed";</pre><pre>+ static const char video_bitrate_high[] = "vb=8000000";</pre><pre>+ static const char video_bitrate_low[] = "vb=3000000";</pre><pre>+ const char *psz_video_target_usage;</pre><pre>+ const char *psz_video_bitrate;</pre><pre>+</pre><pre>+ switch ( i_quality )</pre><pre>+ {</pre><pre>+ case CONVERSION_QUALITY_HIGH:</pre><pre>+ psz_video_target_usage = video_target_usage_quality;</pre><pre>+ psz_video_bitrate = video_bitrate_high;</pre><pre>+ break;</pre><pre>+ case CONVERSION_QUALITY_MEDIUM:</pre><pre>+ psz_video_target_usage = video_target_usage_balanced;</pre><pre>+ psz_video_bitrate = video_bitrate_high;</pre><pre>+ break;</pre><pre>+ case CONVERSION_QUALITY_LOW:</pre><pre>+ psz_video_target_usage = video_target_usage_balanced;</pre><pre>+ psz_video_bitrate = video_bitrate_low;</pre><pre>+ break;</pre><pre>+ default:</pre><pre>+ case CONVERSION_QUALITY_LOWCPU:</pre><pre>+ psz_video_target_usage = video_target_usage_speed;</pre><pre>+ psz_video_bitrate = video_bitrate_low;</pre><pre>+ break;</pre><pre>+ }</pre><pre>+</pre><pre>+ ssout << "venc=qsv{target-usage=" << psz_video_target_usage <<</pre><pre>+ "}," << psz_video_bitrate;</pre><pre>+ return ssout.str();</pre><pre>+}</pre><pre>+</pre><pre>+std::string vlc_sout_renderer_GetVencX264Option( sout_stream_t * /* </pre><pre>p_stream */,</pre><pre>+ const video_format_t *p_vid,</pre><pre>+ int i_quality )</pre><pre>+{</pre><pre>+ std::stringstream ssout;</pre><pre>+ static const char video_x264_preset_veryfast[] = "veryfast";</pre><pre>+ static const char video_x264_preset_ultrafast[] = "ultrafast";</pre><pre>+ const char *psz_video_x264_preset;</pre><pre>+ unsigned i_video_x264_crf_hd, i_video_x264_crf_720p;</pre><pre>+</pre><pre>+ switch ( i_quality )</pre><pre>+ {</pre><pre>+ case CONVERSION_QUALITY_HIGH:</pre><pre>+ i_video_x264_crf_hd = i_video_x264_crf_720p = 21;</pre><pre>+ psz_video_x264_preset = video_x264_preset_veryfast;</pre><pre>+ break;</pre><pre>+ case CONVERSION_QUALITY_MEDIUM:</pre><pre>+ i_video_x264_crf_hd = 23;</pre><pre>+ i_video_x264_crf_720p = 21;</pre><pre>+ psz_video_x264_preset = video_x264_preset_veryfast;</pre><pre>+ break;</pre><pre>+ case CONVERSION_QUALITY_LOW:</pre><pre>+ i_video_x264_crf_hd = i_video_x264_crf_720p = 23;</pre><pre>+ psz_video_x264_preset = video_x264_preset_veryfast;</pre><pre>+ break;</pre><pre>+ default:</pre><pre>+ case CONVERSION_QUALITY_LOWCPU:</pre><pre>+ i_video_x264_crf_hd = i_video_x264_crf_720p = 23;</pre><pre>+ psz_video_x264_preset = video_x264_preset_ultrafast;</pre><pre>+ break;</pre><pre>+ }</pre><pre>+</pre><pre>+ const bool b_hdres = p_vid->i_height == 0 || p_vid->i_height >= </pre><pre>800;</pre><pre>+ unsigned i_video_x264_crf = b_hdres ? i_video_x264_crf_hd : </pre><pre>i_video_x264_crf_720p;</pre><pre>+</pre><pre>+ ssout << "venc=x264{preset=" << psz_video_x264_preset</pre><pre>+ << ",crf=" << i_video_x264_crf << "}";</pre><pre>+ return ssout.str();</pre><pre>+}</pre><pre>+</pre><pre>+#ifdef __APPLE__</pre><pre>+std::string vlc_sout_renderer_GetVencAvcodecVTOption( sout_stream_t * /</pre><pre>* p_stream */,</pre><pre>+ const video_format_t * </pre><pre>p_vid,</pre><pre>+ int i_quality )</pre><pre>+{</pre><pre>+ std::stringstream ssout;</pre><pre>+ ssout << </pre><pre>"venc=avcodec{codec=h264_videotoolbox,options{realtime=1}}";</pre><pre>+ switch( i_quality )</pre><pre>+ {</pre><pre>+ /* Here, performances issues won't come from videotoolbox but </pre><pre>from</pre><pre>+ * some old chromecast devices */</pre><pre>+</pre><pre>+ case CONVERSION_QUALITY_HIGH:</pre><pre>+ break;</pre><pre>+ case CONVERSION_QUALITY_MEDIUM:</pre><pre>+ ssout << ",vb=8000000";</pre><pre>+ break;</pre><pre>+ case CONVERSION_QUALITY_LOW:</pre><pre>+ case CONVERSION_QUALITY_LOWCPU:</pre><pre>+ ssout << ",vb=3000000";</pre><pre>+ break;</pre><pre>+ }</pre><pre>+</pre><pre>+ return ssout.str();</pre><pre>+}</pre><pre>+#endif</pre><pre>diff --git a/modules/stream_out/renderer_common.hpp b/modules/</pre><pre>stream_out/renderer_common.hpp</pre><pre>new file mode 100644</pre><pre>index 0000000000..8233d5874b</pre><pre>--- /dev/null</pre><pre>+++ b/modules/stream_out/renderer_common.hpp</pre><pre>@@ -0,0 +1,109 @@</pre><pre>+/</pre><pre>*****************************************************************************</pre><pre>+ * renderer_common.hpp : renderer helper functions</pre><pre>+ </pre><pre>*****************************************************************************</pre><pre>+ * Copyright © 2014-2018 VideoLAN</pre><pre>+ *</pre><pre>+ * Authors: Adrien Maglo <</pre><a href="mailto:magsoft@videolan.org"><pre>magsoft@videolan.org</pre></a><pre>></pre><pre>+ * Jean-Baptiste Kempf <</pre><a href="mailto:jb@videolan.org"><pre>jb@videolan.org</pre></a><pre>></pre><pre>+ * Steve Lhomme <</pre><a href="mailto:robux4@videolabs.io"><pre>robux4@videolabs.io</pre></a><pre>></pre><pre>+ * Shaleen Jain <</pre><a href="mailto:shaleen@jain.sh"><pre>shaleen@jain.sh</pre></a><pre>></pre><pre>+ *</pre><pre>+ * This program is free software; you can redistribute it and/or modify </pre><pre>it</pre><pre>+ * under the terms of the GNU Lesser General Public License as </pre><pre>published by</pre><pre>+ * the Free Software Foundation; either version 2.1 of the License, or</pre><pre>+ * (at your option) any later version.</pre><pre>+ *</pre><pre>+ * This program is distributed in the hope that it will be useful,</pre><pre>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</pre><pre>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</pre><pre>+ * GNU Lesser General Public License for more details.</pre><pre>+ *</pre><pre>+ * You should have received a copy of the GNU Lesser General Public </pre><pre>License</pre><pre>+ * along with this program; if not, write to the Free Software </pre><pre>Foundation,</pre><pre>+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.</pre><pre>+ </pre><pre>*****************************************************************************/</pre><pre>+</pre><pre>+#ifndef RENDERER_COMMON_H</pre><pre>+#define RENDERER_COMMON_H</pre><pre>+</pre><pre>+#include <string></pre><pre>+</pre><pre>+#include <vlc_common.h></pre><pre>+#include <vlc_sout.h></pre><pre>+</pre><pre>+#define PERF_TEXT N_( "Performance warning" )</pre><pre>+#define PERF_LONGTEXT N_( "Display a performance warning when </pre><pre>transcoding" )</pre><pre>+#define AUDIO_PASSTHROUGH_TEXT N_( "Enable Audio passthrough" )</pre><pre>+#define AUDIO_PASSTHROUGH_LONGTEXT N_( "Disable if your receiver does </pre><pre>not support Dolby®." )</pre><pre>+#define CONVERSION_QUALITY_TEXT N_( "Conversion quality" )</pre><pre>+#define CONVERSION_QUALITY_LONGTEXT N_( "Change this option to increase </pre><pre>conversion speed or quality." )</pre><pre>+</pre><pre>+#if defined (__ANDROID__) || defined (__arm__) || (defined </pre><pre>(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)</pre><pre>+# define CONVERSION_QUALITY_DEFAULT CONVERSION_QUALITY_LOW</pre><pre>+#else</pre><pre>+# define CONVERSION_QUALITY_DEFAULT CONVERSION_QUALITY_MEDIUM</pre><pre>+#endif</pre><pre>+</pre><pre>+#define RENDERER_CFG_PREFIX "sout-renderer-"</pre><pre>+</pre><pre>+#define add_renderer_opts(prefix) \</pre><pre>+ add_integer(RENDERER_CFG_PREFIX "show-perf-warning", 1, \</pre><pre>+ PERF_TEXT, PERF_LONGTEXT, true ) \</pre><pre>+ change_private() \</pre><pre>+ add_bool(prefix "audio-passthrough", false, \</pre><pre>+ AUDIO_PASSTHROUGH_TEXT, AUDIO_PASSTHROUGH_LONGTEXT, false ) </pre><pre>\</pre><pre>+ add_integer(prefix "conversion-quality", </pre><pre>CONVERSION_QUALITY_DEFAULT, \</pre><pre>+ CONVERSION_QUALITY_TEXT, CONVERSION_QUALITY_LONGTEXT, </pre><pre>false ); \</pre><pre>+ change_integer_list(conversion_quality_list, </pre><pre>conversion_quality_list_text)</pre><pre>+</pre><pre>+static const char *const conversion_quality_list_text[] = {</pre><pre>+ N_( "High (high quality and high bandwidth)" ),</pre><pre>+ N_( "Medium (medium quality and medium bandwidth)" ),</pre><pre>+ N_( "Low (low quality and low bandwidth)" ),</pre><pre>+ N_( "Low CPU (low quality but high bandwidth)" ),</pre><pre>+};</pre><pre>+</pre><pre>+enum {</pre><pre>+ CONVERSION_QUALITY_HIGH = 0,</pre><pre>+ CONVERSION_QUALITY_MEDIUM = 1,</pre><pre>+ CONVERSION_QUALITY_LOW = 2,</pre><pre>+ CONVERSION_QUALITY_LOWCPU = 3,</pre><pre>+};</pre><pre>+</pre><pre>+static const int conversion_quality_list[] = {</pre><pre>+ CONVERSION_QUALITY_HIGH,</pre><pre>+ CONVERSION_QUALITY_MEDIUM,</pre><pre>+ CONVERSION_QUALITY_LOW,</pre><pre>+ CONVERSION_QUALITY_LOWCPU,</pre><pre>+};</pre><pre>+</pre><pre>+struct venc_options</pre><pre>+{</pre><pre>+ vlc_fourcc_t fcc;</pre><pre>+ std::string (*get_opt)( sout_stream_t *, const video_format_t *, </pre><pre>int);</pre><pre>+};</pre><pre>+</pre><pre>+std::string</pre><pre>+vlc_sout_renderer_GetVencOption( sout_stream_t *p_stream, int </pre><pre>venc_opt_idx,</pre><pre>+ venc_options venc_opt_list[], size_t opt_list_length,</pre><pre>+ vlc_fourcc_t *p_codec_video, const video_format_t *p_vid,</pre><pre>+ int i_quality );</pre><pre>+</pre><pre>+std::string vlc_sout_renderer_GetVencVPXOption( sout_stream_t * /* </pre><pre>p_stream */,</pre><pre>+ const video_format_t * /* p_vid </pre><pre>*/,</pre><pre>+ int /* i_quality */ );</pre><pre>+</pre><pre>+std::string vlc_sout_renderer_GetVencQSVH264Option( sout_stream_t * /* </pre><pre>p_stream */,</pre><pre>+ const video_format_t * /* </pre><pre>p_vid */,</pre><pre>+ int i_quality );</pre><pre>+</pre><pre>+std::string vlc_sout_renderer_GetVencX264Option( sout_stream_t * /* </pre><pre>p_stream */,</pre><pre>+ const video_format_t *p_vid,</pre><pre>+ int i_quality );</pre><pre>+#ifdef __APPLE__</pre><pre>+std::string vlc_sout_renderer_GetVencAvcodecVTOption( sout_stream_t * /</pre><pre>* p_stream */,</pre><pre>+ const video_format_t * </pre><pre>p_vid,</pre><pre>+ int i_quality );</pre><pre>+#endif</pre><pre>+</pre><pre>+#endif /* RENDERER_COMMON_H */</pre><pre>-- </pre><pre>2.19.2</pre><pre>_______________________________________________</pre><pre>vlc-devel mailing list</pre><pre>To unsubscribe or modify your subscription options:</pre><a href="https://mailman.videolan.org/listinfo/vlc-devel"><pre>https://mailman.videolan.org/listinfo/vlc-devel</pre></a><pre><br></pre></blockquote><pre>_______________________________________________</pre><pre>vlc-devel mailing list</pre><pre>To unsubscribe or modify your subscription options:</pre><a href="https://mailman.videolan.org/listinfo/vlc-devel"><pre>https://mailman.videolan.org/listinfo/vlc-devel</pre></a></blockquote><div><span><pre>-- <br></pre><div style="width: 71ch;">Regards,</div><div style="width: 71ch;">Shaleen Jain</div></span></div></body></html>