Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: webrtc/api/java/src/org/webrtc/MediaStream.java

Issue 2111823002: Combine webrtc/api/java/android and webrtc/api/java/src. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 package org.webrtc;
12
13 import java.util.LinkedList;
14
15 /** Java wrapper for a C++ MediaStreamInterface. */
16 public class MediaStream {
17 public final LinkedList<AudioTrack> audioTracks;
18 public final LinkedList<VideoTrack> videoTracks;
19 public final LinkedList<VideoTrack> preservedVideoTracks;
20 // Package-protected for PeerConnection.
21 final long nativeStream;
22
23 public MediaStream(long nativeStream) {
24 audioTracks = new LinkedList<AudioTrack>();
25 videoTracks = new LinkedList<VideoTrack>();
26 preservedVideoTracks = new LinkedList<VideoTrack>();
27 this.nativeStream = nativeStream;
28 }
29
30 public boolean addTrack(AudioTrack track) {
31 if (nativeAddAudioTrack(nativeStream, track.nativeTrack)) {
32 audioTracks.add(track);
33 return true;
34 }
35 return false;
36 }
37
38 public boolean addTrack(VideoTrack track) {
39 if (nativeAddVideoTrack(nativeStream, track.nativeTrack)) {
40 videoTracks.add(track);
41 return true;
42 }
43 return false;
44 }
45
46 // Tracks added in addTrack() call will be auto released once MediaStream.disp ose()
47 // is called. If video track need to be preserved after MediaStream is destroy ed it
48 // should be added to MediaStream using addPreservedTrack() call.
49 public boolean addPreservedTrack(VideoTrack track) {
50 if (nativeAddVideoTrack(nativeStream, track.nativeTrack)) {
51 preservedVideoTracks.add(track);
52 return true;
53 }
54 return false;
55 }
56
57 public boolean removeTrack(AudioTrack track) {
58 audioTracks.remove(track);
59 return nativeRemoveAudioTrack(nativeStream, track.nativeTrack);
60 }
61
62 public boolean removeTrack(VideoTrack track) {
63 videoTracks.remove(track);
64 preservedVideoTracks.remove(track);
65 return nativeRemoveVideoTrack(nativeStream, track.nativeTrack);
66 }
67
68 public void dispose() {
69 // Remove and release previously added audio and video tracks.
70 while (!audioTracks.isEmpty()) {
71 AudioTrack track = audioTracks.getFirst();
72 removeTrack(track);
73 track.dispose();
74 }
75 while (!videoTracks.isEmpty()) {
76 VideoTrack track = videoTracks.getFirst();
77 removeTrack(track);
78 track.dispose();
79 }
80 // Remove, but do not release preserved video tracks.
81 while (!preservedVideoTracks.isEmpty()) {
82 removeTrack(preservedVideoTracks.getFirst());
83 }
84 free(nativeStream);
85 }
86
87 public String label() {
88 return nativeLabel(nativeStream);
89 }
90
91 public String toString() {
92 return "[" + label() + ":A=" + audioTracks.size() +
93 ":V=" + videoTracks.size() + "]";
94 }
95
96 private static native boolean nativeAddAudioTrack(
97 long nativeStream, long nativeAudioTrack);
98
99 private static native boolean nativeAddVideoTrack(
100 long nativeStream, long nativeVideoTrack);
101
102 private static native boolean nativeRemoveAudioTrack(
103 long nativeStream, long nativeAudioTrack);
104
105 private static native boolean nativeRemoveVideoTrack(
106 long nativeStream, long nativeVideoTrack);
107
108 private static native String nativeLabel(long nativeStream);
109
110 private static native void free(long nativeStream);
111 }
OLDNEW
« no previous file with comments | « webrtc/api/java/src/org/webrtc/MediaSource.java ('k') | webrtc/api/java/src/org/webrtc/MediaStreamTrack.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698