ImageTrack.h (3050B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 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_dom_ImageTrack_h 8 #define mozilla_dom_ImageTrack_h 9 10 #include "FrameTimeout.h" 11 #include "mozilla/ErrorResult.h" 12 #include "mozilla/dom/ImageDecoderBinding.h" 13 #include "nsCycleCollectionParticipant.h" 14 #include "nsTArray.h" 15 #include "nsWrapperCache.h" 16 17 class nsIGlobalObject; 18 19 namespace mozilla { 20 namespace image { 21 struct DecodeFrameCountResult; 22 struct DecodeFramesResult; 23 } // namespace image 24 25 namespace dom { 26 class ImageTrackList; 27 class VideoFrame; 28 29 class ImageTrack final : public nsISupports, public nsWrapperCache { 30 public: 31 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 32 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(ImageTrack) 33 34 public: 35 ImageTrack(ImageTrackList* aTrackList, int32_t aIndex, 36 nsTArray<ImageSize>&& aNativeSizes, bool aSelected, bool aAnimated, 37 uint32_t aFrameCount, bool aFrameCountComplete, 38 float aRepetitionCount); 39 40 protected: 41 ~ImageTrack(); 42 43 public: 44 nsIGlobalObject* GetParentObject() const { return mParent; } 45 46 void Destroy(); 47 48 JSObject* WrapObject(JSContext* aCx, 49 JS::Handle<JSObject*> aGivenProto) override; 50 51 int32_t Index() const { return mIndex; } 52 53 bool Animated() const { return mAnimated; } 54 55 uint32_t FrameCount() const { return mFrameCount; } 56 57 bool FrameCountComplete() const { return mFrameCountComplete; } 58 59 float RepetitionCount() const { return mRepetitionCount; } 60 61 bool Selected() const { return mSelected; } 62 63 void SetSelected(bool aSelected); 64 65 void GetSizes(nsTArray<ImageSize>& aSizes); 66 67 void ClearSelected() { mSelected = false; } 68 void MarkSelected() { mSelected = true; } 69 70 size_t DecodedFrameCount() const { return mDecodedFrames.Length(); } 71 72 bool DecodedFramesComplete() const { return mDecodedFramesComplete; } 73 74 VideoFrame* GetDecodedFrame(uint32_t aIndex) const { 75 if (mDecodedFrames.Length() <= aIndex) { 76 return nullptr; 77 } 78 return mDecodedFrames[aIndex]; 79 } 80 81 void OnFrameCountSuccess(const image::DecodeFrameCountResult& aResult); 82 void OnDecodeFramesSuccess(const image::DecodeFramesResult& aResult); 83 84 private: 85 // ImageTrack can run on either main thread or worker thread. 86 void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(ImageTrack); } 87 88 nsCOMPtr<nsIGlobalObject> mParent; 89 RefPtr<ImageTrackList> mTrackList; 90 AutoTArray<RefPtr<VideoFrame>, 1> mDecodedFrames; 91 nsTArray<ImageSize> mNativeSizes; 92 image::FrameTimeout mFramesTimestamp; 93 int32_t mIndex = 0; 94 float mRepetitionCount = 0.0f; 95 uint32_t mFrameCount = 0; 96 bool mFrameCountComplete = false; 97 bool mDecodedFramesComplete = false; 98 bool mAnimated = false; 99 bool mSelected = false; 100 }; 101 102 } // namespace dom 103 } // namespace mozilla 104 105 #endif // mozilla_dom_ImageTrack_h