Halyri - Mobiili  0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
Halyri.AudioVideoTransmitManager Class Reference

Class for managing audio and picture transmission from XNA Microphone and AudioVideoCaptureDevice. Media is captured using PreviewImageCapturer and WavAudioSampleCapturer classes. Capture configuration is taken from MediaConfigurationDto published by the server and available on NetworkConnection's MediaConfigurationUpdatedEvent. Network operations are performed by NetworkConnection class. More...

Public Member Functions

delegate void CaptureConfigurationUpdated (object sender, EventArgs e, MediaConfigurationDto config)
 
 AudioVideoTransmitManager (Connection networkConnection)
 Instantializes a AudioVideoTransmitManager that uses the provided NetworkConnection. The NetworkConnection has to be connected to a server with a valid session. More...
 
void MediaConfigurationUpdateHandler (object sender, EventArgs e, MediaConfigurationDto config)
 Handles media uploading configurations received by NetworkConnection from server. This method only disbles audio and picture transmission if they are currently active and the new configuration suggests that they should be disabled. It also handles configuration changes to active audio and picture capturer classes. More...
 
void StopAllCaptureTransmit ()
 Disables media capture and transmission from any device. More...
 
void ResetThrottlingState ()
 Resets the ECF transfer channel throttling state of this instance. If packet transmissiong has been stalled due to throttling, packet transmission will resume. More...
 
void ExternalSourceDeviceConfigurationChanged (AudioVideoCaptureDevice videoCaptureDevice, Microphone audioCaptureDevice, MediaConfigurationDto mediaConfiguration)
 Handles changes to external media source devices. This method should be called with a valid source device(s) when the media uploading configuration has transitioned from disabled to enabled state for either of the media types. More...
 
delegate void CaptureConfigurationUpdated (object sender, EventArgs e, MediaConfigurationDto config)
 
 AudioVideoTransmitManager (Connection networkConnection)
 Instantializes a AudioVideoTransmitManager that uses the provided NetworkConnection. The NetworkConnection has to be connected to a server with a valid session. More...
 
void MediaConfigurationUpdateHandler (object sender, EventArgs e, MediaConfigurationDto config)
 Handles media uploading configurations received by NetworkConnection from server. This method only disbles audio and picture transmission if they are currently active and the new configuration suggests that they should be disabled. It also handles configuration changes to active audio and picture capturer classes. More...
 
void StopAllCaptureTransmit ()
 Disables media capture and transmission from any device. More...
 
void ResetThrottlingState ()
 Resets the ECF transfer channel throttling state of this instance. If packet transmissiong has been stalled due to throttling, packet transmission will resume. More...
 
void ExternalSourceDeviceConfigurationChanged (AudioVideoCaptureDevice videoCaptureDevice, Microphone audioCaptureDevice, MediaConfigurationDto mediaConfiguration)
 Handles changes to external media source devices. This method should be called with a valid source device(s) when the media uploading configuration has transitioned from disabled to enabled state for either of the media types. More...
 

Public Attributes

CaptureConfigurationUpdated CaptureConfigurationUpdatedEvent
 
PacketThrottlingStarted PacketThrottlingStartedEvent
 
PacketSendStalled PacketSendStalledEvent
 

Properties

bool PacketThrottlingEnabled [get]
 
bool AudioEnabled [get]
 
bool PictureEnabled [get]
 
bool UseUdp [get, set]
 

Private Member Functions

void AudioSampleEventHandler (object sender, EventArgs e, byte[] audioFrame)
 Handles new wave audio fragments. Sends the audio fragments to server if throttling does not prevent this action. More...
 
void PcmSampleEventHandler (object sender, EventArgs e, byte[] audioFrame)
 Compresses the received PCM segment into speex format and transmit it over the UDP data channel if UseUdp = true. Otherwise returns immediately. More...
 
void ImageCaptureEventHandler (object sender, EventArgs e, byte[] jpgData)
 Handles new jpeg images captured from the camera. Sends the pictures to server over WCF transfer channel if throttling does not prevent this action. More...
 
void MediaSendFinishedHandler (object sender, AsyncCompletedEventArgs e)
 Handles async media send over WCF data channel finished events. Performs the throttling action by calculating the time used for sending the packet over the WCF data channel. More...
 
