public override IDataPacket FindReferenceHeader(IDataReader dataReader, ICodecParametersSpec codecParameters)
        {
            // Note: Loop to detect reference headers preceeded by a block of video frames
            //       (e.g. for 3GP files with 'mdat' before the 'moov' atom, so that the slices are located before the SPS/PPS pair)
            while (dataReader.State == DataReaderState.Ready)
            {
                IScanContext scanContext = new ReferenceHeaderScanContext {
                    Detectors = new[] { this }
                };

                var dataBlock = Carve(dataReader, new ReferenceHeaderDataBlockBuilder(), scanContext);
                if (dataBlock == null)
                {
                    break;                     // No (more) data blocks detected
                }

                IResultNode videoObject = scanContext.Results.FindChild(VideoObjectName);
                if ((videoObject != null) && videoObject.HasChildren())
                {
                    IResultNode videoObjectLayer = videoObject.GetFirstChild();
                    if (videoObjectLayer.Name == VideoObjectLayerName)
                    {
                        return(CreateReferenceHeader(dataBlock.DataFormat, videoObject, videoObjectLayer, codecParameters));
                    }
                }

                // VideoObject or VideoObjectLayer is missing: Continue scanning after current data block ...
                dataReader.Position = dataBlock.EndOffset;
            }

            return(null);            // No reference header detected
        }
Example #2
0
        public IDataPacket FindReferenceHeader(IDataReader dataReader, ICodecParametersSpec codecParameters)
        {
            while (dataReader.State == DataReaderState.Ready)
            {
                IScanContext scanContext = new ReferenceHeaderScanContext {
                    Detectors = new[] { this }
                };

                var dataBlock = _carver.Carve(new BitStreamDataReader(dataReader), new ReferenceHeaderDataBlockBuilder(), scanContext);
                if (dataBlock == null)
                {
                    break;                     // No (more) data blocks detected
                }

                IResultNode sequenceHeader = scanContext.Results.FindChild(SequenceHeader.Name);
                if (sequenceHeader != null)
                {
                    return(CreateReferenceHeader(dataBlock.DataFormat, sequenceHeader, codecParameters));
                }

                // Sequence header is missing: Continue scanning after current data block ...
                dataReader.Position = dataBlock.EndOffset;
            }

            return(null);            // No reference header detected
        }
Example #3
0
        public IDataPacket FindReferenceHeader(IDataReader dataReader, ICodecParametersSpec codecParameters)
        {
            // Note: Loop to detect reference headers preceeded by a block of video frames
            //       (e.g. for 3GP files with 'mdat' before the 'moov' atom, so that the slices are located before the SPS/PPS pair)
            while (dataReader.State == DataReaderState.Ready)
            {
                IScanContext scanContext = new ReferenceHeaderScanContext {
                    Detectors = new[] { this }
                };

                var dataBlock = _carver.Carve(new BitStreamDataReader(dataReader), new ReferenceHeaderDataBlockBuilder(), scanContext);
                if (dataBlock == null)
                {
                    break;                     // No (more) data blocks detected
                }

                IResultNode sequenceParameterSet = scanContext.Results.FindChild(SequenceParameterSet.Name);
                if (sequenceParameterSet != null)
                {
                    IResultNode pictureParameterSet = sequenceParameterSet.FindChild(PictureParameterSet.Name);
                    if (pictureParameterSet != null)
                    {
                        // TODO: perhaps we need to include the headers between the SPS and PPS !?
                        IDataPacket data = sequenceParameterSet.Append(pictureParameterSet);

                        // Report codec parameters for reference header
                        codecParameters.Codec  = CodecID.H264;
                        codecParameters.Width  = GetWidth(sequenceParameterSet);
                        codecParameters.Height = GetHeight(sequenceParameterSet);
                        var entropyCodingMode = GetAttributeValue <bool>(pictureParameterSet, PictureParameterSet.Attribute.EntropyCodingMode);
                        codecParameters["EntropyCodingMode"] = entropyCodingMode ? "CABAC" : "CAVLC";
                        // TODO: codecParameters["FrameRate"] = GetAttributeStringValue(sequenceParameterSet, ???);

                        return(data);
                    }
                }

                // Sequence- or Picture Parameter Set is missing: Continue scanning after current data block ...
                dataReader.Position = dataBlock.EndOffset;
            }

            return(null);            // No reference header detected
        }
Example #4
0
 public IDataPacket FindReferenceHeader(IDataReader dataReader, ICodecParametersSpec context)
 {
     return(null);
 }
        private static IDataPacket CreateReferenceHeader(CodecID codec, IDataPacket videoObject, IResultNode videoObjectLayer, ICodecParametersSpec codecParameters)
        {
            // Report codec parameters for reference header
            codecParameters.Codec      = codec;
            codecParameters.Width      = GetAttribute <uint>(videoObjectLayer, VideoObjectLayer.Attribute.Width);
            codecParameters.Height     = GetAttribute <uint>(videoObjectLayer, VideoObjectLayer.Attribute.Height);
            codecParameters["VTIRate"] = GetAttributeStringValue(videoObjectLayer, VideoObjectLayer.Attribute.VopTimeIncrementResolution);

            return(videoObject.Append(videoObjectLayer));
        }
 public IDataPacket FindReferenceHeader(IDataReader dataReader, ICodecParametersSpec codecParameters)
 {
     return(_codecDetector.FindReferenceHeader(dataReader, codecParameters));
 }
Example #7
0
        private static IDataPacket CreateReferenceHeader(CodecID codec, IResultNode sequenceHeader, ICodecParametersSpec codecParameters)
        {
            IDataPacket data = sequenceHeader;

            // Include sequence extensions
            foreach (IResultNode childResultNode in sequenceHeader.Children)
            {
                if (!IsSequenceExtension(childResultNode.Name))
                {
                    break;
                }

                data = data.Append(childResultNode);
            }

            // Report codec parameters for reference header
            var width  = GetAttribute <uint>(sequenceHeader, SequenceHeader.Attribute.HorizontalSizeValue);
            var height = GetAttribute <uint>(sequenceHeader, SequenceHeader.Attribute.VerticalSizeValue);

            if (sequenceHeader.HasChildren())
            {
                IResult sequenceExtension = sequenceHeader.GetFirstChild();
                if (sequenceExtension.Name == SequenceExtension.Name)
                {
                    width  |= GetAttribute <uint>(sequenceExtension, SequenceExtension.Attribute.HorizontalSizeExtension) << 12;
                    height |= GetAttribute <uint>(sequenceExtension, SequenceExtension.Attribute.VerticalSizeExtension) << 12;
                }
            }

            codecParameters.Codec     = codec;
            codecParameters.Width     = width;
            codecParameters.Height    = height;
            codecParameters.FrameRate = GetAttributeStringValue(sequenceHeader, SequenceHeader.Attribute.FrameRateCode);

            return(data);
        }
Example #8
0
 public virtual IDataPacket FindReferenceHeader(IDataReader dataReader, ICodecParametersSpec codecParameters)
 {
     return(null);
 }