66
77namespace SharpRTSPServer
88{
9+ /// <summary>
10+ /// AAC track.
11+ /// </summary>
912 public class AACTrack : ITrack
1013 {
14+ /// <summary>
15+ /// Track ID.
16+ /// </summary>
1117 public int ID { get ; set ; } = 1 ;
18+
19+ /// <summary>
20+ /// Sampling rate.
21+ /// </summary>
1222 public int SamplingRate { get ; set ; } = 44100 ;
23+
24+ /// <summary>
25+ /// Number of channels.
26+ /// </summary>
1327 public int Channels { get ; set ; } = 1 ;
14- public string ConfigDescriptor { get ; set ; } = "1390" ; // hex
1528
16- public bool IsReady { get { return ! string . IsNullOrWhiteSpace ( ConfigDescriptor ) ; } }
29+ /// <summary>
30+ /// AAC configuration descriptor.
31+ /// </summary>
32+ public byte [ ] ConfigDescriptor { get ; set ; }
33+
34+ /// <summary>
35+ /// Is the track ready?
36+ /// </summary>
37+ public bool IsReady { get { return ConfigDescriptor != null && ConfigDescriptor . Length > 0 ; } }
38+
39+ private int _payloadType = - 1 ;
1740
18- public int PayloadType => RTSPServer . DYNAMIC_PAYLOAD_TYPE + ID ;
41+ /// <summary>
42+ /// Payload type. AAC uses a dynamic payload type, which by default we calculate as 96 + track ID.
43+ /// </summary>
44+ public int PayloadType
45+ {
46+ get
47+ {
48+ if ( _payloadType < 0 )
49+ {
50+ return RTSPServer . DYNAMIC_PAYLOAD_TYPE + ID ;
51+ }
52+ else
53+ {
54+ return _payloadType ;
55+ }
56+ }
57+ set
58+ {
59+ _payloadType = value ;
60+ }
61+ }
1962
20- public AACTrack ( int samplingRate , int channels , byte [ ] configDescriptor )
63+ /// <summary>
64+ /// Ctor.
65+ /// </summary>
66+ /// <param name="samplingRate">Audio sampling rate.</param>
67+ /// <param name="channels">Number of audio channels.</param>
68+ public AACTrack ( int samplingRate , int channels )
2169 {
2270 this . SamplingRate = samplingRate ;
2371 this . Channels = channels ;
24- this . ConfigDescriptor = Utilities . ToHexString ( configDescriptor ) ;
72+ }
73+
74+ /// <summary>
75+ /// Ctor.
76+ /// </summary>
77+ /// <param name="configDescriptor">AAC configuration descriptor.</param>
78+ /// <param name="samplingRate">Audio sampling rate.</param>
79+ /// <param name="channels">Number of audio channels.</param>
80+ public AACTrack ( byte [ ] configDescriptor , int samplingRate , int channels ) : this ( samplingRate , channels )
81+ {
82+ SetConfigDescriptor ( configDescriptor ) ;
83+ }
84+
85+ /// <summary>
86+ /// Set the AAC configuration Descriptor.
87+ /// </summary>
88+ /// <param name="configDescriptor">AAC Configuration Descriptor.</param>
89+ public void SetConfigDescriptor ( byte [ ] configDescriptor )
90+ {
91+ this . ConfigDescriptor = configDescriptor ;
2592 }
2693
2794 public StringBuilder BuildSDP ( StringBuilder sdp )
@@ -30,11 +97,11 @@ public StringBuilder BuildSDP(StringBuilder sdp)
3097 sdp . Append ( $ "a=control:trackID={ ID } \n ") ;
3198 sdp . Append ( $ "a=rtpmap:{ PayloadType } mpeg4-generic/{ SamplingRate } /{ Channels } \n ") ;
3299 sdp . Append ( $ "a=fmtp:{ PayloadType } profile-level-id={ GetAACProfileLevel ( SamplingRate , Channels ) } ; " +
33- $ "config={ ConfigDescriptor } ; streamType=5; mode=AAC-hbr; objectType=64; sizeLength=13; indexLength=3; indexDeltaLength=3\n ") ;
100+ $ "config={ Utilities . ToHexString ( ConfigDescriptor ) } ; streamType=5; mode=AAC-hbr; objectType=64; sizeLength=13; indexLength=3; indexDeltaLength=3\n ") ;
34101 return sdp ;
35102 }
36103
37- public ( List < Memory < byte > > , List < IMemoryOwner < byte > > ) PrepareRtpPackets ( List < byte [ ] > samples , uint rtpTimestamp )
104+ public ( List < Memory < byte > > , List < IMemoryOwner < byte > > ) CreateRtpPackets ( List < byte [ ] > samples , uint rtpTimestamp )
38105 {
39106 List < Memory < byte > > rtpPackets = new List < Memory < byte > > ( ) ;
40107 List < IMemoryOwner < byte > > memoryOwners = new List < IMemoryOwner < byte > > ( ) ;
0 commit comments