void disableAudio ()
 Disables the active WavAudioSampleCapturer instance and unregisters audio sample event receivers. More...
 
void disablePicture ()
 Disables the active PreviewImageCapturer instance and unregisters picture sample event receiver. More...
 
void ConfigurePictureCapturerFromConfigurationInstance (PreviewImageCapturer capturer, MediaConfigurationDto configuration)
 Updates the quality parameters on the specified PreviewImageCapturer. New quality parameters are taken from provided MediaConfigurationDto. More...
 
void AudioSampleEventHandler (object sender, EventArgs e, byte[] audioFrame)
 Handles new wave audio fragments. Sends the audio fragments to server if throttling does not prevent this action. More...
 
void PcmSampleEventHandler (object sender, EventArgs e, byte[] audioFrame)
 Compresses the received PCM segment into speex format and transmit it over the UDP data channel if UseUdp = true. Otherwise returns immediately. More...
 
void ImageCaptureEventHandler (object sender, EventArgs e, byte[] jpgData)
 Handles new jpeg images captured from the camera. Sends the pictures to server over WCF transfer channel if throttling does not prevent this action. More...
 
void MediaSendFinishedHandler (object sender, AsyncCompletedEventArgs e)
 Handles async media send over WCF data channel finished events. Performs the throttling action by calculating the time used for sending the packet over the WCF data channel. More...
 
void disableAudio ()
 Disables the active WavAudioSampleCapturer instance and unregisters audio sample event receivers. More...
 
void disablePicture ()
 Disables the active PreviewImageCapturer instance and unregisters picture sample event receiver. More...
 
void ConfigurePictureCapturerFromConfigurationInstance (PreviewImageCapturer capturer, MediaConfigurationDto configuration)
 Updates the quality parameters on the specified PreviewImageCapturer. New quality parameters are taken from provided MediaConfigurationDto. More...
 

Static Private Member Functions

static AudioVideoTransmitManager ()
 
static AudioVideoTransmitManager ()
 

Private Attributes

Object ThrottlingParameterLock = new Object()
 
int overdueLimitMilliseconds = 9050
 
int overduePacketCount = 0
 
int overduePacketLimitSkipPictures = 4
 
int overduePacketLimitDisablePictures = 8
 
int overduePacketLimitDisableAll = 12
 
int successiveSuccesfullPacketCount = 0
 
int throttlingDecreaseFactor = 2
 
int pictureSkipFactor = 1
 
int pictureSkipCounter = 0
 
bool packetThrotting = false
 
MediaConfigurationDto latestMediaConfiguration
 
Connection connection
 
PreviewImageCapturer pictureCapturer
 
AudioVideoCaptureDevice videoDevice
 
WavAudioSampleCapturer audioCapturer
 
Microphone audioDevice
 
SpeexEncoder speexEncoder
 
bool audioEnabled = false
 
bool pictureEnabled = false
 
bool useUdp = true
 

Static Private Attributes

static int[] imageWidthMapping
 
static MediaInformationDto outgoingJpgInformation
 
static MediaInformationDto outgoingWaveInformation
 
static MediaInformation udpOutgoingJpgInformation
 
static MediaInformation udpOutgoingWaveInformation
 
static MediaInformation udpOutgoingSpeexInformation
 

Detailed Description

Class for managing audio and picture transmission from XNA Microphone and AudioVideoCaptureDevice. Media is captured using PreviewImageCapturer and WavAudioSampleCapturer classes. Capture configuration is taken from MediaConfigurationDto published by the server and available on NetworkConnection's MediaConfigurationUpdatedEvent. Network operations are performed by NetworkConnection class.

<author>Veli-Mikko Puupponen</author> Implements a simple packet level throttling when using WCF connection by measuring packet transmission time and comparing it to a set threshold. For every packet whose time exceeds the threshold, a counter is incremented. Once the counter meets overdue packet threshold level, set ratio of picture data packets are dropped. If the overdue counter keeps increasing, picture packets are dropped completely. If the counter still increases, all packets are dropped and the PacketSendStalledEvent is fired.

If UseUdp = true, uses UDP transfer protocol and no packet throttling is performed by this class.

After this AudioVideoTransmitManager instance has been stalled, it has to be manually reset by a call to the ResetThrottlingState method.

