content/media/encoder/fmp4_muxer/ISOMediaWriter.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef ISOMediaWriter_h_
     7 #define ISOMediaWriter_h_
     9 #include "ContainerWriter.h"
    10 #include "nsIRunnable.h"
    12 namespace mozilla {
    14 class ISOControl;
    15 class FragmentBuffer;
    16 class ISOMediaWriterRunnable;
    18 class ISOMediaWriter : public ContainerWriter
    19 {
    20 public:
    21   // Generate an fragmented MP4 stream, ISO/IEC 14496-12.
    22   // Brand names in 'ftyp' box are 'isom' and 'mp42'.
    23   const static uint32_t TYPE_FRAG_MP4 = 1 << 0;
    25   // Generate an fragmented 3GP stream, 3GPP TS 26.244,
    26   // '5.4.3 Basic profile'.
    27   // Brand names in 'ftyp' box are '3gp9' and 'isom'.
    28   const static uint32_t TYPE_FRAG_3GP = 1 << 1;
    30   // aType is the combination of CREATE_AUDIO_TRACK and CREATE_VIDEO_TRACK.
    31   // It is a hint to muxer that the output streaming contains audio, video
    32   // or both.
    33   //
    34   // aHint is one of the value in TYPE_XXXXXXXX. It is a hint to muxer what kind
    35   // of ISO format should be generated.
    36   ISOMediaWriter(uint32_t aType, uint32_t aHint = TYPE_FRAG_MP4);
    37   ~ISOMediaWriter();
    39   // ContainerWriter methods
    40   nsresult WriteEncodedTrack(const EncodedFrameContainer &aData,
    41                              uint32_t aFlags = 0) MOZ_OVERRIDE;
    43   nsresult GetContainerData(nsTArray<nsTArray<uint8_t>>* aOutputBufs,
    44                             uint32_t aFlags = 0) MOZ_OVERRIDE;
    46   nsresult SetMetadata(TrackMetadataBase* aMetadata) MOZ_OVERRIDE;
    48 protected:
    49   /**
    50    * The state of each state will generate one or more blob.
    51    * Each blob will be a moov, moof, moof... until receiving EOS.
    52    * The generated sequence is:
    53    *
    54    *   moov -> moof -> moof -> ... -> moof -> moof
    55    *
    56    * Following is the details of each state.
    57    *   MUXING_HEAD:
    58    *     It collects the metadata to generate a moov. The state transits to
    59    *     MUXING_HEAD after output moov blob.
    60    *
    61    *   MUXING_FRAG:
    62    *     It collects enough audio/video data to generate a fragment blob. This
    63    *     will be repeated until END_OF_STREAM and then transiting to MUXING_DONE.
    64    *
    65    *   MUXING_DONE:
    66    *     End of ISOMediaWriter life cycle.
    67    */
    68   enum MuxState {
    69     MUXING_HEAD,
    70     MUXING_FRAG,
    71     MUXING_DONE,
    72   };
    74 private:
    75   nsresult RunState();
    77   // True if one of following conditions hold:
    78   //   1. Audio/Video accumulates enough data to generate a moof.
    79   //   2. Get EOS signal.
    80   //   aEOS will be assigned to true if it gets EOS signal.
    81   bool ReadyToRunState(bool& aEOS);
    83   // The main class to generate and iso box. Its life time is same as
    84   // ISOMediaWriter and deleted only if ISOMediaWriter is destroyed.
    85   nsAutoPtr<ISOControl> mControl;
    87   // Buffers to keep audio/video data frames, they are created when metadata is
    88   // received. Only one instance for each media type is allowed and they will be
    89   // deleted only if ISOMediaWriter is destroyed.
    90   nsAutoPtr<FragmentBuffer> mAudioFragmentBuffer;
    91   nsAutoPtr<FragmentBuffer> mVideoFragmentBuffer;
    93   MuxState mState;
    95   // A flag to indicate the output buffer is ready to blob out.
    96   bool mBlobReady;
    98   // Combination of Audio_Track or Video_Track.
    99   uint32_t mType;
   100 };
   102 } // namespace mozilla
   103 #endif // ISOMediaWriter_h_

mercurial