mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2025-10-06 17:29:08 +08:00
fftools/ffmpeg_dec: move decoding to a separate thread
This is only a preparatory step to a fully threaded architecture and does not yet make decoding truly parallel - the main thread will currently submit a packet and wait until it has been fully processed by the decoding thread before moving on. Decoder behavior as observed by the rest of the program should remain unchanged. That will change in future commits after encoders and filters are moved to threads and a thread-aware scheduler is added.
This commit is contained in:
@@ -728,6 +728,46 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void subtitle_free(void *opaque, uint8_t *data)
|
||||
{
|
||||
AVSubtitle *sub = (AVSubtitle*)data;
|
||||
avsubtitle_free(sub);
|
||||
av_free(sub);
|
||||
}
|
||||
|
||||
int subtitle_wrap_frame(AVFrame *frame, AVSubtitle *subtitle, int copy)
|
||||
{
|
||||
AVBufferRef *buf;
|
||||
AVSubtitle *sub;
|
||||
int ret;
|
||||
|
||||
if (copy) {
|
||||
sub = av_mallocz(sizeof(*sub));
|
||||
ret = sub ? copy_av_subtitle(sub, subtitle) : AVERROR(ENOMEM);
|
||||
if (ret < 0) {
|
||||
av_freep(&sub);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
sub = av_memdup(subtitle, sizeof(*subtitle));
|
||||
if (!sub)
|
||||
return AVERROR(ENOMEM);
|
||||
memset(subtitle, 0, sizeof(*subtitle));
|
||||
}
|
||||
|
||||
buf = av_buffer_create((uint8_t*)sub, sizeof(*sub),
|
||||
subtitle_free, NULL, 0);
|
||||
if (!buf) {
|
||||
avsubtitle_free(sub);
|
||||
av_freep(&sub);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
frame->buf[0] = buf;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts)
|
||||
{
|
||||
int ret = AVERROR_BUG;
|
||||
@@ -1038,30 +1078,11 @@ static void decode_flush(InputFile *ifile)
|
||||
{
|
||||
for (int i = 0; i < ifile->nb_streams; i++) {
|
||||
InputStream *ist = ifile->streams[i];
|
||||
int ret;
|
||||
|
||||
if (ist->discard)
|
||||
if (ist->discard || !ist->decoding_needed)
|
||||
continue;
|
||||
|
||||
do {
|
||||
ret = process_input_packet(ist, NULL, 1);
|
||||
} while (ret > 0);
|
||||
|
||||
if (ist->decoding_needed) {
|
||||
/* report last frame duration to the demuxer thread */
|
||||
if (ist->par->codec_type == AVMEDIA_TYPE_AUDIO) {
|
||||
LastFrameDuration dur;
|
||||
|
||||
dur.stream_idx = i;
|
||||
dur.duration = av_rescale_q(ist->nb_samples,
|
||||
(AVRational){ 1, ist->dec_ctx->sample_rate},
|
||||
ist->st->time_base);
|
||||
|
||||
av_thread_message_queue_send(ifile->audio_duration_queue, &dur, 0);
|
||||
}
|
||||
|
||||
avcodec_flush_buffers(ist->dec_ctx);
|
||||
}
|
||||
dec_packet(ist, NULL, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user