Constructor & Destructor Documentation

static Halyri.AudioVideoTransmitManager.AudioVideoTransmitManager ( )
staticprivate
Halyri.AudioVideoTransmitManager.AudioVideoTransmitManager ( Connection  networkConnection)

Instantializes a AudioVideoTransmitManager that uses the provided NetworkConnection. The NetworkConnection has to be connected to a server with a valid session.

Parameters
networkConnectionNetworkConnection to be used to send pictures and audio
static Halyri.AudioVideoTransmitManager.AudioVideoTransmitManager ( )
staticprivate
Halyri.AudioVideoTransmitManager.AudioVideoTransmitManager ( Connection  networkConnection)

Instantializes a AudioVideoTransmitManager that uses the provided NetworkConnection. The NetworkConnection has to be connected to a server with a valid session.

Parameters
networkConnectionNetworkConnection to be used to send pictures and audio

Member Function Documentation

void Halyri.AudioVideoTransmitManager.AudioSampleEventHandler ( object  sender,
EventArgs  e,
byte[]  audioFrame 
)
private

Handles new wave audio fragments. Sends the audio fragments to server if throttling does not prevent this action.

Wave fragments are only send over the WCF transfer channel. They are only sent provided that UseUdp = false.

Parameters
senderSending object
eEventArgs for the event
audioFrameWave file bytes
void Halyri.AudioVideoTransmitManager.AudioSampleEventHandler ( object  sender,
EventArgs  e,
byte[]  audioFrame 
)
private

Handles new wave audio fragments. Sends the audio fragments to server if throttling does not prevent this action.

Wave fragments are only send over the WCF transfer channel. They are only sent provided that UseUdp = false.

Parameters
senderSending object
eEventArgs for the event
audioFrameWave file bytes
delegate void Halyri.AudioVideoTransmitManager.CaptureConfigurationUpdated ( object  sender,
EventArgs  e,
MediaConfigurationDto  config 
)
delegate void Halyri.AudioVideoTransmitManager.CaptureConfigurationUpdated ( object  sender,
EventArgs  e,
MediaConfigurationDto  config 
)
void Halyri.AudioVideoTransmitManager.ConfigurePictureCapturerFromConfigurationInstance ( PreviewImageCapturer  capturer,
MediaConfigurationDto  configuration 
)
private

Updates the quality parameters on the specified PreviewImageCapturer. New quality parameters are taken from provided MediaConfigurationDto.

Parameters
capturerThe PreviewImageCapturer whose configuration is updated
configurationThe MediaConfigurationDto providing the configuration
void Halyri.AudioVideoTransmitManager.ConfigurePictureCapturerFromConfigurationInstance ( PreviewImageCapturer  capturer,
MediaConfigurationDto  configuration 
)
private

Updates the quality parameters on the specified PreviewImageCapturer. New quality parameters are taken from provided MediaConfigurationDto.

Parameters
capturerThe PreviewImageCapturer whose configuration is updated
configurationThe MediaConfigurationDto providing the configuration
void Halyri.AudioVideoTransmitManager.disableAudio ( )
private

Disables the active WavAudioSampleCapturer instance and unregisters audio sample event receivers.

void Halyri.AudioVideoTransmitManager.disableAudio ( )
private

Disables the active WavAudioSampleCapturer instance and unregisters audio sample event receivers.

void Halyri.AudioVideoTransmitManager.disablePicture ( )
private

Disables the active PreviewImageCapturer instance and unregisters picture sample event receiver.

void Halyri.AudioVideoTransmitManager.disablePicture ( )
private

Disables the active PreviewImageCapturer instance and unregisters picture sample event receiver.

void Halyri.AudioVideoTransmitManager.ExternalSourceDeviceConfigurationChanged ( AudioVideoCaptureDevice  videoCaptureDevice,
Microphone  audioCaptureDevice,
MediaConfigurationDto  mediaConfiguration 
)

Handles changes to external media source devices. This method should be called with a valid source device(s) when the media uploading configuration has transitioned from disabled to enabled state for either of the media types.

