Ejemplo n.º 1
0
        private AtomTRAF GetTRAF(AtomMOOF pMoof, bool audio)
        {
            var pTrak = GetTRAK(audio);

            if (pTrak == null)
            {
                FATAL("No track found");
                return(null);
            }
            var trackId = (int)pTrak.Id;

            if (trackId == 0)
            {
                FATAL("No track found");
                return(null);
            }

            var trafs = pMoof.Trafs;

            if (trafs.ContainsKey(trackId))
            {
                return(trafs[trackId]);
            }
            FATAL("No track found");
            return(null);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private bool BuildMOOFFrames(AtomMOOF pMOOF, bool audio)
        {
            var pTraf = GetTRAF(pMOOF, audio);

            if (pTraf == null)
            {
                WARN("No {0} fragmented track found", audio ? "audio" : "video");
                return(true);
            }
            var pTfhd = (AtomTFHD )pTraf.GetPath(1, TFHD);

            if (pTfhd == null)
            {
                FATAL("Invalid track. No TFHD atom");
                return(false);
            }
            var pTrack = GetTRAK(audio);

            if (pTrack == null)
            {
                FATAL("no {0} track", audio ? "Audio" : "Video");
                return(false);
            }
            var pMDHD = (AtomMdhd )pTrack.GetPath(2, MDIA, MDHD);

            if (pMDHD == null)
            {
                FATAL("no MDHD");
                return(false);
            }
            var   timeScale      = pMDHD.TimeScale;
            ulong totalTime      = 0;
            var   absoluteOffset = pTfhd.BaseDataOffset;

            var runs = pTraf.Runs;

            foreach (var pRun in runs)
            {
                var   samples = pRun.Samples;
                ulong runSize = 0;
                foreach (var pSample in samples)
                {
                    MediaFrame frame;

                    frame.Start = (uint)(absoluteOffset + pRun.DataOffset + (long)runSize);
                    if (pSample.CompositionTimeOffset != 0)
                    {
                        var doubleVal = (pSample.CompositionTimeOffset / (double)timeScale) * 1000.00;
                        frame.CompositionOffset = (int)doubleVal;
                    }
                    else
                    {
                        frame.CompositionOffset = 0;
                    }

                    if (!audio)
                    {
                        frame.IsKeyFrame = ((pSample.Flags & 0x00010000) == 0);
                    }
                    else
                    {
                        frame.IsKeyFrame = false;
                    }
                    frame.Length         = pSample.Size;
                    frame.Type           = audio ? MediaFrameType.Audio : MediaFrameType.Video;
                    frame.DeltaTime      = (pSample.Duration / (double)timeScale) * 1000.00;
                    frame.AbsoluteTime   = (uint)((totalTime / timeScale) * 1000);
                    frame.IsBinaryHeader = false;
                    totalTime           += pSample.Duration;
                    _frames.Add(frame);
                    runSize += pSample.Size;
                }
            }
            return(true);
        }