Exemple #1
0
 /// <summary>生成と同時に開始する。</summary>
 public CCounter(float n開始値, float n終了値, float n間隔ms, CTimer timer)
     : this()
 {
     this.t開始(n開始値, n終了値, n間隔ms, timer);
 }
Exemple #2
0
        public CVideoDecoder(Device device, string filename)
        {
            this.device = device;
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException(filename + " not found...");
            }

            format_context = ffmpeg.avformat_alloc_context();
            fixed(AVFormatContext **format_contexttmp = &format_context)
            {
                if (ffmpeg.avformat_open_input(format_contexttmp, filename, null, null) != 0)
                {
                    throw new FileLoadException("avformat_open_input failed\n");
                }

                if (ffmpeg.avformat_find_stream_info(*format_contexttmp, null) < 0)
                {
                    throw new FileLoadException("avformat_find_stream_info failed\n");
                }

                // find audio stream
                for (int i = 0; i < (int)format_context->nb_streams; i++)
                {
                    if (format_context->streams[i]->codecpar->codec_type == AVMediaType.AVMEDIA_TYPE_VIDEO)
                    {
                        video_stream = format_context->streams[i];
                        break;
                    }
                }
                if (video_stream == null)
                {
                    throw new FileLoadException("No video stream ...\n");
                }

                // find decoder
                codec = ffmpeg.avcodec_find_decoder(video_stream->codecpar->codec_id);
                if (codec == null)
                {
                    throw new NotSupportedException("No supported decoder ...\n");
                }

                codec_context = ffmpeg.avcodec_alloc_context3(codec);

                if (ffmpeg.avcodec_parameters_to_context(codec_context, video_stream->codecpar) < 0)
                {
                    Trace.WriteLine("avcodec_parameters_to_context failed\n");
                }

                if (ffmpeg.avcodec_open2(codec_context, codec, null) != 0)
                {
                    Trace.WriteLine("avcodec_open2 failed\n");
                }

                this.FrameSize = new Size(codec_context->width, codec_context->height);
                this.Duration  = (video_stream->avg_frame_rate.num / (double)video_stream->avg_frame_rate.den) * video_stream->nb_frames;
                framecount     = codec_context->frame_number;
                Framerate      = video_stream->avg_frame_rate;

                frame  = ffmpeg.av_frame_alloc();
                packet = ffmpeg.av_packet_alloc();
                if (codec_context->pix_fmt != CVPxfmt)
                {
                    convert_context = ffmpeg.sws_getContext(
                        FrameSize.Width,
                        FrameSize.Height,
                        codec_context->pix_fmt,
                        FrameSize.Width,
                        FrameSize.Height,
                        CVPxfmt,
                        ffmpeg.SWS_FAST_BILINEAR, null, null, null);
                    this.IsConvert = true;
                }
                if (convert_context == null)
                {
                    throw new ApplicationException("Could not initialize the conversion context.\n");
                }
                decodedframes = new Queue <CDecodedFrame>();

                CTimer = new CTimer(CTimer.E種別.MultiMedia);

                _convertedFrameBufferPtr = Marshal.AllocHGlobal(ffmpeg.av_image_get_buffer_size(CVPxfmt, codec_context->width, codec_context->height, 1));

                _dstData     = new byte_ptrArray4();
                _dstLinesize = new int_array4();
                ffmpeg.av_image_fill_arrays(ref _dstData, ref _dstLinesize, (byte *)_convertedFrameBufferPtr, CVPxfmt, codec_context->width, codec_context->height, 1);
            }
        }
        // メソッド

        public unsafe CSoundDeviceOpenAL(long n遅延時間ms, bool bUseOSTimer)
        {
            Trace.TraceInformation("OpenAL の初期化を開始します。");

            this.eOutputDevice = ESoundDeviceType.Unknown;
            this.nBufferSizems = this.nOutPutDelayms = n遅延時間ms;
            this.tmSystemTimer = new CTimer();

            #region [ OpenAL サウンドデバイスの作成]

            //Initialize
            this.device  = Alc.OpenDevice(null);
            this.context = Alc.CreateContext(this.device, (int *)null);
            Alc.MakeContextCurrent(this.context);

            //Versionの確認
            var version  = AL.Get(ALGetString.Version);
            var vendor   = AL.Get(ALGetString.Vendor);
            var renderer = AL.Get(ALGetString.Renderer);
            Console.WriteLine("OpenAL Version=" + version);
            Console.WriteLine("OpenAL Vendor=" + vendor);
            Console.WriteLine("OpenAL Renderer=" + renderer);

            // デバイス作成完了。
            this.eOutputDevice = ESoundDeviceType.OpenAL;
            #endregion

            if (!bUseOSTimer)
            {
                #region [ 経過時間計測用サウンドバッファを作成し、ループ再生を開始する。]
                //-----------------

                // 単位繰り上げ間隔[秒]の長さを持つ無音のサウンドを作成。

                uint nデータサイズbyte = n単位繰り上げ間隔sec * 44100 * 2 * 2;
                var  ms          = new MemoryStream();
                var  bw          = new BinaryWriter(ms);
                bw.Write((uint)0x46464952);                                     // 'RIFF'
                bw.Write((uint)(44 + nデータサイズbyte - 8));                         // ファイルサイズ - 8
                bw.Write((uint)0x45564157);                                     // 'WAVE'
                bw.Write((uint)0x20746d66);                                     // 'fmt '
                bw.Write((uint)16);                                             // バイト数
                bw.Write((ushort)1);                                            // フォーマットID(リニアPCM)
                bw.Write((ushort)2);                                            // チャンネル数
                bw.Write((uint)44100);                                          // サンプリング周波数
                bw.Write((uint)(44100 * 2 * 2));                                // bytes/sec
                bw.Write((ushort)(2 * 2));                                      // blockサイズ
                bw.Write((ushort)16);                                           // bit/sample
                bw.Write((uint)0x61746164);                                     // 'data'
                bw.Write((uint)nデータサイズbyte);                                    // データ長
                for (int i = 0; i < nデータサイズbyte / sizeof(long); i++)            // PCMデータ
                {
                    bw.Write((long)0);
                }
                var byArrWaveFleImage = ms.ToArray();
                bw.Close();
                ms = null;
                bw = null;
                this.sd経過時間計測用サウンドバッファ = this.tCreateSound(byArrWaveFleImage, ESoundGroup.Unknown);

                CSound.listインスタンス.Remove(this.sd経過時間計測用サウンドバッファ);                       // 特殊用途なのでインスタンスリストからは除外する。

                // サウンドのループ再生開始。

                this.nループ回数 = 0;
                this.n前回の位置 = 0;
                AL.Source(this.sd経過時間計測用サウンドバッファ.SourceOpen[0], ALSourceb.Looping, true);
                AL.SourcePlay(this.sd経過時間計測用サウンドバッファ.SourceOpen[0]);
                this.n前に経過時間を測定したシステム時刻ms = this.tmSystemTimer.nシステム時刻ms;
                //-----------------
                #endregion
            }
            else
            {
                ctimer = new CTimer();
            }
            Trace.TraceInformation("OpenAL を初期化しました。({0})", bUseOSTimer? "OStimer" : "FDKtimer");
        }
