FFmpeg
Loading...
Searching...
No Matches
ffplay.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003 Fabrice Bellard
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file
23 * simple media player based on the FFmpeg libraries
24 */
25
26#include "config.h"
27#include "config_components.h"
28#include <math.h>
29#include <limits.h>
30#include <signal.h>
31#include <stdint.h>
32
34#include "libavutil/avstring.h"
37#include "libavutil/mem.h"
38#include "libavutil/pixdesc.h"
39#include "libavutil/dict.h"
40#include "libavutil/fifo.h"
42#include "libavutil/samplefmt.h"
43#include "libavutil/time.h"
44#include "libavutil/bprint.h"
45#include "libavcodec/bsf.h"
48#include "libswscale/swscale.h"
49#include "libavutil/opt.h"
50#include "libavutil/tx.h"
52
56
57#include <SDL.h>
58#include <SDL_thread.h>
59
60#include "cmdutils.h"
61#include "ffplay_dir.h"
62#include "ffplay_list.h"
63#include "ffplay_renderer.h"
64#include "opt_common.h"
65
66const char program_name[] = "ffplay";
67const int program_birth_year = 2003;
68
69#define MAX_QUEUE_SIZE (15 * 1024 * 1024)
70#define MIN_FRAMES 25
71#define EXTERNAL_CLOCK_MIN_FRAMES 2
72#define EXTERNAL_CLOCK_MAX_FRAMES 10
73
74/* Minimum SDL audio buffer size, in samples. */
75#define SDL_AUDIO_MIN_BUFFER_SIZE 512
76/* Calculate actual buffer size keeping in mind not cause too frequent audio callbacks */
77#define SDL_AUDIO_MAX_CALLBACKS_PER_SEC 30
78
79/* Step size for volume control in dB */
80#define SDL_VOLUME_STEP (0.75)
81
82/* no AV sync correction is done if below the minimum AV sync threshold */
83#define AV_SYNC_THRESHOLD_MIN 0.04
84/* AV sync correction is done if above the maximum AV sync threshold */
85#define AV_SYNC_THRESHOLD_MAX 0.1
86/* If a frame duration is longer than this, it will not be duplicated to compensate AV sync */
87#define AV_SYNC_FRAMEDUP_THRESHOLD 0.1
88/* no AV correction is done if too big error */
89#define AV_NOSYNC_THRESHOLD 10.0
90
91/* maximum audio speed change to get correct sync */
92#define SAMPLE_CORRECTION_PERCENT_MAX 10
93
94/* external clock speed adjustment constants for realtime sources based on buffer fullness */
95#define EXTERNAL_CLOCK_SPEED_MIN 0.900
96#define EXTERNAL_CLOCK_SPEED_MAX 1.010
97#define EXTERNAL_CLOCK_SPEED_STEP 0.001
98
99/* we use about AUDIO_DIFF_AVG_NB A-V differences to make the average */
100#define AUDIO_DIFF_AVG_NB 20
101
102/* polls for possible required screen refresh at least this often, should be less than 1/fps */
103#define REFRESH_RATE 0.01
104
105/* NOTE: the size must be big enough to compensate the hardware audio buffersize size */
106/* TODO: We assume that a decoded and resampled frame fits into this buffer */
107#define SAMPLE_ARRAY_SIZE (8 * 65536)
108
109#define CURSOR_HIDE_DELAY 1000000
110
111#define USE_ONEPASS_SUBTITLE_RENDER 1
112
117
128
129#define VIDEO_PICTURE_QUEUE_SIZE 3
130#define SUBPICTURE_QUEUE_SIZE 16
131#define SAMPLE_QUEUE_SIZE 9
132#define FRAME_QUEUE_SIZE FFMAX(SAMPLE_QUEUE_SIZE, FFMAX(VIDEO_PICTURE_QUEUE_SIZE, SUBPICTURE_QUEUE_SIZE))
133
141
142typedef struct Clock {
143 double pts; /* clock base */
144 double pts_drift; /* clock base minus time at which we updated the clock */
146 double speed;
147 int serial; /* clock is based on a packet with this serial */
149 int *queue_serial; /* pointer to the current packet queue serial, used for obsolete clock detection */
150} Clock;
151
152typedef struct FrameData {
154} FrameData;
155
156/* Common struct for handling all types of decoded data and allocated render buffers. */
157typedef struct Frame {
161 double pts; /* presentation timestamp for the frame */
162 double duration; /* estimated duration of the frame */
163 int64_t pos; /* byte position of the frame in the input file */
164 int width;
170} Frame;
171
184
190
195
202
203enum {
204 AV_SYNC_AUDIO_MASTER, /* default choice */
206 AV_SYNC_EXTERNAL_CLOCK, /* synchronize to an external clock */
207};
208
209typedef struct Decoder {
221 SDL_Thread *decoder_tid;
222} Decoder;
223
224typedef struct VideoState {
225 SDL_Thread *read_tid;
239
243
247
251
253
255
258 double audio_diff_cum; /* used for AV difference average computation */
265 uint8_t *audio_buf;
266 uint8_t *audio_buf1;
267 unsigned int audio_buf_size; /* in bytes */
268 unsigned int audio_buf1_size;
269 int audio_buf_index; /* in bytes */
272 int muted;
279
289 float *real_data;
291 int xpos;
294 SDL_Texture *vis_texture;
295 SDL_Texture *sub_texture;
296 SDL_Texture *vid_texture;
297 SDL_AudioDeviceID audio_dev;
299
303
310 double max_frame_duration; // maximum duration of a frame - above this, we consider the jump a timestamp discontinuity
312 int eof;
313
314 char *filename;
315 int id;
316 SDL_atomic_t replacement;
317 char *title;
320 int loop;
322 int step;
323
325 AVFilterContext *in_video_filter; // the first filter in the video chain
326 AVFilterContext *out_video_filter; // the last filter in the video chain
327 AVFilterContext *in_audio_filter; // the first filter in the audio chain
328 AVFilterContext *out_audio_filter; // the last filter in the audio chain
329 AVFilterGraph *agraph; // audio filter graph
330
332
334} VideoState;
335
336/* options specified by the user */
338static const char *input_filename;
339static const char *window_title;
340static int default_width = 640;
341static int default_height = 480;
342static int screen_width = 0;
343static int screen_height = 0;
344static int screen_left = SDL_WINDOWPOS_CENTERED;
345static int screen_top = SDL_WINDOWPOS_CENTERED;
346static int audio_disable;
347static int video_disable;
349static const char* wanted_stream_spec[AVMEDIA_TYPE_NB] = {0};
350static int seek_by_bytes = -1;
351static float seek_interval = 10;
353static int borderless;
354static int alwaysontop;
355static int startup_volume = 100;
356static int show_status = -1;
360static int fast = 0;
361static int genpts = 0;
362static int lowres = 0;
363static int decoder_reorder_pts = -1;
364static int autoexit;
367static int loop = 1;
368static int framedrop = -1;
369static int infinite_buffer = -1;
370static enum ShowMode show_mode = SHOW_MODE_NONE;
371static const char *audio_codec_name;
372static const char *subtitle_codec_name;
373static const char *video_codec_name;
374double rdftspeed = 0.02;
376static int cursor_hidden = 0;
378/* the key that pins the list when it is released, 0 for none */
379static SDL_Keycode list_key;
380/* whether the list shows the files of dir_list rather than the chapters of the stream playing */
383/* the directory dir_thread reads, taken over by the event loop once done is set */
384static struct {
385 char *path;
389 SDL_atomic_t abort;
391 int ret;
392 SDL_atomic_t done;
394static SDL_Thread *dir_thread;
395/* the stream chosen in the file list, paused until it can play and replace the one playing */
397static const char **vfilters_list = NULL;
398static int nb_vfilters = 0;
399static char *afilters = NULL;
400static int autorotate = 1;
401static int find_stream_info = 1;
402static int filter_nbthreads = 0;
403static int enable_vulkan = 0;
404static char *vulkan_params = NULL;
405static char *video_background = NULL;
406static const char *hwaccel = NULL;
407
408/* current context */
409static int is_full_screen;
410
411#define FF_QUIT_EVENT (SDL_USEREVENT + 2)
412/* a stream has a picture to show, has no video, no picture before the end of its video, or no room to buffer more */
413#define FF_READY_EVENT (SDL_USEREVENT + 3)
414
415static int last_stream_id;
416
417static volatile sig_atomic_t received_sigterm = 0;
418static volatile int received_nb_signals = 0;
419static int exit_status = 0;
420
421static SDL_Window *window;
422static SDL_Renderer *renderer;
424static SDL_RendererInfo renderer_info = {0};
425
427
432 { AV_PIX_FMT_RGB8, SDL_PIXELFORMAT_RGB332 },
433 { AV_PIX_FMT_RGB444, SDL_PIXELFORMAT_RGB444 },
434 { AV_PIX_FMT_RGB555, SDL_PIXELFORMAT_RGB555 },
435 { AV_PIX_FMT_BGR555, SDL_PIXELFORMAT_BGR555 },
436 { AV_PIX_FMT_RGB565, SDL_PIXELFORMAT_RGB565 },
437 { AV_PIX_FMT_BGR565, SDL_PIXELFORMAT_BGR565 },
438 { AV_PIX_FMT_RGB24, SDL_PIXELFORMAT_RGB24 },
439 { AV_PIX_FMT_BGR24, SDL_PIXELFORMAT_BGR24 },
440 { AV_PIX_FMT_0RGB32, SDL_PIXELFORMAT_RGB888 },
441 { AV_PIX_FMT_0BGR32, SDL_PIXELFORMAT_BGR888 },
442 { AV_PIX_FMT_NE(RGB0, 0BGR), SDL_PIXELFORMAT_RGBX8888 },
443 { AV_PIX_FMT_NE(BGR0, 0RGB), SDL_PIXELFORMAT_BGRX8888 },
444 { AV_PIX_FMT_RGB32, SDL_PIXELFORMAT_ARGB8888 },
445 { AV_PIX_FMT_RGB32_1, SDL_PIXELFORMAT_RGBA8888 },
446 { AV_PIX_FMT_BGR32, SDL_PIXELFORMAT_ABGR8888 },
447 { AV_PIX_FMT_BGR32_1, SDL_PIXELFORMAT_BGRA8888 },
448 { AV_PIX_FMT_YUV420P, SDL_PIXELFORMAT_IYUV },
449 { AV_PIX_FMT_YUYV422, SDL_PIXELFORMAT_YUY2 },
450 { AV_PIX_FMT_UYVY422, SDL_PIXELFORMAT_UYVY },
452
453static int opt_add_vfilter(void *optctx, const char *opt, const char *arg)
454{
456 if (ret < 0)
457 return ret;
458
460 if (!vfilters_list[nb_vfilters - 1])
461 return AVERROR(ENOMEM);
462
463 return 0;
464}
465
466static inline
467int cmp_audio_fmts(enum AVSampleFormat fmt1, int64_t channel_count1,
468 enum AVSampleFormat fmt2, int64_t channel_count2)
469{
470 /* If channel count == 1, planar and non-planar formats are the same */
471 if (channel_count1 == 1 && channel_count2 == 1)
473 else
474 return channel_count1 != channel_count2 || fmt1 != fmt2;
475}
476
478{
479 MyAVPacketList pkt1;
480 int ret;
481
482 if (q->abort_request)
483 return -1;
484
485
486 pkt1.pkt = pkt;
487 pkt1.serial = q->serial;
488
489 ret = av_fifo_write(q->pkt_list, &pkt1, 1);
490 if (ret < 0)
491 return ret;
492 q->nb_packets++;
493 q->size += pkt1.pkt->size + sizeof(pkt1);
494 q->duration += pkt1.pkt->duration;
495 /* XXX: should duplicate packet data in DV case */
496 SDL_CondSignal(q->cond);
497 return 0;
498}
499
501{
502 AVPacket *pkt1;
503 int ret;
504
505 pkt1 = av_packet_alloc();
506 if (!pkt1) {
508 return -1;
509 }
510 av_packet_move_ref(pkt1, pkt);
511
512 SDL_LockMutex(q->mutex);
513 ret = packet_queue_put_private(q, pkt1);
514 SDL_UnlockMutex(q->mutex);
515
516 if (ret < 0)
517 av_packet_free(&pkt1);
518
519 return ret;
520}
521
522static int packet_queue_put_nullpacket(PacketQueue *q, AVPacket *pkt, int stream_index)
523{
524 pkt->stream_index = stream_index;
525 return packet_queue_put(q, pkt);
526}
527
528/* packet queue handling */
530{
531 memset(q, 0, sizeof(PacketQueue));
533 if (!q->pkt_list)
534 return AVERROR(ENOMEM);
535 q->mutex = SDL_CreateMutex();
536 if (!q->mutex) {
537 av_log(NULL, AV_LOG_FATAL, "SDL_CreateMutex(): %s\n", SDL_GetError());
538 return AVERROR(ENOMEM);
539 }
540 q->cond = SDL_CreateCond();
541 if (!q->cond) {
542 av_log(NULL, AV_LOG_FATAL, "SDL_CreateCond(): %s\n", SDL_GetError());
543 return AVERROR(ENOMEM);
544 }
545 q->abort_request = 1;
546 return 0;
547}
548
550{
551 MyAVPacketList pkt1;
552
553 SDL_LockMutex(q->mutex);
554 while (av_fifo_read(q->pkt_list, &pkt1, 1) >= 0)
555 av_packet_free(&pkt1.pkt);
556 q->nb_packets = 0;
557 q->size = 0;
558 q->duration = 0;
559 q->serial++;
560 SDL_UnlockMutex(q->mutex);
561}
562
564{
567 SDL_DestroyMutex(q->mutex);
568 SDL_DestroyCond(q->cond);
569}
570
572{
573 SDL_LockMutex(q->mutex);
574
575 q->abort_request = 1;
576
577 SDL_CondSignal(q->cond);
578
579 SDL_UnlockMutex(q->mutex);
580}
581
583{
584 SDL_LockMutex(q->mutex);
585 q->abort_request = 0;
586 q->serial++;
587 SDL_UnlockMutex(q->mutex);
588}
589
590/* return < 0 if aborted, 0 if no packet and > 0 if packet. */
591static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int *serial)
592{
593 MyAVPacketList pkt1;
594 int ret;
595
596 SDL_LockMutex(q->mutex);
597
598 for (;;) {
599 if (q->abort_request) {
600 ret = -1;
601 break;
602 }
603
604 if (av_fifo_read(q->pkt_list, &pkt1, 1) >= 0) {
605 q->nb_packets--;
606 q->size -= pkt1.pkt->size + sizeof(pkt1);
607 q->duration -= pkt1.pkt->duration;
609 if (serial)
610 *serial = pkt1.serial;
611 av_packet_free(&pkt1.pkt);
612 ret = 1;
613 break;
614 } else if (!block) {
615 ret = 0;
616 break;
617 } else {
618 SDL_CondWait(q->cond, q->mutex);
619 }
620 }
621 SDL_UnlockMutex(q->mutex);
622 return ret;
623}
624
625static int decoder_init(Decoder *d, AVCodecContext *avctx, PacketQueue *queue, SDL_cond *empty_queue_cond) {
626 memset(d, 0, sizeof(Decoder));
627 d->pkt = av_packet_alloc();
628 if (!d->pkt)
629 return AVERROR(ENOMEM);
630 d->avctx = avctx;
631 d->queue = queue;
632 d->empty_queue_cond = empty_queue_cond;
634 d->pkt_serial = -1;
636 return 0;
637}
638
640 int ret = AVERROR(EAGAIN);
641
642 for (;;) {
643 if (d->queue->serial == d->pkt_serial) {
644 do {
645 if (d->queue->abort_request)
646 return -1;
647
648 switch (d->avctx->codec_type) {
651 if (ret >= 0) {
652 if (decoder_reorder_pts == -1) {
653 frame->pts = frame->best_effort_timestamp;
654 } else if (!decoder_reorder_pts) {
655 frame->pts = frame->pkt_dts;
656 }
657 }
658 break;
661 if (ret >= 0) {
662 AVRational tb = (AVRational){1, frame->sample_rate};
663 if (frame->pts != AV_NOPTS_VALUE)
664 frame->pts = av_rescale_q(frame->pts, d->avctx->pkt_timebase, tb);
665 else if (d->next_pts != AV_NOPTS_VALUE)
666 frame->pts = av_rescale_q(d->next_pts, d->next_pts_tb, tb);
667 if (frame->pts != AV_NOPTS_VALUE) {
668 d->next_pts = frame->pts + frame->nb_samples;
669 d->next_pts_tb = tb;
670 }
671 }
672 break;
673 }
674 if (ret == AVERROR_EOF) {
675 d->finished = d->pkt_serial;
677 return 0;
678 }
679 if (ret >= 0)
680 return 1;
681 } while (ret != AVERROR(EAGAIN));
682 }
683
684 do {
685 if (d->queue->nb_packets == 0)
686 SDL_CondSignal(d->empty_queue_cond);
687 if (d->packet_pending) {
688 d->packet_pending = 0;
689 } else {
690 int old_serial = d->pkt_serial;
691 if (packet_queue_get(d->queue, d->pkt, 1, &d->pkt_serial) < 0)
692 return -1;
693 if (old_serial != d->pkt_serial) {
695 d->finished = 0;
696 d->next_pts = d->start_pts;
698 }
699 }
700 if (d->queue->serial == d->pkt_serial)
701 break;
703 } while (1);
704
706 int got_frame = 0;
707 ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, d->pkt);
708 if (ret < 0) {
709 ret = AVERROR(EAGAIN);
710 } else {
711 if (got_frame && !d->pkt->data) {
712 d->packet_pending = 1;
713 }
714 ret = got_frame ? 0 : (d->pkt->data ? AVERROR(EAGAIN) : AVERROR_EOF);
715 }
717 } else {
718 if (d->pkt->buf && !d->pkt->opaque_ref) {
719 FrameData *fd;
720
721 d->pkt->opaque_ref = av_buffer_allocz(sizeof(*fd));
722 if (!d->pkt->opaque_ref)
723 return AVERROR(ENOMEM);
724 fd = (FrameData*)d->pkt->opaque_ref->data;
725 fd->pkt_pos = d->pkt->pos;
726 }
727
728 if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
729 av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet both returned EAGAIN, which is an API violation.\n");
730 d->packet_pending = 1;
731 } else {
733 }
734 }
735 }
736}
737
738static void decoder_destroy(Decoder *d) {
739 av_packet_free(&d->pkt);
741}
742
744{
746 avsubtitle_free(&vp->sub);
747}
748
749static int frame_queue_init(FrameQueue *f, PacketQueue *pktq, int max_size, int keep_last)
750{
751 int i;
752 memset(f, 0, sizeof(FrameQueue));
753 if (!(f->mutex = SDL_CreateMutex())) {
754 av_log(NULL, AV_LOG_FATAL, "SDL_CreateMutex(): %s\n", SDL_GetError());
755 return AVERROR(ENOMEM);
756 }
757 if (!(f->cond = SDL_CreateCond())) {
758 av_log(NULL, AV_LOG_FATAL, "SDL_CreateCond(): %s\n", SDL_GetError());
759 return AVERROR(ENOMEM);
760 }
761 f->pktq = pktq;
762 f->max_size = FFMIN(max_size, FRAME_QUEUE_SIZE);
763 f->keep_last = !!keep_last;
764 for (i = 0; i < f->max_size; i++)
765 if (!(f->queue[i].frame = av_frame_alloc()))
766 return AVERROR(ENOMEM);
767 return 0;
768}
769
771{
772 int i;
773 for (i = 0; i < f->max_size; i++) {
774 Frame *vp = &f->queue[i];
776 av_frame_free(&vp->frame);
777 }
778 SDL_DestroyMutex(f->mutex);
779 SDL_DestroyCond(f->cond);
780}
781
783{
784 SDL_LockMutex(f->mutex);
785 SDL_CondSignal(f->cond);
786 SDL_UnlockMutex(f->mutex);
787}
788
790{
791 return &f->queue[(f->rindex + f->rindex_shown) % f->max_size];
792}
793
795{
796 return &f->queue[(f->rindex + f->rindex_shown + 1) % f->max_size];
797}
798
800{
801 return &f->queue[f->rindex];
802}
803
805{
806 /* wait until we have space to put a new frame */
807 SDL_LockMutex(f->mutex);
808 while (f->size >= f->max_size &&
809 !f->pktq->abort_request) {
810 SDL_CondWait(f->cond, f->mutex);
811 }
812 SDL_UnlockMutex(f->mutex);
813
814 if (f->pktq->abort_request)
815 return NULL;
816
817 return &f->queue[f->windex];
818}
819
821{
822 /* wait until we have a readable a new frame */
823 SDL_LockMutex(f->mutex);
824 while (f->size - f->rindex_shown <= 0 &&
825 !f->pktq->abort_request) {
826 SDL_CondWait(f->cond, f->mutex);
827 }
828 SDL_UnlockMutex(f->mutex);
829
830 if (f->pktq->abort_request)
831 return NULL;
832
833 return &f->queue[(f->rindex + f->rindex_shown) % f->max_size];
834}
835
837{
838 if (++f->windex == f->max_size)
839 f->windex = 0;
840 SDL_LockMutex(f->mutex);
841 f->size++;
842 SDL_CondSignal(f->cond);
843 SDL_UnlockMutex(f->mutex);
844}
845
847{
848 if (f->keep_last && !f->rindex_shown) {
849 f->rindex_shown = 1;
850 return;
851 }
852 frame_queue_unref_item(&f->queue[f->rindex]);
853 if (++f->rindex == f->max_size)
854 f->rindex = 0;
855 SDL_LockMutex(f->mutex);
856 f->size--;
857 SDL_CondSignal(f->cond);
858 SDL_UnlockMutex(f->mutex);
859}
860
861/* return the number of undisplayed frames in the queue */
863{
864 return f->size - f->rindex_shown;
865}
866
867/* return last shown position */
869{
870 Frame *fp = &f->queue[f->rindex];
871 if (f->rindex_shown && fp->serial == f->pktq->serial)
872 return fp->pos;
873 else
874 return -1;
875}
876
877static void decoder_abort(Decoder *d, FrameQueue *fq)
878{
881 SDL_WaitThread(d->decoder_tid, NULL);
882 d->decoder_tid = NULL;
884}
885
886static inline void fill_rectangle(int x, int y, int w, int h)
887{
888 SDL_Rect rect;
889 rect.x = x;
890 rect.y = y;
891 rect.w = w;
892 rect.h = h;
893 if (w && h)
894 SDL_RenderFillRect(renderer, &rect);
895}
896
897static int realloc_texture(SDL_Texture **texture, Uint32 new_format, int new_width, int new_height, SDL_BlendMode blendmode, int init_texture)
898{
899 Uint32 format;
900 int access, w, h;
901 if (!*texture || SDL_QueryTexture(*texture, &format, &access, &w, &h) < 0 || new_width != w || new_height != h || new_format != format) {
902 void *pixels;
903 int pitch;
904 if (*texture)
905 SDL_DestroyTexture(*texture);
906 if (!(*texture = SDL_CreateTexture(renderer, new_format, SDL_TEXTUREACCESS_STREAMING, new_width, new_height)))
907 return -1;
908 if (SDL_SetTextureBlendMode(*texture, blendmode) < 0)
909 return -1;
910 if (init_texture) {
911 if (SDL_LockTexture(*texture, NULL, &pixels, &pitch) < 0)
912 return -1;
913 memset(pixels, 0, pitch * new_height);
914 SDL_UnlockTexture(*texture);
915 }
916 av_log(NULL, AV_LOG_VERBOSE, "Created %dx%d texture with %s.\n", new_width, new_height, SDL_GetPixelFormatName(new_format));
917 }
918 return 0;
919}
920
921static void calculate_display_rect(SDL_Rect *rect,
922 int scr_xleft, int scr_ytop, int scr_width, int scr_height,
923 int pic_width, int pic_height, AVRational pic_sar)
924{
925 AVRational aspect_ratio = pic_sar;
926 int64_t width, height, x, y;
927
928 if (av_cmp_q(aspect_ratio, av_make_q(0, 1)) <= 0)
929 aspect_ratio = av_make_q(1, 1);
930
931 aspect_ratio = av_mul_q(aspect_ratio, av_make_q(pic_width, pic_height));
932
933 /* XXX: we suppose the screen has a 1.0 pixel ratio */
934 height = scr_height;
935 width = av_rescale(height, aspect_ratio.num, aspect_ratio.den) & ~1;
936 if (width > scr_width) {
937 width = scr_width;
938 height = av_rescale(width, aspect_ratio.den, aspect_ratio.num) & ~1;
939 }
940 x = (scr_width - width) / 2;
941 y = (scr_height - height) / 2;
942 rect->x = scr_xleft + x;
943 rect->y = scr_ytop + y;
944 rect->w = FFMAX((int)width, 1);
945 rect->h = FFMAX((int)height, 1);
946}
947
948static void get_sdl_pix_fmt_and_blendmode(int format, Uint32 *sdl_pix_fmt, SDL_BlendMode *sdl_blendmode)
949{
950 int i;
951 *sdl_blendmode = SDL_BLENDMODE_NONE;
952 *sdl_pix_fmt = SDL_PIXELFORMAT_UNKNOWN;
953 if (format == AV_PIX_FMT_RGB32 ||
957 *sdl_blendmode = SDL_BLENDMODE_BLEND;
958 for (i = 0; i < FF_ARRAY_ELEMS(sdl_texture_format_map); i++) {
960 *sdl_pix_fmt = sdl_texture_format_map[i].texture_fmt;
961 return;
962 }
963 }
964}
965
966static int upload_texture(SDL_Texture **tex, AVFrame *frame)
967{
968 int ret = 0;
969 Uint32 sdl_pix_fmt;
970 SDL_BlendMode sdl_blendmode;
971 get_sdl_pix_fmt_and_blendmode(frame->format, &sdl_pix_fmt, &sdl_blendmode);
972 if (realloc_texture(tex, sdl_pix_fmt == SDL_PIXELFORMAT_UNKNOWN ? SDL_PIXELFORMAT_ARGB8888 : sdl_pix_fmt, frame->width, frame->height, sdl_blendmode, 0) < 0)
973 return -1;
974 switch (sdl_pix_fmt) {
975 case SDL_PIXELFORMAT_IYUV:
976 if (frame->linesize[0] > 0 && frame->linesize[1] > 0 && frame->linesize[2] > 0) {
977 ret = SDL_UpdateYUVTexture(*tex, NULL, frame->data[0], frame->linesize[0],
978 frame->data[1], frame->linesize[1],
979 frame->data[2], frame->linesize[2]);
980 } else if (frame->linesize[0] < 0 && frame->linesize[1] < 0 && frame->linesize[2] < 0) {
981 ret = SDL_UpdateYUVTexture(*tex, NULL, frame->data[0] + frame->linesize[0] * (frame->height - 1), -frame->linesize[0],
982 frame->data[1] + frame->linesize[1] * (AV_CEIL_RSHIFT(frame->height, 1) - 1), -frame->linesize[1],
983 frame->data[2] + frame->linesize[2] * (AV_CEIL_RSHIFT(frame->height, 1) - 1), -frame->linesize[2]);
984 } else {
985 av_log(NULL, AV_LOG_ERROR, "Mixed negative and positive linesizes are not supported.\n");
986 return -1;
987 }
988 break;
989 default:
990 if (frame->linesize[0] < 0) {
991 ret = SDL_UpdateTexture(*tex, NULL, frame->data[0] + frame->linesize[0] * (frame->height - 1), -frame->linesize[0]);
992 } else {
993 ret = SDL_UpdateTexture(*tex, NULL, frame->data[0], frame->linesize[0]);
994 }
995 break;
996 }
997 return ret;
998}
999
1005
1010
1012{
1013#if SDL_VERSION_ATLEAST(2,0,8)
1014 SDL_YUV_CONVERSION_MODE mode = SDL_YUV_CONVERSION_AUTOMATIC;
1015 if (frame && (frame->format == AV_PIX_FMT_YUV420P || frame->format == AV_PIX_FMT_YUYV422 || frame->format == AV_PIX_FMT_UYVY422)) {
1016 if (frame->color_range == AVCOL_RANGE_JPEG)
1017 mode = SDL_YUV_CONVERSION_JPEG;
1018 else if (frame->colorspace == AVCOL_SPC_BT709)
1019 mode = SDL_YUV_CONVERSION_BT709;
1020 else if (frame->colorspace == AVCOL_SPC_BT470BG || frame->colorspace == AVCOL_SPC_SMPTE170M)
1021 mode = SDL_YUV_CONVERSION_BT601;
1022 }
1023 SDL_SetYUVConversionMode(mode); /* FIXME: no support for linear transfer */
1024#endif
1025}
1026
1028{
1029 const int tile_size = VIDEO_BACKGROUND_TILE_SIZE;
1030 SDL_Rect *rect = &is->render_params.target_rect;
1031 SDL_BlendMode blendMode;
1032
1033 if (!SDL_GetTextureBlendMode(is->vid_texture, &blendMode) && blendMode == SDL_BLENDMODE_BLEND) {
1034 switch (is->render_params.video_background_type) {
1036 SDL_SetRenderDrawColor(renderer, 237, 237, 237, 255);
1037 fill_rectangle(rect->x, rect->y, rect->w, rect->h);
1038 SDL_SetRenderDrawColor(renderer, 222, 222, 222, 255);
1039 for (int x = 0; x < rect->w; x += tile_size * 2)
1040 fill_rectangle(rect->x + x, rect->y, FFMIN(tile_size, rect->w - x), rect->h);
1041 for (int y = 0; y < rect->h; y += tile_size * 2)
1042 fill_rectangle(rect->x, rect->y + y, rect->w, FFMIN(tile_size, rect->h - y));
1043 SDL_SetRenderDrawColor(renderer, 237, 237, 237, 255);
1044 for (int y = 0; y < rect->h; y += tile_size * 2) {
1045 int h = FFMIN(tile_size, rect->h - y);
1046 for (int x = 0; x < rect->w; x += tile_size * 2)
1047 fill_rectangle(x + rect->x, y + rect->y, FFMIN(tile_size, rect->w - x), h);
1048 }
1049 break;
1051 const uint8_t *c = is->render_params.video_background_color;
1052 SDL_SetRenderDrawColor(renderer, c[0], c[1], c[2], c[3]);
1053 fill_rectangle(rect->x, rect->y, rect->w, rect->h);
1054 break;
1055 }
1057 SDL_SetTextureBlendMode(is->vid_texture, SDL_BLENDMODE_NONE);
1058 break;
1059 }
1060 }
1061}
1062
1063static int current_chapter(VideoState *is);
1064static void file_list_listed(VideoState *is);
1065static void seek_chapter(VideoState *is, int i);
1066
1067static const char *chapter_tag(const AVChapter *chapter, const char *key)
1068{
1069 const AVDictionaryEntry *tag = av_dict_get(chapter->metadata, key, NULL, 0);
1070
1071 return tag ? tag->value : NULL;
1072}
1073
1074/* shows the chapter list with the chapter selected, or with the selection kept when no row shows it */
1075static int chapter_list_show(VideoState *is, int chapter)
1076{
1077 ListEntry *entries = av_calloc(is->ic->nb_chapters, sizeof(*entries));
1078 int ret;
1079
1080 if (!entries)
1081 return AVERROR(ENOMEM);
1082 for (int i = 0; i < is->ic->nb_chapters; i++) {
1083 const AVChapter *ch = is->ic->chapters[i];
1084
1085 entries[i] = (ListEntry){ chapter_tag(ch, "title"), chapter_tag(ch, "artist"), -1, ch->metadata };
1086 if (ch->end != AV_NOPTS_VALUE && ch->end > ch->start && (uint64_t)ch->end - ch->start <= INT64_MAX)
1087 entries[i].length = av_rescale_q(ch->end - ch->start, ch->time_base, AV_TIME_BASE_Q);
1088 }
1089 if (list_shows_files)
1091 ret = list_view_show(list, entries, is->ic->nb_chapters, chapter);
1092 av_free(entries);
1093 if (ret >= 0)
1094 list_shows_files = 0;
1095 return ret;
1096}
1097
1099{
1101 list_view_pin(list, 1);
1102}
1103
1105{
1106 Frame *vp;
1107 Frame *sp = NULL;
1108 SDL_Rect *rect = &is->render_params.target_rect;
1109
1110 vp = frame_queue_peek_last(&is->pictq);
1111 calculate_display_rect(rect, is->xleft, is->ytop, is->width, is->height, vp->width, vp->height, vp->sar);
1112 if (vk_renderer) {
1113 vk_renderer_display(vk_renderer, vp->frame, &is->render_params);
1114 return;
1115 }
1116
1117 if (is->subtitle_st) {
1118 if (frame_queue_nb_remaining(&is->subpq) > 0) {
1119 sp = frame_queue_peek(&is->subpq);
1120
1121 if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 1000)) {
1122 if (!sp->uploaded) {
1123 uint8_t* pixels[4];
1124 int pitch[4];
1125 int i;
1126 if (!sp->width || !sp->height) {
1127 sp->width = vp->width;
1128 sp->height = vp->height;
1129 }
1130 if (realloc_texture(&is->sub_texture, SDL_PIXELFORMAT_ARGB8888, sp->width, sp->height, SDL_BLENDMODE_BLEND, 1) < 0)
1131 return;
1132
1133 for (i = 0; i < sp->sub.num_rects; i++) {
1134 AVSubtitleRect *sub_rect = sp->sub.rects[i];
1135
1136 sub_rect->x = av_clip(sub_rect->x, 0, sp->width );
1137 sub_rect->y = av_clip(sub_rect->y, 0, sp->height);
1138 sub_rect->w = av_clip(sub_rect->w, 0, sp->width - sub_rect->x);
1139 sub_rect->h = av_clip(sub_rect->h, 0, sp->height - sub_rect->y);
1140
1141 is->sub_convert_ctx = sws_getCachedContext(is->sub_convert_ctx,
1142 sub_rect->w, sub_rect->h, AV_PIX_FMT_PAL8,
1143 sub_rect->w, sub_rect->h, AV_PIX_FMT_BGRA,
1144 0, NULL, NULL, NULL);
1145 if (!is->sub_convert_ctx) {
1146 av_log(NULL, AV_LOG_FATAL, "Cannot initialize the conversion context\n");
1147 return;
1148 }
1149 if (!SDL_LockTexture(is->sub_texture, (SDL_Rect *)sub_rect, (void **)pixels, pitch)) {
1150 sws_scale(is->sub_convert_ctx, (const uint8_t * const *)sub_rect->data, sub_rect->linesize,
1151 0, sub_rect->h, pixels, pitch);
1152 SDL_UnlockTexture(is->sub_texture);
1153 }
1154 }
1155 sp->uploaded = 1;
1156 }
1157 } else
1158 sp = NULL;
1159 }
1160 }
1161
1163
1164 if (!vp->uploaded) {
1165 if (upload_texture(&is->vid_texture, vp->frame) < 0) {
1167 return;
1168 }
1169 vp->uploaded = 1;
1170 vp->flip_v = vp->frame->linesize[0] < 0;
1171 }
1172
1174 SDL_RenderCopyEx(renderer, is->vid_texture, NULL, rect, 0, NULL, vp->flip_v ? SDL_FLIP_VERTICAL : 0);
1176 if (sp) {
1177#if USE_ONEPASS_SUBTITLE_RENDER
1178 SDL_RenderCopy(renderer, is->sub_texture, NULL, rect);
1179#else
1180 int i;
1181 double xratio = (double)rect->w / (double)sp->width;
1182 double yratio = (double)rect->h / (double)sp->height;
1183 for (i = 0; i < sp->sub.num_rects; i++) {
1184 SDL_Rect *sub_rect = (SDL_Rect*)sp->sub.rects[i];
1185 SDL_Rect target = {.x = rect.x + sub_rect->x * xratio,
1186 .y = rect.y + sub_rect->y * yratio,
1187 .w = sub_rect->w * xratio,
1188 .h = sub_rect->h * yratio};
1189 SDL_RenderCopy(renderer, is->sub_texture, sub_rect, &target);
1190 }
1191#endif
1192 }
1193}
1194
1195static inline int compute_mod(int a, int b)
1196{
1197 return a < 0 ? a%b + b : a%b;
1198}
1199
1201{
1202 int i, i_start, x, y1, y, ys, delay, n, nb_display_channels;
1203 int ch, channels, h, h2;
1204 int64_t time_diff;
1205 int rdft_bits, nb_freq;
1206
1207 for (rdft_bits = 1; (1 << rdft_bits) < 2 * s->height; rdft_bits++)
1208 ;
1209 nb_freq = 1 << (rdft_bits - 1);
1210
1211 /* compute display index : center on currently output samples */
1212 channels = s->audio_tgt.ch_layout.nb_channels;
1213 nb_display_channels = channels;
1214 if (!s->paused) {
1215 int data_used= s->show_mode == SHOW_MODE_WAVES ? s->width : (2*nb_freq);
1216 n = 2 * channels;
1217 delay = s->audio_write_buf_size;
1218 delay /= n;
1219
1220 /* to be more precise, we take into account the time spent since
1221 the last buffer computation */
1222 if (s->audio_callback_time) {
1223 time_diff = av_gettime_relative() - s->audio_callback_time;
1224 delay -= (time_diff * s->audio_tgt.freq) / 1000000;
1225 }
1226
1227 delay += 2 * data_used;
1228 if (delay < data_used)
1229 delay = data_used;
1230
1231 i_start= x = compute_mod(s->sample_array_index - delay * channels, SAMPLE_ARRAY_SIZE);
1232 if (s->show_mode == SHOW_MODE_WAVES) {
1233 h = INT_MIN;
1234 for (i = 0; i < 1000; i += channels) {
1235 int idx = (SAMPLE_ARRAY_SIZE + x - i) % SAMPLE_ARRAY_SIZE;
1236 int a = s->sample_array[idx];
1237 int b = s->sample_array[(idx + 4 * channels) % SAMPLE_ARRAY_SIZE];
1238 int c = s->sample_array[(idx + 5 * channels) % SAMPLE_ARRAY_SIZE];
1239 int d = s->sample_array[(idx + 9 * channels) % SAMPLE_ARRAY_SIZE];
1240 int score = a - d;
1241 if (h < score && (b ^ c) < 0) {
1242 h = score;
1243 i_start = idx;
1244 }
1245 }
1246 }
1247
1248 s->last_i_start = i_start;
1249 } else {
1250 i_start = s->last_i_start;
1251 }
1252
1253 if (s->show_mode == SHOW_MODE_WAVES) {
1254 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
1255
1256 /* total height for one channel */
1257 h = s->height / nb_display_channels;
1258 /* graph height / 2 */
1259 h2 = (h * 9) / 20;
1260 for (ch = 0; ch < nb_display_channels; ch++) {
1261 i = i_start + ch;
1262 y1 = s->ytop + ch * h + (h / 2); /* position of center line */
1263 for (x = 0; x < s->width; x++) {
1264 y = (s->sample_array[i] * h2) >> 15;
1265 if (y < 0) {
1266 y = -y;
1267 ys = y1 - y;
1268 } else {
1269 ys = y1;
1270 }
1271 fill_rectangle(s->xleft + x, ys, 1, y);
1272 i += channels;
1273 if (i >= SAMPLE_ARRAY_SIZE)
1275 }
1276 }
1277
1278 SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
1279
1280 for (ch = 1; ch < nb_display_channels; ch++) {
1281 y = s->ytop + ch * h;
1282 fill_rectangle(s->xleft, y, s->width, 1);
1283 }
1284 } else {
1285 int err = 0;
1286 if (realloc_texture(&s->vis_texture, SDL_PIXELFORMAT_ARGB8888, s->width, s->height, SDL_BLENDMODE_NONE, 1) < 0)
1287 return;
1288
1289 if (s->xpos >= s->width)
1290 s->xpos = 0;
1291 nb_display_channels= FFMIN(nb_display_channels, 2);
1292 if (rdft_bits != s->rdft_bits) {
1293 const float rdft_scale = 1.0;
1294 av_tx_uninit(&s->rdft);
1295 av_freep(&s->real_data);
1296 av_freep(&s->rdft_data);
1297 s->rdft_bits = rdft_bits;
1298 s->real_data = av_malloc_array(nb_freq, 4 *sizeof(*s->real_data));
1299 s->rdft_data = av_malloc_array(nb_freq + 1, 2 *sizeof(*s->rdft_data));
1300 err = av_tx_init(&s->rdft, &s->rdft_fn, AV_TX_FLOAT_RDFT,
1301 0, 1 << rdft_bits, &rdft_scale, 0);
1302 }
1303 if (err < 0 || !s->rdft_data) {
1304 av_log(NULL, AV_LOG_ERROR, "Failed to allocate buffers for RDFT, switching to waves display\n");
1305 s->show_mode = SHOW_MODE_WAVES;
1306 } else {
1307 float *data_in[2];
1308 AVComplexFloat *data[2];
1309 SDL_Rect rect = {.x = s->xpos, .y = 0, .w = 1, .h = s->height};
1310 uint32_t *pixels;
1311 int pitch;
1312 for (ch = 0; ch < nb_display_channels; ch++) {
1313 data_in[ch] = s->real_data + 2 * nb_freq * ch;
1314 data[ch] = s->rdft_data + nb_freq * ch;
1315 i = i_start + ch;
1316 for (x = 0; x < 2 * nb_freq; x++) {
1317 double w = (x-nb_freq) * (1.0 / nb_freq);
1318 data_in[ch][x] = s->sample_array[i] * (1.0 - w * w);
1319 i += channels;
1320 if (i >= SAMPLE_ARRAY_SIZE)
1322 }
1323 s->rdft_fn(s->rdft, data[ch], data_in[ch], sizeof(float));
1324 }
1325 /* Least efficient way to do this, we should of course
1326 * directly access it but it is more than fast enough. */
1327 if (!SDL_LockTexture(s->vis_texture, &rect, (void **)&pixels, &pitch)) {
1328 double w = 1 / sqrt(nb_freq);
1329 int show_phase = s->show_mode == SHOW_MODE_PHASE && nb_display_channels == 2;
1330 pitch >>= 2;
1331 pixels += pitch * s->height;
1332 for (y = 0; y < s->height; y++) {
1333 int a = sqrt(w * sqrt(data[0][y].re * data[0][y].re + data[0][y].im * data[0][y].im));
1334 int b = (nb_display_channels == 2 ) ? sqrt(w * hypot(data[1][y].re, data[1][y].im))
1335 : a;
1336 a = FFMIN(a, 255);
1337 b = FFMIN(b, 255);
1338 int blue = (a+b) >> 1;
1339 if (show_phase) {
1340 /* phase(left) - phase(right) in units of pi */
1341 double phase = atan2(data[0][y].im * data[1][y].re - data[0][y].re * data[1][y].im,
1342 data[0][y].re * data[1][y].re + data[0][y].im * data[1][y].im) / M_PI;
1343 int phase_shift = lrint(phase * FFMIN(a, b));
1344 a = FFMIN(a - phase_shift / 2, 255);
1345 b = FFMIN(b - phase_shift / 2, 255);
1346 blue = FFMIN(blue + phase_shift, 255);
1347 }
1348 pixels -= pitch;
1349 *pixels = (a << 16) + (b << 8) + blue;
1350 }
1351 SDL_UnlockTexture(s->vis_texture);
1352 }
1353 SDL_RenderCopy(renderer, s->vis_texture, NULL, NULL);
1354 }
1355 if (!s->paused)
1356 s->xpos++;
1357 }
1358}
1359
1360static void uninit_bsf_graph(AVFormatContext *ic, int stream_index)
1361{
1362 FormatContext *ici = ic->opaque;
1363 Stream *sti;
1364 StreamGroup *stgi;
1365
1366 if (stream_index >= ici->nb_streams)
1367 return;
1368
1369 sti = ici->streams[stream_index];
1370 sti->filter = NULL;
1371
1372 stgi = sti->group;
1373 if (stgi) {
1374 av_bsf_graph_free(&stgi->graph);
1375 stgi->sink = NULL;
1376
1377 for (int i = 0; i < stgi->stg->nb_entries; i++) {
1378 ici->streams[stgi->stg->entries[i]->stream->index]->filter = NULL;
1379 ici->streams[stgi->stg->entries[i]->stream->index]->group = NULL;
1380 }
1381 }
1382 sti->group = stgi;
1383}
1384
1385static void stream_component_close(VideoState *is, int stream_index)
1386{
1387 AVFormatContext *ic = is->ic;
1388
1389 AVCodecParameters *codecpar;
1390
1391 if (stream_index < 0 || stream_index >= ic->nb_streams)
1392 return;
1393 codecpar = ic->streams[stream_index]->codecpar;
1394
1395 uninit_bsf_graph(ic, stream_index);
1396
1397 switch (codecpar->codec_type) {
1398 case AVMEDIA_TYPE_AUDIO:
1399 decoder_abort(&is->auddec, &is->sampq);
1400 avfilter_graph_free(&is->agraph);
1401 SDL_CloseAudioDevice(is->audio_dev);
1402 is->audio_dev = 0;
1403 decoder_destroy(&is->auddec);
1404 swr_free(&is->swr_ctx);
1405 av_freep(&is->audio_buf1);
1406 is->audio_buf1_size = 0;
1407 is->audio_buf = NULL;
1408
1409 if (is->rdft) {
1410 av_tx_uninit(&is->rdft);
1411 av_freep(&is->real_data);
1412 av_freep(&is->rdft_data);
1413 is->rdft = NULL;
1414 is->rdft_bits = 0;
1415 }
1416 break;
1417 case AVMEDIA_TYPE_VIDEO:
1418 decoder_abort(&is->viddec, &is->pictq);
1419 decoder_destroy(&is->viddec);
1420 break;
1422 decoder_abort(&is->subdec, &is->subpq);
1423 decoder_destroy(&is->subdec);
1424 break;
1425 default:
1426 break;
1427 }
1428
1429 ic->streams[stream_index]->discard = AVDISCARD_ALL;
1430 switch (codecpar->codec_type) {
1431 case AVMEDIA_TYPE_AUDIO:
1432 is->audio_st = NULL;
1433 is->audio_stream = -1;
1434 break;
1435 case AVMEDIA_TYPE_VIDEO:
1436 is->video_st = NULL;
1437 is->video_stream = -1;
1438 break;
1440 is->subtitle_st = NULL;
1441 is->subtitle_stream = -1;
1442 break;
1443 default:
1444 break;
1445 }
1446}
1447
1449{
1450 /* XXX: use a special url_shutdown call to abort parse cleanly */
1451 is->abort_request = 1;
1452 SDL_WaitThread(is->read_tid, NULL);
1453
1454 /* close each stream */
1455 if (is->audio_stream >= 0)
1456 stream_component_close(is, is->audio_stream);
1457 if (is->video_stream >= 0)
1458 stream_component_close(is, is->video_stream);
1459 if (is->subtitle_stream >= 0)
1460 stream_component_close(is, is->subtitle_stream);
1461
1462 if (is->ic) {
1463 FormatContext *ici = is->ic->opaque;
1464 for (int i = 0; i < ici->nb_streams; i++)
1465 av_freep(&ici->streams[i]);
1466 av_freep(&ici->streams);
1467 for (int i = 0; i < ici->nb_stream_groups; i++)
1468 av_freep(&ici->stream_groups[i]);
1469 av_freep(&ici->stream_groups);
1470 av_freep(&is->ic->opaque);
1471 }
1472
1474
1475 packet_queue_destroy(&is->videoq);
1476 packet_queue_destroy(&is->audioq);
1477 packet_queue_destroy(&is->subtitleq);
1478
1479 /* free all pictures */
1480 frame_queue_destroy(&is->pictq);
1481 frame_queue_destroy(&is->sampq);
1482 frame_queue_destroy(&is->subpq);
1483 SDL_DestroyCond(is->continue_read_thread);
1484 sws_freeContext(is->sub_convert_ctx);
1485 av_free(is->filename);
1486 av_free(is->title);
1487 if (is->vis_texture)
1488 SDL_DestroyTexture(is->vis_texture);
1489 if (is->vid_texture)
1490 SDL_DestroyTexture(is->vid_texture);
1491 if (is->sub_texture)
1492 SDL_DestroyTexture(is->sub_texture);
1493 av_free(is);
1494}
1495
1496static void do_exit(VideoState *is)
1497{
1498 if (is) {
1500 }
1501 if (next_stream)
1503 SDL_AtomicSet(&dir_request.abort, 1);
1504 for (int waited = 0; dir_thread && !SDL_AtomicGet(&dir_request.done) && waited < 2000; waited += 10)
1505 SDL_Delay(10);
1506 if (dir_thread && !SDL_AtomicGet(&dir_request.done)) {
1507 /* a protocol that does not take the interrupt keeps the thread and its request until the process ends */
1508 SDL_DetachThread(dir_thread);
1509 } else {
1510 if (dir_thread)
1511 SDL_WaitThread(dir_thread, NULL);
1513 av_freep(&dir_request.path);
1514 av_dict_free(&dir_request.options);
1515 }
1517 if (renderer)
1518 SDL_DestroyRenderer(renderer);
1519 if (vk_renderer)
1521 if (window)
1522 SDL_DestroyWindow(window);
1523 uninit_opts();
1524 for (int i = 0; i < nb_vfilters; i++)
1533 if (show_status)
1534 printf("\n");
1535 SDL_Quit();
1536 av_log(NULL, AV_LOG_QUIET, "%s", "");
1537 exit(exit_status);
1538}
1539
1540static void sigterm_handler(int sig)
1541{
1543 if (++received_nb_signals > 3)
1544 exit(123);
1545}
1546
1548{
1549 SDL_Rect rect;
1550 int max_width = screen_width ? screen_width : INT_MAX;
1551 int max_height = screen_height ? screen_height : INT_MAX;
1552 if (max_width == INT_MAX && max_height == INT_MAX)
1553 max_height = height;
1554 calculate_display_rect(&rect, 0, 0, max_width, max_height, width, height, sar);
1557}
1558
1560{
1561 int w,h;
1562
1565
1566 SDL_SetWindowTitle(window, window_title ? window_title : is->title ? is->title : is->filename);
1567
1568 SDL_SetWindowSize(window, w, h);
1569 SDL_SetWindowPosition(window, screen_left, screen_top);
1570 if (is_full_screen)
1571 SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
1572 SDL_ShowWindow(window);
1573
1574 is->width = w;
1575 is->height = h;
1577
1578 return 0;
1579}
1580
1581/* display the current picture, if any */
1583{
1584 if (!is->width)
1585 video_open(is);
1586
1587 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
1588 SDL_RenderClear(renderer);
1589 if (is->audio_st && is->show_mode != SHOW_MODE_VIDEO)
1591 else if (is->video_st && is->pictq.rindex_shown)
1594 SDL_RenderPresent(renderer);
1595}
1596
1597static double get_clock(Clock *c)
1598{
1599 if (*c->queue_serial != c->serial)
1600 return NAN;
1601 if (c->paused) {
1602 return c->pts;
1603 } else {
1604 double time = av_gettime_relative() / 1000000.0;
1605 return c->pts_drift + time - (time - c->last_updated) * (1.0 - c->speed);
1606 }
1607}
1608
1609static void set_clock_at(Clock *c, double pts, int serial, double time)
1610{
1611 c->pts = pts;
1612 c->last_updated = time;
1613 c->pts_drift = c->pts - time;
1614 c->serial = serial;
1615}
1616
1617static void set_clock(Clock *c, double pts, int serial)
1618{
1619 double time = av_gettime_relative() / 1000000.0;
1620 set_clock_at(c, pts, serial, time);
1621}
1622
1623static void set_clock_speed(Clock *c, double speed)
1624{
1625 set_clock(c, get_clock(c), c->serial);
1626 c->speed = speed;
1627}
1628
1629static void init_clock(Clock *c, int *queue_serial)
1630{
1631 c->speed = 1.0;
1632 c->paused = 0;
1633 c->queue_serial = queue_serial;
1634 set_clock(c, NAN, -1);
1635}
1636
1637static void sync_clock_to_slave(Clock *c, Clock *slave)
1638{
1639 double clock = get_clock(c);
1640 double slave_clock = get_clock(slave);
1641 if (!isnan(slave_clock) && (isnan(clock) || fabs(clock - slave_clock) > AV_NOSYNC_THRESHOLD))
1642 set_clock(c, slave_clock, slave->serial);
1643}
1644
1646 if (is->av_sync_type == AV_SYNC_VIDEO_MASTER) {
1647 if (is->video_st)
1648 return AV_SYNC_VIDEO_MASTER;
1649 else
1650 return AV_SYNC_AUDIO_MASTER;
1651 } else if (is->av_sync_type == AV_SYNC_AUDIO_MASTER) {
1652 if (is->audio_st)
1653 return AV_SYNC_AUDIO_MASTER;
1654 else
1656 } else {
1658 }
1659}
1660
1661/* get the current master clock value */
1663{
1664 double val;
1665
1666 switch (get_master_sync_type(is)) {
1668 val = get_clock(&is->vidclk);
1669 break;
1671 val = get_clock(&is->audclk);
1672 break;
1673 default:
1674 val = get_clock(&is->extclk);
1675 break;
1676 }
1677 return val;
1678}
1679
1681 if (is->video_stream >= 0 && is->videoq.nb_packets <= EXTERNAL_CLOCK_MIN_FRAMES ||
1682 is->audio_stream >= 0 && is->audioq.nb_packets <= EXTERNAL_CLOCK_MIN_FRAMES) {
1684 } else if ((is->video_stream < 0 || is->videoq.nb_packets > EXTERNAL_CLOCK_MAX_FRAMES) &&
1685 (is->audio_stream < 0 || is->audioq.nb_packets > EXTERNAL_CLOCK_MAX_FRAMES)) {
1687 } else {
1688 double speed = is->extclk.speed;
1689 if (speed != 1.0)
1690 set_clock_speed(&is->extclk, speed + EXTERNAL_CLOCK_SPEED_STEP * (1.0 - speed) / fabs(1.0 - speed));
1691 }
1692}
1693
1694/* seek in the stream */
1695static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int by_bytes)
1696{
1697 if (!is->seek_req) {
1698 is->seek_pos = pos;
1699 is->seek_rel = rel;
1700 is->seek_flags &= ~AVSEEK_FLAG_BYTE;
1701 if (by_bytes)
1702 is->seek_flags |= AVSEEK_FLAG_BYTE;
1703 is->seek_req = 1;
1704 SDL_CondSignal(is->continue_read_thread);
1705 }
1706}
1707
1708/* pause or resume the video */
1710{
1711 if (is->paused) {
1712 is->frame_timer += av_gettime_relative() / 1000000.0 - is->vidclk.last_updated;
1713 if (is->read_pause_return != AVERROR(ENOSYS)) {
1714 is->vidclk.paused = 0;
1715 }
1716 set_clock(&is->vidclk, get_clock(&is->vidclk), is->vidclk.serial);
1717 }
1718 set_clock(&is->extclk, get_clock(&is->extclk), is->extclk.serial);
1719 is->paused = is->audclk.paused = is->vidclk.paused = is->extclk.paused = !is->paused;
1720}
1721
1723{
1725 is->step = 0;
1726}
1727
1729{
1730 is->muted = !is->muted;
1731}
1732
1733static void update_volume(VideoState *is, int sign, double step)
1734{
1735 double volume_level = is->audio_volume ? (20 * log(is->audio_volume / (double)SDL_MIX_MAXVOLUME) / log(10)) : -1000.0;
1736 int new_volume = lrint(SDL_MIX_MAXVOLUME * pow(10.0, (volume_level + sign * step) / 20.0));
1737 is->audio_volume = av_clip(is->audio_volume == new_volume ? (is->audio_volume + sign) : new_volume, 0, SDL_MIX_MAXVOLUME);
1738}
1739
1741{
1742 /* if the stream is paused unpause it, then step */
1743 if (is->paused)
1745 is->step = 1;
1746}
1747
1748static double compute_target_delay(double delay, VideoState *is)
1749{
1750 double sync_threshold, diff = 0;
1751
1752 /* update delay to follow master synchronisation source */
1754 /* if video is slave, we try to correct big delays by
1755 duplicating or deleting a frame */
1756 diff = get_clock(&is->vidclk) - get_master_clock(is);
1757
1758 /* skip or repeat frame. We take into account the
1759 delay to compute the threshold. I still don't know
1760 if it is the best guess */
1761 sync_threshold = FFMAX(AV_SYNC_THRESHOLD_MIN, FFMIN(AV_SYNC_THRESHOLD_MAX, delay));
1762 if (!isnan(diff) && fabs(diff) < is->max_frame_duration) {
1763 if (diff <= -sync_threshold)
1764 delay = FFMAX(0, delay + diff);
1765 else if (diff >= sync_threshold && delay > AV_SYNC_FRAMEDUP_THRESHOLD)
1766 delay = delay + diff;
1767 else if (diff >= sync_threshold)
1768 delay = 2 * delay;
1769 }
1770 }
1771
1772 av_log(NULL, AV_LOG_TRACE, "video: delay=%0.3f A-V=%f\n",
1773 delay, -diff);
1774
1775 return delay;
1776}
1777
1778static double vp_duration(VideoState *is, Frame *vp, Frame *nextvp) {
1779 if (vp->serial == nextvp->serial) {
1780 double duration = nextvp->pts - vp->pts;
1781 if (isnan(duration) || duration <= 0 || duration > is->max_frame_duration)
1782 return vp->duration;
1783 else
1784 return duration;
1785 } else {
1786 return 0.0;
1787 }
1788}
1789
1790static void update_video_pts(VideoState *is, double pts, int serial)
1791{
1792 /* update current video pts */
1793 set_clock(&is->vidclk, pts, serial);
1794 sync_clock_to_slave(&is->extclk, &is->vidclk);
1795}
1796
1797/* called to display each frame */
1798static void video_refresh(void *opaque, double *remaining_time)
1799{
1800 VideoState *is = opaque;
1801 double time;
1802
1803 Frame *sp, *sp2;
1804
1805 if (!is->paused && get_master_sync_type(is) == AV_SYNC_EXTERNAL_CLOCK && is->realtime)
1807
1808 if (!display_disable && is->show_mode != SHOW_MODE_VIDEO && is->audio_st) {
1809 time = av_gettime_relative() / 1000000.0;
1810 if (is->force_refresh || is->last_vis_time + rdftspeed < time) {
1812 is->last_vis_time = time;
1813 }
1814 *remaining_time = FFMIN(*remaining_time, is->last_vis_time + rdftspeed - time);
1815 }
1816
1817 if (is->video_st) {
1818retry:
1819 if (frame_queue_nb_remaining(&is->pictq) == 0) {
1820 // nothing to do, no picture to display in the queue
1821 } else {
1822 double last_duration, duration, delay;
1823 Frame *vp, *lastvp;
1824
1825 /* dequeue the picture */
1826 lastvp = frame_queue_peek_last(&is->pictq);
1827 vp = frame_queue_peek(&is->pictq);
1828
1829 if (vp->serial != is->videoq.serial) {
1830 frame_queue_next(&is->pictq);
1831 goto retry;
1832 }
1833
1834 if (lastvp->serial != vp->serial)
1835 is->frame_timer = av_gettime_relative() / 1000000.0;
1836
1837 if (is->paused)
1838 goto display;
1839
1840 /* compute nominal last_duration */
1841 last_duration = vp_duration(is, lastvp, vp);
1842 delay = compute_target_delay(last_duration, is);
1843
1844 time= av_gettime_relative()/1000000.0;
1845 if (time < is->frame_timer + delay) {
1846 *remaining_time = FFMIN(is->frame_timer + delay - time, *remaining_time);
1847 goto display;
1848 }
1849
1850 is->frame_timer += delay;
1851 if (delay > 0 && time - is->frame_timer > AV_SYNC_THRESHOLD_MAX)
1852 is->frame_timer = time;
1853
1854 SDL_LockMutex(is->pictq.mutex);
1855 if (!isnan(vp->pts))
1856 update_video_pts(is, vp->pts, vp->serial);
1857 SDL_UnlockMutex(is->pictq.mutex);
1858
1859 if (frame_queue_nb_remaining(&is->pictq) > 1) {
1860 Frame *nextvp = frame_queue_peek_next(&is->pictq);
1861 duration = vp_duration(is, vp, nextvp);
1862 if(!is->step && (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) && time > is->frame_timer + duration){
1863 is->frame_drops_late++;
1864 frame_queue_next(&is->pictq);
1865 goto retry;
1866 }
1867 }
1868
1869 if (is->subtitle_st) {
1870 while (frame_queue_nb_remaining(&is->subpq) > 0) {
1871 sp = frame_queue_peek(&is->subpq);
1872
1873 if (frame_queue_nb_remaining(&is->subpq) > 1)
1874 sp2 = frame_queue_peek_next(&is->subpq);
1875 else
1876 sp2 = NULL;
1877
1878 if (sp->serial != is->subtitleq.serial
1879 || (is->vidclk.pts > (sp->pts + ((float) sp->sub.end_display_time / 1000)))
1880 || (sp2 && is->vidclk.pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000))))
1881 {
1882 if (sp->uploaded) {
1883 int i;
1884 for (i = 0; i < sp->sub.num_rects; i++) {
1885 AVSubtitleRect *sub_rect = sp->sub.rects[i];
1886 uint8_t *pixels;
1887 int pitch, j;
1888
1889 if (!SDL_LockTexture(is->sub_texture, (SDL_Rect *)sub_rect, (void **)&pixels, &pitch)) {
1890 for (j = 0; j < sub_rect->h; j++, pixels += pitch)
1891 memset(pixels, 0, sub_rect->w << 2);
1892 SDL_UnlockTexture(is->sub_texture);
1893 }
1894 }
1895 }
1896 frame_queue_next(&is->subpq);
1897 } else {
1898 break;
1899 }
1900 }
1901 }
1902
1903 frame_queue_next(&is->pictq);
1904 is->force_refresh = 1;
1905
1906 if (is->step && !is->paused)
1908 }
1909display:
1910 /* display picture */
1911 if (!display_disable && is->force_refresh && is->show_mode == SHOW_MODE_VIDEO)
1913 }
1914 is->force_refresh = 0;
1915 if (show_status) {
1916 AVBPrint buf;
1917 static int64_t last_time;
1918 int64_t cur_time;
1919 int aqsize, vqsize, sqsize;
1920 double av_diff;
1921
1922 cur_time = av_gettime_relative();
1923 if (!last_time || (cur_time - last_time) >= 30000) {
1924 aqsize = 0;
1925 vqsize = 0;
1926 sqsize = 0;
1927 if (is->audio_st)
1928 aqsize = is->audioq.size;
1929 if (is->video_st)
1930 vqsize = is->videoq.size;
1931 if (is->subtitle_st)
1932 sqsize = is->subtitleq.size;
1933 av_diff = 0;
1934 if (is->audio_st && is->video_st)
1935 av_diff = get_clock(&is->audclk) - get_clock(&is->vidclk);
1936 else if (is->video_st)
1937 av_diff = get_master_clock(is) - get_clock(&is->vidclk);
1938 else if (is->audio_st)
1939 av_diff = get_master_clock(is) - get_clock(&is->audclk);
1940
1942 av_bprintf(&buf,
1943 "%7.2f %s:%7.3f fd=%4d aq=%5dKB vq=%5dKB sq=%5dB \r",
1945 (is->audio_st && is->video_st) ? "A-V" : (is->video_st ? "M-V" : (is->audio_st ? "M-A" : " ")),
1946 av_diff,
1947 is->frame_drops_early + is->frame_drops_late,
1948 aqsize / 1024,
1949 vqsize / 1024,
1950 sqsize);
1951
1953 fprintf(stderr, "%s", buf.str);
1954 else
1955 av_log(NULL, AV_LOG_INFO, "%s", buf.str);
1956
1957 fflush(stderr);
1958 av_bprint_finalize(&buf, NULL);
1959
1960 last_time = cur_time;
1961 }
1962 }
1963}
1964
1965static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, double duration, int64_t pos, int serial)
1966{
1967 Frame *vp;
1968
1969#if defined(DEBUG_SYNC)
1970 printf("frame_type=%c pts=%0.3f\n",
1972#endif
1973
1974 if (!(vp = frame_queue_peek_writable(&is->pictq)))
1975 return -1;
1976
1977 vp->sar = src_frame->sample_aspect_ratio;
1978 vp->uploaded = 0;
1979
1980 vp->width = src_frame->width;
1981 vp->height = src_frame->height;
1982 vp->format = src_frame->format;
1983
1984 vp->pts = pts;
1985 vp->duration = duration;
1986 vp->pos = pos;
1987 vp->serial = serial;
1988
1989 set_default_window_size(vp->width, vp->height, vp->sar);
1990
1991 av_frame_move_ref(vp->frame, src_frame);
1992 frame_queue_push(&is->pictq);
1993 return 0;
1994}
1995
1997{
1998 int got_picture;
1999
2000 if ((got_picture = decoder_decode_frame(&is->viddec, frame, NULL)) < 0)
2001 return -1;
2002
2003 if (got_picture) {
2004 double dpts = NAN;
2005
2006 if (frame->pts != AV_NOPTS_VALUE)
2007 dpts = av_q2d(is->video_st->time_base) * frame->pts;
2008
2009 frame->sample_aspect_ratio = av_guess_sample_aspect_ratio(is->ic, is->video_st, frame);
2010
2012 if (frame->pts != AV_NOPTS_VALUE) {
2013 double diff = dpts - get_master_clock(is);
2014 if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD &&
2015 diff - is->frame_last_filter_delay < 0 &&
2016 is->viddec.pkt_serial == is->vidclk.serial &&
2017 is->videoq.nb_packets) {
2018 is->frame_drops_early++;
2020 got_picture = 0;
2021 }
2022 }
2023 }
2024 }
2025
2026 return got_picture;
2027}
2028
2029static int configure_filtergraph(AVFilterGraph *graph, const char *filtergraph,
2030 AVFilterContext *source_ctx, AVFilterContext *sink_ctx)
2031{
2032 int ret, i;
2033 int nb_filters = graph->nb_filters;
2035
2036 if (filtergraph) {
2039 if (!outputs || !inputs) {
2040 ret = AVERROR(ENOMEM);
2041 goto fail;
2042 }
2043
2044 outputs->name = av_strdup("in");
2045 outputs->filter_ctx = source_ctx;
2046 outputs->pad_idx = 0;
2047 outputs->next = NULL;
2048
2049 inputs->name = av_strdup("out");
2050 inputs->filter_ctx = sink_ctx;
2051 inputs->pad_idx = 0;
2052 inputs->next = NULL;
2053
2054 if ((ret = avfilter_graph_parse_ptr(graph, filtergraph, &inputs, &outputs, NULL)) < 0)
2055 goto fail;
2056 } else {
2057 if ((ret = avfilter_link(source_ctx, 0, sink_ctx, 0)) < 0)
2058 goto fail;
2059 }
2060
2061 /* Reorder the filters to ensure that inputs of the custom filters are merged first */
2062 for (i = 0; i < graph->nb_filters - nb_filters; i++)
2063 FFSWAP(AVFilterContext*, graph->filters[i], graph->filters[i + nb_filters]);
2064
2065 ret = avfilter_graph_config(graph, NULL);
2066fail:
2069 return ret;
2070}
2071
2072static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const char *vfilters, AVFrame *frame)
2073{
2075 char sws_flags_str[512] = "";
2076 int ret;
2077 AVFilterContext *filt_src = NULL, *filt_out = NULL, *last_filter = NULL;
2078 AVCodecParameters *codecpar = is->video_st->codecpar;
2079 AVRational fr = av_guess_frame_rate(is->ic, is->video_st, NULL);
2080 const AVDictionaryEntry *e = NULL;
2081 int nb_pix_fmts = 0;
2082 int i, j;
2084
2085 if (!par)
2086 return AVERROR(ENOMEM);
2087
2088 for (i = 0; i < renderer_info.num_texture_formats; i++) {
2089 for (j = 0; j < FF_ARRAY_ELEMS(sdl_texture_format_map); j++) {
2090 if (renderer_info.texture_formats[i] == sdl_texture_format_map[j].texture_fmt) {
2091 pix_fmts[nb_pix_fmts++] = sdl_texture_format_map[j].format;
2092 break;
2093 }
2094 }
2095 }
2096
2097 while ((e = av_dict_iterate(sws_dict, e))) {
2098 if (!strcmp(e->key, "sws_flags")) {
2099 av_strlcatf(sws_flags_str, sizeof(sws_flags_str), "%s=%s:", "flags", e->value);
2100 } else
2101 av_strlcatf(sws_flags_str, sizeof(sws_flags_str), "%s=%s:", e->key, e->value);
2102 }
2103 if (strlen(sws_flags_str))
2104 sws_flags_str[strlen(sws_flags_str)-1] = '\0';
2105
2106 graph->scale_sws_opts = av_strdup(sws_flags_str);
2107
2108
2109 filt_src = avfilter_graph_alloc_filter(graph, avfilter_get_by_name("buffer"),
2110 "ffplay_buffer");
2111 if (!filt_src) {
2112 ret = AVERROR(ENOMEM);
2113 goto fail;
2114 }
2115
2116 par->format = frame->format;
2117 par->time_base = is->video_st->time_base;
2118 par->width = frame->width;
2119 par->height = frame->height;
2121 par->color_space = frame->colorspace;
2122 par->color_range = frame->color_range;
2123 par->alpha_mode = frame->alpha_mode;
2124 par->frame_rate = fr;
2125 par->hw_frames_ctx = frame->hw_frames_ctx;
2126 ret = av_buffersrc_parameters_set(filt_src, par);
2127 if (ret < 0)
2128 goto fail;
2129
2130 ret = avfilter_init_dict(filt_src, NULL);
2131 if (ret < 0)
2132 goto fail;
2133
2134 filt_out = avfilter_graph_alloc_filter(graph, avfilter_get_by_name("buffersink"),
2135 "ffplay_buffersink");
2136 if (!filt_out) {
2137 ret = AVERROR(ENOMEM);
2138 goto fail;
2139 }
2140
2141 if ((ret = av_opt_set_array(filt_out, "pixel_formats", AV_OPT_SEARCH_CHILDREN,
2142 0, nb_pix_fmts, AV_OPT_TYPE_PIXEL_FMT, pix_fmts)) < 0)
2143 goto fail;
2144 if (!vk_renderer &&
2145 (ret = av_opt_set_array(filt_out, "colorspaces", AV_OPT_SEARCH_CHILDREN,
2148 goto fail;
2149
2150 if ((ret = av_opt_set_array(filt_out, "alphamodes", AV_OPT_SEARCH_CHILDREN,
2153 goto fail;
2154
2155 ret = avfilter_init_dict(filt_out, NULL);
2156 if (ret < 0)
2157 goto fail;
2158
2159 last_filter = filt_out;
2160
2161/* Note: this macro adds a filter before the lastly added filter, so the
2162 * processing order of the filters is in reverse */
2163#define INSERT_FILT(name, arg) do { \
2164 AVFilterContext *filt_ctx; \
2165 \
2166 ret = avfilter_graph_create_filter(&filt_ctx, \
2167 avfilter_get_by_name(name), \
2168 "ffplay_" name, arg, NULL, graph); \
2169 if (ret < 0) \
2170 goto fail; \
2171 \
2172 ret = avfilter_link(filt_ctx, 0, last_filter, 0); \
2173 if (ret < 0) \
2174 goto fail; \
2175 \
2176 last_filter = filt_ctx; \
2177} while (0)
2178
2179 if (autorotate) {
2180 double theta = 0.0;
2181 int32_t *displaymatrix = NULL;
2183 if (sd)
2184 displaymatrix = (int32_t *)sd->data;
2185 if (!displaymatrix) {
2186 const AVPacketSideData *psd = av_packet_side_data_get(is->video_st->codecpar->coded_side_data,
2187 is->video_st->codecpar->nb_coded_side_data,
2189 if (psd)
2190 displaymatrix = (int32_t *)psd->data;
2191 }
2192 theta = get_rotation(displaymatrix);
2193
2194 if (fabs(theta - 90) < 1.0) {
2195 INSERT_FILT("transpose", displaymatrix[3] > 0 ? "cclock_flip" : "clock");
2196 } else if (fabs(theta - 180) < 1.0) {
2197 if (displaymatrix[0] < 0)
2198 INSERT_FILT("hflip", NULL);
2199 if (displaymatrix[4] < 0)
2200 INSERT_FILT("vflip", NULL);
2201 } else if (fabs(theta - 270) < 1.0) {
2202 INSERT_FILT("transpose", displaymatrix[3] < 0 ? "clock_flip" : "cclock");
2203 } else if (fabs(theta) > 1.0) {
2204 char rotate_buf[64];
2205 snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
2206 INSERT_FILT("rotate", rotate_buf);
2207 } else {
2208 if (displaymatrix && displaymatrix[4] < 0)
2209 INSERT_FILT("vflip", NULL);
2210 }
2211 }
2212
2213 if ((ret = configure_filtergraph(graph, vfilters, filt_src, last_filter)) < 0)
2214 goto fail;
2215
2216 is->in_video_filter = filt_src;
2217 is->out_video_filter = filt_out;
2218
2219fail:
2220 av_freep(&par);
2221 return ret;
2222}
2223
2224static int configure_audio_filters(VideoState *is, const char *afilters, int force_output_format)
2225{
2226 AVFilterContext *filt_asrc = NULL, *filt_asink = NULL;
2227 char aresample_swr_opts[512] = "";
2228 const AVDictionaryEntry *e = NULL;
2229 AVBPrint bp;
2230 char asrc_args[256];
2231 int ret;
2232
2233 avfilter_graph_free(&is->agraph);
2234 if (!(is->agraph = avfilter_graph_alloc()))
2235 return AVERROR(ENOMEM);
2236 is->agraph->nb_threads = filter_nbthreads;
2237
2239
2240 while ((e = av_dict_iterate(swr_opts, e)))
2241 av_strlcatf(aresample_swr_opts, sizeof(aresample_swr_opts), "%s=%s:", e->key, e->value);
2242 if (strlen(aresample_swr_opts))
2243 aresample_swr_opts[strlen(aresample_swr_opts)-1] = '\0';
2244 av_opt_set(is->agraph, "aresample_swr_opts", aresample_swr_opts, 0);
2245
2246 av_channel_layout_describe_bprint(&is->audio_filter_src.ch_layout, &bp);
2247
2248 ret = snprintf(asrc_args, sizeof(asrc_args),
2249 "sample_rate=%d:sample_fmt=%s:time_base=%d/%d:channel_layout=%s",
2250 is->audio_filter_src.freq, av_get_sample_fmt_name(is->audio_filter_src.fmt),
2251 1, is->audio_filter_src.freq, bp.str);
2252
2253 ret = avfilter_graph_create_filter(&filt_asrc,
2254 avfilter_get_by_name("abuffer"), "ffplay_abuffer",
2255 asrc_args, NULL, is->agraph);
2256 if (ret < 0)
2257 goto end;
2258
2259 filt_asink = avfilter_graph_alloc_filter(is->agraph, avfilter_get_by_name("abuffersink"),
2260 "ffplay_abuffersink");
2261 if (!filt_asink) {
2262 ret = AVERROR(ENOMEM);
2263 goto end;
2264 }
2265
2266 if ((ret = av_opt_set(filt_asink, "sample_formats", "s16", AV_OPT_SEARCH_CHILDREN)) < 0)
2267 goto end;
2268
2269 if (force_output_format) {
2270 if ((ret = av_opt_set_array(filt_asink, "channel_layouts", AV_OPT_SEARCH_CHILDREN,
2271 0, 1, AV_OPT_TYPE_CHLAYOUT, &is->audio_tgt.ch_layout)) < 0)
2272 goto end;
2273 if ((ret = av_opt_set_array(filt_asink, "samplerates", AV_OPT_SEARCH_CHILDREN,
2274 0, 1, AV_OPT_TYPE_INT, &is->audio_tgt.freq)) < 0)
2275 goto end;
2276 }
2277
2278 ret = avfilter_init_dict(filt_asink, NULL);
2279 if (ret < 0)
2280 goto end;
2281
2282 if ((ret = configure_filtergraph(is->agraph, afilters, filt_asrc, filt_asink)) < 0)
2283 goto end;
2284
2285 is->in_audio_filter = filt_asrc;
2286 is->out_audio_filter = filt_asink;
2287
2288end:
2289 if (ret < 0)
2290 avfilter_graph_free(&is->agraph);
2292
2293 return ret;
2294}
2295
2296static int audio_thread(void *arg)
2297{
2298 VideoState *is = arg;
2300 Frame *af;
2301 int last_serial = -1;
2302 int reconfigure;
2303 int got_frame = 0;
2304 AVRational tb;
2305 int ret = 0;
2306
2307 if (!frame)
2308 return AVERROR(ENOMEM);
2309
2310 do {
2311 if ((got_frame = decoder_decode_frame(&is->auddec, frame, NULL)) < 0)
2312 goto the_end;
2313
2314 if (got_frame) {
2315 tb = (AVRational){1, frame->sample_rate};
2316
2317 reconfigure =
2318 cmp_audio_fmts(is->audio_filter_src.fmt, is->audio_filter_src.ch_layout.nb_channels,
2319 frame->format, frame->ch_layout.nb_channels) ||
2320 av_channel_layout_compare(&is->audio_filter_src.ch_layout, &frame->ch_layout) ||
2321 is->audio_filter_src.freq != frame->sample_rate ||
2322 is->auddec.pkt_serial != last_serial;
2323
2324 if (reconfigure) {
2325 char buf1[1024], buf2[1024];
2326 av_channel_layout_describe(&is->audio_filter_src.ch_layout, buf1, sizeof(buf1));
2327 av_channel_layout_describe(&frame->ch_layout, buf2, sizeof(buf2));
2329 "Audio frame changed from rate:%d ch:%d fmt:%s layout:%s serial:%d to rate:%d ch:%d fmt:%s layout:%s serial:%d\n",
2330 is->audio_filter_src.freq, is->audio_filter_src.ch_layout.nb_channels, av_get_sample_fmt_name(is->audio_filter_src.fmt), buf1, last_serial,
2331 frame->sample_rate, frame->ch_layout.nb_channels, av_get_sample_fmt_name(frame->format), buf2, is->auddec.pkt_serial);
2332
2333 is->audio_filter_src.fmt = frame->format;
2334 ret = av_channel_layout_copy(&is->audio_filter_src.ch_layout, &frame->ch_layout);
2335 if (ret < 0)
2336 goto the_end;
2337 is->audio_filter_src.freq = frame->sample_rate;
2338 last_serial = is->auddec.pkt_serial;
2339
2340 if ((ret = configure_audio_filters(is, afilters, 1)) < 0)
2341 goto the_end;
2342 }
2343
2344 if ((ret = av_buffersrc_add_frame(is->in_audio_filter, frame)) < 0)
2345 goto the_end;
2346
2347 while ((ret = av_buffersink_get_frame_flags(is->out_audio_filter, frame, 0)) >= 0) {
2348 FrameData *fd = frame->opaque_ref ? (FrameData*)frame->opaque_ref->data : NULL;
2349 tb = av_buffersink_get_time_base(is->out_audio_filter);
2350 if (!(af = frame_queue_peek_writable(&is->sampq)))
2351 goto the_end;
2352
2353 af->pts = (frame->pts == AV_NOPTS_VALUE) ? NAN : frame->pts * av_q2d(tb);
2354 af->pos = fd ? fd->pkt_pos : -1;
2355 af->serial = is->auddec.pkt_serial;
2356 af->duration = av_q2d((AVRational){frame->nb_samples, frame->sample_rate});
2357
2359 frame_queue_push(&is->sampq);
2360
2361 if (is->audioq.serial != is->auddec.pkt_serial)
2362 break;
2363 }
2364 if (ret == AVERROR_EOF)
2365 is->auddec.finished = is->auddec.pkt_serial;
2366 }
2367 } while (ret >= 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF);
2368 the_end:
2369 avfilter_graph_free(&is->agraph);
2371 return ret;
2372}
2373
2374static int decoder_start(Decoder *d, int (*fn)(void *), const char *thread_name, void* arg)
2375{
2376 d->decoder_tid = SDL_CreateThread(fn, thread_name, arg);
2377 if (!d->decoder_tid) {
2378 av_log(NULL, AV_LOG_ERROR, "SDL_CreateThread(): %s\n", SDL_GetError());
2379 return AVERROR(ENOMEM);
2380 }
2381 return 0;
2382}
2383
2384/* pushes the event for the event loop, marked with the stream it comes from */
2386{
2387 SDL_Event event = { .user = { .type = type, .code = is->id } };
2388
2389 if (SDL_PushEvent(&event) < 0)
2390 av_log(NULL, AV_LOG_ERROR, "Could not push the event of '%s': %s\n", is->filename, SDL_GetError());
2391}
2392
2393static int video_thread(void *arg)
2394{
2395 VideoState *is = arg;
2397 double pts;
2398 double duration;
2399 int ret, announced = 0;
2400 AVRational tb = is->video_st->time_base;
2401 AVRational frame_rate = av_guess_frame_rate(is->ic, is->video_st, NULL);
2402
2403 AVFilterGraph *graph = NULL;
2404 AVFilterContext *filt_out = NULL, *filt_in = NULL;
2405 int last_w = 0;
2406 int last_h = 0;
2407 enum AVPixelFormat last_format = -2;
2408 int last_serial = -1;
2409 int last_vfilter_idx = 0;
2410
2411 if (!frame)
2412 return AVERROR(ENOMEM);
2413
2414 for (;;) {
2416 if (ret < 0)
2417 goto the_end;
2418 if (!ret) {
2419 if (is->viddec.finished == is->viddec.pkt_serial && !announced) {
2421 announced = 1;
2422 }
2423 continue;
2424 }
2425
2426 if ( last_w != frame->width
2427 || last_h != frame->height
2428 || last_format != frame->format
2429 || last_serial != is->viddec.pkt_serial
2430 || last_vfilter_idx != is->vfilter_idx) {
2432 "Video frame changed from size:%dx%d format:%s serial:%d to size:%dx%d format:%s serial:%d\n",
2433 last_w, last_h,
2434 (const char *)av_x_if_null(av_get_pix_fmt_name(last_format), "none"), last_serial,
2435 frame->width, frame->height,
2436 (const char *)av_x_if_null(av_get_pix_fmt_name(frame->format), "none"), is->viddec.pkt_serial);
2437 avfilter_graph_free(&graph);
2438 graph = avfilter_graph_alloc();
2439 if (!graph) {
2440 ret = AVERROR(ENOMEM);
2441 goto the_end;
2442 }
2444 if ((ret = configure_video_filters(graph, is, vfilters_list ? vfilters_list[is->vfilter_idx] : NULL, frame)) < 0) {
2446 goto the_end;
2447 }
2448 filt_in = is->in_video_filter;
2449 filt_out = is->out_video_filter;
2450 last_w = frame->width;
2451 last_h = frame->height;
2452 last_format = frame->format;
2453 last_serial = is->viddec.pkt_serial;
2454 last_vfilter_idx = is->vfilter_idx;
2455 frame_rate = av_buffersink_get_frame_rate(filt_out);
2456 }
2457
2458 ret = av_buffersrc_add_frame(filt_in, frame);
2459 if (ret < 0)
2460 goto the_end;
2461
2462 while (ret >= 0) {
2463 FrameData *fd;
2464
2465 is->frame_last_returned_time = av_gettime_relative() / 1000000.0;
2466
2467 ret = av_buffersink_get_frame_flags(filt_out, frame, 0);
2468 if (ret < 0) {
2469 if (ret == AVERROR_EOF)
2470 is->viddec.finished = is->viddec.pkt_serial;
2471 ret = 0;
2472 break;
2473 }
2474
2475 fd = frame->opaque_ref ? (FrameData*)frame->opaque_ref->data : NULL;
2476
2477 is->frame_last_filter_delay = av_gettime_relative() / 1000000.0 - is->frame_last_returned_time;
2478 if (fabs(is->frame_last_filter_delay) > AV_NOSYNC_THRESHOLD / 10.0)
2479 is->frame_last_filter_delay = 0;
2480 tb = av_buffersink_get_time_base(filt_out);
2481 duration = (frame_rate.num && frame_rate.den ? av_q2d((AVRational){frame_rate.den, frame_rate.num}) : 0);
2482 pts = (frame->pts == AV_NOPTS_VALUE) ? NAN : frame->pts * av_q2d(tb);
2483 ret = queue_picture(is, frame, pts, duration, fd ? fd->pkt_pos : -1, is->viddec.pkt_serial);
2485 if (ret >= 0 && !announced) {
2487 announced = 1;
2488 }
2489 if (is->videoq.serial != is->viddec.pkt_serial)
2490 break;
2491 }
2492
2493 if (ret < 0)
2494 goto the_end;
2495 }
2496 the_end:
2497 if (!announced && SDL_AtomicGet(&is->replacement))
2499 avfilter_graph_free(&graph);
2501 return 0;
2502}
2503
2504static int subtitle_thread(void *arg)
2505{
2506 VideoState *is = arg;
2507 Frame *sp;
2508 int got_subtitle;
2509 double pts;
2510
2511 for (;;) {
2512 if (!(sp = frame_queue_peek_writable(&is->subpq)))
2513 return 0;
2514
2515 if ((got_subtitle = decoder_decode_frame(&is->subdec, NULL, &sp->sub)) < 0)
2516 break;
2517
2518 pts = 0;
2519
2520 if (got_subtitle && sp->sub.format == 0) {
2521 if (sp->sub.pts != AV_NOPTS_VALUE)
2522 pts = sp->sub.pts / (double)AV_TIME_BASE;
2523 sp->pts = pts;
2524 sp->serial = is->subdec.pkt_serial;
2525 sp->width = is->subdec.avctx->width;
2526 sp->height = is->subdec.avctx->height;
2527 sp->uploaded = 0;
2528
2529 /* now we can update the picture count */
2530 frame_queue_push(&is->subpq);
2531 } else if (got_subtitle) {
2532 avsubtitle_free(&sp->sub);
2533 }
2534 }
2535 return 0;
2536}
2537
2538/* copy samples for viewing in editor window */
2539static void update_sample_display(VideoState *is, short *samples, int samples_size)
2540{
2541 int size, len;
2542
2543 size = samples_size / sizeof(short);
2544 while (size > 0) {
2545 len = SAMPLE_ARRAY_SIZE - is->sample_array_index;
2546 if (len > size)
2547 len = size;
2548 memcpy(is->sample_array + is->sample_array_index, samples, len * sizeof(short));
2549 samples += len;
2550 is->sample_array_index += len;
2551 if (is->sample_array_index >= SAMPLE_ARRAY_SIZE)
2552 is->sample_array_index = 0;
2553 size -= len;
2554 }
2555}
2556
2557/* return the wanted number of samples to get better sync if sync_type is video
2558 * or external master clock */
2559static int synchronize_audio(VideoState *is, int nb_samples)
2560{
2561 int wanted_nb_samples = nb_samples;
2562
2563 /* if not master, then we try to remove or add samples to correct the clock */
2565 double diff, avg_diff;
2566 int min_nb_samples, max_nb_samples;
2567
2568 diff = get_clock(&is->audclk) - get_master_clock(is);
2569
2570 if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD) {
2571 is->audio_diff_cum = diff + is->audio_diff_avg_coef * is->audio_diff_cum;
2572 if (is->audio_diff_avg_count < AUDIO_DIFF_AVG_NB) {
2573 /* not enough measures to have a correct estimate */
2574 is->audio_diff_avg_count++;
2575 } else {
2576 /* estimate the A-V difference */
2577 avg_diff = is->audio_diff_cum * (1.0 - is->audio_diff_avg_coef);
2578
2579 if (fabs(avg_diff) >= is->audio_diff_threshold) {
2580 wanted_nb_samples = nb_samples + (int)(diff * is->audio_src.freq);
2581 min_nb_samples = ((nb_samples * (100 - SAMPLE_CORRECTION_PERCENT_MAX) / 100));
2582 max_nb_samples = ((nb_samples * (100 + SAMPLE_CORRECTION_PERCENT_MAX) / 100));
2583 wanted_nb_samples = av_clip(wanted_nb_samples, min_nb_samples, max_nb_samples);
2584 }
2585 av_log(NULL, AV_LOG_TRACE, "diff=%f adiff=%f sample_diff=%d apts=%0.3f %f\n",
2586 diff, avg_diff, wanted_nb_samples - nb_samples,
2587 is->audio_clock, is->audio_diff_threshold);
2588 }
2589 } else {
2590 /* too big difference : may be initial PTS errors, so
2591 reset A-V filter */
2592 is->audio_diff_avg_count = 0;
2593 is->audio_diff_cum = 0;
2594 }
2595 }
2596
2597 return wanted_nb_samples;
2598}
2599
2600/**
2601 * Decode one audio frame and return its uncompressed size.
2602 *
2603 * The processed audio frame is decoded, converted if required, and
2604 * stored in is->audio_buf, with size in bytes given by the return
2605 * value.
2606 */
2608{
2609 int data_size, resampled_data_size;
2610 av_unused double audio_clock0;
2611 int wanted_nb_samples;
2612 Frame *af;
2613
2614 if (is->paused)
2615 return -1;
2616
2617 do {
2618#if defined(_WIN32)
2619 while (frame_queue_nb_remaining(&is->sampq) == 0) {
2620 if ((av_gettime_relative() - is->audio_callback_time) > 1000000LL * is->audio_hw_buf_size / is->audio_tgt.bytes_per_sec / 2)
2621 return -1;
2622 av_usleep (1000);
2623 }
2624#endif
2625 if (!(af = frame_queue_peek_readable(&is->sampq)))
2626 return -1;
2627 frame_queue_next(&is->sampq);
2628 } while (af->serial != is->audioq.serial);
2629
2631 af->frame->nb_samples,
2632 af->frame->format, 1);
2633
2634 wanted_nb_samples = synchronize_audio(is, af->frame->nb_samples);
2635
2636 if (af->frame->format != is->audio_src.fmt ||
2637 av_channel_layout_compare(&af->frame->ch_layout, &is->audio_src.ch_layout) ||
2638 af->frame->sample_rate != is->audio_src.freq ||
2639 (wanted_nb_samples != af->frame->nb_samples && !is->swr_ctx)) {
2640 int ret;
2641 swr_free(&is->swr_ctx);
2642 ret = swr_alloc_set_opts2(&is->swr_ctx,
2643 &is->audio_tgt.ch_layout, is->audio_tgt.fmt, is->audio_tgt.freq,
2644 &af->frame->ch_layout, af->frame->format, af->frame->sample_rate,
2645 0, NULL);
2646 if (ret < 0 || swr_init(is->swr_ctx) < 0) {
2648 "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",
2650 is->audio_tgt.freq, av_get_sample_fmt_name(is->audio_tgt.fmt), is->audio_tgt.ch_layout.nb_channels);
2651 swr_free(&is->swr_ctx);
2652 return -1;
2653 }
2654 if (av_channel_layout_copy(&is->audio_src.ch_layout, &af->frame->ch_layout) < 0)
2655 return -1;
2656 is->audio_src.freq = af->frame->sample_rate;
2657 is->audio_src.fmt = af->frame->format;
2658 }
2659
2660 if (is->swr_ctx) {
2661 const uint8_t **in = (const uint8_t **)af->frame->extended_data;
2662 uint8_t **out = &is->audio_buf1;
2663 int out_count = (int64_t)wanted_nb_samples * is->audio_tgt.freq / af->frame->sample_rate + 256;
2664 int out_size = av_samples_get_buffer_size(NULL, is->audio_tgt.ch_layout.nb_channels, out_count, is->audio_tgt.fmt, 0);
2665 int len2;
2666 if (out_size < 0) {
2667 av_log(NULL, AV_LOG_ERROR, "av_samples_get_buffer_size() failed\n");
2668 return -1;
2669 }
2670 if (wanted_nb_samples != af->frame->nb_samples) {
2671 if (swr_set_compensation(is->swr_ctx, (wanted_nb_samples - af->frame->nb_samples) * is->audio_tgt.freq / af->frame->sample_rate,
2672 wanted_nb_samples * is->audio_tgt.freq / af->frame->sample_rate) < 0) {
2673 av_log(NULL, AV_LOG_ERROR, "swr_set_compensation() failed\n");
2674 return -1;
2675 }
2676 }
2677 av_fast_malloc(&is->audio_buf1, &is->audio_buf1_size, out_size);
2678 if (!is->audio_buf1)
2679 return AVERROR(ENOMEM);
2680 len2 = swr_convert(is->swr_ctx, out, out_count, in, af->frame->nb_samples);
2681 if (len2 < 0) {
2682 av_log(NULL, AV_LOG_ERROR, "swr_convert() failed\n");
2683 return -1;
2684 }
2685 if (len2 == out_count) {
2686 av_log(NULL, AV_LOG_WARNING, "audio buffer is probably too small\n");
2687 if (swr_init(is->swr_ctx) < 0)
2688 swr_free(&is->swr_ctx);
2689 }
2690 is->audio_buf = is->audio_buf1;
2691 resampled_data_size = len2 * is->audio_tgt.ch_layout.nb_channels * av_get_bytes_per_sample(is->audio_tgt.fmt);
2692 } else {
2693 is->audio_buf = af->frame->data[0];
2694 resampled_data_size = data_size;
2695 }
2696
2697 audio_clock0 = is->audio_clock;
2698 /* update the audio clock with the pts */
2699 if (!isnan(af->pts))
2700 is->audio_clock = af->pts + (double) af->frame->nb_samples / af->frame->sample_rate;
2701 else
2702 is->audio_clock = NAN;
2703 is->audio_clock_serial = af->serial;
2704#ifdef DEBUG
2705 {
2706 static double last_clock;
2707 printf("audio: delay=%0.3f clock=%0.3f clock0=%0.3f\n",
2708 is->audio_clock - last_clock,
2709 is->audio_clock, audio_clock0);
2710 last_clock = is->audio_clock;
2711 }
2712#endif
2713 return resampled_data_size;
2714}
2715
2716/* prepare a new audio buffer */
2717static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
2718{
2719 VideoState *is = opaque;
2720 int audio_size, len1;
2721
2722 is->audio_callback_time = av_gettime_relative();
2723
2724 while (len > 0) {
2725 if (is->audio_buf_index >= is->audio_buf_size) {
2726 audio_size = audio_decode_frame(is);
2727 if (audio_size < 0) {
2728 /* if error, just output silence */
2729 is->audio_buf = NULL;
2730 is->audio_buf_size = SDL_AUDIO_MIN_BUFFER_SIZE / is->audio_tgt.frame_size * is->audio_tgt.frame_size;
2731 } else {
2732 if (is->show_mode != SHOW_MODE_VIDEO)
2733 update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
2734 is->audio_buf_size = audio_size;
2735 }
2736 is->audio_buf_index = 0;
2737 }
2738 len1 = is->audio_buf_size - is->audio_buf_index;
2739 if (len1 > len)
2740 len1 = len;
2741 if (!is->muted && is->audio_buf && is->audio_volume == SDL_MIX_MAXVOLUME)
2742 memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
2743 else {
2744 memset(stream, 0, len1);
2745 if (!is->muted && is->audio_buf)
2746 SDL_MixAudioFormat(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, AUDIO_S16SYS, len1, is->audio_volume);
2747 }
2748 len -= len1;
2749 stream += len1;
2750 is->audio_buf_index += len1;
2751 }
2752 is->audio_write_buf_size = is->audio_buf_size - is->audio_buf_index;
2753 /* Let's assume the audio driver that is used by SDL has two periods. */
2754 if (!isnan(is->audio_clock)) {
2755 set_clock_at(&is->audclk, is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / is->audio_tgt.bytes_per_sec, is->audio_clock_serial, is->audio_callback_time / 1000000.0);
2756 sync_clock_to_slave(&is->extclk, &is->audclk);
2757 }
2758}
2759
2760static int audio_open(VideoState *is, AVChannelLayout *wanted_channel_layout, int wanted_sample_rate, struct AudioParams *audio_hw_params)
2761{
2762 SDL_AudioSpec wanted_spec, spec;
2763 const char *env;
2764 static const int next_nb_channels[] = {0, 0, 1, 6, 2, 6, 4, 6};
2765 static const int next_sample_rates[] = {0, 44100, 48000, 96000, 192000};
2766 int next_sample_rate_idx = FF_ARRAY_ELEMS(next_sample_rates) - 1;
2767 int wanted_nb_channels = wanted_channel_layout->nb_channels;
2768
2769 env = SDL_getenv("SDL_AUDIO_CHANNELS");
2770 if (env) {
2771 wanted_nb_channels = atoi(env);
2772 av_channel_layout_uninit(wanted_channel_layout);
2773 av_channel_layout_default(wanted_channel_layout, wanted_nb_channels);
2774 }
2775 if (wanted_channel_layout->order != AV_CHANNEL_ORDER_NATIVE) {
2776 av_channel_layout_uninit(wanted_channel_layout);
2777 av_channel_layout_default(wanted_channel_layout, wanted_nb_channels);
2778 }
2779 wanted_nb_channels = wanted_channel_layout->nb_channels;
2780 wanted_spec.channels = wanted_nb_channels;
2781 wanted_spec.freq = wanted_sample_rate;
2782 if (wanted_spec.freq <= 0 || wanted_spec.channels <= 0) {
2783 av_log(NULL, AV_LOG_ERROR, "Invalid sample rate or channel count!\n");
2784 return -1;
2785 }
2786 while (next_sample_rate_idx && next_sample_rates[next_sample_rate_idx] >= wanted_spec.freq)
2787 next_sample_rate_idx--;
2788 wanted_spec.format = AUDIO_S16SYS;
2789 wanted_spec.silence = 0;
2790 wanted_spec.samples = FFMAX(SDL_AUDIO_MIN_BUFFER_SIZE, 2 << av_log2(wanted_spec.freq / SDL_AUDIO_MAX_CALLBACKS_PER_SEC));
2791 wanted_spec.callback = sdl_audio_callback;
2792 wanted_spec.userdata = is;
2793 while (!(is->audio_dev = SDL_OpenAudioDevice(NULL, 0, &wanted_spec, &spec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE))) {
2794 av_log(NULL, AV_LOG_WARNING, "SDL_OpenAudio (%d channels, %d Hz): %s\n",
2795 wanted_spec.channels, wanted_spec.freq, SDL_GetError());
2796 wanted_spec.channels = next_nb_channels[FFMIN(7, wanted_spec.channels)];
2797 if (!wanted_spec.channels) {
2798 wanted_spec.freq = next_sample_rates[next_sample_rate_idx--];
2799 wanted_spec.channels = wanted_nb_channels;
2800 if (!wanted_spec.freq) {
2802 "No more combinations to try, audio open failed\n");
2803 return -1;
2804 }
2805 }
2806 av_channel_layout_default(wanted_channel_layout, wanted_spec.channels);
2807 }
2808 if (spec.format != AUDIO_S16SYS) {
2810 "SDL advised audio format %d is not supported!\n", spec.format);
2811 return -1;
2812 }
2813 if (spec.channels != wanted_spec.channels) {
2814 av_channel_layout_uninit(wanted_channel_layout);
2815 av_channel_layout_default(wanted_channel_layout, spec.channels);
2816 if (wanted_channel_layout->order != AV_CHANNEL_ORDER_NATIVE) {
2818 "SDL advised channel count %d is not supported!\n", spec.channels);
2819 return -1;
2820 }
2821 }
2822
2823 audio_hw_params->fmt = AV_SAMPLE_FMT_S16;
2824 audio_hw_params->freq = spec.freq;
2825 if (av_channel_layout_copy(&audio_hw_params->ch_layout, wanted_channel_layout) < 0)
2826 return -1;
2827 audio_hw_params->frame_size = av_samples_get_buffer_size(NULL, audio_hw_params->ch_layout.nb_channels, 1, audio_hw_params->fmt, 1);
2828 audio_hw_params->bytes_per_sec = av_samples_get_buffer_size(NULL, audio_hw_params->ch_layout.nb_channels, audio_hw_params->freq, audio_hw_params->fmt, 1);
2829 if (audio_hw_params->bytes_per_sec <= 0 || audio_hw_params->frame_size <= 0) {
2830 av_log(NULL, AV_LOG_ERROR, "av_samples_get_buffer_size failed\n");
2831 return -1;
2832 }
2833 return spec.size;
2834}
2835
2836static int create_hwaccel(AVBufferRef **device_ctx)
2837{
2838 enum AVHWDeviceType type;
2839 int ret;
2840 AVBufferRef *vk_dev;
2841
2842 *device_ctx = NULL;
2843
2844 if (!hwaccel)
2845 return 0;
2846
2849 return AVERROR(ENOTSUP);
2850
2851 if (!vk_renderer) {
2852 av_log(NULL, AV_LOG_ERROR, "Vulkan renderer is not available\n");
2853 return AVERROR(ENOTSUP);
2854 }
2855
2857 if (ret < 0)
2858 return ret;
2859
2860 ret = av_hwdevice_ctx_create_derived(device_ctx, type, vk_dev, 0);
2861 if (!ret)
2862 return 0;
2863
2864 if (ret != AVERROR(ENOSYS))
2865 return ret;
2866
2867 av_log(NULL, AV_LOG_WARNING, "Derive %s from vulkan not supported.\n", hwaccel);
2868 ret = av_hwdevice_ctx_create(device_ctx, type, NULL, NULL, 0);
2869 return ret;
2870}
2871
2872static int init_lcevc_graph(AVFormatContext *ic, int stream_index)
2873{
2874 FormatContext *ici = ic->opaque;
2875 StreamGroup *stgi = ici->streams[stream_index]->group;
2876 AVStreamGroup *stg = stgi->stg;
2877 const AVBitStreamFilter *filter, *lcevc_filter = av_bsf_get_by_name("lcevc_merge");
2879 int ret;
2880
2881 stgi->graph = av_bsf_graph_alloc();
2882 if (!stgi->graph)
2883 return AVERROR(ENOMEM);
2884
2886 AVStream *base_st = ic->streams[stream_index];
2887 AVStream *lcevc_st = stg->entries[lcevc->el_index]->stream;
2888 Stream *lcevc_sti = ici->streams[lcevc_st->index];
2889 Stream *base_sti = ici->streams[stream_index];
2890
2891 filter = av_bsf_get_by_name("source");
2892 ret = av_bsf_graph_alloc_filter(&base_sti->filter, filter, "lcevc_merge_base", stgi->graph);
2893 if (ret < 0)
2894 return ret;
2895 av_opt_set_q(base_sti->filter->priv_data, "time_base", base_st->time_base, 0);
2896 ret = av_bsf_source_parameters_set(base_sti->filter, base_st->codecpar);
2897 if (ret < 0)
2898 return ret;
2899
2900 ret = av_bsf_graph_alloc_filter(&lcevc_sti->filter, filter, "lcevc_merge_enhancement", stgi->graph);
2901 if (ret < 0)
2902 return ret;
2903 av_opt_set_q(lcevc_sti->filter->priv_data, "time_base", lcevc_st->time_base, 0);
2904 ret = av_bsf_source_parameters_set(lcevc_sti->filter, lcevc_st->codecpar);
2905 if (ret < 0)
2906 return ret;
2907
2908 ret = av_bsf_graph_alloc_filter(&lcevc_merge, lcevc_filter, "lcevc_merge", stgi->graph);
2909 if (ret < 0)
2910 return ret;
2911
2912 filter = av_bsf_get_by_name("sink");
2913 ret = av_bsf_graph_alloc_filter(&stgi->sink, filter, "lcevc_merge_sink", stgi->graph);
2914 if (ret < 0)
2915 return ret;
2916
2917 ret = av_bsf_init_dict(base_sti->filter, NULL);
2918 if (ret < 0)
2919 return ret;
2920 ret = av_bsf_init_dict(lcevc_sti->filter, NULL);
2921 if (ret < 0)
2922 return ret;
2924 if (ret < 0)
2925 return ret;
2926 ret = av_bsf_init_dict(stgi->sink, NULL);
2927 if (ret < 0)
2928 return ret;
2929
2930 ret = av_bsf_link(base_sti->filter, 0, lcevc_merge, 0);
2931 if (ret < 0)
2932 return ret;
2933 ret = av_bsf_link(lcevc_sti->filter, 0, lcevc_merge, 1);
2934 if (ret < 0)
2935 return ret;
2936 ret = av_bsf_link(lcevc_merge, 0, stgi->sink, 0);
2937 if (ret < 0)
2938 return ret;
2939
2941 if (ret < 0)
2942 return ret;
2943
2944 lcevc_st->discard = AVDISCARD_DEFAULT;
2945 lcevc_sti->group = stgi;
2946
2947 return 0;
2948}
2949
2950/* opens the audio device for the output of the audio filters and starts decoding and playing the audio */
2952{
2953 AVChannelLayout ch_layout = { 0 };
2954 int ret = av_buffersink_get_ch_layout(is->out_audio_filter, &ch_layout);
2955
2956 if (ret >= 0)
2957 ret = audio_open(is, &ch_layout, av_buffersink_get_sample_rate(is->out_audio_filter), &is->audio_tgt);
2958 av_channel_layout_uninit(&ch_layout);
2959 if (ret < 0)
2960 return ret;
2961 is->audio_hw_buf_size = ret;
2962 is->audio_src = is->audio_tgt;
2963 is->audio_buf_size = 0;
2964 is->audio_buf_index = 0;
2965
2966 /* init averaging filter */
2967 is->audio_diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB);
2968 is->audio_diff_avg_count = 0;
2969 /* since we do not have a precise anough audio FIFO fullness,
2970 we correct audio sync only if larger than this threshold */
2971 is->audio_diff_threshold = (double)(is->audio_hw_buf_size) / is->audio_tgt.bytes_per_sec;
2972
2973 if ((ret = decoder_start(&is->auddec, audio_thread, "audio_decoder", is)) < 0)
2974 return ret;
2975 SDL_PauseAudioDevice(is->audio_dev, 0);
2976 return 0;
2977}
2978
2979/* open a given stream. Return 0 if OK */
2980static int stream_component_open(VideoState *is, int stream_index)
2981{
2982 AVFormatContext *ic = is->ic;
2983 FormatContext *ici = ic->opaque;
2984 AVCodecContext *avctx;
2985 const AVCodec *codec;
2986 const char *forced_codec_name = NULL;
2988 int ret = 0;
2989 int stream_lowres = lowres;
2990
2991 if (stream_index < 0 || stream_index >= ic->nb_streams)
2992 return -1;
2993
2995 if (!avctx)
2996 return AVERROR(ENOMEM);
2997
2998 ret = avcodec_parameters_to_context(avctx, ic->streams[stream_index]->codecpar);
2999 if (ret < 0)
3000 goto fail;
3001 avctx->pkt_timebase = ic->streams[stream_index]->time_base;
3002
3003 codec = avcodec_find_decoder(avctx->codec_id);
3004
3005 switch(avctx->codec_type){
3006 case AVMEDIA_TYPE_AUDIO : is->last_audio_stream = stream_index; forced_codec_name = audio_codec_name; break;
3007 case AVMEDIA_TYPE_SUBTITLE: is->last_subtitle_stream = stream_index; forced_codec_name = subtitle_codec_name; break;
3008 case AVMEDIA_TYPE_VIDEO : is->last_video_stream = stream_index; forced_codec_name = video_codec_name; break;
3009 }
3010 if (forced_codec_name)
3011 codec = avcodec_find_decoder_by_name(forced_codec_name);
3012 if (!codec) {
3013 if (forced_codec_name) av_log(NULL, AV_LOG_WARNING,
3014 "No codec could be found with name '%s'\n", forced_codec_name);
3016 "No decoder could be found for codec %s\n", avcodec_get_name(avctx->codec_id));
3017 ret = AVERROR(EINVAL);
3018 goto fail;
3019 }
3020
3021 avctx->codec_id = codec->id;
3022 if (stream_lowres > codec->max_lowres) {
3023 av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
3024 codec->max_lowres);
3025 stream_lowres = codec->max_lowres;
3026 }
3027 avctx->lowres = stream_lowres;
3028
3029 if (fast)
3030 avctx->flags2 |= AV_CODEC_FLAG2_FAST;
3031
3033 ic->streams[stream_index], codec, &opts, NULL);
3034 if (ret < 0)
3035 goto fail;
3036
3037 if (!av_dict_get(opts, "threads", NULL, 0))
3038 av_dict_set(&opts, "threads", "auto", 0);
3039 if (stream_lowres)
3040 av_dict_set_int(&opts, "lowres", stream_lowres, 0);
3041
3042 av_dict_set(&opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
3043
3044 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
3045 ret = create_hwaccel(&avctx->hw_device_ctx);
3046 if (ret < 0)
3047 goto fail;
3048 }
3049
3050 if ((ret = avcodec_open2(avctx, codec, &opts)) < 0) {
3051 goto fail;
3052 }
3054 if (ret < 0)
3055 goto fail;
3056
3057 is->eof = 0;
3058 ic->streams[stream_index]->discard = AVDISCARD_DEFAULT;
3059 switch (avctx->codec_type) {
3060 case AVMEDIA_TYPE_AUDIO:
3061 is->audio_filter_src.freq = avctx->sample_rate;
3062 ret = av_channel_layout_copy(&is->audio_filter_src.ch_layout, &avctx->ch_layout);
3063 if (ret < 0)
3064 goto fail;
3065 is->audio_filter_src.fmt = avctx->sample_fmt;
3066 if ((ret = configure_audio_filters(is, afilters, 0)) < 0)
3067 goto fail;
3068
3069 is->audio_stream = stream_index;
3070
3071 if ((ret = decoder_init(&is->auddec, avctx, &is->audioq, is->continue_read_thread)) < 0)
3072 goto fail;
3073 if (is->ic->iformat->flags & AVFMT_NOTIMESTAMPS) {
3074 is->auddec.start_pts = ic->streams[stream_index]->start_time;
3075 is->auddec.start_pts_tb = ic->streams[stream_index]->time_base;
3076 }
3077 if (!SDL_AtomicGet(&is->replacement) && (ret = audio_start(is)) < 0)
3078 stream_component_close(is, stream_index);
3079 else
3080 is->audio_st = ic->streams[stream_index];
3081 break;
3082 case AVMEDIA_TYPE_VIDEO:
3083 is->video_stream = stream_index;
3084 is->video_st = ic->streams[stream_index];
3085
3086 if (ici->streams[stream_index]->group) {
3087 if ((ret = init_lcevc_graph(ic, stream_index)) < 0)
3088 goto fail;
3089 }
3090 if ((ret = decoder_init(&is->viddec, avctx, &is->videoq, is->continue_read_thread)) < 0)
3091 goto fail;
3092 if ((ret = decoder_start(&is->viddec, video_thread, "video_decoder", is)) < 0)
3093 goto out;
3094 is->queue_attachments_req = 1;
3095 break;
3097 is->subtitle_stream = stream_index;
3098 is->subtitle_st = ic->streams[stream_index];
3099
3100 if ((ret = decoder_init(&is->subdec, avctx, &is->subtitleq, is->continue_read_thread)) < 0)
3101 goto fail;
3102 if ((ret = decoder_start(&is->subdec, subtitle_thread, "subtitle_decoder", is)) < 0)
3103 goto out;
3104 break;
3105 default:
3106 break;
3107 }
3108 goto out;
3109
3110fail:
3111 avcodec_free_context(&avctx);
3112out:
3114
3115 return ret;
3116}
3117
3118static int decode_interrupt_cb(void *ctx)
3119{
3120 VideoState *is = ctx;
3121 return is->abort_request;
3122}
3123
3124static int stream_has_enough_packets(AVStream *st, int stream_id, PacketQueue *queue) {
3125 return stream_id < 0 ||
3126 queue->abort_request ||
3128 queue->nb_packets > MIN_FRAMES && (!queue->duration || av_q2d(st->time_base) * queue->duration > 1.0);
3129}
3130
3132{
3133 if( !strcmp(s->iformat->name, "rtp")
3134 || !strcmp(s->iformat->name, "rtsp")
3135 || !strcmp(s->iformat->name, "sdp")
3136 )
3137 return 1;
3138
3139 if(s->pb && ( !strncmp(s->url, "rtp:", 4)
3140 || !strncmp(s->url, "udp:", 4)
3141 )
3142 )
3143 return 1;
3144 return 0;
3145}
3146
3148 Stream *sti, AVPacket *pkt)
3149{
3150 StreamGroup *stgi = sti->group;
3151 AVBitStreamFilterContext *source = sti->filter;
3152 int ret;
3153
3155 if (ret < 0) {
3156 if (pkt)
3158 av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for filtering: %s\n",
3159 av_err2str(ret));
3160 return ret;
3161 }
3162
3163 while (1) {
3164 ret = av_bsf_sink_get_packet(stgi->sink, pkt, 0);
3165 if (ret == AVERROR(EAGAIN))
3166 return 0;
3167 else if (ret < 0) {
3168 if (ret != AVERROR_EOF)
3170 "Error applying bitstream filters to a packet: %s\n",
3171 av_err2str(ret));
3172 return ret;
3173 }
3174 pkt->time_base = av_bsf_sink_get_time_base(stgi->sink);
3175 packet_queue_put(&is->videoq, pkt);
3176 }
3177
3178 return 0;
3179}
3180
3182{
3183 FormatContext *ici = ic->opaque;
3184 int ret;
3185
3186 for (unsigned i = 0; i < ic->nb_streams; i++) {
3187 Stream *sti = ici->streams[i];
3188 StreamGroup *stgi = sti->group;
3189
3190 if (!stgi || !stgi->graph)
3191 continue;
3192
3193 ret = do_bsf_graph(ic, is, sti, NULL);
3194 ret = (ret == AVERROR_EOF) ? 0 : (ret < 0) ? ret : AVERROR_BUG;
3195 if (ret < 0) {
3196 av_log(NULL, AV_LOG_ERROR, "Error flushing BSFs: %s\n",
3197 av_err2str(ret));
3198 return ret;
3199 }
3200 }
3201
3202 return 0;
3203}
3204
3205/* this thread gets the stream from the disk or the network */
3206static int read_thread(void *arg)
3207{
3208 VideoState *is = arg;
3209 AVFormatContext *ic = NULL;
3210 FormatContext *ici = NULL;
3211 int err, i, ret;
3212 int st_index[AVMEDIA_TYPE_NB];
3213 AVPacket *pkt = NULL;
3214 int64_t stream_start_time;
3215 char metadata_description[96];
3216 int pkt_in_play_range = 0;
3217 int announced = 0;
3218 const AVDictionaryEntry *t;
3219 SDL_mutex *wait_mutex = SDL_CreateMutex();
3220 AVDictionary *format_options = NULL;
3221 int scan_all_pmts_set = 0;
3222 int64_t pkt_ts;
3223
3224 if (!wait_mutex) {
3225 av_log(NULL, AV_LOG_FATAL, "SDL_CreateMutex(): %s\n", SDL_GetError());
3226 ret = AVERROR(ENOMEM);
3227 goto fail;
3228 }
3229
3230 memset(st_index, -1, sizeof(st_index));
3231 is->eof = 0;
3232
3233 pkt = av_packet_alloc();
3234 if (!pkt) {
3235 av_log(NULL, AV_LOG_FATAL, "Could not allocate packet.\n");
3236 ret = AVERROR(ENOMEM);
3237 goto fail;
3238 }
3240 if (!ic) {
3241 av_log(NULL, AV_LOG_FATAL, "Could not allocate context.\n");
3242 ret = AVERROR(ENOMEM);
3243 goto fail;
3244 }
3245 ic->opaque = av_mallocz(sizeof(FormatContext));
3246 if (!ic->opaque) {
3247 av_log(NULL, AV_LOG_FATAL, "Could not allocate internal context.\n");
3248 ret = AVERROR(ENOMEM);
3249 goto fail;
3250 }
3254 if ((ret = av_dict_copy(&format_options, format_opts, 0)) < 0)
3255 goto fail;
3256 if (!av_dict_get(format_options, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
3257 av_dict_set(&format_options, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
3258 scan_all_pmts_set = 1;
3259 }
3260 err = avformat_open_input(&ic, is->filename, is->iformat, &format_options);
3261 if (err < 0) {
3262 print_error(is->filename, err);
3263 ret = -1;
3264 goto fail;
3265 }
3266 if (scan_all_pmts_set)
3267 av_dict_set(&format_options, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
3268 remove_avoptions(&format_options, codec_opts);
3269
3270 ret = check_avoptions(format_options);
3271 if (ret < 0)
3272 goto fail;
3273 is->ic = ic;
3274
3275 if (genpts)
3276 ic->flags |= AVFMT_FLAG_GENPTS;
3277
3278 if (find_stream_info) {
3280 int orig_nb_streams = ic->nb_streams;
3281
3283 if (err < 0) {
3285 "Error setting up avformat_find_stream_info() options\n");
3286 ret = err;
3287 goto fail;
3288 }
3289
3291
3292 for (i = 0; i < orig_nb_streams; i++)
3293 av_dict_free(&opts[i]);
3294 av_freep(&opts);
3295
3296 if (err < 0) {
3298 "%s: could not find codec parameters\n", is->filename);
3299 ret = -1;
3300 goto fail;
3301 }
3302 }
3303
3304 if (ic->pb)
3305 ic->pb->eof_reached = 0; // FIXME hack, ffplay maybe should not use avio_feof() to test for the end
3306
3307 if (is->seek_by_bytes < 0)
3308 is->seek_by_bytes = !(ic->iformat->flags & AVFMT_NO_BYTE_SEEK) &&
3309 !!(ic->iformat->flags & AVFMT_TS_DISCONT) &&
3310 strcmp("ogg", ic->iformat->name);
3311
3312 is->max_frame_duration = (ic->iformat->flags & AVFMT_TS_DISCONT) ? 10.0 : 3600.0;
3313
3314 if (!window_title && (t = av_dict_get(ic->metadata, "title", NULL, 0)))
3315 is->title = av_asprintf("%s - %s", t->value, is->filename);
3316
3317 /* if seeking requested, we execute it */
3318 if (start_time != AV_NOPTS_VALUE) {
3319 int64_t timestamp;
3320
3321 timestamp = start_time;
3322 /* add the stream start time */
3323 if (ic->start_time != AV_NOPTS_VALUE)
3324 timestamp += ic->start_time;
3325 ret = avformat_seek_file(ic, -1, INT64_MIN, timestamp, INT64_MAX, 0);
3326 if (ret < 0) {
3327 av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
3328 is->filename, (double)timestamp / AV_TIME_BASE);
3329 }
3330 }
3331
3332 is->realtime = is_realtime(ic);
3333
3334 if (show_status) {
3335 fprintf(stderr, "\x1b[2K\r");
3336 av_dump_format(ic, 0, is->filename, 0);
3337 }
3338
3339 ici = ic->opaque;
3340 ici->streams = av_calloc(ic->nb_streams, sizeof(*ici->streams));
3341 if (!ici->streams) {
3342 av_log(NULL, AV_LOG_FATAL, "Could not allocate internal streams context.\n");
3343 ret = AVERROR(ENOMEM);
3344 goto fail;
3345 }
3346 ici->nb_streams = ic->nb_streams;
3347 for (i = 0; i < ic->nb_streams; i++) {
3348 AVStream *st = ic->streams[i];
3349 enum AVMediaType type = st->codecpar->codec_type;
3350 ici->streams[i] = av_mallocz(sizeof(Stream));
3351 if (!ici->streams[i]) {
3352 av_log(NULL, AV_LOG_FATAL, "Could not allocate internal stream context.\n");
3353 ret = AVERROR(ENOMEM);
3354 goto fail;
3355 }
3356 st->discard = AVDISCARD_ALL;
3357 if (type >= 0 && wanted_stream_spec[type] && st_index[type] == -1)
3359 st_index[type] = i;
3360 // Clear all pre-existing metadata update flags to avoid printing
3361 // initial metadata as update.
3363 }
3364 ici->stream_groups = av_calloc(ic->nb_stream_groups, sizeof(*ici->stream_groups));
3365 if (!ici->stream_groups) {
3366 av_log(NULL, AV_LOG_FATAL, "Could not allocate internal stream groups context.\n");
3367 ret = AVERROR(ENOMEM);
3368 goto fail;
3369 }
3371 for (i = 0; i < ic->nb_stream_groups; i++) {
3372 AVStreamGroup *stg = ic->stream_groups[i];
3373
3374 ici->stream_groups[i] = av_mallocz(sizeof(*ici->stream_groups[i]));
3375 if (!ici->stream_groups[i]) {
3376 av_log(NULL, AV_LOG_FATAL, "Could not allocate internal stream group.\n");
3377 ret = AVERROR(ENOMEM);
3378 goto fail;
3379 }
3380 ici->stream_groups[i]->stg = stg;
3381
3383 continue;
3384 if (!av_bsf_get_by_name("lcevc_merge") || stg->nb_entries != 2)
3385 continue;
3386 for (int j = 0; j < stg->nb_entries; j++) {
3387 AVStreamGroupEntry *entry = stg->entries[j];
3388 if (entry->type != AV_STREAM_GROUP_ENTRY_STREAM) {
3389 ret = AVERROR_BUG;
3390 goto fail;
3391 }
3392 }
3393
3395 const AVStream *base_st = ic->streams[stg->entries[!lcevc->el_index]->stream->index];
3396 Stream *base_sti = ici->streams[base_st->index];
3397
3398 base_sti->group = ici->stream_groups[i];
3399 }
3401 for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
3402 if (wanted_stream_spec[i] && st_index[i] == -1) {
3403 av_log(NULL, AV_LOG_ERROR, "Stream specifier %s does not match any %s stream\n", wanted_stream_spec[i], av_get_media_type_string(i));
3404 st_index[i] = INT_MAX;
3405 }
3406 }
3407
3408 if (!video_disable)
3409 st_index[AVMEDIA_TYPE_VIDEO] =
3411 st_index[AVMEDIA_TYPE_VIDEO], -1, NULL, 0);
3412 if (!audio_disable)
3413 st_index[AVMEDIA_TYPE_AUDIO] =
3415 st_index[AVMEDIA_TYPE_AUDIO],
3416 st_index[AVMEDIA_TYPE_VIDEO],
3417 NULL, 0);
3419 st_index[AVMEDIA_TYPE_SUBTITLE] =
3421 st_index[AVMEDIA_TYPE_SUBTITLE],
3422 (st_index[AVMEDIA_TYPE_AUDIO] >= 0 ?
3423 st_index[AVMEDIA_TYPE_AUDIO] :
3424 st_index[AVMEDIA_TYPE_VIDEO]),
3425 NULL, 0);
3426
3427 is->show_mode = show_mode;
3428 if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) {
3429 AVStream *st = ic->streams[st_index[AVMEDIA_TYPE_VIDEO]];
3430 AVCodecParameters *codecpar = st->codecpar;
3432 if (codecpar->width)
3433 set_default_window_size(codecpar->width, codecpar->height, sar);
3434 }
3435
3436 /* open the streams */
3437 if (st_index[AVMEDIA_TYPE_AUDIO] >= 0) {
3439 }
3440
3441 ret = -1;
3442 if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) {
3444 }
3445 if (is->show_mode == SHOW_MODE_NONE)
3446 is->show_mode = ret >= 0 ? SHOW_MODE_VIDEO : SHOW_MODE_RDFT;
3447
3448 if (st_index[AVMEDIA_TYPE_SUBTITLE] >= 0) {
3450 }
3451
3452 if (is->video_stream < 0 && is->audio_stream < 0) {
3453 av_log(NULL, AV_LOG_FATAL, "Failed to open file '%s' or configure filtergraph\n",
3454 is->filename);
3455 ret = -1;
3456 goto fail;
3457 }
3458 if (is->video_stream < 0)
3460
3461 if (is->infinite_buffer < 0 && is->realtime)
3462 is->infinite_buffer = 1;
3463
3464 for (;;) {
3465 if (is->abort_request)
3466 break;
3467 if (is->paused != is->last_paused) {
3468 is->last_paused = is->paused;
3469 if (is->paused)
3470 is->read_pause_return = av_read_pause(ic);
3471 else
3472 av_read_play(ic);
3473 }
3474#if CONFIG_RTSP_DEMUXER || CONFIG_MMSH_PROTOCOL
3475 if (is->paused &&
3476 (!strcmp(ic->iformat->name, "rtsp") ||
3477 (ic->pb && !strncmp(is->filename, "mmsh:", 5)))) {
3478 /* wait 10 ms to avoid trying to get another packet */
3479 /* XXX: horrible */
3480 SDL_Delay(10);
3481 continue;
3482 }
3483#endif
3484 if (is->seek_req) {
3485 int64_t seek_target = is->seek_pos;
3486 int64_t seek_min = is->seek_rel > 0 ? seek_target - is->seek_rel + 2: INT64_MIN;
3487 int64_t seek_max = is->seek_rel < 0 ? seek_target - is->seek_rel - 2: INT64_MAX;
3488// FIXME the +-2 is due to rounding being not done in the correct direction in generation
3489// of the seek_pos/seek_rel variables
3490
3491 ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, is->seek_flags);
3492 if (ret < 0) {
3494 "%s: error while seeking\n", is->ic->url);
3495 } else {
3496 if (is->audio_stream >= 0)
3497 packet_queue_flush(&is->audioq);
3498 if (is->subtitle_stream >= 0)
3499 packet_queue_flush(&is->subtitleq);
3500 if (is->video_stream >= 0) {
3501 packet_queue_flush(&is->videoq);
3502 uninit_bsf_graph(is->ic, is->video_stream);
3503 if (ici->streams[is->video_stream]->group) {
3504 if ((ret = init_lcevc_graph(is->ic, is->video_stream)) < 0)
3505 goto fail;
3506 }
3507 }
3508 if (is->seek_flags & AVSEEK_FLAG_BYTE) {
3509 set_clock(&is->extclk, NAN, 0);
3510 } else {
3511 set_clock(&is->extclk, seek_target / (double)AV_TIME_BASE, 0);
3512 }
3513 }
3514 is->seek_req = 0;
3515 is->queue_attachments_req = 1;
3516 is->eof = 0;
3517 if (is->paused)
3519 }
3520 if (is->queue_attachments_req) {
3521 if (is->video_st && is->video_st->disposition & AV_DISPOSITION_ATTACHED_PIC) {
3522 if ((ret = av_packet_ref(pkt, &is->video_st->attached_pic)) < 0)
3523 goto fail;
3524 packet_queue_put(&is->videoq, pkt);
3525 packet_queue_put_nullpacket(&is->videoq, pkt, is->video_stream);
3526 }
3527 is->queue_attachments_req = 0;
3528 }
3529
3530 /* if the queue are full, no need to read more */
3531 if (is->infinite_buffer < 1 &&
3532 (is->audioq.size + is->videoq.size + is->subtitleq.size > MAX_QUEUE_SIZE
3533 || (stream_has_enough_packets(is->audio_st, is->audio_stream, &is->audioq) &&
3534 stream_has_enough_packets(is->video_st, is->video_stream, &is->videoq) &&
3535 stream_has_enough_packets(is->subtitle_st, is->subtitle_stream, &is->subtitleq)))) {
3536 if (!announced && SDL_AtomicGet(&is->replacement) && is->audioq.size + is->videoq.size + is->subtitleq.size > MAX_QUEUE_SIZE) {
3538 announced = 1;
3539 }
3540 /* wait 10 ms */
3541 SDL_LockMutex(wait_mutex);
3542 SDL_CondWaitTimeout(is->continue_read_thread, wait_mutex, 10);
3543 SDL_UnlockMutex(wait_mutex);
3544 continue;
3545 }
3546 if (!is->paused &&
3547 (!is->audio_st || (is->auddec.finished == is->audioq.serial && frame_queue_nb_remaining(&is->sampq) == 0)) &&
3548 (!is->video_st || (is->viddec.finished == is->videoq.serial && frame_queue_nb_remaining(&is->pictq) == 0))) {
3549 if (is->loop != 1 && (!is->loop || --is->loop)) {
3551 } else if (autoexit) {
3552 ret = AVERROR_EOF;
3553 goto fail;
3554 }
3555 }
3556 ret = av_read_frame(ic, pkt);
3557 if (ret < 0) {
3558 if ((ret == AVERROR_EOF || avio_feof(ic->pb)) && !is->eof) {
3559 if (is->video_stream >= 0) {
3560 ret = do_bsf_flush(ic, is);
3561 if (ret < 0)
3562 goto fail;
3563 packet_queue_put_nullpacket(&is->videoq, pkt, is->video_stream);
3564 }
3565 if (is->audio_stream >= 0)
3566 packet_queue_put_nullpacket(&is->audioq, pkt, is->audio_stream);
3567 if (is->subtitle_stream >= 0)
3568 packet_queue_put_nullpacket(&is->subtitleq, pkt, is->subtitle_stream);
3569 is->eof = 1;
3570 }
3571 if (ic->pb && ic->pb->error) {
3572 if (autoexit)
3573 goto fail;
3574 else
3575 break;
3576 }
3577 SDL_LockMutex(wait_mutex);
3578 SDL_CondWaitTimeout(is->continue_read_thread, wait_mutex, 10);
3579 SDL_UnlockMutex(wait_mutex);
3580 continue;
3581 } else {
3582 is->eof = 0;
3583 }
3584
3585 if (show_status) {
3587 fprintf(stderr, "\x1b[2K\r");
3589 "\r New metadata", " ", AV_LOG_INFO);
3590 }
3591 if (ic->streams[pkt->stream_index]->event_flags &
3593 fprintf(stderr, "\x1b[2K\r");
3594 snprintf(metadata_description,
3595 sizeof(metadata_description),
3596 "\r New metadata for stream %d",
3597 pkt->stream_index);
3598 dump_dictionary(NULL, ic->streams[pkt->stream_index]->metadata,
3599 metadata_description, " ", AV_LOG_INFO);
3600 }
3601 }
3604
3605 /* check if packet is in play range specified by user, then queue, otherwise discard */
3606 stream_start_time = ic->streams[pkt->stream_index]->start_time;
3607 pkt_ts = pkt->pts == AV_NOPTS_VALUE ? pkt->dts : pkt->pts;
3608 pkt_in_play_range = duration == AV_NOPTS_VALUE ||
3609 (pkt_ts - (stream_start_time != AV_NOPTS_VALUE ? stream_start_time : 0)) *
3610 av_q2d(ic->streams[pkt->stream_index]->time_base) -
3611 (double)(start_time != AV_NOPTS_VALUE ? start_time : 0) / 1000000
3612 <= ((double)duration / 1000000);
3613 if (pkt->stream_index == is->audio_stream && pkt_in_play_range) {
3614 packet_queue_put(&is->audioq, pkt);
3615 } else if (pkt->stream_index == is->video_stream && pkt_in_play_range
3616 && !(is->video_st->disposition & AV_DISPOSITION_ATTACHED_PIC)) {
3617 Stream *sti = ici->streams[is->video_stream];
3618 StreamGroup *stgi = sti->group;
3619 if (stgi && stgi->graph) {
3620 ret = do_bsf_graph(ic, is, sti, pkt);
3621 if (ret < 0)
3622 goto fail;
3623 } else
3624 packet_queue_put(&is->videoq, pkt);
3625 } else if (pkt->stream_index == is->subtitle_stream && pkt_in_play_range) {
3626 packet_queue_put(&is->subtitleq, pkt);
3627 } else {
3628 Stream *sti = ici->streams[pkt->stream_index];
3629 StreamGroup *stgi = sti->group;
3630 if (stgi && stgi->graph) {
3631 ret = do_bsf_graph(ic, is, sti, pkt);
3632 if (ret < 0)
3633 goto fail;
3634 }
3636 }
3637 }
3638
3639 ret = 0;
3640 fail:
3641 if (ic && !is->ic) {
3642 av_freep(&ic->opaque);
3644 }
3645 av_dict_free(&format_options);
3646
3648 if (ret != 0)
3650 SDL_DestroyMutex(wait_mutex);
3651 return 0;
3652}
3653
3654/* replaced is the stream playing which the new one is to replace, NULL for none; the replacement starts paused with
3655 * the volume of the stream it replaces, and opens no audio device before stream_replace() */
3656static VideoState *stream_open(const char *filename,
3657 const AVInputFormat *iformat, const VideoState *replaced)
3658{
3659 VideoState *is;
3660
3661 is = av_mallocz(sizeof(VideoState));
3662 if (!is)
3663 return NULL;
3664 is->last_video_stream = is->video_stream = -1;
3665 is->last_audio_stream = is->audio_stream = -1;
3666 is->last_subtitle_stream = is->subtitle_stream = -1;
3667 is->filename = av_strdup(filename);
3668 is->id = ++last_stream_id;
3669 if (!is->filename)
3670 goto fail;
3671 is->iformat = iformat;
3672 is->seek_by_bytes = seek_by_bytes;
3673 is->infinite_buffer = infinite_buffer;
3674 is->loop = loop;
3675 is->ytop = 0;
3676 is->xleft = 0;
3677
3678 /* start video display */
3679 if (frame_queue_init(&is->pictq, &is->videoq, VIDEO_PICTURE_QUEUE_SIZE, 1) < 0)
3680 goto fail;
3681 if (frame_queue_init(&is->subpq, &is->subtitleq, SUBPICTURE_QUEUE_SIZE, 0) < 0)
3682 goto fail;
3683 if (frame_queue_init(&is->sampq, &is->audioq, SAMPLE_QUEUE_SIZE, 1) < 0)
3684 goto fail;
3685
3686 if (packet_queue_init(&is->videoq) < 0 ||
3687 packet_queue_init(&is->audioq) < 0 ||
3688 packet_queue_init(&is->subtitleq) < 0)
3689 goto fail;
3690
3691 if (!(is->continue_read_thread = SDL_CreateCond())) {
3692 av_log(NULL, AV_LOG_FATAL, "SDL_CreateCond(): %s\n", SDL_GetError());
3693 goto fail;
3694 }
3695
3696 init_clock(&is->vidclk, &is->videoq.serial);
3697 init_clock(&is->audclk, &is->audioq.serial);
3698 init_clock(&is->extclk, &is->extclk.serial);
3699 is->audio_clock_serial = -1;
3700 if (startup_volume < 0)
3701 av_log(NULL, AV_LOG_WARNING, "-volume=%d < 0, setting to 0\n", startup_volume);
3702 if (startup_volume > 100)
3703 av_log(NULL, AV_LOG_WARNING, "-volume=%d > 100, setting to 100\n", startup_volume);
3704 if (video_background) {
3705 if (!strcmp(video_background, "none")) {
3706 is->render_params.video_background_type = VIDEO_BACKGROUND_NONE;
3707 } else if (strcmp(video_background, "tiles")) {
3708 if (av_parse_color(is->render_params.video_background_color, video_background, -1, NULL) >= 0)
3709 is->render_params.video_background_type = VIDEO_BACKGROUND_COLOR;
3710 else
3711 goto fail;
3712 }
3713 }
3714 is->audio_volume = SDL_MIX_MAXVOLUME * av_clip(startup_volume, 0, 100) / 100;
3715 is->muted = 0;
3716 if (replaced) {
3717 SDL_AtomicSet(&is->replacement, 1);
3718 is->audio_volume = replaced->audio_volume;
3719 is->muted = replaced->muted;
3720 is->paused = is->audclk.paused = is->vidclk.paused = is->extclk.paused = 1;
3721 }
3722 is->av_sync_type = av_sync_type;
3723 is->read_tid = SDL_CreateThread(read_thread, "read_thread", is);
3724 if (!is->read_tid) {
3725 av_log(NULL, AV_LOG_FATAL, "SDL_CreateThread(): %s\n", SDL_GetError());
3726fail:
3728 return NULL;
3729 }
3730 return is;
3731}
3732
3734{
3735 AVFormatContext *ic = is->ic;
3736 int start_index, stream_index;
3737 int old_index;
3738 AVStream *st;
3739 AVProgram *p = NULL;
3740 int nb_streams = is->ic->nb_streams;
3741
3743 start_index = is->last_video_stream;
3744 old_index = is->video_stream;
3745 } else if (codec_type == AVMEDIA_TYPE_AUDIO) {
3746 start_index = is->last_audio_stream;
3747 old_index = is->audio_stream;
3748 } else {
3749 start_index = is->last_subtitle_stream;
3750 old_index = is->subtitle_stream;
3751 }
3752 stream_index = start_index;
3753
3754 if (codec_type != AVMEDIA_TYPE_VIDEO && is->video_stream != -1) {
3755 p = av_find_program_from_stream(ic, NULL, is->video_stream);
3756 if (p) {
3757 nb_streams = p->nb_stream_indexes;
3758 for (start_index = 0; start_index < nb_streams; start_index++)
3759 if (p->stream_index[start_index] == stream_index)
3760 break;
3761 if (start_index == nb_streams)
3762 start_index = -1;
3763 stream_index = start_index;
3764 }
3765 }
3766
3767 for (;;) {
3768 if (++stream_index >= nb_streams)
3769 {
3771 {
3772 stream_index = -1;
3773 is->last_subtitle_stream = -1;
3774 goto the_end;
3775 }
3776 if (start_index == -1)
3777 return;
3778 stream_index = 0;
3779 }
3780 if (stream_index == start_index)
3781 return;
3782 st = is->ic->streams[p ? p->stream_index[stream_index] : stream_index];
3783 if (st->codecpar->codec_type == codec_type) {
3784 /* check that parameters are OK */
3785 switch (codec_type) {
3786 case AVMEDIA_TYPE_AUDIO:
3787 if (st->codecpar->sample_rate != 0 &&
3788 st->codecpar->ch_layout.nb_channels != 0)
3789 goto the_end;
3790 break;
3791 case AVMEDIA_TYPE_VIDEO:
3793 goto the_end;
3794 default:
3795 break;
3796 }
3797 }
3798 }
3799 the_end:
3800 if (p && stream_index != -1)
3801 stream_index = p->stream_index[stream_index];
3802 av_log(NULL, AV_LOG_INFO, "Switch %s stream from #%d to #%d\n",
3804 old_index,
3805 stream_index);
3806
3807 stream_component_close(is, old_index);
3808 stream_component_open(is, stream_index);
3809}
3810
3811
3813{
3815 SDL_SetWindowFullscreen(window, is_full_screen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
3816}
3817
3819{
3820 int next = is->show_mode;
3821 do {
3822 next = (next + 1) % SHOW_MODE_NB;
3823 } while (next != is->show_mode && (next == SHOW_MODE_VIDEO && !is->video_st || next != SHOW_MODE_VIDEO && !is->audio_st));
3824 if (is->show_mode != next) {
3825 is->force_refresh = 1;
3826 is->show_mode = next;
3827 }
3828}
3829
3830static void refresh_loop_wait_event(VideoState *is, SDL_Event *event) {
3831 double remaining_time = 0.0;
3832 SDL_PumpEvents();
3833 while (!SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT)) {
3834 if (received_sigterm) {
3835 exit_status = 123;
3836 do_exit(is);
3837 }
3839 SDL_ShowCursor(0);
3840 cursor_hidden = 1;
3841 }
3842 if (remaining_time > 0.0) {
3843 if (!wait_for_events)
3844 av_usleep((int64_t)(remaining_time * 1000000.0));
3845 else if (SDL_WaitEventTimeout(NULL, ceil(remaining_time * 1000)))
3846 continue;
3847 }
3848 remaining_time = REFRESH_RATE;
3851 if (dir_thread && SDL_AtomicGet(&dir_request.done))
3854 is->force_refresh = 1;
3855 if (is->show_mode != SHOW_MODE_NONE && (!is->paused || is->force_refresh))
3856 video_refresh(is, &remaining_time);
3857 SDL_PumpEvents();
3858 }
3859}
3860
3861/* index of the chapter containing the current playback position, -1 before the first one */
3863{
3865 int i;
3866
3867 for (i = 0; i < is->ic->nb_chapters; i++) {
3868 AVChapter *ch = is->ic->chapters[i];
3869 if (av_compare_ts(pos, AV_TIME_BASE_Q, ch->start, ch->time_base) < 0)
3870 break;
3871 }
3872 return i - 1;
3873}
3874
3875static void seek_chapter(VideoState *is, int i)
3876{
3877 i = FFMAX(i, 0);
3878 chapter_list_show(is, FFMIN(i, is->ic->nb_chapters - 1));
3879 if (i >= is->ic->nb_chapters)
3880 return;
3881
3882 av_log(NULL, AV_LOG_VERBOSE, "Seeking to chapter %d.\n", i);
3883 stream_seek(is, av_rescale_q(is->ic->chapters[i]->start, is->ic->chapters[i]->time_base,
3884 AV_TIME_BASE_Q), 0, 0);
3885}
3886
3887/* shows the files of the directory with the entry selected */
3888static int file_list_show(DirList *dl, int selected)
3889{
3890 int ret;
3891
3892 if (!list_shows_files)
3894 ret = list_view_show(list, dl->entries, dl->nb_entries, selected);
3895 if (ret >= 0)
3896 list_shows_files = 1;
3897 return ret;
3898}
3899
3900/* opens the file to replace the stream playing once it can play */
3901static void file_play(VideoState *is, const char *path)
3902{
3903 if (next_stream)
3906 av_log(NULL, AV_LOG_ERROR, "Could not open '%s'\n", path);
3907}
3908
3909static int dir_interrupt_cb(void *ctx)
3910{
3911 return SDL_AtomicGet(&dir_request.abort);
3912}
3913
3914static int dir_thread_func(void *arg)
3915{
3917
3919 SDL_AtomicSet(&dir_request.done, 1);
3920 return 0;
3921}
3922
3923/* starts reading the directory on dir_thread, unless it is busy; with play_if_no_dir the path is played when it is no
3924 * directory */
3925static void file_list_read(const char *path, int play_if_no_dir)
3926{
3927 int ret = 0;
3928
3929 if (dir_thread) {
3930 av_log(NULL, AV_LOG_VERBOSE, "Not listing '%s' while '%s' is being read\n", path, dir_request.path);
3931 return;
3932 }
3933 dir_request.play_if_no_dir = play_if_no_dir;
3934 dir_request.cancelled = 0;
3935 SDL_AtomicSet(&dir_request.abort, 0);
3936 SDL_AtomicSet(&dir_request.done, 0);
3937 if (!(dir_request.path = av_strdup(path)))
3938 ret = AVERROR(ENOMEM);
3939 else
3940 ret = av_dict_copy(&dir_request.options, format_opts, 0);
3941 if (ret < 0 || !(dir_thread = SDL_CreateThread(dir_thread_func, "dir_reader", NULL))) {
3942 av_log(NULL, AV_LOG_ERROR, "Could not list the directory '%s': %s\n", path, ret < 0 ? av_err2str(ret) : SDL_GetError());
3943 av_freep(&dir_request.path);
3944 av_dict_free(&dir_request.options);
3945 }
3946}
3947
3948/* takes over what dir_thread read: shows the directory, plays the path when it is no directory, or drops the result of
3949 * a cancelled request */
3951{
3952 int ret;
3953
3954 SDL_WaitThread(dir_thread, NULL);
3955 dir_thread = NULL;
3956 av_dict_free(&dir_request.options);
3957 if (dir_request.cancelled) {
3959 } else if (dir_request.ret < 0) {
3960 av_log(NULL, dir_request.play_if_no_dir ? AV_LOG_VERBOSE : AV_LOG_ERROR, "Could not list the directory '%s': %s\n",
3962 if (dir_request.play_if_no_dir)
3963 file_play(is, dir_request.path);
3964 } else if ((ret = file_list_show(dir_request.dl, 0)) < 0) {
3965 av_log(NULL, AV_LOG_ERROR, "Could not show the list: %s\n", av_err2str(ret));
3967 } else {
3969 dir_list = dir_request.dl;
3970 dir_request.dl = NULL;
3972 list_view_pin(list, 1);
3973 }
3974 av_freep(&dir_request.path);
3975}
3976
3977/* pins the file list, showing the directory listed last or else the directory of the input */
3979{
3980 const char *name = is->filename, *dir;
3981 char *path;
3982
3983 if (dir_list) {
3984 if (file_list_show(dir_list, -1) >= 0)
3985 list_view_pin(list, 1);
3986 return;
3987 }
3988 av_strstart(name, "file:", &name);
3989 if (!(path = av_strdup(name)))
3990 return;
3991 dir = av_dirname(path);
3992 file_list_read(*dir ? dir : "/", 0);
3993 av_free(path);
3994}
3995
3996/* lists the chosen directory, or plays the chosen file */
3998{
3999 char *path = dir_list_path(dir_list, entry);
4000
4001 if (!path)
4002 return;
4003 if (entry < dir_list->nb_dirs + dir_list->nb_maybe_dirs)
4004 file_list_read(path, entry >= dir_list->nb_dirs);
4005 else
4006 file_play(is, path);
4007 av_free(path);
4008}
4009
4010static void list_choose(VideoState *is, int entry)
4011{
4012 if (list_shows_files)
4014 else
4016}
4017
4018/* plays next_stream instead of the stream playing, which goes on from its position when next_stream has no video and
4019 * its audio cannot play */
4021{
4022 int audio_stream = is->audio_stream;
4023 double pos = get_master_clock(is);
4024
4026 SDL_AtomicSet(&next_stream->replacement, 0);
4027 if (next_stream->audio_stream >= 0 && audio_start(next_stream) < 0) {
4029 if (next_stream->video_stream < 0) {
4030 av_log(NULL, AV_LOG_ERROR, "Could not play '%s'\n", next_stream->filename);
4032 next_stream = NULL;
4034 av_log(NULL, AV_LOG_ERROR, "Could not reopen the audio of '%s'\n", is->filename);
4035 if (!is->seek_by_bytes && !isnan(pos))
4036 stream_seek(is, (int64_t)(pos * AV_TIME_BASE), 0, 0);
4037 return is;
4038 }
4039 }
4040 /* the chapter entries belong to the stream closed */
4041 if (!list_shows_files)
4043 list_view_pin(list, 0);
4044 next_stream->width = is->width;
4045 next_stream->height = is->height;
4047 is = next_stream;
4048 next_stream = NULL;
4049 SDL_SetWindowTitle(window, window_title ? window_title : is->title ? is->title : is->filename);
4051 return is;
4052}
4053
4054/* handle an event sent by the GUI */
4055static void event_loop(VideoState *cur_stream)
4056{
4057 SDL_Event event;
4058 double incr, pos, frac;
4059 int chosen;
4060
4061 for (;;) {
4062 double x;
4063 refresh_loop_wait_event(cur_stream, &event);
4064 switch (event.type) {
4065 case SDL_KEYDOWN:
4067 (event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_q))) {
4068 do_exit(cur_stream);
4069 break;
4070 }
4071 // If we don't yet have a window, skip all key events, because read_thread might still be initializing...
4072 if (!cur_stream->width)
4073 continue;
4074 if (list_view_pinned(list)) {
4075 if (!list_shows_files && (event.key.keysym.sym == SDLK_PAGEUP || event.key.keysym.sym == SDLK_PAGEDOWN))
4076 seek_chapter(cur_stream, current_chapter(cur_stream) + (event.key.keysym.sym == SDLK_PAGEUP ? 1 : -1));
4077 else if ((chosen = list_view_key(list, event.key.keysym.sym)) >= 0)
4078 list_choose(cur_stream, chosen);
4079 /* escape while a directory is being read for the list */
4080 if (dir_thread && !list_view_pinned(list)) {
4081 dir_request.cancelled = 1;
4082 SDL_AtomicSet(&dir_request.abort, 1);
4083 }
4084 break;
4085 }
4086 switch (event.key.keysym.sym) {
4087 case SDLK_f:
4088 toggle_full_screen(cur_stream);
4089 cur_stream->force_refresh = 1;
4090 break;
4091 case SDLK_p:
4092 case SDLK_SPACE:
4093 toggle_pause(cur_stream);
4094 break;
4095 case SDLK_m:
4096 toggle_mute(cur_stream);
4097 break;
4098 case SDLK_KP_MULTIPLY:
4099 case SDLK_0:
4100 update_volume(cur_stream, 1, SDL_VOLUME_STEP);
4101 break;
4102 case SDLK_KP_DIVIDE:
4103 case SDLK_9:
4104 update_volume(cur_stream, -1, SDL_VOLUME_STEP);
4105 break;
4106 case SDLK_s: // S: Step to next frame
4107 step_to_next_frame(cur_stream);
4108 break;
4109 case SDLK_a:
4111 break;
4112 case SDLK_v:
4114 break;
4115 case SDLK_c:
4119 break;
4120 case SDLK_t:
4122 break;
4123 case SDLK_l:
4124 list_key = cur_stream->ic->nb_chapters > 0 ? SDLK_l : 0;
4125 break;
4126 case SDLK_o:
4127 list_key = SDLK_o;
4128 break;
4129 case SDLK_RETURN:
4130 case SDLK_KP_ENTER:
4131 if (list_view_visible(list) && (chosen = list_view_selected(list)) >= 0)
4132 list_choose(cur_stream, chosen);
4133 break;
4134 case SDLK_w:
4135 if (cur_stream->show_mode == SHOW_MODE_VIDEO && cur_stream->vfilter_idx < nb_vfilters - 1) {
4136 if (++cur_stream->vfilter_idx >= nb_vfilters)
4137 cur_stream->vfilter_idx = 0;
4138 } else {
4139 cur_stream->vfilter_idx = 0;
4140 toggle_audio_display(cur_stream);
4141 }
4142 break;
4143 case SDLK_PAGEUP:
4144 if (cur_stream->ic->nb_chapters <= 1) {
4145 incr = 600.0;
4146 goto do_seek;
4147 }
4148 seek_chapter(cur_stream, current_chapter(cur_stream) + 1);
4149 break;
4150 case SDLK_PAGEDOWN:
4151 if (cur_stream->ic->nb_chapters <= 1) {
4152 incr = -600.0;
4153 goto do_seek;
4154 }
4155 seek_chapter(cur_stream, current_chapter(cur_stream) - 1);
4156 break;
4157 case SDLK_LEFT:
4158 incr = seek_interval ? -seek_interval : -10.0;
4159 goto do_seek;
4160 case SDLK_RIGHT:
4161 incr = seek_interval ? seek_interval : 10.0;
4162 goto do_seek;
4163 case SDLK_UP:
4164 incr = 60.0;
4165 goto do_seek;
4166 case SDLK_DOWN:
4167 incr = -60.0;
4168 do_seek:
4169 if (cur_stream->seek_by_bytes) {
4170 pos = -1;
4172 pos = frame_queue_last_pos(&cur_stream->pictq);
4174 pos = frame_queue_last_pos(&cur_stream->sampq);
4175 if (pos < 0)
4176 pos = avio_tell(cur_stream->ic->pb);
4177 if (cur_stream->ic->bit_rate)
4178 incr *= cur_stream->ic->bit_rate / 8.0;
4179 else
4180 incr *= 180000.0;
4181 pos += incr;
4182 stream_seek(cur_stream, pos, incr, 1);
4183 } else {
4184 pos = get_master_clock(cur_stream);
4185 if (isnan(pos))
4186 pos = (double)cur_stream->seek_pos / AV_TIME_BASE;
4187 pos += incr;
4188 if (cur_stream->ic->start_time != AV_NOPTS_VALUE && pos < cur_stream->ic->start_time / (double)AV_TIME_BASE)
4189 pos = cur_stream->ic->start_time / (double)AV_TIME_BASE;
4190 stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), (int64_t)(incr * AV_TIME_BASE), 0);
4191 }
4192 break;
4193 default:
4194 break;
4195 }
4196 break;
4197 case SDL_KEYUP:
4198 /* on the release of a press made while unpinned, so that the key's own text input does not start the search */
4199 if (list_key && event.key.keysym.sym == list_key) {
4200 if (list_key == SDLK_o)
4201 file_list_open(cur_stream);
4202 else
4203 chapter_list_pin(cur_stream);
4204 }
4205 list_key = 0;
4206 break;
4207 case SDL_TEXTINPUT:
4209 list_view_text(list, event.text.text);
4210 break;
4211 case SDL_MOUSEWHEEL:
4213 list_view_move(list, -event.wheel.y);
4214 break;
4215 case SDL_MOUSEBUTTONDOWN:
4216 if (exit_on_mousedown) {
4217 do_exit(cur_stream);
4218 break;
4219 }
4220 if (event.button.button == SDL_BUTTON_LEFT && list_view_visible(list) &&
4221 list_view_click(list, event.button.x, event.button.y, &chosen)) {
4222 if (chosen >= 0)
4223 list_choose(cur_stream, chosen);
4224 break;
4225 }
4226 if (event.button.button == SDL_BUTTON_LEFT) {
4227 static int64_t last_mouse_left_click = 0;
4228 if (av_gettime_relative() - last_mouse_left_click <= 500000) {
4229 toggle_full_screen(cur_stream);
4230 cur_stream->force_refresh = 1;
4231 last_mouse_left_click = 0;
4232 } else {
4233 last_mouse_left_click = av_gettime_relative();
4234 }
4235 }
4237 case SDL_MOUSEMOTION:
4238 if (cursor_hidden) {
4239 SDL_ShowCursor(1);
4240 cursor_hidden = 0;
4241 }
4243 if (event.type == SDL_MOUSEMOTION)
4244 list_view_hover(list, event.motion.x, event.motion.y);
4245 if (event.type == SDL_MOUSEBUTTONDOWN) {
4246 if (event.button.button != SDL_BUTTON_RIGHT)
4247 break;
4248 x = event.button.x;
4249 } else {
4250 if (!(event.motion.state & SDL_BUTTON_RMASK))
4251 break;
4252 x = event.motion.x;
4253 }
4254 if (cur_stream->seek_by_bytes || cur_stream->ic->duration <= 0) {
4255 uint64_t size = avio_size(cur_stream->ic->pb);
4256 stream_seek(cur_stream, size*x/cur_stream->width, 0, 1);
4257 } else {
4258 int64_t ts;
4259 int ns, hh, mm, ss;
4260 int tns, thh, tmm, tss;
4261 tns = cur_stream->ic->duration / 1000000LL;
4262 thh = tns / 3600;
4263 tmm = (tns % 3600) / 60;
4264 tss = (tns % 60);
4265 frac = x / cur_stream->width;
4266 ns = frac * tns;
4267 hh = ns / 3600;
4268 mm = (ns % 3600) / 60;
4269 ss = (ns % 60);
4271 "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100,
4272 hh, mm, ss, thh, tmm, tss);
4273 ts = frac * cur_stream->ic->duration;
4274 if (cur_stream->ic->start_time != AV_NOPTS_VALUE)
4275 ts += cur_stream->ic->start_time;
4276 stream_seek(cur_stream, ts, 0, 0);
4277 }
4278 break;
4279 case SDL_WINDOWEVENT:
4280 switch (event.window.event) {
4281 case SDL_WINDOWEVENT_LEAVE:
4282 list_view_hover(list, -1, -1);
4283 break;
4284 case SDL_WINDOWEVENT_SIZE_CHANGED:
4285 screen_width = cur_stream->width = event.window.data1;
4286 screen_height = cur_stream->height = event.window.data2;
4287 if (cur_stream->vis_texture) {
4288 SDL_DestroyTexture(cur_stream->vis_texture);
4289 cur_stream->vis_texture = NULL;
4290 }
4292 if (vk_renderer)
4295 case SDL_WINDOWEVENT_EXPOSED:
4296 cur_stream->force_refresh = 1;
4297 }
4298 break;
4299 case FF_READY_EVENT:
4300 if (next_stream && event.user.code == next_stream->id)
4301 cur_stream = stream_replace(cur_stream);
4302 break;
4303 case FF_QUIT_EVENT:
4304 if (next_stream && event.user.code == next_stream->id) {
4305 av_log(NULL, AV_LOG_ERROR, "Could not play '%s'\n", next_stream->filename);
4307 next_stream = NULL;
4308 }
4309 if (event.user.code != cur_stream->id)
4310 break;
4312 case SDL_QUIT:
4313 do_exit(cur_stream);
4314 break;
4315 default:
4316 break;
4317 }
4318 }
4319}
4320
4321static int opt_width(void *optctx, const char *opt, const char *arg)
4322{
4323 double num;
4324 int ret = parse_number(opt, arg, OPT_TYPE_INT64, 1, INT_MAX, &num);
4325 if (ret < 0)
4326 return ret;
4327
4328 screen_width = num;
4329 return 0;
4330}
4331
4332static int opt_height(void *optctx, const char *opt, const char *arg)
4333{
4334 double num;
4335 int ret = parse_number(opt, arg, OPT_TYPE_INT64, 1, INT_MAX, &num);
4336 if (ret < 0)
4337 return ret;
4338
4340 return 0;
4341}
4342
4343static int opt_format(void *optctx, const char *opt, const char *arg)
4344{
4346 if (!file_iformat) {
4347 av_log(NULL, AV_LOG_FATAL, "Unknown input format: %s\n", arg);
4348 return AVERROR(EINVAL);
4349 }
4350 return 0;
4351}
4352
4353static int opt_sync(void *optctx, const char *opt, const char *arg)
4354{
4355 if (!strcmp(arg, "audio"))
4357 else if (!strcmp(arg, "video"))
4359 else if (!strcmp(arg, "ext"))
4361 else {
4362 av_log(NULL, AV_LOG_ERROR, "Unknown value for %s: %s\n", opt, arg);
4363 exit(1);
4364 }
4365 return 0;
4366}
4367
4368static int opt_show_mode(void *optctx, const char *opt, const char *arg)
4369{
4370 show_mode = !strcmp(arg, "video") ? SHOW_MODE_VIDEO :
4371 !strcmp(arg, "waves") ? SHOW_MODE_WAVES :
4372 !strcmp(arg, "rdft" ) ? SHOW_MODE_RDFT :
4373 !strcmp(arg, "phase") ? SHOW_MODE_PHASE : SHOW_MODE_NONE;
4374
4375 if (show_mode == SHOW_MODE_NONE) {
4376 double num;
4377 int ret = parse_number(opt, arg, OPT_TYPE_INT, 0, SHOW_MODE_NB-1, &num);
4378 if (ret < 0)
4379 return ret;
4380 show_mode = num;
4381 }
4382 return 0;
4383}
4384
4385static int opt_input_file(void *optctx, const char *filename)
4386{
4387 if (input_filename) {
4389 "Argument '%s' provided as input filename, but '%s' was already specified.\n",
4390 filename, input_filename);
4391 return AVERROR(EINVAL);
4392 }
4393 if (!strcmp(filename, "-"))
4394 filename = "fd:";
4395 input_filename = av_strdup(filename);
4396 if (!input_filename)
4397 return AVERROR(ENOMEM);
4398
4399 return 0;
4400}
4401
4402static int opt_codec(void *optctx, const char *opt, const char *arg)
4403{
4404 const char *spec = strchr(opt, ':');
4405 const char **name;
4406 if (!spec) {
4408 "No media specifier was specified in '%s' in option '%s'\n",
4409 arg, opt);
4410 return AVERROR(EINVAL);
4411 }
4412 spec++;
4413
4414 switch (spec[0]) {
4415 case 'a' : name = &audio_codec_name; break;
4416 case 's' : name = &subtitle_codec_name; break;
4417 case 'v' : name = &video_codec_name; break;
4418 default:
4420 "Invalid media specifier '%s' in option '%s'\n", spec, opt);
4421 return AVERROR(EINVAL);
4422 }
4423
4424 av_freep(name);
4425 *name = av_strdup(arg);
4426 return *name ? 0 : AVERROR(ENOMEM);
4427}
4428
4429static int dummy;
4430
4431static const OptionDef options[] = {
4433 { "x", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_width }, "force displayed width", "width" },
4434 { "y", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_height }, "force displayed height", "height" },
4435 { "fs", OPT_TYPE_BOOL, 0, { &is_full_screen }, "force full screen" },
4436 { "an", OPT_TYPE_BOOL, 0, { &audio_disable }, "disable audio" },
4437 { "vn", OPT_TYPE_BOOL, 0, { &video_disable }, "disable video" },
4438 { "sn", OPT_TYPE_BOOL, 0, { &subtitle_disable }, "disable subtitling" },
4439 { "ast", OPT_TYPE_STRING, OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_AUDIO] }, "select desired audio stream", "stream_specifier" },
4440 { "vst", OPT_TYPE_STRING, OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_VIDEO] }, "select desired video stream", "stream_specifier" },
4441 { "sst", OPT_TYPE_STRING, OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_SUBTITLE] }, "select desired subtitle stream", "stream_specifier" },
4442 { "ss", OPT_TYPE_TIME, 0, { &start_time }, "seek to a given position in seconds", "pos" },
4443 { "t", OPT_TYPE_TIME, 0, { &duration }, "play \"duration\" seconds of audio/video", "duration" },
4444 { "bytes", OPT_TYPE_INT, 0, { &seek_by_bytes }, "seek by bytes 0=off 1=on -1=auto", "val" },
4445 { "seek_interval", OPT_TYPE_FLOAT, 0, { &seek_interval }, "set seek interval for left/right keys, in seconds", "seconds" },
4446 { "nodisp", OPT_TYPE_BOOL, 0, { &display_disable }, "disable graphical display" },
4447 { "noborder", OPT_TYPE_BOOL, 0, { &borderless }, "borderless window" },
4448 { "alwaysontop", OPT_TYPE_BOOL, 0, { &alwaysontop }, "window always on top" },
4449 { "volume", OPT_TYPE_INT, 0, { &startup_volume}, "set startup volume 0=min 100=max", "volume" },
4450 { "f", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_format }, "force format", "fmt" },
4451 { "stats", OPT_TYPE_BOOL, OPT_EXPERT, { &show_status }, "show status", "" },
4452 { "fast", OPT_TYPE_BOOL, OPT_EXPERT, { &fast }, "non spec compliant optimizations", "" },
4453 { "genpts", OPT_TYPE_BOOL, OPT_EXPERT, { &genpts }, "generate pts", "" },
4454 { "drp", OPT_TYPE_INT, OPT_EXPERT, { &decoder_reorder_pts }, "let decoder reorder pts 0=off 1=on -1=auto", ""},
4455 { "lowres", OPT_TYPE_INT, OPT_EXPERT, { &lowres }, "", "" },
4456 { "sync", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT, { .func_arg = opt_sync }, "set audio-video sync. type (type=audio/video/ext)", "type" },
4457 { "autoexit", OPT_TYPE_BOOL, OPT_EXPERT, { &autoexit }, "exit at the end", "" },
4458 { "exitonkeydown", OPT_TYPE_BOOL, OPT_EXPERT, { &exit_on_keydown }, "exit on key down", "" },
4459 { "exitonmousedown", OPT_TYPE_BOOL, OPT_EXPERT, { &exit_on_mousedown }, "exit on mouse down", "" },
4460 { "loop", OPT_TYPE_INT, OPT_EXPERT, { &loop }, "set number of times the playback shall be looped", "loop count" },
4461 { "framedrop", OPT_TYPE_BOOL, OPT_EXPERT, { &framedrop }, "drop frames when cpu is too slow", "" },
4462 { "infbuf", OPT_TYPE_BOOL, OPT_EXPERT, { &infinite_buffer }, "don't limit the input buffer size (useful with realtime streams)", "" },
4463 { "window_title", OPT_TYPE_STRING, 0, { &window_title }, "set window title", "window title" },
4464 { "left", OPT_TYPE_INT, OPT_EXPERT, { &screen_left }, "set the x position for the left of the window", "x pos" },
4465 { "top", OPT_TYPE_INT, OPT_EXPERT, { &screen_top }, "set the y position for the top of the window", "y pos" },
4466 { "vf", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT, { .func_arg = opt_add_vfilter }, "set video filters", "filter_graph" },
4467 { "af", OPT_TYPE_STRING, 0, { &afilters }, "set audio filters", "filter_graph" },
4468 { "rdftspeed", OPT_TYPE_INT, OPT_AUDIO | OPT_EXPERT, { &rdftspeed }, "rdft speed", "msecs" },
4469 { "showmode", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_show_mode}, "select show mode (0 = video, 1 = waves, 2 = RDFT, 3 = phase)", "mode" },
4470 { "i", OPT_TYPE_BOOL, 0, { &dummy}, "read specified file", "input_file"},
4471 { "codec", OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_codec}, "force decoder", "decoder_name" },
4472 { "acodec", OPT_TYPE_STRING, OPT_EXPERT, { &audio_codec_name }, "force audio decoder", "decoder_name" },
4473 { "scodec", OPT_TYPE_STRING, OPT_EXPERT, { &subtitle_codec_name }, "force subtitle decoder", "decoder_name" },
4474 { "vcodec", OPT_TYPE_STRING, OPT_EXPERT, { &video_codec_name }, "force video decoder", "decoder_name" },
4475 { "autorotate", OPT_TYPE_BOOL, 0, { &autorotate }, "automatically rotate video", "" },
4476 { "find_stream_info", OPT_TYPE_BOOL, OPT_INPUT | OPT_EXPERT, { &find_stream_info },
4477 "read and decode the streams to fill missing information with heuristics" },
4478 { "filter_threads", OPT_TYPE_INT, OPT_EXPERT, { &filter_nbthreads }, "number of filter threads per graph" },
4479 { "enable_vulkan", OPT_TYPE_BOOL, 0, { &enable_vulkan }, "enable vulkan renderer" },
4480 { "vulkan_params", OPT_TYPE_STRING, OPT_EXPERT, { &vulkan_params }, "vulkan configuration using a list of key=value pairs separated by ':'" },
4481 { "video_bg", OPT_TYPE_STRING, OPT_EXPERT, { &video_background }, "set video background for transparent videos" },
4482 { "hwaccel", OPT_TYPE_STRING, OPT_EXPERT, { &hwaccel }, "use HW accelerated decoding" },
4483 { NULL, },
4484};
4485
4486static void show_usage(void)
4487{
4488 av_log(NULL, AV_LOG_INFO, "Simple media player\n");
4489 av_log(NULL, AV_LOG_INFO, "usage: %s [options] input_file\n", program_name);
4490 av_log(NULL, AV_LOG_INFO, "\n");
4491}
4492
4493void show_help_default(const char *opt, const char *arg)
4494{
4496 show_usage();
4497 show_help_options(options, "Main options:", 0, OPT_EXPERT);
4498 show_help_options(options, "Advanced options:", OPT_EXPERT, 0);
4499 printf("\n");
4503 printf("\nWhile playing:\n"
4504 "q, ESC quit\n"
4505 "f toggle full screen\n"
4506 "p, SPC pause\n"
4507 "m toggle mute\n"
4508 "9, 0 decrease and increase volume respectively\n"
4509 "/, * decrease and increase volume respectively\n"
4510 "a cycle audio channel in the current program\n"
4511 "v cycle video channel\n"
4512 "t cycle subtitle channel in the current program\n"
4513 "c cycle program\n"
4514 "w cycle video filters or show modes\n"
4515 "s activate frame-step mode\n"
4516 "left/right seek backward/forward by 10 seconds or a custom interval if -seek_interval is set\n"
4517 "down/up seek backward/forward 1 minute\n"
4518 "page down/page up seek to previous/next chapter or backward/forward 10 minutes if no chapters\n"
4519 "l keep the chapter list on screen; typing then filters it, down/up move its selection and escape closes it\n"
4520 "o list the directory of the input; enter or a click opens a directory or plays a file, escape closes the list\n"
4521 "enter seek to the chapter selected in the chapter list while it is shown\n"
4522 "mouse wheel move the chapter list selection while it is shown\n"
4523 "left click seek to the clicked chapter list entry, or sort the list by the clicked column, again to flip it;\n"
4524 " the left half of the shuffle button lowers its seed, the right half raises it\n"
4525 "mouse over (i) show the metadata of that chapter list entry\n"
4526 "right mouse click seek to percentage in file corresponding to fraction of width\n"
4527 "left double-click toggle full screen\n"
4528 );
4529}
4530
4531/* Called from the main */
4532int main(int argc, char **argv)
4533{
4534 int flags, ret;
4535 VideoState *is;
4536
4537 init_dynload();
4538
4540 parse_loglevel(argc, argv, options);
4541
4542 /* register all codecs, demux and protocols */
4543#if CONFIG_AVDEVICE
4545#endif
4547
4548 signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
4549 signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
4550
4551 show_banner(argc, argv, options);
4552
4553 ret = parse_options(NULL, argc, argv, options, opt_input_file);
4554 if (ret < 0)
4555 exit(ret == AVERROR_EXIT ? 0 : 1);
4556
4557 if (!input_filename) {
4558 show_usage();
4559 av_log(NULL, AV_LOG_FATAL, "An input file must be specified\n");
4561 "Use -h to get full help or, even better, run 'man %s'\n", program_name);
4562 exit(1);
4563 }
4564
4565 if (display_disable) {
4566 video_disable = 1;
4567 }
4568 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
4569 if (audio_disable)
4570 flags &= ~SDL_INIT_AUDIO;
4571 if (display_disable)
4572 flags &= ~SDL_INIT_VIDEO;
4573 if (SDL_Init (flags)) {
4574 av_log(NULL, AV_LOG_FATAL, "Could not initialize SDL - %s\n", SDL_GetError());
4575 av_log(NULL, AV_LOG_FATAL, "(Did you set the DISPLAY variable?)\n");
4576 exit(1);
4577 }
4578
4579 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
4580 SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
4581
4582 if (!display_disable) {
4583 int flags = SDL_WINDOW_HIDDEN;
4584 if (alwaysontop)
4585#if SDL_VERSION_ATLEAST(2,0,5)
4586 flags |= SDL_WINDOW_ALWAYS_ON_TOP;
4587#else
4588 av_log(NULL, AV_LOG_WARNING, "Your SDL version doesn't support SDL_WINDOW_ALWAYS_ON_TOP. Feature will be inactive.\n");
4589#endif
4590 if (borderless)
4591 flags |= SDL_WINDOW_BORDERLESS;
4592 else
4593 flags |= SDL_WINDOW_RESIZABLE;
4594
4595#ifdef SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR
4596 SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
4597#endif
4598 if (hwaccel && !enable_vulkan) {
4599 av_log(NULL, AV_LOG_INFO, "Enable vulkan renderer to support hwaccel %s\n", hwaccel);
4600 enable_vulkan = 1;
4601 }
4602 if (enable_vulkan) {
4604 if (vk_renderer) {
4605#if SDL_VERSION_ATLEAST(2, 0, 6)
4606 flags |= SDL_WINDOW_VULKAN;
4607#endif
4608 } else {
4609 av_log(NULL, AV_LOG_WARNING, "Doesn't support vulkan renderer, fallback to SDL renderer\n");
4610 enable_vulkan = 0;
4611 }
4612 }
4613 window = SDL_CreateWindow(program_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, default_width, default_height, flags);
4614 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
4615 if (!window) {
4616 av_log(NULL, AV_LOG_FATAL, "Failed to create window: %s", SDL_GetError());
4617 do_exit(NULL);
4618 }
4619 SDL_version version;
4620 SDL_GetVersion(&version);
4621 /* SDL before 2.0.16 waits for events by polling */
4622 wait_for_events = SDL_VERSIONNUM(version.major, version.minor, version.patch) >= SDL_VERSIONNUM(2, 0, 16);
4623
4624 if (vk_renderer) {
4625 AVDictionary *dict = NULL;
4626
4627 if (vulkan_params) {
4628 int ret = av_dict_parse_string(&dict, vulkan_params, "=", ":", 0);
4629 if (ret < 0) {
4630 av_log(NULL, AV_LOG_FATAL, "Failed to parse, %s\n", vulkan_params);
4631 do_exit(NULL);
4632 }
4633 }
4635 av_dict_free(&dict);
4636 if (ret < 0) {
4637 av_log(NULL, AV_LOG_FATAL, "Failed to create vulkan renderer, %s\n", av_err2str(ret));
4638 do_exit(NULL);
4639 }
4640 } else {
4641 renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
4642 if (!renderer) {
4643 av_log(NULL, AV_LOG_WARNING, "Failed to initialize a hardware accelerated renderer: %s\n", SDL_GetError());
4644 renderer = SDL_CreateRenderer(window, -1, 0);
4645 }
4646 if (renderer) {
4647 if (!SDL_GetRendererInfo(renderer, &renderer_info))
4648 av_log(NULL, AV_LOG_VERBOSE, "Initialized %s renderer.\n", renderer_info.name);
4649 }
4650 if (!renderer || !renderer_info.num_texture_formats) {
4651 av_log(NULL, AV_LOG_FATAL, "Failed to create window or renderer: %s", SDL_GetError());
4652 do_exit(NULL);
4653 }
4654 }
4655 }
4656
4658 if (!list) {
4659 av_log(NULL, AV_LOG_FATAL, "Could not allocate the list\n");
4660 do_exit(NULL);
4661 }
4663 if (!is) {
4664 av_log(NULL, AV_LOG_FATAL, "Failed to initialize VideoState!\n");
4665 do_exit(NULL);
4666 }
4667
4668 event_loop(is);
4669
4670 /* never returns */
4671
4672 return 0;
4673}
#define fn(a)
static double val(void *priv, double ch)
Definition aeval.c:77
static const AVFilterPad inputs[]
Definition af_aap.c:299
static const AVFilterPad outputs[]
Definition af_aap.c:310
static const char *const format[]
Definition af_aiir.c:445
#define entry
static FILE * out
static int out_size
static AVFormatContext * ctx
static AVDictionary * opts
channels
Definition aptx.h:31
int32_t
Main libavdevice API header.
Main libavfilter public API header.
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, const AVCodec **decoder_ret, int flags)
Definition avformat.c:529
Main libavformat public API header.
#define AVFMT_EVENT_FLAG_METADATA_UPDATED
Definition avformat.h:1796
@ AV_STREAM_GROUP_ENTRY_STREAM
Definition avformat.h:1173
@ AV_STREAM_GROUP_PARAMS_LCEVC
Definition avformat.h:1162
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition avformat.h:502
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition avformat.h:508
#define AVFMT_FLAG_GENPTS
Generate missing pts even if it requires parsing future frames.
Definition avformat.h:1554
#define AVSEEK_FLAG_BYTE
seeking based on position in bytes
Definition avformat.h:2748
#define AVSTREAM_EVENT_FLAG_METADATA_UPDATED
Definition avformat.h:886
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition avformat.h:694
#define AVSEEK_FLAG_PREROLL
move the target back by the audio pre-roll, see avformat_seek_file()
Definition avformat.h:2751
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:500
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition aviobuf.c:326
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:507
char * av_asprintf(const char *fmt,...)
Definition avstring.c:115
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition avstring.c:103
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:121
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
AVBPrint public header.
#define AV_BPRINT_SIZE_AUTOMATIC
memory buffer sink API for audio and video
Memory buffer source API.
#define is(width, name, range_min, range_max, subs,...)
Definition cbs_h264.c:78
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define ss(width, name, subs,...)
Definition cbs_vp9.c:202
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
void show_help_children(const AVClass *class, int flags)
Show help for all options with given flags in class and all its children.
Definition cmdutils.c:138
void init_dynload(void)
Initialize dynamic library loading.
Definition cmdutils.c:73
int check_avoptions(AVDictionary *m)
Definition cmdutils.c:1606
void dump_dictionary(void *ctx, const AVDictionary *m, const char *name, const char *indent, int log_level)
This does the same as libavformat/dump.c corresponding function and should probably be kept in sync w...
Definition cmdutils.c:1617
AVDictionary * swr_opts
Definition cmdutils.c:55
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
Definition cmdutils.c:554
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags)
Print help for all options matching specified flags.
Definition cmdutils.c:105
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
Definition cmdutils.c:68
AVDictionary * format_opts
Definition cmdutils.c:56
int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, int(*parse_arg_function)(void *, const char *))
Parse the command line arguments.
Definition cmdutils.c:418
int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec, AVDictionary **dst, AVDictionary **opts_used)
Filter out options for given codec.
Definition cmdutils.c:1424
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition cmdutils.c:1597
AVDictionary * codec_opts
Definition cmdutils.c:56
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents.
Definition cmdutils.c:60
double get_rotation(const int32_t *displaymatrix)
Definition cmdutils.c:1554
int setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *local_codec_opts, AVDictionary ***dst)
Setup AVCodecContext options for avformat_find_stream_info().
Definition cmdutils.c:1492
int parse_number(const char *context, const char *numstr, enum OptionType type, double min, double max, double *dst)
Parse a string and return its corresponding value as a double.
Definition cmdutils.c:82
AVDictionary * sws_dict
Definition cmdutils.c:54
const char program_name[]
program name, defined by the program for show_version().
Definition ffmpeg.c:89
#define OPT_FUNC_ARG
Definition cmdutils.h:205
#define OPT_INPUT
Definition cmdutils.h:237
static void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
Definition cmdutils.h:472
@ OPT_TYPE_BOOL
Definition cmdutils.h:82
@ OPT_TYPE_STRING
Definition cmdutils.h:83
@ OPT_TYPE_INT64
Definition cmdutils.h:85
@ OPT_TYPE_INT
Definition cmdutils.h:84
@ OPT_TYPE_TIME
Definition cmdutils.h:88
@ OPT_TYPE_FUNC
Definition cmdutils.h:81
@ OPT_TYPE_FLOAT
Definition cmdutils.h:86
void show_banner(int argc, char **argv, const OptionDef *options)
Print the program banner to stderr.
Definition opt_common.c:240
#define GROW_ARRAY(array, nb_elems)
Definition cmdutils.h:536
#define OPT_AUDIO
Definition cmdutils.h:213
#define OPT_EXPERT
Definition cmdutils.h:211
const int program_birth_year
program birth year, defined by the program for show_banner()
Definition ffmpeg.c:90
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Definition codec_par.c:206
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define av_clip
Definition common.h:100
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static __device__ float ceil(float a)
__device__ int printf(const char *,...)
static __device__ float fabs(float a)
static int16_t block[64]
Definition dct.c:125
static AVPacket * pkt
static AVStream * video_stream
static AVStream * audio_stream
static AVFrame * frame
Public dictionary API.
int main
Definition dovi_rpuenc.c:38
int8_t exp
Definition eval.c:76
static volatile int received_sigterm
Definition ffmpeg.c:141
const AVIOInterruptCB int_cb
Definition ffmpeg.c:322
static int decode_interrupt_cb(void *ctx)
Definition ffmpeg.c:317
static volatile int received_nb_signals
Definition ffmpeg.c:142
static void sigterm_handler(int sig)
Definition ffmpeg.c:148
char * filter_nbthreads
Definition ffmpeg_opt.c:73
const char * key
static int list_shows_files
Definition ffplay.c:381
static void show_usage(void)
Definition ffplay.c:4486
static char * vulkan_params
Definition ffplay.c:404
static double compute_target_delay(double delay, VideoState *is)
Definition ffplay.c:1748
#define SDL_AUDIO_MAX_CALLBACKS_PER_SEC
Definition ffplay.c:77
static int default_height
Definition ffplay.c:341
static char * video_background
Definition ffplay.c:405
static int autorotate
Definition ffplay.c:400
static int screen_left
Definition ffplay.c:344
static int is_realtime(AVFormatContext *s)
Definition ffplay.c:3131
static void frame_queue_destroy(FrameQueue *f)
Definition ffplay.c:770
static int packet_queue_put_nullpacket(PacketQueue *q, AVPacket *pkt, int stream_index)
Definition ffplay.c:522
static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub)
Definition ffplay.c:639
static int audio_open(VideoState *is, AVChannelLayout *wanted_channel_layout, int wanted_sample_rate, struct AudioParams *audio_hw_params)
Definition ffplay.c:2760
static const char * hwaccel
Definition ffplay.c:406
static Frame * frame_queue_peek_writable(FrameQueue *f)
Definition ffplay.c:804
static int default_width
Definition ffplay.c:340
static struct @246041210053127217121266371217250007267067234212 dir_request
static int video_open(VideoState *is)
Definition ffplay.c:1559
static int current_chapter(VideoState *is)
Definition ffplay.c:3862
static int infinite_buffer
Definition ffplay.c:369
static void draw_video_background(VideoState *is)
Definition ffplay.c:1027
static void do_exit(VideoState *is)
Definition ffplay.c:1496
static int is_full_screen
Definition ffplay.c:409
static int64_t duration
Definition ffplay.c:359
static int upload_texture(SDL_Texture **tex, AVFrame *frame)
Definition ffplay.c:966
static void set_clock_at(Clock *c, double pts, int serial, double time)
Definition ffplay.c:1609
static void stream_toggle_pause(VideoState *is)
Definition ffplay.c:1709
static double get_master_clock(VideoState *is)
Definition ffplay.c:1662
static int file_list_show(DirList *dl, int selected)
Definition ffplay.c:3888
static double vp_duration(VideoState *is, Frame *vp, Frame *nextvp)
Definition ffplay.c:1778
static int display_disable
Definition ffplay.c:352
static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
Definition ffplay.c:2717
#define EXTERNAL_CLOCK_MAX_FRAMES
Definition ffplay.c:72
static int audio_decode_frame(VideoState *is)
Decode one audio frame and return its uncompressed size.
Definition ffplay.c:2607
static void event_loop(VideoState *cur_stream)
Definition ffplay.c:4055
static int opt_format(void *optctx, const char *opt, const char *arg)
Definition ffplay.c:4343
#define EXTERNAL_CLOCK_SPEED_STEP
Definition ffplay.c:97
static const AVInputFormat * file_iformat
Definition ffplay.c:337
static int video_disable
Definition ffplay.c:347
#define AV_SYNC_THRESHOLD_MAX
Definition ffplay.c:85
static int find_stream_info
Definition ffplay.c:401
#define SAMPLE_QUEUE_SIZE
Definition ffplay.c:131
static int screen_height
Definition ffplay.c:343
#define MIN_FRAMES
Definition ffplay.c:70
static Frame * frame_queue_peek(FrameQueue *f)
Definition ffplay.c:789
static const char * chapter_tag(const AVChapter *chapter, const char *key)
Definition ffplay.c:1067
static int opt_codec(void *optctx, const char *opt, const char *arg)
Definition ffplay.c:4402
static Frame * frame_queue_peek_next(FrameQueue *f)
Definition ffplay.c:794
static const char ** vfilters_list
Definition ffplay.c:397
static int genpts
Definition ffplay.c:361
static int get_master_sync_type(VideoState *is)
Definition ffplay.c:1645
static void video_image_display(VideoState *is)
Definition ffplay.c:1104
char * path
Definition ffplay.c:385
int cancelled
Definition ffplay.c:388
static Frame * frame_queue_peek_readable(FrameQueue *f)
Definition ffplay.c:820
static VideoState * stream_replace(VideoState *is)
Definition ffplay.c:4020
static int decoder_reorder_pts
Definition ffplay.c:363
static int subtitle_disable
Definition ffplay.c:348
static void packet_queue_destroy(PacketQueue *q)
Definition ffplay.c:563
static int nb_vfilters
Definition ffplay.c:398
static void set_clock(Clock *c, double pts, int serial)
Definition ffplay.c:1617
static int av_sync_type
Definition ffplay.c:357
static int init_lcevc_graph(AVFormatContext *ic, int stream_index)
Definition ffplay.c:2872
static int borderless
Definition ffplay.c:353
static int startup_volume
Definition ffplay.c:355
static void toggle_mute(VideoState *is)
Definition ffplay.c:1728
static void frame_queue_next(FrameQueue *f)
Definition ffplay.c:846
static void fill_rectangle(int x, int y, int w, int h)
Definition ffplay.c:886
static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int by_bytes)
Definition ffplay.c:1695
#define EXTERNAL_CLOCK_SPEED_MAX
Definition ffplay.c:96
static int opt_input_file(void *optctx, const char *filename)
Definition ffplay.c:4385
static const char * video_codec_name
Definition ffplay.c:373
#define SAMPLE_ARRAY_SIZE
Definition ffplay.c:107
static const char * input_filename
Definition ffplay.c:338
static void video_display(VideoState *is)
Definition ffplay.c:1582
static int dir_thread_func(void *arg)
Definition ffplay.c:3914
static int audio_start(VideoState *is)
Definition ffplay.c:2951
static void packet_queue_abort(PacketQueue *q)
Definition ffplay.c:571
static void chapter_list_pin(VideoState *is)
Definition ffplay.c:1098
static void update_volume(VideoState *is, int sign, double step)
Definition ffplay.c:1733
static void toggle_audio_display(VideoState *is)
Definition ffplay.c:3818
#define SDL_VOLUME_STEP
Definition ffplay.c:80
#define MAX_QUEUE_SIZE
Definition ffplay.c:69
static void refresh_loop_wait_event(VideoState *is, SDL_Event *event)
Definition ffplay.c:3830
static enum AVColorSpace sdl_supported_color_spaces[]
Definition ffplay.c:1000
static enum ShowMode show_mode
Definition ffplay.c:370
static int show_status
Definition ffplay.c:356
static int subtitle_thread(void *arg)
Definition ffplay.c:2504
static int frame_queue_nb_remaining(FrameQueue *f)
Definition ffplay.c:862
static const char * window_title
Definition ffplay.c:339
int ret
Definition ffplay.c:391
static int get_video_frame(VideoState *is, AVFrame *frame)
Definition ffplay.c:1996
int play_if_no_dir
Definition ffplay.c:387
static enum AVAlphaMode sdl_supported_alpha_modes[]
Definition ffplay.c:1006
static void video_audio_display(VideoState *s)
Definition ffplay.c:1200
static int decoder_start(Decoder *d, int(*fn)(void *), const char *thread_name, void *arg)
Definition ffplay.c:2374
static int last_stream_id
Definition ffplay.c:415
static void decoder_abort(Decoder *d, FrameQueue *fq)
Definition ffplay.c:877
static int64_t frame_queue_last_pos(FrameQueue *f)
Definition ffplay.c:868
static void update_video_pts(VideoState *is, double pts, int serial)
Definition ffplay.c:1790
static int autoexit
Definition ffplay.c:364
static const char * audio_codec_name
Definition ffplay.c:371
SDL_atomic_t done
Definition ffplay.c:392
@ AV_SYNC_AUDIO_MASTER
Definition ffplay.c:204
@ AV_SYNC_EXTERNAL_CLOCK
Definition ffplay.c:206
@ AV_SYNC_VIDEO_MASTER
Definition ffplay.c:205
static int dummy
Definition ffplay.c:4429
static float seek_interval
Definition ffplay.c:351
static int packet_queue_init(PacketQueue *q)
Definition ffplay.c:529
#define FF_READY_EVENT
Definition ffplay.c:413
static Frame * frame_queue_peek_last(FrameQueue *f)
Definition ffplay.c:799
static char * afilters
Definition ffplay.c:399
#define SUBPICTURE_QUEUE_SIZE
Definition ffplay.c:130
static void file_list_read(const char *path, int play_if_no_dir)
Definition ffplay.c:3925
static const struct TextureFormatEntry sdl_texture_format_map[]
static void set_default_window_size(int width, int height, AVRational sar)
Definition ffplay.c:1547
static VideoState * next_stream
Definition ffplay.c:396
#define INSERT_FILT(name, arg)
static int frame_queue_init(FrameQueue *f, PacketQueue *pktq, int max_size, int keep_last)
Definition ffplay.c:749
void show_help_default(const char *opt, const char *arg)
Per-fftool specific help handler.
Definition ffplay.c:4493
static void frame_queue_unref_item(Frame *vp)
Definition ffplay.c:743
static void init_clock(Clock *c, int *queue_serial)
Definition ffplay.c:1629
static DirList * dir_list
Definition ffplay.c:382
static int opt_show_mode(void *optctx, const char *opt, const char *arg)
Definition ffplay.c:4368
static int compute_mod(int a, int b)
Definition ffplay.c:1195
static int opt_sync(void *optctx, const char *opt, const char *arg)
Definition ffplay.c:4353
static int do_bsf_flush(AVFormatContext *ic, VideoState *is)
Definition ffplay.c:3181
static int chapter_list_show(VideoState *is, int chapter)
Definition ffplay.c:1075
#define EXTERNAL_CLOCK_SPEED_MIN
Definition ffplay.c:95
static void stream_cycle_channel(VideoState *is, int codec_type)
Definition ffplay.c:3733
static int exit_status
Definition ffplay.c:419
static SDL_Renderer * renderer
Definition ffplay.c:422
static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int *serial)
Definition ffplay.c:591
#define AUDIO_DIFF_AVG_NB
Definition ffplay.c:100
static void frame_queue_push(FrameQueue *f)
Definition ffplay.c:836
static void file_list_choose(VideoState *is, int entry)
Definition ffplay.c:3997
static int decode_interrupt_cb(void *ctx)
Definition ffplay.c:3118
static int decoder_init(Decoder *d, AVCodecContext *avctx, PacketQueue *queue, SDL_cond *empty_queue_cond)
Definition ffplay.c:625
static int audio_thread(void *arg)
Definition ffplay.c:2296
static int configure_audio_filters(VideoState *is, const char *afilters, int force_output_format)
Definition ffplay.c:2224
static SDL_Thread * dir_thread
Definition ffplay.c:394
static int64_t cursor_last_shown
Definition ffplay.c:375
static int lowres
Definition ffplay.c:362
static int fast
Definition ffplay.c:360
#define SDL_AUDIO_MIN_BUFFER_SIZE
Definition ffplay.c:75
static int configure_filtergraph(AVFilterGraph *graph, const char *filtergraph, AVFilterContext *source_ctx, AVFilterContext *sink_ctx)
Definition ffplay.c:2029
static VideoState * stream_open(const char *filename, const AVInputFormat *iformat, const VideoState *replaced)
Definition ffplay.c:3656
static void stream_close(VideoState *is)
Definition ffplay.c:1448
static int video_thread(void *arg)
Definition ffplay.c:2393
static ListView * list
Definition ffplay.c:377
static int exit_on_mousedown
Definition ffplay.c:366
static int screen_width
Definition ffplay.c:342
static void file_list_open(VideoState *is)
Definition ffplay.c:3978
#define AV_SYNC_THRESHOLD_MIN
Definition ffplay.c:83
static SDL_Window * window
Definition ffplay.c:421
static void decoder_destroy(Decoder *d)
Definition ffplay.c:738
static int do_bsf_graph(AVFormatContext *ic, VideoState *is, Stream *sti, AVPacket *pkt)
Definition ffplay.c:3147
static int stream_component_open(VideoState *is, int stream_index)
Definition ffplay.c:2980
static void stream_component_close(VideoState *is, int stream_index)
Definition ffplay.c:1385
static int framedrop
Definition ffplay.c:368
static void uninit_bsf_graph(AVFormatContext *ic, int stream_index)
Definition ffplay.c:1360
static int seek_by_bytes
Definition ffplay.c:350
static void packet_queue_flush(PacketQueue *q)
Definition ffplay.c:549
SDL_atomic_t abort
Definition ffplay.c:389
#define REFRESH_RATE
Definition ffplay.c:103
static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const char *vfilters, AVFrame *frame)
Definition ffplay.c:2072
static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
Definition ffplay.c:477
static void list_choose(VideoState *is, int entry)
Definition ffplay.c:4010
#define FF_QUIT_EVENT
Definition ffplay.c:411
static int dir_interrupt_cb(void *ctx)
Definition ffplay.c:3909
#define CURSOR_HIDE_DELAY
Definition ffplay.c:109
static int screen_top
Definition ffplay.c:345
static int opt_width(void *optctx, const char *opt, const char *arg)
Definition ffplay.c:4321
static void file_play(VideoState *is, const char *path)
Definition ffplay.c:3901
static void packet_queue_start(PacketQueue *q)
Definition ffplay.c:582
static void get_sdl_pix_fmt_and_blendmode(int format, Uint32 *sdl_pix_fmt, SDL_BlendMode *sdl_blendmode)
Definition ffplay.c:948
static SDL_RendererInfo renderer_info
Definition ffplay.c:424
static void step_to_next_frame(VideoState *is)
Definition ffplay.c:1740
static void toggle_pause(VideoState *is)
Definition ffplay.c:1722
DirList * dl
Definition ffplay.c:390
static void seek_chapter(VideoState *is, int i)
Definition ffplay.c:3875
static int opt_height(void *optctx, const char *opt, const char *arg)
Definition ffplay.c:4332
#define EXTERNAL_CLOCK_MIN_FRAMES
Definition ffplay.c:71
#define AV_NOSYNC_THRESHOLD
Definition ffplay.c:89
static void update_sample_display(VideoState *is, short *samples, int samples_size)
Definition ffplay.c:2539
static int cmp_audio_fmts(enum AVSampleFormat fmt1, int64_t channel_count1, enum AVSampleFormat fmt2, int64_t channel_count2)
Definition ffplay.c:467
static int exit_on_keydown
Definition ffplay.c:365
#define FRAME_QUEUE_SIZE
Definition ffplay.c:132
static int realloc_texture(SDL_Texture **texture, Uint32 new_format, int new_width, int new_height, SDL_BlendMode blendmode, int init_texture)
Definition ffplay.c:897
static int loop
Definition ffplay.c:367
static int opt_add_vfilter(void *optctx, const char *opt, const char *arg)
Definition ffplay.c:453
static int create_hwaccel(AVBufferRef **device_ctx)
Definition ffplay.c:2836
static void video_refresh(void *opaque, double *remaining_time)
Definition ffplay.c:1798
static void frame_queue_signal(FrameQueue *f)
Definition ffplay.c:782
static int enable_vulkan
Definition ffplay.c:403
static double get_clock(Clock *c)
Definition ffplay.c:1597
static int cursor_hidden
Definition ffplay.c:376
#define SAMPLE_CORRECTION_PERCENT_MAX
Definition ffplay.c:92
static const char * subtitle_codec_name
Definition ffplay.c:372
static int wait_for_events
Definition ffplay.c:423
#define VIDEO_PICTURE_QUEUE_SIZE
Definition ffplay.c:129
static SDL_Keycode list_key
Definition ffplay.c:379
static int alwaysontop
Definition ffplay.c:354
static void set_clock_speed(Clock *c, double speed)
Definition ffplay.c:1623
static void calculate_display_rect(SDL_Rect *rect, int scr_xleft, int scr_ytop, int scr_width, int scr_height, int pic_width, int pic_height, AVRational pic_sar)
Definition ffplay.c:921
static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, double duration, int64_t pos, int serial)
Definition ffplay.c:1965
static int audio_disable
Definition ffplay.c:346
static void check_external_clock_speed(VideoState *is)
Definition ffplay.c:1680
static void sync_clock_to_slave(Clock *c, Clock *slave)
Definition ffplay.c:1637
static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
Definition ffplay.c:500
double rdftspeed
Definition ffplay.c:374
static void toggle_full_screen(VideoState *is)
Definition ffplay.c:3812
static void file_list_listed(VideoState *is)
Definition ffplay.c:3950
static const char * wanted_stream_spec[AVMEDIA_TYPE_NB]
Definition ffplay.c:349
static int stream_has_enough_packets(AVStream *st, int stream_id, PacketQueue *queue)
Definition ffplay.c:3124
static void push_stream_event(VideoState *is, Uint32 type)
Definition ffplay.c:2385
#define AV_SYNC_FRAMEDUP_THRESHOLD
Definition ffplay.c:87
static void sigterm_handler(int sig)
Definition ffplay.c:1540
static int synchronize_audio(VideoState *is, int nb_samples)
Definition ffplay.c:2559
static int read_thread(void *arg)
Definition ffplay.c:3206
static VkRenderer * vk_renderer
Definition ffplay.c:426
static void set_sdl_yuv_conversion_mode(AVFrame *frame)
Definition ffplay.c:1011
static int64_t start_time
Definition ffplay.c:358
int dir_list_read(DirList **pdl, const char *path, const AVIOInterruptCB *int_cb, AVDictionary **options)
Reads the directory into a new list.
Definition ffplay_dir.c:113
void dir_list_free(DirList **pdl)
Definition ffplay_dir.c:159
char * dir_list_path(const DirList *dl, int entry)
Definition ffplay_dir.c:184
The content of a directory as list entries, leaving out hidden entries, special files and links to th...
int list_view_selected(const ListView *lv)
void list_view_set_size(ListView *lv, int width, int height)
Sets the size of the window the list is drawn into.
ListView * list_view_alloc(SDL_Renderer *renderer)
void list_view_set_playing(ListView *lv, int entry)
Marks the entry as playing, -1 for none.
int list_view_show(ListView *lv, const ListEntry *entries, int nb_entries, int selected)
Replaces the entries and shows the list, fading it in.
int list_view_pinned(const ListView *lv)
int list_view_click(ListView *lv, int x, int y, int *chosen)
Handles a left click at window coordinates: a click on an entry chooses it, a click on a column butto...
void list_view_move(ListView *lv, int delta)
Moves the selection by delta rows.
void list_view_clear_search(ListView *lv)
Clears the search, listing all entries.
void list_view_free(ListView **plv)
void list_view_hover(ListView *lv, int x, int y)
Keeps the mouse position, in window coordinates, -1 when the mouse left the window.
int list_view_visible(const ListView *lv)
void list_view_pin(ListView *lv, int pinned)
Keeps the list on screen and lets it take the keyboard and text input, or lets it fade out again.
int list_view_update(ListView *lv)
Brings the list up to date for the next frame, once the pending input is handled.
void list_view_text(ListView *lv, const char *text)
Appends text typed while the list is pinned to the search, or erases its last character when text is ...
void list_view_draw(ListView *lv)
Draws the list onto the window, between its other content and the present.
int list_view_key(ListView *lv, SDL_Keycode key)
Handles a key while the list is pinned: escape unpins it, up/down move the selection,...
void list_view_clear(ListView *lv)
Removes the entries, which may be freed after this, and resets the sort and the search.
A list overlay for ffplay: entries with title, artist, length and metadata that the user can sort,...
int vk_renderer_create(VkRenderer *renderer, SDL_Window *window, AVDictionary *opt)
int vk_renderer_display(VkRenderer *renderer, AVFrame *frame, RenderParams *render_params)
VkRenderer * vk_get_renderer(void)
int vk_renderer_get_hw_dev(VkRenderer *renderer, AVBufferRef **dev)
int vk_renderer_resize(VkRenderer *renderer, int width, int height)
void vk_renderer_destroy(VkRenderer *renderer)
#define VIDEO_BACKGROUND_TILE_SIZE
@ VIDEO_BACKGROUND_TILES
@ VIDEO_BACKGROUND_NONE
@ VIDEO_BACKGROUND_COLOR
static const AVInputFormat * iformat
Definition ffprobe.c:383
static unsigned int nb_streams
Definition ffprobe.c:390
A generic FIFO API.
#define fail
Definition test.h:479
#define AV_OPT_FLAG_FILTERING_PARAM
A generic parameter which can be set by the user for filtering.
Definition opt.h:380
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
Definition opt.h:306
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_CHLAYOUT
Underlying C type is AVChannelLayout.
Definition opt.h:330
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
int av_bsf_sink_get_packet(AVBitStreamFilterContext *ctx, AVPacket *pkt, int flags)
Get a packet with filtered data from sink and put it in packet.
Definition sink.c:52
AVRational av_bsf_sink_get_time_base(const AVBitStreamFilterContext *ctx)
Definition sink.c:126
int av_bsf_source_parameters_set(AVBitStreamFilterContext *ctx, const AVCodecParameters *par)
Initialize the source filter with the provided parameters.
Definition source.c:46
av_warn_unused_result int av_bsf_source_add_packet(AVBitStreamFilterContext *ctx, AVPacket *pkt, int flags)
Add a packet to the buffer source.
Definition source.c:67
@ AV_BSF_SOURCE_FLAG_PUSH
Immediately push the packet to the output.
Definition bsf.h:594
int av_bsf_init_dict(AVBitStreamFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options.
AVBitStreamFilterGraph * av_bsf_graph_alloc(void)
Allocate a filter graph.
Definition bsfgraph.c:48
int av_bsf_link(AVBitStreamFilterContext *src, unsigned srcpad, AVBitStreamFilterContext *dst, unsigned dstpad)
Link two filters together.
int av_bsf_graph_config(AVBitStreamFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
Definition bsfgraph.c:294
void av_bsf_graph_free(AVBitStreamFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
Definition bsfgraph.c:93
int av_bsf_graph_alloc_filter(AVBitStreamFilterContext **filt_ctx, const AVBitStreamFilter *filter, const char *name, AVBitStreamFilterGraph *graph)
Create a new filter instance in a filter graph.
Definition bsfgraph.c:139
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition avcodec.c:142
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
Definition avcodec.h:337
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition options.c:188
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition options.c:149
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition allcodecs.c:999
const AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition allcodecs.c:1027
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition avcodec.c:419
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition utils.c:421
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition options.c:168
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Alias for avcodec_receive_frame_flags(avctx, frame, 0).
Definition avcodec.c:718
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition decode.c:738
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
Definition decode.c:955
@ AVDISCARD_ALL
discard all
Definition defs.h:248
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition defs.h:243
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
Definition avcodec.c:387
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
Definition packet.c:571
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition packet.h:105
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition packet.c:74
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:435
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition packet.c:492
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition packet.c:63
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition packet.c:443
FF_VISIBILITY_POP_HIDDEN av_cold void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
Definition alldevices.c:67
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
Definition utils.c:589
int avformat_network_init(void)
Do global initialization of network libraries.
Definition utils.c:577
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition options.c:165
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition options.c:193
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition format.c:146
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
Definition avformat.c:478
int av_read_pause(AVFormatContext *s)
Pause a network-based stream (e.g.
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
Definition seek.c:789
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition demux.c:1646
int av_read_play(AVFormatContext *s)
Start playing a network-based stream (e.g.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition demux.c:231
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition demux.c:2674
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition demux.c:400
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
Definition avformat.c:842
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
Definition avformat.c:771
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
Definition dump.c:936
AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame)
Guess the sample aspect ratio of a frame, based on both the stream and the frame aspect ratio.
Definition avformat.c:819
int av_buffersink_get_sample_rate(const AVFilterContext *ctx)
AVRational av_buffersink_get_frame_rate(const AVFilterContext *ctx)
Definition buffersink.c:259
int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out)
Definition buffersink.c:279
AVRational av_buffersink_get_time_base(const AVFilterContext *ctx)
int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Get a frame with filtered data from sink and put it in frame.
Definition buffersink.c:138
int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *param)
Initialize the buffersrc or abuffersrc filter with the provided parameters.
Definition buffersrc.c:131
int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
Definition buffersrc.c:202
AVBufferSrcParameters * av_buffersrc_parameters_alloc(void)
Allocate a new AVBufferSrcParameters instance.
Definition buffersrc.c:116
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition allfilters.c:657
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition graphparser.c:76
int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx)
Add a graph described by a string to a graph.
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options.
Definition avfilter.c:930
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition avfilter.c:149
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
A convenience wrapper that allocates and initializes a filter in a single step.
const AVClass * avfilter_get_class(void)
Definition avfilter.c:1688
AVFilterInOut * avfilter_inout_alloc(void)
Allocate a single AVFilterInOut entry.
Definition graphparser.c:71
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, AVBPrint *bp)
bprint variant of av_channel_layout_describe().
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:234
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition buffer.c:94
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
Definition dict.h:84
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:236
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition dict.c:61
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition dict.c:43
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition dict.c:250
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:87
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition dict.h:81
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
Definition dict.c:213
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition dict.h:74
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition dict.c:180
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition error.h:58
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition fifo.c:47
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition fifo.c:286
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition fifo.h:63
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition fifo.c:188
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition fifo.c:240
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:499
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:662
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition frame.c:526
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:53
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition frame.h:85
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_QUIET
Print no output.
Definition log.h:192
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition log.h:204
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition log.c:497
#define AV_LOG_SKIP_REPEATED
Skip repeated messages, this requires the user app to use av_log() instead of (f)printf as the 2 woul...
Definition log.h:400
int av_log_get_level(void)
Get the current log level.
Definition log.c:477
void av_log_set_flags(int arg)
Definition log.c:487
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition rational.c:80
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition rational.h:89
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition mem.c:661
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition utils.c:28
AVMediaType
Definition avutil.h:198
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition avutil.h:311
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_NB
Definition avutil.h:205
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition utils.c:40
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition samplefmt.c:109
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
Definition samplefmt.c:78
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
Definition samplefmt.c:122
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition samplefmt.c:52
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition samplefmt.h:58
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition avstring.c:36
const char * av_dirname(char *path)
Thread safe dirname.
Definition avstring.c:274
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_TIME_BASE
Internal time base represented as integer.
Definition avutil.h:253
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
SwsContext * sws_getCachedContext(SwsContext *context, int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Check if context can be reused, otherwise reallocate a new one.
Definition utils.c:2419
int attribute_align_arg sws_scale(SwsContext *sws, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
Definition swscale.c:1695
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
Definition utils.c:2338
int swr_alloc_set_opts2(struct SwrContext **ps, const AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, const AVChannelLayout *in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)
Allocate SwrContext if needed and set/reset common parameters.
Definition swresample.c:54
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
Definition swresample.c:137
int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance)
Activate resampling compensation ("soft" compensation).
Definition swresample.c:939
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *const *out_arg, int out_count, const uint8_t *const *in_arg, int in_count)
Convert audio.
Definition swresample.c:751
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
Definition swresample.c:156
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition opt.h:604
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
Definition opt.c:961
int av_opt_set_array(void *obj, const char *name, int search_flags, unsigned int start_elem, unsigned int nb_elems, enum AVOptionType val_type, const void *val)
Add, replace, or remove elements for an array option.
Definition opt.c:2371
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition opt.c:904
int a
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
Definition hwcontext.c:673
int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, enum AVHWDeviceType type, AVBufferRef *src_ref, int flags)
Create a new device of the specified type from an existing device.
Definition hwcontext.c:776
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
Definition hwcontext.c:111
AVHWDeviceType
Definition hwcontext.h:27
@ AV_HWDEVICE_TYPE_NONE
Definition hwcontext.h:28
#define b
Definition input.c:43
#define av_log2
Definition intmath.h:84
enum MPFType type
Definition jpegmpfenc.c:55
static int lcevc_merge(FFPacketSync *fs)
Definition lcevc_merge.c:85
const char * arg
Definition jacosubdec.c:66
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define av_unused
Definition attributes.h:164
version
Definition libkvazaar.c:313
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
uint8_t w
Definition llvidencdsp.c:39
#define FFSWAP(type, a, b)
Definition macros.h:52
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define NAN
#define M_PI
Definition mathematics.h:67
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
uint32_t tag
Definition movenc.c:2144
const char data[16]
Definition mxf.c:149
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
#define CMDUTILS_COMMON_OPTIONS
Definition opt_common.h:199
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
Definition parseutils.c:359
misc parsing utilities
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition pixdesc.c:3404
#define AV_PIX_FMT_0RGB32
Definition pixfmt.h:524
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:792
#define AV_PIX_FMT_BGR555
Definition pixfmt.h:541
AVAlphaMode
Correlation between the alpha channel and color values.
Definition pixfmt.h:825
@ AVALPHA_MODE_STRAIGHT
Alpha channel is independent of color values.
Definition pixfmt.h:828
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
Definition pixfmt.h:826
#define AV_PIX_FMT_BGR32
Definition pixfmt.h:522
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition pixfmt.h:88
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)3R 3G 2B(lsb)
Definition pixfmt.h:93
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition pixfmt.h:74
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
#define AV_PIX_FMT_RGB32_1
Definition pixfmt.h:521
#define AV_PIX_FMT_BGR32_1
Definition pixfmt.h:523
#define AV_PIX_FMT_BGR565
Definition pixfmt.h:540
#define AV_PIX_FMT_RGB565
Definition pixfmt.h:535
#define AV_PIX_FMT_RGB444
Definition pixfmt.h:537
#define AV_PIX_FMT_NE(be, le)
Definition pixfmt.h:517
#define AV_PIX_FMT_0BGR32
Definition pixfmt.h:525
#define AV_PIX_FMT_RGB32
Definition pixfmt.h:520
#define AV_PIX_FMT_RGB555
Definition pixfmt.h:536
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:711
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition pixfmt.h:713
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition pixfmt.h:717
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition pixfmt.h:718
const char * name
Definition qsvenc.c:142
enum AVMediaType codec_type
Definition rtp.c:37
static volatile sig_atomic_t sig
Definition signal.c:48
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition spdifenc.c:431
An instance of a filter.
Definition bsf.h:347
void * priv_data
Opaque filter-specific private data.
Definition bsf.h:375
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
This structure contains the parameters describing the frames that will be passed to this filter.
Definition buffersrc.h:73
AVRational frame_rate
Video only, the frame rate of the input video.
Definition buffersrc.h:100
enum AVColorRange color_range
Definition buffersrc.h:122
int format
video: the pixel format, value corresponds to enum AVPixelFormat audio: the sample format,...
Definition buffersrc.h:78
int width
Video only, the display dimensions of the input frames.
Definition buffersrc.h:87
enum AVColorSpace color_space
Video only, the YUV colorspace and range.
Definition buffersrc.h:121
enum AVAlphaMode alpha_mode
Video only, the alpha mode.
Definition buffersrc.h:130
AVRational time_base
The timebase to be used for the timestamps on the input frames.
Definition buffersrc.h:82
AVBufferRef * hw_frames_ctx
Video with a hwaccel pixel format only.
Definition buffersrc.h:106
AVRational sample_aspect_ratio
Video only, the sample (pixel) aspect ratio.
Definition buffersrc.h:92
An AVChannelLayout holds information about the channel layout of audio data.
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
int64_t start
Definition avformat.h:1363
AVDictionary * metadata
Definition avformat.h:1364
int64_t end
chapter start/end time in time_base units
Definition avformat.h:1363
AVRational time_base
time base in which the start/end timestamps are specified
Definition avformat.h:1362
main external API structure.
Definition avcodec.h:443
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1059
int flags2
AV_CODEC_FLAG2_*.
Definition avcodec.h:507
enum AVSampleFormat sample_fmt
audio sample format
Definition avcodec.h:1051
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition avcodec.h:554
enum AVMediaType codec_type
Definition avcodec.h:451
int sample_rate
samples per second
Definition avcodec.h:1044
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition avcodec.h:1499
enum AVCodecID codec_id
Definition avcodec.h:453
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition avcodec.h:1712
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
int height
The height of the video frame in pixels.
Definition codec_par.h:150
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
Definition codec_par.h:161
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
AVCodec.
Definition codec.h:175
enum AVCodecID id
Definition codec.h:189
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition codec.h:195
char * key
Definition dict.h:91
char * value
Definition dict.h:92
Definition fifo.c:35
An instance of a filter.
Definition avfilter.h:279
unsigned nb_filters
Definition avfilter.h:575
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition avfilter.h:577
AVFilterContext ** filters
Definition avfilter.h:574
int nb_threads
Maximum number of threads used by filters in this graph.
Definition avfilter.h:598
A linked-list of the inputs/outputs of the filter chain.
Definition avfilter.h:752
Format I/O context.
Definition avformat.h:1401
int event_flags
Flags indicating events happening on the file, a combination of AVFMT_EVENT_FLAG_*.
Definition avformat.h:1789
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition avformat.h:1457
AVStreamGroup ** stream_groups
A list of all stream groups in the file.
Definition avformat.h:1489
AVIOContext * pb
I/O context.
Definition avformat.h:1443
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
Definition avformat.h:1527
AVDictionary * metadata
Metadata that applies to the whole file.
Definition avformat.h:1649
int flags
Flags modifying the (de)muxer behaviour.
Definition avformat.h:1553
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition avformat.h:1687
const struct AVInputFormat * iformat
The input container format.
Definition avformat.h:1413
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition avformat.h:1502
void * opaque
User data.
Definition avformat.h:1986
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition avformat.h:1544
unsigned int nb_stream_groups
Number of elements in AVFormatContext.stream_groups.
Definition avformat.h:1476
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1469
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition avformat.h:1537
int seek_flags
Flags added to the flags of every avformat_seek_file(): AVSEEK_FLAG_ANY and AVSEEK_FLAG_PREROLL.
Definition avformat.h:2069
Structure to hold side data for an AVFrame.
Definition frame.h:334
uint8_t * data
Definition frame.h:336
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
int nb_samples
number of audio samples (per channel) described by this frame
Definition frame.h:559
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
int width
Definition frame.h:551
int height
Definition frame.h:551
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition frame.h:576
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:524
int sample_rate
Sample rate of the audio data.
Definition frame.h:642
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition frame.h:825
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:566
enum AVPictureType pict_type
Picture type of the frame.
Definition frame.h:571
uint8_t ** extended_data
pointers to the data planes/channels.
Definition frame.h:540
int eof_reached
true if was unable to read due to error or eof
Definition avio.h:238
int error
contains the error code or 0 if no error happened
Definition avio.h:239
Callback for checking whether to abort blocking functions.
Definition avio.h:59
void * opaque
Definition avio.h:61
int(* callback)(void *)
Definition avio.h:60
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_EXPERIMENTAL, AVFMT_SHOW_IDS,...
Definition avformat.h:587
const char * name
A comma separated list of short names for the format.
Definition avformat.h:572
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition packet.h:431
uint8_t * data
Definition packet.h:432
This structure stores compressed data.
Definition packet.h:587
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition packet.h:593
int size
Definition packet.h:611
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition packet.h:628
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition packet.h:646
uint8_t * data
Definition packet.h:610
int64_t pos
byte position in stream, -1 if unknown
Definition packet.h:630
New fields can be added to the end with minor version bumps.
Definition avformat.h:1325
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
AVStream * stream
Definition avformat.h:1180
AVStreamGroupLayeredVideo is meant to define the relation between a base layer video stream and a sep...
Definition avformat.h:1104
unsigned int el_index
Index of the enhancement layer stream in AVStreamGroup.
Definition avformat.h:1113
unsigned int nb_entries
Number of elements in AVStreamGroup.entries.
Definition avformat.h:1286
enum AVStreamGroupParamsType type
Group type.
Definition avformat.h:1212
AVStreamGroupEntry ** entries
A list of streams or child groups in the group.
Definition avformat.h:1299
union AVStreamGroup::@313244315204024013007202273061153315146016101155 params
Group type-specific parameters.
struct AVStreamGroupLayeredVideo * layered_video
Definition avformat.h:1221
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition avformat.h:839
AVDictionary * metadata
Definition avformat.h:848
int index
stream index in AVFormatContext
Definition avformat.h:774
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition avformat.h:817
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:807
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
Definition avformat.h:879
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition avformat.h:837
int x
top left corner of pict, undefined when pict is not set
Definition avcodec.h:2081
int w
width of pict, undefined when pict is not set
Definition avcodec.h:2083
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition avcodec.h:2091
int y
top left corner of pict, undefined when pict is not set
Definition avcodec.h:2082
int linesize[4]
Definition avcodec.h:2092
int h
height of pict, undefined when pict is not set
Definition avcodec.h:2084
uint16_t format
Definition avcodec.h:2108
uint32_t start_display_time
Definition avcodec.h:2109
uint32_t end_display_time
Definition avcodec.h:2110
unsigned num_rects
Definition avcodec.h:2111
AVSubtitleRect ** rects
Definition avcodec.h:2112
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition avcodec.h:2113
int bytes_per_sec
Definition ffplay.c:139
int frame_size
Definition ffplay.c:138
enum AVSampleFormat fmt
Definition ffplay.c:137
AVChannelLayout ch_layout
Definition ffplay.c:136
int serial
Definition ffplay.c:147
double pts
Definition ffplay.c:143
double pts_drift
Definition ffplay.c:144
double last_updated
Definition ffplay.c:145
int paused
Definition ffplay.c:148
double speed
Definition ffplay.c:146
int * queue_serial
Definition ffplay.c:149
SDL_cond * empty_queue_cond
Definition ffplay.c:216
int64_t start_pts
Definition ffplay.c:217
int64_t next_pts
Definition ffplay.c:219
PacketQueue * queue
Definition ffplay.c:211
int packet_pending
Definition ffplay.c:215
int finished
Definition ffplay.c:214
SDL_Thread * decoder_tid
Definition ffplay.c:221
AVCodecContext * avctx
Definition ffplay.c:212
AVRational next_pts_tb
Definition ffplay.c:220
AVRational start_pts_tb
Definition ffplay.c:218
int pkt_serial
Definition ffplay.c:213
AVPacket * pkt
Definition ffplay.c:210
Stream ** streams
Definition ffplay.c:197
int nb_stream_groups
Definition ffplay.c:200
int nb_streams
Definition ffplay.c:198
StreamGroup ** stream_groups
Definition ffplay.c:199
int64_t pkt_pos
Definition ffplay.c:153
SDL_mutex * mutex
Definition ffplay.c:180
SDL_cond * cond
Definition ffplay.c:181
int keep_last
Definition ffplay.c:178
PacketQueue * pktq
Definition ffplay.c:182
int rindex
Definition ffplay.c:174
int size
Definition ffplay.c:176
int rindex_shown
Definition ffplay.c:179
Frame queue[FRAME_QUEUE_SIZE]
Definition ffplay.c:173
int windex
Definition ffplay.c:175
int max_size
Definition ffplay.c:177
int width
Definition ffplay.c:164
AVRational sar
Definition ffplay.c:167
int uploaded
Definition ffplay.c:168
AVFrame * frame
Definition ffplay.c:158
double duration
Definition ffplay.c:162
int serial
Definition ffplay.c:160
int height
Definition ffplay.c:165
int64_t pos
Definition ffplay.c:163
AVSubtitle sub
Definition ffplay.c:159
int format
Definition ffplay.c:166
double pts
Definition ffplay.c:161
int flip_v
Definition ffplay.c:169
int64_t length
in AV_TIME_BASE units, negative when unknown
Definition ffplay_list.h:39
AVPacket * pkt
Definition ffplay.c:114
int serial
Definition ffplay.c:124
AVFifo * pkt_list
Definition ffplay.c:119
SDL_mutex * mutex
Definition ffplay.c:125
SDL_cond * cond
Definition ffplay.c:126
int64_t duration
Definition ffplay.c:122
int abort_request
Definition ffplay.c:123
int nb_packets
Definition ffplay.c:120
Definition cms.c:66
AVBitStreamFilterContext * sink
Definition ffplay.c:188
AVBitStreamFilterGraph * graph
Definition ffplay.c:187
AVStreamGroup * stg
Definition ffplay.c:186
StreamGroup * group
Definition ffplay.c:192
AVBitStreamFilterContext * filter
Definition ffplay.c:193
The libswresample context.
Main external API structure.
Definition swscale.h:227
enum AVPixelFormat format
Definition ffplay.c:429
AVFilterContext * out_video_filter
Definition ffplay.c:326
float * real_data
Definition ffplay.c:289
int last_i_start
Definition ffplay.c:285
struct AudioParams audio_src
Definition ffplay.c:273
int xpos
Definition ffplay.c:291
AVFilterGraph * agraph
Definition ffplay.c:329
int height
Definition ffplay.c:321
int last_paused
Definition ffplay.c:230
int16_t sample_array[SAMPLE_ARRAY_SIZE]
Definition ffplay.c:283
Decoder auddec
Definition ffplay.c:248
AVTXContext * rdft
Definition ffplay.c:286
int abort_request
Definition ffplay.c:227
int width
Definition ffplay.c:321
int subtitle_stream
Definition ffplay.c:300
int av_sync_type
Definition ffplay.c:254
RenderParams render_params
Definition ffplay.c:293
int xleft
Definition ffplay.c:321
SDL_Texture * vid_texture
Definition ffplay.c:296
unsigned int audio_buf_size
Definition ffplay.c:267
int vfilter_idx
Definition ffplay.c:324
enum VideoState::ShowMode show_mode
int audio_stream
Definition ffplay.c:252
int paused
Definition ffplay.c:229
int audio_volume
Definition ffplay.c:271
SDL_AudioDeviceID audio_dev
Definition ffplay.c:297
AVStream * video_st
Definition ffplay.c:308
struct AudioParams audio_tgt
Definition ffplay.c:275
Clock audclk
Definition ffplay.c:240
AVStream * audio_st
Definition ffplay.c:262
double audio_diff_cum
Definition ffplay.c:258
int rdft_bits
Definition ffplay.c:288
const AVInputFormat * iformat
Definition ffplay.c:226
double audio_diff_threshold
Definition ffplay.c:260
int read_pause_return
Definition ffplay.c:236
Clock extclk
Definition ffplay.c:242
double audio_diff_avg_coef
Definition ffplay.c:259
AVFilterContext * out_audio_filter
Definition ffplay.c:328
Decoder subdec
Definition ffplay.c:250
int sample_array_index
Definition ffplay.c:284
int frame_drops_late
Definition ffplay.c:278
int audio_buf_index
Definition ffplay.c:269
int infinite_buffer
Definition ffplay.c:319
double frame_timer
Definition ffplay.c:304
int64_t seek_pos
Definition ffplay.c:234
double max_frame_duration
Definition ffplay.c:310
double frame_last_returned_time
Definition ffplay.c:305
struct SwrContext * swr_ctx
Definition ffplay.c:276
SDL_Texture * vis_texture
Definition ffplay.c:294
char * title
Definition ffplay.c:317
int step
Definition ffplay.c:322
SDL_atomic_t replacement
Definition ffplay.c:316
int frame_drops_early
Definition ffplay.c:277
struct AudioParams audio_filter_src
Definition ffplay.c:274
int seek_by_bytes
Definition ffplay.c:318
int audio_hw_buf_size
Definition ffplay.c:264
SDL_cond * continue_read_thread
Definition ffplay.c:333
int ytop
Definition ffplay.c:321
FrameQueue subpq
Definition ffplay.c:245
AVFormatContext * ic
Definition ffplay.c:237
@ SHOW_MODE_VIDEO
Definition ffplay.c:281
@ SHOW_MODE_NONE
Definition ffplay.c:281
@ SHOW_MODE_PHASE
Definition ffplay.c:281
@ SHOW_MODE_RDFT
Definition ffplay.c:281
@ SHOW_MODE_NB
Definition ffplay.c:281
@ SHOW_MODE_WAVES
Definition ffplay.c:281
Decoder viddec
Definition ffplay.c:249
AVComplexFloat * rdft_data
Definition ffplay.c:290
int audio_diff_avg_count
Definition ffplay.c:261
FrameQueue pictq
Definition ffplay.c:244
uint8_t * audio_buf1
Definition ffplay.c:266
int loop
Definition ffplay.c:320
char * filename
Definition ffplay.c:314
int last_subtitle_stream
Definition ffplay.c:331
PacketQueue subtitleq
Definition ffplay.c:302
int realtime
Definition ffplay.c:238
int video_stream
Definition ffplay.c:307
int muted
Definition ffplay.c:272
int force_refresh
Definition ffplay.c:228
int seek_flags
Definition ffplay.c:233
double frame_last_filter_delay
Definition ffplay.c:306
int last_video_stream
Definition ffplay.c:331
int audio_clock_serial
Definition ffplay.c:257
AVStream * subtitle_st
Definition ffplay.c:301
unsigned int audio_buf1_size
Definition ffplay.c:268
av_tx_fn rdft_fn
Definition ffplay.c:287
struct SwsContext * sub_convert_ctx
Definition ffplay.c:311
int last_audio_stream
Definition ffplay.c:331
double last_vis_time
Definition ffplay.c:292
int64_t seek_rel
Definition ffplay.c:235
int64_t audio_callback_time
Definition ffplay.c:298
PacketQueue audioq
Definition ffplay.c:263
AVFilterContext * in_video_filter
Definition ffplay.c:325
PacketQueue videoq
Definition ffplay.c:309
int audio_write_buf_size
Definition ffplay.c:270
double audio_clock
Definition ffplay.c:256
int seek_req
Definition ffplay.c:232
int queue_attachments_req
Definition ffplay.c:231
SDL_Thread * read_tid
Definition ffplay.c:225
SDL_Texture * sub_texture
Definition ffplay.c:295
uint8_t * audio_buf
Definition ffplay.c:265
int eof
Definition ffplay.c:312
FrameQueue sampq
Definition ffplay.c:246
AVFilterContext * in_audio_filter
Definition ffplay.c:327
Clock vidclk
Definition ffplay.c:241
Definition swscale.c:85
int w
Definition f_ebur128.c:78
int y
Definition f_ebur128.c:78
int h
Definition f_ebur128.c:78
int x
Definition f_ebur128.c:78
libswresample public header
external API header
#define lrint
Definition tablegen.h:53
#define av_free(p)
#define av_malloc_array(a, b)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
int num
Definition error.c:23
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99
FILE * fp
Definition swscale.c:145
AVThreadMessageQueue * queue
Definition swscale.c:148
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition time.c:93
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition time.c:57
static int64_t pts
int size
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition tx.c:295
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition tx.c:903
@ AV_TX_FLOAT_RDFT
Real to complex and complex to real DFTs.
Definition tx.h:90
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition tx.h:151
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
int len
static double c[64]