FFmpeg
jit.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005 Aurelien Jacobs <aurel@gnuage.org>
3  * Copyright (C) 2009, 2026 Ramiro Polla <ramiro.polla@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config.h"
23 
24 #include "libavutil/error.h"
25 
26 #include "jit.h"
27 
28 #if HAVE_MMAP && HAVE_MPROTECT
29 # define _DEFAULT_SOURCE
30 # define _SVID_SOURCE // needed for MAP_ANONYMOUS
31 # define _DARWIN_C_SOURCE // needed for MAP_ANON
32 # include <sys/mman.h>
33 # if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
34 # define MAP_ANONYMOUS MAP_ANON
35 # endif
36 #endif
37 
38 #if HAVE_MMAP && HAVE_MPROTECT && defined(MAP_ANONYMOUS)
39 
40 void *ff_sws_jit_alloc(size_t size)
41 {
42  void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
43  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
44  if (ptr == MAP_FAILED)
45  return NULL;
46  return ptr;
47 }
48 
49 int ff_sws_jit_protect(void *ptr, size_t size)
50 {
51  if (mprotect(ptr, size, PROT_READ | PROT_EXEC) == -1)
52  return AVERROR(errno);
53  return 0;
54 }
55 
56 void ff_sws_jit_free(void *ptr, size_t size)
57 {
58  if (ptr)
59  munmap(ptr, size);
60 }
61 
62 #elif HAVE_VIRTUALALLOC
63 
64 #include <windows.h>
65 
66 void *ff_sws_jit_alloc(size_t size)
67 {
68  return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
69 }
70 
71 int ff_sws_jit_protect(void *ptr, size_t size)
72 {
73  DWORD old_protect;
74  if (!VirtualProtect(ptr, size, PAGE_EXECUTE_READ, &old_protect))
75  return AVERROR(EINVAL);
76  return 0;
77 }
78 
79 void ff_sws_jit_free(void *ptr, size_t size)
80 {
81  if (ptr)
82  VirtualFree(ptr, 0, MEM_RELEASE);
83 }
84 
85 #else
86 
87 #include "libavutil/mem.h"
88 
89 void *ff_sws_jit_alloc(size_t size)
90 {
91  return av_malloc(size);
92 }
93 
94 int ff_sws_jit_protect(void *ptr, size_t size)
95 {
96  return 0;
97 }
98 
99 void ff_sws_jit_free(void *ptr, size_t size)
100 {
101  av_free(ptr);
102 }
103 
104 #endif
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_sws_jit_free
void ff_sws_jit_free(void *ptr, size_t size)
Definition: jit.c:99
NULL
#define NULL
Definition: coverity.c:32
jit.h
error.h
size
int size
Definition: twinvq_data.h:10344
av_malloc
#define av_malloc(s)
Definition: ops_static.c:44
ff_sws_jit_alloc
void * ff_sws_jit_alloc(size_t size)
Definition: jit.c:89
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
ff_sws_jit_protect
int ff_sws_jit_protect(void *ptr, size_t size)
Definition: jit.c:94