1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "MediaStreamWindowCapturer.h"
8 #include "AudioStreamTrack.h"
9 #include "DOMMediaStream.h"
10 #include "MediaTrackGraph.h"
13 using dom::AudioStreamTrack
;
14 using dom::MediaStreamTrack
;
16 MediaStreamWindowCapturer::CapturedTrack::CapturedTrack(
17 MediaStreamTrack
* aTrack
, uint64_t aWindowID
)
19 mPort(aTrack
->Graph()->ConnectToCaptureTrack(aWindowID
,
20 aTrack
->GetTrack())) {}
22 MediaStreamWindowCapturer::CapturedTrack::~CapturedTrack() {
28 MediaStreamWindowCapturer::MediaStreamWindowCapturer(DOMMediaStream
* aStream
,
30 : mStream(aStream
), mWindowId(aWindowId
) {
31 mStream
->RegisterTrackListener(this);
32 nsTArray
<RefPtr
<AudioStreamTrack
>> tracks
;
33 mStream
->GetAudioTracks(tracks
);
34 for (const auto& t
: tracks
) {
42 MediaStreamWindowCapturer::~MediaStreamWindowCapturer() {
44 mStream
->UnregisterTrackListener(this);
48 void MediaStreamWindowCapturer::NotifyTrackAdded(
49 const RefPtr
<MediaStreamTrack
>& aTrack
) {
50 if (AudioStreamTrack
* at
= aTrack
->AsAudioStreamTrack()) {
55 void MediaStreamWindowCapturer::NotifyTrackRemoved(
56 const RefPtr
<MediaStreamTrack
>& aTrack
) {
57 if (AudioStreamTrack
* at
= aTrack
->AsAudioStreamTrack()) {
62 void MediaStreamWindowCapturer::AddTrack(AudioStreamTrack
* aTrack
) {
63 if (aTrack
->Ended()) {
66 mTracks
.AppendElement(MakeUnique
<CapturedTrack
>(aTrack
, mWindowId
));
69 void MediaStreamWindowCapturer::RemoveTrack(AudioStreamTrack
* aTrack
) {
70 for (size_t i
= mTracks
.Length(); i
> 0; --i
) {
71 if (mTracks
[i
- 1]->mTrack
== aTrack
) {
72 mTracks
.RemoveElementAt(i
- 1);
77 } // namespace mozilla