UnityAudioDecoderFactory.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "pch.h"
  2. #include <api/audio_codecs/L16/audio_decoder_L16.h>
  3. #include <api/audio_codecs/audio_decoder_factory_template.h>
  4. #include <api/audio_codecs/g711/audio_decoder_g711.h>
  5. #include <api/audio_codecs/g722/audio_decoder_g722.h>
  6. #include <api/audio_codecs/ilbc/audio_decoder_ilbc.h>
  7. #include <api/audio_codecs/isac/audio_decoder_isac.h>
  8. #include <api/audio_codecs/opus/audio_decoder_multi_channel_opus.h>
  9. #include <api/audio_codecs/opus/audio_decoder_opus.h>
  10. #include "UnityAudioDecoderFactory.h"
  11. using namespace ::webrtc;
  12. namespace unity
  13. {
  14. namespace webrtc
  15. {
  16. template<typename T>
  17. struct StereoSupportDecoder
  18. {
  19. using Config = typename T::Config;
  20. static absl::optional<Config> SdpToConfig(const SdpAudioFormat& audio_format)
  21. {
  22. return T::SdpToConfig(audio_format);
  23. }
  24. static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs)
  25. {
  26. std::vector<AudioCodecSpec> new_specs;
  27. T::AppendSupportedDecoders(&new_specs);
  28. RTC_DCHECK_EQ(new_specs.size(), 1);
  29. auto spec = new_specs[0];
  30. if (spec.format.num_channels == 2)
  31. {
  32. if (spec.format.parameters.find("stereo") == spec.format.parameters.end())
  33. spec.format.parameters.emplace("stereo", "1");
  34. if (spec.format.parameters.find("sprop-stereo") == spec.format.parameters.end())
  35. spec.format.parameters.emplace("sprop-stereo", "1");
  36. spec.info.num_channels = 2;
  37. }
  38. specs->push_back(spec);
  39. }
  40. static std::unique_ptr<AudioDecoder>
  41. MakeAudioDecoder(const Config& config, absl::optional<AudioCodecPairId> codec_pair_id)
  42. {
  43. return T::MakeAudioDecoder(config, codec_pair_id);
  44. }
  45. };
  46. rtc::scoped_refptr<AudioDecoderFactory> CreateAudioDecoderFactory()
  47. {
  48. return ::webrtc::CreateAudioDecoderFactory<
  49. StereoSupportDecoder<AudioDecoderOpus>,
  50. AudioDecoderMultiChannelOpus,
  51. AudioDecoderIlbc,
  52. AudioDecoderIsac,
  53. AudioDecoderG722,
  54. AudioDecoderG711,
  55. AudioDecoderL16>();
  56. }
  57. } // end namespace webrtc
  58. } // end namespace unity