| 57 | } |
| 58 | |
| 59 | int main(int argc, char *argv[]) |
| 60 | { |
| 61 | AVFormatContext *fmt_ctx = NULL; |
| 62 | AVIOContext *avio_ctx = NULL; |
| 63 | uint8_t *buffer = NULL, *avio_ctx_buffer = NULL; |
| 64 | size_t buffer_size, avio_ctx_buffer_size = 4096; |
| 65 | char *input_filename = NULL; |
| 66 | int ret = 0; |
| 67 | struct buffer_data bd = { 0 }; |
| 68 | |
| 69 | if (argc != 2) { |
| 70 | fprintf(stderr, "usage: %s input_file\n" |
| 71 | "API example program to show how to read from a custom buffer " |
| 72 | "accessed through AVIOContext.\n", argv[0]); |
| 73 | return 1; |
| 74 | } |
| 75 | input_filename = argv[1]; |
| 76 | |
| 77 | /* slurp file content into buffer */ |
| 78 | ret = av_file_map(input_filename, &buffer, &buffer_size, 0, NULL); |
| 79 | if (ret < 0) |
| 80 | goto end; |
| 81 | |
| 82 | /* fill opaque structure used by the AVIOContext read callback */ |
| 83 | bd.ptr = buffer; |
| 84 | bd.size = buffer_size; |
| 85 | |
| 86 | if (!(fmt_ctx = avformat_alloc_context())) { |
| 87 | ret = AVERROR(ENOMEM); |
| 88 | goto end; |
| 89 | } |
| 90 | |
| 91 | avio_ctx_buffer = av_malloc(avio_ctx_buffer_size); |
| 92 | if (!avio_ctx_buffer) { |
| 93 | ret = AVERROR(ENOMEM); |
| 94 | goto end; |
| 95 | } |
| 96 | avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size, |
| 97 | 0, &bd, &read_packet, NULL, NULL); |
| 98 | if (!avio_ctx) { |
| 99 | av_freep(&avio_ctx_buffer); |
| 100 | ret = AVERROR(ENOMEM); |
| 101 | goto end; |
| 102 | } |
| 103 | fmt_ctx->pb = avio_ctx; |
| 104 | |
| 105 | ret = avformat_open_input(&fmt_ctx, NULL, NULL, NULL); |
| 106 | if (ret < 0) { |
| 107 | fprintf(stderr, "Could not open input\n"); |
| 108 | goto end; |
| 109 | } |
| 110 | |
| 111 | ret = avformat_find_stream_info(fmt_ctx, NULL); |
| 112 | if (ret < 0) { |
| 113 | fprintf(stderr, "Could not find stream information\n"); |
| 114 | goto end; |
| 115 | } |
| 116 |
nothing calls this directly
no test coverage detected