static void demux_close_rtp(demuxer_t* demuxer) { Nemesi_DemuxerStreamData * ndsd = demuxer->priv; rtsp_ctrl * ctl = ndsd->rtsp; RTSP_Error err; mp_msg(MSGT_DEMUX, MSGL_INFO, "Closing libNemesi RTSP Stream...\n"); if (ndsd == NULL) return; free(ndsd); if (rtsp_close(ctl)) { err = rtsp_wait(ctl); if (err.got_error) mp_msg(MSGT_DEMUX, MSGL_ERR, "Error Closing Stream: %s\n", err.message.reply_str); } rtsp_uninit(ctl); }
int main(int argc, char **argv) { int opt; char *url, *out = "nemesi.dump"; FILE *outfile = NULL; rtsp_ctrl *ctl; rtsp_session *sess; rtsp_medium *med; nms_rtsp_hints rtsp_hints = { -1 }; sdp_attr *attr; RTSP_Error reply; if (argc < 2) { fprintf(stderr, "\tPlease specify at least an url.\n"); fprintf(stderr, "\tUsage: %s [-f outputfile ] [-p rtp_port] [-t url\n", argv[0]); exit(1); } #ifndef WIN32 while ((opt = getopt(argc, argv, "df:p:v:")) != -1) { switch (opt) { /* Set output file */ case 'f': out = strdup(optarg); break; /* Set rtp port */ case 'p': rtsp_hints.first_rtp_port = atoi(optarg); break; /* Set verbosity */ case 'v': nms_verbosity_set(atoi(optarg)); break; /* Unknown option */ case '?': fprintf(stderr, "\n Unknown option `-%c'.\n", optopt); fprintf(stderr, "\tUsage: %s [-f outputfile ] [-d] url\n\n", argv[0]); return 1; } } #endif outfile = fopen(out, "rb"); if (outfile == NULL) outfile = stderr; url = argv[argc - 1]; fprintf(stderr, "URL %s.\n", url); /* initialize the rtsp state machine, starts the rtsp and the rtp threads * the hints available are just one: * - the first port to use (instead of picking one at random) */ if ((ctl = rtsp_init(&rtsp_hints)) == NULL) { fprintf(stderr, "Cannot init rtsp.\n"); return 1; } if (rtsp_open(ctl, url)) { fprintf(stderr, "rtsp_open failed.\n"); // die return 1; } // you must call rtsp_wait after issuing any command reply = rtsp_wait(ctl); printf("OPEN: Received reply from server: %s\n", reply.message.reply_str); // Get the session information sess = ctl->rtsp_queue; if (!sess) { fprintf(stderr, "No session available.\n"); return 1; } while (sess) { // foreach session... fprintf(outfile, "\tSession %s\n", sess->pathname); fprintf(outfile, "\tSession Duration %s\n", sess->info->t); for (attr = sess->info->attr_list; attr; attr = attr->next) { fprintf(outfile, "\t* %s %s\n", attr->name, attr->value); } med = sess->media_queue; while (med) { //... foreach medium switch (med->medium_info->media_type) { // Just care about audio and video case 'A': case 'V': fprintf(outfile, "\tTransport %s\n", med->medium_info->transport); fprintf(outfile, "\tMedia Type %s\n", (med->medium_info->media_type == 'A'? "Audio" : "Video")); fprintf(outfile, "\tMedia format %s\n", med->medium_info->fmts); break; default: //do nothing break; } // attributes are already parsed, get them from the list for (attr = med->medium_info->attr_list; attr; attr = attr->next) { fprintf(outfile, "\t* %s %s\n", attr->name, attr->value); } med = med->next; } sess = sess->next; } /* * Close the rtsp connection, we are polite */ rtsp_close(ctl); reply = rtsp_wait(ctl); printf("CLOSE: Received reply from server: %s\n", reply.message.reply_str); /* * Kill the threads, dealloc everything. */ rtsp_uninit(ctl); return 0; }