rework android-rmt display, add a few buttons
[goodguy/history.git] / cinelerra-5.0 / cinelerra / ffmpeg.h
index 210e2171481bbea5920b30d77600dde1db57111b..68649d16218c5f03763c00b282e41589b762a1bc 100644 (file)
@@ -8,13 +8,18 @@
 #include <string.h>
 
 #include "arraylist.h"
-#include "linklist.h"
 #include "asset.inc"
 #include "bccmodels.h"
+#include "bcwindowbase.inc"
+#include "condition.h"
 #include "cstrdup.h"
+#include "linklist.h"
 #include "ffmpeg.inc"
 #include "filebase.inc"
 #include "fileffmpeg.inc"
+#include "indexstate.inc"
+#include "mutex.h"
+#include "thread.h"
 #include "vframe.inc"
 
 extern "C" {
@@ -61,32 +66,9 @@ public:
        void dequeue();
 };
 
-class FFAudioHistory {
-public:
-       float *inp, *outp, *bfr, *lmt;
-       long sz, bsz;
-       int nch;
-
-       FFAudioHistory();
-       ~FFAudioHistory();
-       void reserve(long sz, int nch);
-       void realloc(long sz, int nch);
-       long used();
-       long avail();
-       void reset();
-       void iseek(int64_t ofs);
-       float *get_outp(int len);
-       int64_t get_inp(int len);
-       int write(const float *fp, long len);
-       int copy(float *fp, long len);
-       int zero(long len);
-       int read(double *dp, long len, int ch);
-       int write(const double *dp, long len, int ch);
-};
-
 class FFStream {
 public:
-       FFStream(FFMPEG *ffmpeg, AVStream *st, int idx);
+       FFStream(FFMPEG *ffmpeg, AVStream *st, int fidx);
        ~FFStream();
        static void ff_lock(const char *cp=0);
        static void ff_unlock();
@@ -96,12 +78,20 @@ public:
        virtual int encode_activate();
        virtual int decode_activate();
        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 decode_frame(AVFrame *frame, int &got_frame) = 0;
+       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 init_frame(AVFrame *frame) = 0;
        virtual int create_filter(const char *filter_spec,
                AVCodecContext *src_ctx, AVCodecContext *sink_ctx) = 0;
+       virtual void load_markers() = 0;
        int create_filter(const char *filter_spec);
        int load_filter(AVFrame *frame);
        int read_filter(AVFrame *frame);
@@ -139,91 +129,122 @@ public:
        int frm_count;
        List<FFrame> frms;
        Mutex *frm_lock;
+       IndexMarks *index_markers;
 
        int64_t nudge;
-       int idx;
+       int64_t seek_pos, curr_pos;
+       int fidx;
        int reading, writing;
-       int eof;
-
-       int st_eof() {
-               return eof;
-       }
-       void st_eof(int v) {
-               if( !v ) { flushed = 0;  need_packet = 1; }
-               eof = v;
-       }
+       int seeked, eof;
+
+       int st_eof() { return eof; }
+       void st_eof(int v) { eof = v; }
 };
 
 class FFAudioStream : public FFStream {
+       float *inp, *outp, *bfr, *lmt;
+       int64_t hpos, sz;
+       int nch;
+
+       int read(float *fp, long len);
+       void realloc(long nsz, int nch, long len);
+       void realloc(long nsz, int nch);
+       void reserve(long nsz, int nch);
+       long used();
+       long avail();
+       void iseek(int64_t ofs);
+       float *get_outp(int len);
+       int64_t put_inp(int len);
+       int write(const float *fp, long len);
+       int zero(long len);
+       int write(const double *dp, long len, int ch);
 public:
-       FFAudioStream(FFMPEG *ffmpeg, AVStream *strm, int idx);
+       FFAudioStream(FFMPEG *ffmpeg, AVStream *strm, int idx, int fidx);
        virtual ~FFAudioStream();
-       int load_history(float *&bfr, int len);
-       int decode_frame(AVFrame *frame, int &got_frame);
+       int is_audio() { return 1; }
+       int is_video() { return 0; }
+       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);
+       void load_markers();
 
        int encode_activate();
        int nb_samples();
-       void alloc_history(int len);
-       void reserve_history(int len);
-       void append_history(const float *fp, int len);
-       void zero_history(int len);
        int64_t load_buffer(double ** const sp, int len);
-       float *get_history(int len);
        int in_history(int64_t pos);
+       void reset_history();
+       int read(double *dp, long len, int ch);
 
        int init_frame(AVFrame *frame);
        int load(int64_t pos, int len);
        int audio_seek(int64_t pos);
        int encode(double **samples, int len);
 
+       int idx;
        int channel0, channels;
        int sample_rate;
        int mbsz, frame_sz;
-       int64_t seek_pos, curr_pos;
        int64_t length;
 
-       FFAudioHistory history;
        SwrContext *resample_context;
        int aud_bfr_sz;
        float *aud_bfr;
 };
 
