LEADTOOLS Multimedia (Leadtools.Multimedia assembly)
LEAD Technologies, Inc

GetCacheObject Method

Example 





Value that indicates which caching object to retrieve. This must be one of the TargetFormatObject constants.
Gets the caching filter object.
Syntax
public object GetCacheObject( 
   TargetFormatObject ObjType
)
'Declaration
 
Public Function GetCacheObject( _
   ByVal ObjType As TargetFormatObject _
) As Object
'Usage
 
Dim instance As TargetFormat
Dim ObjType As TargetFormatObject
Dim value As Object
 
value = instance.GetCacheObject(ObjType)
public object GetCacheObject( 
   TargetFormatObject ObjType
)
 function Leadtools.Multimedia.TargetFormat.GetCacheObject( 
   ObjType 
)
public:
Object^ GetCacheObject( 
   TargetFormatObject ObjType
) 

Parameters

ObjType
Value that indicates which caching object to retrieve. This must be one of the TargetFormatObject constants.

Return Value

A System.Object of the type specified by the TargetFormatObject and represents the caching filter object.
Remarks
Use the UseFilterCache property to get a value that indicates whether the toolkit is currently caching filters, or set a value that indicates whether to enable or disable the caching of filters. Use the ShowCacheDialog method to display a specific property dialog for the caching filter. Use the HasCacheDialog method to query whether the specified property dialog for the caching filter is available.
Example
Copy CodeCopy Code  
Public _result As Boolean = False
         Public _form As CaptureCtrlForm = New CaptureCtrlForm()
         Public _pMpgMux As LMMpg2MxTLib.LMMpg2MxT
         ' This example will show you the correct way to set up a muxer's properties during capture
         ' Normally, the muxer is added only after the capture graph has been build with ReadyCapture or StartCapture
         ' But at this point, the graph is in running mode, so some muxer operations might fail
         ' If you need to make changes to the muxer in stopped state (like adding KLV data stream, for example),
         ' then you need to change the muxer before the graph is fully built. You can do so by instructing the toolkit
         ' to cache the target filters by setting the the TargetFormat.UseFilterCache property to true
         ' In this situation, the filters used to implement a certain target format are created and used whenever 
         ' you set that target format.

         ' This example will show you how to add KLV data to a MPEG-2 Transport Stream in a capture situation.

         Public Sub UseFilterCacheExample()
             ' reference the capture control
             Dim capturectrl As CaptureCtrl = _form.CaptureCtrl
             Dim outFile As String = Path.Combine(LEAD_VARS.MediaDir, "CaptureKLV.mpg")

             Try
                 ' select the capture device
                 capturectrl.VideoDevices.Selection = 0 ' Use a different video device if you want 

                 ' capturectrl.Preview = true; -- enable this if you want 


                 ' set the video compressor (only if the capture device is not already capturing compressed video)

                 capturectrl.VideoCompressors.Mpeg2.Selected = True

                 ' set the target output file
                 capturectrl.TargetFile = outFile

                 ' subscribe to the compete event
                 AddHandler capturectrl.Started, AddressOf CaptureCtrl_Started

                 ' just 10 seconds of capture time
                 capturectrl.TimeLimit = 10
                 capturectrl.UseTimeLimit = True

                 ' subscribe to the compete event
                 AddHandler capturectrl.Complete, AddressOf CaptureCtrl_Complete

                 ' IN a capture situation 
                 'in order to get the mux in a capture situation, set the UseFilterCache property for the target format to TRUE
                 '      This tells the toolkit to create a Mux object and keep it around when building or rebuilding graphs
                 capturectrl.TargetFormats(Leadtools.Multimedia.TargetFormatType.MPEG2Transport).UseFilterCache = True
                 capturectrl.TargetFormat = Leadtools.Multimedia.TargetFormatType.MPEG2Transport

                 _pMpgMux = DirectCast(capturectrl.TargetFormats(Leadtools.Multimedia.TargetFormatType.MPEG2Transport).GetCacheObject(TargetFormatObject.Mux), LMMpg2MxTLib.LMMpg2MxT)
                 If _pMpgMux IsNot Nothing Then
                     _pMpgMux.PrivateDataPID = &H70
                     _pMpgMux.PrivateDataFormatID = &H41564C4B
                     _pMpgMux.EnablePrivateData = True
                 End If

                 ' start capture
                 capturectrl.StartCapture(Leadtools.Multimedia.CaptureMode.Video)
             Catch generatedExceptionName As Exception
                 _result = False
             End Try
         End Sub

         Private Sub WriteKLVData(ByVal pMpgMux As LMMpg2MxTLib.LMMpg2MxT)
             ' get the current time since Jan 1, 1970
             Dim basetime As TimeSpan = DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)
             ' get the number of microseconds since Jan 1, 1970
             Dim timestamp As Int64 = CLng(basetime.TotalSeconds) * 1000000
             ' don't really need to do this, since I am writing only one item
             pMpgMux.KlvBuilder.Clear()
             ' write the UDS timestamp (number of microseconds since Jan 1, 1970)
             pMpgMux.KlvBuilder.InsertUInt64(-1, "06 0E 2B 34 01 01 01 03 07 02 01 01 01 05 00 00", CULng(timestamp))
             ' write one KLV data at the beginning
             pMpgMux.WritePrivateData(CInt(LMMpg2MxTLib.Mpg2MxT_WriteFlags.Mpg2MxT_WriteFlag_PTSValid) _
                                      Or CInt(LMMpg2MxTLib.Mpg2MxT_WriteFlags.Mpg2MxT_WriteFlag_PTSInSeconds), _
                                      0.0, pMpgMux.KlvBuilder.GetData(), -1)
             ' close the stream
             pMpgMux.ClosePrivateData()
         End Sub

         Public Sub CaptureCtrl_Started(ByVal sender As Object, ByVal e As EventArgs)
             WriteKLVData(_pMpgMux)
         End Sub

         Public Sub CaptureCtrl_Complete(ByVal sender As Object, ByVal e As EventArgs)
             ' set result
             _result = True
         End Sub

