### Preview Mode and Dynamic Quality Control (C) Source: https://context7.com/openmediatransport/libomt/llms.txt Demonstrates receiving low-resolution preview frames and dynamically adjusting quality preferences. The `OMTReceiveFlags_Preview` flag enables preview mode, and `omt_receive_setsuggestedquality` can be used to suggest encoding quality. The example shows switching from preview to full resolution by changing flags and quality settings during runtime. ```c #include "libomt.h" #include int main() { // Start in preview mode (1/8th resolution) omt_receive_t* receiver = omt_receive_create( "omt://hostname:6400", OMTFrameType_Video, OMTPreferredVideoFormat_UYVY, OMTReceiveFlags_Preview ); if (!receiver) { return 1; } // Suggest low quality encoding omt_receive_setsuggestedquality(receiver, OMTQuality_Low); printf("Receiving preview frames...\n"); for (int i = 0; i < 60; i++) { OMTMediaFrame* frame = omt_receive(receiver, OMTFrameType_Video, 1000); if (frame) { printf("Preview frame: %dx%d\n", frame->Width, frame->Height); } } // Switch to full resolution dynamically printf("Switching to full resolution...\n"); omt_receive_setflags(receiver, OMTReceiveFlags_None); omt_receive_setsuggestedquality(receiver, OMTQuality_High); for (int i = 0; i < 60; i++) { OMTMediaFrame* frame = omt_receive(receiver, OMTFrameType_Video, 1000); if (frame) { printf("Full frame: %dx%d\n", frame->Width, frame->Height); } } omt_receive_destroy(receiver); return 0; } ``` -------------------------------- ### Create and Send Video Frames (C) Source: https://context7.com/openmediatransport/libomt/llms.txt This C code example shows how to create a sender instance using libomt and broadcast video frames over the network. It handles sender creation, address retrieval, setting sender information, allocating and filling video buffers, and sending frames with automatic quality negotiation. The code requires the libomt library and standard C libraries for memory management and string manipulation. ```c #include "libomt.h" #include #include int main() { // Create sender with name and quality setting omt_send_t* sender = omt_send_create("My Video Source", OMTQuality_High); if (!sender) { return 1; } // Get and display the sender's address char address[OMT_MAX_STRING_LENGTH] = {0}; omt_send_getaddress(sender, address, OMT_MAX_STRING_LENGTH); printf("Sender address: %s\n", address); // Set sender information OMTSenderInfo info = {0}; strncpy(info.ProductName, "Video Capture App", OMT_MAX_STRING_LENGTH - 1); strncpy(info.Manufacturer, "MyCompany", OMT_MAX_STRING_LENGTH - 1); strncpy(info.Version, "1.0.0", OMT_MAX_STRING_LENGTH - 1); omt_send_setsenderinformation(sender, &info); // Allocate video buffer (1920x1080 UYVY format) int width = 1920; int height = 1080; int stride = width * 2; // UYVY is 2 bytes per pixel int buffer_size = stride * height; void* video_buffer = malloc(buffer_size); // Fill with test pattern (gray frame) memset(video_buffer, 0x80, buffer_size); // Prepare video frame OMTMediaFrame frame = {0}; frame.Type = OMTFrameType_Video; frame.Codec = OMTCodec_UYVY; frame.Width = width; frame.Height = height; frame.Stride = stride; frame.FrameRateN = 60; frame.FrameRateD = 1; frame.AspectRatio = 16.0f / 9.0f; frame.ColorSpace = OMTColorSpace_BT709; frame.Data = video_buffer; frame.DataLength = buffer_size; frame.Timestamp = -1; // Auto-generate timestamps // Send 300 frames (5 seconds at 60fps) for (int i = 0; i < 300; i++) { int result = omt_send(sender, &frame); if (result == 0) { printf("Failed to send frame %d\n", i); } // Check connection count int connections = omt_send_connections(sender); if (i % 60 == 0) { printf("Frame %d sent, %d receivers connected\n", i, connections); } } free(video_buffer); omt_send_destroy(sender); return 0; } ``` -------------------------------- ### Receive Compressed Video Frames for Recording (C) Source: https://context7.com/openmediatransport/libomt/llms.txt Receives compressed VMX1 video frames without decoding, which is ideal for recording or forwarding. The `OMTReceiveFlags_IncludeCompressed` flag is used to obtain the compressed data. The example writes both uncompressed UYVY data and compressed VMX1 data to separate files. File operations are handled using standard C file I/O. ```c #include "libomt.h" #include int main() { omt_receive_t* receiver = omt_receive_create( "omt://hostname:6400", OMTFrameType_Video, OMTPreferredVideoFormat_UYVY, OMTReceiveFlags_IncludeCompressed // Also get compressed data ); if (!receiver) { return 1; } FILE* compressed_file = fopen("output.vmx", "wb"); FILE* uncompressed_file = fopen("output.uyvy", "wb"); for (int i = 0; i < 100; i++) { OMTMediaFrame* frame = omt_receive(receiver, OMTFrameType_Video, 5000); if (frame) { // Write uncompressed UYVY data if (frame->Data && frame->DataLength > 0) { fwrite(frame->Data, 1, frame->DataLength, uncompressed_file); } // Write compressed VMX1 data for recording if (frame->CompressedData && frame->CompressedLength > 0) { fwrite(frame->CompressedData, 1, frame->CompressedLength, compressed_file); printf("Frame %d: compressed %d bytes -> uncompressed %d bytes\n", i, frame->CompressedLength, frame->DataLength); } } } fclose(compressed_file); fclose(uncompressed_file); omt_receive_destroy(receiver); return 0; } ``` -------------------------------- ### Discover Network Media Sources (C) Source: https://context7.com/openmediatransport/libomt/llms.txt This C code snippet demonstrates how to discover available media sources on the network using the libomt discovery API. It retrieves an array of network addresses that can be used by receivers to connect to senders. No external dependencies are required beyond the libomt header. ```c #include "libomt.h" #include int main() { int count = 0; char** addresses = omt_discovery_getaddresses(&count); if (addresses != NULL && count > 0) { printf("Found %d sources:\n", count); for (int i = 0; i < count; i++) { printf(" [%d] %s\n", i, addresses[i]); } // Use addresses[0] to connect a receiver return 0; } printf("No sources found on network\n"); return 1; } ``` -------------------------------- ### Send Audio Frames with libomt Source: https://context7.com/openmediatransport/libomt/llms.txt Sends 32-bit floating-point planar audio frames to connected receivers using libomt. It handles audio configuration, buffer allocation, sine wave generation for testing, and frame packaging with sample-accurate timing. Dependencies include stdlib.h and math.h for memory allocation and mathematical functions. ```c #include "libomt.h" #include #include int main() { omt_send_t* sender = omt_send_create("Audio Source", OMTQuality_Default); if (!sender) { return 1; } // Audio configuration: 48kHz, 2 channels, 1920 samples per buffer int sample_rate = 48000; int channels = 2; int samples_per_channel = 1920; // 40ms at 48kHz int bytes_per_channel = samples_per_channel * sizeof(float); int total_bytes = bytes_per_channel * channels; // Allocate planar audio buffer (separate buffer per channel) float* audio_buffer = (float*)malloc(total_bytes); // Generate 1 second of 440Hz tone on left, 880Hz on right for (int frame = 0; frame < 25; frame++) { // 25 frames = 1 second // Left channel: 440Hz sine wave for (int i = 0; i < samples_per_channel; i++) { float t = (float)(frame * samples_per_channel + i) / sample_rate; audio_buffer[i] = sinf(2.0f * 3.14159f * 440.0f * t) * 0.5f; } // Right channel: 880Hz sine wave for (int i = 0; i < samples_per_channel; i++) { float t = (float)(frame * samples_per_channel + i) / sample_rate; audio_buffer[samples_per_channel + i] = sinf(2.0f * 3.14159f * 880.0f * t) * 0.5f; } OMTMediaFrame audio_frame = {0}; audio_frame.Type = OMTFrameType_Audio; audio_frame.Codec = OMTCodec_FPA1; // Floating-point planar audio audio_frame.SampleRate = sample_rate; audio_frame.Channels = channels; audio_frame.SamplesPerChannel = samples_per_channel; audio_frame.Data = audio_buffer; audio_frame.DataLength = total_bytes; audio_frame.Timestamp = -1; // Auto-generate if (!omt_send(sender, &audio_frame)) { printf("Failed to send audio frame %d\n", frame); } } free(audio_buffer); omt_send_destroy(sender); return 0; } ``` -------------------------------- ### Sender API - Create and Send Video Frames Source: https://context7.com/openmediatransport/libomt/llms.txt Creates a sender instance that broadcasts media to connected receivers, with automatic quality negotiation based on receiver preferences. ```APIDOC ## Sender API - Create and Send Video Frames ### Description Creates a sender instance that broadcasts media to connected receivers, with automatic quality negotiation based on receiver preferences. ### Method POST (Implicit) ### Endpoint N/A (Function Calls) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Function parameters and structures) - **name** (const char*) - Name of the sender. - **quality** (OMTQuality) - Desired initial quality setting (e.g., OMTQuality_High). - **OMTSenderInfo** (struct) - Information about the sender (ProductName, Manufacturer, Version). - **OMTMediaFrame** (struct) - Structure containing details and data for the media frame to be sent. ### Request Example ```c #include "libomt.h" #include #include int main() { // Create sender with name and quality setting omt_send_t* sender = omt_send_create("My Video Source", OMTQuality_High); if (!sender) { return 1; } // Get and display the sender's address char address[OMT_MAX_STRING_LENGTH] = {0}; omt_send_getaddress(sender, address, OMT_MAX_STRING_LENGTH); printf("Sender address: %s\n", address); // Set sender information OMTSenderInfo info = {0}; strncpy(info.ProductName, "Video Capture App", OMT_MAX_STRING_LENGTH - 1); strncpy(info.Manufacturer, "MyCompany", OMT_MAX_STRING_LENGTH - 1); strncpy(info.Version, "1.0.0", OMT_MAX_STRING_LENGTH - 1); omt_send_setsenderinformation(sender, &info); // Allocate video buffer (1920x1080 UYVY format) int width = 1920; int height = 1080; int stride = width * 2; // UYVY is 2 bytes per pixel int buffer_size = stride * height; void* video_buffer = malloc(buffer_size); // Fill with test pattern (gray frame) memset(video_buffer, 0x80, buffer_size); // Prepare video frame OMTMediaFrame frame = {0}; frame.Type = OMTFrameType_Video; frame.Codec = OMTCodec_UYVY; frame.Width = width; frame.Height = height; frame.Stride = stride; frame.FrameRateN = 60; frame.FrameRateD = 1; frame.AspectRatio = 16.0f / 9.0f; frame.ColorSpace = OMTColorSpace_BT709; frame.Data = video_buffer; frame.DataLength = buffer_size; frame.Timestamp = -1; // Auto-generate timestamps // Send 300 frames (5 seconds at 60fps) for (int i = 0; i < 300; i++) { int result = omt_send(sender, &frame); if (result == 0) { printf("Failed to send frame %d\n", i); } // Check connection count int connections = omt_send_connections(sender); if (i % 60 == 0) { printf("Frame %d sent, %d receivers connected\n", i, connections); } } free(video_buffer); omt_send_destroy(sender); return 0; } ``` ### Response #### Success Response (Implicit) - **Return Value** (int) - Returns 1 on success, 0 on failure for sending frames. Other functions like `omt_send_create` return a pointer to `omt_send_t` on success and NULL on failure. - **Address** (char array) - The sender's network address is retrieved via `omt_send_getaddress`. - **Connection Count** (int) - The number of connected receivers can be queried using `omt_send_connections`. #### Response Example ```json // C code demonstrates usage, not a direct JSON response // Example output: // Sender address: tcp://0.0.0.0:5000 // Frame 0 sent, 1 receivers connected // Frame 60 sent, 1 receivers connected // ... // Frame 240 sent, 1 receivers connected ``` ``` -------------------------------- ### Configure Custom Discovery Server in C Source: https://context7.com/openmediatransport/libomt/llms.txt Configures a centralized discovery server URL for libomt, overriding the default local DNS-SD. This is useful for managing discovery in larger or more controlled network environments. ```c #include "libomt.h" #include int main() { // Set discovery server URL before any discovery operations omt_settings_set_string("DiscoveryServer", "omt://discovery.example.com:6399"); // Verify setting char server[OMT_MAX_STRING_LENGTH] = {0}; int len = omt_settings_get_string("DiscoveryServer", server, OMT_MAX_STRING_LENGTH); if (len > 0) { printf("Discovery server: %s\n", server); } // Now discovery will query the centralized server int count = 0; char** addresses = omt_discovery_getaddresses(&count); // Clear to revert to DNS-SD omt_settings_set_string("DiscoveryServer", ""); return 0; } ``` -------------------------------- ### Connect and Receive Decoded Video Frames with Format Conversion (C) Source: https://context7.com/openmediatransport/libomt/llms.txt Connects to a media sender and receives decoded video and audio frames. It supports automatic format conversion to UYVY or BGRA and allows for receiving compressed data for recording. The function omt_receive_create initializes the receiver, and omt_receive fetches frames. Error handling for connection failures and frame reception timeouts is included. ```c #include "libomt.h" #include int main() { // Connect using address from discovery or manual URL const char* address = "omt://hostname:6400"; omt_receive_t* receiver = omt_receive_create( address, OMTFrameType_Video | OMTFrameType_Audio, OMTPreferredVideoFormat_UYVYorBGRA, // Get BGRA only if alpha present OMTReceiveFlags_None ); if (!receiver) { printf("Failed to connect to %s\n", address); return 1; } // Get sender information OMTSenderInfo info = {0}; omt_receive_getsenderinformation(receiver, &info); printf("Connected to: %s by %s (v%s)\n", info.ProductName, info.Manufacturer, info.Version); // Receive 300 video frames for (int i = 0; i < 300; i++) { OMTMediaFrame* frame = omt_receive(receiver, OMTFrameType_Video, 5000); if (frame) { printf("Frame %d: %dx%d %s, %d bytes, timestamp: %lld\n", i, frame->Width, frame->Height, frame->Codec == OMTCodec_UYVY ? "UYVY" : "BGRA", frame->DataLength, frame->Timestamp); // Process video data // frame->Data contains the pixel data // frame->Stride is the row stride in bytes // Check for per-frame metadata if (frame->FrameMetadata && frame->FrameMetadataLength > 0) { printf("Frame metadata: %s\n", (char*)frame->FrameMetadata); } } else { printf("Timeout waiting for frame\n"); break; } } omt_receive_destroy(receiver); return 0; } ``` -------------------------------- ### Discovery API - Network Source Discovery Source: https://context7.com/openmediatransport/libomt/llms.txt Discovers available media sources on the network, returning an array of addresses that can be used to connect receivers to senders. ```APIDOC ## Discovery API - Network Source Discovery ### Description Discovers available media sources on the network, returning an array of addresses that can be used to connect receivers to senders. ### Method GET (Implicit) ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include "libomt.h" #include int main() { int count = 0; char** addresses = omt_discovery_getaddresses(&count); if (addresses != NULL && count > 0) { printf("Found %d sources:\n", count); for (int i = 0; i < count; i++) { printf(" [%d] %s\n", i, addresses[i]); } // Use addresses[0] to connect a receiver return 0; } printf("No sources found on network\n"); return 1; } ``` ### Response #### Success Response (Implicit) - **addresses** (char**) - An array of strings, where each string is a network address of a discovered media source. The `count` parameter is updated with the number of addresses found. #### Response Example ```json // C code demonstrates usage, not a direct JSON response // Example output: // Found 2 sources: // [0] tcp://192.168.1.100:8080 // [1] tcp://192.168.1.101:8080 ``` ``` -------------------------------- ### Monitor Sender Statistics with libomt Source: https://context7.com/openmediatransport/libomt/llms.txt Retrieves and displays performance statistics for video and audio transmission using libomt. This includes metrics such as bytes sent, frame counts, dropped frames, and codec encoding time. Requires stdio.h for printing output. ```c #include "libomt.h" #include void print_statistics(omt_send_t* sender) { OMTStatistics video_stats = {0}; OMTStatistics audio_stats = {0}; omt_send_getvideostatistics(sender, &video_stats); omt_send_getaudiostatistics(sender, &audio_stats); // Calculate bitrate (bytes per second) double video_mbps = (video_stats.BytesSentSinceLast * 8.0) / (1000000.0); printf("Video: %.2f Mbps, %lld frames, %lld dropped\n", video_mbps, video_stats.Frames, video_stats.FramesDropped); // Calculate average encoding time if (video_stats.Frames > 0) { double avg_encode_ms = (double)video_stats.CodecTime / video_stats.Frames; printf("Average encode time: %.2f ms\n", avg_encode_ms); } printf("Last frame encode: %lld ms\n", video_stats.CodecTimeSinceLast); printf("Audio: %lld bytes sent, %lld frames\n", audio_stats.BytesSent, audio_stats.Frames); } ``` -------------------------------- ### Set Tally States (Preview/Program) in C Source: https://context7.com/openmediatransport/libomt/llms.txt Sets tally states (preview/program) for a receiver, which are aggregated and sent to the sender. This allows for integration with production workflows. ```c #include "libomt.h" #include int main() { omt_receive_t* receiver = omt_receive_create( "omt://hostname:6400", OMTFrameType_Video, OMTPreferredVideoFormat_UYVY, OMTReceiveFlags_None ); if (!receiver) { return 1; } // Set tally to indicate this receiver has the source on preview OMTTally tally = {0}; tally.preview = 1; // Source is on preview monitor tally.program = 0; // Not on program output omt_receive_settally(receiver, &tally); printf("Set preview tally ON\n"); // Process frames for 5 seconds for (int i = 0; i < 300; i++) { OMTMediaFrame* frame = omt_receive(receiver, OMTFrameType_Video, 100); if (frame) { // Process video... } // Switch to program after 3 seconds if (i == 180) { tally.preview = 0; tally.program = 1; omt_receive_settally(receiver, &tally); printf("Set program tally ON\n"); } } // Clear tally tally.preview = 0; tally.program = 0; omt_receive_settally(receiver, &tally); omt_receive_destroy(receiver); return 0; } ``` -------------------------------- ### Send Metadata and Tally with libomt Source: https://context7.com/openmediatransport/libomt/llms.txt Transmits XML metadata to receivers and monitors tally states using libomt. This includes sending connection-specific metadata, per-frame metadata, and querying the current tally status (preview/program). It also demonstrates receiving metadata from remote senders. Requires string.h for string manipulation. ```c #include "libomt.h" #include int main() { omt_send_t* sender = omt_send_create("Camera 1", OMTQuality_Medium); if (!sender) { return 1; } // Add connection metadata (sent automatically to new receivers) const char* metadata_xml = "" "CAM-001Studio A"; omt_send_addconnectionmetadata(sender, metadata_xml); // Send per-frame metadata const char* frame_metadata = "01:00:00:00"; OMTMediaFrame metadata_frame = {0}; metadata_frame.Type = OMTFrameType_Metadata; metadata_frame.Data = (void*)frame_metadata; metadata_frame.DataLength = strlen(frame_metadata) + 1; // Include null terminator omt_send(sender, &metadata_frame); // Monitor tally state with 100ms timeout OMTTally tally = {0}; int changed = omt_send_gettally(sender, 100, &tally); if (changed) { printf("Tally changed - Preview: %d, Program: %d\n", tally.preview, tally.program); } // Receive metadata from receivers OMTMediaFrame* received = omt_send_receive(sender, 5000); // 5 second timeout if (received && received->Type == OMTFrameType_Metadata) { printf("Received metadata: %s\n", (char*)received->Data); } omt_send_clearconnectionmetadata(sender); omt_send_destroy(sender); return 0; } ``` -------------------------------- ### Configure Logging File Location in C Source: https://context7.com/openmediatransport/libomt/llms.txt Configures the log file location for debugging and troubleshooting libomt operations. Logs can be written to a specified file or disabled by setting the filename to NULL. ```c #include "libomt.h" int main() { // Set custom log file before creating any instances omt_setloggingfilename("/var/log/myapp/omt.log"); // Or disable logging omt_setloggingfilename(NULL); // Now create sender/receiver instances omt_send_t* sender = omt_send_create("Source", OMTQuality_High); // Logs will be written to the specified file omt_send_destroy(sender); return 0; } ``` -------------------------------- ### Configure Sender Network Port Range in C Source: https://context7.com/openmediatransport/libomt/llms.txt Configures the port range used for sender instances. This allows control over the network ports libomt will use for outgoing connections. ```c #include "libomt.h" int main() { // Configure port range before creating senders omt_settings_set_integer("NetworkPortStart", 7000); omt_settings_set_integer("NetworkPortEnd", 7100); // Verify settings int start = omt_settings_get_integer("NetworkPortStart"); int end = omt_settings_get_integer("NetworkPortEnd"); printf("Using ports %d-%d\n", start, end); // Create sender (will use port in 7000-7100 range) omt_send_t* sender = omt_send_create("My Source", OMTQuality_Default); omt_send_destroy(sender); return 0; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.