public void CreateCodecStreams(IDataBlockBuilder dataBlockBuilder)
        {
            IDataObject dataObject = GetObject <DataObject>(_root) ?? GetObject <DataObjectWithoutStart>(_root) ?? default(IDataObject);

            if (dataObject == null)
            {
                return;
            }

            CodecListObject codecList = GetObject <CodecListObject>(_root);             // the value null is okay for this codecList

            IDictionary <byte, ICodecStreamBuilder> codecStreamBuilders = new Dictionary <byte, ICodecStreamBuilder>();

            foreach (DataPacket dataPacket in dataObject.DataPackets)
            {
                foreach (Payload payload in dataPacket.Payloads)
                {
                    AddPayload(dataBlockBuilder, codecStreamBuilders, payload, codecList, _root);
                }
            }
        }
        private void AddPayload(IDataBlockBuilder dataBlockBuilder, IDictionary <byte, ICodecStreamBuilder> codecStreamBuilders, Payload payload, CodecListObject codecList, AsfObject asfObject)
        {
            if (payload.Streams == null || payload.Streams.Count == 0)
            {
                return;
            }

            byte streamNumber = payload.StreamNumber;

            if (codecStreamBuilders.ContainsKey(streamNumber))
            {
                ICodecStreamBuilder codecStreamBuilder = codecStreamBuilders[streamNumber];

                foreach (IDataPacket streamData in payload.Streams)
                {
                    codecStreamBuilder.Data = codecStreamBuilder.Data.Append(streamData);
                }
            }
            else
            {
                StreamPropertiesObject streamProperty = GetStreamProperty(asfObject, streamNumber);

                ICodecStreamBuilder codecStreamBuilder = dataBlockBuilder.AddCodecStream();
                codecStreamBuilder.Name = GetCodecStreamName(streamNumber, streamProperty, codecList);
                // The DataFormat will be set by the codec detector (if one exists)
                //codecStreamBuilder.DataFormat = GetDataFormat(streamProperty);
                codecStreamBuilder.Data = GetStreamData(streamProperty, payload.Streams[0]);
                for (int streamIndex = 1; streamIndex < payload.Streams.Count; streamIndex++)
                {
                    codecStreamBuilder.Data = codecStreamBuilder.Data.Append(payload.Streams[streamIndex]);
                }
                codecStreamBuilder.AbsoluteStartOffset = codecStreamBuilder.Data.StartOffset;

                codecStreamBuilders.Add(streamNumber, codecStreamBuilder);
            }
        }
        private string GetCodecStreamName(byte streamNumber, StreamPropertiesObject streamProperty, CodecListObject codecList)
        {
            StringBuilder codecStreamName = new StringBuilder();

            codecStreamName.AppendFormat(CultureInfo.CurrentCulture, "Stream {0}", streamNumber);

            if (streamProperty != null)                 // No stream property ASF-object found
            {
                // The Stream Type
                codecStreamName.AppendFormat(CultureInfo.CurrentCulture, ", {0}", Enum.GetName(typeof(ObjectStreamTypeGuid), streamProperty.StreamType));

                // The codec 4CC
                if (!string.IsNullOrEmpty(streamProperty.CompressionId))
                {
                    codecStreamName.AppendFormat(CultureInfo.CurrentCulture, ", {0}", streamProperty.CompressionId);
                }

                // The codec name
                string codecName = null;
                if (codecList != null)
                {
                    if (codecList.CodecNames.TryGetValue(GetCodecType(streamProperty.StreamType), out codecName))
                    {
                        codecStreamName.AppendFormat(CultureInfo.CurrentCulture, ", {0}", codecName);
                    }
                }
                if (string.IsNullOrEmpty(codecName) && !string.IsNullOrEmpty(streamProperty.CompressionId))
                {
                    codecStreamName.AppendDescriptiveCodecName(streamProperty.CompressionId);
                }
            }
            return(codecStreamName.ToString());
        }
示例#4
0
 public Codec(CodecListObject codecList)
     : base(Attribute.Codec, string.Empty, "{0}")
 {
     _outerClass = codecList;
 }