Beispiel #1
0
 public void ChangeAudioCfg(AudioEncodeCfg aCfg)
 {
     try
     {
         _aCfg = aCfg;
         if (_me != null)
         {
             _me.Error -= OnError;
             _me.Stop();
             _me.Dispose();
             _me = null;
         }
         _me        = new MicEncoder(_aCfg, OnCaptured);
         _me.Error += OnError;
         if (_isRuning)
         {
             if (IsAudioPub)
             {
                 _me.Start();
             }
         }
     }
     catch (Exception e)
     {
         OnError(e);
         Stop();
     }
 }
Beispiel #2
0
        public MicEncoder(AudioEncodeCfg audioCfg, Action <MediaFrame> callback)
        {
            _audioCfg  = audioCfg;
            _channels  = audioCfg.Channel;
            _frequency = audioCfg.Frequency;
            _capturer  = new MicCapturer(audioCfg.MicId, _channels, _frequency, audioCfg.Samples, MicCapturer_CallBack);
            if (audioCfg.encodeName.EqIgnoreCase("SPEX"))
            {
                _speex = new Speex(4);
            }
            else if (audioCfg.encodeName.EqIgnoreCase("AAC_"))
            {
                if (audioCfg.Params.ContainsKey("UseLastFaacImp") && FaacImp.LastFaacImp != null)
                {
                    _faacImp = FaacImp.LastFaacImp;
                    _faacImp.Encode(new byte[2048]);
                    _faacImp.Encode(new byte[2048]);
                    _faacImp.Encode(new byte[2048]);
                    _faacImp.Encode(new byte[2048]);
                    _faacImp.Encode(new byte[2048]);
                }
                else
                {
                    _faacImp = new FaacImp(_channels, _frequency, audioCfg.Bitrate);
                }
            }

            _callBack = callback;
        }
Beispiel #3
0
 public MediaCapturer(VideoEncodeCfg cfgVideo, AudioEncodeCfg cfgAudio)
 {
     IsVideoPub = true;
     IsAudioPub = true;
     _vCfg      = cfgVideo;
     _aCfg      = cfgAudio;
     Init();
 }
Beispiel #4
0
        public static MediaFrame CreateAudioKeyFrame(AudioEncodeCfg cfg, long timetick, byte[] data, int offset, int size)
        {
            MediaFrame mFrame = CreateAudioFrame(cfg, timetick, data, offset, size);// new

            // MediaFrame((byte)
            // 1);
            mFrame.MediaFrameVersion = 1;
            mFrame.IsKeyFrame        = 1;
            mFrame.Frequency         = cfg.Frequency;
            mFrame.Channel           = cfg.Channel;
            mFrame.AudioFormat       = (short)cfg.Format;
            mFrame.Samples           = (short)cfg.Samples;
            mFrame.Encoder           = cfg.encoder;

            return(mFrame);
        }
Beispiel #5
0
        public static MediaFrame CreateAudioFrame(AudioEncodeCfg cfg, long timetick, byte[] data, int offset, int size)
        {
            if (cfg is null)
            {
                throw new ArgumentNullException(nameof(cfg));
            }

            MediaFrame mFrame = new MediaFrame(0)
            {
                IsAudio    = 1,
                IsKeyFrame = 0,
                NTimetick  = timetick,
                Size       = size,
                Offset     = offset,
            };

            mFrame.SetData(data);
            return(mFrame);
        }
Beispiel #6
0
        public void ChangeCfg(VideoEncodeCfg vCfg, AudioEncodeCfg aCfg)
        {
            try
            {
                _vCfg = vCfg;
                _aCfg = aCfg;

                if (_ce != null)
                {
                    _ce.Error -= OnError;
                    _ce.Stop();
                    _ce.Dispose();
                    _ce = null;
                }
                if (_me != null)
                {
                    _me.Error -= OnError;
                    _me.Stop();
                    _me.Dispose();
                    _me = null;
                }
                Init();

                if (_isRuning)
                {
                    if (IsVideoPub)
                    {
                        _ce.Start();
                    }
                    if (IsAudioPub)
                    {
                        _me.Start();
                    }
                }
            }
            catch (Exception e)
            {
                OnError(e);
                Stop();
            }
        }