Trying to get a Stream from camera with the MIP SDK

Hi Milestone Support,

I’m encountering a challenge while integrating a live stream from the MIP SDK into another application. While using StreamDataSource seems like a promising approach, I’m unsure how to proceed further.

Here’s the code snippet I have so far:

private void StartLiveStream(VideoOS.Platform.Item camera)
{
    const int port = 7777;
    UdpClient udpClient = new UdpClient(port);
    Console.WriteLine($"Streaming server started on port {port}");
    while (true)
    {
        if (Console.KeyAvailable) break;
 
        // Current approach using StreamDataSource
        StreamDataSource streamSource = new StreamDataSource(camera);
        var stream = streamSource.GetTypes()[0];  // Clarification needed
 
        // Intended outcome (replace with actual stream handling)
        // udpClient.Send(sourceDgram, sourceDgram.Length, new IPEndPoint(IPAddress.Broadcast, port));
 
        // Simulate 30 FPS frame rate
        Thread.Sleep(33);
    }
    udpClient.Close();
}

My specific questions are:

  1. Retrieving Stream Data: How can I effectively access the actual video stream data using StreamDataSource or other suitable MIP SDK methods?
  2. Data Format: What format is the retrieved stream data in (e.g., raw bytes, encoded frames)?

I’d greatly appreciate any insights or recommendations you can offer to help me successfully integrate a live stream from the MIP SDK.

Thank you for your time and support.

Sincerely,

Ok, I found how to do it, I’m sharing the code for persons who are in need of the solution:

private void StartLiveStream(Item camera)
{
    // Create a new data source from the camera
    var streamDataSource = new StreamDataSource(camera);
    // Select the first available data type
    DataType dataTypeSelected = streamDataSource.GetTypes()[0];
    // Create a new live JPEG broadcast source from the camera
    var jpegLive = new JPEGLiveSource(camera)
    {
        // Set the stream ID to that of the selected data type
        StreamId = dataTypeSelected.Id,
        // Start the live broadcast
        LiveModeStart = true,
        // Set the height and width of the live broadcast to 0
        Height = 0,
        Width = 0,
    };
    // Initialize the live broadcast source
    jpegLive.Init();
    // Add an event handler for the live content
    jpegLive.LiveContentEvent += (sender, e) =>
    {
        // Convert the event argument to LiveContentEventArgs
        var args = e as LiveContentEventArgs;
        if (args != null)
        {
            // If live content is available, send it
            if (args.LiveContent != null)
            {
                SendBytes(args.LiveContent.Content);
            }
            // If an exception occurred, display it
            else if (args.Exception != null)
            {
                Console.WriteLine("Error: " + args.Exception.Message);
            }
        }
    };
}