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
2c785e25
Commit
2c785e25
authored
Dec 24, 2012
by
Justin Ruggles
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mpegaudio: decode directly to the user-provided AVFrame
parent
dc33fbbf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
20 deletions
+20
-20
mpegaudiodec.c
libavcodec/mpegaudiodec.c
+20
-20
No files found.
libavcodec/mpegaudiodec.c
View file @
2c785e25
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
* MPEG Audio decoder
* MPEG Audio decoder
*/
*/
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/channel_layout.h"
#include "libavutil/float_dsp.h"
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#include "avcodec.h"
...
@@ -84,7 +85,7 @@ typedef struct MPADecodeContext {
...
@@ -84,7 +85,7 @@ typedef struct MPADecodeContext {
AVCodecContext
*
avctx
;
AVCodecContext
*
avctx
;
MPADSPContext
mpadsp
;
MPADSPContext
mpadsp
;
AVFloatDSPContext
fdsp
;
AVFloatDSPContext
fdsp
;
AVFrame
frame
;
AVFrame
*
frame
;
}
MPADecodeContext
;
}
MPADecodeContext
;
#if CONFIG_FLOAT
#if CONFIG_FLOAT
...
@@ -448,9 +449,6 @@ static av_cold int decode_init(AVCodecContext * avctx)
...
@@ -448,9 +449,6 @@ static av_cold int decode_init(AVCodecContext * avctx)
if
(
avctx
->
codec_id
==
AV_CODEC_ID_MP3ADU
)
if
(
avctx
->
codec_id
==
AV_CODEC_ID_MP3ADU
)
s
->
adu_mode
=
1
;
s
->
adu_mode
=
1
;
avcodec_get_frame_defaults
(
&
s
->
frame
);
avctx
->
coded_frame
=
&
s
->
frame
;
return
0
;
return
0
;
}
}
...
@@ -1612,12 +1610,13 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples,
...
@@ -1612,12 +1610,13 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples,
/* get output buffer */
/* get output buffer */
if
(
!
samples
)
{
if
(
!
samples
)
{
s
->
frame
.
nb_samples
=
s
->
avctx
->
frame_size
;
av_assert0
(
s
->
frame
!=
NULL
);
if
((
ret
=
ff_get_buffer
(
s
->
avctx
,
&
s
->
frame
))
<
0
)
{
s
->
frame
->
nb_samples
=
s
->
avctx
->
frame_size
;
if
((
ret
=
ff_get_buffer
(
s
->
avctx
,
s
->
frame
))
<
0
)
{
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"get_buffer() failed
\n
"
);
av_log
(
s
->
avctx
,
AV_LOG_ERROR
,
"get_buffer() failed
\n
"
);
return
ret
;
return
ret
;
}
}
samples
=
(
OUT_INT
**
)
s
->
frame
.
extended_data
;
samples
=
(
OUT_INT
**
)
s
->
frame
->
extended_data
;
}
}
/* apply the synthesis filter */
/* apply the synthesis filter */
...
@@ -1679,11 +1678,13 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
...
@@ -1679,11 +1678,13 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
buf_size
=
s
->
frame_size
;
buf_size
=
s
->
frame_size
;
}
}
s
->
frame
=
data
;
ret
=
mp_decode_frame
(
s
,
NULL
,
buf
,
buf_size
);
ret
=
mp_decode_frame
(
s
,
NULL
,
buf
,
buf_size
);
if
(
ret
>=
0
)
{
if
(
ret
>=
0
)
{
*
got_frame_ptr
=
1
;
s
->
frame
->
nb_samples
=
avctx
->
frame_size
;
*
(
AVFrame
*
)
data
=
s
->
frame
;
*
got_frame_ptr
=
1
;
avctx
->
sample_rate
=
s
->
sample_rate
;
avctx
->
sample_rate
=
s
->
sample_rate
;
//FIXME maybe move the other codec info stuff from above here too
//FIXME maybe move the other codec info stuff from above here too
}
else
{
}
else
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Error while decoding MPEG audio frame.
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"Error while decoding MPEG audio frame.
\n
"
);
...
@@ -1750,14 +1751,15 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
...
@@ -1750,14 +1751,15 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
s
->
frame_size
=
len
;
s
->
frame_size
=
len
;
s
->
frame
=
data
;
ret
=
mp_decode_frame
(
s
,
NULL
,
buf
,
buf_size
);
ret
=
mp_decode_frame
(
s
,
NULL
,
buf
,
buf_size
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Error while decoding MPEG audio frame.
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"Error while decoding MPEG audio frame.
\n
"
);
return
ret
;
return
ret
;
}
}
*
got_frame_ptr
=
1
;
*
got_frame_ptr
=
1
;
*
(
AVFrame
*
)
data
=
s
->
frame
;
return
buf_size
;
return
buf_size
;
}
}
...
@@ -1769,7 +1771,6 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
...
@@ -1769,7 +1771,6 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
* Context for MP3On4 decoder
* Context for MP3On4 decoder
*/
*/
typedef
struct
MP3On4DecodeContext
{
typedef
struct
MP3On4DecodeContext
{
AVFrame
*
frame
;
int
frames
;
///< number of mp3 frames per block (number of mp3 decoder instances)
int
frames
;
///< number of mp3 frames per block (number of mp3 decoder instances)
int
syncword
;
///< syncword patch
int
syncword
;
///< syncword patch
const
uint8_t
*
coff
;
///< channel offsets in output buffer
const
uint8_t
*
coff
;
///< channel offsets in output buffer
...
@@ -1858,7 +1859,6 @@ static int decode_init_mp3on4(AVCodecContext * avctx)
...
@@ -1858,7 +1859,6 @@ static int decode_init_mp3on4(AVCodecContext * avctx)
// Put decoder context in place to make init_decode() happy
// Put decoder context in place to make init_decode() happy
avctx
->
priv_data
=
s
->
mp3decctx
[
0
];
avctx
->
priv_data
=
s
->
mp3decctx
[
0
];
decode_init
(
avctx
);
decode_init
(
avctx
);
s
->
frame
=
avctx
->
coded_frame
;
// Restore mp3on4 context pointer
// Restore mp3on4 context pointer
avctx
->
priv_data
=
s
;
avctx
->
priv_data
=
s
;
s
->
mp3decctx
[
0
]
->
adu_mode
=
1
;
// Set adu mode
s
->
mp3decctx
[
0
]
->
adu_mode
=
1
;
// Set adu mode
...
@@ -1895,6 +1895,7 @@ static void flush_mp3on4(AVCodecContext *avctx)
...
@@ -1895,6 +1895,7 @@ static void flush_mp3on4(AVCodecContext *avctx)
static
int
decode_frame_mp3on4
(
AVCodecContext
*
avctx
,
void
*
data
,
static
int
decode_frame_mp3on4
(
AVCodecContext
*
avctx
,
void
*
data
,
int
*
got_frame_ptr
,
AVPacket
*
avpkt
)
int
*
got_frame_ptr
,
AVPacket
*
avpkt
)
{
{
AVFrame
*
frame
=
data
;
const
uint8_t
*
buf
=
avpkt
->
data
;
const
uint8_t
*
buf
=
avpkt
->
data
;
int
buf_size
=
avpkt
->
size
;
int
buf_size
=
avpkt
->
size
;
MP3On4DecodeContext
*
s
=
avctx
->
priv_data
;
MP3On4DecodeContext
*
s
=
avctx
->
priv_data
;
...
@@ -1906,12 +1907,12 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
...
@@ -1906,12 +1907,12 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
int
fr
,
ch
,
ret
;
int
fr
,
ch
,
ret
;
/* get output buffer */
/* get output buffer */
s
->
frame
->
nb_samples
=
MPA_FRAME_SIZE
;
frame
->
nb_samples
=
MPA_FRAME_SIZE
;
if
((
ret
=
ff_get_buffer
(
avctx
,
s
->
frame
))
<
0
)
{
if
((
ret
=
ff_get_buffer
(
avctx
,
frame
))
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"get_buffer() failed
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"get_buffer() failed
\n
"
);
return
ret
;
return
ret
;
}
}
out_samples
=
(
OUT_INT
**
)
s
->
frame
->
extended_data
;
out_samples
=
(
OUT_INT
**
)
frame
->
extended_data
;
// Discard too short frames
// Discard too short frames
if
(
buf_size
<
HEADER_SIZE
)
if
(
buf_size
<
HEADER_SIZE
)
...
@@ -1961,9 +1962,8 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
...
@@ -1961,9 +1962,8 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
/* update codec info */
/* update codec info */
avctx
->
sample_rate
=
s
->
mp3decctx
[
0
]
->
sample_rate
;
avctx
->
sample_rate
=
s
->
mp3decctx
[
0
]
->
sample_rate
;
s
->
frame
->
nb_samples
=
out_size
/
(
avctx
->
channels
*
sizeof
(
OUT_INT
));
frame
->
nb_samples
=
out_size
/
(
avctx
->
channels
*
sizeof
(
OUT_INT
));
*
got_frame_ptr
=
1
;
*
got_frame_ptr
=
1
;
*
(
AVFrame
*
)
data
=
*
s
->
frame
;
return
buf_size
;
return
buf_size
;
}
}
...
...
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