FFmpeg
Loading...
Searching...
No Matches
file.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stdarg.h>
20#include <stdio.h>
21
22#include "libavutil/file.c"
23#include "libavutil/log.h"
24
25static int last_log_level = -1;
26
27static void log_callback(void *ctx, int level, const char *fmt, va_list args)
28{
29 (void)ctx; (void)fmt; (void)args;
31}
32
33int main(int argc, char **argv)
34{
35 const char *path = argc > 1 ? argv[1] : "file.c";
36 uint8_t *buf;
37 size_t size;
38
40
41 /* map an existing file and verify it is non-empty and readable */
42 if (av_file_map(path, &buf, &size, 0, NULL) < 0)
43 return 1;
44 av_file_unmap(buf, size);
45 if (size == 0)
46 return 1;
47
48 /* for offset i, error must be logged at AV_LOG_ERROR + i */
49 for (int i = 0; i < 2; i++) {
50 last_log_level = -1;
51 if (av_file_map("no_such_file_xyz", &buf, &size, i, NULL) >= 0) {
52 av_file_unmap(buf, size);
53 return 2;
54 }
55 if (last_log_level != AV_LOG_ERROR + i) {
56 fprintf(stderr, "expected level %d with offset=%d, got %d\n",
58 return 3;
59 }
60 }
61
62 return 0;
63}
static AVFormatContext * ctx
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
int main
Definition dovi_rpuenc.c:38
static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
Definition ffprobe.c:381
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition log.c:491
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition file.c:142
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
Definition file.c:55
static void log_callback(void *ctx, int level, const char *fmt, va_list args)
Definition file.c:27
static int last_log_level
Definition file.c:25
uint8_t level
Definition svq3.c:208
int size