<commit_before>/*
 * OneToManyProcessor.cpp
 */

#include "OneToManyProcessor.h"

#include <map>
#include <string>

#include "./MediaStream.h"
#include "rtp/RtpHeaders.h"
#include "rtp/RtpUtils.h"

namespace erizo {
  DEFINE_LOGGER(OneToManyProcessor, "OneToManyProcessor");
  OneToManyProcessor::OneToManyProcessor() : feedbackSink_{nullptr} {
    ELOG_DEBUG("OneToManyProcessor constructor");
  }

  OneToManyProcessor::~OneToManyProcessor() {
  }

  int OneToManyProcessor::deliverAudioData_(std::shared_ptr<DataPacket> audio_packet) {
    if (audio_packet->length <= 0)
      return 0;

    boost::unique_lock<boost::mutex> lock(monitor_mutex_);
    if (subscribers.empty())
      return 0;

    std::map<std::string, std::shared_ptr<MediaSink>>::iterator it;
    RtpHeader* head = reinterpret_cast<RtpHeader*>(audio_packet->data);
    RtcpHeader* chead = reinterpret_cast<RtcpHeader*>(audio_packet->data);
    for (it = subscribers.begin(); it != subscribers.end(); ++it) {
      if ((*it).second != nullptr) {
        // Hack to avoid audio drift
        if (chead->isRtcp() && chead->isSDES()) {
          chead->setSSRC((*it).second->getAudioSinkSSRC());
        } else {
          head->setSSRC((*it).second->getAudioSinkSSRC());
        }
        // Note: deliverAudioData must copy the packet inmediately
        (*it).second->deliverAudioData(audio_packet);
      }
    }

    return 0;
  }

  bool OneToManyProcessor::isSSRCFromAudio(uint32_t ssrc) {
    std::map<std::string, std::shared_ptr<MediaSink>>::iterator it;
    for (it = subscribers.begin(); it != subscribers.end(); ++it) {
      if ((*it).second->getAudioSinkSSRC() == ssrc) {
        return true;
      }
    }
    return false;
  }

  int OneToManyProcessor::deliverVideoData_(std::shared_ptr<DataPacket> video_packet) {<commit_msg>Check for null pointers in OTM (#1554)<commit_after>/*
 * OneToManyProcessor.cpp
 */

#include "OneToManyProcessor.h"

#include <map>
#include <string>

#include "./MediaStream.h"
#include "rtp/RtpHeaders.h"
#include "rtp/RtpUtils.h"

namespace erizo {
  DEFINE_LOGGER(OneToManyProcessor, "OneToManyProcessor");
  OneToManyProcessor::OneToManyProcessor() : feedbackSink_{nullptr} {
    ELOG_DEBUG("OneToManyProcessor constructor");
  }

  OneToManyProcessor::~OneToManyProcessor() {
  }

  int OneToManyProcessor::deliverAudioData_(std::shared_ptr<DataPacket> audio_packet) {
    if (audio_packet->length <= 0)
      return 0;

    boost::unique_lock<boost::mutex> lock(monitor_mutex_);
    if (subscribers.empty())
      return 0;

    std::map<std::string, std::shared_ptr<MediaSink>>::iterator it;
    RtpHeader* head = reinterpret_cast<RtpHeader*>(audio_packet->data);
    RtcpHeader* chead = reinterpret_cast<RtcpHeader*>(audio_packet->data);
    for (it = subscribers.begin(); it != subscribers.end(); ++it) {
      if ((*it).second != nullptr) {
        // Hack to avoid audio drift
        if (chead->isRtcp() && chead->isSDES()) {
          chead->setSSRC((*it).second->getAudioSinkSSRC());
        } else {
          head->setSSRC((*it).second->getAudioSinkSSRC());
        }
        // Note: deliverAudioData must copy the packet inmediately
        (*it).second->deliverAudioData(audio_packet);
      }
    }

    return 0;
  }

  bool OneToManyProcessor::isSSRCFromAudio(uint32_t ssrc) {
    std::map<std::string, std::shared_ptr<MediaSink>>::iterator it;
    for (it = subscribers.begin(); it != subscribers.end(); ++it) {
      if ((*it).second != nullptr) {
        if ((*it).second->getAudioSinkSSRC() == ssrc) {
          return true;
        }
      }
    }
    return false;
  }

  int OneToManyProcessor::deliverVideoData_(std::shared_ptr<DataPacket> video_packet) {
{'fraction_non_alphanumeric': 0.15224445646295295, 'fraction_numerical': 0.004326663061114116, 'mean_word_length': 3.7790697674418605, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1870334', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1210, 'n_words': 205}