[mythtv] [PATCH] mythmusic: lameencoder bugfix / switch to VERBOSE logging macro

Stefan Frank sfr+lists at 6913304088794.gnuu.de
Wed Dec 17 13:18:47 EST 2003


This fixes the segfault when the output file is non-writable which
has been reported in the past. But it started with the change of 
log messages to use the VERBOSE macro instead of cout directly. 

Thor, have a look at the patch and apply it if it looks ok to you.
As the VERBOSE options are tailored for mythtv i only used GENERAL or
ALL for now. What about adding a DEBUG option? There are some couts left
which are only used for debugging.

Bye, Stefan

-- 
BOFH excuse #290:

The CPU has shifted, and become decentralized.
-------------- next part --------------
diff -ur mythmusic/mythmusic/cddecoder.cpp mythmusic-local/mythmusic/cddecoder.cpp
--- mythmusic/mythmusic/cddecoder.cpp	2003-09-10 02:21:45.000000000 +0200
+++ mythmusic-local/mythmusic/cddecoder.cpp	2003-12-17 15:18:35.000000000 +0100
@@ -424,7 +424,7 @@
     if (ret < 0)
     {
         cd_finish(cd);
-        cout << "bad lookup :(\n";
+        VERBOSE(VB_ALL, QString("Error during CD lookup: %1").arg(ret));
         return NULL;
     }
 
@@ -501,7 +501,7 @@
     if (ret < 0)
     {
         cd_finish(cd);
-        cout << "bad lookup :(\n";
+        VERBOSE(VB_ALL, QString("Error during CD lookup: %1").arg(ret));
         return;
     }
   
diff -ur mythmusic/mythmusic/cdrip.cpp mythmusic-local/mythmusic/cdrip.cpp
--- mythmusic/mythmusic/cdrip.cpp	2003-12-05 02:18:42.000000000 +0100
+++ mythmusic-local/mythmusic/cdrip.cpp	2003-12-17 17:21:35.000000000 +0100
@@ -362,7 +362,7 @@
         QString tempstr = QString::number(track->Track(), 10);
         tempstr += " - " + track->Title();
         filename += fixFileToken(tempstr);
-        cout << "Invalid file storage definition.\n";
+        VERBOSE(VB_GENERAL, QString("Invalid file storage definition."));
     }
 
     if (no_ws)
@@ -514,7 +514,7 @@
 
     if (!PostRipCDScript.isEmpty()) 
     {
-        cout << "PostCDRipScript: " << PostRipCDScript << endl;
+        VERBOSE(VB_ALL, QString("PostCDRipScript: %1").arg(PostRipCDScript));
         pid_t child = fork();
         if (child < 0)
         {
diff -ur mythmusic/mythmusic/databasebox.cpp mythmusic-local/mythmusic/databasebox.cpp
--- mythmusic/mythmusic/databasebox.cpp	2003-12-05 21:24:45.000000000 +0100
+++ mythmusic-local/mythmusic/databasebox.cpp	2003-12-17 15:53:33.000000000 +0100
@@ -896,7 +896,7 @@
     if (tracknum != all_music->getCDTrackCount())
     {
         cd_status_changed = true;
-        cout << "set cd_status_changed to true " << endl ;
+        VERBOSE(VB_ALL, QString("Set cd_status_changed to true"));
     }
     else
         cd_status_changed = false;
diff -ur mythmusic/mythmusic/encoder.cpp mythmusic-local/mythmusic/encoder.cpp
--- mythmusic/mythmusic/encoder.cpp	2003-12-05 02:18:42.000000000 +0100
+++ mythmusic-local/mythmusic/encoder.cpp	2003-12-17 16:13:36.000000000 +0100
@@ -3,6 +3,8 @@
 #include "metadata.h"
 #include "encoder.h"
 
+#include <mythtv/mythcontext.h> 
+
 using namespace std;
 
 Encoder::Encoder(const QString &outfile, int qualitylevel, Metadata *metadata) 
@@ -11,7 +13,7 @@
     {
         out = fopen(outfile.ascii(), "w");
         if (!out) 
-            cout << "ERROR opening output file " << outfile << "\n";
+            VERBOSE(VB_GENERAL, QString("Error opening output file: %1").arg(outfile));
     } 
     else 
         out = NULL;
diff -ur mythmusic/mythmusic/flacencoder.cpp mythmusic-local/mythmusic/flacencoder.cpp
--- mythmusic/mythmusic/flacencoder.cpp	2003-02-10 18:51:12.000000000 +0100
+++ mythmusic-local/mythmusic/flacencoder.cpp	2003-12-17 17:17:00.000000000 +0100
@@ -12,6 +12,7 @@
 
 #include <FLAC/file_encoder.h>
 #include <FLAC/assert.h>
+#include <mythtv/mythcontext.h>
 
 FlacEncoder::FlacEncoder(const QString &outfile, int qualitylevel,
                          Metadata *metadata)
@@ -53,9 +54,11 @@
 
     FLAC__file_encoder_set_filename(encoder, outfile.ascii());
 
-    if (FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
+    int ret = FLAC__file_encoder_init(encoder);
+    if (ret != FLAC__FILE_ENCODER_OK)
     {
-        cout << "Couldn't init encoder.\n";
+        VERBOSE(VB_GENERAL, QString("Error initializing FLAC encoder."
+                                    " Got return code: %1").arg(ret));
     }
 
     for (int i = 0; i < NUM_CHANNELS; i++)
@@ -102,6 +105,8 @@
                                             (const FLAC__int32 * const *) input,
                                             sampleindex))
             {
+                VERBOSE(VB_GENERAL, QString("Failed to write flac data."
+                                            " Aborting."));
                 return EENCODEERROR;
             }
             sampleindex = 0;
diff -ur mythmusic/mythmusic/lameencoder.cpp mythmusic-local/mythmusic/lameencoder.cpp
--- mythmusic/mythmusic/lameencoder.cpp	2003-12-05 02:18:42.000000000 +0100
+++ mythmusic-local/mythmusic/lameencoder.cpp	2003-12-17 16:52:45.000000000 +0100
@@ -33,6 +33,9 @@
 #include "lameencoder.h"
 
 #include <iostream>
+
+#include <mythtv/mythcontext.h>
+
 using namespace std;
 
 int write_buffer(char *buf, int bufsize, FILE *fp)
@@ -123,9 +126,11 @@
 
     init_id3tags(gf, metadata);
 
-    if (init_encoder(gf, qualitylevel, vbr) < 0)
+    int lameret = init_encoder(gf, qualitylevel, vbr);
+    if (lameret < 0)
     {
-        cout << "Couldn't initialize lame encoder\n";
+        VERBOSE(VB_GENERAL, QString("Error initializing LAME encoder. "
+                                    "Got return code: %1").arg(lameret));
         return;
     }
 }
@@ -161,13 +166,16 @@
 
     if (lameret < 0)
     {
-        cout << "Lame encoder error '" << lameret << "', aborting.\n";
-        return EENCODEERROR;
+        VERBOSE(VB_ALL, QString("LAME encoder error."));
     } 
     else if (lameret > 0 && out)
     {
         if (write_buffer(mp3buf, lameret, out) != lameret)
-            cout << "Failed to write mp3 data to output file\n";
+        {
+            VERBOSE(VB_GENERAL, QString("Failed to write mp3 data."
+                                        " Aborting."));
+            return EENCODEERROR;
+        }
     }
 
     return 0;
diff -ur mythmusic/mythmusic/treecheckitem.cpp mythmusic-local/mythmusic/treecheckitem.cpp
--- mythmusic/mythmusic/treecheckitem.cpp	2003-08-18 23:30:34.000000000 +0200
+++ mythmusic-local/mythmusic/treecheckitem.cpp	2003-12-17 16:35:33.000000000 +0100
@@ -232,7 +232,7 @@
 bool PlaylistTitle::isDefault()
 {
 //    return ptr_to_owner->isDefault();
-    cout << "Why are you asking " << endl;
+    VERBOSE(VB_ALL, QString("Why are you asking?"));
     return false;
 }
 
diff -ur mythmusic/mythmusic/vorbisencoder.cpp mythmusic-local/mythmusic/vorbisencoder.cpp
--- mythmusic/mythmusic/vorbisencoder.cpp	2003-12-05 02:18:42.000000000 +0100
+++ mythmusic-local/mythmusic/vorbisencoder.cpp	2003-12-17 16:53:35.000000000 +0100
@@ -10,6 +10,9 @@
 #include <vorbis/vorbisfile.h>
 
 #include <iostream>
+
+#include <mythtv/mythcontext.h>
+
 using namespace std;
 
 int write_page(ogg_page *page, FILE *fp)
@@ -57,10 +60,12 @@
         quality = 0.4;
     if (qualitylevel == 1)
         quality = 0.7;
-   
-    if (vorbis_encode_setup_vbr(&vi, 2, 44100, quality))
+  
+    int ret = vorbis_encode_setup_vbr(&vi, 2, 44100, quality);
+    if (ret)
     {
-        cout << "Couldn't initialize vorbis encoder\n";
+        VERBOSE(VB_GENERAL, QString("Error initializing VORBIS encoder."
+                                    " Got return code: %1").arg(ret));
         vorbis_info_clear(&vi);
         return;
     }
@@ -90,7 +95,8 @@
         int ret = write_page(&og, out);
         if (ret != og.header_len + og.body_len)
         {
-            cout << "Failed to write header to output stream\n";
+            VERBOSE(VB_ALL, QString("Failed to write header"
+                                    " to output stream."));
         }
     }
 }
@@ -148,6 +154,8 @@
                 int ret = write_page(&og, out);
                 if (ret != og.header_len + og.body_len)
                 {
+                    VERBOSE(VB_GENERAL, QString("Failed to write ogg data."
+                                            " Aborting."));
                     return EENCODEERROR;
                 }
                 bytes_written += ret;


More information about the mythtv-dev mailing list