1 /* 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MEDIA_ENGINE_PAYLOAD_TYPE_MAPPER_H_ 12 #define MEDIA_ENGINE_PAYLOAD_TYPE_MAPPER_H_ 13 14 #include <map> 15 #include <set> 16 17 #include "absl/types/optional.h" 18 #include "api/audio_codecs/audio_format.h" 19 #include "media/base/codec.h" 20 21 namespace cricket { 22 23 webrtc::SdpAudioFormat AudioCodecToSdpAudioFormat(const AudioCodec& ac); 24 25 class PayloadTypeMapper { 26 public: 27 PayloadTypeMapper(); 28 ~PayloadTypeMapper(); 29 30 // Finds the current payload type for `format` or assigns a new one, if no 31 // current mapping exists. Will return an empty value if it was unable to 32 // create a mapping, i.e. if all dynamic payload type ids have been used up. 33 absl::optional<int> GetMappingFor(const webrtc::SdpAudioFormat& format); 34 35 // Finds the current payload type for `format`, if any. Returns an empty value 36 // if no payload type mapping exists for the format. 37 absl::optional<int> FindMappingFor( 38 const webrtc::SdpAudioFormat& format) const; 39 40 // Like GetMappingFor, but fills in an AudioCodec structure with the necessary 41 // information instead. 42 absl::optional<AudioCodec> ToAudioCodec(const webrtc::SdpAudioFormat& format); 43 44 private: 45 struct SdpAudioFormatOrdering { 46 bool operator()(const webrtc::SdpAudioFormat& a, 47 const webrtc::SdpAudioFormat& b) const; 48 }; 49 50 int next_unused_payload_type_; 51 int max_payload_type_; 52 std::map<webrtc::SdpAudioFormat, int, SdpAudioFormatOrdering> mappings_; 53 std::set<int> used_payload_types_; 54 }; 55 56 } // namespace cricket 57 #endif // MEDIA_ENGINE_PAYLOAD_TYPE_MAPPER_H_ 58