Beispiel #1
0
 public override void AtomCreated(BaseAtom atom)
 {
     switch (atom.Type)
     {
         case ESDS:
             _atomESDS = (AtomESDS)atom;
             break;
         case WAVE:
             _atomWAVE = (AtomWAVE)atom;
             break;
         case CHAN:
            // _atomCHAN = (AtomCHAN)atom;
             break;
     }
 }
Beispiel #2
0
 public override void AtomCreated(BaseAtom atom)
 {
     switch (atom.Type)
     {
         case MP4A:
             _atomMp4A = atom as AtomMP4A;
             return;
         case ESDS:
             _atomEsds = atom as AtomESDS;
             return;
         case NULL:
             return;
         default:
             return;
     }
 }
Beispiel #3
0
        public override void AtomCreated(BaseAtom atom)
        {
            switch (atom.Type)
            {
            case ESDS:
                _atomESDS = (AtomESDS)atom;
                break;

            case WAVE:
                _atomWAVE = (AtomWAVE)atom;
                break;

            case CHAN:
                // _atomCHAN = (AtomCHAN)atom;
                break;
            }
        }
Beispiel #4
0
        public override void AtomCreated(BaseAtom atom)
        {
            switch (atom.Type)
            {
            case MP4A:
                _atomMp4A = atom as AtomMP4A;
                return;

            case ESDS:
                _atomEsds = atom as AtomESDS;
                return;

            case NULL:
                return;

            default:
                return;
            }
        }
Beispiel #5
0
        public BaseAtom ReadAtom(IBoxContainer parentAtom)
        {
            BaseAtom atom       = null;
            uint     type       = 0;
            var      currentPos = MediaFile.Position;
            long     size       = MediaFile.Br.ReadUInt32();

            if (size == 0)
            {
                atom = new AtomNULL(this, type, size, currentPos)
                {
                    Parent = parentAtom
                };
                return(atom);
            }
            type = MediaFile.Br.ReadUInt32();
            if (size == 1)
            {
                size = MediaFile.Br.ReadInt64();
                if (size == 0)
                {
                    atom = new AtomNULL(this, type, size, currentPos)
                    {
                        Parent = parentAtom
                    };
                    return(atom);
                }
            }
            switch (type)
            {
            case FTYP:
                atom = new AtomFTYP(this, size, currentPos);
                break;

            case MOOV:
                atom = new AtomMOOV(this, type, size, currentPos);
                break;

            case MOOF:
                atom = new AtomMOOF(this, type, size, currentPos);
                break;

            case MVEX:
                atom = new AtomMVEX(this, type, size, currentPos);
                break;

            case MVHD:
                atom = new AtomMVHD(this, type, size, currentPos);
                break;

            case MFHD:
                atom = new AtomMFHD(this, type, size, currentPos);
                break;

            case TRAK:
                atom = new AtomTRAK(this, type, size, currentPos);
                break;

            case TRAF:
                atom = new AtomTRAF(this, type, size, currentPos);
                break;

            case TREX:
                atom = new AtomTREX(this, type, size, currentPos);
                break;

            case TRUN:
                atom = new AtomTRUN(this, type, size, currentPos);
                break;

            case TKHD:
                atom = new AtomTKHD(this, type, size, currentPos);
                break;

            case TFHD:
                atom = new AtomTFHD(this, type, size, currentPos);
                break;

            case MDIA:
                atom = new AtomMDIA(this, type, size, currentPos);
                break;

            case MDHD:
                atom = new AtomMdhd(this, type, size, currentPos);
                break;

            case HDLR:
                atom = new AtomHdlr(this, type, size, currentPos);
                break;

            case MINF:
                atom = new AtomMINF(this, type, size, currentPos);
                break;

            case SMHD:
                atom = new AtomSMHD(this, type, size, currentPos);
                break;

            case DINF:
                atom = new AtomDINF(this, type, size, currentPos);
                break;

            case STBL:
                atom = new AtomSTBL(this, type, size, currentPos);
                break;

            case VMHD:
                atom = new AtomVMHD(this, type, size, currentPos);
                break;

            case DREF:
                atom = new AtomDREF(this, type, size, currentPos);
                break;

            case STSD:
                atom = new AtomSTSD(this, type, size, currentPos);
                break;

            case STTS:
                atom = new AtomSTTS(this, type, size, currentPos);
                break;

            case STSC:
                atom = new AtomSTSC(this, type, size, currentPos);
                break;

            case STSZ:
                atom = new AtomSTSZ(this, type, size, currentPos);
                break;

            case STCO:
                atom = new AtomSTCO(this, type, size, currentPos);
                break;

            case CTTS:
                atom = new AtomCTTS(this, type, size, currentPos);
                break;

            case STSS:
                atom = new AtomSTSS(this, type, size, currentPos);
                break;

            case URL:
                atom = new AtomURL(this, type, size, currentPos);
                break;

            case MP4A:
                atom = new AtomMP4A(this, type, size, currentPos);
                break;

            case AVC1:
                atom = new AtomAVC1(this, type, size, currentPos);
                break;

            case ESDS:
                atom = new AtomESDS(this, type, size, currentPos);
                break;

            case AVCC:
                atom = new AtomAVCC(this, type, size, currentPos);
                break;

            case UDTA:
                atom = new AtomUDTA(this, type, size, currentPos);
                break;

            case WAVE:
                atom = new AtomWAVE(this, type, size, currentPos);
                break;

            case META:
                atom = new AtomMETA(this, type, size, currentPos);
                break;

            case NULL:
                atom = new AtomNULL(this, type, size, currentPos);
                break;

            case ILST:
                atom = new AtomILST(this, type, size, currentPos);
                break;

            case DATA:
                atom = new AtomDATA(this, type, size, currentPos);
                break;

            case CO64:
                atom = new AtomCO64(this, type, size, currentPos);
                break;

            case _COM:
            case NAME:
            case COVR:
            case AART:
            case _WRT:
            case _GRP:
            case _LYR:
            case _NAM:
            case _ART1:
            case _ART2:
            case _PRT:
            case _TOO:
            case _DAY:
            case _CMT:
            case _CPY:
            case _DES:
            case _ALB:
            case TRKN:
            case CPIL:
            case PGAP:
            case TMPO:
            case GNRE:
            case DISK:
            case _GEN:
            case DESC:
            case TVSH:
            case TVEN:
            case TVSN:
            case TVES:
                atom = new AtomMetaField(this, type, size, currentPos);
                break;

            default:
            {
                atom = new IgnoredAtom(this, type, size, currentPos);
                break;
            }
            }
            atom.Parent = parentAtom;
            atom.Read();
            if (currentPos + atom.Size != MediaFile.Position)
            {
                FATAL("atom start:{0};Atom Size:{1};currentPostion:{2}", currentPos, atom.Size, MediaFile.Position);
            }
            return(atom);
        }