Parameters
videoCaptureDeviceAudioVideoCaptureDevice opened for at least video if video is enabled in the configuration
audioCaptureDeviceXNA Microphone instance for capturing audio
mediaConfigurationThe media uploading configuration used to set the devices in the UI
void Halyri.AudioVideoTransmitManager.ExternalSourceDeviceConfigurationChanged ( AudioVideoCaptureDevice  videoCaptureDevice,
Microphone  audioCaptureDevice,
MediaConfigurationDto  mediaConfiguration 
)

Handles changes to external media source devices. This method should be called with a valid source device(s) when the media uploading configuration has transitioned from disabled to enabled state for either of the media types.

Parameters
videoCaptureDeviceAudioVideoCaptureDevice opened for at least video if video is enabled in the configuration
audioCaptureDeviceXNA Microphone instance for capturing audio
mediaConfigurationThe media uploading configuration used to set the devices in the UI
void Halyri.AudioVideoTransmitManager.ImageCaptureEventHandler ( object  sender,
EventArgs  e,
byte[]  jpgData 
)
private

Handles new jpeg images captured from the camera. Sends the pictures to server over WCF transfer channel if throttling does not prevent this action.

If UseUdp = true, uses UDP transfer channel and performs no throttling.

Parameters
senderSender instance of the event, not used
eEventArgs for the event, not used
jpgDataJPEG image byte data
void Halyri.AudioVideoTransmitManager.ImageCaptureEventHandler ( object  sender,
EventArgs  e,
byte[]  jpgData 
)
private

Handles new jpeg images captured from the camera. Sends the pictures to server over WCF transfer channel if throttling does not prevent this action.

If UseUdp = true, uses UDP transfer channel and performs no throttling.

Parameters
senderSender instance of the event, not used
eEventArgs for the event, not used
jpgDataJPEG image byte data
void Halyri.AudioVideoTransmitManager.MediaConfigurationUpdateHandler ( object  sender,
EventArgs  e,
MediaConfigurationDto  config 
)

Handles media uploading configurations received by NetworkConnection from server. This method only disbles audio and picture transmission if they are currently active and the new configuration suggests that they should be disabled. It also handles configuration changes to active audio and picture capturer classes.

If picture or audio is changed from enabled to disabled or vice versa, the configuration event is propagated through CaptureConfigurationUpdatedEvent to to the UI managing the capture devices.

Parameters
senderSending object
eEventargs, not currently used
configNew media uploading configuration
void Halyri.AudioVideoTransmitManager.MediaConfigurationUpdateHandler ( object  sender,
EventArgs  e,
MediaConfigurationDto  config 
)

Handles media uploading configurations received by NetworkConnection from server. This method only disbles audio and picture transmission if they are currently active and the new configuration suggests that they should be disabled. It also handles configuration changes to active audio and picture capturer classes.

If picture or audio is changed from enabled to disabled or vice versa, the configuration event is propagated through CaptureConfigurationUpdatedEvent to to the UI managing the capture devices.

Parameters
senderSending object
eEventargs, not currently used
configNew media uploading configuration
void Halyri.AudioVideoTransmitManager.MediaSendFinishedHandler ( object  sender,
AsyncCompletedEventArgs  e 
)
private

Handles async media send over WCF data channel finished events. Performs the throttling action by calculating the time used for sending the packet over the WCF data channel.

Not used id UseUdp = true;

Parameters
senderSender instance of the event, not used
eEventArgs that containt a UserState instance specifying the send time of the packet related to this event
void Halyri.AudioVideoTransmitManager.MediaSendFinishedHandler ( object  sender,
AsyncCompletedEventArgs  e 
)
private

Handles async media send over WCF data channel finished events. Performs the throttling action by calculating the time used for sending the packet over the WCF data channel.

Not used id UseUdp = true;

Parameters
senderSender instance of the event, not used
eEventArgs that containt a UserState instance specifying the send time of the packet related to this event
void Halyri.AudioVideoTransmitManager.PcmSampleEventHandler ( object  sender,
EventArgs  e,
byte[]  audioFrame 
)
private

Compresses the received PCM segment into speex format and transmit it over the UDP data channel if UseUdp = true. Otherwise returns immediately.

Parameters
senderSender instance of the event, not used
eEventArgs for the event, not used
audioFrameFramgnet of PCM data frames
void Halyri.AudioVideoTransmitManager.PcmSampleEventHandler ( object  sender,
EventArgs  e,
byte[]  audioFrame 
)
private

