AudioFramesMixer.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include <pjmedia.h>
  3. #include <log4cpp/Category.hh>
  4. #include <boost/noncopyable.hpp>
  5. #include <mutex>
  6. namespace mixer {
  7. class Exception : public std::runtime_error {
  8. public:
  9. Exception(const char *title) : std::runtime_error(title) {
  10. mesg += title;
  11. }
  12. Exception(const char *title, pj_status_t status) : std::runtime_error(title) {
  13. char errorMsgBuffer[500];
  14. pj_strerror(status, errorMsgBuffer, sizeof(errorMsgBuffer));
  15. mesg += title;
  16. mesg += ": ";
  17. mesg += errorMsgBuffer;
  18. }
  19. virtual const char *what() const throw() override {
  20. return mesg.c_str();
  21. }
  22. private:
  23. std::string mesg;
  24. };
  25. class AudioFramesMixer : boost::noncopyable {
  26. public:
  27. AudioFramesMixer(pj_pool_factory &poolFactory);
  28. virtual ~AudioFramesMixer();
  29. void addFrameToBuffer(int sessionId, int sequenceNumber, int16_t *samples, int samplesLength);
  30. int getMixedSamples(int16_t *mixedSamples, int requestedLength);
  31. void clean();
  32. private:
  33. log4cpp::Category &logger;
  34. pj_pool_t *pool = nullptr;
  35. pjmedia_circ_buf *inputBuff;
  36. std::mutex inBuffAccessMutex;
  37. };
  38. }