Exemple #4
0
 public void Stop()
 {
     cts?.Cancel();
     CTimer.t一時停止();
     this.bPlaying = false;
 }
Exemple #5
0
 public void Start()
 {
     CTimer.tリセット();
     CTimer.t再開();
     this.bPlaying = true;
 }
Exemple #6
0
 /// <summary>生成と同時に開始する。</summary>
 public CCounter(int n開始値, int n終了値, int n間隔ms, CTimer timer)
     : this()
 {
     this.tStart(n開始値, n終了値, n間隔ms, timer);
 }
Exemple #7
0
        // メソッド

        public CSoundDeviceDirectSound(IntPtr hWnd, long n遅延時間ms, bool bUseOSTimer)
        {
            Trace.TraceInformation("DirectSound の初期化を開始します。");

            this.e出力デバイス     = ESoundDeviceType.Unknown;
            this.n実バッファサイズms = this.n実出力遅延ms = n遅延時間ms;
            this.tmシステムタイマ   = new CTimer(CTimer.E種別.MultiMedia);

            #region [ DirectSound デバイスを作成する。]
            //-----------------
            this.DirectSound = new DirectSound();               // 失敗したら例外をそのまま発出。

            // デバイスの協調レベルを設定する。

            bool priority = true;
            try
            {
                this.DirectSound.SetCooperativeLevel(hWnd, CooperativeLevel.Priority);
            }
            catch
            {
                this.DirectSound.SetCooperativeLevel(hWnd, CooperativeLevel.Normal);                    // これでも失敗したら例外をそのまま発出。
                priority = false;
            }

            // デバイス作成完了。

            this.e出力デバイス = ESoundDeviceType.DirectSound;
            //-----------------
            #endregion

            if (!bUseOSTimer)
            {
                #region [ 経過時間計測用サウンドバッファを作成し、ループ再生を開始する。]
                //-----------------

                // 単位繰り上げ間隔[秒]の長さを持つ無音のサウンドを作成。

                uint nデータサイズbyte = n単位繰り上げ間隔sec * 44100 * 2 * 2;
                var  ms          = new MemoryStream();
                var  bw          = new BinaryWriter(ms);
                bw.Write((uint)0x46464952);                                     // 'RIFF'
                bw.Write((uint)(44 + nデータサイズbyte - 8));                         // ファイルサイズ - 8
                bw.Write((uint)0x45564157);                                     // 'WAVE'
                bw.Write((uint)0x20746d66);                                     // 'fmt '
                bw.Write((uint)16);                                             // バイト数
                bw.Write((ushort)1);                                            // フォーマットID(リニアPCM)
                bw.Write((ushort)2);                                            // チャンネル数
                bw.Write((uint)44100);                                          // サンプリング周波数
                bw.Write((uint)(44100 * 2 * 2));                                // bytes/sec
                bw.Write((ushort)(2 * 2));                                      // blockサイズ
                bw.Write((ushort)16);                                           // bit/sample
                bw.Write((uint)0x61746164);                                     // 'data'
                bw.Write((uint)nデータサイズbyte);                                    // データ長
                for (int i = 0; i < nデータサイズbyte / sizeof(long); i++)            // PCMデータ
                {
                    bw.Write((long)0);
                }
                var byArrWaveFleImage = ms.ToArray();
                bw.Close();
                ms = null;
                bw = null;
                this.sd経過時間計測用サウンドバッファ = this.tサウンドを作成する(byArrWaveFleImage, ESoundGroup.Unknown);

                CSound.listインスタンス.Remove(this.sd経過時間計測用サウンドバッファ);                       // 特殊用途なのでインスタンスリストからは除外する。

                // サウンドのループ再生開始。

                this.nループ回数 = 0;
                this.n前回の位置 = 0;
                this.sd経過時間計測用サウンドバッファ.DirectSoundBuffer.Play(0, PlayFlags.Looping);
                this.n前に経過時間を測定したシステム時刻ms = this.tmシステムタイマ.nシステム時刻ms;
                //-----------------
                #endregion
            }
            else
            {
                ctimer = new CTimer(CTimer.E種別.MultiMedia);
            }
            Trace.TraceInformation("DirectSound を初期化しました。({0})({1})", (priority) ? "Priority" : "Normal", bUseOSTimer? "OStimer" : "FDKtimer");
        }
