Android code to Broadcast live audio stream from phone [duplicate] - java

The code is only streaming for one user at a time. Can anyone help me to play the stream in more than one system at the same time(convert it to multicast or broadcast).
Thanks in advance.
The library source is over here:
https://github.com/fyhertz/libstreaming
my current code is:
mSurfaceView = (net.majorkernelpanic.streaming.gl.SurfaceView) findViewById(R.id.surface);
// Sets the port of the RTSP server to 1234
Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString(RtspServer.KEY_PORT, String.valueOf(5060)); // audio port num
editor.commit();
// Configures the SessionBuilde
SessionBuilder.getInstance()
.setSurfaceView(mSurfaceView)
.setPreviewOrientation(90)
.setContext(getApplicationContext())
.setAudioEncoder(SessionBuilder.AUDIO_AAC)
.setVideoEncoder(SessionBuilder.VIDEO_NONE);
MainActivity.this.startService(new Intent(MainActivity.this,RtspServer.class));

I looked at the code at github and seems that you only need to specify the multicast address to the SessionBuilder class and then the underlying RTSP server and RTP transport should handle everything (at least the RTSP responses seem have code to produce correct transport descriptions). So I guess adding a setDestination call to your SessionBuilder configuration should be ok (replace the 232.0.1.2 with the address you need):
// Configures the SessionBuilde
SessionBuilder.getInstance()
.setSurfaceView(mSurfaceView)
.setPreviewOrientation(90)
.setContext(getApplicationContext())
.setAudioEncoder(SessionBuilder.AUDIO_AAC)
.setVideoEncoder(SessionBuilder.VIDEO_NONE)
.setDestination("232.0.1.2");
The clients will still connect to the RTSP server through it's address but the actual RTP stream should be single and shared among all the clients.

Related

Discover BACnet device in different network with bacnet4j

I am using bacnet4j library to discover Remote BACnet devices. In the same network, everything is working as expected. But I could not find the BACnet controller device located in the different network.
String hostAddress="10.8.102.28";
IpNetwork network = new IpNetworkBuilder().withPort(47808).withSubnet(hostAddress, 24).build();
Transport transport = new DefaultTransport(network);
LocalDevice localDevice = new LocalDevice(Integer.decode(this.settings.getDeviceId()), transport);
localDevice.initialize();
//Finding remote device
int remoteId=1234;
RemoteDeviceFuture remoteFuture = RemoteDeviceFinder.findDevice(localDevice, remoteId);
RemoteDevice remoteDevice = null;
try {
remoteDevice = remoteFuture.get(); //remote device is null here
} catch (Exception e) {
LOGGER.error("Remote device with id " + remoteId + " does NOT exist!");
}
The above code snippet finds remote device with a given remoteId in the same network. But it can not find a device located in different network. Is there anything wrong here?
That is actually by design. The discovery process takes place using broadcast "Who-Is" messages that are not routed via IP routers. So any devices on a different IP subnet are not discovered this way. If you know the IP address of the remote device, you may be able to configure/program the IP directly as a static IP address.
However, there is something called a BBMD (BACnet Broadcast Management Device). One of these needs to be placed on each subnet, each configured with the IP address of the other BBMD. The BBMDs will intercept the BACnet related broadcasts on its subnet, send it across to the peer BBMD on the other subnet, which will retransmit the broadcast, effectively bridging the two (or more) subnets.
OR, your could configure/program your client as a "Foreign Device", have it register with a BBMD on the far subnet, which will achieve much the same.
BBMDs are fairly common. Most (all) BACnet/IP to BACnet MS/TP routers have the functionality. A lot of BACnet devices also allow the functionality to be enabled.
Hope this helps. See http://www.bacnetwiki.com for more.
UDP/IP Broadcasts - that are used as part of the 'Who-Is' (BACnet) service, generally are not routed by default and in most cases will not be allowed to be routed - e.g. security concerns been the main reason.
But if routing is in place, you could send unicast/directed traffic to the device in question.
(If I remember correctly, theoretically you should now be able to now send a Who-Is as a unicast/directed request - but even if I'm correct in saying that, it's highly likely that the majority of devices will only be listening for Who-Is services via broadcasts only.)
BBMD's are not strictly necessary - and have been considered as security concern as they can give out too much info.
It can be possible to use (effectively) bog-standard network routing instead of a BBMD - having traffic fly across a few different/target VLANs.
(Also be aware of mixing the use of a private IP(v4) address - of your choosing, and a public IP(v4) address - between the client & server/serving-device, you might encounter issues.)

Originate call to sip trunk via asterisk manager api java