-class FFVideoStream : public FFStream {
+
+class FFVideoConvert {
 public:
-       FFVideoStream(FFMPEG *ffmpeg, AVStream *strm, int idx);
+       struct SwsContext *convert_ctx;
+
+       FFVideoConvert() { convert_ctx = 0; }
+       ~FFVideoConvert() { if( convert_ctx ) sws_freeContext(convert_ctx); }
+
+       static PixelFormat color_model_to_pix_fmt(int color_model);
+       static int pix_fmt_to_color_model(PixelFormat pix_fmt);
+
+       int convert_picture_vframe(VFrame *frame,
+               AVPicture *ip, PixelFormat ifmt, int iw, int ih);
+       int convert_cmodel(VFrame *frame_out,
+               AVPicture *ip, PixelFormat ifmt, int iw, int ih);
+       int transfer_cmodel(VFrame *frame_in,  //defaults->metadata
+               AVFrame *ifp, PixelFormat ifmt, int iw, int ih);
+       int convert_vframe_picture(VFrame *frame,
+               AVPicture *op, PixelFormat ofmt, int ow, int oh);
+       int convert_pixfmt(VFrame *frame_in,
+                AVPicture *op, PixelFormat ofmt, int ow, int oh);
+       int transfer_pixfmt(VFrame *frame_in,  //metadata->defaults
+                AVFrame *ofp, PixelFormat ofmt, int ow, int oh);
+};
+
+class FFVideoStream : public FFStream, public FFVideoConvert {
+public:
+       FFVideoStream(FFMPEG *ffmpeg, AVStream *strm, int idx, int fidx);
        virtual ~FFVideoStream();
-       int decode_frame(AVFrame *frame, int &got_frame);
+       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);
+       void load_markers();
 
        int init_frame(AVFrame *picture);
        int load(VFrame *vframe, int64_t pos);
        int video_seek(int64_t pos);
        int encode(VFrame *vframe);
 
+       int idx;
        double frame_rate;
        int width, height;
-       int64_t seek_pos, curr_pos;
        int64_t length;
        float aspect_ratio;
 
-       struct SwsContext *convert_ctx;
        uint8_t *pkt_bfr;
        int pkt_bfr_sz;
-
-       static PixelFormat color_model_to_pix_fmt(int color_model);
-       static int pix_fmt_to_color_model(PixelFormat pix_fmt);
-
-       int convert_picture_vframe(VFrame *frame,
-               AVPicture *ip, PixelFormat ifmt, int iw, int ih);
-       int convert_cmodel(VFrame *frame_out,
-               AVPicture *ip, PixelFormat ifmt, int iw, int ih);
-       int convert_vframe_picture(VFrame *frame,
-               AVPicture *op, PixelFormat ofmt, int ow, int oh);
-       int convert_pixfmt(VFrame *frame_in,
-                AVPicture *op, PixelFormat ofmt, int ow, int oh);
+       int64_t start_pts;
 };
 
 class FFMPEG : public Thread {
@@ -234,21 +255,23 @@ public:
 
        int check_sample_rate(AVCodec *codec, int sample_rate);
        AVRational check_frame_rate(AVCodec *codec, double frame_rate);
-       AVRational to_sample_aspect_ratio(double aspect_ratio);
+       AVRational to_sample_aspect_ratio(Asset *asset);
        AVRational to_time_base(int sample_rate);
 
        static void set_option_path(char *path, const char *fmt, ...);
        static void get_option_path(char *path, const char *type, const char *spec);
-       int check_option(const char *path, char *spec);
-       const char *get_file_format();
-       int scan_option_line(char *cp,char *tag,char *val);
-       int read_options(const char *options, char *format, char *codec,
-               char *bsfilter, char *bsargs, AVDictionary *&opts);
-       int read_options(FILE *fp, const char *options,
-               char *format, char *codec, AVDictionary *&opts);
+       static int get_format(char *format, const char *path, char *spec);
+       static int scan_option_line(char *cp,char *tag,char *val);
+       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 read_options(FILE *fp, const char *options, AVDictionary *&opts, int no=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);
+       static int load_options(const char *path, char *bfr, int len);
        void set_loglevel(const char *ap);
        static double to_secs(int64_t time, AVRational time_base);
        int info(char *text, int len);
@@ -256,7 +279,7 @@ public:
        int init_decoder(const char *filename);
        int open_decoder();
        int init_encoder(const char *filename);
-       int open_encoder(const char *path, const char *spec);
+       int open_encoder(const char *type, const char *spec);
        int close_encoder();
 
        int total_audio_channels();
@@ -287,7 +310,7 @@ public:
                uint16_t st_idx, st_ch;
                ffidx() { st_idx = st_ch = 0; }
                ffidx(const ffidx &t) { st_idx = t.st_idx;  st_ch = t.st_ch; }
-               ffidx(uint16_t idx, uint16_t ch) { st_idx = idx; st_ch = ch; }
+               ffidx(uint16_t fidx, uint16_t ch) { st_idx = fidx; st_ch = ch; }
        };
 
        ArrayList<ffidx> astrm_index;
@@ -311,6 +334,7 @@ public:
 
        FFMPEG(FileBase *file_base=0);
        ~FFMPEG();
+       int scan(IndexState *index_state, int64_t *scan_position, int *canceled);
 
        int ff_audio_stream(int channel) { return astrm_index[channel].st_idx; }
        int ff_video_stream(int layer) { return vstrm_index[layer].st_idx; }