webrtc_m130/sdk/android/api/org/webrtc/MediaStream.java

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
3.4 KiB
Java
Raw Normal View History

/*
* Copyright 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
package org.webrtc;
import java.util.LinkedList;
/** Java wrapper for a C++ MediaStreamInterface. */
public class MediaStream {
PeerConnection shutdown-time fixes - TCPPort::~TCPPort() was leaking incoming_ sockets; now they are deleted. - PeerConnection::RemoveStream() now removes streams even if the PeerConnection::IsClosed(). Previously such streams would never get removed. - Gave MediaStreamTrackInterface a virtual destructor to ensure deletes on base pointers are dispatched virtually. - VideoTrack.dispose() delegates to super.dispose() (instead of leaking) - PeerConnection.dispose() now removes streams before disposing of them. - MediaStream.dispose() now removes tracks before disposing of them. - VideoCapturer.dispose() only unowned VideoCapturers (mirroring C++ API) - AppRTCDemo.disconnectAndExit() now correctly .dispose()s its VideoSource and PeerConnectionFactory. - CHECK that Release()d objects are deleted when expected to (i.e. no ref-cycles or missing .dispose() calls) in the Java API. - Create & Return webrtc::Traces at factory birth/death to be able to assert that _all_ threads started during the test are collected by the end. - Name threads attached to the JVM more informatively for debugging. - Removed a bunch of unnecessary scoped_refptr instances in peerconnection_jni.cc whose only job was messing with refcounts. RISK=P2 TESTED=AppRTCDemo can be ended and restarted just fine instead of crashing on camera unavailability. No more post-app-exit logcat lines. PCTest.java now asserts that all threads are collected before exit. BUG=2183 R=wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2005004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4534 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-08-12 23:26:21 +00:00
public final LinkedList<AudioTrack> audioTracks;
public final LinkedList<VideoTrack> videoTracks;
public final LinkedList<VideoTrack> preservedVideoTracks;
PeerConnection shutdown-time fixes - TCPPort::~TCPPort() was leaking incoming_ sockets; now they are deleted. - PeerConnection::RemoveStream() now removes streams even if the PeerConnection::IsClosed(). Previously such streams would never get removed. - Gave MediaStreamTrackInterface a virtual destructor to ensure deletes on base pointers are dispatched virtually. - VideoTrack.dispose() delegates to super.dispose() (instead of leaking) - PeerConnection.dispose() now removes streams before disposing of them. - MediaStream.dispose() now removes tracks before disposing of them. - VideoCapturer.dispose() only unowned VideoCapturers (mirroring C++ API) - AppRTCDemo.disconnectAndExit() now correctly .dispose()s its VideoSource and PeerConnectionFactory. - CHECK that Release()d objects are deleted when expected to (i.e. no ref-cycles or missing .dispose() calls) in the Java API. - Create & Return webrtc::Traces at factory birth/death to be able to assert that _all_ threads started during the test are collected by the end. - Name threads attached to the JVM more informatively for debugging. - Removed a bunch of unnecessary scoped_refptr instances in peerconnection_jni.cc whose only job was messing with refcounts. RISK=P2 TESTED=AppRTCDemo can be ended and restarted just fine instead of crashing on camera unavailability. No more post-app-exit logcat lines. PCTest.java now asserts that all threads are collected before exit. BUG=2183 R=wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2005004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4534 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-08-12 23:26:21 +00:00
// Package-protected for PeerConnection.
final long nativeStream;
public MediaStream(long nativeStream) {
audioTracks = new LinkedList<AudioTrack>();
videoTracks = new LinkedList<VideoTrack>();
preservedVideoTracks = new LinkedList<VideoTrack>();
this.nativeStream = nativeStream;
}
public boolean addTrack(AudioTrack track) {
if (nativeAddAudioTrack(nativeStream, track.nativeTrack)) {
audioTracks.add(track);
return true;
}
return false;
}
public boolean addTrack(VideoTrack track) {
if (nativeAddVideoTrack(nativeStream, track.nativeTrack)) {
videoTracks.add(track);
return true;
}
return false;
}
// Tracks added in addTrack() call will be auto released once MediaStream.dispose()
// is called. If video track need to be preserved after MediaStream is destroyed it
// should be added to MediaStream using addPreservedTrack() call.
public boolean addPreservedTrack(VideoTrack track) {
if (nativeAddVideoTrack(nativeStream, track.nativeTrack)) {
preservedVideoTracks.add(track);
return true;
}
return false;
}
public boolean removeTrack(AudioTrack track) {
audioTracks.remove(track);
return nativeRemoveAudioTrack(nativeStream, track.nativeTrack);
}
public boolean removeTrack(VideoTrack track) {
videoTracks.remove(track);
preservedVideoTracks.remove(track);
return nativeRemoveVideoTrack(nativeStream, track.nativeTrack);
}
public void dispose() {
// Remove and release previously added audio and video tracks.
PeerConnection shutdown-time fixes - TCPPort::~TCPPort() was leaking incoming_ sockets; now they are deleted. - PeerConnection::RemoveStream() now removes streams even if the PeerConnection::IsClosed(). Previously such streams would never get removed. - Gave MediaStreamTrackInterface a virtual destructor to ensure deletes on base pointers are dispatched virtually. - VideoTrack.dispose() delegates to super.dispose() (instead of leaking) - PeerConnection.dispose() now removes streams before disposing of them. - MediaStream.dispose() now removes tracks before disposing of them. - VideoCapturer.dispose() only unowned VideoCapturers (mirroring C++ API) - AppRTCDemo.disconnectAndExit() now correctly .dispose()s its VideoSource and PeerConnectionFactory. - CHECK that Release()d objects are deleted when expected to (i.e. no ref-cycles or missing .dispose() calls) in the Java API. - Create & Return webrtc::Traces at factory birth/death to be able to assert that _all_ threads started during the test are collected by the end. - Name threads attached to the JVM more informatively for debugging. - Removed a bunch of unnecessary scoped_refptr instances in peerconnection_jni.cc whose only job was messing with refcounts. RISK=P2 TESTED=AppRTCDemo can be ended and restarted just fine instead of crashing on camera unavailability. No more post-app-exit logcat lines. PCTest.java now asserts that all threads are collected before exit. BUG=2183 R=wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2005004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4534 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-08-12 23:26:21 +00:00
while (!audioTracks.isEmpty()) {
AudioTrack track = audioTracks.getFirst();
removeTrack(track);
track.dispose();
}
PeerConnection shutdown-time fixes - TCPPort::~TCPPort() was leaking incoming_ sockets; now they are deleted. - PeerConnection::RemoveStream() now removes streams even if the PeerConnection::IsClosed(). Previously such streams would never get removed. - Gave MediaStreamTrackInterface a virtual destructor to ensure deletes on base pointers are dispatched virtually. - VideoTrack.dispose() delegates to super.dispose() (instead of leaking) - PeerConnection.dispose() now removes streams before disposing of them. - MediaStream.dispose() now removes tracks before disposing of them. - VideoCapturer.dispose() only unowned VideoCapturers (mirroring C++ API) - AppRTCDemo.disconnectAndExit() now correctly .dispose()s its VideoSource and PeerConnectionFactory. - CHECK that Release()d objects are deleted when expected to (i.e. no ref-cycles or missing .dispose() calls) in the Java API. - Create & Return webrtc::Traces at factory birth/death to be able to assert that _all_ threads started during the test are collected by the end. - Name threads attached to the JVM more informatively for debugging. - Removed a bunch of unnecessary scoped_refptr instances in peerconnection_jni.cc whose only job was messing with refcounts. RISK=P2 TESTED=AppRTCDemo can be ended and restarted just fine instead of crashing on camera unavailability. No more post-app-exit logcat lines. PCTest.java now asserts that all threads are collected before exit. BUG=2183 R=wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2005004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4534 4adac7df-926f-26a2-2b94-8c16560cd09d
2013-08-12 23:26:21 +00:00
while (!videoTracks.isEmpty()) {
VideoTrack track = videoTracks.getFirst();
removeTrack(track);
track.dispose();
}
// Remove, but do not release preserved video tracks.
while (!preservedVideoTracks.isEmpty()) {
removeTrack(preservedVideoTracks.getFirst());
}
free(nativeStream);
}
public String label() {
return nativeLabel(nativeStream);
}
@Override
public String toString() {
return "[" + label() + ":A=" + audioTracks.size() + ":V=" + videoTracks.size() + "]";
}
private static native boolean nativeAddAudioTrack(long nativeStream, long nativeAudioTrack);
private static native boolean nativeAddVideoTrack(long nativeStream, long nativeVideoTrack);
private static native boolean nativeRemoveAudioTrack(long nativeStream, long nativeAudioTrack);
private static native boolean nativeRemoveVideoTrack(long nativeStream, long nativeVideoTrack);
private static native String nativeLabel(long nativeStream);
private static native void free(long nativeStream);
}