platform/upstream/gstreamer.git
15 years agomedia: don't leak session pads
Wim Taymans [Thu, 4 Jun 2009 17:20:26 +0000 (19:20 +0200)]
media: don't leak session pads

15 years agomedia: clean up the messages a bit
Wim Taymans [Thu, 4 Jun 2009 16:32:15 +0000 (18:32 +0200)]
media: clean up the messages a bit

15 years agosdp: warn and skip streams without media
Wim Taymans [Wed, 3 Jun 2009 10:13:21 +0000 (12:13 +0200)]
sdp: warn and skip streams without media

15 years agovala: Fixed typo in header file of RTSPMediaStream
Sebastian Pölsterl [Sat, 30 May 2009 12:38:34 +0000 (14:38 +0200)]
vala: Fixed typo in header file of RTSPMediaStream

15 years agomedia: fix message
Wim Taymans [Wed, 27 May 2009 09:15:22 +0000 (11:15 +0200)]
media: fix message

Fix a debug message
Make dumping RTCP stats configurable

15 years agomedia: be less verbose and leak less
Wim Taymans [Tue, 26 May 2009 17:20:07 +0000 (19:20 +0200)]
media: be less verbose and leak less

15 years agomedia: don't leak the destination address
Wim Taymans [Tue, 26 May 2009 17:05:07 +0000 (19:05 +0200)]
media: don't leak the destination address

15 years agortsp: use RTCP to keep the session alive
Wim Taymans [Tue, 26 May 2009 17:01:10 +0000 (19:01 +0200)]
rtsp: use RTCP to keep the session alive

Use the RTCP rtcp-from stats field to find the associated session and use this
to keep the session alive.

15 years agosession: add 5sec to the real session timeout
Wim Taymans [Tue, 26 May 2009 15:27:07 +0000 (17:27 +0200)]
session: add 5sec to the real session timeout

Allow the session to live 5sec longer before really timing out. This should give
clients some extra time to keep the session active.

15 years agoclient: replay OK to GET/SET_PARAMETER
Wim Taymans [Tue, 26 May 2009 15:25:59 +0000 (17:25 +0200)]
client: replay OK to GET/SET_PARAMETER

Some clients (vlc) use GET/SET_PARAMETER to keep the TCP session open. Make it
so that we return OK for those requests.

15 years agomedia: keep track of active transports
Wim Taymans [Tue, 26 May 2009 09:42:41 +0000 (11:42 +0200)]
media: keep track of active transports

Keep track of which transport is active to avoid closing the connection too
soon.
Remove the destination transport also when going to NULL.
Print some stats about the SDES and other RTCP messages we receive from the
clients.

15 years agoexample: add SDP relay example
Wim Taymans [Sun, 24 May 2009 18:00:19 +0000 (20:00 +0200)]
example: add SDP relay example

15 years agomedia: also count active TCP connections
Wim Taymans [Sun, 24 May 2009 17:56:45 +0000 (19:56 +0200)]
media: also count active TCP connections

15 years agortsp: add support for dynamic elements
Wim Taymans [Sun, 24 May 2009 17:34:52 +0000 (19:34 +0200)]
rtsp: add support for dynamic elements

Add support for dynamic elements.
Don't set live pipelines back to paused.

15 years agosdp: don't add encoding name when absent in caps
Wim Taymans [Sun, 24 May 2009 17:33:22 +0000 (19:33 +0200)]
sdp: don't add encoding name when absent in caps

15 years agoclient: warn when we can't do RTP-Info
Wim Taymans [Sat, 23 May 2009 14:30:55 +0000 (16:30 +0200)]
client: warn when we can't do RTP-Info

15 years agofactory: factor out the stream construction
Wim Taymans [Sat, 23 May 2009 14:18:04 +0000 (16:18 +0200)]
factory: factor out the stream construction

15 years agoclient: only add RTP-Info when we have the info
Wim Taymans [Sat, 23 May 2009 14:17:02 +0000 (16:17 +0200)]
client: only add RTP-Info when we have the info

Only add RTP-Info for a stream when we can get the seqnum and timestamp from the
depayloader.

15 years agoback to development
Wim Taymans [Sun, 17 May 2009 12:04:31 +0000 (14:04 +0200)]
back to development

