OSDN Git Service

[General][I18N] Update Japanese translations.
[csp-qt/common_source_project-fm7.git] / source / src / qt / avio / movie_loader.h
1 /*
2  * Common Source Code Project for Qt : movie saver.
3  * (C) 2016 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  *  License: GPLv2
5  *  History: May 27, 2016 : Initial. This refer from ffmpeg: doc/examples/demuxing_decoding.c.
6  */
7
8 #ifndef _QT_OSD_MOVIE_LOADER_H
9 #define _QT_OSD_MOVIE_LOADER_H
10
11 #if defined(USE_LIBAV)
12 extern "C" {
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"
22 }
23 #endif
24
25 // Copy from FFMPEG-3.0.2; doc/example/muxing.c .
26 #define STREAM_PIX_FMT  AV_PIX_FMT_RGBA /* default pix_fmt */
27
28 //#define SCALE_FLAGS SWS_BICUBLIN
29 //#define SCALE_FLAGS SWS_POINT
30 #define SCALE_FLAGS SWS_FAST_BILINEAR
31
32 #include <QObject>
33 #include <QReadWriteLock>
34 #include <QWaitCondition>
35 #include <QQueue>
36
37 #include "config.h"
38
39 typedef struct {
40         uint8_t *data[4];
41         long unpadded_linesize;
42 } sound_data_queue_t;
43
44 QT_BEGIN_NAMESPACE
45 class OSD;
46 class QMutex;
47 class CSP_Logger;
48 class DLL_PREFIX MOVIE_LOADER: public QObject
49 {
50         Q_OBJECT
51 private:
52         bool req_transfer;
53         CSP_Logger *p_logger;
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;
65         AVPacket pkt;
66         struct SwsContext *sws_context;
67         struct SwrContext *swr_context;
68
69         int64_t video_frame_count; // = 0;
70         int64_t duration_us;
71         int64_t audio_total_samples;
72         
73         int refcount; // = 0
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);
77 #endif
78 protected:
79         OSD *p_osd;
80         config_t *p_cfg;
81
82         QMutex *video_mutex;
83         QMutex *snd_write_lock;
84         double frame_rate;
85         double mod_frames;
86         int sound_rate;
87         bool now_opening;
88         QString _filename;
89         
90         bool use_hwaccel;
91         QString video_format;
92         QString video_codec;
93         QString audio_codec;
94         QString hwaccel_method;
95
96         bool now_pausing;
97         bool now_playing;
98         
99         int src_width, src_height;
100         int dst_width, dst_height;
101         int old_dst_width, old_dst_height;
102
103         QQueue<sound_data_queue_t *> sound_data_queue;
104 public:
105         MOVIE_LOADER(OSD *osd, config_t *cfg);
106         ~MOVIE_LOADER();
107         bool open(QString filename);
108         void close();
109         
110         void get_video_frame(void);     
111         double  get_movie_frame_rate(void);
112         int get_movie_sound_rate(void);
113
114         QReadWriteLock frame_lock;
115         QWaitCondition lock_cond;
116         
117         uint64_t get_current_frame(void);
118         bool is_playing(void);
119         bool is_pausing(void);
120
121 public slots:
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);
126         
127         void do_play();
128         void do_stop();
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);
133
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();
137         
138 signals:
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
143 };
144 QT_END_NAMESPACE
145 #endif //_QT_OSD_MOVIE_LOADER_H
146