Beispiel #1
0
        private static IContainer LoadMetadataFromFFprobe(this IContainer resource)
        {
            var mediaLoader = new MediaLoader(resource);

            if (mediaLoader.HasAudio)
            {
                resource.Streams.AddRange(mediaLoader.BaseData.Streams
                                          .OfType <AudioStreamMetadata>()
                                          .Select(audioMetadata => AudioStream.Create(MetadataInfo.Create(audioMetadata))));
            }

            if (mediaLoader.HasVideo)
            {
                resource.Streams.AddRange(mediaLoader.BaseData.Streams
                                          .OfType <VideoStreamMetadata>()
                                          .Select(videoMetadata => VideoStream.Create(MetadataInfo.Create(videoMetadata))));
            }

            if (mediaLoader.HasData)
            {
                resource.Streams.AddRange(mediaLoader.BaseData.Streams
                                          .OfType <DataStreamMetadata>()
                                          .Select(dataMetadata => DataStream.Create(MetadataInfo.Create(dataMetadata))));
            }

            return(resource);
        }
Beispiel #2
0
        private void Initialize(object file)
        {
            if ((ViewPageTotalSize / ViewPageCount) % this.BlockSize != 0)
            {
                throw new ArgumentException(string.Format("This '{0}' value of blockSize parameter is invalid.", this.BlockSize));
            }

            //计算缓存区总共有多少个存储块
            _blockCount = (int)(StorageSize / this.BlockSize);

            //计算缓存区的总大(为存储区长度+索引区长度+分配表区长度+文件头长度)
            _capacity = StorageSize + (_blockCount * 4) + (36 * BufferUtility.KB) + MetadataInfo.HeadSize;

            //判断传入参数是否为文件流
            var fileStream = file as FileStream;

            if (fileStream == null)
            {
                var fileInfo = new FileInfo((string)file);

                if (fileInfo.Exists && fileInfo.Length > 0 && fileInfo.Length != _capacity)
                {
                    throw new ArgumentException("file");
                }

                fileStream = new FileStream((string)file,
                                            FileMode.OpenOrCreate,
                                            FileAccess.ReadWrite,
                                            FileShare.ReadWrite,
                                            this.BlockSize,
                                            FileOptions.RandomAccess);

                if (fileStream.Length == 0)
                {
                    fileStream.SetLength(_capacity);
                }
            }
            else
            {
                if (fileStream.Length > 0 && fileStream.Length != _capacity)
                {
                    throw new ArgumentException("file");
                }
            }

            //创建内存映射文件对象
            _memoryMappedFile = MemoryMappedFile.CreateFromFile(fileStream,
                                                                Path.GetFileName(fileStream.Name),
                                                                _capacity,
                                                                MemoryMappedFileAccess.ReadWrite,
                                                                null,
                                                                HandleInheritability.Inheritable,
                                                                false);

            //构建默认的元数据描述对象
            _metadata = MetadataInfo.Create(this.BlockSize, _blockCount);

            //创建缓存页面管理器对象
            _pageManager = new MemoryMappedPageManager(this, (uint)_metadata.StorageOffset);
        }
Beispiel #3
0
        public MetadataInfoTreeContainer EditInfo(MetadataInfoTreeContainer infoToUpdate, List <MetadataInfoTreeContainer> suppliedInfo)
        {
            var emptyMetadataInfo = MetadataInfo.Create();

            emptyMetadataInfo.AudioMetadata = new AudioStreamMetadata
            {
                SampleRate = SampleRate ?? 44100,
                Duration   = TimeSpan.MaxValue,
                DurationTs = long.MaxValue,
            };

            return(MetadataInfoTreeContainer.Create(AudioStream.Create(emptyMetadataInfo)));
        }
Beispiel #4
0
        public MetadataInfoTreeContainer EditInfo(MetadataInfoTreeContainer infoToUpdate, List <MetadataInfoTreeContainer> suppliedInfo)
        {
            var emptyMetadataInfo = MetadataInfo.Create();

            emptyMetadataInfo.VideoMetadata = new VideoStreamMetadata
            {
                Width            = Size.HasValue ? Size.Value.Width : 320,
                Height           = Size.HasValue ? Size.Value.Height : 240,
                AverageFrameRate = Fraction.Create(FrameRate ?? 25, 1),
                RFrameRate       = Fraction.Create(FrameRate ?? 25, 1),
                Duration         = Duration ?? TimeSpan.MaxValue,
                DurationTs       = long.MaxValue,
            };

            return(MetadataInfoTreeContainer.Create(VideoStream.Create(emptyMetadataInfo)));
        }
        private static IContainer LoadMetadataFromFFprobe(this IContainer resource)
        {
            var mediaLoader = new Metadata.FFprobe.MediaLoader(resource);

            if (mediaLoader.HasAudio)
            {
                var audioStreamMetadata = MetadataInfo.Create(mediaLoader.AudioStream);

                resource.Streams.Add(AudioStream.Create(audioStreamMetadata));
            }

            if (mediaLoader.HasVideo)
            {
                var videoStreamMetadata = MetadataInfo.Create(mediaLoader.VideoStream);

                resource.Streams.Add(VideoStream.Create(videoStreamMetadata));
            }

            return(resource);
        }
Beispiel #6
0
 public VideoStream()
 {
     Map  = Helpers.NewMap();
     Info = MetadataInfo.Create();
 }