* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
using System;
using System.Threading.Tasks;
-using System.Runtime.InteropServices;
namespace Tizen.Multimedia
{
private bool _disposed = false;
private EventHandler<StateChangedEventArgs> _stateChanged;
- private Interop.ScreenMirroring.StateErrorCallback _stateErrorCallback;
- private EventHandler<ErrorOccurredEventArgs> _errorOccurred;
+ private Interop.ScreenMirroring.StateChangedCallback _stateChangedCallback;
/// <summary>
/// Initializes a new instance of the ScreenMirroring class with parameters Ip, Port, Surface type and Display handle.
public ScreenMirroring(SurfaceType type, MediaView display, string ip, string port)
{
int ret = Interop.ScreenMirroring.Create(out _handle);
- if (ret != (int)SCMirroringError.None)
+ if (ret != (int)ScreenMirroringError.None)
{
ScreenMirroringErrorFactory.ThrowException(ret, "Failed to create Screen Mirroring Sink");
}
// Set ip and port
int ret1 = Interop.ScreenMirroring.SetIpAndPort(_handle, _ip, _port);
- if (ret1 != (int)SCMirroringError.None)
+ if (ret1 != (int)ScreenMirroringError.None)
{
- Log.Error(ScreenMirroringLog.LogTag, "Set ip and port failed" + (SCMirroringError)ret1);
+ Log.Error(ScreenMirroringLog.LogTag, "Set ip and port failed" + (ScreenMirroringError)ret1);
ScreenMirroringErrorFactory.ThrowException(ret, "set ip and port failed");
}
// Set display
int ret2 = Interop.ScreenMirroring.SetDisplay(_handle, (int)_type, _display);
- if (ret2 != (int)SCMirroringError.None)
+ if (ret2 != (int)ScreenMirroringError.None)
{
- Log.Error(ScreenMirroringLog.LogTag, "Set display failed" + (SCMirroringError)ret2);
+ Log.Error(ScreenMirroringLog.LogTag, "Set display failed" + (ScreenMirroringError)ret2);
ScreenMirroringErrorFactory.ThrowException(ret, "set display failed");
}
}
/// <summary>
- /// ErrorOccurred event is raised when error is occured in screen mirroring sink.
- /// Must be called after Create() API.
- /// </summary>
- public event EventHandler<ErrorOccurredEventArgs> ErrorOccurred
- {
- add
- {
- if (_errorOccurred == null)
- {
- RegisterErrorOccurredEvent();
- }
-
- _errorOccurred += value;
- }
-
- remove
- {
- _errorOccurred -= value;
- if (_errorOccurred == null)
- {
- UnregisterErrorOccurredEvent();
- }
- }
- }
-
- /// <summary>
/// Sets the server ip and port.
/// This must be called before connect() and after create().
/// </summary>
public void SetIpAndPort(string ip, string port)
{
int ret = Interop.ScreenMirroring.SetIpAndPort(_handle, ip, port);
- if (ret != (int)SCMirroringError.None)
+ if (ret != (int)ScreenMirroringError.None)
{
- Log.Error(ScreenMirroringLog.LogTag, "Set ip and port failed" + (SCMirroringError)ret);
+ Log.Error(ScreenMirroringLog.LogTag, "Set ip and port failed" + (ScreenMirroringError)ret);
ScreenMirroringErrorFactory.ThrowException(ret, "set ip and port failed");
}
}
public void SetResolution(int resolution)
{
int ret = Interop.ScreenMirroring.SetResolution(_handle, resolution);
- if (ret != (int)SCMirroringError.None)
+ if (ret != (int)ScreenMirroringError.None)
{
- Log.Error(ScreenMirroringLog.LogTag, "Set resolution failed" + (SCMirroringError)ret);
+ Log.Error(ScreenMirroringLog.LogTag, "Set resolution failed" + (ScreenMirroringError)ret);
ScreenMirroringErrorFactory.ThrowException(ret, "set resolution failed");
}
}
/// </example>
/// <param name="type">Type.</param>
/// <param name="display">Display.</param>
- /// <remarks> Display Handle not clear </remarks>
+ /// <remarks> Display Handle creates using mediaview class </remarks>
/// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
/// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
public void SetDisplay(SurfaceType type, MediaView display)
{
int ret = Interop.ScreenMirroring.SetDisplay(_handle, (int)type, display);
- if (ret != (int)SCMirroringError.None)
+ if (ret != (int)ScreenMirroringError.None)
{
- Log.Error(ScreenMirroringLog.LogTag, "Set display failed" + (SCMirroringError)ret);
+ Log.Error(ScreenMirroringLog.LogTag, "Set display failed" + (ScreenMirroringError)ret);
ScreenMirroringErrorFactory.ThrowException(ret, "set display failed");
}
}
public void Prepare()
{
int ret = Interop.ScreenMirroring.Prepare(_handle);
- if (ret != (int)SCMirroringError.None)
+ if (ret != (int)ScreenMirroringError.None)
{
ScreenMirroringErrorFactory.ThrowException(ret, "Failed to prepare sink for screen mirroring");
}
}
/// <summary>
- /// Creates connection and prepare for receiving data from SCMIRRORING source.
+ /// Creates connection and prepare for receiving data from ScreenMirroring source.
/// This must be called after prepare().
/// </summary>
/// <remarks> It will not give the current state. Need to subscribe for event to get the current state </remarks>
/// <returns>bool value</returns>
/// <privilege>http://tizen.org/privilege/internet</privilege>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
/// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
public Task<bool> ConnectAsync()
{
var task = new TaskCompletionSource<bool>();
Task.Factory.StartNew(() =>
- {
- if (ret == (int)SCMirroringError.None)
{
- task.SetResult(true);
- }
-
- else if (ret != (int)SCMirroringError.None)
- {
- task.SetResult(false);
- ScreenMirroringErrorFactory.ThrowException(ret, "Failed to connect the screen mirroring source");
- }
- });
+ if (ret == (int)ScreenMirroringError.None)
+ {
+ task.SetResult(true);
+ }
+
+ else if (ret != (int)ScreenMirroringError.None)
+ {
+ Log.Error(ScreenMirroringLog.LogTag, "Failed to start screen mirroring" + (ScreenMirroringError)ret);
+ InvalidOperationException e = new InvalidOperationException("Operation Failed");
+ task.TrySetException(e);
+ }
+ });
return task.Task;
}
}
/// <summary>
- /// Start receiving data from the SCMIRRORING source and display it(Mirror).
+ /// Start receiving data from the ScreenMirroring source and display it(Mirror).
/// This must be called after connectasync().
/// </summary>
/// <remarks> It will not give the current state. Need to subscribe for event to get the current state </remarks>
/// <returns>bool value<returns>
/// <privilege>http://tizen.org/privilege/internet</privilege>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
/// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
public Task<bool> StartAsync()
{
var task = new TaskCompletionSource<bool>();
Task.Factory.StartNew(() =>
- {
- if (ret == (int)SCMirroringError.None)
{
- task.SetResult(true);
- }
-
- else if (ret != (int)SCMirroringError.None)
- {
- task.SetResult(false);
- ScreenMirroringErrorFactory.ThrowException(ret, "Failed to start the screen mirroring");
- }
- });
+ if (ret == (int)ScreenMirroringError.None)
+ {
+ task.SetResult(true);
+ }
+
+ else if (ret != (int)ScreenMirroringError.None)
+ {
+ Log.Error(ScreenMirroringLog.LogTag, "Failed to start screen mirroring" + (ScreenMirroringError)ret);
+ InvalidOperationException e = new InvalidOperationException("Operation Failed");
+ task.TrySetException(e);
+ }
+ });
return task.Task;
}
/// <summary>
- /// Pauses receiving data from the SCMIRRORING source.
+ /// Pauses receiving data from the ScreenMirroring source.
/// This must be called after startasync().
/// </summary>
/// <remarks> It will not give the current state. Need to subscribe for event to get the current state </remarks>
/// <returns>bool value</returns>
/// <privilege>http://tizen.org/privilege/internet</privilege>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
/// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
public Task<bool> PauseAsync()
{
var task = new TaskCompletionSource<bool>();
Task.Factory.StartNew(() =>
- {
- if (ret == (int)SCMirroringError.None)
- {
- task.SetResult(true);
- }
-
- else if (ret != (int)SCMirroringError.None)
{
- task.SetResult(false);
- ScreenMirroringErrorFactory.ThrowException(ret, "Failed to pause the receiving data from screen mirroring source");
- }
- });
+ if (ret == (int)ScreenMirroringError.None)
+ {
+ task.SetResult(true);
+ }
+
+ else if (ret != (int)ScreenMirroringError.None)
+ {
+ Log.Error(ScreenMirroringLog.LogTag, "Failed to start screen mirroring" + (ScreenMirroringError)ret);
+ InvalidOperationException e = new InvalidOperationException("Operation Failed");
+ task.TrySetException(e);
+ }
+ });
return task.Task;
}
/// <summary>
- /// Resumes receiving data from the SCMIRRORING source.
+ /// Resumes receiving data from the ScreenMirroring source.
/// This must be called after pauseasync().
/// </summary>
/// <remarks> It will not give the current state. Need to subscribe for event to get the current state </remarks>
/// <returns>bool value</returns>
/// <privilege>http://tizen.org/privilege/internet</privilege>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
/// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
public Task<bool> ResumeAsync()
{
var task = new TaskCompletionSource<bool>();
Task.Factory.StartNew(() =>
- {
- if (ret == (int)SCMirroringError.None)
{
- task.SetResult(true);
- }
-
- else if (ret != (int)SCMirroringError.None)
- {
- task.SetResult(false);
- ScreenMirroringErrorFactory.ThrowException(ret, "Failed to resume the receiving data from screen mirroring source");
- }
- });
+ if (ret == (int)ScreenMirroringError.None)
+ {
+ task.SetResult(true);
+ }
+
+ else if (ret != (int)ScreenMirroringError.None)
+ {
+ Log.Error(ScreenMirroringLog.LogTag, "Failed to start screen mirroring" + (ScreenMirroringError)ret);
+ InvalidOperationException e = new InvalidOperationException("Operation Failed");
+ task.TrySetException(e);
+ }
+ });
return task.Task;
}
/// valid states: connected/playing/paused
/// </summary>
/// <privilege>http://tizen.org/privilege/internet</privilege>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
+ /// <exception cref="ArgumentException">Thrown when method fail due to no connection between devices</exception>
/// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
public void Disconnect()
{
int ret = Interop.ScreenMirroring.Disconnect(_handle);
- if (ret != (int)SCMirroringError.None)
+ if (ret != (int)ScreenMirroringError.None)
{
ScreenMirroringErrorFactory.ThrowException(ret, "Failed to disconnect sink for screen mirroring");
}
/// Unprepare this instance.
/// valid states: prepared/disconnected.
/// </summary>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
/// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
public void Unprepare()
{
int ret = Interop.ScreenMirroring.Unprepare(_handle);
- if (ret != (int)SCMirroringError.None)
+ if (ret != (int)ScreenMirroringError.None)
{
ScreenMirroringErrorFactory.ThrowException(ret, "Failed to reset the screen mirroring sink");
}
private void StateError(int state, int error)
{
///if _stateChanged is subscribe, this will be invoke.
- StateChangedEventArgs eventArgsState = new StateChangedEventArgs(state);
+ StateChangedEventArgs eventArgsState = new StateChangedEventArgs(state, error);
_stateChanged?.Invoke(this, eventArgsState);
-
- ///if _errorOccurred is subscribe, this will be invoke.
- ErrorOccurredEventArgs eventArgsError = new ErrorOccurredEventArgs(error);
- _errorOccurred?.Invoke(this, eventArgsError);
}
/// <summary>
/// Registers the state changed event.
/// </summary>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
/// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
private void RegisterStateChangedEvent()
{
- _stateErrorCallback = (IntPtr userData, int state, int error) =>
+ _stateChangedCallback = (IntPtr userData, int state, int error) =>
{
StateError(state, error);
};
- int ret = Interop.ScreenMirroring.SetStateErrorCb(_handle, _stateErrorCallback, IntPtr.Zero);
- if (ret != (int)SCMirroringError.None)
+ int ret = Interop.ScreenMirroring.SetStateChangedCb(_handle, _stateChangedCallback, IntPtr.Zero);
+ if (ret != (int)ScreenMirroringError.None)
{
- Log.Error(ScreenMirroringLog.LogTag, "Setting StateChanged callback failed" + (SCMirroringError)ret);
+ Log.Error(ScreenMirroringLog.LogTag, "Setting StateChanged callback failed" + (ScreenMirroringError)ret);
ScreenMirroringErrorFactory.ThrowException(ret, "Setting StateChanged callback failed");
}
}
/// <summary>
/// Unregisters the state changed event.
/// </summary>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
/// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
private void UnregisterStateChangedEvent()
{
- int ret = Interop.ScreenMirroring.UnsetStateErrorCb(_handle);
- if (ret != (int)SCMirroringError.None)
+ int ret = Interop.ScreenMirroring.UnsetStateChangedCb(_handle);
+ if (ret != (int)ScreenMirroringError.None)
{
- Log.Error(ScreenMirroringLog.LogTag, "Unsetting StateChnaged callback failed" + (SCMirroringError)ret);
+ Log.Error(ScreenMirroringLog.LogTag, "Unsetting StateChnaged callback failed" + (ScreenMirroringError)ret);
ScreenMirroringErrorFactory.ThrowException(ret, "Unsetting StateChanged callback failed");
}
}
-
- /// <summary>
- /// Registers the error occurred event.
- /// </summary>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
- /// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
- private void RegisterErrorOccurredEvent()
- {
- _stateErrorCallback = (IntPtr userData, int state, int error) =>
- {
- StateError(state, error);
- };
-
- int ret = Interop.ScreenMirroring.SetStateErrorCb(_handle, _stateErrorCallback, IntPtr.Zero);
- if (ret != (int)SCMirroringError.None)
- {
- Log.Error(ScreenMirroringLog.LogTag, "Setting ErrorOccurred callback failed" + (SCMirroringError)ret);
- ScreenMirroringErrorFactory.ThrowException(ret, "Setting ErrorOccurred callback failed");
- }
- }
-
- /// <summary>
- /// Unregisters the error occurred event.
- /// </summary>
- /// <exception cref="ArgumentException">Thrown when method fail due to an invalid parameter</exception>
- /// <exception cref="InvalidOperationException">Thrown when method fail due to an internal error</exception>
- private void UnregisterErrorOccurredEvent()
- {
- int ret = Interop.ScreenMirroring.UnsetStateErrorCb(_handle);
- if (ret != (int)SCMirroringError.None)
- {
- Log.Error(ScreenMirroringLog.LogTag, "Unsetting ErrorOccurred callback failed" + (SCMirroringError)ret);
- ScreenMirroringErrorFactory.ThrowException(ret, "Unsetting ErrorOccurred callback failed");
- }
- }
}
-}
\ No newline at end of file
+}