|
|
@@ -21,14 +21,12 @@ int packet_queue_init(PacketQueue* q)
|
|
|
if (!q->pkt_list)
|
|
|
return AVERROR(ENOMEM);
|
|
|
q->mutex = new QMutex();
|
|
|
- if (!q->mutex)
|
|
|
- {
|
|
|
+ if (!q->mutex) {
|
|
|
av_log(nullptr, AV_LOG_FATAL, "new QMutex() error.\n");
|
|
|
return AVERROR(ENOMEM);
|
|
|
}
|
|
|
q->cond = new QWaitCondition();
|
|
|
- if (!q->cond)
|
|
|
- {
|
|
|
+ if (!q->cond) {
|
|
|
av_log(nullptr, AV_LOG_FATAL, "new QWaitCondition() error.\n");
|
|
|
return AVERROR(ENOMEM);
|
|
|
}
|
|
|
@@ -85,16 +83,13 @@ int packet_queue_get(PacketQueue* q, AVPacket* pkt, int block, int* serial)
|
|
|
|
|
|
q->mutex->lock();
|
|
|
|
|
|
- for (;;)
|
|
|
- {
|
|
|
- if (q->abort_request)
|
|
|
- {
|
|
|
+ for (;;) {
|
|
|
+ if (q->abort_request) {
|
|
|
ret = -1;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if (av_fifo_read(q->pkt_list, &pkt1, 1) >= 0)
|
|
|
- {
|
|
|
+ if (av_fifo_read(q->pkt_list, &pkt1, 1) >= 0) {
|
|
|
q->nb_packets--;
|
|
|
q->size -= pkt1.pkt->size + sizeof(pkt1);
|
|
|
q->duration -= pkt1.pkt->duration;
|
|
|
@@ -104,14 +99,10 @@ int packet_queue_get(PacketQueue* q, AVPacket* pkt, int block, int* serial)
|
|
|
av_packet_free(&pkt1.pkt);
|
|
|
ret = 1;
|
|
|
break;
|
|
|
- }
|
|
|
- else if (!block)
|
|
|
- {
|
|
|
+ } else if (!block) {
|
|
|
ret = 0;
|
|
|
break;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
q->cond->wait(q->mutex);
|
|
|
}
|
|
|
}
|
|
|
@@ -123,9 +114,18 @@ void packet_queue_print(const PacketQueue* q, const AVPacket* pkt, const QString
|
|
|
{
|
|
|
qDebug("[%s]Queue:[%p](nb_packets:%d, size:%d, dur:%d, serial:%d), "
|
|
|
"pkt(pts:%lld,dts:%lld,size:%d,s_index:%d,dur:%lld,pos:%lld).",
|
|
|
- qUtf8Printable(prefix), q, q->nb_packets, q->size, q->duration,
|
|
|
- q->serial, pkt->pts, pkt->dts, pkt->size, pkt->stream_index,
|
|
|
- pkt->duration, pkt->pos);
|
|
|
+ qUtf8Printable(prefix),
|
|
|
+ q,
|
|
|
+ q->nb_packets,
|
|
|
+ q->size,
|
|
|
+ q->duration,
|
|
|
+ q->serial,
|
|
|
+ pkt->pts,
|
|
|
+ pkt->dts,
|
|
|
+ pkt->size,
|
|
|
+ pkt->stream_index,
|
|
|
+ pkt->duration,
|
|
|
+ pkt->pos);
|
|
|
}
|
|
|
|
|
|
int packet_queue_put(PacketQueue* q, AVPacket* pkt)
|
|
|
@@ -134,8 +134,7 @@ int packet_queue_put(PacketQueue* q, AVPacket* pkt)
|
|
|
int ret = -1;
|
|
|
|
|
|
pkt1 = av_packet_alloc();
|
|
|
- if (!pkt1)
|
|
|
- {
|
|
|
+ if (!pkt1) {
|
|
|
av_packet_unref(pkt);
|
|
|
return ret;
|
|
|
}
|
|
|
@@ -149,7 +148,7 @@ int packet_queue_put(PacketQueue* q, AVPacket* pkt)
|
|
|
av_packet_free(&pkt1);
|
|
|
|
|
|
#if PRINT_PACKETQUEUE_INFO
|
|
|
- // packet_queue_print(q, pkt, "packet_queue_put");
|
|
|
+ // packet_queue_print(q, pkt, "packet_queue_put");
|
|
|
#endif
|
|
|
return ret;
|
|
|
}
|
|
|
@@ -186,13 +185,11 @@ int frame_queue_init(FrameQueue* f, PacketQueue* pktq, int max_size, int keep_la
|
|
|
{
|
|
|
int i;
|
|
|
memset(f, 0, sizeof(FrameQueue));
|
|
|
- if (!(f->mutex = new QMutex()))
|
|
|
- {
|
|
|
+ if (!(f->mutex = new QMutex())) {
|
|
|
av_log(nullptr, AV_LOG_FATAL, "new QMutex() error!\n");
|
|
|
return AVERROR(ENOMEM);
|
|
|
}
|
|
|
- if (!(f->cond = new QWaitCondition()))
|
|
|
- {
|
|
|
+ if (!(f->cond = new QWaitCondition())) {
|
|
|
av_log(nullptr, AV_LOG_FATAL, "new QWaitCondition() error\n");
|
|
|
return AVERROR(ENOMEM);
|
|
|
}
|
|
|
@@ -208,8 +205,7 @@ int frame_queue_init(FrameQueue* f, PacketQueue* pktq, int max_size, int keep_la
|
|
|
void frame_queue_destory(FrameQueue* f)
|
|
|
{
|
|
|
int i;
|
|
|
- for (i = 0; i < f->max_size; i++)
|
|
|
- {
|
|
|
+ for (i = 0; i < f->max_size; i++) {
|
|
|
Frame* vp = &f->queue[i];
|
|
|
frame_queue_unref_item(vp);
|
|
|
av_frame_free(&vp->frame);
|
|
|
@@ -242,14 +238,16 @@ Frame* frame_queue_peek_next(FrameQueue* f)
|
|
|
return &f->queue[(f->rindex + f->rindex_shown + 1) % f->max_size];
|
|
|
}
|
|
|
|
|
|
-Frame* frame_queue_peek_last(FrameQueue* f) { return &f->queue[f->rindex]; }
|
|
|
+Frame* frame_queue_peek_last(FrameQueue* f)
|
|
|
+{
|
|
|
+ return &f->queue[f->rindex];
|
|
|
+}
|
|
|
|
|
|
Frame* frame_queue_peek_writable(FrameQueue* f)
|
|
|
{
|
|
|
/* wait until we have space to put a new frame */
|
|
|
f->mutex->lock();
|
|
|
- while (f->size >= f->max_size && !f->pktq->abort_request)
|
|
|
- {
|
|
|
+ while (f->size >= f->max_size && !f->pktq->abort_request) {
|
|
|
f->cond->wait(f->mutex);
|
|
|
}
|
|
|
f->mutex->unlock();
|
|
|
@@ -264,8 +262,7 @@ Frame* frame_queue_peek_readable(FrameQueue* f)
|
|
|
{
|
|
|
/* wait until we have a readable a new frame */
|
|
|
f->mutex->lock();
|
|
|
- while (f->size - f->rindex_shown <= 0 && !f->pktq->abort_request)
|
|
|
- {
|
|
|
+ while (f->size - f->rindex_shown <= 0 && !f->pktq->abort_request) {
|
|
|
f->cond->wait(f->mutex);
|
|
|
}
|
|
|
f->mutex->unlock();
|
|
|
@@ -288,8 +285,7 @@ void frame_queue_push(FrameQueue* f)
|
|
|
|
|
|
void frame_queue_next(FrameQueue* f)
|
|
|
{
|
|
|
- if (f->keep_last && !f->rindex_shown)
|
|
|
- {
|
|
|
+ if (f->keep_last && !f->rindex_shown) {
|
|
|
f->rindex_shown = 1;
|
|
|
return;
|
|
|
}
|
|
|
@@ -318,17 +314,24 @@ int64_t frame_queue_last_pos(FrameQueue* f)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-int queue_picture(VideoState* is, AVFrame* src_frame, double pts, double duration, int64_t pos, int serial)
|
|
|
+int queue_picture(
|
|
|
+ VideoState* is, AVFrame* src_frame, double pts, double duration, int64_t pos, int serial)
|
|
|
{
|
|
|
#if PRINT_PACKETQUEUE_INFO
|
|
|
// int64 lld, double lf
|
|
|
qDebug("queue picture, w:%d, h:%d, nb:%d, ft:%d(%s), kf:%d, pic_t:%d(%c), "
|
|
|
"pts:%lf, duration:%lf, pos:%lld, serial:%d",
|
|
|
- src_frame->width, src_frame->height, src_frame->nb_samples,
|
|
|
+ src_frame->width,
|
|
|
+ src_frame->height,
|
|
|
+ src_frame->nb_samples,
|
|
|
src_frame->format,
|
|
|
av_get_sample_fmt_name(AVSampleFormat(src_frame->format)),
|
|
|
- src_frame->key_frame, src_frame->pict_type,
|
|
|
- av_get_picture_type_char(src_frame->pict_type), pts, duration, pos,
|
|
|
+ src_frame->key_frame,
|
|
|
+ src_frame->pict_type,
|
|
|
+ av_get_picture_type_char(src_frame->pict_type),
|
|
|
+ pts,
|
|
|
+ duration,
|
|
|
+ pos,
|
|
|
serial);
|
|
|
#endif
|
|
|
|
|
|
@@ -361,27 +364,20 @@ int get_video_frame(VideoState* is, AVFrame* frame)
|
|
|
if ((got_picture = decoder_decode_frame(&is->viddec, frame, nullptr)) < 0)
|
|
|
return -1;
|
|
|
|
|
|
- if (got_picture)
|
|
|
- {
|
|
|
+ if (got_picture) {
|
|
|
double dpts = NAN;
|
|
|
|
|
|
if (frame->pts != AV_NOPTS_VALUE)
|
|
|
dpts = av_q2d(is->video_st->time_base) * frame->pts;
|
|
|
|
|
|
- frame->sample_aspect_ratio =
|
|
|
- av_guess_sample_aspect_ratio(is->ic, is->video_st, frame);
|
|
|
+ frame->sample_aspect_ratio = av_guess_sample_aspect_ratio(is->ic, is->video_st, frame);
|
|
|
|
|
|
- if (framedrop > 0 ||
|
|
|
- (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER))
|
|
|
- {
|
|
|
- if (frame->pts != AV_NOPTS_VALUE)
|
|
|
- {
|
|
|
+ if (framedrop > 0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) {
|
|
|
+ if (frame->pts != AV_NOPTS_VALUE) {
|
|
|
double diff = dpts - get_master_clock(is);
|
|
|
- if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD &&
|
|
|
- diff - is->frame_last_filter_delay < 0 &&
|
|
|
- is->viddec.pkt_serial == is->vidclk.serial &&
|
|
|
- is->videoq.nb_packets)
|
|
|
- {
|
|
|
+ if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD
|
|
|
+ && diff - is->frame_last_filter_delay < 0
|
|
|
+ && is->viddec.pkt_serial == is->vidclk.serial && is->videoq.nb_packets) {
|
|
|
is->frame_drops_early++;
|
|
|
av_frame_unref(frame);
|
|
|
got_picture = 0;
|
|
|
@@ -393,7 +389,10 @@ int get_video_frame(VideoState* is, AVFrame* frame)
|
|
|
return got_picture;
|
|
|
}
|
|
|
|
|
|
-int decoder_init(Decoder* d, AVCodecContext* avctx, PacketQueue* queue, QWaitCondition* empty_queue_cond)
|
|
|
+int decoder_init(Decoder* d,
|
|
|
+ AVCodecContext* avctx,
|
|
|
+ PacketQueue* queue,
|
|
|
+ QWaitCondition* empty_queue_cond)
|
|
|
{
|
|
|
memset(d, 0, sizeof(Decoder));
|
|
|
d->pkt = av_packet_alloc();
|
|
|
@@ -427,7 +426,8 @@ void decoder_abort(Decoder* d, FrameQueue* fq)
|
|
|
packet_queue_abort(d->queue);
|
|
|
frame_queue_signal(fq);
|
|
|
// SDL_WaitThread(d->decoder_tid, nullptr);
|
|
|
- ((QThread*)(d->decoder_tid))->wait();
|
|
|
+ // TODO: //
|
|
|
+ // ((ThreadBase*) (d->decoder_tid))->join();
|
|
|
d->decoder_tid = nullptr;
|
|
|
packet_queue_flush(d->queue);
|
|
|
}
|
|
|
@@ -436,50 +436,39 @@ int decoder_decode_frame(Decoder* d, AVFrame* frame, AVSubtitle* sub)
|
|
|
{
|
|
|
int ret = AVERROR(EAGAIN);
|
|
|
int decoder_reorder_pts = -1;
|
|
|
- for (;;)
|
|
|
- {
|
|
|
- if (d->queue->serial == d->pkt_serial)
|
|
|
- {
|
|
|
- do
|
|
|
- {
|
|
|
+ for (;;) {
|
|
|
+ if (d->queue->serial == d->pkt_serial) {
|
|
|
+ do {
|
|
|
if (d->queue->abort_request)
|
|
|
return -1;
|
|
|
|
|
|
- switch (d->avctx->codec_type)
|
|
|
- {
|
|
|
- case AVMEDIA_TYPE_VIDEO:
|
|
|
- ret = avcodec_receive_frame(d->avctx, frame);
|
|
|
- if (ret >= 0)
|
|
|
- {
|
|
|
- if (decoder_reorder_pts == -1)
|
|
|
- {
|
|
|
- frame->pts = frame->best_effort_timestamp;
|
|
|
- }
|
|
|
- else if (!decoder_reorder_pts)
|
|
|
- {
|
|
|
- frame->pts = frame->pkt_dts;
|
|
|
- }
|
|
|
+ switch (d->avctx->codec_type) {
|
|
|
+ case AVMEDIA_TYPE_VIDEO:
|
|
|
+ ret = avcodec_receive_frame(d->avctx, frame);
|
|
|
+ if (ret >= 0) {
|
|
|
+ if (decoder_reorder_pts == -1) {
|
|
|
+ frame->pts = frame->best_effort_timestamp;
|
|
|
+ } else if (!decoder_reorder_pts) {
|
|
|
+ frame->pts = frame->pkt_dts;
|
|
|
}
|
|
|
- break;
|
|
|
- case AVMEDIA_TYPE_AUDIO:
|
|
|
- ret = avcodec_receive_frame(d->avctx, frame);
|
|
|
- if (ret >= 0)
|
|
|
- {
|
|
|
- AVRational tb = AVRational{1, frame->sample_rate};
|
|
|
- if (frame->pts != AV_NOPTS_VALUE)
|
|
|
- frame->pts = av_rescale_q(frame->pts, d->avctx->pkt_timebase, tb);
|
|
|
- else if (d->next_pts != AV_NOPTS_VALUE)
|
|
|
- frame->pts = av_rescale_q(d->next_pts, d->next_pts_tb, tb);
|
|
|
- if (frame->pts != AV_NOPTS_VALUE)
|
|
|
- {
|
|
|
- d->next_pts = frame->pts + frame->nb_samples;
|
|
|
- d->next_pts_tb = tb;
|
|
|
- }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case AVMEDIA_TYPE_AUDIO:
|
|
|
+ ret = avcodec_receive_frame(d->avctx, frame);
|
|
|
+ if (ret >= 0) {
|
|
|
+ AVRational tb = AVRational{1, frame->sample_rate};
|
|
|
+ if (frame->pts != AV_NOPTS_VALUE)
|
|
|
+ frame->pts = av_rescale_q(frame->pts, d->avctx->pkt_timebase, tb);
|
|
|
+ else if (d->next_pts != AV_NOPTS_VALUE)
|
|
|
+ frame->pts = av_rescale_q(d->next_pts, d->next_pts_tb, tb);
|
|
|
+ if (frame->pts != AV_NOPTS_VALUE) {
|
|
|
+ d->next_pts = frame->pts + frame->nb_samples;
|
|
|
+ d->next_pts_tb = tb;
|
|
|
}
|
|
|
- break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
- if (ret == AVERROR_EOF)
|
|
|
- {
|
|
|
+ if (ret == AVERROR_EOF) {
|
|
|
d->finished = d->pkt_serial;
|
|
|
avcodec_flush_buffers(d->avctx);
|
|
|
return 0;
|
|
|
@@ -489,22 +478,17 @@ int decoder_decode_frame(Decoder* d, AVFrame* frame, AVSubtitle* sub)
|
|
|
} while (ret != AVERROR(EAGAIN));
|
|
|
}
|
|
|
|
|
|
- do
|
|
|
- {
|
|
|
+ do {
|
|
|
if (d->queue->nb_packets == 0)
|
|
|
d->empty_queue_cond->wakeAll();
|
|
|
|
|
|
- if (d->packet_pending)
|
|
|
- {
|
|
|
+ if (d->packet_pending) {
|
|
|
d->packet_pending = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
int old_serial = d->pkt_serial;
|
|
|
if (packet_queue_get(d->queue, d->pkt, 1, &d->pkt_serial) < 0)
|
|
|
return -1;
|
|
|
- if (old_serial != d->pkt_serial)
|
|
|
- {
|
|
|
+ if (old_serial != d->pkt_serial) {
|
|
|
avcodec_flush_buffers(d->avctx);
|
|
|
d->finished = 0;
|
|
|
d->next_pts = d->start_pts;
|
|
|
@@ -516,35 +500,26 @@ int decoder_decode_frame(Decoder* d, AVFrame* frame, AVSubtitle* sub)
|
|
|
av_packet_unref(d->pkt);
|
|
|
} while (1);
|
|
|
|
|
|
- if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE)
|
|
|
- {
|
|
|
+ if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
|
|
|
int got_frame = 0;
|
|
|
ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, d->pkt);
|
|
|
- if (ret < 0)
|
|
|
- {
|
|
|
+ if (ret < 0) {
|
|
|
ret = AVERROR(EAGAIN);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (got_frame && !d->pkt->data)
|
|
|
- {
|
|
|
+ } else {
|
|
|
+ if (got_frame && !d->pkt->data) {
|
|
|
d->packet_pending = 1;
|
|
|
}
|
|
|
ret = got_frame ? 0 : (d->pkt->data ? AVERROR(EAGAIN) : AVERROR_EOF);
|
|
|
}
|
|
|
av_packet_unref(d->pkt);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN))
|
|
|
- {
|
|
|
- av_log(d->avctx, AV_LOG_ERROR,
|
|
|
+ } else {
|
|
|
+ if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
|
|
|
+ av_log(d->avctx,
|
|
|
+ AV_LOG_ERROR,
|
|
|
"Receive_frame and send_packet both returned EAGAIN, which is "
|
|
|
"an API violation.\n");
|
|
|
d->packet_pending = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
av_packet_unref(d->pkt);
|
|
|
}
|
|
|
}
|
|
|
@@ -554,8 +529,7 @@ int decoder_decode_frame(Decoder* d, AVFrame* frame, AVSubtitle* sub)
|
|
|
void get_file_info(const char* filename, int64_t& duration)
|
|
|
{
|
|
|
AVFormatContext* pFormatCtx = avformat_alloc_context();
|
|
|
- if (avformat_open_input(&pFormatCtx, filename, NULL, NULL) == 0)
|
|
|
- {
|
|
|
+ if (avformat_open_input(&pFormatCtx, filename, NULL, NULL) == 0) {
|
|
|
if (pFormatCtx->duration < 0)
|
|
|
avformat_find_stream_info(pFormatCtx, NULL);
|
|
|
duration = pFormatCtx->duration;
|
|
|
@@ -565,7 +539,8 @@ void get_file_info(const char* filename, int64_t& duration)
|
|
|
avformat_free_context(pFormatCtx);
|
|
|
}
|
|
|
|
|
|
-void get_duration_time(const int64_t duration_us, int64_t& hours, int64_t& mins, int64_t& secs, int64_t& us)
|
|
|
+void get_duration_time(
|
|
|
+ const int64_t duration_us, int64_t& hours, int64_t& mins, int64_t& secs, int64_t& us)
|
|
|
{
|
|
|
int64_t duration = duration_us + (duration_us <= INT64_MAX - 5000 ? 5000 : 0);
|
|
|
duration = duration < 0 ? 0 : duration;
|
|
|
@@ -582,12 +557,9 @@ double get_clock(Clock* c)
|
|
|
{
|
|
|
if (*c->queue_serial != c->serial)
|
|
|
return NAN;
|
|
|
- if (c->paused)
|
|
|
- {
|
|
|
+ if (c->paused) {
|
|
|
return c->pts;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
double time = av_gettime_relative() / 1000000.0;
|
|
|
return c->pts_drift + time - (time - c->last_updated) * (1.0 - c->speed);
|
|
|
}
|
|
|
@@ -625,24 +597,21 @@ void sync_clock_to_slave(Clock* c, Clock* slave)
|
|
|
{
|
|
|
double clock = get_clock(c);
|
|
|
double slave_clock = get_clock(slave);
|
|
|
- if (!isnan(slave_clock) &&
|
|
|
- (isnan(clock) || fabs(clock - slave_clock) > AV_NOSYNC_THRESHOLD))
|
|
|
+ if (!isnan(slave_clock) && (isnan(clock) || fabs(clock - slave_clock) > AV_NOSYNC_THRESHOLD))
|
|
|
set_clock(c, slave_clock, slave->serial);
|
|
|
}
|
|
|
|
|
|
int stream_has_enough_packets(AVStream* st, int stream_id, PacketQueue* queue)
|
|
|
{
|
|
|
- return stream_id < 0 || queue->abort_request ||
|
|
|
- (st->disposition & AV_DISPOSITION_ATTACHED_PIC) ||
|
|
|
- queue->nb_packets > MIN_FRAMES &&
|
|
|
- (!queue->duration ||
|
|
|
- av_q2d(st->time_base) * queue->duration > 1.0);
|
|
|
+ return stream_id < 0 || queue->abort_request || (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
|
|
|
+ || queue->nb_packets > MIN_FRAMES
|
|
|
+ && (!queue->duration || av_q2d(st->time_base) * queue->duration > 1.0);
|
|
|
}
|
|
|
|
|
|
int is_realtime(AVFormatContext* s)
|
|
|
{
|
|
|
- if (!strcmp(s->iformat->name, "rtp") || !strcmp(s->iformat->name, "rtsp") ||
|
|
|
- !strcmp(s->iformat->name, "sdp"))
|
|
|
+ if (!strcmp(s->iformat->name, "rtp") || !strcmp(s->iformat->name, "rtsp")
|
|
|
+ || !strcmp(s->iformat->name, "sdp"))
|
|
|
return 1;
|
|
|
|
|
|
if (s->pb && (!strncmp(s->url, "rtp:", 4) || !strncmp(s->url, "udp:", 4)))
|
|
|
@@ -652,22 +621,17 @@ int is_realtime(AVFormatContext* s)
|
|
|
|
|
|
int get_master_sync_type(VideoState* is)
|
|
|
{
|
|
|
- if (is->av_sync_type == AV_SYNC_VIDEO_MASTER)
|
|
|
- {
|
|
|
+ if (is->av_sync_type == AV_SYNC_VIDEO_MASTER) {
|
|
|
if (is->video_st)
|
|
|
return AV_SYNC_VIDEO_MASTER;
|
|
|
else
|
|
|
return AV_SYNC_AUDIO_MASTER;
|
|
|
- }
|
|
|
- else if (is->av_sync_type == AV_SYNC_AUDIO_MASTER)
|
|
|
- {
|
|
|
+ } else if (is->av_sync_type == AV_SYNC_AUDIO_MASTER) {
|
|
|
if (is->audio_st)
|
|
|
return AV_SYNC_AUDIO_MASTER;
|
|
|
else
|
|
|
return AV_SYNC_EXTERNAL_CLOCK;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
return AV_SYNC_EXTERNAL_CLOCK;
|
|
|
}
|
|
|
}
|
|
|
@@ -677,56 +641,44 @@ double get_master_clock(VideoState* is)
|
|
|
{
|
|
|
double val;
|
|
|
|
|
|
- switch (get_master_sync_type(is))
|
|
|
- {
|
|
|
- case AV_SYNC_VIDEO_MASTER:
|
|
|
- val = get_clock(&is->vidclk);
|
|
|
- break;
|
|
|
- case AV_SYNC_AUDIO_MASTER:
|
|
|
- val = get_clock(&is->audclk);
|
|
|
- break;
|
|
|
- default:
|
|
|
- val = get_clock(&is->extclk);
|
|
|
- break;
|
|
|
+ switch (get_master_sync_type(is)) {
|
|
|
+ case AV_SYNC_VIDEO_MASTER:
|
|
|
+ val = get_clock(&is->vidclk);
|
|
|
+ break;
|
|
|
+ case AV_SYNC_AUDIO_MASTER:
|
|
|
+ val = get_clock(&is->audclk);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ val = get_clock(&is->extclk);
|
|
|
+ break;
|
|
|
}
|
|
|
return val;
|
|
|
}
|
|
|
|
|
|
void check_external_clock_speed(VideoState* is)
|
|
|
{
|
|
|
- if ((is->video_stream >= 0 &&
|
|
|
- is->videoq.nb_packets <= EXTERNAL_CLOCK_MIN_FRAMES) ||
|
|
|
- (is->audio_stream >= 0 &&
|
|
|
- is->audioq.nb_packets <= EXTERNAL_CLOCK_MIN_FRAMES))
|
|
|
- {
|
|
|
+ if ((is->video_stream >= 0 && is->videoq.nb_packets <= EXTERNAL_CLOCK_MIN_FRAMES)
|
|
|
+ || (is->audio_stream >= 0 && is->audioq.nb_packets <= EXTERNAL_CLOCK_MIN_FRAMES)) {
|
|
|
set_clock_speed(&is->extclk,
|
|
|
FFMAX(EXTERNAL_CLOCK_SPEED_MIN,
|
|
|
is->extclk.speed - EXTERNAL_CLOCK_SPEED_STEP));
|
|
|
- }
|
|
|
- else if ((is->video_stream < 0 ||
|
|
|
- is->videoq.nb_packets > EXTERNAL_CLOCK_MAX_FRAMES) &&
|
|
|
- (is->audio_stream < 0 ||
|
|
|
- is->audioq.nb_packets > EXTERNAL_CLOCK_MAX_FRAMES))
|
|
|
- {
|
|
|
+ } else if ((is->video_stream < 0 || is->videoq.nb_packets > EXTERNAL_CLOCK_MAX_FRAMES)
|
|
|
+ && (is->audio_stream < 0 || is->audioq.nb_packets > EXTERNAL_CLOCK_MAX_FRAMES)) {
|
|
|
set_clock_speed(&is->extclk,
|
|
|
FFMIN(EXTERNAL_CLOCK_SPEED_MAX,
|
|
|
is->extclk.speed + EXTERNAL_CLOCK_SPEED_STEP));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
double speed = is->extclk.speed;
|
|
|
if (speed != 1.0)
|
|
|
- set_clock_speed(&is->extclk, speed + EXTERNAL_CLOCK_SPEED_STEP *
|
|
|
- (1.0 - speed) /
|
|
|
- fabs(1.0 - speed));
|
|
|
+ set_clock_speed(&is->extclk,
|
|
|
+ speed + EXTERNAL_CLOCK_SPEED_STEP * (1.0 - speed) / fabs(1.0 - speed));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* seek in the stream */
|
|
|
void stream_seek(VideoState* is, int64_t pos, int64_t rel, int seek_by_bytes)
|
|
|
{
|
|
|
- if (!is->seek_req)
|
|
|
- {
|
|
|
+ if (!is->seek_req) {
|
|
|
is->seek_pos = pos;
|
|
|
is->seek_rel = rel;
|
|
|
is->seek_flags &= ~AVSEEK_FLAG_BYTE;
|
|
|
@@ -756,42 +708,36 @@ void stream_seek(VideoState* is, int64_t pos, int64_t rel, int seek_by_bytes)
|
|
|
|
|
|
void toggle_pause(VideoState* is, bool pause)
|
|
|
{
|
|
|
- if (is->paused)
|
|
|
- {
|
|
|
- is->frame_timer +=
|
|
|
- av_gettime_relative() / 1000000.0 - is->vidclk.last_updated;
|
|
|
- if (is->read_pause_return != AVERROR(ENOSYS))
|
|
|
- {
|
|
|
+ if (is->paused) {
|
|
|
+ is->frame_timer += av_gettime_relative() / 1000000.0 - is->vidclk.last_updated;
|
|
|
+ if (is->read_pause_return != AVERROR(ENOSYS)) {
|
|
|
is->vidclk.paused = 0;
|
|
|
}
|
|
|
set_clock(&is->vidclk, get_clock(&is->vidclk), is->vidclk.serial);
|
|
|
}
|
|
|
set_clock(&is->extclk, get_clock(&is->extclk), is->extclk.serial);
|
|
|
- is->paused = is->audclk.paused = is->vidclk.paused = is->extclk.paused =
|
|
|
- pause; // !is->paused;
|
|
|
+ is->paused = is->audclk.paused = is->vidclk.paused = is->extclk.paused = pause; // !is->paused;
|
|
|
is->step = 0;
|
|
|
}
|
|
|
|
|
|
void toggle_mute(VideoState* is, bool mute)
|
|
|
{
|
|
|
bool muted = !!is->muted;
|
|
|
- if (muted != mute)
|
|
|
- {
|
|
|
+ if (muted != mute) {
|
|
|
is->muted = mute;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void update_volume(VideoState* is, int sign, double step)
|
|
|
{
|
|
|
- double volume_level =
|
|
|
- is->audio_volume
|
|
|
- ? (20 * log(is->audio_volume / (double)SDL_MIX_MAXVOLUME) / log(10))
|
|
|
- : -1000.0;
|
|
|
- int new_volume =
|
|
|
- lrint(SDL_MIX_MAXVOLUME * pow(10.0, (volume_level + sign * step) / 20.0));
|
|
|
- is->audio_volume = av_clip(
|
|
|
- is->audio_volume == new_volume ? (is->audio_volume + sign) : new_volume,
|
|
|
- 0, SDL_MIX_MAXVOLUME);
|
|
|
+ double volume_level = is->audio_volume
|
|
|
+ ? (20 * log(is->audio_volume / (double) SDL_MIX_MAXVOLUME) / log(10))
|
|
|
+ : -1000.0;
|
|
|
+ int new_volume = lrint(SDL_MIX_MAXVOLUME * pow(10.0, (volume_level + sign * step) / 20.0));
|
|
|
+ is->audio_volume = av_clip(is->audio_volume == new_volume ? (is->audio_volume + sign)
|
|
|
+ : new_volume,
|
|
|
+ 0,
|
|
|
+ SDL_MIX_MAXVOLUME);
|
|
|
}
|
|
|
|
|
|
void step_to_next_frame(VideoState* is)
|
|
|
@@ -807,8 +753,7 @@ double compute_target_delay(double delay, VideoState* is)
|
|
|
double sync_threshold, diff = 0;
|
|
|
|
|
|
/* update delay to follow master synchronisation source */
|
|
|
- if (get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)
|
|
|
- {
|
|
|
+ if (get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER) {
|
|
|
/* if video is slave, we try to correct big delays by
|
|
|
duplicating or deleting a frame */
|
|
|
diff = get_clock(&is->vidclk) - get_master_clock(is);
|
|
|
@@ -816,10 +761,8 @@ double compute_target_delay(double delay, VideoState* is)
|
|
|
/* skip or repeat frame. We take into account the
|
|
|
delay to compute the threshold. I still don't know
|
|
|
if it is the best guess */
|
|
|
- sync_threshold =
|
|
|
- FFMAX(AV_SYNC_THRESHOLD_MIN, FFMIN(AV_SYNC_THRESHOLD_MAX, delay));
|
|
|
- if (!isnan(diff) && fabs(diff) < is->max_frame_duration)
|
|
|
- {
|
|
|
+ sync_threshold = FFMAX(AV_SYNC_THRESHOLD_MIN, FFMIN(AV_SYNC_THRESHOLD_MAX, delay));
|
|
|
+ if (!isnan(diff) && fabs(diff) < is->max_frame_duration) {
|
|
|
if (diff <= -sync_threshold)
|
|
|
delay = FFMAX(0, delay + diff);
|
|
|
else if (diff >= sync_threshold && delay > AV_SYNC_FRAMEDUP_THRESHOLD)
|
|
|
@@ -835,8 +778,7 @@ double compute_target_delay(double delay, VideoState* is)
|
|
|
|
|
|
double vp_duration(VideoState* is, Frame* vp, Frame* nextvp)
|
|
|
{
|
|
|
- if (vp->serial == nextvp->serial)
|
|
|
- {
|
|
|
+ if (vp->serial == nextvp->serial) {
|
|
|
double duration = nextvp->pts - vp->pts;
|
|
|
if (isnan(duration) || duration <= 0 || duration > is->max_frame_duration)
|
|
|
return vp->duration;
|
|
|
@@ -857,25 +799,36 @@ void update_video_pts(VideoState* is, double pts, int64_t pos, int serial)
|
|
|
#if PRINT_PACKETQUEUE_INFO
|
|
|
void print_state_info(VideoState* is)
|
|
|
{
|
|
|
- if (is)
|
|
|
- {
|
|
|
+ if (is) {
|
|
|
PacketQueue* pPacket = &is->videoq;
|
|
|
qDebug("[VideoState] V PacketQueue[%p](nb_packets:%d,size:%d,dur:%lld, "
|
|
|
"abort:%d, serial:%d)",
|
|
|
- pPacket, pPacket->nb_packets, pPacket->size, pPacket->duration,
|
|
|
- pPacket->abort_request, pPacket->serial);
|
|
|
+ pPacket,
|
|
|
+ pPacket->nb_packets,
|
|
|
+ pPacket->size,
|
|
|
+ pPacket->duration,
|
|
|
+ pPacket->abort_request,
|
|
|
+ pPacket->serial);
|
|
|
|
|
|
pPacket = &is->audioq;
|
|
|
qDebug("[VideoState] A PacketQueue[%p](nb_packets:%d,size:%d,dur:%lld, "
|
|
|
"abort:%d, serial:%d)",
|
|
|
- pPacket, pPacket->nb_packets, pPacket->size, pPacket->duration,
|
|
|
- pPacket->abort_request, pPacket->serial);
|
|
|
+ pPacket,
|
|
|
+ pPacket->nb_packets,
|
|
|
+ pPacket->size,
|
|
|
+ pPacket->duration,
|
|
|
+ pPacket->abort_request,
|
|
|
+ pPacket->serial);
|
|
|
|
|
|
pPacket = &is->subtitleq;
|
|
|
qDebug("[VideoState] S PacketQueue[%p](nb_packets:%d,size:%d,dur:%lld, "
|
|
|
"abort:%d, serial:%d)",
|
|
|
- pPacket, pPacket->nb_packets, pPacket->size, pPacket->duration,
|
|
|
- pPacket->abort_request, pPacket->serial);
|
|
|
+ pPacket,
|
|
|
+ pPacket->nb_packets,
|
|
|
+ pPacket->size,
|
|
|
+ pPacket->duration,
|
|
|
+ pPacket->abort_request,
|
|
|
+ pPacket->serial);
|
|
|
|
|
|
/*qDebug("[VideoState]FrameQueue(v:%p,a:%p,s:%p)",
|
|
|
&is->pictq, &is->sampq, &is->subpq);
|
|
|
@@ -900,23 +853,18 @@ void set_audio_playspeed(VideoState* is, double value)
|
|
|
|
|
|
const size_t len = 32;
|
|
|
if (!is->afilters)
|
|
|
- is->afilters = (char*)av_malloc(len);
|
|
|
+ is->afilters = (char*) av_malloc(len);
|
|
|
|
|
|
- if (value <= 0.5)
|
|
|
- {
|
|
|
+ if (value <= 0.5) {
|
|
|
snprintf(is->afilters, len, "atempo=0.5,");
|
|
|
char tmp[128];
|
|
|
snprintf(tmp, sizeof(tmp), "atempo=%lf", value / 0.5);
|
|
|
|
|
|
// strncat(is->afilters, tmp, len - strlen(is->afilters) - 1);
|
|
|
strncat_s(is->afilters, len, tmp, len - strlen(is->afilters) - 1);
|
|
|
- }
|
|
|
- else if (value <= 2.0)
|
|
|
- {
|
|
|
+ } else if (value <= 2.0) {
|
|
|
snprintf(is->afilters, len, "atempo=%lf", value);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
snprintf(is->afilters, len, "atempo=2.0,");
|
|
|
char tmp[128];
|
|
|
snprintf(tmp, sizeof(tmp), "atempo=%lf", value / 2.0);
|
|
|
@@ -940,7 +888,7 @@ void set_video_playspeed(VideoState* is)
|
|
|
|
|
|
size_t len = 32;
|
|
|
if (!is->vfilters)
|
|
|
- is->vfilters = (char*)av_malloc(len);
|
|
|
+ is->vfilters = (char*) av_malloc(len);
|
|
|
|
|
|
snprintf(is->vfilters, len, "setpts=%.4lf*PTS", 1.0 / speed);
|
|
|
|
|
|
@@ -949,8 +897,10 @@ void set_video_playspeed(VideoState* is)
|
|
|
qDebug("changing video filters to :%s", is->vfilters);
|
|
|
}
|
|
|
|
|
|
-int cmp_audio_fmts(enum AVSampleFormat fmt1, int64_t channel_count1,
|
|
|
- enum AVSampleFormat fmt2, int64_t channel_count2)
|
|
|
+int cmp_audio_fmts(enum AVSampleFormat fmt1,
|
|
|
+ int64_t channel_count1,
|
|
|
+ enum AVSampleFormat fmt2,
|
|
|
+ int64_t channel_count2)
|
|
|
{
|
|
|
/* If channel count == 1, planar and non-planar formats are the same */
|
|
|
if (channel_count1 == 1 && channel_count2 == 1)
|
|
|
@@ -965,18 +915,19 @@ int cmp_audio_fmts(enum AVSampleFormat fmt1, int64_t channel_count1,
|
|
|
//== channels) return channel_layout; else return 0;
|
|
|
//}
|
|
|
|
|
|
-int configure_filtergraph(AVFilterGraph* graph, const char* filtergraph, AVFilterContext* source_ctx, AVFilterContext* sink_ctx)
|
|
|
+int configure_filtergraph(AVFilterGraph* graph,
|
|
|
+ const char* filtergraph,
|
|
|
+ AVFilterContext* source_ctx,
|
|
|
+ AVFilterContext* sink_ctx)
|
|
|
{
|
|
|
int ret;
|
|
|
int nb_filters = graph->nb_filters;
|
|
|
AVFilterInOut *outputs = nullptr, *inputs = nullptr;
|
|
|
|
|
|
- if (filtergraph)
|
|
|
- {
|
|
|
+ if (filtergraph) {
|
|
|
outputs = avfilter_inout_alloc();
|
|
|
inputs = avfilter_inout_alloc();
|
|
|
- if (!outputs || !inputs)
|
|
|
- {
|
|
|
+ if (!outputs || !inputs) {
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
goto fail;
|
|
|
}
|
|
|
@@ -991,12 +942,9 @@ int configure_filtergraph(AVFilterGraph* graph, const char* filtergraph, AVFilte
|
|
|
inputs->pad_idx = 0;
|
|
|
inputs->next = nullptr;
|
|
|
|
|
|
- if ((ret = avfilter_graph_parse_ptr(graph, filtergraph, &inputs, &outputs,
|
|
|
- nullptr)) < 0)
|
|
|
+ if ((ret = avfilter_graph_parse_ptr(graph, filtergraph, &inputs, &outputs, nullptr)) < 0)
|
|
|
goto fail;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
if ((ret = avfilter_link(source_ctx, 0, sink_ctx, 0)) < 0)
|
|
|
goto fail;
|
|
|
}
|
|
|
@@ -1004,8 +952,7 @@ int configure_filtergraph(AVFilterGraph* graph, const char* filtergraph, AVFilte
|
|
|
/* Reorder the filters to ensure that inputs of the custom filters are merged
|
|
|
* first */
|
|
|
for (unsigned int i = 0; i < graph->nb_filters - nb_filters; i++)
|
|
|
- FFSWAP(AVFilterContext*, graph->filters[i],
|
|
|
- graph->filters[i + nb_filters]);
|
|
|
+ FFSWAP(AVFilterContext*, graph->filters[i], graph->filters[i + nb_filters]);
|
|
|
|
|
|
ret = avfilter_graph_config(graph, nullptr);
|
|
|
fail:
|
|
|
@@ -1016,8 +963,7 @@ fail:
|
|
|
|
|
|
int configure_audio_filters(VideoState* is, const char* afilters, int force_output_format)
|
|
|
{
|
|
|
- static const enum AVSampleFormat sample_fmts[] = {AV_SAMPLE_FMT_S16,
|
|
|
- AV_SAMPLE_FMT_NONE};
|
|
|
+ static const enum AVSampleFormat sample_fmts[] = {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE};
|
|
|
int sample_rates[2] = {0, -1};
|
|
|
// int64_t channel_layouts[2] = { 0, -1 };
|
|
|
// AVChannelLayout channel_layouts[2] = {};
|
|
|
@@ -1043,55 +989,66 @@ int configure_audio_filters(VideoState* is, const char* afilters, int force_outp
|
|
|
av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
|
|
|
av_channel_layout_describe_bprint(&is->audio_filter_src.ch_layout, &bp);
|
|
|
|
|
|
- snprintf(asrc_args, sizeof(asrc_args),
|
|
|
+ snprintf(asrc_args,
|
|
|
+ sizeof(asrc_args),
|
|
|
"sample_rate=%d:sample_fmt=%s:time_base=%d/%d:channel_layout=%s",
|
|
|
is->audio_filter_src.freq,
|
|
|
- av_get_sample_fmt_name(is->audio_filter_src.fmt), 1,
|
|
|
- is->audio_filter_src.freq, bp.str);
|
|
|
-
|
|
|
- ret = avfilter_graph_create_filter(
|
|
|
- &filt_asrc, avfilter_get_by_name("abuffer"), "ffplay_abuffer", asrc_args,
|
|
|
- nullptr, is->agraph);
|
|
|
+ av_get_sample_fmt_name(is->audio_filter_src.fmt),
|
|
|
+ 1,
|
|
|
+ is->audio_filter_src.freq,
|
|
|
+ bp.str);
|
|
|
+
|
|
|
+ ret = avfilter_graph_create_filter(&filt_asrc,
|
|
|
+ avfilter_get_by_name("abuffer"),
|
|
|
+ "ffplay_abuffer",
|
|
|
+ asrc_args,
|
|
|
+ nullptr,
|
|
|
+ is->agraph);
|
|
|
if (ret < 0)
|
|
|
goto end;
|
|
|
|
|
|
- ret = avfilter_graph_create_filter(
|
|
|
- &filt_asink, avfilter_get_by_name("abuffersink"), "ffplay_abuffersink",
|
|
|
- nullptr, nullptr, is->agraph);
|
|
|
+ ret = avfilter_graph_create_filter(&filt_asink,
|
|
|
+ avfilter_get_by_name("abuffersink"),
|
|
|
+ "ffplay_abuffersink",
|
|
|
+ nullptr,
|
|
|
+ nullptr,
|
|
|
+ is->agraph);
|
|
|
if (ret < 0)
|
|
|
goto end;
|
|
|
|
|
|
- if ((ret = av_opt_set_int_list(filt_asink, "sample_fmts", sample_fmts,
|
|
|
- AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) <
|
|
|
- 0)
|
|
|
+ if ((ret = av_opt_set_int_list(filt_asink,
|
|
|
+ "sample_fmts",
|
|
|
+ sample_fmts,
|
|
|
+ AV_SAMPLE_FMT_NONE,
|
|
|
+ AV_OPT_SEARCH_CHILDREN))
|
|
|
+ < 0)
|
|
|
goto end;
|
|
|
- if ((ret = av_opt_set_int(filt_asink, "all_channel_counts", 1,
|
|
|
- AV_OPT_SEARCH_CHILDREN)) < 0)
|
|
|
+ if ((ret = av_opt_set_int(filt_asink, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0)
|
|
|
goto end;
|
|
|
|
|
|
- if (force_output_format)
|
|
|
- {
|
|
|
+ if (force_output_format) {
|
|
|
sample_rates[0] = is->audio_filter_src.freq;
|
|
|
// channel_layouts[0] = is->audio_filter_src.channel_layout;
|
|
|
// channels[0] = is->audio_filter_src.channels;
|
|
|
- if ((ret = av_opt_set_int(filt_asink, "all_channel_counts", 0,
|
|
|
- AV_OPT_SEARCH_CHILDREN)) < 0)
|
|
|
+ if ((ret = av_opt_set_int(filt_asink, "all_channel_counts", 0, AV_OPT_SEARCH_CHILDREN)) < 0)
|
|
|
goto end;
|
|
|
|
|
|
- if ((ret = av_opt_set(filt_asink, "ch_layouts", bp.str,
|
|
|
- AV_OPT_SEARCH_CHILDREN)) < 0)
|
|
|
+ if ((ret = av_opt_set(filt_asink, "ch_layouts", bp.str, AV_OPT_SEARCH_CHILDREN)) < 0)
|
|
|
goto end;
|
|
|
/*if ((ret = av_opt_set_int_list(filt_asink, "channel_layouts",
|
|
|
channel_layouts, -1, AV_OPT_SEARCH_CHILDREN)) < 0) goto end;*/
|
|
|
/*if ((ret = av_opt_set_int_list(filt_asink, "channel_counts", channels, -1,
|
|
|
AV_OPT_SEARCH_CHILDREN)) < 0) goto end;*/
|
|
|
- if ((ret = av_opt_set_int_list(filt_asink, "sample_rates", sample_rates, -1,
|
|
|
- AV_OPT_SEARCH_CHILDREN)) < 0)
|
|
|
+ if ((ret = av_opt_set_int_list(filt_asink,
|
|
|
+ "sample_rates",
|
|
|
+ sample_rates,
|
|
|
+ -1,
|
|
|
+ AV_OPT_SEARCH_CHILDREN))
|
|
|
+ < 0)
|
|
|
goto end;
|
|
|
}
|
|
|
|
|
|
- if ((ret = configure_filtergraph(is->agraph, afilters, filt_asrc,
|
|
|
- filt_asink)) < 0)
|
|
|
+ if ((ret = configure_filtergraph(is->agraph, afilters, filt_asrc, filt_asink)) < 0)
|
|
|
goto end;
|
|
|
|
|
|
is->in_audio_filter = filt_asrc;
|
|
|
@@ -1104,14 +1061,16 @@ end:
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-int configure_video_filters(AVFilterGraph* graph, VideoState* is, const char* vfilters, AVFrame* frame)
|
|
|
+int configure_video_filters(AVFilterGraph* graph,
|
|
|
+ VideoState* is,
|
|
|
+ const char* vfilters,
|
|
|
+ AVFrame* frame)
|
|
|
{
|
|
|
enum AVPixelFormat pix_fmts[1]; // FF_ARRAY_ELEMS(sdl_texture_format_map)
|
|
|
// char sws_flags_str[512] = "";
|
|
|
char buffersrc_args[256];
|
|
|
int ret;
|
|
|
- AVFilterContext *filt_src = nullptr, *filt_out = nullptr,
|
|
|
- *last_filter = nullptr;
|
|
|
+ AVFilterContext *filt_src = nullptr, *filt_out = nullptr, *last_filter = nullptr;
|
|
|
AVCodecParameters* codecpar = is->video_st->codecpar;
|
|
|
AVRational fr = av_guess_frame_rate(is->ic, is->video_st, nullptr);
|
|
|
// const AVDictionaryEntry* e = nullptr;
|
|
|
@@ -1143,29 +1102,43 @@ int configure_video_filters(AVFilterGraph* graph, VideoState* is, const char* vf
|
|
|
|
|
|
graph->scale_sws_opts = av_strdup(sws_flags_str);*/
|
|
|
|
|
|
- snprintf(buffersrc_args, sizeof(buffersrc_args),
|
|
|
+ snprintf(buffersrc_args,
|
|
|
+ sizeof(buffersrc_args),
|
|
|
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
|
|
|
- frame->width, frame->height, frame->format,
|
|
|
- is->video_st->time_base.num, is->video_st->time_base.den,
|
|
|
+ frame->width,
|
|
|
+ frame->height,
|
|
|
+ frame->format,
|
|
|
+ is->video_st->time_base.num,
|
|
|
+ is->video_st->time_base.den,
|
|
|
codecpar->sample_aspect_ratio.num,
|
|
|
FFMAX(codecpar->sample_aspect_ratio.den, 1));
|
|
|
if (fr.num && fr.den)
|
|
|
- av_strlcatf(buffersrc_args, sizeof(buffersrc_args), ":frame_rate=%d/%d",
|
|
|
- fr.num, fr.den);
|
|
|
-
|
|
|
- if ((ret = avfilter_graph_create_filter(
|
|
|
- &filt_src, avfilter_get_by_name("buffer"), "ffplay_buffer",
|
|
|
- buffersrc_args, nullptr, graph)) < 0)
|
|
|
+ av_strlcatf(buffersrc_args, sizeof(buffersrc_args), ":frame_rate=%d/%d", fr.num, fr.den);
|
|
|
+
|
|
|
+ if ((ret = avfilter_graph_create_filter(&filt_src,
|
|
|
+ avfilter_get_by_name("buffer"),
|
|
|
+ "ffplay_buffer",
|
|
|
+ buffersrc_args,
|
|
|
+ nullptr,
|
|
|
+ graph))
|
|
|
+ < 0)
|
|
|
goto fail;
|
|
|
|
|
|
- ret = avfilter_graph_create_filter(
|
|
|
- &filt_out, avfilter_get_by_name("buffersink"), "ffplay_buffersink",
|
|
|
- nullptr, nullptr, graph);
|
|
|
+ ret = avfilter_graph_create_filter(&filt_out,
|
|
|
+ avfilter_get_by_name("buffersink"),
|
|
|
+ "ffplay_buffersink",
|
|
|
+ nullptr,
|
|
|
+ nullptr,
|
|
|
+ graph);
|
|
|
if (ret < 0)
|
|
|
goto fail;
|
|
|
|
|
|
- if ((ret = av_opt_set_int_list(filt_out, "pix_fmts", pix_fmts,
|
|
|
- AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0)
|
|
|
+ if ((ret = av_opt_set_int_list(filt_out,
|
|
|
+ "pix_fmts",
|
|
|
+ pix_fmts,
|
|
|
+ AV_PIX_FMT_NONE,
|
|
|
+ AV_OPT_SEARCH_CHILDREN))
|
|
|
+ < 0)
|
|
|
goto fail;
|
|
|
|
|
|
last_filter = filt_out;
|
|
|
@@ -1173,21 +1146,24 @@ int configure_video_filters(AVFilterGraph* graph, VideoState* is, const char* vf
|
|
|
#if 0
|
|
|
/* Note: this macro adds a filter before the lastly added filter, so the
|
|
|
* processing order of the filters is in reverse */
|
|
|
-#define INSERT_FILT(name, arg) \
|
|
|
- do \
|
|
|
- { \
|
|
|
- AVFilterContext* filt_ctx; \
|
|
|
- \
|
|
|
- ret = avfilter_graph_create_filter(&filt_ctx, avfilter_get_by_name(name), \
|
|
|
- "ffplay_" name, arg, nullptr, graph); \
|
|
|
- if (ret < 0) \
|
|
|
- goto fail; \
|
|
|
- \
|
|
|
- ret = avfilter_link(filt_ctx, 0, last_filter, 0); \
|
|
|
- if (ret < 0) \
|
|
|
- goto fail; \
|
|
|
- \
|
|
|
- last_filter = filt_ctx; \
|
|
|
+#define INSERT_FILT(name, arg) \
|
|
|
+ do { \
|
|
|
+ AVFilterContext* filt_ctx; \
|
|
|
+\
|
|
|
+ ret = avfilter_graph_create_filter(&filt_ctx, \
|
|
|
+ avfilter_get_by_name(name), \
|
|
|
+ "ffplay_" name, \
|
|
|
+ arg, \
|
|
|
+ nullptr, \
|
|
|
+ graph); \
|
|
|
+ if (ret < 0) \
|
|
|
+ goto fail; \
|
|
|
+\
|
|
|
+ ret = avfilter_link(filt_ctx, 0, last_filter, 0); \
|
|
|
+ if (ret < 0) \
|
|
|
+ goto fail; \
|
|
|
+\
|
|
|
+ last_filter = filt_ctx; \
|
|
|
} while (0)
|
|
|
|
|
|
if (autorotate) {
|