So I am a total newbie in asterisk and managing call lines in general but I managed to install Asterisk Now 13 distro, I have connected 2 sip phones with pjsip and configured a sip trunk which works when I dial an external number with the corresponding prefix. Now I have to programmaticly originate calls and connect them to local extensions which I have no idea how to achieve and I cant seem to find much information about it on the internet after hours of searching.
I managed to connect 2 local sip phones with the asterisk manager api and OriginateAction in the following way:
originateAction = new OriginateAction();
originateAction.setChannel(ConnectionType+"/"+extCaller);
originateAction.setContext(context);
originateAction.setCallerId(idCaller);
originateAction.setExten(tDestination);
originateAction.setPriority(priority);
originateAction.setTimeout(timeoutCall);
managerConnection.login();
originateResponse = managerConnection.sendAction(originateAction, timeoutRequest);
I also tried this channel originate pjsip/201 extension number#from-ptsn and channel originate local/201#from-local extension number#trunkName .
The context of the PJSIP trunk is from-pstn,I tried using that in various ways without luck both in asterisk cli and the application.
How do I make it use the PJSIP trunk when originating the call and make a call out of the office?
EDIT: I originated an outgoing call using a number that completes with the trunk outgoing route requisites and the "from-internal" context like this:
channel originate Local/201#from-internal extension (prefix)numberToCall#from-internal
I still do not understand why this works and if it is the correct answer to my question.
So the answer is in the edit of the question. The only way to generate an outgoing call that I could find is to originate that call "internaly" (with the context "from-internal" which happens to be the same context that is used when originating internal calls) introducing a target number value that completes with the sip trunk's route pattern requirements.
Example:
I have a route configured for the sip trunk( trunk1 ) with a pattern(RegEx): [0]{1}/number/ that means that with a 0 infront of any nubmer it will be a valid value for that route and it will try to call using trunk1.
In the case of AsteriskNow CentOS installation it happens to be with the context "from-internal". Since the asterisk configuration files are owned by the FreePBX it is recomended to use the FreePBX GUI instead of configuring the .conf files of asterisk manualy.
That concludes to :
channel originate Local/201#from-internal extension (0)[numberToCall]#from-internal
Which will make the extension 201 ring first and when picked up it will try to use the sip trunk to dial that [numberToCall] because the route with the 0 is "called".
In order to send that command to asterisk using asterisk-java I wrote the following code:
ManagerConnectionFactory factory = new
ManagerConnectionFactory("serverIp", "username",
"passwd");
ManagerConnection managerConnection=factory.createManagerConnection()
OriginateAction originateAction=new OriginateAction();
final String randomUUID=java.util.UUID.randomUUID().toString();
System.out.println("ID random:_"+randomUUID);
originateAction.setChannel([connectionType]+"/"+[callerExtension]);<-- SIP or PJSIP / 201(the phone that will ring first)
originateAction.setContext("from-internal"); <-- Default FreePBX context
originateAction.setCallerId([callerId]); // what will be showed on the phone screen (in most cases your phone)
originateAction.setExten([targetExten]); //where to call.. the target extension... internal extension or the outgoing number.. the 0[nomberToCall]
originateAction.setPriority([priority]);// priority of the call
originateAction.setTimeout(timeoutCall); // the time that a pickup event will be waited for
originateAction.setVariable("UUID", randomUUID); // asigning a unique ID in order to be able to hangup the call.

jPcap - send packet to selected MAC (not the selected interface)

I'm trying to send ethernet packet to choosed destination MAC address using jPcap:
public void sendPacket(Packet packet, byte[] srcMac, byte[] dstMac, Interface i) throws IOException
{
JpcapSender sender = JpcapSender.openDevice(i.netInterface);
EthernetPacket ether = new EthernetPacket();
ether.frametype = EthernetPacket.ETHERTYPE_IP;
ether.src_mac = srcMac; // MAC address of selected interface
ether.dst_mac = dstMac; // MAC addr. choosed somwhere on form
packet.datalink = ether;
sender.sendPacket(packet);
sender.close();
}
It works, but it's always sent to the selected interface not to the dst_mac!
So I don't understand the relation between selected interface and scr_mac:
why I have to choose both (interface and scr_mac)?
why I have to add dst_mac even if it's not used?
how to send packet out of my computer then?
why I have to choose both (interface and scr_mac)?
The interface is what the software is using to communicate (to send or receive packets). This is usually your ethernet card. You need to specify it so that Jpcap knows how to send the information. The src_mac address is part of the packet header. It is intended to be used dynamically so that as the packets are being sent they are updated with the appropriate information. The src_mac does not necessarily play a role in how the packet is sent.
why I have to add dst_mac even if it's not used?
It is used. Make sure that you have the other device with the specified mac address linked to your source by a direct ethernet connection, and also make sure that it is ready to receive the data. Right now, what I suspect is happening, is you're trying to read back through your same interface on the host computer.
Jpcap's website has some tutorials and samples I found useful. I've worked quite a bit with the Jpcap library, and I would be happy to help you if you have any more questions.

Sending messages from pc via mobile phone using java

