aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Video/DirectSampleGrabber.cs
blob: 36e1482676a29caa0d97ba4edc0db3da4f2c0d5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.high
using DirectShowLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Video.DirectShow
{
    internal class SampleGrabberImpl : ISampleGrabberCB
    {
        #region delegates
        public delegate int BufferCallback(double SampleTime, IntPtr pBuffer, int BufferLen);
        public delegate int BufferCallback2(double sampleTime, IMediaSample pSample);
        #endregion

        #region Members

        readonly BufferCallback _callback;
        readonly BufferCallback2 _callback2;
        #endregion

        #region Constructor
        public SampleGrabberImpl(BufferCallback callback, BufferCallback2 callback2 = null)
        {
            _callback = callback;
            _callback2 = callback2;
        }
        #endregion

        #region ISampleGrabberCB Members

        public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
        {
            if (_callback != null)
            {
                return _callback(SampleTime, pBuffer, BufferLen);
            }
            return 0;
        }

        public int SampleCB(double SampleTime, IMediaSample pSample)
        {
            if (_callback2 != null)
            {
                return _callback2(SampleTime, pSample);
            }
            Marshal.ReleaseComObject(pSample);
            return 0;
        }

        #endregion
    }
}