MediaSourceDecoder.h (3300B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_MEDIASOURCEDECODER_H_ 8 #define MOZILLA_MEDIASOURCEDECODER_H_ 9 10 #include "MediaDecoder.h" 11 #include "mozilla/RefPtr.h" 12 #include "mozilla/dom/MediaDebugInfoBinding.h" 13 14 namespace mozilla { 15 16 class MediaDecoderStateMachineBase; 17 class MediaSourceDemuxer; 18 19 namespace dom { 20 21 class MediaSource; 22 23 } // namespace dom 24 25 DDLoggedTypeDeclNameAndBase(MediaSourceDecoder, MediaDecoder); 26 27 class MediaSourceDecoder : public MediaDecoder, 28 public DecoderDoctorLifeLogger<MediaSourceDecoder> { 29 public: 30 explicit MediaSourceDecoder(MediaDecoderInit& aInit); 31 32 nsresult Load(nsIPrincipal* aPrincipal); 33 media::TimeIntervals GetSeekable() override; 34 media::TimeRanges GetSeekableTimeRanges() override; 35 media::TimeIntervals GetBuffered() override; 36 37 void Shutdown() override; 38 39 void AttachMediaSource(dom::MediaSource* aMediaSource); 40 void DetachMediaSource(); 41 42 void Ended(bool aEnded); 43 44 // Return the duration of the video in seconds. 45 double GetDuration() override; 46 47 void SetInitialDuration(const media::TimeUnit& aDuration); 48 void SetMediaSourceDuration(const media::TimeUnit& aDuration); 49 void SetMediaSourceDuration(double aDuration); 50 51 MediaSourceDemuxer* GetDemuxer() { return mDemuxer; } 52 53 already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override; 54 55 bool HadCrossOriginRedirects() override; 56 57 bool IsTransportSeekable() override { return true; } 58 59 // Requests that the MediaSourceDecoder populates aInfo with debug 60 // information. This may be done asynchronously, and aInfo should *not* be 61 // accessed by the caller until the returned promise is resolved or rejected. 62 RefPtr<GenericPromise> RequestDebugInfo( 63 dom::MediaSourceDecoderDebugInfo& aInfo); 64 65 void AddSizeOfResources(ResourceSizes* aSizes) override; 66 67 MediaDecoderOwner::NextFrameStatus NextFrameBufferedStatus() override; 68 69 bool IsMSE() const override { return true; } 70 71 void NotifyInitDataArrived(); 72 73 // Called as data appended to the source buffer or EOS is called on the media 74 // source. Main thread only. 75 void NotifyDataArrived(); 76 77 private: 78 MediaDecoderStateMachineBase* CreateStateMachine( 79 bool aDisableExternalEngine) override; 80 81 template <typename IntervalType> 82 IntervalType GetSeekableImpl(); 83 84 void DoSetMediaSourceDuration(double aDuration); 85 media::TimeInterval ClampIntervalToEnd(const media::TimeInterval& aInterval); 86 bool CanPlayThroughImpl() override; 87 88 #ifdef MOZ_WMF_MEDIA_ENGINE 89 void MetadataLoaded(UniquePtr<MediaInfo> aInfo, UniquePtr<MetadataTags> aTags, 90 MediaDecoderEventVisibility aEventVisibility) override; 91 #endif 92 93 RefPtr<nsIPrincipal> mPrincipal; 94 95 // The owning MediaSource holds a strong reference to this decoder, and 96 // calls Attach/DetachMediaSource on this decoder to set and clear 97 // mMediaSource. 98 dom::MediaSource* mMediaSource; 99 RefPtr<MediaSourceDemuxer> mDemuxer; 100 101 bool mEnded; 102 }; 103 104 } // namespace mozilla 105 106 #endif /* MOZILLA_MEDIASOURCEDECODER_H_ */