Line data Source code
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 : #include "MediaElementAudioSourceNode.h"
8 : #include "mozilla/dom/MediaElementAudioSourceNodeBinding.h"
9 :
10 : namespace mozilla {
11 : namespace dom {
12 :
13 0 : MediaElementAudioSourceNode::MediaElementAudioSourceNode(AudioContext* aContext)
14 0 : : MediaStreamAudioSourceNode(aContext)
15 : {
16 0 : }
17 :
18 : /* static */ already_AddRefed<MediaElementAudioSourceNode>
19 0 : MediaElementAudioSourceNode::Create(AudioContext& aAudioContext,
20 : const MediaElementAudioSourceOptions& aOptions,
21 : ErrorResult& aRv)
22 : {
23 0 : if (aAudioContext.IsOffline()) {
24 0 : aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
25 0 : return nullptr;
26 : }
27 :
28 0 : if (aAudioContext.CheckClosed(aRv)) {
29 0 : return nullptr;
30 : }
31 :
32 : RefPtr<MediaElementAudioSourceNode> node =
33 0 : new MediaElementAudioSourceNode(&aAudioContext);
34 :
35 : RefPtr<DOMMediaStream> stream =
36 0 : aOptions.mMediaElement->CaptureAudio(aRv, aAudioContext.Destination()->Stream()->Graph());
37 0 : if (aRv.Failed()) {
38 0 : return nullptr;
39 : }
40 :
41 0 : node->Init(stream, aRv);
42 0 : if (aRv.Failed()) {
43 0 : return nullptr;
44 : }
45 :
46 0 : return node.forget();
47 : }
48 :
49 : JSObject*
50 0 : MediaElementAudioSourceNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
51 : {
52 0 : return MediaElementAudioSourceNodeBinding::Wrap(aCx, this, aGivenProto);
53 : }
54 :
55 : } // namespace dom
56 : } // namespace mozilla
|