Beispiel #6
0
        protected override bool BuildFrames()
        {
            _frames.Clear();
            AtomTRAK track;
            AtomAVCC avcc = null;

            if (null != (track = GetTRAK(false)))
            {
                avcc = (AtomAVCC)track.GetPath(6, MDIA, MINF,
                                               STBL, STSD, AVC1, AVCC);
            }
            AtomESDS esds = null;

            if (null != (track = GetTRAK(true)))
            {
                esds = (AtomESDS)track.GetPath(6, MDIA, MINF,
                                               STBL, STSD, MP4A, ESDS) ?? (AtomESDS)track.GetPath(7, MDIA, MINF,
                                                                                                  STBL, STSD, MP4A, WAVE, ESDS);
            }
            if (avcc != null)
            {
                if (!BuildMOOVFrames(false))
                {
                    return(false);
                }
            }
            foreach (var moof in _moof)
            {
                if (!BuildMOOFFrames(moof, true))
                {
                    FATAL("Unable to build audio frames from MOOF");
                    return(false);
                }
                if (!BuildMOOFFrames(moof, false))
                {
                    FATAL("Unable to build video frames from MOOF");
                    return(false);
                }
            }
            _frames.Sort(CompareFrames);
            if (esds != null)
            {
                MediaFrame audioHeader;
                audioHeader.Type              = MediaFrameType.Audio;
                audioHeader.IsBinaryHeader    = true;
                audioHeader.IsKeyFrame        = true;
                audioHeader.Length            = esds.ExtraDataLength;
                audioHeader.AbsoluteTime      = 0;
                audioHeader.Start             = (uint)esds.ExtraDataStart;
                audioHeader.DeltaTime         = 0;
                audioHeader.CompositionOffset = 0;
                MediaFile.SeekTo(audioHeader.Start);
                var raw = MediaFile.Br.ReadBytes((int)audioHeader.Length);
                _streamCapabilities.InitAudioAAC(new MemoryStream(raw), raw.Length);
                _frames.Add(audioHeader);
            }
            else
            {
                if ((track = GetTRAK(true)) != null)
                {
                    var mp3 = track.GetPath(5, MDIA, MINF,
                                            STBL, STSD, MP3);
                    if (mp3 != null)
                    {
                        _streamCapabilities.AudioCodecId = AudioCodec.Mp3;
                    }
                }
            }
            if (avcc != null)
            {
                MediaFrame videoHeader;
                videoHeader.Type              = MediaFrameType.Video;
                videoHeader.IsBinaryHeader    = true;
                videoHeader.IsKeyFrame        = true;
                videoHeader.Length            = (uint)avcc.ExtraDataLength;
                videoHeader.AbsoluteTime      = 0;
                videoHeader.Start             = (uint)avcc.ExtraDataStart;
                videoHeader.DeltaTime         = 0;
                videoHeader.CompositionOffset = 0;
                MediaFile.SeekTo(videoHeader.Start);
                var raw = MediaFile.Br.ReadBytes((int)videoHeader.Length);
                if (raw.Length < 8)
                {
                    FATAL("Invalid AVC codec bytes");
                    return(false);
                }
                var spsLength = raw.ReadUShort(6);
                var ppsLength = raw.ReadUShort(8 + spsLength + 1);
                var psps      = new byte[spsLength];
                Buffer.BlockCopy(raw, 8, psps, 0, (int)spsLength);
                var pps = new byte[ppsLength];
                Buffer.BlockCopy(raw, 8 + spsLength + 3, psps, 0, ppsLength);
                _streamCapabilities.InitVideoH264(psps, pps);
                _frames.Add(videoHeader);
            }

            return(true);
        }