[gnome-sound-recorder] redefined audioProfile



commit 2fa3299ef54a91b77440f77b419c41e17a19e42b
Author: Kavan Mevada <kavanmevada gmail com>
Date:   Thu Apr 9 20:06:07 2020 +0530

    redefined audioProfile

 data/org.gnome.SoundRecorder.gschema.xml.in      |   1 +
 data/ui/infodialog.ui                            |   1 +
 data/ui/preferences.ui                           |   7 --
 po/POTFILES.in                                   |   1 -
 src/audioProfile.js                              | 118 -----------------------
 src/encodingProfile.js                           |  73 ++++++++++++++
 src/info.js                                      |   7 +-
 src/mainWindow.js                                |  13 +--
 src/org.gnome.SoundRecorder.src.gresource.xml.in |   2 +-
 src/preferences.js                               |  20 +++-
 src/record.js                                    |  16 +--
 11 files changed, 104 insertions(+), 155 deletions(-)
---
diff --git a/data/org.gnome.SoundRecorder.gschema.xml.in b/data/org.gnome.SoundRecorder.gschema.xml.in
index 97a656c..0266e61 100644
--- a/data/org.gnome.SoundRecorder.gschema.xml.in
+++ b/data/org.gnome.SoundRecorder.gschema.xml.in
@@ -34,3 +34,4 @@
 </schemalist>
 
 
+
diff --git a/data/ui/infodialog.ui b/data/ui/infodialog.ui
index 2e38829..e939418 100644
--- a/data/ui/infodialog.ui
+++ b/data/ui/infodialog.ui
@@ -151,6 +151,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="halign">start</property>
+                <property name="label" translatable="yes">Unknown</property>
               </object>
               <packing>
                 <property name="left_attach">1</property>
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
index 45a60ba..4cc308c 100644
--- a/data/ui/preferences.ui
+++ b/data/ui/preferences.ui
@@ -73,13 +73,6 @@
                 <property name="halign">start</property>
                 <property name="valign">center</property>
                 <property name="active">0</property>
-                <items>
-                  <item translatable="yes">Ogg Vorbis</item>
-                  <item translatable="yes">Opus</item>
-                  <item translatable="yes">FLAC</item>
-                  <item translatable="yes">MP3</item>
-                  <item translatable="yes">MOV</item>
-                </items>
               </object>
               <packing>
                 <property name="left_attach">1</property>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0ebedb3..1f5cd97 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,7 +5,6 @@ data/ui/window.ui
 data/ui/preferences.ui
 data/ui/infodialog.ui
 data/ui/row.ui
-src/audioProfile.js
 src/application.js
 src/utils.js
 src/info.js
diff --git a/src/encodingProfile.js b/src/encodingProfile.js
new file mode 100644
index 0000000..33186eb
--- /dev/null
+++ b/src/encodingProfile.js
@@ -0,0 +1,73 @@
+const Gst = imports.gi.Gst;
+const GstPbutils = imports.gi.GstPbutils;
+
+
+const EncodingProfile = {
+    Profiles: {
+        VORBIS: { index: 0,
+            name: 'VORBIS',
+            containerCaps: 'application/ogg;audio/ogg;video/ogg',
+            audioCaps: 'audio/x-vorbis',
+            mimeType: 'audio/x-vorbis' },
+
+        OPUS: { index: 1,
+            name: 'OPUS',
+            containerCaps: 'application/ogg',
+            audioCaps: 'audio/x-opus',
+            mimeType: 'audio/x-opus' },
+
+        FLAC: { index: 2,
+            name: 'FLAC',
+            containerCaps: 'audio/x-flac',
+            audioCaps: 'audio/x-flac',
+            mimeType: 'audio/x-flac' },
+
+        MP3: { index: 3,
+            name: 'MP3',
+            containerCaps: 'application/x-id3',
+            audioCaps: 'audio/mpeg,mpegversion=(int)1,layer=(int)3',
+            mimeType: 'audio/mpeg' },
+
+        M4A: { index: 4,
+            name: 'M4A',
+            containerCaps: 'video/quicktime,variant=(string)iso',
+            audioCaps: 'audio/mpeg,mpegversion=(int)4',
+            mimeType: 'audio/mpeg' },
+    },
+
+
+
+    fromSettings: index => {
+        let profile;
+        switch (index) {
+        case 0:
+            profile = EncodingProfile.Profiles.VORBIS;
+            break;
+        case 1:
+            profile = EncodingProfile.Profiles.OPUS;
+            break;
+        case 2:
+            profile = EncodingProfile.Profiles.FLAC;
+            break;
+        case 3:
+            profile = EncodingProfile.Profiles.MP3;
+            break;
+        case 4:
+            profile = EncodingProfile.Profiles.M4A;
+            break;
+        }
+
+        return EncodingProfile.create(profile);
+    },
+
+
+    create: profile => {
+        let audioCaps = Gst.Caps.from_string(profile.audioCaps);
+        let encodingProfile = GstPbutils.EncodingAudioProfile.new(audioCaps, null, null, 1);
+        let containerCaps = Gst.Caps.from_string(profile.containerCaps);
+        let containerProfile = GstPbutils.EncodingContainerProfile.new('record', null, containerCaps, null);
+        containerProfile.add_profile(encodingProfile);
+
+        return containerProfile;
+    },
+};
diff --git a/src/info.js b/src/info.js
index 90dc799..4542780 100644
--- a/src/info.js
+++ b/src/info.js
@@ -23,7 +23,9 @@ const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
 const GObject = imports.gi.GObject;
+
 const Utils = imports.utils;