15 years agorelease: 0.10.3
Wim Taymans [Sun, 17 May 2009 11:59:10 +0000 (13:59 +0200)]
release: 0.10.3

 - Fixes a bug where it put the wrong verion in pkgconfig
 - Link RTP and RTCP sources

15 years agomedia: link the RTP udpsrc to the session manager
Wim Taymans [Fri, 15 May 2009 15:58:44 +0000 (17:58 +0200)]
media: link the RTP udpsrc to the session manager

Link the RTP udpsrc and the appsrc to the session manager so that they don't
shut down when the client sends a packet to open firewalls.

15 years agoDon't use hard-coded version number in pkg-config file
Sebastian Pölsterl [Fri, 15 May 2009 15:10:44 +0000 (17:10 +0200)]
Don't use hard-coded version number in pkg-config file

15 years agoback to development
Wim Taymans [Mon, 11 May 2009 08:51:47 +0000 (10:51 +0200)]
back to development

15 years agorelease 0.10.2
Wim Taymans [Mon, 11 May 2009 08:50:31 +0000 (10:50 +0200)]
release 0.10.2

15 years agoadd some .gitignore files
Wim Taymans [Mon, 11 May 2009 08:38:44 +0000 (10:38 +0200)]
add some .gitignore files

15 years agomedia: seek to key frames
Wim Taymans [Wed, 29 Apr 2009 15:24:46 +0000 (17:24 +0200)]
media: seek to key frames

15 years agomedia: emit the unprepared signal by id
Wim Taymans [Tue, 21 Apr 2009 20:44:05 +0000 (22:44 +0200)]
media: emit the unprepared signal by id

Emit the unprepared signal by id instead of name and set the media as
reused.

15 years agoSet pipeline's state to NULL no matter if the media is reusable and emit unprepared...
Sebastian Pölsterl [Tue, 21 Apr 2009 20:23:54 +0000 (22:23 +0200)]
Set pipeline's state to NULL no matter if the media is reusable and emit unprepared signal in gst_rtsp_media_unprepare

15 years agoAdded finalize function to GstRTPSPServer to unref session pool and media mapping
Sebastian Pölsterl [Sat, 18 Apr 2009 14:10:59 +0000 (16:10 +0200)]
Added finalize function to GstRTPSPServer to unref session pool and media mapping

15 years agoUpdated vala bindings
Sebastian Pölsterl [Fri, 17 Apr 2009 19:13:07 +0000 (21:13 +0200)]
Updated vala bindings

15 years agoserver: use appsink and appsrc with the API
Wim Taymans [Tue, 14 Apr 2009 21:38:58 +0000 (23:38 +0200)]
server: use appsink and appsrc with the API

Use the appsink/appsrc API instead of the signals for higher
performance.

15 years agotests: set the payload type correctly
Wim Taymans [Tue, 14 Apr 2009 21:38:15 +0000 (23:38 +0200)]
tests: set the payload type correctly

15 years agofactory: connect to the unprepare signal
Wim Taymans [Fri, 3 Apr 2009 20:46:22 +0000 (22:46 +0200)]
factory: connect to the unprepare signal

Connect to the unprepare signal for non-reusable media so that we can remove
them from the cache.

15 years agomedia: add signal to notify of unprepare
Wim Taymans [Fri, 3 Apr 2009 20:45:57 +0000 (22:45 +0200)]
media: add signal to notify of unprepare

15 years agomedia: more work on making the media shared
Wim Taymans [Fri, 3 Apr 2009 20:22:30 +0000 (22:22 +0200)]
media: more work on making the media shared

Add a reusable flag to medias, indicating that they can be reused after a state
change to NULL.

Small cleanups.

15 years agoexamples: mark the example as shared for testing
Wim Taymans [Fri, 3 Apr 2009 17:47:38 +0000 (19:47 +0200)]
examples: mark the example as shared for testing

15 years agoclient: support shared media
Wim Taymans [Fri, 3 Apr 2009 17:44:37 +0000 (19:44 +0200)]
client: support shared media

Always perform the state actions even if the target state of the pipeline is
already correct, we still want to add/remove the transports when we are dealing
with shared media.

Keep a counter of the number of active transports for a media so that we can use
this to perform a state change when needed.

Perform a state change of the pipeline only when the first transport was added
or when there are no active transports.

