3

I'm trying to build an app for Google Glass that can stream to a server and have a client view the stream via a web browser. So far it seems I need to do this via RTSP to a media server such as Wowza and then have a web server hosting some video player that views the RTMP stream but I'm not having much luck.

Using libstreaming (https://github.com/fyhertz/libstreaming) I'm never able to view the stream.

I also would be interested in doing something with WebRTC so that I could make a solution similar to Hangouts but am not sure there is any libraries that support this yet.

Any help is appreciated.

egfconnor
  • 2,637
  • 1
  • 26
  • 44
  • 1
    Google Glass connected to WebRTC: http://tech.pristine.io/pristine-presents-at-the-austin-gdg/ (thanks to [Arin Sime](http://www.realtimeweekly.com)) – Alex Cohn May 27 '14 at 08:11

1 Answers1

5

Since January, libsreaming has been fixed to work on Glass. Its RTSP video can easily be viewed in VLC player or plugin. Code below does not include the auto-generated stubs.

public class MainActivity extends Activity implements SurfaceHolder.Callback, Session.Callback {

private int mRtspPort = -1;

private ServiceConnection mRtspServerConnection = new ServiceConnection() {

    private static final int RTSP_PORT = 1234;

    @Override
    public void onServiceConnected(ComponentName className, IBinder binder) {
        RtspServer s = ((RtspServer.LocalBinder) binder).getService();
        s.setPort(RTSP_PORT);
        mRtspPort = s.getPort();
    }
  };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_main);

    // Configures the SessionBuilder
    SessionBuilder.getInstance()
            .setSurfaceView((SurfaceView) findViewById(R.id.surface))
            .setCallback(this)
            .setPreviewOrientation(90)
            .setContext(getApplicationContext())
            .setAudioEncoder(SessionBuilder.AUDIO_NONE)
            .setVideoEncoder(SessionBuilder.VIDEO_H264)
            .setVideoQuality(new VideoQuality(320, 240, 20, 500000));

    // Starts the RTSP server
    bindService(new Intent(this, RtspServer.class), mRtspServerConnection, Context.BIND_AUTO_CREATE);
}

@Override
public void onResume() {
    super.onResume();
    mResumed = true;
    displayConnectString();
    SessionBuilder.getInstance().getSurfaceView().setAspectRatioMode(SurfaceView.ASPECT_RATIO_PREVIEW);
    SessionBuilder.getInstance().getSurfaceView().getHolder().addCallback(this);
}

private void displayConnectString() {
    WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();
    String ipAddress = Formatter.formatIpAddress(ip);
    ((TextView) findViewById(R.id.connectInfo)).setText("rtsp://" + ipAddress + ":" + mRtspPort);
}

@Override
public void onDestroy() {
    super.onDestroy();
    unbindService(mRtspServerConnection);
}

@Override
public void onSessionStarted() {
    ((TextView) findViewById(R.id.connectInfo)).setText("");
}

