private MSR.LST.MDShow._AMMediaType copy_AMMediaType(UW.CSE.MDShow._AMMediaType uwmt) { MSR.LST.MDShow._AMMediaType msrmt = new MSR.LST.MDShow._AMMediaType(); msrmt.bFixedSizeSamples = uwmt.bFixedSizeSamples == 0?false:true; msrmt.bTemporalCompression = uwmt.bTemporalCompression == 0?false:true; msrmt.cbFormat = uwmt.cbFormat; msrmt.formattype = uwmt.formattype; msrmt.lSampleSize = uwmt.lSampleSize; msrmt.majortype = uwmt.majortype; msrmt.pbFormat = uwmt.pbFormat; msrmt.punk = uwmt.punk; msrmt.subtype = uwmt.subtype; return(msrmt); }
/// <summary> /// Build a graph with sampleGrabber. Render it, and get the media type. /// </summary> /// <param name="payload"></param> /// <returns></returns> public bool Build(PayloadType payload, RtpStream newStream) { this.stream = newStream; this.ssrc = newStream.SSRC; //Required as of RC3: this.stream.IsUsingNextFrame = true; if ((ssrc == 0) || !((payload == PayloadType.dynamicVideo) || (payload == PayloadType.dynamicAudio))) { errorMsg = "Invalid inputs to build method."; return(false); } fgm = new FilgraphManagerClass(); MSR.LST.MDShow.IBaseFilter bfSource = null; IGraphBuilder iGB = (IGraphBuilder)fgm; //if (false) // rotnum = FilterGraph.AddToRot(iGB); //AddToRot(iGB); try { bfSource = RtpSourceClass.CreateInstance(); ((MSR.LST.MDShow.Filters.IRtpSource)bfSource).Initialize(this.stream); iGB.AddFilter(bfSource, "RtpSource"); MSR.LST.MDShow.IPin sourceOutput = Filter.GetPin(bfSource, _PinDirection.PINDIR_OUTPUT, Guid.Empty, Guid.Empty, false, 0); //Add SampleGrabber filter MSR.LST.MDShow.IBaseFilter bfGrabber = SampleGrabberClass.CreateInstance(); iGB.AddFilter(bfGrabber, "Grabber"); UW.CSE.MDShow.ISampleGrabber sgGrabber = (UW.CSE.MDShow.ISampleGrabber)bfGrabber; //Set mediatype UW.CSE.MDShow._AMMediaType mt = new UW.CSE.MDShow._AMMediaType(); if (payload == PayloadType.dynamicVideo) { mt.majortype = MediaType.MajorType.MEDIATYPE_Video; //PRI2: RGB24 seems to work for all video? We have used YUY2 in the past, but that won't work // for screen streaming. Probably could use more testing //mt.subtype = MediaType.SubType.MEDIASUBTYPE_YUY2; mt.subtype = MediaType.SubType.MEDIASUBTYPE_RGB24; } else { mt.majortype = MediaType.MajorType.MEDIATYPE_Audio; mt.subtype = MediaType.SubType.MEDIASUBTYPE_PCM; //MEDIASUBTYPE_PCM; } sgGrabber.SetMediaType(ref mt); //Add samplegrabber callback //0 is sampleCB, 1 is bufferCB. Only bufferCB is actually returning data so far. sgGrabber.SetCallback(callBack, 1); sgGrabber.SetOneShot(0); sgGrabber.SetBufferSamples(0); iGB.Render(sourceOutput); UW.CSE.MDShow._AMMediaType uwmt = new UW.CSE.MDShow._AMMediaType(); sgGrabber.GetConnectedMediaType(ref uwmt); connectedMT = copy_AMMediaType(uwmt); } catch (Exception e) { errorMsg = e.Message; Debug.WriteLine("Exception while building graph: " + e.ToString()); eventLog.WriteEntry("Exception while building graph: " + e.ToString(), EventLogEntryType.Error, 1001); return(false); } return(true); }