15 years agoclient: fix refcounting crasher
Wim Taymans [Fri, 3 Apr 2009 07:03:59 +0000 (09:03 +0200)]
client: fix refcounting crasher

Don't need to remove the weak refs in the finalize methods, they are already
removed in the dispose.
Don't register the callback with a DestroyNofity.

15 years agoFix rtsp client refcount management in TCP mode.
Tim-Philipp Müller [Wed, 1 Apr 2009 00:01:46 +0000 (01:01 +0100)]
Fix rtsp client refcount management in TCP mode.

Don't unref a client ref we never had. Fixes an unref
of an already-free client object after a client
teardown request for me.

15 years agodocs: fix typo in API docs
Tim-Philipp Müller [Tue, 31 Mar 2009 23:45:17 +0000 (00:45 +0100)]
docs: fix typo in API docs

15 years agoMore seeking fixes.
Wim Taymans [Fri, 13 Mar 2009 14:57:42 +0000 (15:57 +0100)]
More seeking fixes.

Keep the udp sources in playing even if we go to paused. unlock the sources when
we shut down.
Add some more debug info.
Only seek when we need to.
Keep track of the position when we go to paused.

15 years agoAdd beginnings of seeking.
Wim Taymans [Thu, 12 Mar 2009 19:32:14 +0000 (20:32 +0100)]
Add beginnings of seeking.

Parse the Range header and perform a seek on the pipeline for the requested
position. It's disabled currently until I figure out what's going wrong.

15 years agoallow pause requests for now.
Wim Taymans [Thu, 12 Mar 2009 19:31:22 +0000 (20:31 +0100)]
allow pause requests for now.

--

15 years agoRemove weak ref on the session in teardown
Wim Taymans [Wed, 11 Mar 2009 19:03:06 +0000 (20:03 +0100)]
Remove weak ref on the session in teardown

We need to remove our weakref from the session when we do a teardown because
else we close the TCP connection prematurely.

15 years agoDo some more session cleanup
Wim Taymans [Wed, 11 Mar 2009 18:38:06 +0000 (19:38 +0100)]
Do some more session cleanup

Make session timeout kill the TCP connection that currently watches the
session.
Remove the client timeout property.

15 years agoAdd TCP transports
Wim Taymans [Wed, 11 Mar 2009 15:45:12 +0000 (16:45 +0100)]
Add TCP transports

Use appsrc and appsink to send and receive RTP/RTCP packets in the TCP
connection.

15 years agoAdd example server that takes launch lines
Wim Taymans [Wed, 11 Mar 2009 15:39:20 +0000 (16:39 +0100)]
Add example server that takes launch lines

Add an example server that streams any -launch line.

15 years agoAdd support for live streams
Wim Taymans [Fri, 6 Mar 2009 18:34:14 +0000 (19:34 +0100)]
Add support for live streams

Add support for live streams and ranges
Start on handling TCP data transfer.

15 years agoFree the pipeline before other things
Wim Taymans [Wed, 4 Mar 2009 15:33:59 +0000 (16:33 +0100)]
Free the pipeline before other things

---

15 years agoOnly free the pending tunnel if there is one
Wim Taymans [Wed, 4 Mar 2009 15:33:21 +0000 (16:33 +0100)]
Only free the pending tunnel if there is one

--

15 years agortsp-server: Add support for tunneling
Wim Taymans [Wed, 4 Mar 2009 11:44:01 +0000 (12:44 +0100)]
rtsp-server: Add support for tunneling

Add support for tunneling over HTTP.
Use new connection methods to retrieve the url.
Dispatch messages based on the message type instead of blindly
assuming it's always a request.
Keep track of the watch id so that we can remove it later.
Set the media pipeline to NULL before unreffing the pipeline.

15 years agoFix for channel -> watch rename in gstreamer
Wim Taymans [Thu, 19 Feb 2009 14:53:50 +0000 (15:53 +0100)]
Fix for channel -> watch rename in gstreamer

Rename the RTSPChannel to RTSPWatch and remove an unused variable.

15 years agoUse ASYNC RTSP io
Wim Taymans [Wed, 18 Feb 2009 17:57:31 +0000 (18:57 +0100)]
Use ASYNC RTSP io

Use the async RTSP channels instead of spawning a new thread for each client.
If a sessionid is specified in a request, fail if we don't have the session.