I am working on an application, using java, that has the following features:
User connects his mobile to a PC using a usb cable or bluetooth.
User types a message on his PC (in the textfield provided by my software).
User types a phone number (in a textbox provided by my software).
User clicks the send button.
Then, the software should send the message to the specified phone number and appropriate charges should be applied to my mobile balance. In other words, I am directing my mobile through my software to send message to a specified number.
How shall i do that? Is core java sufficient for this purpose or i have to use j2me or is there any particular java framework that would be suitable for this?
One option is to connect the phone to the pc using serial link (COM). Need to configure the phone connected physically by USB or Bluetooth in order to appear in a COM (serial) port.
Then you need to create an application for PC (Java or whatever can open serial ports) that opens the COM port used by the phone and send the proper AT commands. Serial port can be opened by JavaComm 2.0 Win32 or more recently RxTx.
Open the serial port and write and read command by writing and reading bytes, in the same way a socket.
Then create a visual application that let user set the information like phone number for destination, text...
You need Java SE or whatever language allows you to create visual applications and opening serial ports (Java, .NET, Python...).
Some links about AT commands by serial port in Windows: 1, 2, 3.
Another option could be using native API from the mobile OS through a socket, but seems complex and using AT commands and serial port should work for all phones and the only problem is connecting the phone by serial over USB or BlueTooth and managing the serial port.
This is highly dependent on the Mobile OS you're using. Are you using Windows Mobile, Android OS, BlackBerry OS?
If you're using Android, then you should use the built in SmsManager to do that. The SmsManager can do the following:
Manages SMS operations such as sending data, text, and pdu SMS messages.
Update:
Since you're using Symbian OS, then check out the documentation for more information on sending SMS messages. I assume that you can figure out the rest (i.e. how to get the text fields for the number and the message, etc.)
Here is an example from the Symbian OS documentation:
public boolean sendSms(String number, String message){
boolean result = true;
try {
//sets address to send message
String addr = "sms://"+number;
// opens connection
MessageConnection conn = (MessageConnection) Connector.open(addr);
// prepares text message
TextMessage msg =
(TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
//set text
msg.setPayloadText(message);
// send message
conn.send(msg);
conn.close();
} catch (SecurityException se) {
// probably the user has not allowed to send sms
// you may want to handle this differently
result = false;
} catch (Exception e) {
result = false;
}
return result;
}
The above snippet came from the guide on "How to Send Text SMS in Java ME"

Playing live http stream in vlcj

I'm trying to use vlcj to play live internet radio stations in a project. I've played around with some sample programs for a few hours, but I cannot get either the sample programs or programs that I've played around with to play the stream from the URL.
An example of a URL I'm trying to play is: http://network.absoluteradio.co.uk/core/audio/wmp/live.asx?service=vr
Is there anything special I have to do in order to get vlcj to play this stream? I couldn't find anything to help in the API. (Assuming it can because it can be played through the VLC media player!)
Thanks a lot
Ok, the MRL you have provided us http://network.absoluteradio.co.uk/core/audio/wmp/live.asx?service=vr is a MMS server that may pull a ASX (XML) metafile which may contain at least one sub-item.
http://all-streaming-media.com/faq/streaming-media/Metafiles-ASX-Advanced-Stream-Redirector.htm
To be able to play this type of streaming media and go through each sub-item, you need to do the following code snippet:
VideoPanel.getMediaPlayer().setRepeat(true);
VideoPanel.getMediaPlayer().setPlaySubItems(true);
VideoPanel.getMediaPlayer().prepareMedia(media, options);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
for(String s: VideoPanel.getMediaPlayer().subItems()) System.out.println(s);
VideoPanel.getMediaPlayer().play();
For the example MRL above, it will list down all sub-items as follows:
http://wms.absoluteradio.co.uk/g1/absoluteradio.co.uk/prerolls/ar_account_1310455302_hi.wma
mms://wms.absoluteradio.co.uk/absoluteradio.co.uk/vr_lo?u=
http://wms.absoluteradio.co.uk/absoluteradio.co.uk/vr_lo?u=
mmsu://wms.absoluteradio.co.uk/absoluteradio.co.uk/vr_lo?u=
mmst://wms.absoluteradio.co.uk/absoluteradio.co.uk/vr_lo?u=
mms://wms.absoluteradio.co.uk/absoluteradio.co.uk/prerolls/problems_lo.wma
To stop playing all of them, set the following code snippet:
VideoPanel.getMediaPlayer().setRepeat(false);
VideoPanel.getMediaPlayer().setPlaySubItems(false);
VideoPanel.getMediaPlayer().stop();
For a better explanation, refer to: http://code.google.com/p/vlcj/wiki/HowToHandleYouTubeMedia
You cannot use the http to play such link directly. You will ve to use the port number of the radio station router. this is because if i want to receive my home live video streaming from the internet at my workplace, i type the following on url: http://my dns server ip address:8080 The 8080 is the port number I opened on my router.

Categories

Resources