rework android-rmt display, add a few buttons
[goodguy/history.git] / cinelerra-5.0 / cinelerra / formattools.C
index b27409f96ed9e3ef55ee3188c41e22940d4153d6..f277fde29e319d0c7ab32dfb9c93227e61a08836 100644 (file)
 #include "filesystem.h"
 #include "formattools.h"
 #include "language.h"
+#include "libdv.h"
+#include "libmjpeg.h"
 #include "maxchannels.h"
 #include "mwindow.h"
 #include "preferences.h"
-#include "quicktime.h"
 #include "theme.h"
 #include "videodevice.inc"
 #include <string.h>
@@ -52,10 +53,34 @@ FormatTools::FormatTools(MWindow *mwindow,
        aparams_thread = 0;
        vparams_thread = 0;
        channels_tumbler = 0;
+       audio_switch = 0;
+       video_switch = 0;
        path_textbox = 0;
        path_button = 0;
-       w = window->get_w();
+       format_title = 0;
+       format_button = 0;
+       format_text = 0;
+       audio_title = 0;
+       audio_switch = 0;
+       video_title = 0;
+       video_switch = 0;
+       channels_title = 0;
+       channels_button = 0;
+       multiple_files = 0;
        file_entries = 0;
+       w = window->get_w();
+
+       recording = 0;
+       use_brender = 0;
+       do_audio = 0;
+       do_video = 0;
+       prompt_audio = 0;
+       prompt_audio_channels = 0;
+       prompt_video = 0;
+       prompt_video_compression = 0;
+       strategy = 0;
+       locked_compressor = 0;
+       video_driver = 0;
 }
 
 FormatTools::~FormatTools()
