Skip to content

Commit 6a47096

Browse files
authored
feat: port the media file player example to the client API (#399)
* Let a local track's close be waited for LocalTrack.closeAsync completes once the native track is released, after which a source it was made over may be closed. * Port the media file player example to the client API One runtime in the CUSTOM audio mode replaces the two factories, a loopback signaling the hand-rolled offer, answer and candidate exchange, and the Swing VideoView the example's own panel. Statistics come from onStats, and a Record button records the received tracks with MediaRecorder.
1 parent 824670a commit 6a47096

7 files changed

Lines changed: 248 additions & 415 deletions

File tree

‎design/client-api.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,4 +811,5 @@ Next:
811811
- phase 2 is done: `Whip.to(...).publish(rtc)` and
812812
`Whep.from(...).play(rtc)` return sessions over `HttpURLConnection` (Java 8), and `VideoView` is in
813813
`dev.onvoid.webrtc.client.swing`;
814-
- porting the existing examples (phases 2 and 3).
814+
- porting the existing examples (phases 2 and 3); `MediaFilePlayerExample` is ported, with a
815+
Record button, and `LocalTrack.closeAsync()` came with it.

‎docs/guide/client-api.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ peer.addTrack(rtc.media().audioTrack("movie", file.getAudioSource()));
306306
file.play();
307307
```
308308

309-
Create the runtime before the file: the runtime loads the native library that the file's sources need. The sources belong to the `MediaFileSource`, not to the tracks, so close the runtime, or the tracks, before the file. The file's audio source is pushed audio, so the runtime needs the `CUSTOM` or `HEADLESS` audio mode.
309+
Create the runtime before the file: the runtime loads the native library that the file's sources need. The sources belong to the `MediaFileSource`, not to the tracks, so close the runtime, or the tracks, before the file: `track.closeAsync()` returns a future that completes once the track let go of its source. The file's audio source is pushed audio, so the runtime needs the `CUSTOM` or `HEADLESS` audio mode.
310310

311311
### Pushing Video and Audio
312312

‎docs/guide/examples.md‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,19 @@ mvn exec:java -D"exec.mainClass=dev.onvoid.webrtc.examples.MediaFileExample" -D"
100100

101101
## Media File Player
102102

103-
The [`MediaFilePlayerExample`](https://github.com/devopvoid/webrtc-java/blob/master/webrtc-examples/src/main/java/dev/onvoid/webrtc/examples/MediaFilePlayerExample.java) is a Swing application that sends a media file, or a live RTSP stream, from one peer connection to another in the same process, then shows the received video and plays the received audio in sync. Start and Stop buttons set up and tear down the whole session.
103+
The [`MediaFilePlayerExample`](https://github.com/devopvoid/webrtc-java/blob/master/webrtc-examples/src/main/java/dev/onvoid/webrtc/examples/MediaFilePlayerExample.java) is a Swing application built on the [Client API](/guide/client-api). It sends a media file, or a live RTSP stream, from one peer to another in the same process, then shows the received video and plays the received audio in sync, and records what is received. Start and Stop buttons set up and tear down the whole session, and Record starts and stops a recording.
104104

105105
**Key features demonstrated:**
106-
- Connecting two peer connections in one application, without a signaling server
107-
- Using one factory with a dummy audio layer to send the file, and another with the platform audio layer to play what is received
106+
- Sending the sources of a `MediaFileSource` as client API tracks, with `videoTrack` and `audioTrack`
107+
- Connecting two peers in one application through a loopback signaling
108+
- Using one runtime in the `CUSTOM` audio mode, which sends the file's audio and plays what is received
109+
- Running the peers' handlers on the Swing event dispatch thread
108110
- Keeping audio and video in sync by sending both tracks in the same media stream
109-
- Raising the video sender's `maxBitrate` above WebRTC's default, so a high-resolution file is not held to a fraction of its size
110-
- Rendering received video frames in a Swing component with `VideoBufferConverter`
111-
- Showing the source's format, the playback position, and live receive metrics (codec, resolution, frame rate, bitrate, packet loss, jitter, audio level) read from `getStats()`
112-
- Releasing senders, peer connections, tracks and the source in order on Stop
111+
- Raising the video sender's maximum bitrate once it is connected, so a high-resolution file is not held to a fraction of its size
112+
- Rendering received video in the Swing `VideoView`
113+
- Showing the source's format, the playback position, and live receive metrics (codec, resolution, frame rate, bitrate, packet loss, jitter, audio level) read from `onStats`
114+
- Recording the received tracks into a Matroska file with `MediaRecorder`
115+
- Closing the peers, then the tracks, then the source on Stop
113116

114117
::: info
115118
Like the [Media File](#media-file) example, this one needs the `webrtc-java-media` module. The source argument is optional; a file can also be chosen from the window, or a stream URL typed into it. A stream URL's credentials are never shown, and the Loop box is disabled while a live stream plays, since it has no length to start over from.

0 commit comments

Comments
 (0)