michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef ISOMediaWriter_h_ michael@0: #define ISOMediaWriter_h_ michael@0: michael@0: #include "ContainerWriter.h" michael@0: #include "nsIRunnable.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class ISOControl; michael@0: class FragmentBuffer; michael@0: class ISOMediaWriterRunnable; michael@0: michael@0: class ISOMediaWriter : public ContainerWriter michael@0: { michael@0: public: michael@0: // Generate an fragmented MP4 stream, ISO/IEC 14496-12. michael@0: // Brand names in 'ftyp' box are 'isom' and 'mp42'. michael@0: const static uint32_t TYPE_FRAG_MP4 = 1 << 0; michael@0: michael@0: // Generate an fragmented 3GP stream, 3GPP TS 26.244, michael@0: // '5.4.3 Basic profile'. michael@0: // Brand names in 'ftyp' box are '3gp9' and 'isom'. michael@0: const static uint32_t TYPE_FRAG_3GP = 1 << 1; michael@0: michael@0: // aType is the combination of CREATE_AUDIO_TRACK and CREATE_VIDEO_TRACK. michael@0: // It is a hint to muxer that the output streaming contains audio, video michael@0: // or both. michael@0: // michael@0: // aHint is one of the value in TYPE_XXXXXXXX. It is a hint to muxer what kind michael@0: // of ISO format should be generated. michael@0: ISOMediaWriter(uint32_t aType, uint32_t aHint = TYPE_FRAG_MP4); michael@0: ~ISOMediaWriter(); michael@0: michael@0: // ContainerWriter methods michael@0: nsresult WriteEncodedTrack(const EncodedFrameContainer &aData, michael@0: uint32_t aFlags = 0) MOZ_OVERRIDE; michael@0: michael@0: nsresult GetContainerData(nsTArray>* aOutputBufs, michael@0: uint32_t aFlags = 0) MOZ_OVERRIDE; michael@0: michael@0: nsresult SetMetadata(TrackMetadataBase* aMetadata) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: /** michael@0: * The state of each state will generate one or more blob. michael@0: * Each blob will be a moov, moof, moof... until receiving EOS. michael@0: * The generated sequence is: michael@0: * michael@0: * moov -> moof -> moof -> ... -> moof -> moof michael@0: * michael@0: * Following is the details of each state. michael@0: * MUXING_HEAD: michael@0: * It collects the metadata to generate a moov. The state transits to michael@0: * MUXING_HEAD after output moov blob. michael@0: * michael@0: * MUXING_FRAG: michael@0: * It collects enough audio/video data to generate a fragment blob. This michael@0: * will be repeated until END_OF_STREAM and then transiting to MUXING_DONE. michael@0: * michael@0: * MUXING_DONE: michael@0: * End of ISOMediaWriter life cycle. michael@0: */ michael@0: enum MuxState { michael@0: MUXING_HEAD, michael@0: MUXING_FRAG, michael@0: MUXING_DONE, michael@0: }; michael@0: michael@0: private: michael@0: nsresult RunState(); michael@0: michael@0: // True if one of following conditions hold: michael@0: // 1. Audio/Video accumulates enough data to generate a moof. michael@0: // 2. Get EOS signal. michael@0: // aEOS will be assigned to true if it gets EOS signal. michael@0: bool ReadyToRunState(bool& aEOS); michael@0: michael@0: // The main class to generate and iso box. Its life time is same as michael@0: // ISOMediaWriter and deleted only if ISOMediaWriter is destroyed. michael@0: nsAutoPtr mControl; michael@0: michael@0: // Buffers to keep audio/video data frames, they are created when metadata is michael@0: // received. Only one instance for each media type is allowed and they will be michael@0: // deleted only if ISOMediaWriter is destroyed. michael@0: nsAutoPtr mAudioFragmentBuffer; michael@0: nsAutoPtr mVideoFragmentBuffer; michael@0: michael@0: MuxState mState; michael@0: michael@0: // A flag to indicate the output buffer is ready to blob out. michael@0: bool mBlobReady; michael@0: michael@0: // Combination of Audio_Track or Video_Track. michael@0: uint32_t mType; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: #endif // ISOMediaWriter_h_