Public NotInheritable Class LEAD_VARS
   Public Const MediaDir As String = "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 175\Media";
End Class
public bool _result = false;
      public CaptureCtrlForm _form = new CaptureCtrlForm();
      public LMMpg2MxTLib.LMMpg2MxT _pMpgMux;
      // This example will show you the correct way to set up a muxer's properties during capture
      // Normally, the muxer is added only after the capture graph has been build with ReadyCapture or StartCapture
      // But at this point, the graph is in running mode, so some muxer operations might fail
      // If you need to make changes to the muxer in stopped state (like adding KLV data stream, for example),
      // then you need to change the muxer before the graph is fully built. You can do so by instructing the toolkit
      // to cache the target filters by setting the the TargetFormat.UseFilterCache property to true
      // In this situation, the filters used to implement a certain target format are created and used whenever 
      // you set that target format.
      //
      // This example will show you how to add KLV data to a MPEG-2 Transport Stream in a capture situation.
      public void UseFilterCacheExample()
      {
         // reference the capture control
         CaptureCtrl capturectrl = _form.CaptureCtrl;
         string outFile = Path.Combine(LEAD_VARS.MediaDir, "CaptureKLV.mpg");

         try
         {
            // select the capture device
            capturectrl.VideoDevices.Selection = 0; /* Use a different video device if you want */

            /* capturectrl.Preview = true; -- enable this if you want */

            /* set the video compressor (only if the capture device is not already capturing compressed video) */
            capturectrl.VideoCompressors.Mpeg2.Selected = true;

            // set the target output file
            capturectrl.TargetFile = outFile;

            // subscribe to the started event
            capturectrl.Started += new System.EventHandler(this.CaptureCtrl_Started);

            // just 10 seconds of capture time
            capturectrl.TimeLimit = 10;
            capturectrl.UseTimeLimit = true;

            // subscribe to the complete event
            capturectrl.Complete += new EventHandler(CaptureCtrl_Complete);

            // IN a capture situation 
            //in order to get the mux in a capture situation, set the UseFilterCache property for the target format to TRUE
            //      This tells the toolkit to create a Mux object and keep it around when building or rebuilding graphs
            capturectrl.TargetFormats[Leadtools.Multimedia.TargetFormatType.MPEG2Transport].UseFilterCache = true;
            capturectrl.TargetFormat = Leadtools.Multimedia.TargetFormatType.MPEG2Transport;

            _pMpgMux = (LMMpg2MxTLib.LMMpg2MxT)capturectrl.TargetFormats[Leadtools.Multimedia.TargetFormatType.MPEG2Transport].GetCacheObject(TargetFormatObject.Mux);
            if (_pMpgMux != null)
            {
               _pMpgMux.PrivateDataPID = 0x70;
               _pMpgMux.PrivateDataFormatID = 0x41564c4b;
               _pMpgMux.EnablePrivateData = true;
            }

            // start capture
            capturectrl.StartCapture(Leadtools.Multimedia.CaptureMode.Video);
         }
         catch (Exception)
         {
            _result = false;
         }
      }

      private void WriteKLVData(LMMpg2MxTLib.LMMpg2MxT pMpgMux)
      {
         // get the current time since Jan 1, 1970
         TimeSpan basetime = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0);
         // get the number of microseconds since Jan 1, 1970
         Int64 timestamp = (Int64)basetime.TotalSeconds * 1000000;
         // do not really need to do this, since I am writing only one item
         pMpgMux.KlvBuilder.Clear();
         // write the UDS timestamp (number of microseconds since Jan 1, 1970)
         pMpgMux.KlvBuilder.InsertUInt64(-1, "06 0E 2B 34 01 01 01 03 07 02 01 01 01 05 00 00", (ulong)timestamp);
         // write one KLV data at the beginning
         pMpgMux.WritePrivateData((int)LMMpg2MxTLib.Mpg2MxT_WriteFlags.Mpg2MxT_WriteFlag_PTSValid | 
                                  (int)LMMpg2MxTLib.Mpg2MxT_WriteFlags.Mpg2MxT_WriteFlag_PTSInSeconds, 
                                  0.0, pMpgMux.KlvBuilder.GetData(), 
                                  -1);
         // close the stream
         pMpgMux.ClosePrivateData();
      }

      private void CaptureCtrl_Started(object sender, EventArgs e)
      {
         WriteKLVData(_pMpgMux);
      }

      private void CaptureCtrl_Complete(object sender, EventArgs e)
      {
          // set result
          _result = true;
      }

static class LEAD_VARS
{
   public const string MediaDir = @"C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 175\Media";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

TargetFormat Class
TargetFormat Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Multimedia requires a Multimedia or Multimedia Suite license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features