Ejemplo n.º 1
0
 private void OnAACHeader(RTMPMessage msg)
 {
     using (var s = new MemoryStream(msg.Body, false)) {
         s.Seek(2, SeekOrigin.Current);
         using (var bs = new BitReader(s, true)) {
             var type = bs.ReadBits(5);
             if (type == 31)
             {
                 type = bs.ReadBits(6) + 32;
             }
             var sampling_freq_idx     = bs.ReadBits(4);
             var sampling_freq         = sampling_freq_idx == 0x0F ? bs.ReadBits(24) : sampling_freq_idx;
             var channel_configuration = bs.ReadBits(4);
             this.adtsHeader = new ADTSHeader(
                 0xFFF,                 //sync
                 0,                     //ID
                 0,                     //Layer
                 true,                  //CRC Absent
                 type - 1,              //Profile
                 sampling_freq_idx,     //Sampling frequency index
                 0,                     //Private
                 channel_configuration, //Channel configuration
                 0,                     //Original/Copy
                 0,                     //home
                 0,                     //Copyright identification bit
                 0,                     //Copyright identification start
                 0,                     //frame length
                 0x7FF,                 //buffer fullness
                 0,                     //number of raw data blocks in frame
                 0                      //CRC
                 );
         }
     }
 }
Ejemplo n.º 2
0
 private void Clear()
 {
     pps        = new NALUnit[0];
     sps        = new NALUnit[0];
     spsExt     = new NALUnit[0];
     pat        = new ProgramAssociationTable();
     pmt        = new ProgramMapTable();
     adtsHeader = ADTSHeader.Default;
     nalSizeLen = 0;
     ptsBase    = -1;
 }
Ejemplo n.º 3
0
 public ADTSHeader(
     ADTSHeader other,
     int frame_length)
 {
     this.Sync                = other.Sync;
     this.Id                  = other.Id;
     this.Layer               = other.Layer;
     this.CRCAbsent           = other.CRCAbsent;
     this.Profile             = other.Profile;
     this.SamplingFreqIndex   = other.SamplingFreqIndex;
     this.IsPrivate           = other.IsPrivate;
     this.ChannelConfigurtion = other.ChannelConfigurtion;
     this.IsOriginal          = other.IsOriginal;
     this.IsHome              = other.IsHome;
     this.CopyrightIdBit      = other.CopyrightIdBit;
     this.CopyrightIdStart    = other.CopyrightIdStart;
     this.FrameLength         = frame_length;
     this.BufferFullness      = other.BufferFullness;
     this.RawDataBlocks       = other.RawDataBlocks;
     this.CRC                 = other.CRC;
 }
Ejemplo n.º 4
0
            private void OnAACBody(RTMPMessage msg)
            {
                var pts         = msg.Timestamp - Math.Max(0, ptsBase);
                var raw_length  = msg.Body.Length - 2;
                var header      = new ADTSHeader(adtsHeader, raw_length + adtsHeader.Bytesize);
                var pes_payload = new MemoryStream();

                using (pes_payload) {
                    ADTSHeader.WriteTo(pes_payload, header);
                    pes_payload.Write(msg.Body, 2, raw_length);
                }
                var pes        = new PESPacket(0xC0, TSTimeStamp.FromMilliseconds(pts), null, pes_payload.ToArray());
                var pes_packet = new MemoryStream();

                using (pes_packet) {
                    PESPacket.WriteTo(pes_packet, pes);
                }
                writer.WriteTSPackets(
                    AudioPID,
                    true,
                    null,
                    pes_packet.ToArray()
                    );
            }
Ejemplo n.º 5
0
 public static void WriteTo(Stream stream, ADTSHeader header)
 {
     using (var s = new BitWriter(stream, true)) {
         s.Write(12, header.Sync);
         s.Write(1, header.Id);
         s.Write(2, header.Layer);
         s.Write(1, header.CRCAbsent ? 1 : 0);
         s.Write(2, header.Profile);
         s.Write(4, header.SamplingFreqIndex);
         s.Write(1, header.IsPrivate);
         s.Write(3, header.ChannelConfigurtion);
         s.Write(1, header.IsOriginal);
         s.Write(1, header.IsHome);
         s.Write(1, header.CopyrightIdBit);
         s.Write(1, header.CopyrightIdStart);
         s.Write(13, header.FrameLength);
         s.Write(11, header.BufferFullness);
         s.Write(2, header.RawDataBlocks);
         if (!header.CRCAbsent)
         {
             s.Write(16, header.CRC);
         }
     }
 }