return 0;
}
-static int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* pkt, AVFrame* frame, scf_list_t* h)
+static int __ffmpeg_decode(simp_avio_t* io, AVCodecContext* dec_ctx, AVPacket* pkt, AVFrame* frame, scf_list_t* h, int* nb_vframes)
{
int ret = avcodec_send_packet(dec_ctx, pkt);
if (ret < 0) {
frame->pts = frame->best_effort_timestamp;
- simp_frame_t* f = simp_frame_alloc();
+ scf_logi("frame->pts: %ld, stream_index: %d\n", frame->pts, pkt->stream_index);
+
+ simp_frame_t* f = calloc(1, sizeof(simp_frame_t));
if (!f)
return -ENOMEM;
- ret = av_frame_copy(f->frame, frame);
- if (ret < 0)
- return ret;
+ f->frame = av_frame_clone(frame);
+ if (!f->frame)
+ return -ENOMEM;
pthread_mutex_lock(&io->mutex);
scf_list_add_tail(h, &f->list);
+
+ if (nb_vframes)
+ (*nb_vframes)++;
+
pthread_cond_signal(&io->cond);
pthread_mutex_unlock(&io->mutex);
}
while (!io->exit) {
+ if (io->nb_vframes > 10) {
+ pthread_mutex_lock(&io->mutex);
+ pthread_cond_wait(&io->cond, &io->mutex);
+ pthread_mutex_unlock(&io->mutex);
+ continue;
+ }
+
int ret = av_read_frame(priv->fmt_ctx, pkt);
if (ret < 0) {
scf_loge("av_read_frame error, ret: %s\n", av_err2str(ret));
continue;
}
- ret = __ffmpeg_decode(io, priv->adec_ctx, pkt, priv->aframe, &io->ain);
+ ret = __ffmpeg_decode(io, priv->adec_ctx, pkt, priv->aframe, &io->ain, NULL);
if (ret < 0) {
io->error = ret;
goto end;
continue;
}
- ret = __ffmpeg_decode(io, priv->vdec_ctx, pkt, priv->vframe, &io->vin);
+ ret = __ffmpeg_decode(io, priv->vdec_ctx, pkt, priv->vframe, &io->vin, &io->nb_vframes);
if (ret < 0) {
io->error = ret;
goto end;
scf_list_t* l;
while (!f->exit) {
+ scf_loge("\n");
+
+ usleep(100);
int64_t sys_time = gettime();
int vn = 0;
scf_list_del(&vf->list);
pthread_mutex_unlock(&io->mutex);
+ scf_logi("vf->pts: %ld, vtime: %ld, time: %ld\n", vf->frame->pts, vtime, time);
+
int ret = av_buffersrc_add_frame_flags(io->vbuffersrc_ctx, vf->frame, AV_BUFFERSRC_FLAG_KEEP_REF);
simp_frame_free(vf);
pthread_cond_signal(&io->cond);
pthread_mutex_unlock(&io->mutex);
}
+ scf_loge("\n");
}
if (io->aopen) {
+ scf_loge("\n");
pthread_mutex_lock(&io->mutex);
if (!scf_list_empty(&io->ain)) {
scf_list_del(&af->list);
pthread_mutex_unlock(&io->mutex);
+ scf_logi("af->pts: %ld, atime: %ld, time: %ld\n", af->frame->pts, atime, time);
+
int ret = av_buffersrc_add_frame_flags(io->abuffersrc_ctx, af->frame, AV_BUFFERSRC_FLAG_KEEP_REF);
simp_frame_free(af);
af = NULL;
}
while (1) {
+ scf_loge("\n");
int ret = av_buffersink_get_frame(f->vbuffersink_ctx, f->vframe);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
goto error;
}
+ scf_loge("\n");
pthread_mutex_lock(&io->mutex);
scf_list_add_tail(&io->vout, &vf->list);
pthread_cond_signal(&io->cond);
}
}
+ scf_loge("\n");
while (1) {
int ret = av_buffersink_get_frame(f->abuffersink_ctx, f->aframe);
goto error;
}
+ scf_loge("\n");
for (l = scf_list_head(&f->outputs); l != scf_list_sentinel(&f->outputs); l != scf_list_next(l)) {
io = scf_list_data(l, simp_avio_t, list);
goto error;
}
+ scf_loge("\n");
pthread_mutex_lock(&io->mutex);
scf_list_add_tail(&io->aout, &af->list);
pthread_cond_signal(&io->cond);