Example #1
0
        public ErrorCode process(ISample sample)
        {
            if (sample == null)
            {
                return ErrorCode.NullReference;
            }

            ErrorCode er = ErrorCode.Success;

            if (sample.endTime() < sample.seekTime())
            {
                //drop frame as we should not render it
                return ErrorCode.Success;
            }

            strm_.refresh(sample.pointee());

            while (mpaDecode())
            {
                //create sampe here and deliver to next filter
                byte[] buff = new byte[samples_.Length * sizeof(short)];
                System.Buffer.BlockCopy(samples_, 0, buff, 0, buff.Length);
                ISample decoded = new Sample(buff, sample.startTime(), sample.endTime(), sample.seekTime(), sample.isDiscontinuous());
                if (next_ != null)
                {
                    er = next_.process(decoded);
                }
                if (renderer_ != null)
                {
                    er = renderer_.process(decoded);
                }
            }

            return er;
        }
Example #2
0
        public ErrorCode nextSample(int streamId, out ISample sample)
        {
            UInt64 length = reader_.size() - pos_;
            sample = null;
            if (length == 0)
            {
                return ErrorCode.EndOfStream;
            }
            UInt64 bufSize = Math.Min(BLOCK_SIZE, length);
            byte[] buf = new byte[bufSize];
            Int32 size = (Int32)bufSize;
            reader_.read(buf, ref size);

            UInt64 start = (pos_ - 44) * 800000 / ((UInt64)frequency_ * (UInt64)channels_ * (UInt64)bps_);
            UInt64 stop = (pos_ - 44 + bufSize) * 800000 / ((UInt64)frequency_ * (UInt64)channels_ * (UInt64)bps_);
            sample = new Sample(buf, start, stop, seekTime_, discontinuous_);
            pos_ += bufSize;
            discontinuous_ = false;

            return ErrorCode.Success;
        }
Example #3
0
        public ErrorCode nextSample(int streamId, out ISample sample)
        {
            sample = null;
            MPAHeader hdr = new MPAHeader();
            hdr.valid = false;
            byte[] tmp = new byte[4];
            while (!hdr.valid)
            {
                tmp[0] = tmp[1];
                tmp[1] = tmp[2];
                tmp[2] = tmp[3];

                reader_.read1(tmp, 3);
                hdr = MPAHeaderParser.parse(tmp, 0);
            }

            byte[] buffer = new byte[MPAHeaderParser.mpaPacketSize(hdr)];
            System.Buffer.BlockCopy(tmp, 0, buffer, 0, 4);

            int size = (int)MPAHeaderParser.mpaPacketSize(hdr) - 4;
            reader_.read(buffer, ref size, 4);

            if (size < (int)length_ - 4)
            {
                return ErrorCode.EndOfStream;
            }

            UInt64 start = 100000 * (UInt64)pos_ * samples_ / info_.getAudioInfo().sampleRate;
            UInt64 stop = 100000 * (UInt64)(pos_ + 1) * samples_ / info_.getAudioInfo().sampleRate;
            sample = new Sample(buffer, start, stop, seek_, discontinuous_);
            discontinuous_ = false;
            ++pos_;

            return ErrorCode.Success;
        }