Пример #1
0
        public ITagWriter GetWriter()
        {
            if (_file.Exists)
            {
                _file.Delete();
            }
            FileStream stream = _file.Create();
            ITagWriter writer = new FlvWriter(stream, false);

            writer.WriteHeader();
            return(writer);
        }
Пример #2
0
        public ITagWriter GetAppendWriter()
        {
            // If the file doesnt exist, we cant append to it, so return a writer
            if (!_file.Exists)
            {
#if !SILVERLIGHT
                log.Info("File does not exist, calling writer. This will create a new file.");
#endif
                return(GetWriter());
            }
            //FileStream stream = _file.Open(FileMode.Append);
            FileStream stream = new FileStream(_file.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, 65536);
            ITagWriter writer = new FlvWriter(stream, true);
            return(writer);
        }
Пример #3
0
        public ITagWriter GetAppendWriter()
        {
            // If the file doesnt exist, we cant append to it, so return a writer
            if (!_file.Exists)
            {
#if !SILVERLIGHT
                log.Info("File does not exist, calling writer. This will create a new file.");
#endif
                return GetWriter();
            }
            //FileStream stream = _file.Open(FileMode.Append);
            FileStream stream = new FileStream(_file.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, 65536);
            ITagWriter writer = new FlvWriter(stream, true);
            return writer;
        }
Пример #4
0
 public ITagWriter GetWriter()
 {
     if (_file.Exists)
         _file.Delete();
     FileStream stream = _file.Create();
     ITagWriter writer = new FlvWriter(stream, false);
     writer.WriteHeader();
     return writer;
 }
Пример #5
0
        /// <summary>
        /// Initiates writing of the Metadata.
        /// </summary>
        /// <param name="meta">Metadata to write.</param>
        public void Write(MetaData meta)
        {
            // Get cue points, FLV reader and writer
            MetaCue[] metaArr = meta.MetaCue;
            FlvReader reader = new FlvReader(_file, false);
            FlvWriter writer = new FlvWriter(_output, false);
            ITag tag = null;

            // Read first tag
            if (reader.HasMoreTags())
            {
                tag = reader.ReadTag();
                if (tag.DataType == IOConstants.TYPE_METADATA)
                {
                    if (!reader.HasMoreTags())
                        throw new IOException("File we're writing is metadata only?");
                }
            }

            meta.Duration = (double)reader.Duration / 1000;
            meta.VideoCodecId = reader.VideoCodecId;
            meta.AudioCodecId = reader.AudioCodecId;

            ITag injectedTag = InjectMetaData(meta, tag);
            injectedTag.PreviousTagSize = 0;
            tag.PreviousTagSize = injectedTag.BodySize;

            writer.WriteHeader();
            writer.WriteTag(injectedTag);
            writer.WriteTag(tag);

            int cuePointTimeStamp = 0;
            int counter = 0;

            if (metaArr != null)
            {
                Array.Sort(metaArr);
                cuePointTimeStamp = GetTimeInMilliseconds(metaArr[0]);
            }

            while (reader.HasMoreTags())
            {
                tag = reader.ReadTag();

                // if there are cuePoints in the array 
                if (counter < metaArr.Length)
                {

                    // If the tag has a greater timestamp than the
                    // cuePointTimeStamp, then inject the tag
                    while (tag.Timestamp > cuePointTimeStamp)
                    {

                        injectedTag = InjectMetaCue(metaArr[counter], tag);
                        writer.WriteTag(injectedTag);

                        tag.PreviousTagSize = injectedTag.BodySize;

                        // Advance to the next CuePoint
                        counter++;

                        if (counter > (metaArr.Length - 1))
                        {
                            break;
                        }

                        cuePointTimeStamp = GetTimeInMilliseconds(metaArr[counter]);

                    }
                }

                if (tag.DataType != IOConstants.TYPE_METADATA)
                {
                    writer.WriteTag(tag);
                }

            }
            writer.Close();
        }
Пример #6
0
        /// <summary>
        /// Initiates writing of the Metadata.
        /// </summary>
        /// <param name="meta">Metadata to write.</param>
        public void Write(MetaData meta)
        {
            // Get cue points, FLV reader and writer
            MetaCue[] metaArr = meta.MetaCue;
            FlvReader reader  = new FlvReader(_file, false);
            FlvWriter writer  = new FlvWriter(_output, false);
            ITag      tag     = null;

            // Read first tag
            if (reader.HasMoreTags())
            {
                tag = reader.ReadTag();
                if (tag.DataType == IOConstants.TYPE_METADATA)
                {
                    if (!reader.HasMoreTags())
                    {
                        throw new IOException("File we're writing is metadata only?");
                    }
                }
            }

            meta.Duration     = (double)reader.Duration / 1000;
            meta.VideoCodecId = reader.VideoCodecId;
            meta.AudioCodecId = reader.AudioCodecId;

            ITag injectedTag = InjectMetaData(meta, tag);

            injectedTag.PreviousTagSize = 0;
            tag.PreviousTagSize         = injectedTag.BodySize;

            writer.WriteHeader();
            writer.WriteTag(injectedTag);
            writer.WriteTag(tag);

            int cuePointTimeStamp = 0;
            int counter           = 0;

            if (metaArr != null)
            {
                Array.Sort(metaArr);
                cuePointTimeStamp = GetTimeInMilliseconds(metaArr[0]);
            }

            while (reader.HasMoreTags())
            {
                tag = reader.ReadTag();

                // if there are cuePoints in the array
                if (counter < metaArr.Length)
                {
                    // If the tag has a greater timestamp than the
                    // cuePointTimeStamp, then inject the tag
                    while (tag.Timestamp > cuePointTimeStamp)
                    {
                        injectedTag = InjectMetaCue(metaArr[counter], tag);
                        writer.WriteTag(injectedTag);

                        tag.PreviousTagSize = injectedTag.BodySize;

                        // Advance to the next CuePoint
                        counter++;

                        if (counter > (metaArr.Length - 1))
                        {
                            break;
                        }

                        cuePointTimeStamp = GetTimeInMilliseconds(metaArr[counter]);
                    }
                }

                if (tag.DataType != IOConstants.TYPE_METADATA)
                {
                    writer.WriteTag(tag);
                }
            }
            writer.Close();
        }