2 * Common Source Code Project for Qt : movie saver.
3 * (C) 2016 K.Ohta <whatisthis.sowhat _at_ gmail.com>
5 * History: May 27, 2016 : Initial. This refer from ffmpeg: doc/examples/demuxing_decoding.c.
8 #ifndef _QT_OSD_MOVIE_LOADER_H
9 #define _QT_OSD_MOVIE_LOADER_H
11 #if defined(USE_LIBAV)
13 #include "libavutil/channel_layout.h"
14 #include "libavutil/opt.h"
15 #include "libavutil/mathematics.h"
16 #include "libavutil/timestamp.h"
17 #include "libavutil/imgutils.h"
18 #include "libavutil/samplefmt.h"
19 #include "libavformat/avformat.h"
20 #include "libswscale/swscale.h"
21 #include "libswresample/swresample.h"
25 // Copy from FFMPEG-3.0.2; doc/example/muxing.c .
26 #define STREAM_PIX_FMT AV_PIX_FMT_RGBA /* default pix_fmt */
28 //#define SCALE_FLAGS SWS_BICUBLIN
29 //#define SCALE_FLAGS SWS_POINT
30 #define SCALE_FLAGS SWS_FAST_BILINEAR
33 #include <QReadWriteLock>
34 #include <QWaitCondition>
41 long unpadded_linesize;
48 class DLL_PREFIX MOVIE_LOADER: public QObject
54 #if defined(USE_LIBAV)
55 AVFormatContext *fmt_ctx; // = NULL;
56 AVCodecContext *video_dec_ctx;// = NULL
57 AVCodecContext *audio_dec_ctx;
58 enum AVPixelFormat pix_fmt;
59 AVStream *video_stream, *audio_stream; // NULL
60 uint8_t *video_dst_data[4]; // = {NULL};
61 int video_dst_linesize[4];
62 int video_dst_bufsize;
63 int video_stream_idx, audio_stream_idx; //int video_stream_idx = -1, audio_stream_idx = -1;
64 AVFrame *frame; //AVFrame *frame = NULL;
66 struct SwsContext *sws_context;
67 struct SwrContext *swr_context;
69 int64_t video_frame_count; // = 0;
71 int64_t audio_total_samples;
74 int decode_packet(int *got_frame, int cached);
75 int open_codec_context(int *stream_idx, AVFormatContext *fmt_ctx, enum AVMediaType type);
76 int get_format_from_sample_fmt(const char **fmt, enum AVSampleFormat sample_fmt);
83 QMutex *snd_write_lock;
94 QString hwaccel_method;
99 int src_width, src_height;
100 int dst_width, dst_height;
101 int old_dst_width, old_dst_height;
103 QQueue<sound_data_queue_t *> sound_data_queue;
105 MOVIE_LOADER(OSD *osd, config_t *cfg);
107 bool open(QString filename);
110 void get_video_frame(void);
111 double get_movie_frame_rate(void);
112 int get_movie_sound_rate(void);
114 QReadWriteLock frame_lock;
115 QWaitCondition lock_cond;
117 uint64_t get_current_frame(void);
118 bool is_playing(void);
119 bool is_pausing(void);
122 void do_set_dst_geometry(int width, int height);
123 void do_set_enable_hwaccel_decoding(bool enable);
124 void do_set_enable_hwaccel_scaling(bool enable);
125 void do_set_dst_pixfmt(int type);
129 void do_pause(bool flag);
130 // void do_fast_forward(int ticks);
131 // void do_fast_rewind(int ticks);
132 void do_mute(bool left, bool right);
134 void do_decode_frames(int frames, int width, int height);
135 void do_seek_frame(bool relative, int frames);
136 void do_dequeue_audio();
139 int sig_send_audio_frame(uint8_t *, long); // Call callback.
140 int sig_movie_end(bool); // MOVIE END
141 int sig_movie_ready(bool); // ACK
142 int sig_decoding_error(int); // error_num
145 #endif //_QT_OSD_MOVIE_LOADER_H