int main(int argc, char *argv[]) { unsigned char bbuf[ 204 + 10]; /* bin data buffer */ char tbuf[1024 + 10]; /* txt data buffer */ if(0 != deal_with_parameter(argc, argv)) { return -1; } fd_i = url_open(file_i, "rb"); if(NULL == fd_i) { RPT(RPT_ERR, "open \"%s\" failed", file_i); return -1; } pkt_addr = 0; while(1 == url_read(bbuf, npline, 1, fd_i)) { fprintf(stdout, "*ts, "); b2t(tbuf, bbuf, 188); fprintf(stdout, "%s", tbuf); fprintf(stdout, "*addr, %llX, \n", pkt_addr); pkt_addr += npline; } url_close(fd_i); return 0; }
static int md5_close(URLContext *h) { const char *filename = h->filename; uint8_t md5[16], buf[64]; URLContext *out; int i, err = 0; av_md5_final(h->priv_data, md5); for (i = 0; i < sizeof(md5); i++) snprintf(buf + i*2, 3, "%02x", md5[i]); buf[i*2] = '\n'; av_strstart(filename, "md5:", &filename); if (*filename) { err = url_open(&out, filename, URL_WRONLY); if (err) return err; err = url_write(out, buf, i*2+1); url_close(out); } else { if (fwrite(buf, 1, i*2+1, stdout) < i*2+1) err = AVERROR(errno); } return err; }
static int gopher_open(URLContext *h, const char *uri, int flags) { GopherContext *s; char hostname[1024], auth[1024], path[1024], buf[1024]; int port, err; h->is_streamed = 1; s = av_malloc(sizeof(GopherContext)); if (!s) { return AVERROR(ENOMEM); } h->priv_data = s; /* needed in any case to build the host string */ ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, path, sizeof(path), uri); if (port < 0) port = 70; ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); s->hd = NULL; err = url_open(&s->hd, buf, URL_RDWR); if (err < 0) goto fail; if ((err = gopher_connect(h, path)) < 0) goto fail; return 0; fail: gopher_close(h); return err; }
int url_exist(const char *filename) { URLContext *h; if (url_open(&h, filename, URL_RDONLY) < 0) return 0; url_close(h); return 1; }
static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap) { RTSPState *rt = s->priv_data; RTSPStream *rtsp_st; int size, i, err; char *content; char url[1024]; AVStream *st; /* read the whole sdp file */ /* XXX: better loading */ content = av_malloc(SDP_MAX_SIZE); size = get_buffer(s->pb, content, SDP_MAX_SIZE - 1); if (size <= 0) { av_free(content); return AVERROR_INVALIDDATA; } content[size] ='\0'; sdp_parse(s, content); av_free(content); /* open each RTP stream */ for(i=0;i<rt->nb_rtsp_streams;i++) { rtsp_st = rt->rtsp_streams[i]; snprintf(url, sizeof(url), "rtp://%s:%d?localport=%d&ttl=%d", inet_ntoa(rtsp_st->sdp_ip), rtsp_st->sdp_port, rtsp_st->sdp_port, rtsp_st->sdp_ttl); if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { err = AVERROR_INVALIDDATA; goto fail; } /* open the RTP context */ st = NULL; if (rtsp_st->stream_index >= 0) st = s->streams[rtsp_st->stream_index]; if (!st) s->ctx_flags |= AVFMTCTX_NOHEADER; rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data); if (!rtsp_st->rtp_ctx) { err = AVERROR(ENOMEM); goto fail; } else { if(rtsp_st->dynamic_handler) { rtsp_st->rtp_ctx->dynamic_protocol_context= rtsp_st->dynamic_protocol_context; rtsp_st->rtp_ctx->parse_packet= rtsp_st->dynamic_handler->parse_packet; } } } return 0; fail: rtsp_close_streams(rt); return err; }
static int open_f(stream_t *stream, int mode, void *opts, int *file_format) { int flags = 0; const char *filename; URLContext *ctx = NULL; int res = STREAM_ERROR; int64_t size; int dummy; av_register_all(); if (mode == STREAM_READ) flags = URL_RDONLY; else if (mode == STREAM_WRITE) flags = URL_WRONLY; else { mp_msg(MSGT_OPEN, MSGL_ERR, "[ffmpeg] Unknown open mode %d\n", mode); res = STREAM_UNSUPPORTED; goto out; } if (stream->url) filename = stream->url; else { mp_msg(MSGT_OPEN, MSGL_ERR, "[ffmpeg] No URL\n"); goto out; } if (!strncmp(filename, prefix, strlen(prefix))) filename += strlen(prefix); dummy = !strncmp(filename, "rtsp:", 5); mp_msg(MSGT_OPEN, MSGL_V, "[ffmpeg] Opening %s\n", filename); if (!dummy && url_open(&ctx, filename, flags) < 0) goto out; stream->priv = ctx; size = dummy ? 0 : url_filesize(ctx); if (size >= 0) stream->end_pos = size; stream->type = STREAMTYPE_FILE; stream->seek = seek; if (dummy || ctx->is_streamed) { stream->type = STREAMTYPE_STREAM; stream->seek = NULL; } if (!dummy) { stream->fill_buffer = fill_buffer; stream->write_buffer = write_buffer; stream->control = control; stream->close = close_f; } res = STREAM_OK; out: return res; }
static struct input_stream * input_ffmpeg_open(const char *uri, GMutex *mutex, GCond *cond, GError **error_r) { struct input_ffmpeg *i; if (!g_str_has_prefix(uri, "gopher://") && !g_str_has_prefix(uri, "rtp://") && !g_str_has_prefix(uri, "rtsp://") && !g_str_has_prefix(uri, "rtmp://") && !g_str_has_prefix(uri, "rtmpt://") && !g_str_has_prefix(uri, "rtmps://")) return NULL; i = g_new(struct input_ffmpeg, 1); input_stream_init(&i->base, &input_plugin_ffmpeg, uri, mutex, cond); #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,1,0) int ret = avio_open(&i->h, uri, AVIO_FLAG_READ); #elif LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0) int ret = avio_open(&i->h, uri, AVIO_RDONLY); #else int ret = url_open(&i->h, uri, URL_RDONLY); #endif if (ret != 0) { g_free(i); g_set_error(error_r, ffmpeg_quark(), ret, "libavformat failed to open the URI"); return NULL; } i->eof = false; i->base.ready = true; #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0) i->base.seekable = (i->h->seekable & AVIO_SEEKABLE_NORMAL) != 0; i->base.size = avio_size(i->h); #else i->base.seekable = !i->h->is_streamed; i->base.size = url_filesize(i->h); #endif /* hack to make MPD select the "ffmpeg" decoder plugin - since avio.h doesn't tell us the MIME type of the resource, we can't select a decoder plugin, but the "ffmpeg" plugin is quite good at auto-detection */ i->base.mime = g_strdup("audio/x-mpd-ffmpeg"); return &i->base; }
extern char * s_magic_url(char *url) { url_t *u; char *m; u = url_open(url, "r"); if(!u) return NULL; m = s_magic(u, url); tcfree(u); return m; }
InputSource EntityOpen(Entity e) { FILE16 *f16; if(e->type == ET_external) { const char8 *url = EntityURL(e); if(!url || !(f16 = url_open(url, 0, "r", 0))) return 0; } else { f16 = MakeFILE16FromString((char *)e->text, -1, "r"); } return NewInputSource(e, f16); }
bool StreamingRingBuffer::OpenFile(const QString &lfilename, uint retry_ms) { av_register_all(); safefilename = lfilename; filename = lfilename; LOG(VB_GENERAL, LOG_INFO, LOC + QString("Trying %1").arg(filename)); int res = url_open(&m_context, filename.toAscii(), URL_RDONLY); if (res < 0 || !m_context) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to open stream (error %1)") .arg(res)); return false; } return true; }
extern image_t * load_image(char *skinpath, char *file) { image_params_t ip; char fn[1024]; image_t *img; url_t *u; if(!file) return NULL; snprintf(fn, 1023, "%s/%s", skinpath, file); u = url_open(fn, "r"); if(!u) return NULL; ip.pixel_type = IMAGE_COLOR_RGB | IMAGE_COLOR_ALPHA; img = image_read(u, &ip); u->close(u); return img; }
InputSource EntityOpen(Entity e) { FILE16 *f16; char8 *r_url; if(e->type == ET_external) { const char8 *url = EntityURL(e); if(!url || !(f16 = url_open(url, 0, "r", &r_url))) return 0; if(r_url && !e->base_url) EntitySetBaseURL(e, r_url); Free(r_url); } else { f16 = MakeFILE16FromString((char *)e->text, -1, "r"); } return NewInputSource(e, f16); }
// Open a file with a (possibly) Unicode filename int ufile_fopen(AVIOContext **s, const wxString & name, int flags) { wxString url(wxString(wxT(UFILE_PROTOCOL)) + wxT(":") + name); URLContext *h; int err; // Open the file using our custom protocol and passing the (possibly) Unicode // filename. We convert the name to UTF8 here and it will be converted back // to original encoding in ufile_open(). This allows us to support Unicode // filenames even though FFmpeg does not. err = url_open(&h, (const char *) url.ToUTF8(), flags); if (err < 0) { return err; } // Associate the file with a context err = url_fdopen(s, h); if (err < 0) { url_close(h); return err; } return 0; }
static int pl_addlist(tcvp_playlist_t *tpl, char *file, int pos) { url_t *plf = url_open(file, "r"); char buf[1024], *line = alloca(1024), **lp = &line; char *d, *l; int n = 0; tc2_print("PLAYLIST", TC2_PRINT_DEBUG, "adding list %s\n", file); if(!plf) return -1; if(pos < 0) pos = tpl->nf + pos + 1; if(pos < 0) pos = 0; l = strdup(file); d = strrchr(l, '/'); if(d && !*(d + 1)){ *d = 0; d = strrchr(l, '/'); } if(d){ *d = 0; d = l; } else { d = "."; } while(url_gets(buf, 1024, plf)){ int bl; if(buf[0] == '#') continue; bl = strlen(buf); if(bl == 0) continue; bl--; while(bl > 0 && (buf[bl] == '\n' || buf[bl] == '\r')) buf[bl--] = 0; if(buf[0] == 0) continue; if(buf[0] == '/' || strchr(buf, ':')){ strncpy(line, buf, 1024); line[1023] = 0; } else { snprintf(line, 1024, "%s/%s", d, buf); } n += pl_addauto_unlocked(tpl, lp, 1, pos + n); } free(l); plf->close(plf); return n; }
/* return non zero if error */ static int http_open_cnx(URLContext *h) { const char *path, *proxy_path; char hostname[1024], hoststr[1024]; char auth[1024]; char path1[1024]; char buf[1024]; int port, use_proxy, err, location_changed = 0, redirects = 0; HTTPAuthType cur_auth_type; HTTPContext *s = h->priv_data; URLContext *hd = NULL; proxy_path = getenv("http_proxy"); use_proxy = (proxy_path != NULL) && !getenv("no_proxy") && av_strstart(proxy_path, "http://", NULL); /* fill the dest addr */ redo: /* needed in any case to build the host string */ ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, path1, sizeof(path1), s->location); ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); if (use_proxy) { ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, NULL, 0, proxy_path); path = s->location; } else { if (path1[0] == '\0') path = "/"; else path = path1; } if (port < 0) port = 80; ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); err = url_open(&hd, buf, URL_RDWR); if (err < 0) goto fail; s->hd = hd; cur_auth_type = s->auth_state.auth_type; if (http_connect(h, path, hoststr, auth, &location_changed) < 0) goto fail; if (s->http_code == 401) { if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) { url_close(hd); goto redo; } else { err = AVERROR(EACCES); goto fail; } } if ((s->http_code == 302 || s->http_code == 303) && location_changed == 1) { /* url moved, get next */ url_close(hd); if (redirects++ >= MAX_REDIRECTS) return AVERROR(EFAULT); location_changed = 0; goto redo; } return 0; fail: if (hd) url_close(hd); return err; }
/* * url syntax: rtp://host:port[?option=val...] * option: 'multicast=1' : enable multicast * 'ttl=n' : set the ttl value (for multicast only) * 'localport=n' : set the local port to n * */ static int rtp_open(URLContext *h, const char *uri, int flags) { RTPContext *s; int port, is_output, is_multicast, ttl, local_port; char hostname[256]; char buf[1024]; char path[1024]; const char *p; is_output = (flags & URL_WRONLY); s = av_mallocz(sizeof(RTPContext)); if (!s) return AVERROR(ENOMEM); h->priv_data = s; url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, path, sizeof(path), uri); /* extract parameters */ is_multicast = 0; ttl = -1; local_port = -1; p = strchr(uri, '?'); if (p) { is_multicast = find_info_tag(buf, sizeof(buf), "multicast", p); if (find_info_tag(buf, sizeof(buf), "ttl", p)) { ttl = strtol(buf, NULL, 10); } if (find_info_tag(buf, sizeof(buf), "localport", p)) { local_port = strtol(buf, NULL, 10); } } build_udp_url(buf, sizeof(buf), hostname, port, local_port, is_multicast, ttl); if (url_open(&s->rtp_hd, buf, flags) < 0) goto fail; local_port = udp_get_local_port(s->rtp_hd); /* XXX: need to open another connexion if the port is not even */ /* well, should suppress localport in path */ build_udp_url(buf, sizeof(buf), hostname, port + 1, local_port + 1, is_multicast, ttl); if (url_open(&s->rtcp_hd, buf, flags) < 0) goto fail; /* just to ease handle access. XXX: need to suppress direct handle access */ s->rtp_fd = udp_get_file_handle(s->rtp_hd); s->rtcp_fd = udp_get_file_handle(s->rtcp_hd); h->max_packet_size = url_get_max_packet_size(s->rtp_hd); h->is_streamed = 1; return 0; fail: if (s->rtp_hd) url_close(s->rtp_hd); if (s->rtcp_hd) url_close(s->rtcp_hd); av_free(s); return AVERROR_IO; }
static int mms_open(URLContext *h, const char *uri, int flags) { MMSTContext *mmst; MMSContext *mms; int port, err; char tcpname[256]; h->is_streamed = 1; mmst = h->priv_data = av_mallocz(sizeof(MMSTContext)); if (!h->priv_data) return AVERROR(ENOMEM); mms = &mmst->mms; // only for MMS over TCP, so set proto = NULL av_url_split(NULL, 0, NULL, 0, mmst->host, sizeof(mmst->host), &port, mmst->path, sizeof(mmst->path), uri); if(port<0) port = 1755; // defaut mms protocol port // establish tcp connection. ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL); err = url_open(&mms->mms_hd, tcpname, URL_RDWR); if (err) goto fail; mmst->packet_id = 3; // default, initial value. mmst->header_packet_id = 2; // default, initial value. err = mms_safe_send_recv(mmst, send_startup_packet, SC_PKT_CLIENT_ACCEPTED); if (err) goto fail; err = mms_safe_send_recv(mmst, send_time_test_data, SC_PKT_TIMING_TEST_REPLY); if (err) goto fail; err = mms_safe_send_recv(mmst, send_protocol_select, SC_PKT_PROTOCOL_ACCEPTED); if (err) goto fail; err = mms_safe_send_recv(mmst, send_media_file_request, SC_PKT_MEDIA_FILE_DETAILS); if (err) goto fail; err = mms_safe_send_recv(mmst, send_media_header_request, SC_PKT_HEADER_REQUEST_ACCEPTED); if (err) goto fail; err = mms_safe_send_recv(mmst, NULL, SC_PKT_ASF_HEADER); if (err) goto fail; if((mmst->incoming_flags != 0X08) && (mmst->incoming_flags != 0X0C)) goto fail; err = ff_mms_asf_header_parser(mms); if (err) { dprintf(NULL, "asf header parsed failed!\n"); goto fail; } mms->header_parsed = 1; if (!mms->asf_packet_len || !mms->stream_num) goto fail; clear_stream_buffers(mms); err = mms_safe_send_recv(mmst, send_stream_selection_request, SC_PKT_STREAM_ID_ACCEPTED); if (err) goto fail; // send media packet request err = mms_safe_send_recv(mmst, send_media_packet_request, SC_PKT_MEDIA_PKT_FOLLOWS); if (err) { goto fail; } dprintf(NULL, "Leaving open (success)\n"); return 0; fail: mms_close(h); dprintf(NULL, "Leaving open (failure: %d)\n", err); return err; }
static int rtp_open(URLContext *h, const char *uri, int flags) { RTPContext *s; int rtp_port, rtcp_port, is_output, ttl, local_rtp_port, local_rtcp_port, max_packet_size; char hostname[256]; char buf[1024]; char path[1024]; const char *p; is_output = (flags & URL_WRONLY); s = av_mallocz(sizeof(RTPContext)); if (!s) return AVERROR(ENOMEM); h->priv_data = s; av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port, path, sizeof(path), uri); /* extract parameters */ ttl = -1; rtcp_port = rtp_port+1; local_rtp_port = -1; local_rtcp_port = -1; max_packet_size = -1; p = strchr(uri, '?'); if (p) { if (find_info_tag(buf, sizeof(buf), "ttl", p)) { ttl = strtol(buf, NULL, 10); } if (find_info_tag(buf, sizeof(buf), "rtcpport", p)) { rtcp_port = strtol(buf, NULL, 10); } if (find_info_tag(buf, sizeof(buf), "localport", p)) { local_rtp_port = strtol(buf, NULL, 10); } if (find_info_tag(buf, sizeof(buf), "localrtpport", p)) { local_rtp_port = strtol(buf, NULL, 10); } if (find_info_tag(buf, sizeof(buf), "localrtcpport", p)) { local_rtcp_port = strtol(buf, NULL, 10); } if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) { max_packet_size = strtol(buf, NULL, 10); } } build_udp_url(buf, sizeof(buf), hostname, rtp_port, local_rtp_port, ttl, max_packet_size); if (url_open(&s->rtp_hd, buf, flags) < 0) goto fail; if (local_rtp_port>=0 && local_rtcp_port<0) local_rtcp_port = udp_get_local_port(s->rtp_hd) + 1; build_udp_url(buf, sizeof(buf), hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size); if (url_open(&s->rtcp_hd, buf, flags) < 0) goto fail; /* just to ease handle access. XXX: need to suppress direct handle access */ s->rtp_fd = url_get_file_handle(s->rtp_hd); s->rtcp_fd = url_get_file_handle(s->rtcp_hd); h->max_packet_size = url_get_max_packet_size(s->rtp_hd); h->is_streamed = 1; return 0; fail: if (s->rtp_hd) url_close(s->rtp_hd); if (s->rtcp_hd) url_close(s->rtcp_hd); av_free(s); return AVERROR(EIO); }
/* Try to open a file for reading. If the filename ends in one of the defined compressor extensions, pipe the file through the decompressor */ struct timidity_file *try_to_open(char *name, int decompress) { struct timidity_file *tf; URL url; int len; if((url = url_arc_open(name)) == NULL) if((url = url_open(name)) == NULL) return NULL; tf = (struct timidity_file *)safe_malloc(sizeof(struct timidity_file)); tf->url = url; tf->tmpname = NULL; len = strlen(name); if(decompress && len >= 3 && strcasecmp(name + len - 3, ".gz") == 0) { int method; if(!IS_URL_SEEK_SAFE(tf->url)) { if((tf->url = url_cache_open(tf->url, 1)) == NULL) { close_file(tf); return NULL; } } method = skip_gzip_header(tf->url); if(method == ARCHIVEC_DEFLATED) { url_cache_disable(tf->url); if((tf->url = url_inflate_open(tf->url, -1, 1)) == NULL) { close_file(tf); return NULL; } /* success */ return tf; } /* fail */ url_rewind(tf->url); url_cache_disable(tf->url); } #ifdef __W32__ /* Sorry, DECOMPRESSOR_LIST and PATCH_CONVERTERS are not worked yet. */ return tf; #endif /* __W32__ */ #if defined(DECOMPRESSOR_LIST) if(decompress) { static char *decompressor_list[] = DECOMPRESSOR_LIST, **dec; char tmp[1024]; /* Check if it's a compressed file */ for(dec = decompressor_list; *dec; dec += 2) { if(!check_file_extension(name, *dec, 0)) continue; tf->tmpname = url_dumpfile(tf->url, *dec); if (tf->tmpname == NULL) { close_file(tf); return NULL; } url_close(tf->url); snprintf(tmp, sizeof(tmp), *(dec+1), tf->tmpname); if((tf->url = url_pipe_open(tmp)) == NULL) { close_file(tf); return NULL; } break; } } #endif /* DECOMPRESSOR_LIST */ #if defined(PATCH_CONVERTERS) if(decompress == 2) { static char *decompressor_list[] = PATCH_CONVERTERS, **dec; char tmp[1024]; /* Check if it's a compressed file */ for(dec = decompressor_list; *dec; dec += 2) { if(!check_file_extension(name, *dec, 0)) continue; tf->tmpname = url_dumpfile(tf->url, *dec); if (tf->tmpname == NULL) { close_file(tf); return NULL; } url_close(tf->url); sprintf(tmp, *(dec+1), tf->tmpname); if((tf->url = url_pipe_open(tmp)) == NULL) { close_file(tf); return NULL; } break; } } #endif /* PATCH_CONVERTERS */ return tf; }
jint Java_org_devtcg_rojocam_ffmpeg_RtpOutputContext_nativeCreate(JNIEnv *env, jclass clazz, jint streamConfigNativeInt, jlong nowNanoTime, jstring hostAddress, jint rtpPort) { FFStreamConfig *config = (FFStreamConfig *)streamConfigNativeInt; RtpOutputContext *rtpContext = NULL; AVFormatContext *avContext = NULL; AVStream *st = NULL; uint8_t *dummy_buf; int max_packet_size; rtpContext = av_mallocz(sizeof(RtpOutputContext)); if (rtpContext == NULL) { jniThrowOOM(env); goto cleanup; } rtpContext->lastFrameTime = nowNanoTime; rtpContext->config = config; avContext = avformat_alloc_context(); if (avContext == NULL) { jniThrowOOM(env); goto cleanup; } avContext->oformat = av_guess_format("rtp", NULL, NULL); if (avContext->oformat == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "rtp avformat is not available"); goto cleanup; } rtpContext->avContext = avContext; st = av_mallocz(sizeof(AVStream)); if (st == NULL) { jniThrowOOM(env); goto cleanup; } avContext->nb_streams = 1; avContext->streams = av_malloc(avContext->nb_streams * sizeof(*avContext->streams)); avContext->streams[0] = st; /* XXX: What would we be doing if we supported audio as well? */ memcpy(st, config->streams[0], sizeof(AVStream)); st->priv_data = NULL; const jbyte *hostAddress_str = (*env)->GetStringUTFChars(env, hostAddress, NULL); snprintf(avContext->filename, sizeof(avContext->filename), "rtp://%s:%d?localrtpport=5000&localrtcpport=5001", hostAddress_str, rtpPort); (*env)->ReleaseStringUTFChars(env, hostAddress, hostAddress_str); if (url_open(&rtpContext->urlContext, avContext->filename, URL_WRONLY) < 0) { LOGE("Cannot open url context for filename=%s", avContext->filename); jniThrowException(env, "java/io/IOException", "Unable to open URL"); goto cleanup; } max_packet_size = url_get_max_packet_size(rtpContext->urlContext); /* XXX: No idea what purpose this serves... */ url_open_dyn_packet_buf(&avContext->pb, max_packet_size); av_set_parameters(avContext, NULL); if (av_write_header(avContext) < 0) { jniThrowException(env, "java/io/IOException", "Unexpected error writing dummy RTP header"); goto cleanup; } url_close_dyn_buf(avContext->pb, &dummy_buf); av_free(dummy_buf); return (jint)rtpContext; cleanup: rtp_output_context_free(rtpContext); assert((*env)->ExceptionOccurred(env)); return 0; }
extern muxed_stream_t * s_open(char *name, tcconf_section_t *cs, tcvp_timer_t *t) { char *m; url_t *u; demux_open_t sopen; muxed_stream_t *ms; if(!(u = url_open(name, "r"))) return NULL; m = s_magic(u, name); tc2_print("STREAM", TC2_PRINT_DEBUG, "mime type %s\n", m); if(m && strncmp(m, "audio/", 6) && strncmp(m, "video/", 6)){ free(m); m = NULL; } if(!m) return NULL; if(!(sopen = tc2_get_symbol(m, "open"))) return NULL; free(m); ms = sopen(name, u, cs, t); if(ms){ char *a, *p; tcattr_set(ms, "file", strdup(name), NULL, free); cpattr(ms, u, "title"); cpattr(ms, u, "performer"); cpattr(ms, u, "artist"); cpattr(ms, u, "album"); cpattr(ms, u, "track"); cpattr(ms, u, "year"); cpattr(ms, u, "genre"); cpattr2(ms, u, "title", "user.title"); cpattr2(ms, u, "artist", "user.artist"); cpattr2(ms, u, "album", "user.album"); cpattr2(ms, u, "track", "user.track"); cpattr2(ms, u, "year", "user.year"); cpattr2(ms, u, "genre", "user.genre"); a = tcattr_get(ms, "artist"); p = tcattr_get(ms, "performer"); if(!a && p) tcattr_set(ms, "artist", strdup(p), NULL, free); if(a && !p) tcattr_set(ms, "performer", strdup(a), NULL, free); } tcfree(u); return ms; }
static int sap_read_header(AVFormatContext *s, AVFormatParameters *ap) { struct SAPState *sap = s->priv_data; char host[1024], path[1024], url[1024]; uint8_t recvbuf[1500]; int port; int ret, i; AVInputFormat* infmt; if (!ff_network_init()) return AVERROR(EIO); av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, path, sizeof(path), s->filename); if (port < 0) port = 9875; if (!host[0]) { /* Listen for announcements on sap.mcast.net if no host was specified */ av_strlcpy(host, "224.2.127.254", sizeof(host)); } ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d", port); ret = url_open(&sap->ann_fd, url, URL_RDONLY); if (ret) goto fail; while (1) { int addr_type, auth_len; int pos; ret = url_read(sap->ann_fd, recvbuf, sizeof(recvbuf) - 1); if (ret == AVERROR(EAGAIN)) continue; if (ret < 0) goto fail; recvbuf[ret] = '\0'; /* Null terminate for easier parsing */ if (ret < 8) { av_log(s, AV_LOG_WARNING, "Received too short packet\n"); continue; } if ((recvbuf[0] & 0xe0) != 0x20) { av_log(s, AV_LOG_WARNING, "Unsupported SAP version packet " "received\n"); continue; } if (recvbuf[0] & 0x04) { av_log(s, AV_LOG_WARNING, "Received stream deletion " "announcement\n"); continue; } addr_type = recvbuf[0] & 0x10; auth_len = recvbuf[1]; sap->hash = AV_RB16(&recvbuf[2]); pos = 4; if (addr_type) pos += 16; /* IPv6 */ else pos += 4; /* IPv4 */ pos += auth_len * 4; if (pos + 4 >= ret) { av_log(s, AV_LOG_WARNING, "Received too short packet\n"); continue; } #define MIME "application/sdp" if (strcmp(&recvbuf[pos], MIME) == 0) { pos += strlen(MIME) + 1; } else if (strncmp(&recvbuf[pos], "v=0\r\n", 5) == 0) { // Direct SDP without a mime type } else { av_log(s, AV_LOG_WARNING, "Unsupported mime type %s\n", &recvbuf[pos]); continue; } sap->sdp = av_strdup(&recvbuf[pos]); break; } av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sap->sdp); init_put_byte(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL, NULL, NULL); infmt = av_find_input_format("sdp"); if (!infmt) goto fail; sap->sdp_ctx = avformat_alloc_context(); if (!sap->sdp_ctx) { ret = AVERROR(ENOMEM); goto fail; } sap->sdp_ctx->max_delay = s->max_delay; ap->prealloced_context = 1; ret = av_open_input_stream(&sap->sdp_ctx, &sap->sdp_pb, "temp.sdp", infmt, ap); if (ret < 0) goto fail; if (sap->sdp_ctx->ctx_flags & AVFMTCTX_NOHEADER) s->ctx_flags |= AVFMTCTX_NOHEADER; for (i = 0; i < sap->sdp_ctx->nb_streams; i++) { AVStream *st = av_new_stream(s, i); if (!st) { ret = AVERROR(ENOMEM); goto fail; } avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec); st->time_base = sap->sdp_ctx->streams[i]->time_base; } return 0; fail: sap_read_close(s); return ret; }
/** * @returns 0 on success, <0 on error, 1 if protocol is unavailable. */ static int make_setup_request (AVFormatContext *s, const char *host, int port, int protocol) { RTSPState *rt = s->priv_data; int j, i, err; RTSPStream *rtsp_st; AVStream *st; RTSPHeader reply1, *reply = &reply1; char cmd[2048]; /* for each stream, make the setup request */ /* XXX: we assume the same server is used for the control of each RTSP stream */ for(j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) { char transport[2048]; rtsp_st = rt->rtsp_streams[i]; /* compute available transports */ transport[0] = '\0'; /* RTP/UDP */ if (protocol == RTSP_PROTOCOL_RTP_UDP) { char buf[256]; /* first try in specified port range */ if (RTSP_RTP_PORT_MIN != 0) { while(j <= RTSP_RTP_PORT_MAX) { snprintf(buf, sizeof(buf), "rtp://%s?localport=%d", host, j); j += 2; /* we will use two port by rtp stream (rtp and rtcp) */ if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) { goto rtp_opened; } } } /* then try on any port ** if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) { ** err = AVERROR_INVALIDDATA; ** goto fail; ** } */ rtp_opened: port = rtp_get_local_port(rtsp_st->rtp_handle); if (transport[0] != '\0') av_strlcat(transport, ",", sizeof(transport)); snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, "RTP/AVP/UDP;unicast;client_port=%d-%d", port, port + 1); } /* RTP/TCP */ else if (protocol == RTSP_PROTOCOL_RTP_TCP) { if (transport[0] != '\0') av_strlcat(transport, ",", sizeof(transport)); snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, "RTP/AVP/TCP"); } else if (protocol == RTSP_PROTOCOL_RTP_UDP_MULTICAST) { if (transport[0] != '\0') av_strlcat(transport, ",", sizeof(transport)); snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, "RTP/AVP/UDP;multicast"); } snprintf(cmd, sizeof(cmd), "SETUP %s RTSP/1.0\r\n" "Transport: %s\r\n", rtsp_st->control_url, transport); rtsp_send_cmd(s, cmd, reply, NULL); if (reply->status_code == 461 /* Unsupported protocol */ && i == 0) { err = 1; goto fail; } else if (reply->status_code != RTSP_STATUS_OK || reply->nb_transports != 1) { err = AVERROR_INVALIDDATA; goto fail; } /* XXX: same protocol for all streams is required */ if (i > 0) { if (reply->transports[0].protocol != rt->protocol) { err = AVERROR_INVALIDDATA; goto fail; } } else { rt->protocol = reply->transports[0].protocol; } /* close RTP connection if not choosen */ if (reply->transports[0].protocol != RTSP_PROTOCOL_RTP_UDP && (protocol == RTSP_PROTOCOL_RTP_UDP)) { url_close(rtsp_st->rtp_handle); rtsp_st->rtp_handle = NULL; } switch(reply->transports[0].protocol) { case RTSP_PROTOCOL_RTP_TCP: rtsp_st->interleaved_min = reply->transports[0].interleaved_min; rtsp_st->interleaved_max = reply->transports[0].interleaved_max; break; case RTSP_PROTOCOL_RTP_UDP: { char url[1024]; /* XXX: also use address if specified */ snprintf(url, sizeof(url), "rtp://%s:%d", host, reply->transports[0].server_port_min); if (rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { err = AVERROR_INVALIDDATA; goto fail; } } break; case RTSP_PROTOCOL_RTP_UDP_MULTICAST: { char url[1024]; struct in_addr in; in.s_addr = htonl(reply->transports[0].destination); snprintf(url, sizeof(url), "rtp://%s:%d?ttl=%d", inet_ntoa(in), reply->transports[0].port_min, reply->transports[0].ttl); if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { err = AVERROR_INVALIDDATA; goto fail; } } break; } /* open the RTP context */ st = NULL; if (rtsp_st->stream_index >= 0) st = s->streams[rtsp_st->stream_index]; if (!st) s->ctx_flags |= AVFMTCTX_NOHEADER; rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data); if (!rtsp_st->rtp_ctx) { err = AVERROR(ENOMEM); goto fail; } else { if(rtsp_st->dynamic_handler) { rtsp_st->rtp_ctx->dynamic_protocol_context= rtsp_st->dynamic_protocol_context; rtsp_st->rtp_ctx->parse_packet= rtsp_st->dynamic_handler->parse_packet; } } } return 0; fail: for (i=0; i<rt->nb_rtsp_streams; i++) { if (rt->rtsp_streams[i]->rtp_handle) { url_close(rt->rtsp_streams[i]->rtp_handle); rt->rtsp_streams[i]->rtp_handle = NULL; } } return err; }
static av_cold int concat_open(URLContext *h, const char *uri, int flags) { char *node_uri = NULL, *tmp_uri; int err = 0; int64_t size; size_t len, i; URLContext *uc; struct concat_data *data; struct concat_nodes *nodes; av_strstart(uri, "concat:", &uri); /* creating data */ if (!(data = av_mallocz(sizeof(*data)))) return AVERROR(ENOMEM); h->priv_data = data; for (i = 0, len = 1; uri[i]; i++) if (uri[i] == *AV_CAT_SEPARATOR) /* integer overflow */ if (++len == UINT_MAX / sizeof(*nodes)) { av_freep(&h->priv_data); return AVERROR(ENAMETOOLONG); } if (!(nodes = av_malloc(sizeof(*nodes) * len))) { av_freep(&h->priv_data); return AVERROR(ENOMEM); } else data->nodes = nodes; /* handle input */ if (!*uri) err = AVERROR(ENOENT); for (i = 0; *uri; i++) { /* parsing uri */ len = strcspn(uri, AV_CAT_SEPARATOR); if (!(tmp_uri = av_realloc(node_uri, len+1))) { err = AVERROR(ENOMEM); break; } else node_uri = tmp_uri; av_strlcpy(node_uri, uri, len+1); uri += len + strspn(uri+len, AV_CAT_SEPARATOR); /* creating URLContext */ if ((err = url_open(&uc, node_uri, flags)) < 0) break; /* creating size */ if ((size = url_filesize(uc)) < 0) { url_close(uc); err = AVERROR(ENOSYS); break; } /* assembling */ nodes[i].uc = uc; nodes[i].size = size; } av_free(node_uri); data->length = i; if (err < 0) concat_close(h); else if (!(nodes = av_realloc(nodes, data->length * sizeof(*nodes)))) { concat_close(h); err = AVERROR(ENOMEM); } else data->nodes = nodes; return err; }
/* return non zero if error */ static int http_open(URLContext *h, const char *uri, int flags) { const char *path, *proxy_path; char hostname[1024], hoststr[1024]; char auth[1024]; char path1[1024]; char buf[1024]; int port, use_proxy, err; HTTPContext *s; URLContext *hd = NULL; h->is_streamed = 1; s = av_malloc(sizeof(HTTPContext)); if (!s) { return -ENOMEM; } h->priv_data = s; proxy_path = getenv("http_proxy"); use_proxy = (proxy_path != NULL) && !getenv("no_proxy") && strstart(proxy_path, "http://", NULL); /* fill the dest addr */ redo: /* needed in any case to build the host string */ url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, path1, sizeof(path1), uri); if (port > 0) { snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port); } else { pstrcpy(hoststr, sizeof(hoststr), hostname); } if (use_proxy) { url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, NULL, 0, proxy_path); path = uri; } else { if (path1[0] == '\0') path = "/"; else path = path1; } if (port < 0) port = 80; snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port); err = url_open(&hd, buf, URL_RDWR); if (err < 0) goto fail; s->hd = hd; if (http_connect(h, path, hoststr, auth) < 0) goto fail; if (s->http_code == 303 && s->location[0] != '\0') { /* url moved, get next */ uri = s->location; url_close(hd); goto redo; } return 0; fail: if (hd) url_close(hd); av_free(s); return AVERROR_IO; }
static int rtsp_read_header(AVFormatContext *s, AVFormatParameters *ap) { RTSPState *rt = s->priv_data; char host[1024], path[1024], tcpname[1024], cmd[2048]; URLContext *rtsp_hd; int port, i, j, ret, err; RTSPHeader reply1, *reply = &reply1; unsigned char *content = NULL; RTSPStream *rtsp_st; int protocol_mask; AVStream *st; /* extract hostname and port */ url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, path, sizeof(path), s->filename); if (port < 0) port = RTSP_DEFAULT_PORT; /* open the tcp connexion */ snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port); if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) return AVERROR_IO; rt->rtsp_hd = rtsp_hd; rt->seq = 0; /* describe the stream */ snprintf(cmd, sizeof(cmd), "DESCRIBE %s RTSP/1.0\r\n" "Accept: application/sdp\r\n", s->filename); rtsp_send_cmd(s, cmd, reply, &content); if (!content) { err = AVERROR_INVALIDDATA; goto fail; } if (reply->status_code != RTSP_STATUS_OK) { err = AVERROR_INVALIDDATA; goto fail; } /* now we got the SDP description, we parse it */ ret = sdp_parse(s, (const char *)content); av_freep(&content); if (ret < 0) { err = AVERROR_INVALIDDATA; goto fail; } protocol_mask = rtsp_default_protocols; /* for each stream, make the setup request */ /* XXX: we assume the same server is used for the control of each RTSP stream */ for(j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) { char transport[2048]; rtsp_st = rt->rtsp_streams[i]; /* compute available transports */ transport[0] = '\0'; /* RTP/UDP */ if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP)) { char buf[256]; /* first try in specified port range */ if (RTSP_RTP_PORT_MIN != 0) { while(j <= RTSP_RTP_PORT_MAX) { snprintf(buf, sizeof(buf), "rtp://?localport=%d", j); if (url_open(&rtsp_st->rtp_handle, buf, URL_RDONLY) == 0) { j += 2; /* we will use two port by rtp stream (rtp and rtcp) */ goto rtp_opened; } } } /* then try on any port ** if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) { ** err = AVERROR_INVALIDDATA; ** goto fail; ** } */ rtp_opened: port = rtp_get_local_port(rtsp_st->rtp_handle); if (transport[0] != '\0') pstrcat(transport, sizeof(transport), ","); snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, "RTP/AVP/UDP;unicast;client_port=%d-%d", port, port + 1); } /* RTP/TCP */ else if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_TCP)) { if (transport[0] != '\0') pstrcat(transport, sizeof(transport), ","); snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, "RTP/AVP/TCP"); } else if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP_MULTICAST)) { if (transport[0] != '\0') pstrcat(transport, sizeof(transport), ","); snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, "RTP/AVP/UDP;multicast"); } snprintf(cmd, sizeof(cmd), "SETUP %s RTSP/1.0\r\n" "Transport: %s\r\n", rtsp_st->control_url, transport); rtsp_send_cmd(s, cmd, reply, NULL); if (reply->status_code != RTSP_STATUS_OK || reply->nb_transports != 1) { err = AVERROR_INVALIDDATA; goto fail; } /* XXX: same protocol for all streams is required */ if (i > 0) { if (reply->transports[0].protocol != rt->protocol) { err = AVERROR_INVALIDDATA; goto fail; } } else { rt->protocol = reply->transports[0].protocol; } /* close RTP connection if not choosen */ if (reply->transports[0].protocol != RTSP_PROTOCOL_RTP_UDP && (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP))) { url_close(rtsp_st->rtp_handle); rtsp_st->rtp_handle = NULL; } switch(reply->transports[0].protocol) { case RTSP_PROTOCOL_RTP_TCP: rtsp_st->interleaved_min = reply->transports[0].interleaved_min; rtsp_st->interleaved_max = reply->transports[0].interleaved_max; break; case RTSP_PROTOCOL_RTP_UDP: { char url[1024]; /* XXX: also use address if specified */ snprintf(url, sizeof(url), "rtp://%s:%d", host, reply->transports[0].server_port_min); if (rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { err = AVERROR_INVALIDDATA; goto fail; } } break; case RTSP_PROTOCOL_RTP_UDP_MULTICAST: { char url[1024]; int ttl; ttl = reply->transports[0].ttl; if (!ttl) ttl = 16; snprintf(url, sizeof(url), "rtp://%s:%d?multicast=1&ttl=%d", host, reply->transports[0].server_port_min, ttl); if (url_open(&rtsp_st->rtp_handle, url, URL_RDONLY) < 0) { err = AVERROR_INVALIDDATA; goto fail; } } break; } /* open the RTP context */ st = NULL; if (rtsp_st->stream_index >= 0) st = s->streams[rtsp_st->stream_index]; if (!st) s->ctx_flags |= AVFMTCTX_NOHEADER; rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data); if (!rtsp_st->rtp_ctx) { err = AVERROR_NOMEM; goto fail; } } /* use callback if available to extend setup */ if (ff_rtsp_callback) { if (ff_rtsp_callback(RTSP_ACTION_CLIENT_SETUP, rt->session_id, NULL, 0, rt->last_reply) < 0) { err = AVERROR_INVALIDDATA; goto fail; } } rt->state = RTSP_STATE_IDLE; rt->seek_timestamp = 0; /* default is to start stream at position zero */ if (ap->initial_pause) { /* do not start immediately */ } else { if (rtsp_read_play(s) < 0) { err = AVERROR_INVALIDDATA; goto fail; } } return 0; fail: rtsp_close_streams(rt); av_freep(&content); url_close(rt->rtsp_hd); return err; }
/* return non zero if error */ static int http_open_cnx(URLContext *h) { const char *path, *proxy_path; char hostname[1024], hoststr[1024]; char auth[1024]; char path1[1024]; char buf[1024]; int port, use_proxy, err, location_changed = 0, redirects = 0; HTTPContext *s = h->priv_data; URLContext *hd = NULL; proxy_path = getenv("http_proxy"); use_proxy = (proxy_path != NULL) && !getenv("no_proxy") && av_strstart(proxy_path, "http://", NULL); /* fill the dest addr */ redo: /* needed in any case to build the host string */ url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, path1, sizeof(path1), s->location); if (port > 0) { snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port); } else { av_strlcpy(hoststr, hostname, sizeof(hoststr)); } if (use_proxy) { url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, NULL, 0, proxy_path); path = s->location; } else { if (path1[0] == '\0') path = "/"; else path = path1; } if (port < 0) port = 80; snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port); err = url_open(&hd, buf, URL_RDWR); if (err < 0) goto fail; s->hd = hd; if (http_connect(h, path, hoststr, auth, &location_changed) < 0) goto fail; if ((s->http_code == 302 || s->http_code == 303) && location_changed == 1) { /* url moved, get next */ url_close(hd); if (redirects++ >= MAX_REDIRECTS) return AVERROR(EIO); location_changed = 0; goto redo; } return 0; fail: if (hd) url_close(hd); return AVERROR(EIO); }
static int rtsp_read_header(AVFormatContext *s, AVFormatParameters *ap) { RTSPState *rt = s->priv_data; char host[1024], path[1024], tcpname[1024], cmd[2048], *option_list, *option; URLContext *rtsp_hd; int port, ret, err; RTSPHeader reply1, *reply = &reply1; unsigned char *content = NULL; int protocol_mask = 0; /* extract hostname and port */ url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, path, sizeof(path), s->filename); if (port < 0) port = RTSP_DEFAULT_PORT; /* search for options */ option_list = strchr(path, '?'); if (option_list) { /* remove the options from the path */ *option_list++ = 0; while(option_list) { /* move the option pointer */ option = option_list; option_list = strchr(option_list, '&'); if (option_list) *(option_list++) = 0; /* handle the options */ if (strcmp(option, "udp") == 0) protocol_mask = (1<< RTSP_PROTOCOL_RTP_UDP); else if (strcmp(option, "multicast") == 0) protocol_mask = (1<< RTSP_PROTOCOL_RTP_UDP_MULTICAST); else if (strcmp(option, "tcp") == 0) protocol_mask = (1<< RTSP_PROTOCOL_RTP_TCP); } } if (!protocol_mask) protocol_mask = (1 << RTSP_PROTOCOL_RTP_LAST) - 1; /* open the tcp connexion */ snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port); if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) return AVERROR(EIO); rt->rtsp_hd = rtsp_hd; rt->seq = 0; /* describe the stream */ snprintf(cmd, sizeof(cmd), "DESCRIBE %s RTSP/1.0\r\n" "Accept: application/sdp\r\n", s->filename); rtsp_send_cmd(s, cmd, reply, &content); if (!content) { err = AVERROR_INVALIDDATA; goto fail; } if (reply->status_code != RTSP_STATUS_OK) { err = AVERROR_INVALIDDATA; goto fail; } /* now we got the SDP description, we parse it */ ret = sdp_parse(s, (const char *)content); av_freep(&content); if (ret < 0) { err = AVERROR_INVALIDDATA; goto fail; } do { int protocol = ff_log2_tab[protocol_mask & ~(protocol_mask - 1)]; err = make_setup_request(s, host, port, protocol); if (err < 0) goto fail; protocol_mask &= ~(1 << protocol); if (protocol_mask == 0 && err == 1) { err = AVERROR(FF_NETERROR(EPROTONOSUPPORT)); goto fail; } } while (err); rt->state = RTSP_STATE_IDLE; rt->seek_timestamp = 0; /* default is to start stream at position zero */ if (ap->initial_pause) { /* do not start immediately */ } else { if (rtsp_read_play(s) < 0) { err = AVERROR_INVALIDDATA; goto fail; } } return 0; fail: rtsp_close_streams(rt); av_freep(&content); url_close(rt->rtsp_hd); return err; }