private void ProcessServerDescription(IBufferPacket data) { StspDescription desc = new StspDescription(); var dataLen = data.GetLength(); int descSize = Marshal.SizeOf(typeof(StspDescription)); int streamDescSize = Marshal.SizeOf(typeof(StspStreamDescription)); // Copy description desc = StreamConvertor.TakeObject <StspDescription>(data); // Size of the packet should match size described in the packet (size of Description structure + size of attribute blob) var cbConstantSize = Convert.ToInt32(descSize + (desc.cNumStreams - 1) * streamDescSize); // Check if the input parameters are valid. We only support 2 streams. if (cbConstantSize < Marshal.SizeOf(desc) || desc.cNumStreams == 0 || desc.cNumStreams > 2 || dataLen < cbConstantSize) { ThrowIfError(HResult.MF_E_UNSUPPORTED_FORMAT); } try { List <StspStreamDescription> streamDescs = new List <StspStreamDescription>(desc.aStreams); for (int i = 1; i < desc.cNumStreams; i++) { var sd = StreamConvertor.TakeObject <StspStreamDescription>(data); streamDescs.Add(sd); } int cbAttributeSize = 0; for (int i = 0; i < desc.cNumStreams; ++i) { cbAttributeSize += streamDescs[i].cbAttributesSize; /* todo: check out of range on cbAttributeSize * if (out of range) * { * Throw(HResult.MF_E_UNSUPPORTED_FORMAT); * }*/ } // Validate the parameters. Limit the total size of attributes to 64kB. if ((dataLen != (cbConstantSize + cbAttributeSize)) || (cbAttributeSize > 0x10000)) { Throw(HResult.MF_E_UNSUPPORTED_FORMAT); } //only init for the first video stream. foreach (var sd in streamDescs) { if (sd.guiMajorType == MFMediaType.Video) { initVideoDesctriptor(sd, data); _decoder.initialize(_videoStreamId, _videoMediaType); break; } } } catch (Exception ex) { throw ex; } }
private void ProcessServerDescription(IBufferPacket data) { StspDescription desc = new StspDescription(); var dataLen = data.GetLength(); int descSize = Marshal.SizeOf(typeof(StspDescription)); int streamDescSize = Marshal.SizeOf(typeof(StspStreamDescription)); // Copy description desc = StreamConvertor.TakeObject <StspDescription>(data); // Size of the packet should match size described in the packet (size of Description structure + size of attribute blob) var cbConstantSize = Convert.ToInt32(descSize + (desc.cNumStreams - 1) * streamDescSize); // Check if the input parameters are valid. We only support 2 streams. if (cbConstantSize < Marshal.SizeOf(desc) || desc.cNumStreams == 0 || desc.cNumStreams > 2 || dataLen < cbConstantSize) { ThrowIfError(HResult.MF_E_UNSUPPORTED_FORMAT); } try { List <StspStreamDescription> streamDescs = new List <StspStreamDescription>(desc.aStreams); for (int i = 1; i < desc.cNumStreams; i++) { var sd = StreamConvertor.TakeObject <StspStreamDescription>(data); streamDescs.Add(sd); } int cbAttributeSize = 0; for (int i = 0; i < desc.cNumStreams; ++i) { cbAttributeSize += streamDescs[i].cbAttributesSize; /* todo: check out of range on cbAttributeSize * if (out of range) * { * Throw(HResult.MF_E_UNSUPPORTED_FORMAT); * }*/ } // Validate the parameters. Limit the total size of attributes to 64kB. if ((dataLen != (cbConstantSize + cbAttributeSize)) || (cbAttributeSize > 0x10000)) { Throw(HResult.MF_E_UNSUPPORTED_FORMAT); } // Create stream for every stream description sent by the server. foreach (var sd in streamDescs) { MediaStream spStream; ThrowIfError(MediaStream.CreateInstance(sd, data, this, out spStream)); _streams.Add(spStream); } InitPresentationDescription(); // Everything succeeded we are in stopped state now _eSourceState = SourceState.SourceState_Stopped; CompleteOpen(HResult.S_OK); } catch (Exception ex) { throw ex; } }