|
|
|
|
/************************************************************************
|
|
|
|
|
** <EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> URLProtocol <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
** <EFBFBD><EFBFBD><EFBFBD><EFBFBD> URLProtocol <EFBFBD>ǵײ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>(file,pipe <EFBFBD><EFBFBD>)<EFBFBD>ļ<EFBFBD>װ<EFBFBD><EFBFBD>
|
|
|
|
|
** <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>תվ<EFBFBD><EFBFBD><EFBFBD>ֺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ֺ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "../berrno.h"
|
|
|
|
|
#include "avformat.h"
|
|
|
|
|
|
|
|
|
|
/* ffmpeg<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD>飬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֵ<EFBFBD>Э<EFBFBD>鴮<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
URLProtocol *first_protocol = NULL;
|
|
|
|
|
|
|
|
|
|
/* ע<EFBFBD><EFBFBD>Э<EFBFBD>飨<EFBFBD><EFBFBD>νЭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>壺<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD> */
|
|
|
|
|
int register_protocol(URLProtocol *protocol)
|
|
|
|
|
{
|
|
|
|
|
URLProtocol **p;
|
|
|
|
|
p = &first_protocol;
|
|
|
|
|
while (*p != NULL)
|
|
|
|
|
p = &(*p)->next;
|
|
|
|
|
*p = protocol;
|
|
|
|
|
protocol->next = NULL;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL */
|
|
|
|
|
int url_open(URLContext **puc, const char *filename, int flags)
|
|
|
|
|
{
|
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
URLContext *uc;
|
|
|
|
|
// Э<EFBFBD>鼰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
URLProtocol *up;
|
|
|
|
|
const char *p;
|
|
|
|
|
// Э<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
char proto_str[128], *q;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
p = filename;
|
|
|
|
|
q = proto_str;
|
|
|
|
|
|
|
|
|
|
// ȷ<EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
while (*p != '\0' && *p != ':')
|
|
|
|
|
{
|
|
|
|
|
if (!isalpha(*p)) // protocols can only contain alphabetic chars
|
|
|
|
|
goto file_proto;
|
|
|
|
|
if ((q - proto_str) < sizeof(proto_str) - 1)
|
|
|
|
|
*q++ = *p;
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
// if the protocol has length 1, we consider it is a dos drive
|
|
|
|
|
if (*p == '\0' || (q - proto_str) <= 1)
|
|
|
|
|
{
|
|
|
|
|
file_proto:
|
|
|
|
|
strcpy(proto_str, "file");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*q = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
up = first_protocol;
|
|
|
|
|
|
|
|
|
|
// Ѱ<EFBFBD>Һ<EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD>
|
|
|
|
|
while (up != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(proto_str, up->name))
|
|
|
|
|
goto found;
|
|
|
|
|
up = up->next;
|
|
|
|
|
}
|
|
|
|
|
err = - ENOENT;
|
|
|
|
|
goto fail;
|
|
|
|
|
found:
|
|
|
|
|
|
|
|
|
|
// URL<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
uc = av_malloc(sizeof(URLContext) + strlen(filename));
|
|
|
|
|
if (!uc)
|
|
|
|
|
{
|
|
|
|
|
err = - ENOMEM;
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
strcpy(uc->filename, filename);
|
|
|
|
|
uc->prot = up;
|
|
|
|
|
uc->flags = flags;
|
|
|
|
|
uc->max_packet_size = 0; // default: stream file
|
|
|
|
|
|
|
|
|
|
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL
|
|
|
|
|
err = up->url_open(uc, filename, flags);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
{
|
|
|
|
|
av_free(uc);
|
|
|
|
|
*puc = NULL;
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
*puc = uc;
|
|
|
|
|
return 0;
|
|
|
|
|
fail:
|
|
|
|
|
*puc = NULL;
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
int url_read(URLContext *h, unsigned char *buf, int size)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
if (h->flags &URL_WRONLY)
|
|
|
|
|
return AVERROR_IO;
|
|
|
|
|
ret = h->prot->url_read(h, buf, size);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <EFBFBD>ڹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת */
|
|
|
|
|
offset_t url_seek(URLContext *h, offset_t pos, int whence)
|
|
|
|
|
{
|
|
|
|
|
offset_t ret;
|
|
|
|
|
|
|
|
|
|
if (!h->prot->url_seek)
|
|
|
|
|
return - EPIPE;
|
|
|
|
|
ret = h->prot->url_seek(h, pos, whence);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <EFBFBD>ر<EFBFBD>URL */
|
|
|
|
|
int url_close(URLContext *h)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = h->prot->url_close(h);
|
|
|
|
|
av_free(h);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int url_get_max_packet_size(URLContext *h)
|
|
|
|
|
{
|
|
|
|
|
return h->max_packet_size;
|
|
|
|
|
}
|