From d889b9f233b1c1acdd1fe5a2e694d2a4dce27889 Mon Sep 17 00:00:00 2001
From: Eloi BAIL <eloi.bail@savoirfairelinux.com>
Date: Wed, 18 Mar 2015 14:36:46 -0400
Subject: [PATCH] daemon: define A/V bitrate and use it for encoding

Refs #68792

Change-Id: I42b94679fd3dc03926d5263b9e37dfd1d23d21f5
Signed-off-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
---
 daemon/src/media/media_codec.cpp            |  4 +++-
 daemon/src/media/media_codec.h              |  1 +
 daemon/src/media/media_encoder.cpp          |  2 +-
 daemon/src/media/system_codec_container.cpp | 14 ++++++++++----
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/daemon/src/media/media_codec.cpp b/daemon/src/media/media_codec.cpp
index f870bc9407..a5a0790a0d 100644
--- a/daemon/src/media/media_codec.cpp
+++ b/daemon/src/media/media_codec.cpp
@@ -116,10 +116,12 @@ SystemVideoCodecInfo::SystemVideoCodecInfo(unsigned m_avcodecId,
                                            const std::string m_name,
                                            std::string m_libName,
                                            CodecType m_type,
+                                           unsigned m_bitrate,
                                            unsigned m_payloadType,
                                            unsigned m_frameRate,
                                            unsigned m_profileId)
-    : SystemCodecInfo(m_avcodecId, m_name, m_libName, MEDIA_VIDEO, m_type, m_payloadType)
+    : SystemCodecInfo(m_avcodecId, m_name, m_libName, MEDIA_VIDEO,
+                      m_type, m_bitrate, m_payloadType)
     , frameRate(m_frameRate), profileId(m_profileId)
 {}
 
diff --git a/daemon/src/media/media_codec.h b/daemon/src/media/media_codec.h
index 5b2de4e6c3..181d0bf2bd 100644
--- a/daemon/src/media/media_codec.h
+++ b/daemon/src/media/media_codec.h
@@ -116,6 +116,7 @@ struct SystemVideoCodecInfo : SystemCodecInfo
 {
     SystemVideoCodecInfo(unsigned avcodecId, const std::string name,
                          std::string libName, CodecType type = CODEC_NONE,
+                         unsigned bitrate = 0,
                          unsigned payloadType = 0, unsigned frameRate = 0,
                          unsigned profileId = 0);
 
diff --git a/daemon/src/media/media_encoder.cpp b/daemon/src/media/media_encoder.cpp
index d473ee6a27..0bd8a0a4a8 100644
--- a/daemon/src/media/media_encoder.cpp
+++ b/daemon/src/media/media_encoder.cpp
@@ -81,7 +81,7 @@ void MediaEncoder::setDeviceOptions(const DeviceParams& args)
 void MediaEncoder::setOptions(const MediaDescription& args)
 {
     av_dict_set(&options_, "payload_type", ring::to_string(args.payload_type).c_str(), 0);
-    av_dict_set(&options_, "bitrate", ring::to_string(args.bitrate).c_str(), 0);
+    av_dict_set(&options_, "bitrate", ring::to_string(args.codec->bitrate).c_str(), 0);
 
     auto accountAudioCodec = std::static_pointer_cast<AccountAudioCodecInfo>(args.codec);
     if (accountAudioCodec->audioformat.sample_rate)
diff --git a/daemon/src/media/system_codec_container.cpp b/daemon/src/media/system_codec_container.cpp
index d266d1601e..66d41336ca 100644
--- a/daemon/src/media/system_codec_container.cpp
+++ b/daemon/src/media/system_codec_container.cpp
@@ -40,6 +40,8 @@ namespace ring {
 
 decltype(getGlobalInstance<SystemCodecContainer>)& getSystemCodecContainer = getGlobalInstance<SystemCodecContainer>;
 
+constexpr static auto DEFAULT_VIDEO_BITRATE = 400;
+
 SystemCodecContainer::SystemCodecContainer()
 {
     initCodecConfig();
@@ -58,19 +60,23 @@ SystemCodecContainer::initCodecConfig()
         /* Define supported video codec*/
         std::make_shared<SystemVideoCodecInfo>(AV_CODEC_ID_H264,
                                                "H264", "libx264",
-                                               CODEC_ENCODER_DECODER),
+                                               CODEC_ENCODER_DECODER,
+                                               DEFAULT_VIDEO_BITRATE),
 
         std::make_shared<SystemVideoCodecInfo>(AV_CODEC_ID_H263,
                                                "H263", "h263",
-                                               CODEC_ENCODER_DECODER),
+                                               CODEC_ENCODER_DECODER,
+                                               DEFAULT_VIDEO_BITRATE),
 
         std::make_shared<SystemVideoCodecInfo>(AV_CODEC_ID_VP8,
                                                "VP8", "libvpx",
-                                               CODEC_ENCODER_DECODER),
+                                               CODEC_ENCODER_DECODER,
+                                               DEFAULT_VIDEO_BITRATE),
 
         std::make_shared<SystemVideoCodecInfo>(AV_CODEC_ID_MPEG4,
                                                "MP4V-ES", "mpeg4",
-                                               CODEC_ENCODER_DECODER),
+                                               CODEC_ENCODER_DECODER,
+                                               DEFAULT_VIDEO_BITRATE),
 #endif
         /* Define supported audio codec*/
         std::make_shared<SystemAudioCodecInfo>(AV_CODEC_ID_PCM_ALAW,
-- 
GitLab