Exemple #1
0
        private static async Task <bool> SendSegmentAsync(string fileName, IOwinContext context, StreamItem streamItem)
        {
            if (!string.IsNullOrEmpty(fileName) && streamItem.StreamContext is TranscodeContext tc)
            {
                using (await streamItem.RequestBusyLockAsync(SendDataCancellation.Token))
                {
                    var segment = await MediaConverter.GetSegmentFileAsync((VideoTranscoding)streamItem.TranscoderObject.TranscodingParameter, tc, fileName);

                    if (segment != null)
                    {
                        if (segment.Value.ContainerEnum is VideoContainer)
                        {
                            VideoTranscoding video    = (VideoTranscoding)streamItem.TranscoderObject.TranscodingParameter;
                            List <string>    profiles = ProfileMime.ResolveVideoProfile((VideoContainer)segment.Value.ContainerEnum, video.TargetVideoCodec, video.TargetAudioCodec, EncodingProfile.Unknown, 0, 0, 0, 0, 0, 0, Timestamp.None);
                            string           mime     = "video/unknown";
                            ProfileMime.FindCompatibleMime(streamItem.Profile, profiles, ref mime);
                            context.Response.ContentType = mime;
                        }
                        else if (segment.Value.ContainerEnum is SubtitleCodec)
                        {
                            context.Response.ContentType = SubtitleHelper.GetSubtitleMime((SubtitleCodec)segment.Value.ContainerEnum);
                        }
                        bool onlyHeaders = context.Request.Method == "HEAD" || context.Response.StatusCode == (int)HttpStatusCode.NotModified;
                        Logger.Debug("RetrieveStream: Sending file header only: {0}", onlyHeaders.ToString());

                        await SendWholeFileAsync(context, segment.Value.FileData, onlyHeaders);

                        // Close the Stream so that FFMpeg can replace the playlist file
                        segment.Value.FileData.Dispose();
                        return(true);
                    }
                }
            }
            return(false);
        }