15 years agoAdd better debug info
Wim Taymans [Wed, 18 Feb 2009 16:49:03 +0000 (17:49 +0100)]
Add better debug info

Add some better debug info.

15 years agoTime out sessions
Wim Taymans [Fri, 13 Feb 2009 19:00:34 +0000 (20:00 +0100)]
Time out sessions

Add support for session timeouts in the example.

15 years agoPass GTimeVal around for performance reasons
Wim Taymans [Fri, 13 Feb 2009 18:58:17 +0000 (19:58 +0100)]
Pass GTimeVal around for performance reasons

Get the current time only once and pass it around so that sessions don't have to
get the current time anymore.

Add experimental support for a GSource that dispatches when the session needs to
be cleaned up.

15 years agoAdd better support for session timeouts
Wim Taymans [Fri, 13 Feb 2009 18:56:01 +0000 (19:56 +0100)]
Add better support for session timeouts

Add a method to request the number of milliseconds when a session will timeout.

15 years agoAdd suport for RTP manager monitoring
Wim Taymans [Fri, 13 Feb 2009 18:54:18 +0000 (19:54 +0100)]
Add suport for RTP manager monitoring

Add the first stage in monitoring the rtp manager.
Make sure we don't update the state to something we don't want.

15 years agoAdd support for session keepalive
Wim Taymans [Fri, 13 Feb 2009 18:52:05 +0000 (19:52 +0100)]
Add support for session keepalive

Get and update the session timeout for all requests. get the session as early as
possible.

15 years agoHandle media bus messages
Wim Taymans [Fri, 13 Feb 2009 15:39:36 +0000 (16:39 +0100)]
Handle media bus messages

Handle media bus messages in a custom mainloop and dispatch them to the
RTSPMedia objects. Let the default implementation handle some common messages.

15 years agoSome more session timeout handling
Wim Taymans [Fri, 13 Feb 2009 11:57:45 +0000 (12:57 +0100)]
Some more session timeout handling

Move the session header setting code to a central place so that we always add
the timeout parameter too.

Handle timeouts by running the session cleanup code.

Stop media before cleaning up.

15 years agoAdd timeout property
Wim Taymans [Tue, 10 Feb 2009 15:24:13 +0000 (16:24 +0100)]
Add timeout property

Add a timeout property ot the client and make the other properties into GObject
properties.

15 years agoUse getters and setters in property code
Wim Taymans [Tue, 10 Feb 2009 15:21:17 +0000 (16:21 +0100)]
Use getters and setters in property code

Use the getters and setters for the timeout property instead of locking
ourselves.

15 years agoMerge branch 'master' of git+ssh://git.collabora.co.uk/git/gst-rtsp-server
Wim Taymans [Wed, 4 Feb 2009 19:13:32 +0000 (20:13 +0100)]
Merge branch 'master' of git+ssh://git.collabora.co.uk/git/gst-rtsp-server

15 years agoAdd more timeout stuff
Wim Taymans [Wed, 4 Feb 2009 19:10:39 +0000 (20:10 +0100)]
Add more timeout stuff

Add method to check if a session is expired.
Add method to perform cleanup on a session pool.

15 years agoAdd beginnings of session timeouts and limits
Wim Taymans [Wed, 4 Feb 2009 18:52:50 +0000 (19:52 +0100)]
Add beginnings of session timeouts and limits

Add the timeout value to the Session header for unusual timeout values.

Allow us to configure a limit to the amount of active sessions in a pool. Set a
limit on the amount of retry we do after a sessionid collision.

Add properties to the sessionid and the timeout of a session. Keep track of
creation time and last access time for sessions.

15 years agoCleanup of sessions and more
Wim Taymans [Wed, 4 Feb 2009 16:00:42 +0000 (17:00 +0100)]
Cleanup of sessions and more

Fix the refcounting of media and sessions in the client. Properly clean up the
session data when the client performs a teardown.

Add Server header to responses.

Allow for multiple uri setups in one session.

Add Range header to the PLAY response and add the range attribute to the SDP
message.

Fix the session pool remove method, it used the wrong key in the hashtable. Also
give the ownership of the sessionid to the session object.

15 years agoRename a variable
Wim Taymans [Wed, 4 Feb 2009 08:57:55 +0000 (09:57 +0100)]
Rename a variable

Rename the 'server_port' variable to simply 'port'.