@@ -177,12 +202,17 @@ void FormatTools::create_objects(int &init_x,
 
        window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
        x += 90;
-       window->add_subwindow(format_text = new BC_TextBox(x, y, 200, 1, 
+       window->add_subwindow(format_text = new BC_TextBox(x, y, 180, 1, 
                File::formattostr(asset->format)));
        x += format_text->get_w();
 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
        window->add_subwindow(format_button = new FormatFormat(x, y, this));
        format_button->create_objects();
+       x += format_button->get_w() + 5;
+       window->add_subwindow(ffmpeg_type = new FFMpegType(x, y, 50, 1, asset->fformat));
+       x += ffmpeg_type->get_w();
+       window->add_subwindow(format_ffmpeg = new FormatFFMPEG(x, y, this));
+       format_ffmpeg->create_objects();
 
        x = init_x;
        y += format_button->get_h() + 10;
@@ -263,6 +293,7 @@ void FormatTools::update_driver(int driver)
 {
        this->video_driver = driver;
 
+       locked_compressor = 0;
        switch(driver)
        {
                case CAPTURE_DVB:
@@ -275,81 +306,76 @@ void FormatTools::update_driver(int driver)
                                format_text->update(_("MPEG stream"));
                                asset->format = FILE_MPEG;
                        }
-                       locked_compressor = 0;
                        audio_switch->update(1);
                        video_switch->update(1);
                        break;
 
                case CAPTURE_IEC61883:
                case CAPTURE_FIREWIRE:
+               case CAPTURE_LML:
                case CAPTURE_BUZ:
                case VIDEO4LINUX2JPEG:
                case CAPTURE_JPEG_WEBCAM:
-                       if(asset->format != FILE_AVI &&
-                               asset->format != FILE_MOV)
-                       {
-                               format_text->update(MOV_NAME);
-                               asset->format = FILE_MOV;
-                       }
-                       else
-                               format_text->update(File::formattostr(asset->format));
-
-                       switch(driver)
-                       {
-                               case CAPTURE_IEC61883:
-                               case CAPTURE_FIREWIRE:
-                                       locked_compressor = (char*)QUICKTIME_DVSD;
-                                       strcpy(asset->vcodec, QUICKTIME_DVSD);
-                                       break;
-
-                               case CAPTURE_BUZ:
-                               case VIDEO4LINUX2JPEG:
-                                       locked_compressor = (char*)QUICKTIME_MJPA;
-                                       strcpy(asset->vcodec, QUICKTIME_MJPA);
-                                       break;
+                       asset->format = FILE_FFMPEG;
+                       format_text->update(File::formattostr(asset->format));
 
-                               case CAPTURE_JPEG_WEBCAM:
-                                       locked_compressor = (char*)QUICKTIME_JPEG;
-                                       strcpy(asset->vcodec, QUICKTIME_JPEG);
-                                       break;
+                       switch(driver) {
+                       case CAPTURE_IEC61883:
+                       case CAPTURE_FIREWIRE:
+                               locked_compressor = (char*)CODEC_TAG_DVSD;
+                               break;
+
+                       case CAPTURE_BUZ:
+                       case CAPTURE_LML:
+                       case VIDEO4LINUX2JPEG:
+                               locked_compressor = (char*)CODEC_TAG_MJPEG;
+                               break;
+
+                       case CAPTURE_JPEG_WEBCAM:
+                               locked_compressor = (char*)CODEC_TAG_JPEG;
+                               break;
                        }
+                       if( locked_compressor )
+                               strcpy(asset->vcodec, locked_compressor);
 
                        audio_switch->update(asset->audio_data);
                        video_switch->update(asset->video_data);
                        break;
 
-
-
-
-
                default:
                        format_text->update(File::formattostr(asset->format));
-                       locked_compressor = 0;
                        audio_switch->update(asset->audio_data);
                        video_switch->update(asset->video_data);
                        break;
        }
        close_format_windows();
+       update_format();
 }
 
 void FormatTools::update_format()
 {
-       if( do_audio && audio_switch ) {
-               asset->audio_data = File::supports_audio(asset->format);
+       if( do_audio && prompt_audio && audio_switch ) {
                audio_switch->update(asset->audio_data);
                if( !asset->audio_data )
                        audio_switch->disable();
                else
                        audio_switch->enable();
        }
-       if( do_video && video_switch ) {
-               asset->video_data = File::supports_video(asset->format);
+       if( do_video && prompt_video && video_switch ) {
                video_switch->update(asset->video_data);
                if( !asset->video_data )
                        video_switch->disable();
                else
                        video_switch->enable();
        }
+       if( asset->format == FILE_FFMPEG ) {
+               ffmpeg_type->show();
+               format_ffmpeg->show();
+       }
+       else {
+               ffmpeg_type->hide();
+               format_ffmpeg->hide();
+       }
 }
 
 int FormatTools::handle_event()
@@ -367,7 +393,7 @@ void FormatTools::update_extension()
        const char *extension = File::get_tag(asset->format);
 // split multiple extensions
        ArrayList<const char*> extensions;
-       int len = strlen(extension);
+       int len = !extension ? -1 : strlen(extension);
        const char *extension_ptr = extension;
        for(int i = 0; i <= len; i++)
        {
@@ -420,7 +446,8 @@ void FormatTools::update_extension()
                if(need_extension) 
                {
                        char *ptr1 = ptr;
-                       extension_ptr = extensions.get(0);
+                       extension_ptr = asset->format != FILE_FFMPEG ?
+                               extensions.get(0) : asset->fformat;
                        while(*extension_ptr != 0 && *extension_ptr != '/')
                                *ptr1++ = *extension_ptr++;
                        *ptr1 = 0;
@@ -445,8 +472,10 @@ void FormatTools::update(Asset *asset, int *strategy)
        if(path_textbox) 
                path_textbox->update(asset->path);
        format_text->update(File::formattostr(plugindb, asset->format));
-       if(do_audio && audio_switch) audio_switch->update(asset->audio_data);
-       if(do_video && video_switch) video_switch->update(asset->video_data);
+       if(do_audio && prompt_audio && audio_switch)
+               audio_switch->update(asset->audio_data);
+       if(do_video && prompt_video && video_switch)
+               video_switch->update(asset->video_data);
        if(strategy)
        {
                multiple_files->update(strategy);
@@ -783,13 +812,16 @@ FormatFormat::~FormatFormat()
 
 int FormatFormat::handle_event()
 {
-       if(get_selection(0, 0) >= 0)
-       {
+       BC_ListBoxItem *selection = get_selection(0, 0);
+       if( selection ) {
                int new_format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text());
 //             if(new_format != format->asset->format)
                {
-                       format->asset->format = new_format;
-                       format->format_text->update(get_selection(0, 0)->get_text());
+                       Asset *asset = format->asset;
+                       asset->format = new_format;
+                       asset->audio_data = File::supports_audio(asset->format);
+                       asset->video_data = File::supports_video(asset->format);
+                       format->format_text->update(selection->get_text());
                        format->update_extension();
                        format->close_format_windows();
                        format->update_format();
@@ -799,6 +831,59 @@ int FormatFormat::handle_event()
 }
 
 
+FormatFFMPEG::FormatFFMPEG(int x, int y, FormatTools *format)
+ : FFMPEGPopup(format->plugindb, x, y)
+{ 
+       this->format = format; 
+}
+
+FormatFFMPEG::~FormatFFMPEG() 
+{
+}
+
+int FormatFFMPEG::load_defaults(const char *path, const char *type,
+                char *codec, char *codec_options, int len)
+{
+       char default_file[BCTEXTLEN];
+       FFMPEG::set_option_path(default_file, "%s/%s.dfl", path, type);
+       FILE *fp = fopen(default_file,"r");
+       if( !fp ) return 1;
+       fgets(codec, BCSTRLEN, fp);
+       char *cp = codec;
+       while( *cp && *cp!='\n' ) ++cp;
+       *cp = 0;
+       while( len > 0 && fgets(codec_options, len, fp) ) {
+               int n = strlen(codec_options);
+               codec_options += n;  len -= n;
+       }
+       fclose(fp);
+       FFMPEG::set_option_path(default_file, "%s/%s", path, codec);
+       return FFMPEG::load_options(default_file, codec_options, len);
+}
+
+int FormatFFMPEG::handle_event()
+{
+       BC_ListBoxItem *selection = get_selection(0, 0);
+       if( selection ) {
+               char *text = get_selection(0, 0)->get_text();
+               format->ffmpeg_type->update(text);
+               Asset *asset = format->asset;
+               strcpy(asset->fformat, text);
+               strcpy(asset->ff_audio_options, "");
+               strcpy(asset->ff_video_options, "");
+               asset->audio_data = !load_defaults("audio", text, asset->acodec,
+                       asset->ff_audio_options, sizeof(asset->ff_audio_options));
+               asset->video_data = !load_defaults("video", text, asset->vcodec,
+                       asset->ff_video_options, sizeof(asset->ff_video_options));
+               format->update_extension();
+               format->close_format_windows();
+               format->update_format();
+       }
+       return 1;
+}
+
+
+
 
 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
  : BC_TextBox(x, y, 100, 1, format->asset->channels)