示例#1
0
文件: Media.cs 项目: NU11B0T/SkyMedia
        private static MediaStream GetMediaStream(string authToken, MediaClient mediaClient, StreamingLocator streamingLocator)
        {
            MediaStream mediaStream  = null;
            string      streamingUrl = mediaClient.GetStreamingUrl(streamingLocator, null);

            if (!string.IsNullOrEmpty(streamingUrl))
            {
                Asset        asset        = mediaClient.GetEntity <Asset>(MediaEntity.Asset, streamingLocator.AssetName);
                MediaInsight mediaInsight = GetMediaInsight(mediaClient, asset);
                authToken   = !string.IsNullOrEmpty(mediaInsight.ViewToken) ? mediaInsight.ViewToken : string.Concat(Constant.AuthIntegration.AuthScheme, authToken);
                mediaStream = new MediaStream()
                {
                    Name       = string.IsNullOrEmpty(streamingLocator.Name) ? asset.Name : streamingLocator.Name,
                    Url        = streamingUrl,
                    Poster     = mediaClient.GetDownloadUrl(asset.Name, Constant.Media.Thumbnail.FileName),
                    Tracks     = Track.GetMediaTracks(mediaClient, asset),
                    Insight    = mediaInsight,
                    Protection = mediaClient.GetStreamProtection(authToken, mediaClient, streamingLocator)
                };
                List <string> assetFilterNames = new List <string>();
                AssetFilter[] assetFilters     = mediaClient.GetAllEntities <AssetFilter>(MediaEntity.StreamingFilterAsset, streamingLocator.AssetName);
                foreach (AssetFilter assetFilter in assetFilters)
                {
                    assetFilterNames.Add(assetFilter.Name);
                }
                mediaStream.Filters = assetFilterNames.ToArray();
            }
            return(mediaStream);
        }
示例#2
0
        public static MediaJobPublish PublishJobOutput(string jobName, string insightId)
        {
            MediaJobAccount jobAccount;
            MediaJobPublish jobPublish = null;

            using (DatabaseClient databaseClient = new DatabaseClient())
            {
                string collectionId = Constant.Database.Collection.MediaJobAccount;
                string documentId   = string.IsNullOrEmpty(jobName) ? insightId : jobName;
                jobAccount = databaseClient.GetDocument <MediaJobAccount>(collectionId, documentId);
            }
            if (jobAccount != null)
            {
                using (MediaClient mediaClient = new MediaClient(null, jobAccount.MediaAccount))
                {
                    if (!string.IsNullOrEmpty(insightId))
                    {
                        JObject insight = mediaClient.IndexerGetInsight(insightId);
                        if (insight != null)
                        {
                            using (DatabaseClient databaseClient = new DatabaseClient())
                            {
                                string collectionId = Constant.Database.Collection.MediaContentInsight;
                                databaseClient.UpsertDocument(collectionId, insight);
                            }
                        }
                    }
                    else
                    {
                        Job job = mediaClient.GetEntity <Job>(MediaEntity.TransformJob, jobName, jobAccount.TransformName);
                        if (job != null)
                        {
                            jobPublish = GetJobPublish(job);
                            jobPublish.UserNotification.JobOutputMessage = GetNotificationMessage(job, jobAccount, jobPublish);
                            string streamingPolicyName = PredefinedStreamingPolicy.ClearStreamingOnly;
                            if (!string.IsNullOrEmpty(jobPublish.StreamingPolicyName))
                            {
                                streamingPolicyName = jobPublish.StreamingPolicyName;
                            }
                            foreach (JobOutputAsset jobOutput in job.Outputs)
                            {
                                mediaClient.CreateLocator(jobOutput.AssetName, jobOutput.AssetName, streamingPolicyName, jobPublish.ContentProtection);
                            }
                        }
                    }
                }
            }
            return(jobPublish);
        }
示例#3
0
        private static string[] GetThumbnailUrls(MediaClient mediaClient, StreamingLocator locator)
        {
            List <string>     thumbnailUrls    = new List <string>();
            Asset             asset            = mediaClient.GetEntity <Asset>(MediaEntity.Asset, locator.AssetName);
            MediaAsset        mediaAsset       = new MediaAsset(mediaClient, asset);
            StorageBlobClient blobClient       = new StorageBlobClient(mediaClient.MediaAccount, asset.StorageAccountName);
            StringComparison  stringComparison = StringComparison.OrdinalIgnoreCase;

            foreach (MediaFile assetFile in mediaAsset.Files)
            {
                if (assetFile.Name.StartsWith(Constant.Media.Thumbnail.FileNamePrefix, stringComparison))
                {
                    string thumbnailUrl = blobClient.GetDownloadUrl(asset.Container, assetFile.Name, false);
                    thumbnailUrls.Add(thumbnailUrl);
                }
            }
            return(thumbnailUrls.ToArray());
        }
示例#4
0
        private static MediaStream[] GetMediaStreams(string authToken, MediaClient mediaClient, StreamingLocator locator)
        {
            List <MediaStream> mediaStreams = new List <MediaStream>();
            string             playerUrl    = mediaClient.GetPlayerUrl(locator);

            if (!string.IsNullOrEmpty(playerUrl))
            {
                Asset       asset       = mediaClient.GetEntity <Asset>(MediaEntity.Asset, locator.AssetName);
                MediaStream mediaStream = GetMediaStream(authToken, mediaClient, asset, null, locator, playerUrl);
                mediaStreams.Add(mediaStream);
                AssetFilter[] assetFilters = mediaClient.GetAllEntities <AssetFilter>(MediaEntity.FilterAsset, null, locator.AssetName);
                foreach (AssetFilter assetFilter in assetFilters)
                {
                    MediaStream mediaFilter = GetMediaStream(authToken, mediaClient, asset, assetFilter, locator, playerUrl);
                    mediaStreams.Add(mediaFilter);
                }
            }
            return(mediaStreams.ToArray());
        }
        public StreamProtection[] GetProtectionInfo(string authToken, MediaClient mediaClient, StreamingLocator locator)
        {
            authToken = string.Concat("Bearer=", authToken);
            List <StreamProtection> protectionInfo = new List <StreamProtection>();

            if (locator.StreamingPolicyName == PredefinedStreamingPolicy.ClearKey)
            {
                StreamProtection streamProtection = new StreamProtection()
                {
                    Type = MediaProtection.AES,
                    AuthenticationToken = authToken
                };
                protectionInfo.Add(streamProtection);
            }
            else if (locator.StreamingPolicyName == PredefinedStreamingPolicy.SecureStreaming)
            {
                ContentKeyPolicy contentKeyPolicy = mediaClient.GetEntity <ContentKeyPolicy>(MediaEntity.ContentKeyPolicy, locator.DefaultContentKeyPolicyName);
                foreach (ContentKeyPolicyOption contentKeyPolicyOption in contentKeyPolicy.Options)
                {
                    if (contentKeyPolicyOption.Configuration is ContentKeyPolicyPlayReadyConfiguration)
                    {
                        StreamProtection streamProtection = new StreamProtection()
                        {
                            Type = MediaProtection.PlayReady,
                            AuthenticationToken = authToken
                        };
                        protectionInfo.Add(streamProtection);
                    }
                    else if (contentKeyPolicyOption.Configuration is ContentKeyPolicyWidevineConfiguration)
                    {
                        StreamProtection streamProtection = new StreamProtection()
                        {
                            Type = MediaProtection.Widevine,
                            AuthenticationToken = authToken
                        };
                        protectionInfo.Add(streamProtection);
                    }
                }
            }
            return(protectionInfo.Count == 0 ? null : protectionInfo.ToArray());
        }
        public MediaProtection[] GetStreamProtection(string authToken, MediaClient mediaClient, StreamingLocator locator)
        {
            List <MediaProtection> streamProtection = new List <MediaProtection>();

            if (locator.StreamingPolicyName == PredefinedStreamingPolicy.ClearKey)
            {
                streamProtection.Add(new MediaProtection()
                {
                    Type = MediaContentProtection.AES,
                    AuthenticationToken = authToken
                });
            }
            else if (locator.StreamingPolicyName == PredefinedStreamingPolicy.MultiDrmCencStreaming || locator.StreamingPolicyName == PredefinedStreamingPolicy.MultiDrmStreaming)
            {
                ContentKeyPolicy contentKeyPolicy = mediaClient.GetEntity <ContentKeyPolicy>(MediaEntity.ContentKeyPolicy, locator.DefaultContentKeyPolicyName);
                foreach (ContentKeyPolicyOption contentKeyPolicyOption in contentKeyPolicy.Options)
                {
                    if (contentKeyPolicyOption.Configuration is ContentKeyPolicyPlayReadyConfiguration)
                    {
                        streamProtection.Add(new MediaProtection()
                        {
                            Type = MediaContentProtection.PlayReady,
                            AuthenticationToken = authToken
                        });
                    }
                    else if (contentKeyPolicyOption.Configuration is ContentKeyPolicyWidevineConfiguration)
                    {
                        streamProtection.Add(new MediaProtection()
                        {
                            Type = MediaContentProtection.Widevine,
                            AuthenticationToken = authToken
                        });
                    }
                }
            }
            return(streamProtection.ToArray());
        }