15 years agoRework the way we handle transports for streams
Wim Taymans [Tue, 3 Feb 2009 18:32:38 +0000 (19:32 +0100)]
Rework the way we handle transports for streams

Make the media accept an array of transports for the streams that we have
configured for the play/pause requests.

Implement server states for a client and its media.

Require 0.10.22.1 (git HEAD) of gstreamer.

15 years agoDrop const from functions dealing with urls
Wim Taymans [Sat, 31 Jan 2009 18:50:33 +0000 (19:50 +0100)]
Drop const from functions dealing with urls

Drop const from GstRTSPUrl stuff because the .h files in gst-plugins-base don't
have the right const in them.

15 years agoFix various leaks
Wim Taymans [Fri, 30 Jan 2009 16:06:26 +0000 (17:06 +0100)]
Fix various leaks

Fix some leaks.

15 years agoMore cleanups
Wim Taymans [Fri, 30 Jan 2009 15:24:10 +0000 (16:24 +0100)]
More cleanups

Don't keep a reference to the GstRTSPMedia in the stream.
Free more things when freeing the GstRTSPMedia.

15 years agoMore docs and small cleanups
Wim Taymans [Fri, 30 Jan 2009 13:53:28 +0000 (14:53 +0100)]
More docs and small cleanups

Add some more docs and update the README
Cleanup some method names.
Remove an unneeded idx field in the GstRTSPMediaStream

15 years agoAdd a README and more example code
Wim Taymans [Fri, 30 Jan 2009 12:24:04 +0000 (13:24 +0100)]
Add a README and more example code

Add a README file that contains a small introduction on how to use the server
along with the example code explained in the readme.

15 years agoFix some leaks and change default port
Wim Taymans [Fri, 30 Jan 2009 10:06:31 +0000 (11:06 +0100)]
Fix some leaks and change default port

Fix some memory leaks by setting the udpsrc elements to the unlocked state after
we finished the initial preroll. If we keep them locked, setting the pipeline to
NULL will not stop and clean up the sources correctly.

Change the default RTSP port to 8554 aka the official alternative RTSP port.

15 years agoCleanups to the session object
Wim Taymans [Thu, 29 Jan 2009 17:55:22 +0000 (18:55 +0100)]
Cleanups to the session object

Remove some unneeded variables in the session state of a stream such as the
owner media and the server transport.
Get the configuration of a media stream in a session based on the media_stream
in the original object instead of our cached index.
Free more data in the finalize method.

15 years agoCleanups and reuse media from DESCRIBE
Wim Taymans [Thu, 29 Jan 2009 17:51:02 +0000 (18:51 +0100)]
Cleanups and reuse media from DESCRIBE

Handle thread create errors.
Rename some internal methods to better match what they actually do.
Handle misconfiguration of session_pool and media_mapping gracefully.
Cache the DESCRIBE media and uri in the client connection and reuse them when
we receive a SETUP request in the same connection for the same uri.
Cleanup the client connection object.

15 years agoAdd shared properties to media and factory
Wim Taymans [Thu, 29 Jan 2009 16:20:27 +0000 (17:20 +0100)]
Add shared properties to media and factory

Add the shared property to media.
Implement some simple caching in the factory depending on if the media is shared
or not.

15 years agoAdd a little comment
Wim Taymans [Thu, 29 Jan 2009 16:19:21 +0000 (17:19 +0100)]
Add a little comment

Add some comment about the content-base header.

15 years agoReorganize things, prepare for media sharing
Wim Taymans [Thu, 29 Jan 2009 12:31:27 +0000 (13:31 +0100)]
Reorganize things, prepare for media sharing

Added various other test server examples
Move the SDP message generation to a separate helper.
Refactor common code for finding the session.
Add content-base for realplayer compatibility
Clean up request uris before processing for better vlc compatibility.
Move prerolling and pipeline construction to the RTSPMedia object.
Use multiudpsink for future pipeline reuse.

15 years agoBack to development
Wim Taymans [Fri, 30 Jan 2009 10:23:57 +0000 (11:23 +0100)]
Back to development

Back to 0.10.1.1

15 years agoMake 0.10.1 release
Wim Taymans [Fri, 30 Jan 2009 10:20:18 +0000 (11:20 +0100)]
Make 0.10.1 release

