# AndroidStreamingClient
**Repository Path**: xianleewu/AndroidStreamingClient
## Basic Information
- **Project Name**: AndroidStreamingClient
- **Description**: Library that receives UDP packets wrapped into RTP and coded in H264, decodes the corresponding frames and plays the resulting stream in an Android SurfaceView
- **Primary Language**: HTML
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2016-08-28
- **Last Updated**: 2020-12-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
#Android Streaming Client
##Introduction
###What it does?
**Android Streaming Client** is a library to play real time video in an Android device.
###How does it work
The current version of the code only supports RTP over UDP as the transport protocol and only decodes H264 encoded video.
**Android Streaming Client** uses [efflux library](https://github.com/brunodecarvalho/efflux) to create an underlying RTP session and listen to packages.
It includes two different approaches to handle the package arrival:
* *Min-delay*, which uses an RTP buffer that sends packets upstream for
processing immediately. Each packet will be sent upstream only if it is the one
being expected, hence this approach will work as long as the packages arrive in
order. If a received packet is newer than the one being expected, it will be
stored in order. Also, If stored packages are older than the configured threshold,
they will be discarded.
* *Time-window*, which uses an RTP buffer that keeps packets for a fixed amount
of time and moves forward at a fixed rate. The received packets are pushed
upstream in the same order and at a fixed rate. This approach uses two threads,
one for storing the packets that arrive to the client and another to consume
them with some wisdom.
##How do I use it
* Add the following dependency in your module's build.gradle file:
```
dependencies {
compile('com.creativa77:android_streaming_client:1.0.+')
}
```
> Version number may change.
* Import the library in your main activity
```
import com.c77.androidstreamingclient.lib.RtpMediaDecoder;
```
* On onCreate method, create a `Decoder` and start it
```
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// create an RtpMediaDecoder with the surface view where you want
// the video to be shown
RtpMediaDecoder rtpMediaDecoder = new RtpMediaDecoder(surfaceView);
// start it
rtpMediaDecoder.start();
...
}
```
* Remember to release the Decoder when onStop is called.
```
@Override
protected void onStop() {
...
// release decoder when application is stopped
rtpMediaDecoder.release();
...
}
```
##Video Publishers
###Libstreaming
Android Streaming Client can play video streamed by an Android library called
**libstreaming**. To give it a try, you can use the repositories used while
developing **Android Streaming Client** library.
Follow this steps:
* Clone libstreaming-examples fork:
```
> git clone https://github.com/ashyonline/libstreaming-examples
```
* Clone libstreaming inside libstreaming-examples's folder:
```
> git clone https://github.com/ashyonline/libstreaming
```
* Create an empty Android Studio project.
* Import [libstreaming](https://github.com/ashyonline/libstreaming) library in Android Studio as a module.
* Import [example4](https://github.com/ashyonline/libstreaming-examples/tree/master/example4) project as a module in Android Studio and add the libstreaming dependency to its build.gradle file:
```
dependencies {
compile project(':libstreaming')
}
```
* Clone **this** repository:
```
> git clone git@github.com:creativa77/AndroidStreamingClient.git
```
* Import [example](AndroidStreamingClient/tree/master/example) as a module in Android Studio.
* Check the IP address of the *player* device and change [this line](https://github.com/ashyonline/libstreaming-examples/blob/master/example4/src/net/majorkernelpanic/example4/MainActivity.java#L25) accordingly, so that the publisher knows where to stream the video to.
* Run example4 in the *publisher* Android device.
* Run the *example* module from **Android Streaming Client** in the *player* Android device.
If everything works, you will be streaming video from one device to another in real time.
##FFmpeg
* Generate a raw h264 file:
```
> ffmpeg –i sintel.mp4 –vcodec h264 –s 640*480 –an –f m4v sintel.h264
```
* Streaming:
```
> ffmpeg -re -i sintel.h264 -vcodec copy -f rtp rtp://192.168.0.112:5006
```
* Notice:
"192.168.0.112" is android client's ip address.
"5006" is android client's default port.
##Other video publishers
Be sure to point your video *publisher* to the device's IP where you are playing
video.
###Disclamer
So far, **Android Streaming Client** was tested with video streamed from
[libstreaming library](https://github.com/fyhertz/libstreaming) running in a
separate Android device. It uses a custom version of libstreaming which is
composed of the original libstreaming library plus a couple changes that fix
particular issues encountered while working on the **Android Streaming Client**
library.
##Content of the project
This project contains an Android library which source code is located in the
folder [android_streaming_client](https://github.com/creativa77/AndroidStreamingClient/tree/master/android_streaming_client) and an Android application that uses the library
located in the folder [example](https://github.com/creativa77/AndroidStreamingClient/tree/master/example). The [efflux folder](https://github.com/creativa77/AndroidStreamingClient/tree/master/efflux) includes the efflux library
source code.
Since **Android Streaming Client** was created using Android Studio, you will find
several gradle files that include dependencies, versions, and other project
configurations. The [license_script folder](https://github.com/creativa77/AndroidStreamingClient/tree/master/license_script) includes a script to apply the license
to every java file. You can also find the [LICENSE](https://github.com/creativa77/AndroidStreamingClient/blob/master/LICENCE) and [README](https://github.com/creativa77/AndroidStreamingClient/blob/master/README.md) files.
##Documentation
**Android Streaming Client** library documentation is located in [doc](https://github.com/creativa77/AndroidStreamingClient/tree/master/android_streaming_client/doc),
inside the [android_streaming_client](AndroidStreamingClient/tree/master/android_streaming_client) folder.
##Authors
Ayelen Chavez
Julian Cerruti
##Issues, bugs, feature requests
[Github issue tracker](https://github.com/creativa77/AndroidStreamingClient/issues/new)
##Licensing
This project uses code from [efflux library](https://github.com/brunodecarvalho/efflux) Copyright 2010 Bruno de Carvalho,
licensed under the Apache License, Version 2.0. Efflux author gave us full approval to use his library.
Android Streaming Client is licensed under the Apache License, Version 2.0.