Exemple #8
0
        public CVideoDecoder(Device device, string filename)
        {
            this.device = device;
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException(filename + " not found...");
            }

            format_context = ffmpeg.avformat_alloc_context();
            fixed(AVFormatContext **format_contexttmp = &format_context)
            {
                if (ffmpeg.avformat_open_input(format_contexttmp, filename, null, null) != 0)
                {
                    throw new FileLoadException("avformat_open_input failed\n");
                }

                if (ffmpeg.avformat_find_stream_info(*format_contexttmp, null) < 0)
                {
                    throw new FileLoadException("avformat_find_stream_info failed\n");
                }

                // find audio stream
                for (int i = 0; i < (int)format_context->nb_streams; i++)
                {
                    if (format_context->streams[i]->codecpar->codec_type == AVMediaType.AVMEDIA_TYPE_VIDEO)
                    {
                        video_stream = format_context->streams[i];
                        break;
                    }
                }
                if (video_stream == null)
                {
                    throw new FileLoadException("No video stream ...\n");
                }

                // find decoder
                AVCodec *codec = ffmpeg.avcodec_find_decoder(video_stream->codecpar->codec_id);

                if (codec == null)
                {
                    throw new NotSupportedException("No supported decoder ...\n");
                }

                codec_context = ffmpeg.avcodec_alloc_context3(codec);

                if (ffmpeg.avcodec_parameters_to_context(codec_context, video_stream->codecpar) < 0)
                {
                    Trace.WriteLine("avcodec_parameters_to_context failed\n");
                }

                if (ffmpeg.avcodec_open2(codec_context, codec, null) != 0)
                {
                    Trace.WriteLine("avcodec_open2 failed\n");
                }

                this.FrameSize = new Size(codec_context->width, codec_context->height);
                this.Duration  = (video_stream->avg_frame_rate.num / (double)video_stream->avg_frame_rate.den) * video_stream->nb_frames;
                this.Framerate = video_stream->avg_frame_rate;

                frameconv = new CFrameConverter(FrameSize, codec_context->pix_fmt);

                frame         = ffmpeg.av_frame_alloc();
                decodedframes = new ConcurrentQueue <CDecodedFrame>();

                CTimer = new CTimer();
            }
        }