Release 0.10.1

15 years agoFix make dist
Wim Taymans [Thu, 29 Jan 2009 14:19:01 +0000 (15:19 +0100)]
Fix make dist

Add more directories and files to the dist.

15 years agoFixed compile error of python bindings
Sebastian Pölsterl [Sat, 24 Jan 2009 13:34:35 +0000 (14:34 +0100)]
Fixed compile error of python bindings

15 years agoMarked values as nullable accordingly
Sebastian Pölsterl [Fri, 23 Jan 2009 20:03:53 +0000 (21:03 +0100)]
Marked values as nullable accordingly

15 years agoUpdated Vala bindings
Sebastian Pölsterl [Fri, 23 Jan 2009 19:31:11 +0000 (20:31 +0100)]
Updated Vala bindings

15 years agoCleanups and doc updates
Wim Taymans [Thu, 22 Jan 2009 17:35:17 +0000 (18:35 +0100)]
Cleanups and doc updates

Add some more documentation and do some minor cleanups here and there.

15 years agoMore improvements
Wim Taymans [Thu, 22 Jan 2009 16:58:19 +0000 (17:58 +0100)]
More improvements

Rename GstRTSPMediaBin to GstRTSPMedia
Parse the request url into a GstRTSPUri object and pass this object to the
various handlers and methods that require the uri.

15 years agoUpdate example
Wim Taymans [Thu, 22 Jan 2009 15:54:07 +0000 (16:54 +0100)]
Update example

Add some more docs and remove some old code from the example.

15 years agoHandle state change failures better
Wim Taymans [Thu, 22 Jan 2009 15:53:16 +0000 (16:53 +0100)]
Handle state change failures better

Handle state change failures better when changing the state of the pipeline to
determine the SDP.

15 years agoMake element creation more extendible
Wim Taymans [Thu, 22 Jan 2009 15:51:08 +0000 (16:51 +0100)]
Make element creation more extendible

Add get_element vmethod to the default MediaFactory so that subclasses can just
override that method and still use the default logic for making a MediaBin from
that.

15 years agoMake the server handle arbitrary pipelines
Wim Taymans [Thu, 22 Jan 2009 14:33:29 +0000 (15:33 +0100)]
Make the server handle arbitrary pipelines

Make GstMediaFactory an object that can instantiate GstMediaBin objects.
The GstMediaBin object has a handle to a bin with elements and to a list of
GstMediaStream objects that this bin produces.

Add GstMediaMapper that can map url mountpoints to GstMediaFactory objects along
with methods to register and remove those mappings.

Add methods and a property to GstRTSPServer to manage the GstMediaMapper object
used by the server instance.

Modify the example application so that it shows how to create custom pipelines
attached to a specific mount point.

Various misc cleanps.

15 years agoAllow setting a custom media factory for a server
Wim Taymans [Tue, 20 Jan 2009 18:47:07 +0000 (19:47 +0100)]
Allow setting a custom media factory for a server

15 years agoAllow setting a custom media factory for a client.
Wim Taymans [Tue, 20 Jan 2009 18:46:21 +0000 (19:46 +0100)]
Allow setting a custom media factory for a client.

15 years agoAdd Makefile entry for the media factory
Wim Taymans [Tue, 20 Jan 2009 18:45:28 +0000 (19:45 +0100)]
Add Makefile entry for the media factory

15 years agoAdd media factory to map urls to media pipeline objects.
Wim Taymans [Tue, 20 Jan 2009 18:44:45 +0000 (19:44 +0100)]
Add media factory to map urls to media pipeline objects.

15 years agoAdd comments.
Wim Taymans [Tue, 20 Jan 2009 18:43:47 +0000 (19:43 +0100)]
Add comments.
Remove unused field

15 years agoAllow custom session pools to override the session id allocation algorithms
Wim Taymans [Tue, 20 Jan 2009 18:41:53 +0000 (19:41 +0100)]
Allow custom session pools to override the session id allocation algorithms
Add some comments.

15 years agoAdd some comments.
Wim Taymans [Tue, 20 Jan 2009 18:40:42 +0000 (19:40 +0100)]
Add some comments.

15 years agoMove the connection code in one place
Wim Taymans [Tue, 20 Jan 2009 12:57:47 +0000 (13:57 +0100)]
Move the connection code in one place
Add some comments