Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
885158c8
Commit
885158c8
authored
13 years ago
by
Michael Niedermayer
Browse files
Options
Downloads
Patches
Plain Diff
Move av_tempfile() into libavutil, it is a generically usefull thing and its small.
Signed-off-by:
Michael Niedermayer
<
michaelni@gmx.at
>
parent
7f16ec61
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
libavcodec/libxvid_rc.c
+2
-1
2 additions, 1 deletion
libavcodec/libxvid_rc.c
libavcodec/libxvidff.c
+2
-40
2 additions, 40 deletions
libavcodec/libxvidff.c
libavutil/file.c
+31
-0
31 additions, 0 deletions
libavutil/file.c
libavutil/file.h
+9
-0
9 additions, 0 deletions
libavutil/file.h
with
44 additions
and
41 deletions
libavcodec/libxvid_rc.c
+
2
−
1
View file @
885158c8
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include
<xvid.h>
#include
<xvid.h>
#include
<unistd.h>
#include
<unistd.h>
#include
"libavutil/file.h"
#include
"avcodec.h"
#include
"avcodec.h"
#include
"libxvid_internal.h"
#include
"libxvid_internal.h"
//#include "dsputil.h"
//#include "dsputil.h"
...
@@ -40,7 +41,7 @@ int ff_xvid_rate_control_init(MpegEncContext *s){
...
@@ -40,7 +41,7 @@ int ff_xvid_rate_control_init(MpegEncContext *s){
//xvid_debug=-1;
//xvid_debug=-1;
fd
=
ff
_tempfile
(
"xvidrc."
,
&
tmp_name
);
fd
=
av
_tempfile
(
"xvidrc."
,
&
tmp_name
);
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"Can't create temporary pass2 file.
\n
"
);
av_log
(
NULL
,
AV_LOG_ERROR
,
"Can't create temporary pass2 file.
\n
"
);
return
-
1
;
return
-
1
;
...
...
This diff is collapsed.
Click to expand it.
libavcodec/libxvidff.c
+
2
−
40
View file @
885158c8
...
@@ -28,13 +28,11 @@
...
@@ -28,13 +28,11 @@
#include
<xvid.h>
#include
<xvid.h>
#include
<unistd.h>
#include
<unistd.h>
#include
"avcodec.h"
#include
"avcodec.h"
#include
"libavutil/file.h"
#include
"libavutil/cpu.h"
#include
"libavutil/cpu.h"
#include
"libavutil/intreadwrite.h"
#include
"libavutil/intreadwrite.h"
#include
"libavutil/mathematics.h"
#include
"libavutil/mathematics.h"
#include
"libxvid_internal.h"
#include
"libxvid_internal.h"
#if !HAVE_MKSTEMP
#include
<fcntl.h>
#endif
/**
/**
* Buffer management macros.
* Buffer management macros.
...
@@ -77,42 +75,6 @@ int xvid_strip_vol_header(AVCodecContext *avctx, unsigned char *frame, unsigned
...
@@ -77,42 +75,6 @@ int xvid_strip_vol_header(AVCodecContext *avctx, unsigned char *frame, unsigned
int
xvid_ff_2pass
(
void
*
ref
,
int
opt
,
void
*
p1
,
void
*
p2
);
int
xvid_ff_2pass
(
void
*
ref
,
int
opt
,
void
*
p1
,
void
*
p2
);
void
xvid_correct_framerate
(
AVCodecContext
*
avctx
);
void
xvid_correct_framerate
(
AVCodecContext
*
avctx
);
/* Wrapper to work around the lack of mkstemp() on mingw.
* Also, tries to create file in /tmp first, if possible.
* *prefix can be a character constant; *filename will be allocated internally.
* @return file descriptor of opened file (or -1 on error)
* and opened file name in **filename. */
int
ff_tempfile
(
const
char
*
prefix
,
char
**
filename
)
{
int
fd
=-
1
;
#if !HAVE_MKSTEMP
*
filename
=
tempnam
(
"."
,
prefix
);
#else
size_t
len
=
strlen
(
prefix
)
+
12
;
/* room for "/tmp/" and "XXXXXX\0" */
*
filename
=
av_malloc
(
len
);
#endif
/* -----common section-----*/
if
(
*
filename
==
NULL
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"ff_tempfile: Cannot allocate file name
\n
"
);
return
-
1
;
}
#if !HAVE_MKSTEMP
fd
=
open
(
*
filename
,
O_RDWR
|
O_BINARY
|
O_CREAT
,
0444
);
#else
snprintf
(
*
filename
,
len
,
"/tmp/%sXXXXXX"
,
prefix
);
fd
=
mkstemp
(
*
filename
);
if
(
fd
<
0
)
{
snprintf
(
*
filename
,
len
,
"./%sXXXXXX"
,
prefix
);
fd
=
mkstemp
(
*
filename
);
}
#endif
/* -----common section-----*/
if
(
fd
<
0
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"ff_tempfile: Cannot open temporary file %s
\n
"
,
*
filename
);
return
-
1
;
}
return
fd
;
/* success */
}
#if CONFIG_LIBXVID_ENCODER
#if CONFIG_LIBXVID_ENCODER
/**
/**
...
@@ -270,7 +232,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
...
@@ -270,7 +232,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
rc2pass2
.
version
=
XVID_VERSION
;
rc2pass2
.
version
=
XVID_VERSION
;
rc2pass2
.
bitrate
=
avctx
->
bit_rate
;
rc2pass2
.
bitrate
=
avctx
->
bit_rate
;
fd
=
ff
_tempfile
(
"xvidff."
,
&
(
x
->
twopassfile
));
fd
=
av
_tempfile
(
"xvidff."
,
&
(
x
->
twopassfile
));
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
av_log
(
avctx
,
AV_LOG_ERROR
,
"Xvid: Cannot write 2-pass pipe
\n
"
);
"Xvid: Cannot write 2-pass pipe
\n
"
);
...
...
This diff is collapsed.
Click to expand it.
libavutil/file.c
+
31
−
0
View file @
885158c8
...
@@ -130,6 +130,37 @@ void av_file_unmap(uint8_t *bufptr, size_t size)
...
@@ -130,6 +130,37 @@ void av_file_unmap(uint8_t *bufptr, size_t size)
#endif
#endif
}
}
int
av_tempfile
(
const
char
*
prefix
,
char
**
filename
)
{
int
fd
=-
1
;
#if !HAVE_MKSTEMP
*
filename
=
tempnam
(
"."
,
prefix
);
#else
size_t
len
=
strlen
(
prefix
)
+
12
;
/* room for "/tmp/" and "XXXXXX\0" */
*
filename
=
av_malloc
(
len
);
#endif
/* -----common section-----*/
if
(
*
filename
==
NULL
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"ff_tempfile: Cannot allocate file name
\n
"
);
return
-
1
;
}
#if !HAVE_MKSTEMP
fd
=
open
(
*
filename
,
O_RDWR
|
O_BINARY
|
O_CREAT
,
0444
);
#else
snprintf
(
*
filename
,
len
,
"/tmp/%sXXXXXX"
,
prefix
);
fd
=
mkstemp
(
*
filename
);
if
(
fd
<
0
)
{
snprintf
(
*
filename
,
len
,
"./%sXXXXXX"
,
prefix
);
fd
=
mkstemp
(
*
filename
);
}
#endif
/* -----common section-----*/
if
(
fd
<
0
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"ff_tempfile: Cannot open temporary file %s
\n
"
,
*
filename
);
return
-
1
;
}
return
fd
;
/* success */
}
#ifdef TEST
#ifdef TEST
#undef printf
#undef printf
...
...
This diff is collapsed.
Click to expand it.
libavutil/file.h
+
9
−
0
View file @
885158c8
...
@@ -49,4 +49,13 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
...
@@ -49,4 +49,13 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
*/
*/
void
av_file_unmap
(
uint8_t
*
bufptr
,
size_t
size
);
void
av_file_unmap
(
uint8_t
*
bufptr
,
size_t
size
);
/**
* Wrapper to work around the lack of mkstemp() on mingw.
* Also, tries to create file in /tmp first, if possible.
* *prefix can be a character constant; *filename will be allocated internally.
* @return file descriptor of opened file (or -1 on error)
* and opened file name in **filename.
*/
int
av_tempfile
(
const
char
*
prefix
,
char
**
filename
);
#endif
/* AVUTIL_FILE_H */
#endif
/* AVUTIL_FILE_H */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment