Copying ltmmMediaSample Attributes and Data Example for Visual Basic
The following code demonstrates how to copy a media sample's attributes and data to another media sample.
Function CopyMediaSampleAttributes(Dest As ltmmMediaSample, Source As ltmmMediaSample) As Boolean
Dim MediaType As ltmmMediaType
Dim TimeStartHi As Long
Dim TimeStartLo As Long
Dim TimeStopHi As Long
Dim TimeStopLo As Long
' if there is no room, then return False
If Source.ActualDataLength > Dest.BufferSize Then
CopyMediaSampleAttributes = False
Exit Function
End If
If Source.ActualDataLength > 0 Then
' copy data
Dest.SetData Source.ActualDataLength, Source.GetData (Source.ActualDataLength)
Else
' no data
Dest.ActualDataLength = 0
End If
' copy media type
Set MediaType = Source.GetMediaType
If Not IsNull(MediaType) Then
Dest.SetMediaType MediaType
End If
' other flags
Dest.Discontinuity = Source.Discontinuity
Dest.Preroll = Source.Preroll
Dest.SyncPoint = Source.SyncPoint
' copy sample time
On Error GoTo ResetTime
Source.GetTime TimeStartHi, TimeStartLo, TimeStopHi, TimeStopLo
Dest.SetTime TimeStartHi, TimeStartLo, TimeStopHi, TimeStopLo
GoTo NoResetTime
ResetTime:
Dest.ResetTime
NoResetTime:
' copy media time
On Error GoTo ResetMediaTime
Source.GetMediaTime TimeStartHi, TimeStartLo, TimeStopHi, TimeStopLo
Dest.SetMediaTime TimeStartHi, TimeStartLo, TimeStopHi, TimeStopLo
GoTo NoResetMediaTime
ResetMediaTime:
Dest.ResetMediaTime
NoResetMediaTime:
' all is well
CopyMediaSampleAttributes = True
End Function