MediaTrack.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:set ts=2 sw=2 et tw=78: */
  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. #ifndef mozilla_dom_MediaTrack_h
  7. #define mozilla_dom_MediaTrack_h
  8. #include "mozilla/DOMEventTargetHelper.h"
  9. namespace mozilla {
  10. namespace dom {
  11. class MediaTrackList;
  12. class VideoTrack;
  13. class AudioTrack;
  14. /**
  15. * Base class of AudioTrack and VideoTrack. The AudioTrack and VideoTrack
  16. * objects represent specific tracks of a media resource. Each track has aspects
  17. * of an identifier, category, label, and language, even if a track is removed
  18. * from its corresponding track list, those aspects do not change.
  19. *
  20. * When fetching the media resource, an audio/video track is created if the
  21. * media resource is found to have an audio/video track. When the UA has learned
  22. * that an audio/video track has ended, this audio/video track will be removed
  23. * from its corresponding track list.
  24. *
  25. * Although AudioTrack and VideoTrack are not EventTargets, TextTrack is, and
  26. * TextTrack inherits from MediaTrack as well (or is going to).
  27. */
  28. class MediaTrack : public DOMEventTargetHelper
  29. {
  30. public:
  31. MediaTrack(const nsAString& aId,
  32. const nsAString& aKind,
  33. const nsAString& aLabel,
  34. const nsAString& aLanguage);
  35. NS_DECL_ISUPPORTS_INHERITED
  36. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaTrack, DOMEventTargetHelper)
  37. enum {
  38. DEFAULT = 0,
  39. FIRE_NO_EVENTS = 1 << 0,
  40. };
  41. // The default behavior of enabling an audio track or selecting a video track
  42. // fires a change event and notifies its media resource about the changes.
  43. // It should not fire any events when fetching media resource.
  44. virtual void SetEnabledInternal(bool aEnabled, int aFlags) = 0;
  45. virtual AudioTrack* AsAudioTrack()
  46. {
  47. return nullptr;
  48. }
  49. virtual VideoTrack* AsVideoTrack()
  50. {
  51. return nullptr;
  52. }
  53. const nsString& GetId() const
  54. {
  55. return mId;
  56. }
  57. // WebIDL
  58. void GetId(nsAString& aId) const
  59. {
  60. aId = mId;
  61. }
  62. void GetKind(nsAString& aKind) const
  63. {
  64. aKind = mKind;
  65. }
  66. void GetLabel(nsAString& aLabel) const
  67. {
  68. aLabel = mLabel;
  69. }
  70. void GetLanguage(nsAString& aLanguage) const
  71. {
  72. aLanguage = mLanguage;
  73. }
  74. friend class MediaTrackList;
  75. protected:
  76. virtual ~MediaTrack();
  77. void SetTrackList(MediaTrackList* aList);
  78. void Init(nsPIDOMWindowInner* aOwnerWindow);
  79. RefPtr<MediaTrackList> mList;
  80. nsString mId;
  81. nsString mKind;
  82. nsString mLabel;
  83. nsString mLanguage;
  84. };
  85. } // namespace dom
  86. } // namespace mozilla
  87. #endif // mozilla_dom_MediaTrack_h