int main(int argc, char **argv) { MastSendTool *tool = NULL; SF_INFO sfinfo; // Create the send tool object tool = new MastSendTool( MAST_TOOL_NAME ); tool->enable_scheduling(); // Parse the command line arguments // and configure the session parse_cmd_line( argc, argv, tool ); // Open the input file by filename memset( &sfinfo, 0, sizeof(sfinfo) ); g_input_file = sf_open(g_filename, SFM_READ, &sfinfo); if (g_input_file == NULL) MAST_FATAL("Failed to open input file:\n%s", sf_strerror(NULL)); tool->set_input_channels( sfinfo.channels ); tool->set_input_samplerate( sfinfo.samplerate ); // Display some information about the input file print_file_info( g_input_file, &sfinfo ); // Setup signal handlers mast_setup_signals(); // Run the main loop tool->run(); // Clean up delete tool; // Close input file if (sf_close( g_input_file )) { MAST_ERROR("Failed to close input file:\n%s", sf_strerror(g_input_file)); } // Success ! return 0; }
int main(int argc, char **argv) { MastSendTool *tool = NULL; jack_client_t* client = NULL; // Create the send tool object tool = new MastSendTool( MAST_TOOL_NAME ); // Parse the command line arguments // and configure the session parse_cmd_line( argc, argv, tool ); // Initialise Jack client = init_jack( tool ); if (client==NULL) MAST_FATAL( "Failed to initialise JACK client" ); // Get the samplerate of the JACK Router tool->set_input_samplerate( jack_get_sample_rate( client ) ); // Setup signal handlers mast_setup_signals(); // Run the main loop tool->run(); // Clean up delete tool; // Shut down JACK deinit_jack( client ); // Success ! return 0; }
int main(int argc, char **argv) { MastTool* tool = NULL; mblk_t* packet = NULL; mblk_t* body = NULL; PayloadType* pt = NULL; int payload_size = 0; // Create an RTP session tool = new MastTool( MAST_TOOL_NAME, RTP_SESSION_RECVONLY ); if (tool==NULL) return -1; // Parse the command line arguments // and configure the session parse_cmd_line( argc, argv, tool->get_session() ); // Setup signal handlers mast_setup_signals(); // Recieve a single packet packet = tool->wait_for_rtp_packet(); if (packet == NULL) MAST_FATAL("Failed to receive a packet"); body = packet->b_cont; payload_size = (body->b_wptr - body->b_rptr); // Display information about the packet received printf("\n"); printf("RTP Header\n"); printf("==========\n"); printf("Payload type : %u\n", rtp_get_payload_type( packet ) ); printf("Payload size : %u bytes\n", payload_size ); printf("Sequence Number : %u\n", rtp_get_seqnumber( packet ) ); printf("Timestamp : %u\n", rtp_get_timestamp( packet ) ); printf("SSRC Identifier : %x\n", rtp_get_ssrc( packet ) ); printf("Marker Bit : %s\n", rtp_get_markbit( packet ) ? "Set" : "Not Set"); printf("\n"); // Lookup the payload type pt = rtp_profile_get_payload( tool->get_profile(), rtp_get_payload_type( packet ) ); if (pt == NULL) { MAST_WARNING( "Payload type %u isn't registered with oRTP", rtp_get_payload_type( packet ) ); } else { const char* mime_major = "?"; printf("Payload Details\n"); printf("===============\n"); if (pt->type==PAYLOAD_AUDIO_CONTINUOUS) mime_major = "audio"; else if (pt->type==PAYLOAD_AUDIO_PACKETIZED) mime_major = "audio"; else if (pt->type==PAYLOAD_VIDEO) mime_major = "video"; printf("Mime Type : %s/%s\n", mime_major, pt->mime_type); if (pt->clock_rate) printf("Clock Rate : %u Hz\n", pt->clock_rate); if (pt->channels) printf("Channels : %u\n", pt->channels); if (pt->bits_per_sample) printf("Bits per Sample : %u\n", pt->bits_per_sample); if (pt->normal_bitrate) { printf("Normal Bitrate : %u kbps\n", (pt->normal_bitrate/1000)); printf("Packet duration : %u ms\n", (payload_size*1000)/(pt->normal_bitrate/8) ); } if (pt->recv_fmtp) printf("Recieve FMTP : %s\n", pt->recv_fmtp); if (pt->send_fmtp) printf("Send FMTP : %s\n", pt->send_fmtp); printf("\n"); } // Parse the MPEG Audio header if (rtp_get_payload_type( packet ) == RTP_MPEG_AUDIO_PT) { /* FIXME: check fragment offset header (see rfc2250) */ unsigned char* mpa_ptr = body->b_rptr + 4; MPA_Header mh; printf("MPEG Audio Header\n"); printf("=================\n"); if (!mh.parse( mpa_ptr )) { MAST_WARNING("Failed to parse MPEG Audio header"); } else { mh.debug( stdout ); } } // Close RTP session delete tool; // Success ! return 0; }
int main(int argc, char **argv) { MastTool* tool = NULL; RtpProfile* profile = &av_profile; PayloadType* pt = NULL; FILE* output = NULL; mblk_t* packet = NULL; int ts_diff = 0; int ts = 0; // Create an RTP session tool = new MastTool( MAST_TOOL_NAME, RTP_SESSION_RECVONLY ); tool->enable_scheduling(); // Parse the command line arguments // and configure the session parse_cmd_line( argc, argv, tool ); // Recieve an initial packet packet = tool->wait_for_rtp_packet(); if (packet == NULL) MAST_FATAL("Failed to receive an initial packet"); // Lookup the payload type pt = rtp_profile_get_payload( profile, rtp_get_payload_type( packet ) ); if (pt == NULL) MAST_FATAL( "Payload type %d isn't registered with oRTP", rtp_get_payload_type( packet ) ); fprintf(stderr, "Payload type: %s\n", payload_type_get_rtpmap( pt )); // Work out the duration of the packet ts_diff = mast_rtp_packet_duration( packet ); MAST_DEBUG("ts_diff = %d", ts_diff); // Open the output file output = open_output_file( g_filename ); if (output==NULL) MAST_FATAL( "failed to open output file" ); // We can free the packet now freemsg( packet ); // Setup signal handlers mast_setup_signals(); // The main loop while( mast_still_running() ) { // Read in a packet packet = rtp_session_recvm_with_ts( tool->get_session(), ts ); if (packet==NULL) { MAST_DEBUG( "packet is NULL" ); } else { int data_len = mast_rtp_packet_size( packet ); if (data_len==0) { MAST_WARNING("Failed to get size of packet's payload"); } else { unsigned char* data_ptr = packet->b_cont->b_rptr; int bytes_written = 0; // Skip the extra header for MPA payload if (rtp_get_payload_type( packet ) == RTP_MPEG_AUDIO_PT) { data_ptr += 4; data_len -= 4; } // Update the timestamp difference ts_diff = mast_rtp_packet_duration( packet ); MAST_DEBUG("ts_diff = %d", ts_diff); MAST_DEBUG("data_len = %d", data_len); // Write to disk bytes_written = fwrite( data_ptr, 1, data_len, output ); if (bytes_written != data_len) { MAST_ERROR("Failed to write data to disk: %s", strerror(errno) ); break; } } } // Increment the timestamp for the next packet ts += ts_diff; } // Close output file if (fclose( output )) { MAST_ERROR("Failed to close output file:\n%s", strerror(errno)); } // Close RTP session delete tool; // Success return 0; }