-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
992 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
352 changes: 247 additions & 105 deletions
352
QNDroidRTCDemo/app/src/main/java/com/qiniu/droid/rtc/demo/activity/RoomActivity.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
QNDroidRTCDemo/app/src/main/java/com/qiniu/droid/rtc/demo/model/RTCRoomUsersMergeOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.qiniu.droid.rtc.demo.model; | ||
|
||
import com.qiniu.droid.rtc.QNTrackInfo; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RTCRoomUsersMergeOption { | ||
|
||
private Map<String, RTCUserMergeOptions> mRTCUserMap; | ||
private List<RTCUserMergeOptions> mRTCUsers; | ||
private List<RTCTrackMergeOption> mRTCVideoMergeOptions; | ||
|
||
public RTCRoomUsersMergeOption() { | ||
mRTCUserMap = new HashMap<>(); | ||
mRTCUsers = new ArrayList<>(); | ||
mRTCVideoMergeOptions = new ArrayList<>(); | ||
} | ||
|
||
public RTCUserMergeOptions getRoomUserByPosition(int pos) { | ||
return mRTCUsers.get(pos); | ||
} | ||
|
||
public RTCUserMergeOptions getRoomUserByUserId(String userId) { | ||
return mRTCUserMap.get(userId); | ||
} | ||
|
||
public List<RTCTrackMergeOption> getRTCVideoMergeOptions() { | ||
return mRTCVideoMergeOptions; | ||
} | ||
|
||
public List<RTCTrackMergeOption> getRTCAudioTracks() { | ||
List<RTCTrackMergeOption> rtcAudioTracks = new ArrayList<>(); | ||
for (RTCUserMergeOptions item : mRTCUsers) { | ||
if (item.getAudioTrack() != null) { | ||
rtcAudioTracks.add(item.getAudioTrack()); | ||
} | ||
} | ||
return rtcAudioTracks; | ||
} | ||
|
||
public void onUserJoined(String userId, String userData) { | ||
if (mRTCUserMap.get(userId) == null) { | ||
RTCUserMergeOptions userMergeOptions = new RTCUserMergeOptions(userId, userData); | ||
mRTCUserMap.put(userId, userMergeOptions); | ||
mRTCUsers.add(userMergeOptions); | ||
} | ||
} | ||
|
||
public void onUserLeft(String userId) { | ||
RTCUserMergeOptions userMergeOptions = mRTCUserMap.remove(userId); | ||
if (userMergeOptions != null) { | ||
mRTCUsers.remove(userMergeOptions); | ||
} | ||
} | ||
|
||
public void onTracksPublished(String userId, List<QNTrackInfo> trackInfoList) { | ||
RTCUserMergeOptions userMergeOptions = getRoomUserByUserId(userId); | ||
if (userMergeOptions == null) { | ||
return; | ||
} | ||
List<RTCTrackMergeOption> userVideoTracks = userMergeOptions.addTracks(trackInfoList); | ||
mRTCVideoMergeOptions.addAll(userVideoTracks); | ||
} | ||
|
||
public void onTracksUnPublished(String userId, List<QNTrackInfo> trackInfoList) { | ||
RTCUserMergeOptions userMergeOptions = getRoomUserByUserId(userId); | ||
if (userMergeOptions == null) { | ||
return; | ||
} | ||
List<RTCTrackMergeOption> userVideoTracks = userMergeOptions.removeTracks(trackInfoList); | ||
mRTCVideoMergeOptions.removeAll(userVideoTracks); | ||
} | ||
|
||
public int size() { | ||
return mRTCUsers.size(); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
QNDroidRTCDemo/app/src/main/java/com/qiniu/droid/rtc/demo/model/RTCTrackMergeOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.qiniu.droid.rtc.demo.model; | ||
|
||
import com.qiniu.droid.rtc.QNTrackInfo; | ||
import com.qiniu.droid.rtc.demo.utils.QNAppServer; | ||
import com.qiniu.droid.rtc.model.QNMergeTrackOption; | ||
|
||
public class RTCTrackMergeOption { | ||
|
||
private final String mTrackId; | ||
private final QNTrackInfo mQNTrackInfo; | ||
|
||
private boolean mTrackInclude = true; | ||
private final QNMergeTrackOption mQNMergeTrackOption; | ||
|
||
public RTCTrackMergeOption(QNTrackInfo QNTrackInfo) { | ||
mQNTrackInfo = QNTrackInfo; | ||
mTrackId = mQNTrackInfo.getTrackId(); | ||
|
||
mQNMergeTrackOption = new QNMergeTrackOption(); | ||
mQNMergeTrackOption.setWidth(QNAppServer.STREAMING_WIDTH); | ||
mQNMergeTrackOption.setHeight(QNAppServer.STREAMING_HEIGHT); | ||
mQNMergeTrackOption.setTrackId(mTrackId); | ||
} | ||
|
||
public String getTrackId() { | ||
return mTrackId; | ||
} | ||
|
||
public QNTrackInfo getQNTrackInfo() { | ||
return mQNTrackInfo; | ||
} | ||
|
||
public QNMergeTrackOption getQNMergeTrackOption() { | ||
return mQNMergeTrackOption; | ||
} | ||
|
||
public boolean isTrackInclude() { | ||
return mTrackInclude; | ||
} | ||
|
||
public void setTrackInclude(boolean trackInclude) { | ||
mTrackInclude = trackInclude; | ||
} | ||
|
||
public void updateQNMergeTrackOption(QNMergeTrackOption option) { | ||
if (option == null) { | ||
return; | ||
} | ||
mQNMergeTrackOption.setX(option.getX()); | ||
mQNMergeTrackOption.setY(option.getY()); | ||
mQNMergeTrackOption.setZ(option.getZ()); | ||
mQNMergeTrackOption.setWidth(option.getWidth()); | ||
mQNMergeTrackOption.setHeight(option.getHeight()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof RTCTrackMergeOption) { | ||
return mQNTrackInfo.equals(((RTCTrackMergeOption) obj).mQNTrackInfo); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return mQNTrackInfo.hashCode(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
QNDroidRTCDemo/app/src/main/java/com/qiniu/droid/rtc/demo/model/RTCUserMergeOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.qiniu.droid.rtc.demo.model; | ||
|
||
import com.qiniu.droid.rtc.QNRTCUser; | ||
import com.qiniu.droid.rtc.QNTrackInfo; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class RTCUserMergeOptions extends QNRTCUser { | ||
|
||
private RTCTrackMergeOption mAudioTrack; | ||
private List<RTCTrackMergeOption> mVideoTracks = new LinkedList<>(); | ||
|
||
public RTCUserMergeOptions(String userId, String userData) { | ||
super(userId, userData); | ||
} | ||
|
||
public RTCTrackMergeOption getAudioTrack() { | ||
return mAudioTrack; | ||
} | ||
|
||
public List<RTCTrackMergeOption> getVideoTracks() { | ||
return mVideoTracks; | ||
} | ||
|
||
public List<RTCTrackMergeOption> addTracks(List<QNTrackInfo> trackInfoList) { | ||
List<RTCTrackMergeOption> videoTracks = new ArrayList<>(); | ||
for (QNTrackInfo item : trackInfoList) { | ||
RTCTrackMergeOption newVideoTrack = addTrack(item); | ||
if (newVideoTrack != null) { | ||
videoTracks.add(newVideoTrack); | ||
} | ||
} | ||
return videoTracks; | ||
} | ||
|
||
private RTCTrackMergeOption addTrack(QNTrackInfo trackInfo) { | ||
if (trackInfo.isAudio()) { | ||
mAudioTrack = new RTCTrackMergeOption(trackInfo); | ||
return null; | ||
} else { | ||
RTCTrackMergeOption newVideoTrack = new RTCTrackMergeOption(trackInfo); | ||
// replace | ||
mVideoTracks.remove(newVideoTrack); | ||
mVideoTracks.add(newVideoTrack); | ||
return newVideoTrack; | ||
} | ||
} | ||
|
||
public List<RTCTrackMergeOption> removeTracks(List<QNTrackInfo> trackInfoList) { | ||
List<RTCTrackMergeOption> videoTracks = new ArrayList<>(); | ||
for (QNTrackInfo item : trackInfoList) { | ||
RTCTrackMergeOption removedVideoTrack = removeTracks(item); | ||
if (removedVideoTrack != null) { | ||
videoTracks.add(removedVideoTrack); | ||
} | ||
} | ||
return videoTracks; | ||
} | ||
|
||
private RTCTrackMergeOption removeTracks(QNTrackInfo trackInfo) { | ||
if (trackInfo.isAudio()) { | ||
mAudioTrack = null; | ||
return null; | ||
} else { | ||
RTCTrackMergeOption newUserTrack = new RTCTrackMergeOption(trackInfo); | ||
mVideoTracks.remove(newUserTrack); | ||
return newUserTrack; | ||
} | ||
} | ||
} |
Oops, something went wrong.