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