📄 megaco_sdp.erl
字号:
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %% $Id$%%%%----------------------------------------------------------------------%% Purpose: %%-----------------------------------------------------------------------module(megaco_sdp).%%----------------------------------------------------------------------%% Include files%%-----------------------------------------------------------------------include_lib("megaco/include/megaco.hrl").-include_lib("megaco/src/app/megaco_internal.hrl").-include_lib("megaco/include/megaco_message_v1.hrl").-include_lib("megaco/include/megaco_sdp.hrl").%%----------------------------------------------------------------------%% External exports%%-----------------------------------------------------------------------export([ decode/1, encode/1, get_sdp_record_from_PropertyGroup/2 ]).%%----------------------------------------------------------------------%% Internal exports%%----------------------------------------------------------------------%%----------------------------------------------------------------------%% Macros%%----------------------------------------------------------------------%%----------------------------------------------------------------------%% Records%%----------------------------------------------------------------------%%======================================================================%% External functions%%======================================================================%% ---------------------------------------------------------------------%% decode(PP) -> {ok, SDP} | {error, Reason}%% %% This function performs the following conversion:%% property_parm() -> sdp()%% property_group() -> sdp_property_group()%% property_groups() -> sdp_property_groups()%% %% ---------------------------------------------------------------------decode(SDP) -> case (catch do_decode(SDP)) of {ok, _} = OK -> OK; {error, _} = ERR -> ERR; {'EXIT', Reason} -> {error, {exit, Reason}}; CRAP -> {error, {crap, CRAP}} end.do_decode(PP) when is_record(PP, 'PropertyParm') -> decode_PropertyParm(PP);do_decode([PP|_] = PG) when is_record(PP, 'PropertyParm') -> decode_PropertyGroup(PG);do_decode([H|_] = PGs) when is_list(H) -> decode_PropertyGroups(PGs);do_decode(asn1_NOVALUE = V) -> {ok, V};do_decode(Bad) -> {error, {bad_sdp, Bad}}.%% ---------------------------------------------------------------------%% encode(SDPs) -> {ok, PP} | {error, Reason}%% %% This function performs the following conversion:%% sdp() -> property_parm()%% sdp_property_group() -> property_group()%% sdp_property_groups() -> property_groups()%% %% ---------------------------------------------------------------------encode(SDP) -> case (catch do_encode(SDP)) of {ok, _} = OK -> OK; {error, _} = ERR -> ERR; {'EXIT', Reason} -> {error, {exit, Reason}}; CRAP -> {error, {crap, CRAP}} end.do_encode(SDP) when is_tuple(SDP) -> {ok, encode_PropertyParm(SDP)};do_encode([SDP|_] = PG) when tuple(SDP) -> encode_PropertyGroup(PG);do_encode([H|_] = PGs) when is_list(H) -> encode_PropertyGroups(PGs);do_encode(asn1_NOVALUE = V) -> {ok, V}.%%-----------------------------------------------------------------%% Generate sdp records from PropertyParm records%%-----------------------------------------------------------------decode_PropertyGroups(PGs) -> decode_PropertyGroups(PGs, []).decode_PropertyGroups([], DecodedPGs) -> {ok, lists:reverse(DecodedPGs)};decode_PropertyGroups([PG | PGs], DecodedPGs) -> {ok, DecodedPG} = decode_PropertyGroup(PG), decode_PropertyGroups(PGs, [DecodedPG | DecodedPGs]).decode_PropertyGroup(PG) -> {ok, decode_PropertyGroup(PG, [])}.decode_PropertyGroup([], Acc) -> lists:reverse(Acc);decode_PropertyGroup([PP | PG], Acc) -> case (catch decode_PropertyParm(PP)) of {ok, PP2} -> decode_PropertyGroup(PG, [PP2 | Acc]); {error, Reason} -> decode_PropertyGroup(PG, [{PP, Reason} | Acc]); Error -> decode_PropertyGroup(PG, [{PP, Error} | Acc]) end.%% ===== Protocol Version =====%% decode_PropertyParm(#'PropertyParm'{name = "v", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_protocol_version(V);%% ===== Origin =====%% decode_PropertyParm(#'PropertyParm'{name = "o", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_origin(V);%% ===== Session Name =====%% decode_PropertyParm(#'PropertyParm'{name = "s", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_session_name(V);%% ===== Session and Media Information =====%% decode_PropertyParm(#'PropertyParm'{name = "i", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_session_media_id(V);%% ===== URI =====%% decode_PropertyParm(#'PropertyParm'{name = "u", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_uri(V);%% ===== Email Address and Phone Number =====%% decode_PropertyParm(#'PropertyParm'{name = "e", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_email(V);decode_PropertyParm(#'PropertyParm'{name = "p", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_phone(V);%% ===== Connection Data =====%% decode_PropertyParm(#'PropertyParm'{name = "c", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_connection_data(V);%% ===== Bandwidth =====%% decode_PropertyParm(#'PropertyParm'{name = "b", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_bandwidth(V);%% ===== Times, Repeat Times and Time Zones =====%% decode_PropertyParm(#'PropertyParm'{name = "t", value = [V], extraInfo = asn1_NOVALUE }) -> decode_pp_times(V);decode_PropertyParm(#'PropertyParm'{name = "r", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_rtimes(V);decode_PropertyParm(#'PropertyParm'{name = "z", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_tzones(V);%% ===== Encryption Keys =====%% decode_PropertyParm(#'PropertyParm'{name = "k", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_encryption_keys(V);%% ===== Attributes =====%% decode_PropertyParm(#'PropertyParm'{name = "a", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_attribute(V);%% ===== Media Announcements =====%% decode_PropertyParm(#'PropertyParm'{name = "m", value = [V], extraInfo = asn1_NOVALUE}) -> decode_pp_media_announcement(V);decode_PropertyParm(_PP) -> ?d("decode_PropertyParm -> entry with" "~n _PP: ~p", [_PP]), {error, undefined_PropertyParm}.%%-----------------------------------------------------------------%% Generate PropertyParm records from sdp records%%-----------------------------------------------------------------encode_PropertyGroups(PGs) -> encode_PropertyGroups(PGs, []).encode_PropertyGroups([], Acc) -> {ok, lists:reverse(Acc)};encode_PropertyGroups([PG | PGs], Acc) -> {ok, EncodedPG} = encode_PropertyGroup(PG), encode_PropertyGroups(PGs, [EncodedPG | Acc]).encode_PropertyGroup(PG) -> encode_PropertyGroup(PG, []).encode_PropertyGroup([], Acc) -> {ok, lists:reverse(Acc)};encode_PropertyGroup([PP | PG], Acc) -> EncodedPP = encode_PropertyParm(PP), encode_PropertyGroup(PG, [EncodedPP | Acc]). %% ===== Protocol Version =====%% encode_PropertyParm(#megaco_sdp_v{version = Version}) -> encode_pp_protocol_version(Version);%% ===== Origin =====%% encode_PropertyParm(#megaco_sdp_o{user_name = User, session_id = SessionId, version = Version, network_type = Network, address_type = AddrType, address = Addr}) -> encode_pp_origin(User, SessionId, Version, Network, AddrType, Addr); %% ===== Session Name =====%% encode_PropertyParm(#megaco_sdp_s{name = Name}) -> encode_pp_session_name(Name); %% ===== Session and Media Information =====%% encode_PropertyParm(#megaco_sdp_i{session_descriptor = SD}) -> encode_pp_session_media_id(SD);%% ===== URI =====%% encode_PropertyParm(#megaco_sdp_u{uri = URI}) -> encode_pp_uri(URI);%% ===== Email Address and Phone Number =====%% encode_PropertyParm(#megaco_sdp_e{email = Email}) -> encode_pp_email(Email);encode_PropertyParm(#megaco_sdp_p{phone_number = Num}) -> encode_pp_phone(Num);%% ===== Connection Data =====%% encode_PropertyParm(#megaco_sdp_c{network_type = NetType, address_type = AddressType, connection_addr = ConnectionAddr}) -> encode_pp_connection_data(NetType, AddressType, ConnectionAddr);%% ===== Bandwidth =====%% encode_PropertyParm(#megaco_sdp_b{modifier = Modifier, bandwidth = Bandwidth}) -> encode_pp_bandwidth(Modifier, Bandwidth);%% ===== Times, Repeat Times and Time Zones =====%% encode_PropertyParm(#megaco_sdp_t{start = Start, stop = Stop}) -> encode_pp_times(Start, Stop);encode_PropertyParm(#megaco_sdp_r{repeat_interval = Repeat, active_duration = Duration, list_of_offsets = ListOfOffsets}) -> encode_pp_rtimes(Repeat, Duration, ListOfOffsets);encode_PropertyParm(#megaco_sdp_z{list_of_adjustments = LOA}) -> encode_pp_tzones(LOA);%% ===== Encryption Keys =====%% encode_PropertyParm(#megaco_sdp_k{method = Method, encryption_key = EncryptionKey}) -> encode_pp_encryption_keys(Method, EncryptionKey);%% ===== Attributes =====%% encode_PropertyParm(#megaco_sdp_a_rtpmap{payload_type = Payload, encoding_name = EncName, clock_rate = ClockRate, encoding_parms = EncPar}) -> encode_pp_attribute_rtpmap(Payload, EncName, ClockRate, EncPar);encode_PropertyParm(#megaco_sdp_a_ptime{packet_time = PacketTime}) -> encode_pp_attribute_ptime(PacketTime);encode_PropertyParm(#megaco_sdp_a_quality{quality = Quality}) -> encode_pp_attribute_quality(Quality);encode_PropertyParm(#megaco_sdp_a_fmtp{format = Fmt, param = Param}) -> encode_pp_attribute_fmtp(Fmt, Param);encode_PropertyParm(#megaco_sdp_a{attribute = Attr, value = Value}) -> encode_pp_attribute(Attr, Value);%% ===== Media Announcements =====%% encode_PropertyParm(#megaco_sdp_m{media = Media, port = Port, num_ports = NOP, transport = Transport, fmt_list = FMT}) -> encode_pp_media_announcement(Media, Port, NOP, Transport, FMT);%% This is a "manually" encoded PropertyParm, leave it as is.%% encode_PropertyParm(PP) when is_record(PP, 'PropertyParm') -> PP;%% Bad dataencode_PropertyParm(SDP) -> error({unknown_sdp, SDP}).%%-----------------------------------------------------------------%% Func: get_sdp_record_from_PropertGroup/2%% Description: Get all sdp records of a certain type from a %% property group%%-----------------------------------------------------------------get_sdp_record_from_PropertyGroup(Type, PG) when is_atom(Type) and is_list(PG) -> F = fun(R) -> not is_pg_record(Type, R) end, lists:filter(F, PG).is_pg_record(v, R) when record(R, megaco_sdp_v) -> true;is_pg_record(c, R) when record(R, megaco_sdp_c) -> true;is_pg_record(m, R) when record(R, megaco_sdp_m) -> true;is_pg_record(o, R) when record(R, megaco_sdp_o) -> true;is_pg_record(a, R) when record(R, megaco_sdp_a) -> true;is_pg_record(a, R) when record(R, megaco_sdp_a_ptime) -> true;is_pg_record(a, R) when record(R, megaco_sdp_a_rtpmap) -> true;is_pg_record(b, R) when record(R, megaco_sdp_b) -> true;is_pg_record(t, R) when record(R, megaco_sdp_t) -> true;is_pg_record(r, R) when record(R, megaco_sdp_r) -> true;is_pg_record(z, R) when record(R, megaco_sdp_z) -> true;is_pg_record(k, R) when record(R, megaco_sdp_k) -> true;is_pg_record(s, R) when record(R, megaco_sdp_s) -> true;is_pg_record(i, R) when record(R, megaco_sdp_i) -> true;is_pg_record(u, R) when record(R, megaco_sdp_u) -> true;is_pg_record(e, R) when record(R, megaco_sdp_e) -> true;is_pg_record(p, R) when record(R, megaco_sdp_p) -> true;is_pg_record(_, _) -> false. %%======================================================================%% Internal functions%%======================================================================%% ===== Protocol Version =====
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -