protected override bool EnumerateStreams(bool forceRefresh) { //FIXME: TSReader only offers Audio in IAMStreamSelect, it would be cleaner to expose subs as well. bool refreshed = base.EnumerateStreams(forceRefresh); if (refreshed) { // If base class has refreshed the stream infos, then update the subtitle streams. ISubtitleStream subtitleStream = _sourceFilter as ISubtitleStream; int count = 0; if (subtitleStream != null) { _streamInfoSubtitles = new StreamInfoHandler(); subtitleStream.GetSubtitleStreamCount(ref count); if (count > 0) { StreamInfo subStream = new StreamInfo(null, NO_STREAM_INDEX, NO_SUBTITLES, 0); _streamInfoSubtitles.AddUnique(subStream); } for (int i = 0; i < count; ++i) { //FIXME: language should be passed back also as LCID SubtitleLanguage language = new SubtitleLanguage(); subtitleStream.GetSubtitleStreamLanguage(i, ref language); int lcid = LookupLcidFromName(language.lang); // Note: the "type" is no longer considered in MP1 code as well, so I guess DVBSub3 only supports Bitmap subs at all. string name = language.lang; StreamInfo subStream = new StreamInfo(null, i, name, lcid); _streamInfoSubtitles.AddUnique(subStream); } } } return(refreshed); }
private void SetPreferredSubtitle_intern(ref StreamInfoHandler subtitleStreams) { if (subtitleStreams == null) { return; } VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>() ?? new VideoSettings(); // first try to find a stream by it's exact LCID. StreamInfo streamInfo = subtitleStreams.FindStream(settings.PreferredSubtitleLanguage) ?? subtitleStreams.FindSimilarStream(settings.PreferredSubtitleStreamName); if (streamInfo == null || !settings.EnableSubtitles) { // auto-activate forced subtitles StreamInfo forced = subtitleStreams.FindForcedStream(); if (forced != null) { subtitleStreams.EnableStream(forced.Name); } else { subtitleStreams.EnableStream(NO_SUBTITLES); } } else { subtitleStreams.EnableStream(streamInfo.Name); } }
/// <summary> /// Release all COM object references to IAMStreamSelect instances. /// </summary> protected virtual void ReleaseStreamSelectors() { // Release all existing stream selector references if (_streamSelectors != null) { foreach (IAMStreamSelect streamSelector in _streamSelectors) { Marshal.ReleaseComObject(streamSelector); } } _streamSelectors = null; _streamInfoAudio = null; _streamInfoSubtitles = null; _streamInfoTitles = null; }
protected override void EnumerateChapters(bool forceRefresh) { StreamInfoHandler chapterInfo; lock (SyncObj) chapterInfo = _chapterInfo; if (chapterInfo != null && !forceRefresh) { return; } IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>(); for (int index = 0; index < playerContextManager.NumActivePlayerContexts; index++) { IPlayerContext playerContext = playerContextManager.GetPlayerContext(index); if (playerContext == null || playerContext.CurrentPlayer != this) { continue; } LiveTvMediaItem liveTvMediaItem = playerContext.CurrentMediaItem as LiveTvMediaItem; if (liveTvMediaItem == null) { continue; } _timeshiftContexes = liveTvMediaItem.TimeshiftContexes; chapterInfo = new StreamInfoHandler(); int i = 0; foreach (ITimeshiftContext timeshiftContext in _timeshiftContexes) { chapterInfo.AddUnique(new StreamInfo(null, i++, GetContextTitle(timeshiftContext), 0)); } } lock (SyncObj) _chapterInfo = chapterInfo; }
protected override bool EnumerateStreams(bool forceRefresh) { //FIXME: TSReader only offers Audio in IAMStreamSelect, it would be cleaner to expose subs as well. bool refreshed = base.EnumerateStreams(forceRefresh); if (refreshed) { // If base class has refreshed the stream infos, then update the subtitle streams. ISubtitleStream subtitleStream = _fileSource as ISubtitleStream; int count = 0; if (subtitleStream != null) { _streamInfoSubtitles = new StreamInfoHandler(); subtitleStream.GetSubtitleStreamCount(ref count); if (count > 0) { StreamInfo subStream = new StreamInfo(null, NO_STREAM_INDEX, NO_SUBTITLES, 0); _streamInfoSubtitles.AddUnique(subStream); } for (int i = 0; i < count; ++i) { //FIXME: language should be passed back also as LCID SubtitleLanguage language = new SubtitleLanguage(); int type = 0; subtitleStream.GetSubtitleStreamLanguage(i, ref language); subtitleStream.GetSubtitleStreamType(i, ref type); int lcid = LookupLcidFromName(language.lang); string name = type == 0 ? String.Format("{0} (DVB)", language.lang) : String.Format("{0} (Teletext)", language.lang); StreamInfo subStream = new StreamInfo(null, i, name, lcid); _streamInfoSubtitles.AddUnique(subStream); } } } return(refreshed); }
protected override bool EnumerateStreams(bool forceRefresh) { //FIXME: TSReader only offers Audio in IAMStreamSelect, it would be cleaner to expose subs as well. bool refreshed = base.EnumerateStreams(forceRefresh); if (refreshed) { // If base class has refreshed the stream infos, then update the subtitle streams. ISubtitleStream subtitleStream = _sourceFilter as ISubtitleStream; int count = 0; if (subtitleStream != null) { _streamInfoSubtitles = new StreamInfoHandler(); subtitleStream.GetSubtitleStreamCount(ref count); if (count > 0) { StreamInfo subStream = new StreamInfo(null, NO_STREAM_INDEX, NO_SUBTITLES, 0); _streamInfoSubtitles.AddUnique(subStream); } for (int i = 0; i < count; ++i) { //FIXME: language should be passed back also as LCID SubtitleLanguage language = new SubtitleLanguage(); int type = 0; subtitleStream.GetSubtitleStreamLanguage(i, ref language); subtitleStream.GetSubtitleStreamType(i, ref type); int lcid = LookupLcidFromName(language.lang); string name = type == 0 ? String.Format("{0} (DVB)", language.lang) : String.Format("{0} (Teletext)", language.lang); StreamInfo subStream = new StreamInfo(null, i, name, lcid); _streamInfoSubtitles.AddUnique(subStream); } } } return refreshed; }
protected override bool EnumerateStreams(bool forceRefresh) { if (_dvdInfo == null || !_initialized) { return(false); } StreamInfoHandler audioStreams; StreamInfoHandler subtitleStreams; lock (SyncObj) { audioStreams = _streamInfoAudio; subtitleStreams = _streamInfoSubtitles; } if (forceRefresh || audioStreams == null || subtitleStreams == null) { audioStreams = new StreamInfoHandler(); subtitleStreams = new StreamInfoHandler(); int streamsAvailable, currentStream; _dvdInfo.GetCurrentAudio(out streamsAvailable, out currentStream); for (int i = 0; i < streamsAvailable; ++i) { int audioLanguage; DvdAudioAttributes attr; _dvdInfo.GetAudioLanguage(i, out audioLanguage); _dvdInfo.GetAudioAttributes(i, out attr); int currentLCID = (audioLanguage & 0x3ff); string languageName = GetLanguageName(currentLCID); StringBuilder currentAudio = new StringBuilder(); currentAudio.AppendFormat("{0} ({1}/{2} ch/{3} KHz)", languageName, attr.AudioFormat, attr.bNumberOfChannels, (attr.dwFrequency / 1000)); switch (attr.LanguageExtension) { case DvdAudioLangExt.NotSpecified: case DvdAudioLangExt.Captions: break; case DvdAudioLangExt.VisuallyImpaired: case DvdAudioLangExt.DirectorComments1: case DvdAudioLangExt.DirectorComments2: currentAudio.AppendFormat(" ({0})", ServiceRegistration.Get <ILocalization>().ToString("[Playback." + attr.LanguageExtension + "]")); break; } audioStreams.AddUnique(new StreamInfo(null, i, currentAudio.ToString(), currentLCID)); } bool isDisabled; _dvdInfo.GetCurrentSubpicture(out streamsAvailable, out currentStream, out isDisabled); for (int i = 0; i < streamsAvailable; ++i) { DvdSubpictureAttributes attr; int iLanguage; _dvdInfo.GetSubpictureLanguage(i, out iLanguage); _dvdInfo.GetSubpictureAttributes(i, out attr); int currentLCID = (iLanguage & 0x3ff); string languageName = GetLanguageName(currentLCID); String localizationTag = attr.LanguageExtension.ToString(); String currentSubtitle = String.Format("{0} {1}", languageName, ServiceRegistration.Get <ILocalization>().ToString("[Playback." + localizationTag + "]") ?? localizationTag); subtitleStreams.AddUnique(new StreamInfo(null, i, currentSubtitle, currentLCID)); } lock (SyncObj) { _streamInfoAudio = audioStreams; _streamInfoSubtitles = subtitleStreams; } return(true); // refreshed } return(false); }
private void SetPreferredSubtitle_intern(ref StreamInfoHandler subtitleStreams) { if (subtitleStreams == null) return; VideoSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<VideoSettings>() ?? new VideoSettings(); // first try to find a stream by it's exact LCID. StreamInfo streamInfo = subtitleStreams.FindStream(settings.PreferredSubtitleLanguage) ?? subtitleStreams.FindSimilarStream(settings.PreferredSubtitleStreamName); if (streamInfo == null || !settings.EnableSubtitles) { // auto-activate forced subtitles StreamInfo forced = subtitleStreams.FindForcedStream(); if (forced != null) { subtitleStreams.EnableStream(forced.Name); } else { StreamInfo noSubtitleStream = subtitleStreams.FindSimilarStream(NO_SUBTITLES); if (noSubtitleStream != null) subtitleStreams.EnableStream(noSubtitleStream.Name); } } else subtitleStreams.EnableStream(streamInfo.Name); }
/// <summary> /// Release all COM object references to IAMStreamSelect instances. /// </summary> protected virtual void ReleaseStreamSelectors() { // Release all existing stream selector references if (_streamSelectors != null) foreach (IAMStreamSelect streamSelector in _streamSelectors) Marshal.ReleaseComObject(streamSelector); _streamSelectors = null; _streamInfoAudio = null; _streamInfoSubtitles = null; _streamInfoTitles = null; }
protected override bool EnumerateStreams(bool forceRefresh) { //FIXME: TSReader only offers Audio in IAMStreamSelect, it would be cleaner to expose subs as well. bool refreshed = base.EnumerateStreams(forceRefresh); if (refreshed) { // If base class has refreshed the stream infos, then update the subtitle streams. ISubtitleStream subtitleStream = _sourceFilter as ISubtitleStream; int count = 0; if (subtitleStream != null) { _streamInfoSubtitles = new StreamInfoHandler(); subtitleStream.GetSubtitleStreamCount(ref count); if (count > 0) { StreamInfo subStream = new StreamInfo(null, NO_STREAM_INDEX, NO_SUBTITLES, 0); _streamInfoSubtitles.AddUnique(subStream); } for (int i = 0; i < count; ++i) { //FIXME: language should be passed back also as LCID SubtitleLanguage language = new SubtitleLanguage(); subtitleStream.GetSubtitleStreamLanguage(i, ref language); int lcid = LookupLcidFromName(language.lang); // Note: the "type" is no longer considered in MP1 code as well, so I guess DVBSub3 only supports Bitmap subs at all. string name = language.lang; StreamInfo subStream = new StreamInfo(null, i, name, lcid); _streamInfoSubtitles.AddUnique(subStream); } } } return refreshed; }
/// <summary> /// Enumerates streams from video (audio, subtitles). /// </summary> /// <param name="forceRefresh">Force refresh</param> /// <returns><c>true</c> if information has been changed.</returns> protected virtual bool EnumerateStreams(bool forceRefresh) { if (_graphBuilder == null || !_initialized) { return(false); } StreamInfoHandler audioStreams; StreamInfoHandler subtitleStreams; StreamInfoHandler titleStreams; lock (SyncObj) { audioStreams = _streamInfoAudio; subtitleStreams = _streamInfoSubtitles; titleStreams = _streamInfoTitles; } if (forceRefresh || audioStreams == null || subtitleStreams == null || titleStreams == null) { audioStreams = new StreamInfoHandler(); subtitleStreams = new StreamInfoHandler(); titleStreams = new StreamInfoHandler(); // Release stream selectors ReleaseStreamSelectors(); _streamSelectors = FilterGraphTools.FindFiltersByInterface <IAMStreamSelect>(_graphBuilder); foreach (IAMStreamSelect streamSelector in _streamSelectors) { FilterInfo fi = FilterGraphTools.QueryFilterInfoAndFree(((IBaseFilter)streamSelector)); int streamCount; streamSelector.Count(out streamCount); for (int i = 0; i < streamCount; ++i) { AMMediaType mediaType; AMStreamSelectInfoFlags selectInfoFlags; int groupNumber, lcid; string name; object pppunk, ppobject; streamSelector.Info(i, out mediaType, out selectInfoFlags, out lcid, out groupNumber, out name, out pppunk, out ppobject); // If stream does not contain a LCID, try a lookup from stream name. if (lcid == 0) { lcid = LookupLcidFromName(name); } ServiceRegistration.Get <ILogger>().Debug("Stream {4}|{0}: MajorType {1}; Name {2}; PWDGroup: {3}; LCID: {5}", i, mediaType.majorType, name, groupNumber, fi.achName, lcid); StreamInfo currentStream = new StreamInfo(streamSelector, i, name, lcid); switch ((StreamGroup)groupNumber) { case StreamGroup.Video: break; case StreamGroup.Audio: if (mediaType.majorType == MediaType.AnalogAudio || mediaType.majorType == MediaType.Audio) { String streamName = name.Trim(); String streamAppendix; if (!CodecHandler.MediaSubTypes.TryGetValue(mediaType.subType, out streamAppendix)) { streamAppendix = string.Empty; } // if audio information is available via WaveEx format, query the channel count if (mediaType.formatType == FormatType.WaveEx && mediaType.formatPtr != IntPtr.Zero) { WaveFormatEx waveFormatEx = (WaveFormatEx)Marshal.PtrToStructure(mediaType.formatPtr, typeof(WaveFormatEx)); currentStream.ChannelCount = waveFormatEx.nChannels; streamAppendix = String.Format("{0} {1}ch", streamAppendix, currentStream.ChannelCount); } if (!string.IsNullOrEmpty(streamAppendix)) { currentStream.Name = String.Format("{0} ({1})", streamName, streamAppendix); } audioStreams.AddUnique(currentStream); } break; case StreamGroup.Subtitle: case StreamGroup.DirectVobSubtitle: subtitleStreams.AddUnique(currentStream, true); break; case StreamGroup.MatroskaEdition: // This is a MKV Edition handled by Haali splitter titleStreams.AddUnique(currentStream, true); break; } // Free MediaType and references FilterGraphTools.FreeAMMediaType(mediaType); } } lock (SyncObj) { _streamInfoAudio = audioStreams; _streamInfoSubtitles = subtitleStreams; _streamInfoTitles = titleStreams; } return(true); } return(false); }
protected override bool EnumerateStreams(bool forceRefresh) { if (_dvdInfo == null || !_initialized) return false; StreamInfoHandler audioStreams; StreamInfoHandler subtitleStreams; lock (SyncObj) { audioStreams = _streamInfoAudio; subtitleStreams = _streamInfoSubtitles; } if (forceRefresh || audioStreams == null || subtitleStreams == null) { audioStreams = new StreamInfoHandler(); subtitleStreams = new StreamInfoHandler(); int streamsAvailable, currentStream; _dvdInfo.GetCurrentAudio(out streamsAvailable, out currentStream); for (int i = 0; i < streamsAvailable; ++i) { int audioLanguage; DvdAudioAttributes attr; _dvdInfo.GetAudioLanguage(i, out audioLanguage); _dvdInfo.GetAudioAttributes(i, out attr); int currentLCID = (audioLanguage & 0x3ff); string languageName = GetLanguageName(currentLCID); StringBuilder currentAudio = new StringBuilder(); currentAudio.AppendFormat("{0} ({1}/{2} ch/{3} KHz)", languageName, attr.AudioFormat, attr.bNumberOfChannels, (attr.dwFrequency / 1000)); switch (attr.LanguageExtension) { case DvdAudioLangExt.NotSpecified: case DvdAudioLangExt.Captions: break; case DvdAudioLangExt.VisuallyImpaired: case DvdAudioLangExt.DirectorComments1: case DvdAudioLangExt.DirectorComments2: currentAudio.AppendFormat(" ({0})", ServiceRegistration.Get<ILocalization>().ToString("[Playback." + attr.LanguageExtension + "]")); break; } audioStreams.AddUnique(new StreamInfo(null, i, currentAudio.ToString(), currentLCID)); } bool isDisabled; _dvdInfo.GetCurrentSubpicture(out streamsAvailable, out currentStream, out isDisabled); for (int i = 0; i < streamsAvailable; ++i) { DvdSubpictureAttributes attr; int iLanguage; _dvdInfo.GetSubpictureLanguage(i, out iLanguage); _dvdInfo.GetSubpictureAttributes(i, out attr); int currentLCID = (iLanguage & 0x3ff); string languageName = GetLanguageName(currentLCID); String localizationTag = attr.LanguageExtension.ToString(); String currentSubtitle = String.Format("{0} {1}", languageName, ServiceRegistration.Get<ILocalization>().ToString("[Playback." + localizationTag + "]") ?? localizationTag); subtitleStreams.AddUnique(new StreamInfo(null, i, currentSubtitle, currentLCID)); } lock (SyncObj) { _streamInfoAudio = audioStreams; _streamInfoSubtitles = subtitleStreams; } return true; // refreshed } return false; }
/// <summary> /// Enumerates streams from video (audio, subtitles). /// </summary> /// <param name="forceRefresh">Force refresh</param> /// <returns><c>true</c> if information has been changed.</returns> protected virtual bool EnumerateStreams(bool forceRefresh) { if (_graphBuilder == null || !_initialized) return false; StreamInfoHandler audioStreams; StreamInfoHandler subtitleStreams; StreamInfoHandler titleStreams; lock (SyncObj) { audioStreams = _streamInfoAudio; subtitleStreams = _streamInfoSubtitles; titleStreams = _streamInfoTitles; } if (forceRefresh || audioStreams == null || subtitleStreams == null || titleStreams == null) { audioStreams = new StreamInfoHandler(); subtitleStreams = new StreamInfoHandler(); titleStreams = new StreamInfoHandler(); // Release stream selectors ReleaseStreamSelectors(); _streamSelectors = FilterGraphTools.FindFiltersByInterface<IAMStreamSelect>(_graphBuilder); foreach (IAMStreamSelect streamSelector in _streamSelectors) { FilterInfo fi = FilterGraphTools.QueryFilterInfoAndFree(((IBaseFilter) streamSelector)); int streamCount; streamSelector.Count(out streamCount); for (int i = 0; i < streamCount; ++i) { AMMediaType mediaType; AMStreamSelectInfoFlags selectInfoFlags; int groupNumber, lcid; string name; object pppunk, ppobject; streamSelector.Info(i, out mediaType, out selectInfoFlags, out lcid, out groupNumber, out name, out pppunk, out ppobject); // If stream does not contain a LCID, try a lookup from stream name. if (lcid == 0) lcid = LookupLcidFromName(name); ServiceRegistration.Get<ILogger>().Debug("Stream {4}|{0}: MajorType {1}; Name {2}; PWDGroup: {3}; LCID: {5}", i, mediaType.majorType, name, groupNumber, fi.achName, lcid); StreamInfo currentStream = new StreamInfo(streamSelector, i, name, lcid); switch ((StreamGroup) groupNumber) { case StreamGroup.Video: break; case StreamGroup.Audio: if (mediaType.majorType == MediaType.AnalogAudio || mediaType.majorType == MediaType.Audio) { String streamName = name.Trim(); String streamAppendix; if (!CodecHandler.MediaSubTypes.TryGetValue(mediaType.subType, out streamAppendix)) streamAppendix = string.Empty; // if audio information is available via WaveEx format, query the channel count if (mediaType.formatType == FormatType.WaveEx && mediaType.formatPtr != IntPtr.Zero) { WaveFormatEx waveFormatEx = (WaveFormatEx) Marshal.PtrToStructure(mediaType.formatPtr, typeof(WaveFormatEx)); currentStream.ChannelCount = waveFormatEx.nChannels; streamAppendix = String.Format("{0} {1}ch", streamAppendix, currentStream.ChannelCount); } if (!string.IsNullOrEmpty(streamAppendix)) currentStream.Name = String.Format("{0} ({1})", streamName, streamAppendix); audioStreams.AddUnique(currentStream); } break; case StreamGroup.Subtitle: case StreamGroup.DirectVobSubtitle: subtitleStreams.AddUnique(currentStream, true); break; case StreamGroup.MatroskaEdition: // This is a MKV Edition handled by Haali splitter titleStreams.AddUnique(currentStream, true); break; } // Free MediaType and references FilterGraphTools.FreeAMMediaType(mediaType); } } lock (SyncObj) { _streamInfoAudio = audioStreams; _streamInfoSubtitles = subtitleStreams; _streamInfoTitles = titleStreams; } return true; } return false; }
private void SetPreferedAudio_intern(ref StreamInfoHandler audioStreams, bool useFirstAsDefault) { if (audioStreams == null || audioStreams.Count == 0) { return; } VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>(); // When multiple streams are available, we select the stream by channel count preference (PreferMultiChannelAudio). Predicate <StreamInfo> channelCountPreference; if (settings.PreferMultiChannelAudio) { channelCountPreference = (a => a.ChannelCount > 2); // Prefer more then stereo (usually 6ch) } else { channelCountPreference = (a => a.ChannelCount <= 2); // Stereo or even mono } // Check if there are multiple audio streams for the PreferredAudioLanguage. int preferredAudioLCID = settings.PreferredAudioLanguage; List <StreamInfo> streamsForLCID = audioStreams.ToList().FindAll(a => a.LCID == preferredAudioLCID && a.LCID != 0); int count = streamsForLCID.Count; if (count > 0) { // If we have only one choice, select this stream. if (count == 1) { audioStreams.EnableStream(streamsForLCID[0].Name); return; } StreamInfo bestChannelStream = streamsForLCID.Find(channelCountPreference); if (bestChannelStream != null) { audioStreams.EnableStream(bestChannelStream.Name); return; } } // If we did not find matching languages by LCID no try to find them by name. StreamInfo streamInfo = null; if (preferredAudioLCID != 0) { CultureInfo ci = new CultureInfo(preferredAudioLCID); string languagePart = ci.EnglishName.Substring(0, ci.EnglishName.IndexOf("(") - 1); streamInfo = audioStreams.FindSimilarStream(languagePart); } // Still no matching languages? Then select the first that matches channelCountPreference. if (streamInfo == null) { streamInfo = audioStreams.ToList().Find(channelCountPreference); } if (streamInfo != null) { audioStreams.EnableStream(streamInfo.Name); } else if (useFirstAsDefault) { audioStreams.EnableStream(audioStreams[0].Name); } }
private void SetPreferedAudio_intern(ref StreamInfoHandler audioStreams, bool useFirstAsDefault) { if (audioStreams == null || audioStreams.Count == 0) return; VideoSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<VideoSettings>(); // When multiple streams are available, we select the stream by channel count preference (PreferMultiChannelAudio). Predicate<StreamInfo> channelCountPreference; if (settings.PreferMultiChannelAudio) channelCountPreference = (a => a.ChannelCount > 2); // Prefer more then stereo (usually 6ch) else channelCountPreference = (a => a.ChannelCount <= 2); // Stereo or even mono // Check if there are multiple audio streams for the PreferredAudioLanguage. int preferredAudioLCID = settings.PreferredAudioLanguage; List<StreamInfo> streamsForLCID = audioStreams.ToList().FindAll(a => a.LCID == preferredAudioLCID && a.LCID != 0); int count = streamsForLCID.Count; if (count > 0) { // If we have only one choice, select this stream. if (count == 1) { audioStreams.EnableStream(streamsForLCID[0].Name); return; } StreamInfo bestChannelStream = streamsForLCID.Find(channelCountPreference); if (bestChannelStream != null) { audioStreams.EnableStream(bestChannelStream.Name); return; } } // If we did not find matching languages by LCID no try to find them by name. StreamInfo streamInfo = null; if (preferredAudioLCID != 0) { try { CultureInfo ci = new CultureInfo(preferredAudioLCID); string languagePart = ci.EnglishName.Substring(0, ci.EnglishName.IndexOf("(") - 1); streamInfo = audioStreams.FindSimilarStream(languagePart); } catch { } } // Still no matching languages? Then select the first that matches channelCountPreference. if (streamInfo == null) streamInfo = audioStreams.ToList().Find(channelCountPreference); if (streamInfo != null) audioStreams.EnableStream(streamInfo.Name); else if (useFirstAsDefault) audioStreams.EnableStream(audioStreams[0].Name); }
/// <summary> /// Enumerates streams from video (audio, subtitles). /// </summary> /// <param name="forceRefresh">Force refresh</param> /// <returns><c>true</c> if information has been changed.</returns> protected virtual bool EnumerateStreams(bool forceRefresh) { if (_graphBuilder == null || !_initialized) { return(false); } StreamInfoHandler audioStreams; StreamInfoHandler subtitleStreams; StreamInfoHandler titleStreams; lock (SyncObj) { audioStreams = _streamInfoAudio; subtitleStreams = _streamInfoSubtitles; titleStreams = _streamInfoTitles; } if (forceRefresh || audioStreams == null || subtitleStreams == null || titleStreams == null) { audioStreams = new StreamInfoHandler(); subtitleStreams = new StreamInfoHandler(); titleStreams = new StreamInfoHandler(); // Release stream selectors ReleaseStreamSelectors(); _streamSelectors = FilterGraphTools.FindFiltersByInterface <IAMStreamSelect>(_graphBuilder); foreach (IAMStreamSelect streamSelector in _streamSelectors) { FilterInfo fi = FilterGraphTools.QueryFilterInfoAndFree(((IBaseFilter)streamSelector)); int streamCount; streamSelector.Count(out streamCount); for (int i = 0; i < streamCount; ++i) { IntPtr pp_punk = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_object = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_name = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_groupNumber = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_lcid = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_selectInfoFlags = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_mediaType = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); int hr = streamSelector.Info(i, pp_mediaType, pp_selectInfoFlags, pp_lcid, pp_groupNumber, pp_name, pp_punk, pp_object); new HRESULT(hr).Throw(); // We get a pointer to pointer for a structure. AMMediaType mediaType = (AMMediaType)Marshal.PtrToStructure(Marshal.ReadIntPtr(pp_mediaType), typeof(AMMediaType)); int groupNumber = Marshal.ReadInt32(pp_groupNumber); int lcid = Marshal.ReadInt32(pp_lcid); string name = Marshal.PtrToStringAuto(Marshal.ReadIntPtr(pp_name)); // If stream does not contain a LCID, try a lookup from stream name. if (lcid == 0) { lcid = LookupLcidFromName(name); } ServiceRegistration.Get <ILogger>().Debug("Stream {4}|{0}: MajorType {1}; Name {2}; PWDGroup: {3}; LCID: {5}", i, mediaType.majorType, name, groupNumber, fi.achName, lcid); StreamInfo currentStream = new StreamInfo(streamSelector, i, name, lcid); switch ((StreamGroup)groupNumber) { case StreamGroup.Video: break; case StreamGroup.Audio: if (mediaType.majorType == MediaType.AnalogAudio || mediaType.majorType == MediaType.Audio) { String streamName = name.Trim(); String streamAppendix; if (!CodecHandler.MediaSubTypes.TryGetValue(mediaType.subType, out streamAppendix)) { streamAppendix = string.Empty; } // if audio information is available via WaveEx format, query the channel count if (mediaType.formatType == FormatType.WaveEx && mediaType.formatPtr != IntPtr.Zero) { WaveFormatEx waveFormatEx = (WaveFormatEx)Marshal.PtrToStructure(mediaType.formatPtr, typeof(WaveFormatEx)); currentStream.ChannelCount = waveFormatEx.nChannels; streamAppendix = String.Format("{0} {1}ch", streamAppendix, currentStream.ChannelCount); } if (!string.IsNullOrEmpty(streamAppendix)) { currentStream.Name = String.Format("{0} ({1})", streamName, streamAppendix); } audioStreams.AddUnique(currentStream); } break; case StreamGroup.Subtitle: { currentStream.IsAutoSubtitle = currentStream.Name.ToLowerInvariant().Contains(FORCED_SUBTITLES); subtitleStreams.AddUnique(currentStream, true); } break; case StreamGroup.VsFilterSubtitle: case StreamGroup.VsFilterSubtitleOptions: case StreamGroup.DirectVobSubtitle: subtitleStreams.AddUnique(currentStream, true); break; case StreamGroup.MatroskaEdition: // This is a MKV Edition handled by Haali splitter titleStreams.AddUnique(currentStream, true); break; } // Free MediaType and references DsUtils.FreeAMMediaType(mediaType); Marshal.FreeHGlobal(pp_punk); Marshal.FreeHGlobal(pp_object); Marshal.FreeHGlobal(pp_name); Marshal.FreeHGlobal(pp_groupNumber); Marshal.FreeHGlobal(pp_lcid); Marshal.FreeHGlobal(pp_selectInfoFlags); Marshal.FreeHGlobal(pp_mediaType); } } SetPreferedAudio_intern(ref audioStreams, false); SetPreferredSubtitle_intern(ref subtitleStreams); lock (SyncObj) { _streamInfoAudio = audioStreams; _streamInfoSubtitles = subtitleStreams; _streamInfoTitles = titleStreams; } return(true); } return(false); }
/// <summary> /// Enumerates streams from video (audio, subtitles). /// </summary> /// <param name="forceRefresh">Force refresh</param> /// <returns><c>true</c> if information has been changed.</returns> protected virtual bool EnumerateStreams(bool forceRefresh) { if (_graphBuilder == null || !_initialized) return false; StreamInfoHandler audioStreams; StreamInfoHandler subtitleStreams; StreamInfoHandler titleStreams; lock (SyncObj) { audioStreams = _streamInfoAudio; subtitleStreams = _streamInfoSubtitles; titleStreams = _streamInfoTitles; } if (forceRefresh || audioStreams == null || subtitleStreams == null || titleStreams == null) { audioStreams = new StreamInfoHandler(); subtitleStreams = new StreamInfoHandler(); titleStreams = new StreamInfoHandler(); // Release stream selectors ReleaseStreamSelectors(); _streamSelectors = FilterGraphTools.FindFiltersByInterface<IAMStreamSelect>(_graphBuilder); foreach (IAMStreamSelect streamSelector in _streamSelectors) { FilterInfo fi = FilterGraphTools.QueryFilterInfoAndFree(((IBaseFilter)streamSelector)); int streamCount; streamSelector.Count(out streamCount); for (int i = 0; i < streamCount; ++i) { IntPtr pp_punk = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_object = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_name = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_groupNumber = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_lcid = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_selectInfoFlags = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); IntPtr pp_mediaType = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); int hr = streamSelector.Info(i, pp_mediaType, pp_selectInfoFlags, pp_lcid, pp_groupNumber, pp_name, pp_punk, pp_object); new HRESULT(hr).Throw(); // We get a pointer to pointer for a structure. AMMediaType mediaType = (AMMediaType)Marshal.PtrToStructure(Marshal.ReadIntPtr(pp_mediaType), typeof(AMMediaType)); if (mediaType == null) { ServiceRegistration.Get<ILogger>().Warn("Stream {0}: Could not determine MediaType!", i); continue; } int groupNumber = Marshal.ReadInt32(pp_groupNumber); int lcid = Marshal.ReadInt32(pp_lcid); string name = Marshal.PtrToStringAuto(Marshal.ReadIntPtr(pp_name)); // If stream does not contain a LCID, try a lookup from stream name. if (lcid == 0) lcid = LookupLcidFromName(name); ServiceRegistration.Get<ILogger>().Debug("Stream {4}|{0}: MajorType {1}; Name {2}; PWDGroup: {3}; LCID: {5}", i, mediaType.majorType, name, groupNumber, fi.achName, lcid); StreamInfo currentStream = new StreamInfo(streamSelector, i, name, lcid); switch ((StreamGroup)groupNumber) { case StreamGroup.Video: break; case StreamGroup.Audio: if (mediaType.majorType == MediaType.AnalogAudio || mediaType.majorType == MediaType.Audio) { String streamName = name.Trim(); String streamAppendix; if (!CodecHandler.MediaSubTypes.TryGetValue(mediaType.subType, out streamAppendix)) streamAppendix = string.Empty; // if audio information is available via WaveEx format, query the channel count if (mediaType.formatType == FormatType.WaveEx && mediaType.formatPtr != IntPtr.Zero) { WaveFormatEx waveFormatEx = (WaveFormatEx)Marshal.PtrToStructure(mediaType.formatPtr, typeof(WaveFormatEx)); currentStream.ChannelCount = waveFormatEx.nChannels; streamAppendix = String.Format("{0} {1}ch", streamAppendix, currentStream.ChannelCount); } if (!string.IsNullOrEmpty(streamAppendix)) currentStream.Name = String.Format("{0} ({1})", streamName, streamAppendix); audioStreams.AddUnique(currentStream); } break; case StreamGroup.Subtitle: { currentStream.IsAutoSubtitle = currentStream.Name.ToLowerInvariant().Contains(FORCED_SUBTITLES); subtitleStreams.AddUnique(currentStream, true); } break; case StreamGroup.VsFilterSubtitle: case StreamGroup.VsFilterSubtitleOptions: case StreamGroup.DirectVobSubtitle: subtitleStreams.AddUnique(currentStream, true); break; case StreamGroup.MatroskaEdition: // This is a MKV Edition handled by Haali splitter titleStreams.AddUnique(currentStream, true); break; } // Free MediaType and references DsUtils.FreeAMMediaType(mediaType); Marshal.FreeHGlobal(pp_punk); Marshal.FreeHGlobal(pp_object); Marshal.FreeHGlobal(pp_name); Marshal.FreeHGlobal(pp_groupNumber); Marshal.FreeHGlobal(pp_lcid); Marshal.FreeHGlobal(pp_selectInfoFlags); Marshal.FreeHGlobal(pp_mediaType); } } SetPreferedAudio_intern(ref audioStreams, false); SetPreferredSubtitle_intern(ref subtitleStreams); lock (SyncObj) { _streamInfoAudio = audioStreams; _streamInfoSubtitles = subtitleStreams; _streamInfoTitles = titleStreams; } return true; } return false; }
protected override void EnumerateChapters(bool forceRefresh) { StreamInfoHandler chapterInfo; lock (SyncObj) chapterInfo = _chapterInfo; if (chapterInfo != null && !forceRefresh) return; IPlayerContextManager playerContextManager = ServiceRegistration.Get<IPlayerContextManager>(); for (int index = 0; index < playerContextManager.NumActivePlayerContexts; index++) { IPlayerContext playerContext = playerContextManager.GetPlayerContext(index); if (playerContext == null || playerContext.CurrentPlayer != this) continue; LiveTvMediaItem liveTvMediaItem = playerContext.CurrentMediaItem as LiveTvMediaItem; if (liveTvMediaItem == null) continue; _timeshiftContexes = liveTvMediaItem.TimeshiftContexes; chapterInfo = new StreamInfoHandler(); int i = 0; foreach (ITimeshiftContext timeshiftContext in _timeshiftContexes) chapterInfo.AddUnique(new StreamInfo(null, i++, GetContextTitle(timeshiftContext), 0)); } lock (SyncObj) _chapterInfo = chapterInfo; }
private void EnumerateChapters() { _chapterInfo = new StreamInfoHandler(); IPlayerContextManager playerContextManager = ServiceRegistration.Get<IPlayerContextManager>(); for (int index = 0; index < playerContextManager.NumActivePlayerContexts; index++) { IPlayerContext playerContext = playerContextManager.GetPlayerContext(index); if (playerContext == null || playerContext.CurrentPlayer != this) continue; LiveTvMediaItem liveTvMediaItem = playerContext.CurrentMediaItem as LiveTvMediaItem; if (liveTvMediaItem == null) continue; _timeshiftContexes = liveTvMediaItem.TimeshiftContexes; int i = 0; foreach (ITimeshiftContext timeshiftContext in _timeshiftContexes) { string program = timeshiftContext.Program != null ? timeshiftContext.Program.Title : ServiceRegistration.Get<ILocalization>().ToString("[SlimTvClient.NoProgram]"); _chapterInfo.AddUnique(new StreamInfo(null, i++, string.Format("{0}: {1}", timeshiftContext.Channel.Name, program), 0)); } } }