1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| static void process_client(AVIOContext *client, const char *in_uri) { while ((ret = avio_handshake(client)) > 0) { av_opt_get(client, "resource", AV_OPT_SEARCH_CHILDREN, &resource); if (resource && strlen(resource)) break; av_freep(&resource); } if (ret < 0) goto end; av_log(client, AV_LOG_TRACE, "resource=%p\n", resource); if (resource && resource[0] == '/' && !strcmp((resource + 1), in_uri)) { reply_code = 200; } else { reply_code = AVERROR_HTTP_NOT_FOUND; } if ((ret = av_opt_set_int(client, "reply_code", reply_code, AV_OPT_SEARCH_CHILDREN)) < 0) { av_log(client, AV_LOG_ERROR, "Failed to set reply_code: %s.\n", av_err2str(ret)); goto end; } av_log(client, AV_LOG_TRACE, "Set reply code to %d\n", reply_code);
while ((ret = avio_handshake(client)) > 0);
if (ret < 0) goto end;
fprintf(stderr, "Handshake performed.\n"); if (reply_code != 200) goto end; fprintf(stderr, "Opening input file.\n"); if ((ret = avio_open2(&input, in_uri, AVIO_FLAG_READ, NULL, NULL)) < 0) { av_log(input, AV_LOG_ERROR, "Failed to open input: %s: %s.\n", in_uri, av_err2str(ret)); goto end; } for (;;) { n = avio_read(input, buf, sizeof(buf)); if (n < 0) { if (n == AVERROR_EOF) break; av_log(input, AV_LOG_ERROR, "Error reading from input: %s.\n", av_err2str(n)); break; } avio_write(client, buf, n); avio_flush(client); } end: avio_flush(); avio_close(); avio_close(); av_freep(); }
|