summaryrefslogtreecommitdiff
path: root/dom/tv/TVTuner.h
blob: 50d1531ad4e82d40a7fbb46ff8b3d7690092da2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_TVTuner_h
#define mozilla_dom_TVTuner_h

#include "mozilla/DOMEventTargetHelper.h"
// Include TVTunerBinding.h since enum TVSourceType can't be forward declared.
#include "mozilla/dom/TVTunerBinding.h"

class nsITVService;
class nsITVTunerData;

namespace mozilla {

class DOMMediaStream;

namespace dom {

class Promise;
class TVSource;

class TVTuner final : public DOMEventTargetHelper
{
public:
  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TVTuner, DOMEventTargetHelper)

  static already_AddRefed<TVTuner> Create(nsPIDOMWindow* aWindow,
                                          nsITVTunerData* aData);

  // WebIDL (internal functions)

  virtual JSObject* WrapObject(JSContext *aCx) override;

  nsresult SetCurrentSource(TVSourceType aSourceType);

  nsresult DispatchTVEvent(nsIDOMEvent* aEvent);

  // WebIDL (public APIs)

  void GetSupportedSourceTypes(nsTArray<TVSourceType>& aSourceTypes,
                               ErrorResult& aRv) const;

  already_AddRefed<Promise> GetSources(ErrorResult& aRv);

  already_AddRefed<Promise> SetCurrentSource(const TVSourceType aSourceType,
                                             ErrorResult& aRv);

  void GetId(nsAString& aId) const;

  already_AddRefed<TVSource> GetCurrentSource() const;

  already_AddRefed<DOMMediaStream> GetStream() const;

  IMPL_EVENT_HANDLER(currentsourcechanged);

private:
  explicit TVTuner(nsPIDOMWindow* aWindow);

  ~TVTuner();

  bool Init(nsITVTunerData* aData);

  nsresult InitMediaStream();

  nsresult DispatchCurrentSourceChangedEvent(TVSource* aSource);

  nsCOMPtr<nsITVService> mTVService;
  nsRefPtr<DOMMediaStream> mStream;
  nsRefPtr<TVSource> mCurrentSource;
  nsTArray<nsRefPtr<TVSource>> mSources;
  nsString mId;
  nsTArray<TVSourceType> mSupportedSourceTypes;
};

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_TVTuner_h