Exemplo n.º 1
0
        private void Copy()
        {
            if (!_NewFrame)
            {
                return;
            }

            int num = -1;

            lock (MutexFramebuffer)
            {
                for (int i = 0; i < _FrameBuffer.Length; i++)
                {
                    if (_FrameBuffer[i].displayed)
                    {
                        num = i;
                        break;
                    }
                }

                if (num == -1)
                {
                    _BufferFull = true;
                }
                else
                {
                    TAc_decoder Videodecoder = (TAc_decoder)Marshal.PtrToStructure(_videodecoder, typeof(TAc_decoder));

                    _VideoDecoderTime      = (float)Videodecoder.timecode;
                    _FrameBuffer[num].time = _VideoDecoderTime;

                    if (Videodecoder.buffer != IntPtr.Zero)
                    {
                        Marshal.Copy(Videodecoder.buffer, _FrameBuffer[num].data, 0, _Width * _Height * 4);

                        _FrameBuffer[num].displayed = false;
                    }

                    int numfull = 0;
                    for (int i = 0; i < _FrameBuffer.Length; i++)
                    {
                        if (!_FrameBuffer[i].displayed)
                        {
                            numfull++;
                        }
                    }

                    if (numfull < _FrameBuffer.Length)
                    {
                        _BufferFull = false;
                    }

                    _NewFrame = false;
                }
            }

            //if (!_BufferFull)
            //    EventDecode.Set();
        }
Exemplo n.º 2
0
        public override void Decode(out byte[] Buffer, out float TimeStamp)
        {
            if (!_Initialized && !_FileOpened)
            {
                Buffer    = null;
                TimeStamp = 0f;
                return;
            }

            int FrameFinished = 0;

            try
            {
                FrameFinished = CAcinerella.ac_get_audio_frame(_instance, _audiodecoder);
            }
            catch (Exception)
            {
                FrameFinished = 0;
            }

            if (FrameFinished == 1)
            {
                TAc_decoder Decoder = (TAc_decoder)Marshal.PtrToStructure(_audiodecoder, typeof(TAc_decoder));

                TimeStamp    = (float)Decoder.timecode;
                _CurrentTime = TimeStamp;
                //Console.WriteLine(_CurrentTime.ToString("#0.000") + " Buffer size: " + Decoder.buffer_size.ToString());

                Buffer = new byte[Decoder.buffer_size];

                if (Decoder.buffer_size > 0)
                {
                    Marshal.Copy(Decoder.buffer, Buffer, 0, Buffer.Length);
                }

                return;
            }

            Buffer    = null;
            TimeStamp = 0f;
        }
Exemplo n.º 3
0
        private void DoOpen()
        {
            bool         ok       = false;
            TAc_instance Instance = new TAc_instance();

            try
            {
                _fs = new FileStream(_FileName, FileMode.Open, FileAccess.Read, FileShare.Read);


                _instance = CAcinerella.ac_init();
                CAcinerella.ac_open(_instance, IntPtr.Zero, null, _rc, _sc, null, IntPtr.Zero);

                Instance = (TAc_instance)Marshal.PtrToStructure(_instance, typeof(TAc_instance));
                ok       = true;
            }
            catch (Exception)
            {
                CLog.LogError("Error opening video file: " + _FileName);
                ok = false;
            }


            if (!Instance.opened || !ok)
            {
                //Free();
                return;
            }

            _Duration = (float)Instance.info.duration / 1000f;

            int VideoStreamIndex = -1;

            TAc_stream_info Info = new TAc_stream_info();

            for (int i = 0; i < Instance.stream_count; i++)
            {
                CAcinerella.ac_get_stream_info(_instance, i, out Info);

                if (Info.stream_type == TAc_stream_type.AC_STREAM_TYPE_VIDEO)
                {
                    _videodecoder = CAcinerella.ac_create_decoder(_instance, i);

                    VideoStreamIndex = i;
                    break;
                }
            }

            if (VideoStreamIndex < 0)
            {
                //Free();
                return;
            }

            TAc_decoder Videodecoder = (TAc_decoder)Marshal.PtrToStructure(_videodecoder, typeof(TAc_decoder));

            _Width  = Videodecoder.stream_info.video_info.frame_width;
            _Height = Videodecoder.stream_info.video_info.frame_height;

            if (Videodecoder.stream_info.video_info.frames_per_second > 0)
            {
                _VideoTimeBase = 1f / (float)Videodecoder.stream_info.video_info.frames_per_second;
            }

            _VideoDecoderTime = 0f;
            _Time             = 0f;

            for (int i = 0; i < _FrameBuffer.Length; i++)
            {
                _FrameBuffer[i].time      = -1f;
                _FrameBuffer[i].displayed = true;
                _FrameBuffer[i].data      = new byte[_Width * _Height * 4];
            }
            _FileOpened = true;
        }
Exemplo n.º 4
0
        public override void Open(string FileName, bool Loop)
        {
            if (!_Initialized)
            {
                return;
            }

            _FileName = FileName;
            _fs       = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);

            _instance = CAcinerella.ac_init();
            CAcinerella.ac_open(_instance, IntPtr.Zero, null, _rc, _sc, null, IntPtr.Zero);

            _Instance = (TAc_instance)Marshal.PtrToStructure(_instance, typeof(TAc_instance));

            if (!_Instance.opened)
            {
                //Free();
                return;
            }

            int AudioStreamIndex = -1;

            TAc_stream_info Info = new TAc_stream_info();

            for (int i = 0; i < _Instance.stream_count; i++)
            {
                CAcinerella.ac_get_stream_info(_instance, i, out Info);

                if (Info.stream_type == TAc_stream_type.AC_STREAM_TYPE_AUDIO)
                {
                    try
                    {
                        _audiodecoder = CAcinerella.ac_create_decoder(_instance, i);
                    }
                    catch (Exception)
                    {
                        return;
                    }

                    AudioStreamIndex = i;
                    break;
                }
            }

            if (AudioStreamIndex < 0)
            {
                //Free();
                return;
            }

            TAc_decoder Audiodecoder = (TAc_decoder)Marshal.PtrToStructure(_audiodecoder, typeof(TAc_decoder));

            _FormatInfo = new FormatInfo();

            _FormatInfo.SamplesPerSecond = Audiodecoder.stream_info.audio_info.samples_per_second;
            _FormatInfo.BitDepth         = Audiodecoder.stream_info.audio_info.bit_depth;
            _FormatInfo.ChannelCount     = Audiodecoder.stream_info.audio_info.channel_count;

            _CurrentTime = 0f;

            if (_FormatInfo.BitDepth != 16)
            {
                CLog.LogError("Unsupported BitDepth in file " + FileName);
                return;
            }
            _FileOpened = true;
        }