Serve a file without decoding or demuxing it over the HTTP protocol. Multiple clients can connect and will receive the same file.
/*
* Copyright (c) 2015 Stephan Holljes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @file libavformat multi-client network API usage example
* @example avio_http_serve_files.c
*
* Serve a file without decoding or demuxing it over the HTTP protocol. Multiple
* clients can connect and will receive the same file.
*/
#include <unistd.h>
{
uint8_t buf[1024];
uint8_t *resource =
NULL;
// check for strlen(resource) is necessary, because av_opt_get()
// may return empty string.
if (resource && strlen(resource))
break;
}
goto end;
if (resource && resource[0] == '/' && !strcmp((resource + 1), in_uri)) {
reply_code = 200;
} else {
}
goto end;
}
goto end;
fprintf(stderr, "Handshake performed.\n");
if (reply_code != 200)
goto end;
fprintf(stderr, "Opening input file.\n");
goto end;
}
for(;;) {
if (n < 0) {
break;
break;
}
}
end:
fprintf(stderr, "Flushing client\n");
fprintf(stderr, "Closing client\n");
fprintf(stderr, "Closing input\n");
}
int main(
int argc,
char **argv)
{
const char *in_uri, *out_uri;
if (argc < 3) {
printf(
"usage: %s input http://hostname[:port]\n"
"API example program to serve http to multiple clients.\n"
"\n", argv[0]);
return 1;
}
in_uri = argv[1];
out_uri = argv[2];
fprintf(stderr,
"Failed to set listen mode for server: %s\n",
av_err2str(
ret));
}
}
fprintf(stderr, "Entering main loop.\n");
for(;;) {
goto end;
fprintf(stderr, "Accepted client, forking process.\n");
// XXX: Since we don't reap our children and don't ignore signals
// this produces zombie processes.
pid = fork();
if (pid < 0) {
perror("Fork failed");
goto end;
}
if (pid == 0) {
fprintf(stderr, "In child.\n");
exit(0);
}
if (pid > 0)
}
end:
return 1;
}
return 0;
}