+const EncodingProfile = imports.encodingProfile.EncodingProfile;
 
 
 var InfoDialog = GObject.registerClass({ // eslint-disable-line no-unused-vars
@@ -48,7 +50,10 @@ var InfoDialog = GObject.registerClass({ // eslint-disable-line no-unused-vars
         }
 
         this._dateModifiedValueLabel.label = Utils.Time.getDisplayTime(recording.timeModified);
-        this._mediaTypeLabel.label = recording.mimeType || _('Unknown');
+        Object.values(EncodingProfile.Profiles).forEach(profile => {
+            if (profile.mimeType === recording.mimeType)
+                this._mediaTypeLabel.label = profile.name;
+        });
 
         this._cancelBtn.connect('clicked', () => {
             this.destroy();
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 5929964..3ef2c01 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -25,7 +25,6 @@ const Gio = imports.gi.Gio;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 
-const AudioProfile = imports.audioProfile;
 const Utils = imports.utils;
 const RecordingList = imports.recordingList.RecordingList;
 const Recording = imports.recording.Recording;
@@ -35,8 +34,6 @@ const Player = imports.player.Player;
 const Record = imports.record;
 const Waveform = imports.waveform;
 
-let activeProfile = null;
-var audioProfile = null;
 var displayTime = null;
 var player = null;
 var recordPipeline = null;
@@ -58,8 +55,7 @@ var MainWindow = GObject.registerClass({
             icon_name: pkg.name,
         }, params));
 
-        audioProfile = new AudioProfile.AudioProfile();
-        this._record = new Record.Record(audioProfile);
+        this._record = new Record.Record();
         player = new Player();
         view = this;
 
@@ -100,12 +96,7 @@ var MainWindow = GObject.registerClass({
         player.stopPlaying();
         this._mainStack.set_visible_child_name('mainView');
         this._recordGrid.show();
-
-        if (activeProfile === null)
-            activeProfile = 0;
-
-        audioProfile.profile(activeProfile);
-        this._record.startRecording(activeProfile);
+        this._record.startRecording();
 
         wave = new Waveform.WaveForm(this._recordGrid, null);
     }
diff --git a/src/org.gnome.SoundRecorder.src.gresource.xml.in 
b/src/org.gnome.SoundRecorder.src.gresource.xml.in
index 988ddb7..fa99836 100644
--- a/src/org.gnome.SoundRecorder.src.gresource.xml.in
+++ b/src/org.gnome.SoundRecorder.src.gresource.xml.in
@@ -2,7 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/SoundRecorder@profile@/js">
     <file>application.js</file>
-    <file>audioProfile.js</file>
+    <file>encodingProfile.js</file>
     <file>utils.js</file>
     <file>info.js</file>
     <file>recordingList.js</file>
diff --git a/src/preferences.js b/src/preferences.js
index 8d76768..439149e 100644
--- a/src/preferences.js
+++ b/src/preferences.js
@@ -22,15 +22,18 @@ const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
 const GObject = imports.gi.GObject;
 
+var EncodingProfile = imports.encodingProfile.EncodingProfile;
+
+
 let _settings = new Gio.Settings({ schema: pkg.name });
 
 var settings = {
-    get mediaCodec() {
+    get encodingProfile() {
         return _settings.get_int('media-type-preset');
     },
 
-    set mediaCodec(profileName) {
-        _settings.set_int('media-type-preset', profileName);
+    set encodingProfile(profile) {
+        _settings.get_int('media-type-preset', profile);
     },
 
     get channel() {
@@ -69,9 +72,16 @@ var SettingsDialog = GObject.registerClass({ // eslint-disable-line no-unused-va
             this.destroy();
         });
 
-        this._formateComboBox.set_active(settings.mediaCodec);
+
+
+
+        Object.values(EncodingProfile.Profiles).forEach(profile => {
+            let index = profile.index.toString();
+            this._formateComboBox.append(index, profile.name);
+        });
+        this._formateComboBox.set_active(settings.encodingProfile);
         this._formateComboBox.connect('changed', () => {
-            settings.mediaCodec = this._formateComboBox.get_active();
+            settings.encodingProfile = this._formateComboBox.get_active();
         });
 
         this._channelsComboBox.set_active(settings.channel);
diff --git a/src/record.js b/src/record.js
index 8903b95..e3df63d 100644
--- a/src/record.js
+++ b/src/record.js
@@ -28,6 +28,7 @@ const Gtk = imports.gi.Gtk;
 const Application = imports.application;
 const Settings = imports.preferences;
 const MainWindow = imports.mainWindow;
+const EncodingProfile = imports.encodingProfile.EncodingProfile;
 
 var PipelineStates = {
     PLAYING: 0,
@@ -116,7 +117,8 @@ var Record = class Record {
             }
         });
         this.pipeline.add(this.ebin);
-        this.ebin.set_property('profile', this._mediaProfile);
+        let audioProfile = EncodingProfile.fromSettings(Settings.settings.encodingProfile);
+        this.ebin.set_property('profile', audioProfile);
         this.filesink = Gst.ElementFactory.make('filesink', 'filesink');
         this.filesink.set_property('location', this.initialFileName);
         this.pipeline.add(this.filesink);
@@ -153,16 +155,7 @@ var Record = class Record {
         return true;
     }
 
-    startRecording(profile) {
-        this.profile = profile;
-        this._audioProfile = MainWindow.audioProfile;
-        this._mediaProfile = this._audioProfile.mediaProfile();
-
-        if (this._mediaProfile === -1) {
-            this._showErrorDialog(_('No Media Profile was set.'));
-            errorDialogState = ErrState.ON;
-        }
-
+    startRecording() {
         if (!this.pipeline || this.pipeState === PipelineStates.STOPPED)
             this._recordPipeline();
 
@@ -354,3 +347,4 @@ const BuildFileName = class BuildFileName {
         return this.dateTime;
     }
 };
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]