CreateVideoCodecFactory.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <api/video_codecs/video_decoder_factory.h>
  3. #include <api/video_codecs/video_encoder_factory.h>
  4. #include <string>
  5. namespace unity
  6. {
  7. namespace webrtc
  8. {
  9. using namespace ::webrtc;
  10. constexpr char kInternalImpl[] = "Internal";
  11. constexpr char kNvCodecImpl[] = "NvCodec";
  12. constexpr char kAndroidMediaCodecImpl[] = "MediaCodec";
  13. constexpr char kVideoToolboxImpl[] = "VideoToolbox";
  14. constexpr char kSdpKeyNameCodecImpl[] = "implementation_name";
  15. class IGraphicsDevice;
  16. class ProfilerMarkerFactory;
  17. VideoEncoderFactory*
  18. CreateVideoEncoderFactory(const std::string& impl, IGraphicsDevice* gfxDevice, ProfilerMarkerFactory* profiler);
  19. VideoDecoderFactory*
  20. CreateVideoDecoderFactory(const std::string& impl, IGraphicsDevice* gfxDevice, ProfilerMarkerFactory* profiler);
  21. template<typename Factory>
  22. Factory* FindCodecFactory(
  23. const std::map<std::string, std::unique_ptr<Factory>>& factories, const webrtc::SdpVideoFormat& format)
  24. {
  25. for (const auto& pair : factories)
  26. {
  27. for (const webrtc::SdpVideoFormat& other : pair.second->GetSupportedFormats())
  28. {
  29. if (format.IsSameCodec(other))
  30. return pair.second.get();
  31. }
  32. }
  33. return nullptr;
  34. }
  35. template<typename Factory>
  36. std::vector<webrtc::SdpVideoFormat>
  37. GetSupportedFormatsInFactories(const std::map<std::string, std::unique_ptr<Factory>>& factories)
  38. {
  39. std::vector<SdpVideoFormat> supported_codecs;
  40. for (const auto& pair : factories)
  41. {
  42. for (const webrtc::SdpVideoFormat& format : pair.second->GetSupportedFormats())
  43. {
  44. webrtc::SdpVideoFormat newFormat = format;
  45. if (!pair.first.empty())
  46. newFormat.parameters.emplace(kSdpKeyNameCodecImpl, pair.first);
  47. supported_codecs.push_back(newFormat);
  48. }
  49. }
  50. return supported_codecs;
  51. }
  52. }
  53. }