/// <summary> /// WriteSamples /// Write several samples to the output file. /// </summary> /// <param name="slices"></param> /// <param name="codecType"></param> public override void WriteSamples(IEnumerable <Slice> slices, CodecTypes codecType) { if (codecType == CodecTypes.Audio) { // ignore audio } else if (codecType == CodecTypes.Video) { IMediaTrack trak = MediaTracks.First(t => t.Codec.CodecType == CodecTypes.Video); foreach (Slice sample in slices) { // convert to bit-stream format (prefix with 0001) Stream mstrm = new MemoryStream(sample.SliceBytes); Stream ostr = H264.H264Utilities.H264Stream(firstSample, trak.Codec.PrivateCodecData, mstrm, 0, (uint)sample.SliceBytes.Length); firstSample = false; mstrm.Close(); ostr.Position = 0L; byte[] buf = new byte[ostr.Length]; ostr.Read(buf, 0, (int)ostr.Length); ostr.Close(); sample.SliceBytes = buf; Stream.Write(sample.SliceBytes, 0, sample.SliceBytes.Length); } } else { throw new Exception("WriteSamples: unknown codec type"); } }
public void Initialize() { lock (SourceLock) { if (_state != PlayingState.NONE) { // Already initialized return; } var method = RtspRequest.RtspMethod.OPTIONS; var builder = RtspRequest.CreateBuilder().Uri(_currentUri).Method(method); // TODO(frank.lamar): Add check for supported operations. Otherwise this call // is meaning less. CheckResponse(_client.Send(builder.Build()), method); // Send Describe to server method = RtspRequest.RtspMethod.DESCRIBE; var response = CheckResponse(_client.Send(builder.Method(method).Build()), method); _tracks = MediaTracks.FromSdp(response.GetBodyAsSdp(), _currentUri, _filter); // Initialize our session refresh timmer. _sessionRefreshTimer = new Timer(); _sessionRefreshTimer.AutoReset = true; _sessionRefreshTimer.Elapsed += SessionRefreshTimer_Elapsed; _state = PlayingState.INITIALIZED; } }
public IMediaTrack this[CodecTypes type, int id] { get { if (MediaTracks.Count == 0) { return(null); } GenericMediaTrack track = null; if (id == 0) // get the first track with the given type { if (MediaTracks.Any(trk => trk.Codec.CodecType == type)) { track = (GenericMediaTrack)MediaTracks.First(trk => trk.Codec.CodecType == type); } } else // get specific track with the given type and track ID { if (MediaTracks.Any(trk => trk.Codec.CodecType == type && trk.TrackID == id)) { track = (GenericMediaTrack)MediaTracks.First(trk => trk.Codec.CodecType == type && trk.TrackID == id); } } return(track); } }
/// <summary> /// Open all files associated with the ISM. /// </summary> /// <param name="inPath">path name to ISM file without extension</param> public override void Open(string inPath, bool withCaching) { _mainFolderPath = Path.GetDirectoryName(inPath); _ismFile = new ISMFile(_mainFolderPath, Path.GetFileNameWithoutExtension(inPath)); foreach (ISMElement element in _ismFile.ISMElements) { GenericMediaTrack ismTrack = null; if (element.FragmentType == FragmentType.Video) { ismTrack = new ISMVideoTrack(new ISMVTrackFormat(_mainFolderPath, element.Source, element), this); } else if (element.FragmentType == FragmentType.Audio) { ismTrack = new ISMAudioTrack(new ISMVTrackFormat(_mainFolderPath, element.Source, element), this); } MediaTracks.Add(ismTrack); // choose longest track duration to be stream duration if (DurationIn100NanoSecs < ismTrack.TrackDurationIn100NanoSecs) { DurationIn100NanoSecs = ismTrack.TrackDurationIn100NanoSecs; } } CachingEnabled = withCaching; }
public void AddTrack(IMediaTrack inTrack) { Common.Logger.Instance.Info("[GenericMediaStream::AddTrack] added " + inTrack + ", " + (inTrack != null ? inTrack.GetType().Name : string.Empty)); MediaTracks.Add(inTrack); if (MediaTrackAdded != null) { MediaTrackAdded(inTrack); } }
private Uri DetermineRealUri() { // The VideoXpert system does some non-standard RTSP redirecting so that it can determine the intent of // the client (intent being live or playback). It stats off by creating a spoofed SDP and then will // redirect on play. What we will do it write a wrapper that does some of the RTSP calls to first // determine what the actual live RTSP uri is. using (RtspClient client = new RtspClient(_uri)) { try { var method = RtspRequest.RtspMethod.OPTIONS; CheckResponse(client.Send(RtspRequest.CreateBuilder() .Method(method) .Uri(_uri) .Build()), method); method = RtspRequest.RtspMethod.DESCRIBE; var res = CheckResponse(client.Send(RtspRequest.CreateBuilder() .Method(method) .Uri(_uri) .Build()), method); var sdp = res.GetBodyAsSdp(); if (!sdp.SessionName.Contains("Spoofed session")) { // We are not working with a spoofed session just return // the current uri. return(_uri); } Uri controlUri = null; var tracks = MediaTracks.FromSdp(sdp, _uri); foreach (var track in tracks) { if (track.Type.Is(MimeType.ANY_VIDEO)) { if (GetRedirectUri(client, track, out controlUri)) { return(controlUri); } } } throw new RtspClientException($"Unable to retrieve usable uri from server at endpoint '{_uri}'"); } catch (Exception e) { LOG.Error(e, $"Failed while communicating with RTSP server at '{_uri}'"); throw e; } } }
public void DeleteTrackAccordingPosition(int index, EditorModel m) { var trackName = MediaTracks[index].FullName.Name; MediaTracks.RemoveAt(index); var name = System.IO.Path.Combine(m.Locations.TemporalDirectory.FullName, trackName); if (File.Exists(name)) { try { File.Delete(name); } catch { } } }
public override void InitializeForWriting(List <IsochronousTrackInfo> mediaTracksInfo) { foreach (IsochronousTrackInfo trak in mediaTracksInfo) { if (trak.HandlerType.Equals("Video")) { GenericTrackFormat format = new H264Format(); format.Codec = new Codec(CodecTypes.Video); format.Codec.PrivateCodecData = trak.CodecPrivateData; IMediaTrack item = new GenericVideoTrack(format, this); MediaTracks.Add(item); } } base.InitializeForWriting(mediaTracksInfo); }
/// <summary> /// WriteSamples /// Overloaded method for writing slices directly. /// </summary> /// <param name="slices">A List of Sample(s)</param> /// <param name="codecType">Member of CodecTypes enum</param> public override void WriteSamples(IEnumerable <Slice> slices, CodecTypes codecType) { if (codecType == CodecTypes.Audio) { GenericAudioTrack audioTrack = (GenericAudioTrack)MediaTracks.First(tr => tr.Codec.CodecType == codecType); QBoxTrackFormat trackFormat = (QBoxTrackFormat)audioTrack.TrackFormat; trackFormat.WriteSamples(_binaryWriter, slices); } else if (codecType == CodecTypes.Video) { GenericVideoTrack videoTrack = (GenericVideoTrack)MediaTracks.First(tr => tr.Codec.CodecType == codecType); QBoxTrackFormat trackFormat = (QBoxTrackFormat)videoTrack.TrackFormat; trackFormat.WriteSamples(_binaryWriter, slices); } else { throw new Exception("WriteSamples: unknown codec type"); } }
static void ReadMetaData() { lock (MediaTracks) { MediaTracks.Clear(); string path = get_property_string("path"); if (File.Exists(path)) { using (MediaInfo mi = new MediaInfo(path)) { int count = mi.GetCount(MediaInfoStreamKind.Video); for (int i = 0; i < count; i++) { MediaTrack track = new MediaTrack(); Add(track, mi.GetVideo(i, "Format")); Add(track, mi.GetVideo(i, "Format_Profile")); Add(track, mi.GetVideo(i, "Width") + "x" + mi.GetVideo(i, "Height")); Add(track, mi.GetVideo(i, "FrameRate") + " FPS"); Add(track, mi.GetVideo(i, "Language/String")); Add(track, mi.GetVideo(i, "Forced") == "Yes" ? "Forced" : ""); Add(track, mi.GetVideo(i, "Default") == "Yes" ? "Default" : ""); Add(track, mi.GetVideo(i, "Title")); track.Text = "V: " + track.Text.Trim(' ', ','); track.Type = "v"; track.ID = i + 1; MediaTracks.Add(track); } count = mi.GetCount(MediaInfoStreamKind.Audio); for (int i = 0; i < count; i++) { MediaTrack track = new MediaTrack(); Add(track, mi.GetAudio(i, "Language/String")); Add(track, mi.GetAudio(i, "Format")); Add(track, mi.GetAudio(i, "Format_Profile")); Add(track, mi.GetAudio(i, "BitRate/String")); Add(track, mi.GetAudio(i, "Channel(s)/String")); Add(track, mi.GetAudio(i, "SamplingRate/String")); Add(track, mi.GetAudio(i, "Forced") == "Yes" ? "Forced" : ""); Add(track, mi.GetAudio(i, "Default") == "Yes" ? "Default" : ""); Add(track, mi.GetAudio(i, "Title")); track.Text = "A: " + track.Text.Trim(' ', ','); track.Type = "a"; track.ID = i + 1; MediaTracks.Add(track); } count = mi.GetCount(MediaInfoStreamKind.Text); for (int i = 0; i < count; i++) { MediaTrack track = new MediaTrack(); Add(track, mi.GetText(i, "Language/String")); Add(track, mi.GetText(i, "Format")); Add(track, mi.GetText(i, "Format_Profile")); Add(track, mi.GetText(i, "Forced") == "Yes" ? "Forced" : ""); Add(track, mi.GetText(i, "Default") == "Yes" ? "Default" : ""); Add(track, mi.GetText(i, "Title")); track.Text = "S: " + track.Text.Trim(' ', ','); track.Type = "s"; track.ID = i + 1; MediaTracks.Add(track); } count = get_property_int("edition-list/count"); for (int i = 0; i < count; i++) { MediaTrack track = new MediaTrack(); track.Text = "E: " + get_property_string($"edition-list/{i}/title"); track.Type = "e"; track.ID = i; MediaTracks.Add(track); } void Add(MediaTrack track, string val) { if (!string.IsNullOrEmpty(val) && !(track.Text != null && track.Text.Contains(val))) { track.Text += " " + val + ","; } } } } } lock (Chapters) { Chapters.Clear(); int count = get_property_int("chapter-list/count"); for (int x = 0; x < count; x++) { string text = get_property_string($"chapter-list/{x}/title"); double time = get_property_number($"chapter-list/{x}/time"); Chapters.Add(new KeyValuePair <string, double>(text, time)); } } }