private ActionResult GenerateHttpLiveStream(WebMediaType type, string itemId, int fileindex, WebTranscoderProfile profile, int starttime, string continuationId) { string identifier = ActuallyStartHttpLiveStream(type, itemId, fileindex, profile, starttime, continuationId); if (identifier == null) return new HttpStatusCodeResult((int)HttpStatusCode.InternalServerError); // Return the actual file contents GetStreamControl(type).AuthorizeRemoteHostForStreaming(HttpContext.Request.UserHostAddress); if (GetStreamMode() == StreamType.Direct) { Log.Debug("HLS: Using Direct streaming mode and redirecting to playlist at {0}", HttpLiveUrls[identifier]); return Redirect(HttpLiveUrls[identifier]); } else { ProxyHttpLiveIndex(identifier, HttpLiveUrls[identifier]); return new EmptyResult(); } }
// // Player protected ActionResult CreatePlayer(IWebStreamingService streamControl, PlayerViewModel model, List<StreamTarget> targets, WebTranscoderProfile profile, bool album) { // save stream request if (!PlayerOpenedBy.Contains(Request.UserHostAddress)) { PlayerOpenedBy.Add(Request.UserHostAddress); } // get view properties VideoPlayer player = targets.First(x => profile.Targets.Contains(x.Name)).Player; string viewName = Enum.GetName(typeof(VideoPlayer), player) + (album ? "Album" : "") + "Player"; // generate view var supportedTargets = Configuration.StreamingPlatforms.GetValidTargetsForUserAgent(Request.UserAgent).Intersect(targets.Select(x => x.Name)); model.Transcoders = ProfileModel.GetProfilesForTargets(streamControl, supportedTargets).Select(x => x.Name); model.Transcoder = profile.Name; model.TranscoderProfile = profile; model.Player = player; model.PlayerViewName = viewName; Log.Debug("Created player with size={0} view={1} transcoder={2} url={3}", model.Size, viewName, profile.Name, model.URL); return PartialView("Player", model); }
private string ActuallyStartHttpLiveStream(WebMediaType type, string itemId, int fileindex, WebTranscoderProfile profile, int starttime, string continuationId) { // Get identifier and continuationId continuationId = continuationId ?? "hls-" + randomGenerator.Next(10000, 99999).ToString(); bool alreadyRunning = RunningStreams.ContainsKey(continuationId); string identifier = alreadyRunning ? RunningStreams[continuationId] : "webmediaportal-" + randomGenerator.Next(10000, 99999); Log.Debug("HLS: Requested stream start for continuationId={0}; running={1}; identifier={2}", continuationId, alreadyRunning, identifier); // We only need to start the stream if this is the first request for this file string url; if (!alreadyRunning) { Log.Debug("HLS: Starting stream type={0}; itemId={1}; offset={2}; profile={3}; starttime={4}; continuationId={5}; identifier={6}", type, itemId, fileindex, profile.Name, starttime, continuationId, identifier); Log.Debug("HLS: Stream is for user {0} from host {1}, has identifier {2} and timeout {3}s", HttpContext.User.Identity.Name, Request.UserHostAddress, identifier, STREAM_TIMEOUT_HTTPLIVE); // Start the stream string clientDescription = String.Format("WebMediaPortal (user {0})", HttpContext.User.Identity.Name); using (var scope = WCFClient.EnterOperationScope(GetStreamControl(type))) { WCFClient.SetHeader("forwardedFor", HttpContext.Request.UserHostAddress); if (!GetStreamControl(type).InitStream((WebMediaType)type, GetProvider(type), itemId, fileindex, clientDescription, identifier, STREAM_TIMEOUT_HTTPLIVE)) { Log.Error("HLS: InitStream failed"); return null; } } // Get stream URL url = GetStreamControl(type).StartStream(identifier, profile.Name, starttime); if (String.IsNullOrEmpty(url)) { Log.Error("HLS: StartStream failed"); return null; } Log.Debug("HLS: Started stream successfully at {0}", url); RunningStreams[continuationId] = identifier; HttpLiveUrls[identifier] = url; } return identifier; }
// // Player protected ActionResult CreatePlayer(IWebStreamingService streamControl, PlayerViewModel model, List<StreamTarget> targets, WebTranscoderProfile profile, bool album) { // save stream request if (!PlayerOpenedBy.Contains(Request.UserHostAddress)) { PlayerOpenedBy.Add(Request.UserHostAddress); } // get all transcoder profiles List<string> profiles = new List<string>(); foreach (StreamTarget target in targets) { if (target.ValidForRequest(Request)) profiles = profiles.Concat(streamControl.GetTranscoderProfilesForTarget(target.Name).Select(x => x.Name)).Distinct().ToList(); } // get view properties VideoPlayer player = targets.First(x => profile.Targets.Contains(x.Name)).Player; string viewName = Enum.GetName(typeof(VideoPlayer), player) + (album ? "Album" : "") + "Player"; // generate view model.Transcoders = profiles; model.Transcoder = profile.Name; model.TranscoderProfile = profile; model.Player = player; model.PlayerViewName = viewName; Log.Debug("Created player with size={0} view={1} transcoder={2} url={3}", model.Size, viewName, profile.Name, model.URL); return PartialView("Player", model); }