decoder/ffmpeg: don't copy the AVPacket in ffmpeg_send_packet()
Reduce some overhead. It is not necessary to copy the object.
This commit is contained in:
parent
f243f615ef
commit
70495aada1
@ -349,7 +349,7 @@ PtsToPcmFrame(uint64_t pts, const AVStream &stream,
|
|||||||
*/
|
*/
|
||||||
static DecoderCommand
|
static DecoderCommand
|
||||||
ffmpeg_send_packet(Decoder &decoder, InputStream &is,
|
ffmpeg_send_packet(Decoder &decoder, InputStream &is,
|
||||||
const AVPacket &packet,
|
AVPacket &&packet,
|
||||||
AVCodecContext &codec_context,
|
AVCodecContext &codec_context,
|
||||||
const AVStream &stream,
|
const AVStream &stream,
|
||||||
AVFrame *frame,
|
AVFrame *frame,
|
||||||
@ -370,17 +370,15 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is,
|
|||||||
time_from_ffmpeg(pts, stream.time_base));
|
time_from_ffmpeg(pts, stream.time_base));
|
||||||
}
|
}
|
||||||
|
|
||||||
AVPacket packet2 = packet;
|
|
||||||
|
|
||||||
uint8_t *output_buffer;
|
uint8_t *output_buffer;
|
||||||
|
|
||||||
DecoderCommand cmd = DecoderCommand::NONE;
|
DecoderCommand cmd = DecoderCommand::NONE;
|
||||||
while (packet2.size > 0 && cmd == DecoderCommand::NONE) {
|
while (packet.size > 0 && cmd == DecoderCommand::NONE) {
|
||||||
int audio_size = 0;
|
int audio_size = 0;
|
||||||
int got_frame = 0;
|
int got_frame = 0;
|
||||||
int len = avcodec_decode_audio4(&codec_context,
|
int len = avcodec_decode_audio4(&codec_context,
|
||||||
frame, &got_frame,
|
frame, &got_frame,
|
||||||
&packet2);
|
&packet);
|
||||||
if (len >= 0 && got_frame) {
|
if (len >= 0 && got_frame) {
|
||||||
audio_size = copy_interleave_frame(codec_context,
|
audio_size = copy_interleave_frame(codec_context,
|
||||||
*frame,
|
*frame,
|
||||||
@ -397,8 +395,8 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
packet2.data += len;
|
packet.data += len;
|
||||||
packet2.size -= len;
|
packet.size -= len;
|
||||||
|
|
||||||
if (audio_size <= 0)
|
if (audio_size <= 0)
|
||||||
continue;
|
continue;
|
||||||
@ -631,7 +629,8 @@ ffmpeg_decode(Decoder &decoder, InputStream &input)
|
|||||||
|
|
||||||
if (packet.stream_index == audio_stream) {
|
if (packet.stream_index == audio_stream) {
|
||||||
cmd = ffmpeg_send_packet(decoder, input,
|
cmd = ffmpeg_send_packet(decoder, input,
|
||||||
packet, *codec_context,
|
std::move(packet),
|
||||||
|
*codec_context,
|
||||||
*av_stream,
|
*av_stream,
|
||||||
frame,
|
frame,
|
||||||
min_frame, audio_format.GetFrameSize(),
|
min_frame, audio_format.GetFrameSize(),
|
||||||
|
Loading…
Reference in New Issue
Block a user