dropped several unused functions in libdvbmpeg

This commit is contained in:
Frank Schmirler 2011-11-12 22:28:27 +01:00
parent 6c9c6ca77f
commit 8850e63da5
3 changed files with 1 additions and 534 deletions

View File

@ -1,6 +1,7 @@
VDR Plugin 'streamdev' Revision History VDR Plugin 'streamdev' Revision History
--------------------------------------- ---------------------------------------
- dropped several unused functions in libdvbmpeg
- restricted VTP command RENR to liemikuutio patch < 1.32. Build fails with - restricted VTP command RENR to liemikuutio patch < 1.32. Build fails with
newer versions of this patch (thanks to Ville Skyttä) newer versions of this patch (thanks to Ville Skyttä)
- updated outdated COPYING file and FSF address (thanks to Ville Skyttä) - updated outdated COPYING file and FSF address (thanks to Ville Skyttä)

View File

@ -1876,528 +1876,3 @@ int write_ps_header(uint8_t *buf,
} }
} }
#define MAX_BASE 80
#define MAX_PATH 256
#define MAX_EXT 10
int break_up_filename(char *name, char *base_name, char *path, char *ext)
{
int l,i,sstop,sstart;
l = strlen(name);
sstop = l;
sstart = -1;
for( i= l-1; i >= 0; i--){
if (sstop == l && name[i] == '.') sstop = i;
if (sstart<0 && name[i] == '/') sstart = i+1;
}
if (sstart < 0) sstart = 0;
if (sstop-sstart < MAX_BASE){
strncpy(base_name, name+sstart, sstop-sstart);
base_name[sstop-sstart]=0;
if(sstart > 0){
if( l - sstop + sstart < MAX_PATH){
strncpy(path, name, sstart);
path[sstart] = 0;
} else {
fprintf(stderr,"PATH too long\n");
return -1;
}
} else {
strcpy(path, "./");
}
if(sstop < l){
if( l - sstop -1 < MAX_EXT){
strncpy(ext, name+sstop+1, l-sstop-1);
ext[l-sstop-1]=0;
} else {
fprintf(stderr,"Extension too long\n");
return -1;
}
} else {
strcpy(ext, "");
}
} else {
fprintf(stderr,"Name too long\n");
return -1;
}
/*
printf("%d %d\n",sstart, sstop);
printf("%s %d\n",name, strlen(name));
printf("%s %d\n",base_name, strlen(base_name));
printf("%s %d\n",path,strlen(path));
printf("%s %d\n",ext,strlen(ext));
*/
return 0;
}
int seek_mpg_start(uint8_t *buf, int size)
{
int found = 0;
int c=0;
int seq = 0;
int mpeg = 0;
int mark = 0;
while ( !seq ){
while (found != 4){
switch (found) {
case 0:
if ( buf[c] == 0x00 ) found++;
c++;
break;
case 1:
if ( buf[c] == 0x00 ) found++;
else found = 0;
c++;
break;
case 2:
if ( buf[c] == 0x01 ) found++;
else found = 0;
if ( buf[c] == 0x00 ) found = 2;
c++;
break;
case 3:
if ( (buf[c] & 0xe0) == 0xe0 ) found++;
else found = 0;
c++;
break;
}
if (c >= size) return -1;
}
if (found == 4){
mark = c-4;
c+=2;
if (c >= size) return -1;
if ( (buf[c] & 0xC0) == 0x80 ){
mpeg = 2;
c += 2;
if (c >= size) return -1;
c += buf[c]+1;
if (c >= size) return -1;
} else {
mpeg = 1;
while( buf[c] == 0xFF ) {
c++;
if (c >= size) return -1;
}
if ( (buf[c] & 0xC0) == 0x40) c+=2;
if (c >= size) return -1;
if ( (buf[c] & 0x30) ){
if ( (buf[c] & 0x30) == 0x20) c+=5;
else c+=10;
} else c++;
if (c >= size) return -1;
}
if ( buf[c] == 0x00 &&
buf[c+1] == 0x00 &&
buf[c+2] == 0x01 &&
buf[c+3] == 0xB3 )
seq = 1;
}
found = 0;
}
return size-mark;
}
void write_mpg(int fstart, uint64_t length, int fdin, int fdout)
{
// uint8_t mpeg_end[4] = { 0x00, 0x00, 0x01, 0xB9 };
uint8_t *buf;
uint64_t l=0;
uint64_t count = 0;
struct stat sb;
int buf_size;
fstat (fdout, &sb);
buf_size = sb.st_blksize;
buf = (uint8_t *) alloca (buf_size + sizeof (int));
lseek(fdin, fstart, SEEK_SET);
while ( count < length && (l = read(fdin,buf,buf_size)) >= 0){
if (l > 0) count+=l;
write(fdout,buf,l);
printf("written %02.2f%%\r",(100.*count)/length);
}
printf("\n");
//write( fdout, mpeg_end, 4);
}
#define CHECKBUF (1024*1024)
#define ONE_GIG (1024UL*1024UL*1024UL)
void split_mpg(char *name, uint64_t size)
{
char base_name[MAX_BASE];
char path[MAX_PATH];
char ext[MAX_EXT];
char new_name[256];
uint8_t buf[CHECKBUF];
int fdin;
int fdout;
uint64_t length = 0;
uint64_t last;
int i;
int mark, csize;
struct stat sb;
if (break_up_filename(name,base_name,path,ext) < 0) exit(1);
#ifdef __FreeBSD__
if ( (fdin = open(name, O_RDONLY)) < 0){
#else
if ( (fdin = open(name, O_RDONLY|O_LARGEFILE)) < 0){
#endif
fprintf(stderr,"Can't open %s\n",name);
exit(1);
}
fstat (fdin, &sb);
length = sb.st_size;
if ( length < ONE_GIG )
printf("Filelength = %2.2f MB\n", length/1024./1024.);
else
printf("Filelength = %2.2f GB\n", length/1024./1024./1024.);
if ( length < size ) length = size;
printf("Splitting %s into Files with size <= %2.2f MB\n",name,
size/1024./1024.);
csize = CHECKBUF;
read(fdin, buf, csize);
if ( (mark = seek_mpg_start(buf,csize)) < 0){
fprintf(stderr,"Couldn't find sequence header\n");
exit(1);
}
last = csize-mark;
for ( i = 0 ; i < length/size; i++){
csize = CHECKBUF;
if (csize > length-last) csize = length-last;
lseek(fdin, last+size-csize, SEEK_SET);
read(fdin, buf, csize);
if ( (mark = seek_mpg_start(buf,csize)) < 0){
fprintf(stderr,"Couldn't find sequence header\n");
exit(1);
}
sprintf(new_name,"%s-%03d.%s",base_name,i,ext);
printf("writing %s\n",new_name);
#ifdef __FreeBSD__
if ( (fdout = open(new_name,O_WRONLY|O_CREAT|O_TRUNC,
#else
if ( (fdout = open(new_name,O_WRONLY|O_CREAT|O_TRUNC
|O_LARGEFILE,
#endif
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|
S_IROTH|S_IWOTH)) < 0){
fprintf(stderr,"Can't open %s\n",new_name);
exit(1);
}
write_mpg(last, size-mark, fdin, fdout);
last = last + size - mark;
}
sprintf(new_name,"%s-%03d.%s",base_name,i,ext);
printf("writing %s\n",new_name);
#ifdef __FreeBSD__
if ( (fdout = open(new_name,O_WRONLY|O_CREAT|O_TRUNC,
#else
if ( (fdout = open(new_name,O_WRONLY|O_CREAT|O_TRUNC
|O_LARGEFILE,
#endif
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|
S_IROTH|S_IWOTH)) < 0){
fprintf(stderr,"Can't open %s\n",new_name);
exit(1);
}
write_mpg(last, length-last, fdin, fdout);
}
void cut_mpg(char *name, uint64_t size)
{
char base_name[MAX_BASE];
char path[MAX_PATH];
char ext[MAX_EXT];
char new_name[256];
uint8_t buf[CHECKBUF];
int fdin;
int fdout;
uint64_t length = 0;
uint64_t last;
int mark, csize;
struct stat sb;
if (break_up_filename(name,base_name,path,ext) < 0) exit(1);
#ifdef __FreeBSD__
if ( (fdin = open(name, O_RDONLY)) < 0){
#else
if ( (fdin = open(name, O_RDONLY|O_LARGEFILE)) < 0){
#endif
fprintf(stderr,"Can't open %s\n",name);
exit(1);
}
fstat (fdin, &sb);
length = sb.st_size;
if ( length < ONE_GIG )
printf("Filelength = %2.2f MB\n", length/1024./1024.);
else
printf("Filelength = %2.2f GB\n", length/1024./1024./1024.);
if ( length < size ) length = size;
printf("Splitting %s into 2 Files with length %.2f MB and %.2f MB\n",
name, size/1024./1024., (length-size)/1024./1024.);
csize = CHECKBUF;
read(fdin, buf, csize);
if ( (mark = seek_mpg_start(buf,csize)) < 0){
fprintf(stderr,"Couldn't find sequence header\n");
exit(1);
}
last = csize-mark;
if (csize > length-last) csize = length-last;
lseek(fdin, last+size-csize, SEEK_SET);
read(fdin, buf, csize);
if ( (mark = seek_mpg_start(buf,csize)) < 0){
fprintf(stderr,"Couldn't find sequence header\n");
exit(1);
}
sprintf(new_name,"%s-1.%s",base_name,ext);
printf("writing %s\n",new_name);
#ifdef __FreeBSD__
if ( (fdout = open(new_name,O_WRONLY|O_CREAT|O_TRUNC,
#else
if ( (fdout = open(new_name,O_WRONLY|O_CREAT|O_TRUNC
|O_LARGEFILE,
#endif
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|
S_IROTH|S_IWOTH)) < 0){
fprintf(stderr,"Can't open %s\n",new_name);
exit(1);
}
write_mpg(last, size-mark, fdin, fdout);
last = last + size - mark;
sprintf(new_name,"%s-2.%s",base_name,ext);
printf("writing %s\n",new_name);
#ifdef __FreeBSD__
if ( (fdout = open(new_name,O_WRONLY|O_CREAT|O_TRUNC,
#else
if ( (fdout = open(new_name,O_WRONLY|O_CREAT|O_TRUNC
|O_LARGEFILE,
#endif
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|
S_IROTH|S_IWOTH)) < 0){
fprintf(stderr,"Can't open %s\n",new_name);
exit(1);
}
write_mpg(last, length-last, fdin, fdout);
}
void write_all (int fd, const char *data, int length)
{
int r;
while (length) {
if ((r = write(fd, data, length)) > 0) {
data += r;
length -= r;
}
}
}
void read_all (int fd, char *data, int length)
{
int c = 0;
while(1) {
if( read(fd, data+c, 1) == 1) {
c++;
if(data[c-1] == '\n') {
data[c] = 0;
break;
}
}
else {
fprintf (stderr, "Error reading socket\n");
exit(1);
}
}
}
char *url2host (char *url, char **name, uint32_t *ip, uint32_t *port)
{
char *murl;
struct hostent *hoste;
struct in_addr haddr;
int found_ip = 1;
if (!(strncmp(url, "http://", 7)))
url += 7;
*name = strdup(url);
if (!(*name)) {
*name = NULL;
return (NULL);
}
murl = url;
while (*murl && *murl != ':' && *murl != '/') {
if ((*murl < '0' || *murl > '9') && *murl != '.')
found_ip = 0;
murl++;
}
(*name)[murl - url] = 0;
if (found_ip) {
if ((*ip = inet_addr(*name)) == INADDR_NONE)
return (NULL);
} else {
if (!(hoste = gethostbyname(*name)))
return (NULL);
memcpy (&haddr, hoste->h_addr, sizeof(haddr));
*ip = haddr.s_addr;
}
if (!*murl || *murl == '/') {
*port = 80;
return (murl);
}
*port = atoi(++murl);
while (*murl && *murl != '/')
murl++;
return (murl);
}
#define ACCEPT "Accept: video/mpeg, video/x-mpegurl, */*\r\n"
int http_open (char *url)
{
char purl[1024], *host, req[1024], *sptr;
uint32_t ip;
uint32_t port;
int sock;
int reloc, relocnum = 0;
struct sockaddr_in server;
int mfd;
strncpy (purl, url, 1023);
purl[1023] = '\0';
do {
host = NULL;
strcpy (req, "GET ");
if (!(sptr = url2host(purl, &host, &ip, &port))) {
fprintf (stderr, "Unknown host\n");
exit (1);
}
strcat (req, sptr);
sprintf (req + strlen(req),
" HTTP/1.0\r\nUser-Agent: %s/%s\r\n",
"whatever", "you want");
if (host) {
sprintf(req + strlen(req),
"Host: %s:%u\r\n", host, port);
free (host);
}
strcat (req, ACCEPT);
strcat (req, "\r\n");
server.sin_port = htons(port);
server.sin_family = AF_INET;
server.sin_addr.s_addr = ip;
if ((sock = socket(PF_INET, SOCK_STREAM, 6)) < 0) {
perror ("socket");
exit (1);
}
if (connect(sock, (struct sockaddr *)&server,
sizeof(server))) {
perror ("connect");
exit (1);
}
write_all (sock, req, strlen(req));
if (!(mfd = fileno(fdopen(sock, "rb")))) {
perror ("open");
exit (1);
}
reloc = 0;
purl[0] = '\0';
read_all (mfd, req, 1023);
if ((sptr = strchr(req, ' '))) {
switch (sptr[1]) {
case '2':
break;
case '3':
reloc = 1;
default:
fprintf (stderr, "HTTP req failed:%s",
sptr+1);
exit (1);
}
}
do {
read_all (mfd,req, 1023);
if (!strncmp(req, "Location:", 9))
strncpy (purl, req+10, 1023);
} while (req[0] != '\r' && req[0] != '\n');
} while (reloc && purl[0] && relocnum++ < 3);
if (reloc) {
fprintf (stderr, "Too many HTTP relocations.\n");
exit (1);
}
return sock;
}
extern int errno;
const char * strerrno (void)
{
return strerror(errno);
}

View File

@ -387,16 +387,7 @@ extern "C" {
uint8_t buffer2_scale, uint8_t buffer2_scale,
uint32_t buffer2_size); uint32_t buffer2_size);
int seek_mpg_start(uint8_t *buf, int size);
void split_mpg(char *name, uint64_t size);
void cut_mpg(char *name, uint64_t size);
int http_open (char *url);
ssize_t save_read(int fd, void *buf, size_t count); ssize_t save_read(int fd, void *buf, size_t count);
const char * strerrno(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */