Repository: xbmc/xbmc
File: xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Inputstream.h (C/C++)

Code before:
      const kodi::addon::InputstreamContentlightMetadata& contentLightMetadata)
  {
    m_contentLightMetadata = contentLightMetadata;
    m_cStructure->m_contentLightMetadata = m_contentLightMetadata;
  }

  /// @brief To get with @ref SetContentLightMetadata changed values.
  const kodi::addon::InputstreamContentlightMetadata& GetContentLightMetadata() const
  {
    return m_contentLightMetadata;
  }

  /// @brief Clear content light static Metadata.
  void ClearContentLightMetadata() { m_cStructure->m_contentLightMetadata = nullptr; }

  /// @brief Sets a pre-allocated DVCC metadata pointer.
  ///
  /// @param[in] meta The @ref INPUTSTREAM_DVCC_METADATA settable metadata
  void SetDvccMetadata(INPUTSTREAM_DVCC_METADATA* meta) const
  {
    m_cStructure->m_dvccMetadata = meta;
  }

  /// @brief Get raw pointer to DVCC metadata.
  /// @return Pointer to the DVCC metadata structure, or nullptr if not set.
  INPUTSTREAM_DVCC_METADATA* GetDvccMetadata() const { return m_cStructure->m_dvccMetadata; }

  ///@}

private:
  InputstreamInfo(const INPUTSTREAM_INFO* stream) : CStructHdl(stream)
  {
    SetCryptoSession(StreamCryptoSession(&stream->m_cryptoSession));
    CopyExtraData();
  }
  InputstreamInfo(INPUTSTREAM_INFO* stream) : CStructHdl(stream)
  {
    SetCryptoSession(StreamCryptoSession(&stream->m_cryptoSession));
    CopyExtraData();
  }

  void CopyExtraData()
  {
    if (m_cStructure->m_ExtraData && m_cStructure->m_ExtraSize > 0)
    {
      for (unsigned int i = 0; i < m_cStructure->m_ExtraSize; ++i)
        m_extraData.emplace_back(m_cStructure->m_ExtraData[i]);
    }
    if (m_cStructure->m_masteringMetadata)
      m_masteringMetadata = m_cStructure->m_masteringMetadata;
    if (m_cStructure->m_contentLightMetadata)

Review comment (suggestion):
i find this implementation rusty, it dont follow in same way other implementations of other properties
also i dont see pointer distruction in safe ways

imo it should be implemented with `CStructHdl` that take care of pointer
and not use raw pointer directly as done here
you can take a look for example at `InputstreamContentlightMetadata`


Code after:
  void SetCryptoSession(const kodi::addon::StreamCryptoSession& cryptoSession)
  {
    m_cryptoSession = cryptoSession;
    memcpy(&m_cStructure->m_cryptoSession, m_cryptoSession.GetCStructure(),
           sizeof(STREAM_CRYPTO_SESSION));
  }

  /// @brief To get with @ref GetCryptoSession changed values.
  const kodi::addon::StreamCryptoSession& GetCryptoSession() const { return m_cryptoSession; }

  /// @brief Codec If available, the fourcc code codec.
  ///
  /// @param[in] codecFourCC Codec four CC code
  void SetCodecFourCC(unsigned int codecFourCC) { m_cStructure->m_codecFourCC = codecFourCC; }

  /// @brief To get with @ref SetCodecFourCC changed values
  unsigned int GetCodecFourCC() const { return m_cStructure->m_codecFourCC; }

  /// @brief Definition of colorspace.
  ///
  /// @param[in] colorSpace The with @ref INPUTSTREAM_COLORSPACE setable color space
  void SetColorSpace(INPUTSTREAM_COLORSPACE colorSpace) { m_cStructure->m_colorSpace = colorSpace; }

  /// @brief To get with @ref SetColorSpace changed values.
  INPUTSTREAM_COLORSPACE GetColorSpace() const { return m_cStructure->m_colorSpace; }

  /// @brief Color range if available.
  ///
  /// @param[in] colorRange The with @ref INPUTSTREAM_COLORRANGE setable color space
  void SetColorRange(INPUTSTREAM_COLORRANGE colorRange) { m_cStructure->m_colorRange = colorRange; }

  /// @brief To get with @ref SetColorRange changed values.
  INPUTSTREAM_COLORRANGE GetColorRange() const { return m_cStructure->m_colorRange; }

  /// @brief Chromaticity coordinates of the source primaries. These values match the ones defined by ISO/IEC 23001-8_2013 § 7.1.
  ///
  /// @param[in] colorPrimaries The with @ref INPUTSTREAM_COLORPRIMARIES setable values
  void SetColorPrimaries(INPUTSTREAM_COLORPRIMARIES colorPrimaries)
  {
    m_cStructure->m_colorPrimaries = colorPrimaries;
  }

  /// @brief To get with @ref SetColorPrimaries changed values.
  INPUTSTREAM_COLORPRIMARIES GetColorPrimaries() const { return m_cStructure->m_colorPrimaries; }

  /// @brief Color Transfer Characteristic. These values match the ones defined by ISO/IEC 23001-8_2013 § 7.2.
  ///
  /// @param[in] colorTransferCharacteristic The with @ref INPUTSTREAM_COLORTRC setable characteristic
  void SetColorTransferCharacteristic(INPUTSTREAM_COLORTRC colorTransferCharacteristic)
  {
    m_cStructure->m_colorTransferCharacteristic = colorTransferCharacteristic;