Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
bbefd27e
Commit
bbefd27e
authored
Aug 25, 2012
by
Michael Niedermayer
Committed by
Derek Buitenhuis
Aug 30, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utvideoenc: Avoid writing into the input picture
Signed-off-by:
Michael Niedermayer
<
michaelni@gmx.at
>
parent
11d957fb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
26 deletions
+42
-26
utvideo.h
libavcodec/utvideo.h
+1
-1
utvideoenc.c
libavcodec/utvideoenc.c
+41
-25
No files found.
libavcodec/utvideo.h
View file @
bbefd27e
...
@@ -75,7 +75,7 @@ typedef struct UtvideoContext {
...
@@ -75,7 +75,7 @@ typedef struct UtvideoContext {
int
interlaced
;
int
interlaced
;
int
frame_pred
;
int
frame_pred
;
uint8_t
*
slice_bits
,
*
slice_buffer
;
uint8_t
*
slice_bits
,
*
slice_buffer
[
4
]
;
int
slice_bits_size
;
int
slice_bits_size
;
}
UtvideoContext
;
}
UtvideoContext
;
...
...
libavcodec/utvideoenc.c
View file @
bbefd27e
...
@@ -44,10 +44,12 @@ static int huff_cmp_sym(const void *a, const void *b)
...
@@ -44,10 +44,12 @@ static int huff_cmp_sym(const void *a, const void *b)
static
av_cold
int
utvideo_encode_close
(
AVCodecContext
*
avctx
)
static
av_cold
int
utvideo_encode_close
(
AVCodecContext
*
avctx
)
{
{
UtvideoContext
*
c
=
avctx
->
priv_data
;
UtvideoContext
*
c
=
avctx
->
priv_data
;
int
i
;
av_freep
(
&
avctx
->
coded_frame
);
av_freep
(
&
avctx
->
coded_frame
);
av_freep
(
&
c
->
slice_bits
);
av_freep
(
&
c
->
slice_bits
);
av_freep
(
&
c
->
slice_buffer
);
for
(
i
=
0
;
i
<
4
;
i
++
)
av_freep
(
&
c
->
slice_buffer
[
i
]);
return
0
;
return
0
;
}
}
...
@@ -55,7 +57,7 @@ static av_cold int utvideo_encode_close(AVCodecContext *avctx)
...
@@ -55,7 +57,7 @@ static av_cold int utvideo_encode_close(AVCodecContext *avctx)
static
av_cold
int
utvideo_encode_init
(
AVCodecContext
*
avctx
)
static
av_cold
int
utvideo_encode_init
(
AVCodecContext
*
avctx
)
{
{
UtvideoContext
*
c
=
avctx
->
priv_data
;
UtvideoContext
*
c
=
avctx
->
priv_data
;
int
i
;
uint32_t
original_format
;
uint32_t
original_format
;
c
->
avctx
=
avctx
;
c
->
avctx
=
avctx
;
...
@@ -142,13 +144,14 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
...
@@ -142,13 +144,14 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
}
}
c
->
slice_buffer
=
av_malloc
(
avctx
->
width
*
avctx
->
height
+
for
(
i
=
0
;
i
<
c
->
planes
;
i
++
)
{
FF_INPUT_BUFFER_PADDING_SIZE
);
c
->
slice_buffer
[
i
]
=
av_malloc
(
avctx
->
width
*
(
avctx
->
height
+
1
)
+
FF_INPUT_BUFFER_PADDING_SIZE
);
if
(
!
c
->
slice_buffer
)
{
if
(
!
c
->
slice_buffer
[
i
])
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Cannot allocate temporary buffer 1.
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"Cannot allocate temporary buffer 1.
\n
"
);
utvideo_encode_close
(
avctx
);
utvideo_encode_close
(
avctx
);
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
}
}
}
/*
/*
...
@@ -193,20 +196,33 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
...
@@ -193,20 +196,33 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
return
0
;
return
0
;
}
}
static
void
mangle_rgb_planes
(
uint8_t
*
src
,
int
step
,
int
stride
,
int
width
,
static
void
mangle_rgb_planes
(
uint8_t
*
dst
[
4
],
uint8_t
*
src
,
int
step
,
int
height
)
int
stride
,
int
width
,
int
height
)
{
{
int
i
,
j
;
int
i
,
j
;
uint8_t
r
,
g
,
b
;
int
k
=
width
;
unsigned
int
g
;
for
(
j
=
0
;
j
<
height
;
j
++
)
{
for
(
j
=
0
;
j
<
height
;
j
++
)
{
for
(
i
=
0
;
i
<
width
*
step
;
i
+=
step
)
{
if
(
step
==
3
)
{
r
=
src
[
i
];
for
(
i
=
0
;
i
<
width
*
step
;
i
+=
step
)
{
g
=
src
[
i
+
1
];
g
=
src
[
i
+
1
];
b
=
src
[
i
+
2
];
dst
[
0
][
k
]
=
g
;
g
+=
0x80
;
src
[
i
]
=
r
-
g
+
0x80
;
dst
[
1
][
k
]
=
src
[
i
+
2
]
-
g
;
src
[
i
+
2
]
=
b
-
g
+
0x80
;
dst
[
2
][
k
]
=
src
[
i
+
0
]
-
g
;
k
++
;
}
}
else
{
for
(
i
=
0
;
i
<
width
*
step
;
i
+=
step
)
{
g
=
src
[
i
+
1
];
dst
[
0
][
k
]
=
g
;
g
+=
0x80
;
dst
[
1
][
k
]
=
src
[
i
+
2
]
-
g
;
dst
[
2
][
k
]
=
src
[
i
+
0
]
-
g
;
dst
[
3
][
k
]
=
src
[
i
+
3
];
k
++
;
}
}
}
src
+=
stride
;
src
+=
stride
;
}
}
...
@@ -535,16 +551,16 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
...
@@ -535,16 +551,16 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
/* In case of RGB, mangle the planes to Ut Video's format */
/* In case of RGB, mangle the planes to Ut Video's format */
if
(
avctx
->
pix_fmt
==
PIX_FMT_RGBA
||
avctx
->
pix_fmt
==
PIX_FMT_RGB24
)
if
(
avctx
->
pix_fmt
==
PIX_FMT_RGBA
||
avctx
->
pix_fmt
==
PIX_FMT_RGB24
)
mangle_rgb_planes
(
pic
->
data
[
0
],
c
->
planes
,
pic
->
linesize
[
0
],
width
,
mangle_rgb_planes
(
c
->
slice_buffer
,
pic
->
data
[
0
],
c
->
planes
,
height
);
pic
->
linesize
[
0
],
width
,
height
);
/* Deal with the planes */
/* Deal with the planes */
switch
(
avctx
->
pix_fmt
)
{
switch
(
avctx
->
pix_fmt
)
{
case
PIX_FMT_RGB24
:
case
PIX_FMT_RGB24
:
case
PIX_FMT_RGBA
:
case
PIX_FMT_RGBA
:
for
(
i
=
0
;
i
<
c
->
planes
;
i
++
)
{
for
(
i
=
0
;
i
<
c
->
planes
;
i
++
)
{
ret
=
encode_plane
(
avctx
,
pic
->
data
[
0
]
+
ff_ut_rgb_order
[
i
]
,
ret
=
encode_plane
(
avctx
,
c
->
slice_buffer
[
i
]
+
width
,
c
->
slice_buffer
,
c
->
planes
,
pic
->
linesize
[
0
]
,
c
->
slice_buffer
[
i
],
1
,
width
,
width
,
height
,
&
pb
);
width
,
height
,
&
pb
);
if
(
ret
)
{
if
(
ret
)
{
...
@@ -555,7 +571,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
...
@@ -555,7 +571,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
break
;
break
;
case
PIX_FMT_YUV422P
:
case
PIX_FMT_YUV422P
:
for
(
i
=
0
;
i
<
c
->
planes
;
i
++
)
{
for
(
i
=
0
;
i
<
c
->
planes
;
i
++
)
{
ret
=
encode_plane
(
avctx
,
pic
->
data
[
i
],
c
->
slice_buffer
,
1
,
ret
=
encode_plane
(
avctx
,
pic
->
data
[
i
],
c
->
slice_buffer
[
0
]
,
1
,
pic
->
linesize
[
i
],
width
>>
!!
i
,
height
,
&
pb
);
pic
->
linesize
[
i
],
width
>>
!!
i
,
height
,
&
pb
);
if
(
ret
)
{
if
(
ret
)
{
...
@@ -566,7 +582,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
...
@@ -566,7 +582,7 @@ static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
break
;
break
;
case
PIX_FMT_YUV420P
:
case
PIX_FMT_YUV420P
:
for
(
i
=
0
;
i
<
c
->
planes
;
i
++
)
{
for
(
i
=
0
;
i
<
c
->
planes
;
i
++
)
{
ret
=
encode_plane
(
avctx
,
pic
->
data
[
i
],
c
->
slice_buffer
,
1
,
ret
=
encode_plane
(
avctx
,
pic
->
data
[
i
],
c
->
slice_buffer
[
0
]
,
1
,
pic
->
linesize
[
i
],
width
>>
!!
i
,
height
>>
!!
i
,
pic
->
linesize
[
i
],
width
>>
!!
i
,
height
>>
!!
i
,
&
pb
);
&
pb
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment