yuv colorspace/range + prefs, ffmpeg colorrange probe, x11 direct force colormodel...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / ffmpeg.h
index 4860c0021dd1c9a9d868d5a435e4e1e9b263620f..9a9f855249a1caf83434e00b998de1b8153e5c01 100644 (file)
@@ -40,12 +40,14 @@ extern "C" {
 class FFPacket  {
        AVPacket pkt;
 public:
-       FFPacket();
-       ~FFPacket();
-       void init();
        operator AVPacket*() { return &pkt; }
        operator AVPacket&() { return pkt; }
        AVPacket *operator ->() { return &pkt; }
+
+       void init();
+       void finit();
+       FFPacket() { init(); }
+       ~FFPacket() { finit(); }
 };
 
 class FFrame : public ListItem<FFrame> {
@@ -78,21 +80,21 @@ public:
 
        virtual int encode_activate();
        virtual int decode_activate();
+       virtual int write_packet(FFPacket &pkt);
        int read_packet();
        int seek(int64_t no, double rate);
-       int write_packet(FFPacket &pkt);
        int flush();
        int decode(AVFrame *frame);
        void load_markers(IndexMarks &marks, double rate);
 
        virtual int is_audio() = 0;
        virtual int is_video() = 0;
-       virtual int decode_frame(AVPacket *pkt, AVFrame *frame, int &got_frame) = 0;
-       virtual int encode_frame(AVPacket *pkt, AVFrame *frame, int &got_frame) = 0;
+       virtual int decode_frame(AVFrame *frame) = 0;
+       virtual int encode_frame(AVFrame *frame) = 0;
        virtual int init_frame(AVFrame *frame) = 0;
-       virtual int create_filter(const char *filter_spec,
-               AVCodecContext *src_ctx, AVCodecContext *sink_ctx) = 0;
+       virtual int create_filter(const char *filter_spec, AVCodecParameters *avpar) = 0;
        virtual void load_markers() = 0;
+       virtual IndexMarks *get_markers() = 0;
        int create_filter(const char *filter_spec);
        int load_filter(AVFrame *frame);
        int read_filter(AVFrame *frame);
@@ -101,28 +103,13 @@ public:
        FFMPEG *ffmpeg;
        AVStream *st;
        AVFormatContext *fmt_ctx;
+       AVCodecContext *avctx;
 
        AVFilterContext *buffersink_ctx;
        AVFilterContext *buffersrc_ctx;
        AVFilterGraph *filter_graph;
        AVFrame *frame, *fframe;
-
-       class BSFilter {
-       public:
-               AVBitStreamFilterContext *bsfc;
-               const char *args;
-               BSFilter(const char *bsf, const char *ap) {
-                       bsfc = av_bitstream_filter_init(bsf);
-                       args = ap ? cstrdup(ap) : 0;
-               }
-               ~BSFilter() {
-                       av_bitstream_filter_close(bsfc);
-                       delete [] args;
-               }
-       };
-       void add_bsfilter(const char *bsf, const char *ap);
-       ArrayList<BSFilter *> bsfilter;
-       int bs_filter(AVPacket *pkt);
+       AVBSFContext *bsfc;
 
        FFPacket ipkt;
        int need_packet, flushed;
@@ -130,7 +117,6 @@ public:
        int frm_count;
        List<FFrame> frms;
        Mutex *frm_lock;
-       IndexMarks *index_markers;
 
        int64_t nudge;
        int64_t seek_pos, curr_pos;
@@ -159,21 +145,22 @@ class FFAudioStream : public FFStream {
        int write(const float *fp, long len);
        int zero(long len);
        int write(const double *dp, long len, int ch);
+       int write_packet(FFPacket &pkt);
 public:
        FFAudioStream(FFMPEG *ffmpeg, AVStream *strm, int idx, int fidx);
        virtual ~FFAudioStream();
        int is_audio() { return 1; }
        int is_video() { return 0; }
+       void init_swr(int ichs, int ifmt, int irate);
        int get_samples(float *&samples, uint8_t **data, int len);
        int load_history(uint8_t **data, int len);
-       int decode_frame(AVPacket *pkt, AVFrame *frame, int &got_frame);
-       int encode_frame(AVPacket *pkt, AVFrame *frame, int &got_frame);
-       int create_filter(const char *filter_spec,
-               AVCodecContext *src_ctx, AVCodecContext *sink_ctx);
+       int decode_frame(AVFrame *frame);
+       int encode_frame(AVFrame *frame);
+       int create_filter(const char *filter_spec, AVCodecParameters *avpar);
        void load_markers();
+       IndexMarks *get_markers();
 
        int encode_activate();
-       int nb_samples();
        int64_t load_buffer(double ** const sp, int len);
        int in_history(int64_t pos);
        void reset_history();
@@ -183,6 +170,7 @@ public:
        int load(int64_t pos, int len);
        int audio_seek(int64_t pos);
        int encode(double **samples, int len);
+       int drain();
 
        int idx;
        int channel0, channels;
@@ -191,6 +179,7 @@ public:
        int64_t length;
 
        SwrContext *resample_context;
+       int swr_ichs, swr_ifmt, swr_irate;
        int aud_bfr_sz;
        float *aud_bfr;
 };
@@ -206,36 +195,34 @@ public:
        static AVPixelFormat color_model_to_pix_fmt(int color_model);
        static int pix_fmt_to_color_model(AVPixelFormat pix_fmt);
 
-       int convert_picture_vframe(VFrame *frame,
-               AVFrame *ip, AVPixelFormat ifmt, int iw, int ih);
-       int convert_cmodel(VFrame *frame_out,
-               AVFrame *ip, AVPixelFormat ifmt, int iw, int ih);
-       int transfer_cmodel(VFrame *frame_in,  //defaults->metadata
-               AVFrame *ifp, AVPixelFormat ifmt, int iw, int ih);
-       int convert_vframe_picture(VFrame *frame,
-               AVFrame *op, AVPixelFormat ofmt, int ow, int oh);
-       int convert_pixfmt(VFrame *frame_in,
-                AVFrame *op, AVPixelFormat ofmt, int ow, int oh);
-       int transfer_pixfmt(VFrame *frame_in,  //metadata->defaults
-                AVFrame *ofp, AVPixelFormat ofmt, int ow, int oh);
+       int convert_picture_vframe(VFrame *frame, AVFrame *ip);
+       int convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame *ipic);
+       int convert_cmodel(VFrame *frame, AVFrame *ip);
+       int transfer_cmodel(VFrame *frame, AVFrame *ifp);
+       int convert_vframe_picture(VFrame *frame, AVFrame *op);
+       int convert_vframe_picture(VFrame *frame, AVFrame *op, AVFrame *opic);
+       int convert_pixfmt(VFrame *frame, AVFrame *op);
+       int transfer_pixfmt(VFrame *frame, AVFrame *ofp);
 };
 
 class FFVideoStream : public FFStream, public FFVideoConvert {
+       int write_packet(FFPacket &pkt);
 public:
        FFVideoStream(FFMPEG *ffmpeg, AVStream *strm, int idx, int fidx);
        virtual ~FFVideoStream();
        int is_audio() { return 0; }
        int is_video() { return 1; }
-       int decode_frame(AVPacket *pkt, AVFrame *frame, int &got_frame);
-       int encode_frame(AVPacket *pkt, AVFrame *frame, int &got_frame);
-       int create_filter(const char *filter_spec,
-               AVCodecContext *src_ctx, AVCodecContext *sink_ctx);
+       int decode_frame(AVFrame *frame);
+       int encode_frame(AVFrame *frame);
+       int create_filter(const char *filter_spec, AVCodecParameters *avpar);
        void load_markers();
+       IndexMarks *get_markers();
 
        int init_frame(AVFrame *picture);
        int load(VFrame *vframe, int64_t pos);
        int video_seek(int64_t pos);
        int encode(VFrame *vframe);
+       int drain();
 
        int idx;
        double frame_rate;
@@ -243,9 +230,8 @@ public:
        int64_t length;
        float aspect_ratio;
 
-       uint8_t *pkt_bfr;
-       int pkt_bfr_sz;
-       int64_t start_pts;
+       int interlaced;
+       int top_field_first;
 };
 
 class FFMPEG : public Thread {
@@ -261,17 +247,16 @@ public:
 
        static void set_option_path(char *path, const char *fmt, ...);
        static void get_option_path(char *path, const char *type, const char *spec);
-       static int get_format(char *format, const char *path, char *spec);
+       static int get_format(char *format, const char *path, const char *spec);
+       static int get_codec(char *codec, const char *path, const char *spec);
        static int scan_option_line(char *cp,char *tag,char *val);
        static int load_defaults(const char *path, const char *type,
                 char *codec, char *codec_options, int len);
        static void set_asset_format(Asset *asset, const char *text);
        int get_file_format();
-       int get_encoder(const char *options,
-               char *format, char *codec, char *bsfilter, char *bsargs);
-       int get_encoder(FILE *fp,
-               char *format, char *codec, char *bsfilter, char *bsargs);
-       int read_options(const char *options, AVDictionary *&opts);
+       int get_encoder(const char *options, char *format, char *codec, char *bsfilter);
+       int get_encoder(FILE *fp, char *format, char *codec, char *bsfilter);
+       int read_options(const char *options, AVDictionary *&opts, int skip=0);
        int scan_options(const char *options, AVDictionary *&opts, AVStream *st);
        int read_options(FILE *fp, const char *options, AVDictionary *&opts);
        int load_options(const char *options, AVDictionary *&opts);
@@ -324,7 +309,7 @@ public:
        Condition *mux_lock;
        Condition *flow_lock;
        int done, flow;
-       
+
        void start_muxer();
        void stop_muxer();
        void flow_off();
@@ -365,6 +350,7 @@ public:
        const char *ff_video_format(int stream);
        int64_t ff_video_frames(int stream);
        int ff_video_pid(int stream);
+       int ff_video_mpeg_color_range(int stream);
 
        int ff_cpus();
        void dump_context(AVCodecContext *ctx);