@Override
public void onSessionStopped() {
    displayConnectString();
}
}
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • were you able to get the audio ? – uLYsseus May 05 '14 at 18:01
  • @Why-K-Rum: I was not concerned about audio. I don't know if audio is easy or not. **Note that there has been a major upgrade for Google Glass to KitKat, which is a gamechanger for video recording (MediaCodec may be used)** – Alex Cohn May 06 '14 at 10:03
  • Hi @AlexCohn, I can't do working this code on glass. I show 0.0.0.0 ip... I am connected to the network trough Bluetooth and MyGlass app...Any suggestion for this? If i use this code on a mobile or tablet, I can do working and see the streaming in VLC. Another problem, This only works in local network, when i disable wifi and i use 3G/LTE, this doesn't work, Why? Thanks a lot! – Bae May 08 '14 at 10:00
  • @Bae: **1.** in this code, we ask WiFi Manager for the IP address. Maybe you can get an address from the BT Manager. One thing is sure, **0.0.0.0** is not good. **2.** My cellular provider filters RTMP; furthermore, WiFi at Google Campus also filtered it; therefore, I needed a private WiFi access point to make the streaming from Glass to PC possible. – Alex Cohn May 08 '14 at 11:26
  • @Bae: I was able to stream video to vlc media player on my PC, glass and my PC were on the same wi-fi ....so are you saying that, you were able to stream with wi-fi and not with cellular connection? – uLYsseus May 08 '14 at 13:30
  • @AlexCohn: Understood....with this update, other media encodings were added to the glass ...I was just wondering why isnt audio coming out fine...I know that AAC encoding is supported ....but even that didnt work... – uLYsseus May 08 '14 at 13:33
  • @Why-K-Rum : My glass are paired by bluetooth with my mobile. My mobile is connected to a WiFi Network, so my glass use it trough my mobile. When i use the example 1 of this (https://github.com/fyhertz/libstreaming-examples) i see ip 0.0.0.0. I can't connect my glass to my Wifi network because it requiere user and password, and glass only let me connect with password so i need to use my mobile. Another question is that if i use a 3G/LTE network in my mobile i don't know how i can stream from glass (or other device) to VLC, it's seem like you need both devices are in the same network maybe? – Bae May 08 '14 at 14:04
  • @Bae: when you say both the devices does it mean the glass and the phone ? ...... – uLYsseus May 08 '14 at 14:13
  • @Why-K-Rum : Yes, glass and phone! But My first problem is that i don't know how i can get IP of glass which i can use in VLC like "rtsp://XX.XX.XX.XX:PORT" because it's my mobile which is connected to the WiFi network. – Bae May 08 '14 at 14:28
  • @Bae: im pretty sure that glass fetches ip address using DHCP by default ...so it must have an ip (remember: every networking device has an individual unique ip) ....which example are you using though example 1 or 2 or 3? and this might help you http://stackoverflow.com/questions/18918161/find-internet-ip-address-in-android-mobile-programmatically-no-need-device-ip – uLYsseus May 08 '14 at 14:45
  • @AlexCohn cant we use this library for inter newtwork streaming, it seems to only work for intra network streaming ... – uLYsseus May 08 '14 at 14:49
  • @Why-K-Rum : I am using example 1. I suposse if i could connect my glass to WiFi network i could get an IP with WifiManager, but my glass isn't connected to WiFi, it's paired with my phone and this is which has WiFi network. So i try to use the local ip of my mobile in the VLC. Can you try to disable WiFi of your glass, pair with your phone (with wifi) and try to do streaming in VLC (and which IP use)? – Bae May 08 '14 at 15:10
  • @Bae Quite frankly example 1 didnt make sense to me, before I try that right now, could you please tell me what are your trying to do ? and how are you doing that with example 1? are you trying to stream glass video to pc or are you trying to stream video to the glass? – uLYsseus May 08 '14 at 15:28
  • @Why-K-Rum : i want to stream glass video to PC. Before that I use that code in my Tablet. I run the Code (with my tablet in the same WiFi network that my PC), i open VLC, i click "Ctrl+N" and I introduce the URL: "rtsp://XX.XX.XX:1234" where XX.XX.XX.XX is the IP of my tablet in the local network. I click "Play" and I am streaming from my tablet to PC. It's work ok! Now I did the same with my glass, but WifiManager give me 0.0.0.0 as IP of glass because It isn't connected to Wifi (it's paired with my phone by bluetooth) so i can't stream from glass to PC. What do you do for getting this?? – Bae May 08 '14 at 15:39
  • @Bae which example are you using ? – uLYsseus May 08 '14 at 15:41
  • @Why-K-Rum : sorry, example 1 i am using. What example do you use? – Bae May 08 '14 at 15:44
  • @Bae:I dont see any menu options on example 1 ....example1 is a RSTP Server, not a client......example 2 is an example to stream to a public ip...example 3 is used to stream to a media server ....so im really not sure how are you doing this with example 1 ...is it example 2 whihc you are talking about. please clarify this to me so that I can try... – uLYsseus May 08 '14 at 15:50
  • 1
    @Why-K-Rum: With example 1, your device is like a RTSP server, so when you run it in a tablet and you do a connection in VLC like i said before (Ctrl+N and using rtsp://ip.of.the.tablet:PORT, where port is set to 1234 in code), your VLC is the client and your tablet start to streaming the camera to your VLC. So i am using **example 1**. I also try to use **example 2** in tablet but i only see green screen in VLC and when i tried to use it in my glass (example 2), I don't see anything in VLC because i don't get the IP of my glass (because of it's paired with my phone) – Bae May 08 '14 at 15:58
  • @Why-K-Rum using example 3. I follow this tutorial https://github.com/fyhertz/libstreaming/wiki/Using-libstreaming-with-Wowza-Media-Server#introduction but i don't get to do streaming from Nexus 7 to Wowza server and watching the video on VLC...I am using in a Local network so i suppose i don't need to forward any port... – Bae May 12 '14 at 15:55
  • @Why-K-Rum Hi! Now i am using example 3 and it's work on my mobile. When i use it in Glass, i don't get to see anything. I see in Logcat that No buffer available.. any suggestion?? – Bae May 13 '14 at 16:41
  • @Bae oops sorry I was pretty busy these days, I was about to suggest you that, glad that it worked out on your phone. Can you please post the logcat here... – uLYsseus May 13 '14 at 19:26
  • @Why-K-Rum Don't worry! Thanks for yours answers! I have already gotten it, i run it once with a low Quality (320x240, 15fp, 500 kbps). However if i run it twice, The TextView with KBPS doesn't update. I see in Logcat this `05-14 13:51:22.870: W/MessageQueue(27204): Handler (android.os.Handler) {20f352cc} sending message to a Handler on a dead thread`. Did you solve this? – Bae May 14 '14 at 11:53