Compresses the received PCM segment into speex format and transmit it over the UDP data channel if UseUdp = true. Otherwise returns immediately.

Parameters
senderSender instance of the event, not used
eEventArgs for the event, not used
audioFrameFramgnet of PCM data frames
void Halyri.AudioVideoTransmitManager.ResetThrottlingState ( )

Resets the ECF transfer channel throttling state of this instance. If packet transmissiong has been stalled due to throttling, packet transmission will resume.

Has no effect if the UDP transfer channel is being used.

void Halyri.AudioVideoTransmitManager.ResetThrottlingState ( )

Resets the ECF transfer channel throttling state of this instance. If packet transmissiong has been stalled due to throttling, packet transmission will resume.

Has no effect if the UDP transfer channel is being used.

void Halyri.AudioVideoTransmitManager.StopAllCaptureTransmit ( )

Disables media capture and transmission from any device.

void Halyri.AudioVideoTransmitManager.StopAllCaptureTransmit ( )

Disables media capture and transmission from any device.

Member Data Documentation

WavAudioSampleCapturer Halyri.AudioVideoTransmitManager.audioCapturer
private
Microphone Halyri.AudioVideoTransmitManager.audioDevice
private
bool Halyri.AudioVideoTransmitManager.audioEnabled = false
private
CaptureConfigurationUpdated Halyri.AudioVideoTransmitManager.CaptureConfigurationUpdatedEvent
Connection Halyri.AudioVideoTransmitManager.connection
private
int [] Halyri.AudioVideoTransmitManager.imageWidthMapping
staticprivate
MediaConfigurationDto Halyri.AudioVideoTransmitManager.latestMediaConfiguration
private
static MediaInformationDto Halyri.AudioVideoTransmitManager.outgoingJpgInformation
staticprivate
static MediaInformationDto Halyri.AudioVideoTransmitManager.outgoingWaveInformation
staticprivate
int Halyri.AudioVideoTransmitManager.overdueLimitMilliseconds = 9050
private
int Halyri.AudioVideoTransmitManager.overduePacketCount = 0
private
int Halyri.AudioVideoTransmitManager.overduePacketLimitDisableAll = 12
private
int Halyri.AudioVideoTransmitManager.overduePacketLimitDisablePictures = 8
private
int Halyri.AudioVideoTransmitManager.overduePacketLimitSkipPictures = 4
private
PacketSendStalled Halyri.AudioVideoTransmitManager.PacketSendStalledEvent
bool Halyri.AudioVideoTransmitManager.packetThrotting = false
private
PacketThrottlingStarted Halyri.AudioVideoTransmitManager.PacketThrottlingStartedEvent
PreviewImageCapturer Halyri.AudioVideoTransmitManager.pictureCapturer
private
bool Halyri.AudioVideoTransmitManager.pictureEnabled = false
private
int Halyri.AudioVideoTransmitManager.pictureSkipCounter = 0
private
int Halyri.AudioVideoTransmitManager.pictureSkipFactor = 1
private
SpeexEncoder Halyri.AudioVideoTransmitManager.speexEncoder
private
int Halyri.AudioVideoTransmitManager.successiveSuccesfullPacketCount = 0
private
int Halyri.AudioVideoTransmitManager.throttlingDecreaseFactor = 2
private
Object Halyri.AudioVideoTransmitManager.ThrottlingParameterLock = new Object()
private
static MediaInformation Halyri.AudioVideoTransmitManager.udpOutgoingJpgInformation
staticprivate
static MediaInformation Halyri.AudioVideoTransmitManager.udpOutgoingSpeexInformation
staticprivate
static MediaInformation Halyri.AudioVideoTransmitManager.udpOutgoingWaveInformation
staticprivate
bool Halyri.AudioVideoTransmitManager.useUdp = true
private
AudioVideoCaptureDevice Halyri.AudioVideoTransmitManager.videoDevice
private

Property Documentation

bool Halyri.AudioVideoTransmitManager.AudioEnabled
get
bool Halyri.AudioVideoTransmitManager.PacketThrottlingEnabled
get
bool Halyri.AudioVideoTransmitManager.PictureEnabled
get
bool Halyri.AudioVideoTransmitManager.UseUdp
getset

The documentation for this class was generated from the following file: