Ejemplo n.º 1
0
        /// <summary>
        /// Does the preparation to start a stream
        /// </summary>
        internal static async Task <StreamContext> StartOriginalFileStreamingAsync(string identifier)
        {
            if (STREAM_ITEMS.TryGetValue(identifier, out var currentStreamItem))
            {
                using (await currentStreamItem.RequestBusyLockAsync())
                {
                    if (currentStreamItem.IsActive)
                    {
                        currentStreamItem.TranscoderObject?.StopStreaming();
                        if (currentStreamItem.StreamContext is TranscodeContext context)
                        {
                            context.UpdateStreamUse(false);
                        }
                        else if (currentStreamItem.StreamContext != null)
                        {
                            currentStreamItem.StreamContext.Dispose();
                            currentStreamItem.StreamContext = null;
                        }
                    }

                    IMediaAccessor           mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();
                    List <IResourceAccessor> resources     = new List <IResourceAccessor>();
                    foreach (var res in currentStreamItem.TranscoderObject.Metadata.FilePaths)
                    {
                        var path = ResourcePath.Deserialize(res.Value);
                        if (mediaAccessor.LocalResourceProviders.TryGetValue(path.BasePathSegment.ProviderId, out var resourceProvider) &&
                            resourceProvider is IBaseResourceProvider baseProvider && baseProvider.TryCreateResourceAccessor(res.Value, out var accessor))
                        {
                            using (accessor)
                            {
                                if (accessor is IFileSystemResourceAccessor)
                                {
                                    currentStreamItem.TranscoderObject.StartStreaming();
                                    currentStreamItem.StreamContext = await MediaConverter.GetFileStreamAsync(path);

                                    return(currentStreamItem.StreamContext);
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Does the preparation to start a stream
        /// </summary>
        internal static async Task <StreamContext> StartOriginalFileStreamingAsync(EndPointSettings client, StreamItem newStreamItem)
        {
            if (STREAM_ITEMS.TryAdd(client.ClientId, newStreamItem))
            {
                await newStreamItem.BusyLock.WaitAsync();

                try
                {
                    IMediaAccessor           mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();
                    List <IResourceAccessor> resources     = new List <IResourceAccessor>();
                    foreach (var res in newStreamItem.TranscoderObject.Metadata.FilePaths)
                    {
                        var path = ResourcePath.Deserialize(res.Value);
                        if (mediaAccessor.LocalResourceProviders.TryGetValue(path.BasePathSegment.ProviderId, out var resourceProvider) &&
                            resourceProvider is IBaseResourceProvider baseProvider && baseProvider.TryCreateResourceAccessor(path.BasePathSegment.Path, out var accessor))
                        {
                            using (accessor)
                            {
                                if (accessor is IFileSystemResourceAccessor)
                                {
                                    newStreamItem.TranscoderObject.StartStreaming();
                                    newStreamItem.StreamContext = await MediaConverter.GetFileStreamAsync(path);

                                    return(newStreamItem.StreamContext);
                                }
                            }
                        }
                    }
                }
                finally
                {
                    newStreamItem.BusyLock.Release();
                }
            }

            return(null);
        }